feat: bundle TS types definition into one file
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Mon, 28 Aug 2023 21:26:16 +0000 (23:26 +0200)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Mon, 28 Aug 2023 21:26:16 +0000 (23:26 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
.eslintrc.js
CHANGELOG.md
package.json
pnpm-lock.yaml
rollup.config.mjs
tsconfig.json

index 40f952b098ffe8c6fa993f7272c2b60060fc88fd..952d603a43f635a5c40f8149a4dabbf26cddc166 100644 (file)
@@ -54,6 +54,7 @@ module.exports = defineConfig({
           'deque',
           'dequeue',
           'dequeued',
+          'dts',
           'ecma',
           'elu',
           'enqueue',
index f71698d7a8fe985e05c7582217482a42f7541d2b..b28d6eb61ff41020ddfafff5dbcba30a8fab52cd 100644 (file)
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 ## [Unreleased]
 
+### Added
+
+- Bundle typescript types declaration into one file.
+
 ## [2.6.37] - 2023-08-28
 
 ### Fixed
index a8b0b3132f69dc9e9735b23b4bb6e75645cbe12f..b485e249d65e4693bb3d6791306e93a87d5a96bd 100644 (file)
     "rollup-plugin-analyzer": "^4.0.0",
     "rollup-plugin-command": "^1.1.3",
     "rollup-plugin-delete": "^2.0.0",
+    "rollup-plugin-dts": "^6.0.0",
     "rome": "^12.1.3",
     "sinon": "^15.2.0",
     "source-map-support": "^0.5.21",
index 38feb05f1160034638c999d3543ba142a3ac5d5b..1ec0748bed10a526fb7d8419d5f5ed1905b42046 100644 (file)
@@ -110,6 +110,9 @@ devDependencies:
   rollup-plugin-delete:
     specifier: ^2.0.0
     version: 2.0.0
+  rollup-plugin-dts:
+    specifier: ^6.0.0
+    version: 6.0.0(rollup@3.28.1)(typescript@5.2.2)
   rome:
     specifier: ^12.1.3
     version: 12.1.3
@@ -176,11 +179,13 @@ packages:
   /@babel/helper-validator-identifier@7.22.5:
     resolution: {integrity: sha512-aJXu+6lErq8ltp+JhkJUfk1MTGyuA4v7f3pA+BJ5HLfNC6nAQ0Cpi9uOquUj8Hehg0aUiHzWQbOVJGao6ztBAQ==}
     engines: {node: '>=6.9.0'}
+    requiresBuild: true
     dev: true
 
   /@babel/highlight@7.22.13:
     resolution: {integrity: sha512-C/BaXcnnvBCmHTpz/VGZ8jgtE2aYlW4hxDhseJAWZb7gqGM/qtCK6iZUb0TyKFf7BOUsBH7Q7fkRsDRhg1XklQ==}
     engines: {node: '>=6.9.0'}
+    requiresBuild: true
     dependencies:
       '@babel/helper-validator-identifier': 7.22.5
       chalk: 2.4.2
@@ -1327,6 +1332,7 @@ packages:
   /ansi-styles@3.2.1:
     resolution: {integrity: sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==}
     engines: {node: '>=4'}
+    requiresBuild: true
     dependencies:
       color-convert: 1.9.3
     dev: true
@@ -1716,6 +1722,7 @@ packages:
   /chalk@2.4.2:
     resolution: {integrity: sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==}
     engines: {node: '>=4'}
+    requiresBuild: true
     dependencies:
       ansi-styles: 3.2.1
       escape-string-regexp: 1.0.5
@@ -1825,6 +1832,7 @@ packages:
 
   /color-convert@1.9.3:
     resolution: {integrity: sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==}
+    requiresBuild: true
     dependencies:
       color-name: 1.1.3
     dev: true
@@ -1838,6 +1846,7 @@ packages:
 
   /color-name@1.1.3:
     resolution: {integrity: sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw==}
+    requiresBuild: true
     dev: true
 
   /color-name@1.1.4:
@@ -2339,6 +2348,7 @@ packages:
   /escape-string-regexp@1.0.5:
     resolution: {integrity: sha512-vbRorB5FUQWvla16U8R/qgaFIya2qGzwDrNmCZuYKrbdSUMG6I1ZCGQRefkRVhuOkIGVne7BQ35DSfo1qvJqFg==}
     engines: {node: '>=0.8.0'}
+    requiresBuild: true
     dev: true
 
   /escape-string-regexp@2.0.0:
@@ -3378,6 +3388,7 @@ packages:
   /has-flag@3.0.0:
     resolution: {integrity: sha512-sKJf1+ceQBr4SMkvQnBDNDtf4TXpVhVGateu0t918bl30FnbE2m4vNLX+VWe/dpjlb+HugGYzW7uQXH98HPEYw==}
     engines: {node: '>=4'}
+    requiresBuild: true
     dev: true
 
   /has-flag@4.0.0:
@@ -4403,6 +4414,13 @@ packages:
     engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0}
     dev: true
 
+  /magic-string@0.30.3:
+    resolution: {integrity: sha512-B7xGbll2fG/VjP+SWg4sX3JynwIU0mjoTc6MPpKNuIvftk6u6vqhDnk1R80b8C2GBR6ywqy+1DcKBrevBg+bmw==}
+    engines: {node: '>=12'}
+    dependencies:
+      '@jridgewell/sourcemap-codec': 1.4.15
+    dev: true
+
   /make-dir@4.0.0:
     resolution: {integrity: sha512-hXdUTZYIVOt1Ex//jAQi+wTZZpUpwBj/0QsOzqegb3rGMMeJiSEu5xLHnYfBrRV4RH2+OCSOO95Is/7x1WJ4bw==}
     engines: {node: '>=10'}
@@ -5475,6 +5493,20 @@ packages:
       del: 5.1.0
     dev: true
 
+  /rollup-plugin-dts@6.0.0(rollup@3.28.1)(typescript@5.2.2):
+    resolution: {integrity: sha512-A996xSZDAqnx/KfFttzC8mDEuyMjsRpiLCrlGc8effhK8KhE3AG0g1woQiITgFc5HSE8HWU7ccR9CiQ3vXgUlQ==}
+    engines: {node: '>=v18.17.1'}
+    peerDependencies:
+      rollup: ^3.25.0
+      typescript: ^4.5 || ^5.0
+    dependencies:
+      magic-string: 0.30.3
+      rollup: 3.28.1
+      typescript: 5.2.2
+    optionalDependencies:
+      '@babel/code-frame': 7.22.13
+    dev: true
+
   /rollup@3.28.1:
     resolution: {integrity: sha512-R9OMQmIHJm9znrU3m3cpE8uhN0fGdXiawME7aZIpQqvpS/85+Vt1Hq1/yVIcYfOmaQiHjvXkQAoJukvLpau6Yw==}
     engines: {node: '>=14.18.0', npm: '>=8.0.0'}
@@ -5883,6 +5915,7 @@ packages:
   /supports-color@5.5.0:
     resolution: {integrity: sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==}
     engines: {node: '>=4'}
+    requiresBuild: true
     dependencies:
       has-flag: 3.0.0
     dev: true
index 90d56e6034a53764bc90c4ccc8e744a5d21c44a6..fd0452ecda4ec28eef891149ba07bae2c730a2a8 100644 (file)
@@ -1,4 +1,5 @@
 import * as os from 'node:os'
+import { dts } from 'rollup-plugin-dts'
 import terser from '@rollup/plugin-terser'
 import typescript from '@rollup/plugin-typescript'
 import analyze from 'rollup-plugin-analyzer'
@@ -24,58 +25,78 @@ const isDocumentationBuild = process.env.DOCUMENTATION
 
 const maxWorkers = Math.floor(availableParallelism() / 2)
 
-export default {
-  input: 'src/index.ts',
-  strictDeprecations: true,
-  output: [
-    {
-      format: 'cjs',
-      ...(isDevelopmentBuild && {
-        dir: 'lib',
-        sourcemap: true,
-        preserveModules: true,
-        preserveModulesRoot: 'src'
+export default [
+  {
+    input: 'src/index.ts',
+    strictDeprecations: true,
+    output: [
+      {
+        format: 'cjs',
+        ...(isDevelopmentBuild && {
+          dir: 'lib',
+          sourcemap: true,
+          preserveModules: true,
+          preserveModulesRoot: 'src'
+        }),
+        ...(!isDevelopmentBuild && {
+          file: 'lib/index.js',
+          plugins: [terser({ maxWorkers })]
+        })
+      },
+      {
+        format: 'esm',
+        ...(isDevelopmentBuild && {
+          dir: 'lib',
+          sourcemap: true,
+          entryFileNames: '[name].mjs',
+          preserveModules: true,
+          preserveModulesRoot: 'src'
+        }),
+        ...(!isDevelopmentBuild && {
+          file: 'lib/index.mjs',
+          plugins: [terser({ maxWorkers })]
+        })
+      }
+    ],
+    external: [
+      'node:async_hooks',
+      'node:cluster',
+      'node:crypto',
+      'node:events',
+      'node:fs',
+      'node:os',
+      'node:perf_hooks',
+      'node:worker_threads'
+    ],
+    plugins: [
+      typescript({
+        tsconfig: isDevelopmentBuild
+          ? 'tsconfig.development.json'
+          : 'tsconfig.production.json'
       }),
-      ...(!isDevelopmentBuild && {
-        file: 'lib/index.js',
-        plugins: [terser({ maxWorkers })]
-      })
-    },
-    {
-      format: 'esm',
-      ...(isDevelopmentBuild && {
-        dir: 'lib',
-        sourcemap: true,
-        entryFileNames: '[name].mjs',
-        preserveModules: true,
-        preserveModulesRoot: 'src'
+      del({
+        targets: ['lib/*']
       }),
-      ...(!isDevelopmentBuild && {
-        file: 'lib/index.mjs',
-        plugins: [terser({ maxWorkers })]
+      isAnalyzeBuild && analyze(),
+      isDocumentationBuild && command('pnpm typedoc')
+    ]
+  },
+  {
+    input: './lib/dts/index.d.ts',
+    output: [{ format: 'esm', file: 'lib/index.d.ts' }],
+    external: [
+      'node:async_hooks',
+      'node:cluster',
+      'node:events',
+      'node:perf_hooks',
+      'node:worker_threads'
+    ],
+    plugins: [
+      dts(),
+      del({
+        targets: ['lib/dts'],
+        hook: 'buildEnd'
       })
-    }
-  ],
-  external: [
-    'node:async_hooks',
-    'node:cluster',
-    'node:crypto',
-    'node:events',
-    'node:fs',
-    'node:os',
-    'node:perf_hooks',
-    'node:worker_threads'
-  ],
-  plugins: [
-    typescript({
-      tsconfig: isDevelopmentBuild
-        ? 'tsconfig.development.json'
-        : 'tsconfig.production.json'
-    }),
-    del({
-      targets: ['lib/*']
-    }),
-    isAnalyzeBuild && analyze(),
-    isDocumentationBuild && command('pnpm typedoc')
-  ]
-}
+    ]
+  }
+]
index 7b74ede7f6757a4878bc2c2402759bf7d2d06f5c..182a29da4f281ac862ba8048a3d3c477b0f8b010 100644 (file)
@@ -6,6 +6,7 @@
     "outDir": "lib",
     "moduleResolution": "Node",
     "declaration": true,
+    "declarationDir": "lib/dts",
     "strict": true,
     "verbatimModuleSyntax": true,
     "forceConsistentCasingInFileNames": true