@@ -88,11 +88,11 @@ interface PackageJson {
8888// Get our own version
8989const { version } = createRequire ( import . meta. url ) ( '../package.json' ) as PackageJson
9090
91- // Prepare node built-in modules lists.
91+ // Node built-in prefix handling
9292const nodePrefix = 'node:'
9393const nodePrefixRx = / ^ n o d e : /
9494
95- // Files that mark the root of a workspace.
95+ // Files that mark the root of a workspace
9696const workspaceRootFiles = new Set ( [
9797 'pnpm-workspace.yaml' , // pnpm
9898 'lerna.json' , // Lerna
@@ -130,8 +130,8 @@ function nodeExternals(options: ExternalsOptions = {}): Plugin {
130130 let include : RegExp [ ] ,
131131 exclude : RegExp [ ]
132132
133- const isIncluded = ( id : string ) => include . some ( rx => rx . test ( id ) ) ,
134- isExcluded = ( id : string ) => exclude . some ( rx => rx . test ( id ) )
133+ const isIncluded = ( id : string ) => include . length === 0 || include . some ( rx => rx . test ( id ) ) ,
134+ isExcluded = ( id : string ) => exclude . length > 0 && exclude . some ( rx => rx . test ( id ) )
135135
136136 return {
137137 name : 'node-externals' ,
@@ -226,18 +226,22 @@ function nodeExternals(options: ExternalsOptions = {}): Plugin {
226226 include . push ( new RegExp ( '^(?:' + names . join ( '|' ) + ')(?:/.+)?$' ) )
227227 } ,
228228
229- async resolveId ( specifier ) {
230- // Ignore absolute (already resolved) ids, relative imports and virtual modules.
231- if ( / ^ (?: \0 | \. { 0 , 2 } \/ ) / . test ( specifier ) || path . isAbsolute ( specifier ) )
229+ async resolveId ( specifier , importer ) {
230+ if (
231+ ! importer // Ignore entry points (they should always be resolved)
232+ || path . isAbsolute ( specifier ) // Ignore already resolved ids
233+ || / ^ (?: \0 | \. { 1 , 2 } \/ ) / . test ( specifier ) // Ignore virtual modules and relative imports
234+ ) {
232235 return null
236+ }
233237
234238 // Handle node builtins.
235239 if ( isBuiltin ( specifier ) ) {
236240 const stripped = specifier . replace ( nodePrefixRx , '' )
237241 return {
238242 id : config . builtinsPrefix === 'ignore'
239243 ? specifier
240- : config . builtinsPrefix === 'add' || ( specifier . startsWith ( nodePrefix ) && ! isBuiltin ( stripped ) )
244+ : config . builtinsPrefix === 'add' || ! isBuiltin ( stripped )
241245 ? nodePrefix + stripped
242246 : stripped ,
243247 external : ( config . builtins || isIncluded ( specifier ) ) && ! isExcluded ( specifier ) ,
0 commit comments