rollup-plugin-node-externals
Advanced tools
Comparing version 6.1.2 to 7.0.0
@@ -70,4 +70,3 @@ import type { Plugin } from 'rollup'; | ||
export default nodeExternals; | ||
export { nodeExternals, // Named export since 6.1 | ||
nodeExternals as externals }; | ||
export { nodeExternals }; | ||
//# sourceMappingURL=index.d.ts.map |
import path from 'node:path'; | ||
import fs from 'node:fs/promises'; | ||
import { builtinModules } from 'node:module'; | ||
import { createRequire, isBuiltin } from 'node:module'; | ||
// Get our own version | ||
const { version } = createRequire(import.meta.url)('../package.json'); | ||
// Prepare node built-in modules lists. | ||
// Note: node:test is currently not part of builtinModules... and may well never be | ||
// (see https://github.com/nodejs/node/issues/42785) | ||
const nodePrefix = 'node:'; | ||
const nodePrefixRx = /^node:/; | ||
const builtins = { | ||
all: new Set(builtinModules), | ||
alwaysPrefixed: new Set(builtinModules.filter(mod => nodePrefixRx.test(mod))) | ||
}; | ||
for (const extra of ['node:test']) { | ||
builtins.all.add(extra); | ||
builtins.alwaysPrefixed.add(extra); | ||
} | ||
// Files that mark the root of a workspace. | ||
const workspaceRootFiles = new Set([ | ||
'pnpm-workspace.yaml', | ||
'pnpm-workspace.yaml', // pnpm | ||
'lerna.json', // Lerna | ||
@@ -45,5 +37,6 @@ // Note: is there any interest in the following? | ||
let include, exclude; | ||
const isIncluded = (id) => include.some(rx => rx.test(id)), isExcluded = (id) => exclude.some(rx => rx.test(id)); | ||
const isIncluded = (id) => include.length === 0 || include.some(rx => rx.test(id)), isExcluded = (id) => exclude.length > 0 && exclude.some(rx => rx.test(id)); | ||
return { | ||
name: 'node-externals', | ||
version, | ||
async buildStart() { | ||
@@ -58,5 +51,4 @@ // Map the include and exclude options to arrays of regexes. | ||
result.push(new RegExp('^' + entry.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') + '$')); | ||
else if (entry) { | ||
else if (entry) | ||
this.warn(`Ignoring wrong entry type #${index} in '${option}' option: ${JSON.stringify(entry)}`); | ||
} | ||
return result; | ||
@@ -68,7 +60,10 @@ }, [])); | ||
const packagePaths = [] | ||
.concat(config['packagePath']) | ||
.filter(isString); | ||
.concat(config.packagePath) | ||
.filter(isString) | ||
.map(packagePath => path.resolve(packagePath)); | ||
if (packagePaths.length === 0) { | ||
for (let current = process.cwd(), previous; previous !== current; previous = current, current = path.dirname(current)) { | ||
const entries = await fs.readdir(current, { withFileTypes: true }); | ||
for (let current = process.cwd(), previous = undefined; previous !== current; previous = current, current = path.dirname(current)) { | ||
const entries = await fs.readdir(current, { withFileTypes: true }).catch(() => null); | ||
if (entries === null) | ||
this.error(`Could not read contents of directory ${JSON.stringify(current)}.`); | ||
// Gather package.json files. | ||
@@ -87,2 +82,3 @@ if (entries.some(entry => entry.name === 'package.json' && entry.isFile())) | ||
for (const packagePath of packagePaths) { | ||
this.addWatchFile(packagePath); | ||
try { | ||
@@ -93,3 +89,2 @@ const json = (await fs.readFile(packagePath)).toString(); | ||
Object.assign(dependencies, config.deps ? pkg.dependencies : undefined, config.devDeps ? pkg.devDependencies : undefined, config.peerDeps ? pkg.peerDependencies : undefined, config.optDeps ? pkg.optionalDependencies : undefined); | ||
this.addWatchFile(packagePath); | ||
// Break early if this is a npm/yarn workspace root. | ||
@@ -113,2 +108,3 @@ if ('workspaces' in pkg) | ||
} | ||
// Add all dependencies as an include RegEx. | ||
const names = Object.keys(dependencies); | ||
@@ -118,16 +114,16 @@ if (names.length > 0) | ||
}, | ||
async resolveId(id) { | ||
// Ignore already resolved ids, relative imports and virtual modules. | ||
if (/^(?:\0|\.{0,2}\/)/.test(id) || path.isAbsolute(id)) | ||
async resolveId(specifier) { | ||
// Ignore absolute (already resolved) ids, relative imports and virtual modules. | ||
if (/^(?:\0|\.{0,2}\/)/.test(specifier) || path.isAbsolute(specifier)) | ||
return null; | ||
// Handle node builtins. | ||
if (id.startsWith(nodePrefix) || builtins.all.has(id)) { | ||
const stripped = id.replace(nodePrefixRx, ''); | ||
if (isBuiltin(specifier)) { | ||
const stripped = specifier.replace(nodePrefixRx, ''); | ||
return { | ||
id: config.builtinsPrefix === 'ignore' | ||
? id | ||
: config.builtinsPrefix === 'add' || builtins.alwaysPrefixed.has(id) | ||
? specifier | ||
: config.builtinsPrefix === 'add' || (specifier.startsWith(nodePrefix) && !isBuiltin(stripped)) | ||
? nodePrefix + stripped | ||
: stripped, | ||
external: (config.builtins || isIncluded(id)) && !isExcluded(id), | ||
external: (config.builtins || isIncluded(specifier)) && !isExcluded(specifier), | ||
moduleSideEffects: false | ||
@@ -137,3 +133,3 @@ }; | ||
// Handle npm dependencies. | ||
return isIncluded(id) && !isExcluded(id) | ||
return isIncluded(specifier) && !isExcluded(specifier) | ||
? false // external | ||
@@ -145,5 +141,3 @@ : null; // normal handling | ||
export default nodeExternals; | ||
export { nodeExternals, // Named export since 6.1 | ||
nodeExternals as externals // For backwards compatibility | ||
}; | ||
export { nodeExternals }; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "rollup-plugin-node-externals", | ||
"version": "6.1.2", | ||
"version": "7.0.0", | ||
"description": "Automatically declare NodeJS built-in modules and npm dependencies as 'external' in Rollup config", | ||
@@ -32,3 +32,3 @@ "author": "Stephan Schreiber <septh@sfr.fr>", | ||
"engines": { | ||
"node": ">=16.0.0" | ||
"node": ">= 21 || ^20.6.0 || ^18.19.0" | ||
}, | ||
@@ -51,14 +51,14 @@ "files": [ | ||
"devDependencies": { | ||
"@fast-check/ava": "^1.1.4", | ||
"@types/node": "^18.18.3", | ||
"@typescript-eslint/eslint-plugin": "^6.7.4", | ||
"@typescript-eslint/parser": "^6.7.4", | ||
"ava": "^5.2.0", | ||
"eslint": "^8.40.0", | ||
"fast-check": "^3.8.1", | ||
"rimraf": "^3.0.2", | ||
"rollup": "^4.0.0", | ||
"ts-node": "^10.9.1", | ||
"tslib": "^2.5.0", | ||
"typescript": "^5.0.4" | ||
"@fast-check/ava": "^1.2.1", | ||
"@septh/ts-run": "^1.0.2", | ||
"@types/node": "^18.19.10", | ||
"@typescript-eslint/eslint-plugin": "^6.19.1", | ||
"@typescript-eslint/parser": "^6.19.1", | ||
"ava": "^6.1.0", | ||
"eslint": "^8.56.0", | ||
"fast-check": "^3.15.0", | ||
"rimraf": "^5.0.5", | ||
"rollup": "^4.9.6", | ||
"tslib": "^2.6.2", | ||
"typescript": "^5.3.3" | ||
}, | ||
@@ -74,3 +74,3 @@ "peerDependencies": { | ||
"nodeArguments": [ | ||
"--loader=ts-node/esm" | ||
"--import=@septh/ts-run/register" | ||
] | ||
@@ -77,0 +77,0 @@ }, |
@@ -47,3 +47,2 @@ # rollup-plugin-node-externals | ||
> Note: an undocumented named export `externals` also exists that is kept in v6.1 for backwards compatibility only and will be removed in the next major version. | ||
@@ -193,9 +192,14 @@ ### Options | ||
### Breaking changes in version 6 | ||
### Breaking changes in version 7 | ||
- This package now supports the latest release of [any major version that is supported by Node.js itself](https://github.com/nodejs/Release#release-schedule). | ||
- The undocumented `externals` named export has been removed. | ||
### Breaking changes in previous versions | ||
<details><summary>Previous versions -- click to expand</summary> | ||
#### Breaking changes in version 6 | ||
- This package is now esm-only and requires NodeJS v16+.<br />*If you need CommonJS or older NodeJS support, please stick to v5.* | ||
- This plugin now has a **peer-dependency** on Rollup `^3.0.0 || ^4.0.0`.<br />*If you need Rollup 2 support, please stick to v5.* | ||
<details><summary>Previous versions -- click to expand</summary> | ||
### Breaking changes in version 5 | ||
#### Breaking changes in version 5 | ||
- In previous versions, the `devDeps` option defaulted to `true`.<br>This was practical, but often wrong: devDependencies are meant just for that: being used when developping. Therefore, the `devDeps` option now defaults to `false`, meaning Rollup will include them in your bundle. | ||
@@ -207,10 +211,11 @@ - As anticipated since v4, the `builtinsPrefix` option now defaults to `'add'`. | ||
### Breaking changes in version 4 | ||
#### Breaking changes in version 4 | ||
- In previous versions, the `deps` option defaulted to `false`.<br>This was practical, but often wrong: when bundling for distribution, you want your own dependencies to be installed by the package manager alongside your package, so they should not be bundled in the code. Therefore, the `deps` option now defaults to `true`. | ||
- Now requires Node 14 (up from Node 12 for previous versions). | ||
- Now has a _peer dependency_ on `rollup ^2.60.0`. | ||
</summary> | ||
</details> | ||
## Licence | ||
MIT |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
19470
219
203