Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion packages/nestjs/rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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 }),
Expand Down