From dfbd313f3d357c8d0a65d14f40129182850f4482 Mon Sep 17 00:00:00 2001 From: Tristan Menzel Date: Tue, 13 Feb 2024 13:39:46 -0800 Subject: [PATCH] fix: Tweak rollup config to use a more robust way of externalising node_modules --- package.json | 9 +++++---- rollup.config.ts | 6 ++++-- src/templates/node/rollup.config.ts.sample | 5 ++--- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index cec6735..6b95636 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@makerx/ts-toolkit", - "version": "4.0.0-beta.7", + "version": "4.0.0-beta.8", "description": "This cli facilitates the creation of boilerplate files in a new typescript repo", "type": "module", "scripts": { @@ -56,9 +56,10 @@ "npm-run-all": "^4.1.5", "prettier": "3.2.5", "rimraf": "5.0.5", - "rollup": "4.9.6", - "tsx": "^4.7.0", + "rollup": "4.10.0", + "tsx": "4.7.1", "typescript": "5.3.3", - "vitest": "1.2.2" + "vitest": "1.2.2", + "@rollup/plugin-commonjs": "25.0.7" } } diff --git a/rollup.config.ts b/rollup.config.ts index e7cbe85..abe8916 100644 --- a/rollup.config.ts +++ b/rollup.config.ts @@ -1,8 +1,9 @@ import nodeResolve from '@rollup/plugin-node-resolve' +import commonjs from '@rollup/plugin-commonjs' import typescript from '@rollup/plugin-typescript' import json from '@rollup/plugin-json' import type { RollupOptions } from 'rollup' -import pkg from './package.json' with { type: 'json' } + const config: RollupOptions = { input: ['src/index.ts', 'src/bin/run-cli.ts'], output: [ @@ -28,11 +29,12 @@ const config: RollupOptions = { propertyReadSideEffects: false, }, // List modules that should not be included in the output bundle (ie. they should remain external dependencies) - external: [...Object.keys(pkg.dependencies) /*, ...Object.keys(pkg.peerDependencies) */], + external: [/node_modules/], plugins: [ typescript({ tsconfig: 'tsconfig.build.json', }), + commonjs(), nodeResolve(), json(), ], diff --git a/src/templates/node/rollup.config.ts.sample b/src/templates/node/rollup.config.ts.sample index fe36c84..6125636 100644 --- a/src/templates/node/rollup.config.ts.sample +++ b/src/templates/node/rollup.config.ts.sample @@ -3,8 +3,7 @@ import commonjs from '@rollup/plugin-commonjs' import typescript from '@rollup/plugin-typescript' import json from '@rollup/plugin-json' import type { RollupOptions } from 'rollup' -import pkg from './package.json' with { type: 'json' } -const typedPackage = pkg as {dependencies?: Record, peerDependencies?: Record} + const config: RollupOptions = { input: ['src/index.ts'], output: [ @@ -30,7 +29,7 @@ const config: RollupOptions = { propertyReadSideEffects: false, }, // List modules that should not be included in the output bundle (ie. they should remain external dependencies) - external: [...Object.keys(typedPackage.dependencies ?? {}) , ...Object.keys(typedPackage.peerDependencies?? {}) ], + external: [/node_modules/], plugins: [ typescript({ tsconfig: 'tsconfig.build.json',