@@ -122,6 +122,42 @@ describe('createSwcPlugin externalizeNonSteps', () => {
122122 expect ( output ) . not . toContain ( '@/lib/config' ) ;
123123 } ) ;
124124
125+ it ( 'does not relativize Node.js builtin imports' , async ( ) => {
126+ const outdir = join ( testRoot , 'out' ) ;
127+ const srcDir = join ( testRoot , 'src' ) ;
128+ const stepFile = join ( srcDir , 'step.ts' ) ;
129+
130+ writeFile (
131+ stepFile ,
132+ `import { createHash } from 'crypto';\nimport { join } from 'node:path';\nconsole.log(createHash, join);`
133+ ) ;
134+
135+ const result = await esbuild . build ( {
136+ entryPoints : [ stepFile ] ,
137+ absWorkingDir : testRoot ,
138+ outdir,
139+ bundle : true ,
140+ format : 'esm' ,
141+ platform : 'node' ,
142+ write : false ,
143+ plugins : [
144+ createSwcPlugin ( {
145+ mode : 'step' ,
146+ entriesToBundle : [ stepFile ] ,
147+ outdir,
148+ } ) ,
149+ ] ,
150+ } ) ;
151+
152+ expect ( result . errors ) . toHaveLength ( 0 ) ;
153+ const output = result . outputFiles [ 0 ] . text ;
154+ // Builtins should remain as bare specifiers, not relativized paths
155+ expect ( output ) . toMatch ( / f r o m \s + [ " ' ] c r y p t o [ " ' ] / ) ;
156+ expect ( output ) . toMatch ( / f r o m \s + [ " ' ] n o d e : p a t h [ " ' ] / ) ;
157+ expect ( output ) . not . toMatch ( / f r o m \s + [ " ' ] \. .* c r y p t o [ " ' ] / ) ;
158+ expect ( output ) . not . toMatch ( / f r o m \s + [ " ' ] \. .* n o d e : p a t h [ " ' ] / ) ;
159+ } ) ;
160+
125161 it ( 'does not externalize aliased imports that resolve into node_modules' , async ( ) => {
126162 const outdir = join ( testRoot , 'out' ) ;
127163 const srcDir = join ( testRoot , 'src' ) ;
0 commit comments