From bcaf6e9a3f6b884738a9af850193512bcc2b7bd0 Mon Sep 17 00:00:00 2001 From: Sebastian Alex Date: Mon, 9 Sep 2024 12:33:42 +0200 Subject: [PATCH] nestjs: include tslib in code instead of externalizing it --- packages/nestjs/rollup.config.mjs | 34 ++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/packages/nestjs/rollup.config.mjs b/packages/nestjs/rollup.config.mjs index e8cc1459..8f6e4619 100644 --- a/packages/nestjs/rollup.config.mjs +++ b/packages/nestjs/rollup.config.mjs @@ -7,6 +7,35 @@ import packageJson from './package.json' with { type: 'json' }; const extensions = ['.js', '.ts']; +/** + * Include and exclude externals based on patterns. + * If module is included, is is treated as NOT external. + * + * Include is resolved first, then exclude. + * If both patterns miss, the module is included. + */ +function externals({ include, exclude }) { + function test(pattern, id) { + if (pattern instanceof RegExp) { + return pattern.test(id); + } + + return pattern === id; + } + + return (id) => { + if (include.some((pattern) => test(pattern, id))) { + return false; + } + + if (exclude.some((pattern) => test(pattern, id))) { + return true; + } + + return false; + }; +} + /** @type {import('rollup').RollupOptions} */ export default { input: './src/index.ts', @@ -22,7 +51,10 @@ export default { sourcemap: true, }, ], - external: [/\/node_modules\//, '@backtrace/node'], + external: externals({ + include: [/tslib/], + exclude: [/\/node_modules\//, '@backtrace/node'], + }), plugins: [ typescript({ tsconfig: './tsconfig.build.json' }), nodeResolve({ extensions, preferBuiltins: true }),