@@ -88,31 +88,25 @@ export const flattenId = (id: string): string =>
8888export  const  normalizeId  =  ( id : string ) : string  => 
8989  id . replace ( replaceNestedIdRE ,  ' > ' ) 
9090
91- //TODO: revisit later to see if the edge case that "compiling using node v12 code to be run in node v16 in the server" is what we intend to support. 
92- const  builtins  =  new  Set ( [ 
93-   ...builtinModules , 
94-   'assert/strict' , 
95-   'diagnostics_channel' , 
96-   'dns/promises' , 
97-   'fs/promises' , 
98-   'path/posix' , 
99-   'path/win32' , 
100-   'readline/promises' , 
101-   'stream/consumers' , 
102-   'stream/promises' , 
103-   'stream/web' , 
104-   'timers/promises' , 
105-   'util/types' , 
106-   'wasi' , 
107- ] ) 
108- 
91+ // Supported by Node, Deno, Bun 
10992const  NODE_BUILTIN_NAMESPACE  =  'node:' 
93+ // Supported by Deno 
94+ const  NPM_BUILTIN_NAMESPACE  =  'npm:' 
95+ // Supported by Bun 
96+ const  BUN_BUILTIN_NAMESPACE  =  'bun:' 
97+ // Some runtimes like Bun injects namespaced modules here, which is not a node builtin 
98+ const  nodeBuiltins  =  builtinModules . filter ( ( id )  =>  ! id . includes ( ':' ) ) 
99+ 
100+ // TODO: Use `isBuiltin` from `node:module`, but Deno doesn't support it 
110101export  function  isBuiltin ( id : string ) : boolean  { 
111-   return  builtins . has ( 
112-     id . startsWith ( NODE_BUILTIN_NAMESPACE ) 
113-       ? id . slice ( NODE_BUILTIN_NAMESPACE . length ) 
114-       : id , 
115-   ) 
102+   if  ( process . versions . deno  &&  id . startsWith ( NPM_BUILTIN_NAMESPACE ) )  return  true 
103+   if  ( process . versions . bun  &&  id . startsWith ( BUN_BUILTIN_NAMESPACE ) )  return  true 
104+   return  isNodeBuiltin ( id ) 
105+ } 
106+ 
107+ export  function  isNodeBuiltin ( id : string ) : boolean  { 
108+   if  ( id . startsWith ( NODE_BUILTIN_NAMESPACE ) )  return  true 
109+   return  nodeBuiltins . includes ( id ) 
116110} 
117111
118112export  function  isInNodeModules ( id : string ) : boolean  { 
0 commit comments