From b40c4b06563e29d2d2e51a3cc6c0d58b9e72ff7a Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Mon, 28 Aug 2023 23:26:16 +0200 Subject: [PATCH] feat: bundle TS types definition into one file MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- .eslintrc.js | 1 + CHANGELOG.md | 4 ++ package.json | 1 + pnpm-lock.yaml | 33 ++++++++++++ rollup.config.mjs | 125 +++++++++++++++++++++++++++------------------- tsconfig.json | 1 + 6 files changed, 113 insertions(+), 52 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 40f952b0..952d603a 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -54,6 +54,7 @@ module.exports = defineConfig({ 'deque', 'dequeue', 'dequeued', + 'dts', 'ecma', 'elu', 'enqueue', diff --git a/CHANGELOG.md b/CHANGELOG.md index f71698d7..b28d6eb6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/package.json b/package.json index a8b0b313..b485e249 100644 --- a/package.json +++ b/package.json @@ -140,6 +140,7 @@ "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", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 38feb05f..1ec0748b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -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 diff --git a/rollup.config.mjs b/rollup.config.mjs index 90d56e60..fd0452ec 100644 --- a/rollup.config.mjs +++ b/rollup.config.mjs @@ -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') - ] -} + ] + } +] diff --git a/tsconfig.json b/tsconfig.json index 7b74ede7..182a29da 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -6,6 +6,7 @@ "outDir": "lib", "moduleResolution": "Node", "declaration": true, + "declarationDir": "lib/dts", "strict": true, "verbatimModuleSyntax": true, "forceConsistentCasingInFileNames": true -- 2.34.1