From f5b19c83b7ad1053a10e49f654d73210f1495268 Mon Sep 17 00:00:00 2001 From: Alejandro Gallardo Escobar Date: Mon, 4 Dec 2023 12:36:30 +0100 Subject: [PATCH 1/5] Replace types declaration plugin --- getRollupConfig.js | 22 +++++++++------------- package.json | 2 +- yarn.lock | 29 +++++++++++------------------ 3 files changed, 21 insertions(+), 32 deletions(-) diff --git a/getRollupConfig.js b/getRollupConfig.js index 67ae7b0..87226d4 100644 --- a/getRollupConfig.js +++ b/getRollupConfig.js @@ -1,20 +1,12 @@ const commonjs = require('@rollup/plugin-commonjs'); const { nodeResolve: resolve } = require('@rollup/plugin-node-resolve'); -const command = require('rollup-plugin-command'); const { babel } = require('@rollup/plugin-babel'); const image = require('@rollup/plugin-image'); +const typescript = require('@rollup/plugin-typescript'); const ignoreImport = require('rollup-plugin-ignore-import'); const path = require('path'); -const tsc = require('node-typescript-compiler'); const json = require('@rollup/plugin-json'); -const compileTypings = (cwd) => () => { - return tsc.compile({ - project: cwd, - emitDeclarationOnly: true, - }); -}; - module.exports = (dirname, project) => { const pkgPath = path.join(dirname, 'package.json'); // eslint-disable-next-line import/no-dynamic-require, global-require @@ -40,11 +32,15 @@ module.exports = (dirname, project) => { return external.includes(namespace); }, plugins: [ - command(compileTypings(project || dirname), { - exitOnFail: true, - wait: true, - }), resolve({ extensions }), + typescript({ + tsconfig: project || dirname, + noForceEmit: true, + compilerOptions: { + emitDeclarationOnly: true, + noEmitOnError: true, + }, + }), commonjs(), babel({ extensions, diff --git a/package.json b/package.json index d67b182..90f8e4f 100644 --- a/package.json +++ b/package.json @@ -34,9 +34,9 @@ "@rollup/plugin-image": "^3.0.3", "@rollup/plugin-json": "^6.0.1", "@rollup/plugin-node-resolve": "^15.2.3", + "@rollup/plugin-typescript": "^11.1.5", "cross-spawn": "^7.0.3", "minimist": "^1.2.8", - "node-typescript-compiler": "^3.0.0", "rollup": "^4.6.0", "rollup-plugin-command": "^1.1.3", "rollup-plugin-ignore-import": "^1.3.2", diff --git a/yarn.lock b/yarn.lock index 38319a9..fba27d3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1385,6 +1385,14 @@ is-module "^1.0.0" resolve "^1.22.1" +"@rollup/plugin-typescript@^11.1.5": + version "11.1.5" + resolved "https://registry.yarnpkg.com/@rollup/plugin-typescript/-/plugin-typescript-11.1.5.tgz#039c763bf943a5921f3f42be255895e75764cb91" + integrity sha512-rnMHrGBB0IUEv69Q8/JGRD/n4/n6b3nfpufUu26axhUcboUzv/twfZU8fIBbTOphRAe0v8EyxzeDpKXqGHfyDA== + dependencies: + "@rollup/pluginutils" "^5.0.1" + resolve "^1.22.1" + "@rollup/pluginutils@^5.0.1": version "5.0.2" resolved "https://registry.yarnpkg.com/@rollup/pluginutils/-/pluginutils-5.0.2.tgz#012b8f53c71e4f6f9cb317e311df1404f56e7a33" @@ -1911,7 +1919,7 @@ core-js-pure@^3.30.2: resolved "https://registry.yarnpkg.com/core-js-pure/-/core-js-pure-3.32.0.tgz#5d79f85da7a4373e9a06494ccbef995a4c639f8b" integrity sha512-qsev1H+dTNYpDUEURRuOXMvpdtAnNEvQWS/FMJ2Vb5AY8ZP4rAPQldkE27joykZPJTe0+IVgHZYh1P5Xu1/i1g== -cross-spawn@^7, cross-spawn@^7.0.2, cross-spawn@^7.0.3: +cross-spawn@^7.0.2, cross-spawn@^7.0.3: version "7.0.3" resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.3.tgz#f73a85b9d5d41d045551c177e2882d4ac85728a6" integrity sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w== @@ -2952,7 +2960,7 @@ lodash.merge@^4.6.2: resolved "https://registry.yarnpkg.com/lodash.merge/-/lodash.merge-4.6.2.tgz#558aa53b43b661e1925a0afdfa36a9a1085fe57a" integrity sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ== -lodash@^4, lodash@^4.17.10, lodash@^4.17.21: +lodash@^4.17.10, lodash@^4.17.21: version "4.17.21" resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c" integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg== @@ -3062,16 +3070,6 @@ node-releases@^2.0.13: resolved "https://registry.yarnpkg.com/node-releases/-/node-releases-2.0.13.tgz#d5ed1627c23e3461e819b02e57b75e4899b1c81d" integrity sha512-uYr7J37ae/ORWdZeQ1xxMJe3NtdmqMC/JZK+geofDrkLUApKRHPd18/TxtBOJ4A0/+uUIliorNrfYV6s1b02eQ== -node-typescript-compiler@^3.0.0: - version "3.0.0" - resolved "https://registry.yarnpkg.com/node-typescript-compiler/-/node-typescript-compiler-3.0.0.tgz#f6ed772eb3f1b890fb7896348d63ab5a2e8d6e7d" - integrity sha512-b3sE88wRNdVW2bNa51ASzh97sAf/P/p1ArTybW/rBWL7QBKv9y4amv5EodKXUe2sL9bDatNqZIkD66AlwksfjA== - dependencies: - cross-spawn "^7" - lodash "^4" - path-exists "^4" - tildify "^2" - npm-run-path@^4.0.1: version "4.0.1" resolved "https://registry.yarnpkg.com/npm-run-path/-/npm-run-path-4.0.1.tgz#b7ecd1e5ed53da8e37a55e1c2269e0b97ed748ea" @@ -3220,7 +3218,7 @@ parent-module@^1.0.0: dependencies: callsites "^3.0.0" -path-exists@^4, path-exists@^4.0.0: +path-exists@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/path-exists/-/path-exists-4.0.0.tgz#513bdbe2d3b95d7762e8c1137efa195c6c61b5b3" integrity sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w== @@ -3610,11 +3608,6 @@ text-table@^0.2.0: resolved "https://registry.yarnpkg.com/text-table/-/text-table-0.2.0.tgz#7f5ee823ae805207c00af2df4a84ec3fcfa570b4" integrity sha1-f17oI66AUgfACvLfSoTsP8+lcLQ= -tildify@^2: - version "2.0.0" - resolved "https://registry.yarnpkg.com/tildify/-/tildify-2.0.0.tgz#f205f3674d677ce698b7067a99e949ce03b4754a" - integrity sha512-Cc+OraorugtXNfs50hU9KS369rFXCfgGLpfCfvlc+Ud5u6VWmUQsOAa9HbTvheQdYnrdJqqv1e5oIqXppMYnSw== - titleize@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/titleize/-/titleize-3.0.0.tgz#71c12eb7fdd2558aa8a44b0be83b8a76694acd53" From 3e2d167b3fa4b3e568c404e579479e6a6a87f0c1 Mon Sep 17 00:00:00 2001 From: Alejandro Gallardo Escobar Date: Mon, 4 Dec 2023 12:52:21 +0100 Subject: [PATCH 2/5] 0.1.2-beta.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 90f8e4f..eca4386 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@cabify/package-build", - "version": "0.1.1", + "version": "0.1.2-beta.0", "description": "Common configuration & scripts for building TS packages with rollup", "license": "Apache-2.0", "main": "build.js", From 1d04dae966795eecd5c3b36615e5a86595f9b3cc Mon Sep 17 00:00:00 2001 From: Alejandro Gallardo Escobar Date: Mon, 4 Dec 2023 12:55:52 +0100 Subject: [PATCH 3/5] 0.1.2-beta.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index eca4386..2715f8c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@cabify/package-build", - "version": "0.1.2-beta.0", + "version": "0.1.2-beta.1", "description": "Common configuration & scripts for building TS packages with rollup", "license": "Apache-2.0", "main": "build.js", From f863d7689e0cdb7303dffd053b00e85137dcd796 Mon Sep 17 00:00:00 2001 From: Alejandro Gallardo Escobar Date: Mon, 4 Dec 2023 13:17:29 +0100 Subject: [PATCH 4/5] Fix CHANGELOG --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e8c7c70..30acad5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,13 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] -## [0.1.2] - 2022-06-05 +## [0.1.2] - 2023-06-26 ### Fixed - CJS-ESM interoperability. -## [0.1.1] - 2022-10-27 +## [0.1.1] - 2023-02-06 ### Fixed From a5aa3f522a9371840f460f7b3880f1af4128ca92 Mon Sep 17 00:00:00 2001 From: Alejandro Gallardo Escobar Date: Tue, 5 Dec 2023 10:22:44 +0100 Subject: [PATCH 5/5] Configuration as a plugin --- plugin.js | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 plugin.js diff --git a/plugin.js b/plugin.js new file mode 100644 index 0000000..0dd7b16 --- /dev/null +++ b/plugin.js @@ -0,0 +1,86 @@ +const commonjs = require('@rollup/plugin-commonjs'); +const { nodeResolve: resolve } = require('@rollup/plugin-node-resolve'); +const { babel } = require('@rollup/plugin-babel'); +const image = require('@rollup/plugin-image'); +const typescript = require('@rollup/plugin-typescript'); +const ignoreImport = require('rollup-plugin-ignore-import'); +const path = require('path'); +const json = require('@rollup/plugin-json'); + +/** + * @param {string} dirname path to the root of the package + * @param {string} project path to the tsconfig.json file + * @returns {import("rollup").Plugin} + */ +function cabifyPackagePlugin(dirname, project) { + const pkgPath = path.join(dirname, 'package.json'); + // eslint-disable-next-line import/no-dynamic-require, global-require + const pkg = require(pkgPath); + + const external = [ + ...Object.keys(pkg.dependencies || {}), + ...Object.keys(pkg.peerDependencies || {}), + ]; + + const extensions = ['.js', '.jsx', '.ts', '.tsx']; + + return { + name: 'cabify-package', + options() { + return { + input: { + input: `${dirname}/src/index.ts`, + external: (id) => { + const moduleName = id.replace(dirname, ''); + const [namespace, packageName] = moduleName.split('/'); + + if (namespace.startsWith('@')) { + return external.includes(`${namespace}/${packageName}`); + } + return external.includes(namespace); + }, + plugins: [ + resolve({ extensions }), + typescript({ + tsconfig: project || dirname, + noForceEmit: true, + compilerOptions: { + emitDeclarationOnly: true, + noEmitOnError: true, + }, + }), + commonjs(), + babel({ + extensions, + babelHelpers: 'runtime', + include: ['src/**/*'], + rootMode: 'upward', + }), + image(), + json(), + ignoreImport({ + // Ignore all .scss and .css file imports while building the bundle + extensions: ['.scss', '.css'], + }), + ], + }, + output: [ + { + file: pkg.main, + format: 'cjs', + sourcemap: true, + // See: https://rollupjs.org/configuration-options/#output-interop + interop: 'auto', + }, + { + file: pkg.module, + format: 'esm', + sourcemap: true, + }, + ], + }; + }, + }; +} + +module.exports = cabifyPackagePlugin;