@@ -70,22 +70,22 @@ export async function transformPrimordials(
7070
7171 // The codemod needs to know which primordials we export so it doesn't
7272 // try to call out to identifiers we haven't actually exported. Read
73- // the surface from src/primordials.ts (the ESM source) rather than
74- // dist/primordials.js (esbuild-compiled with a `__export(obj, {…})`
75- // form parseExports doesn't recognize). The runtime require still
76- // points at dist/primordials.js — we just use the .ts source as a
77- // catalog of names .
78- const srcPrimordialsTs = path . join ( distRoot , '..' , 'src' , 'primordials.ts ' )
79- const surface = loadPrimordialsSurface ( distRoot , srcPrimordialsTs )
73+ // the surface from src/primordials/ (the directory of ESM leaves
74+ // post-split) rather than dist/primordials/* .js (esbuild-compiled
75+ // with a `__export(obj, {…})` form parseExports doesn't recognize).
76+ // `loadPrimordialsSurface` concatenates every leaf in the directory
77+ // and parses the unified output as a single primordials surface .
78+ const srcPrimordialsDir = path . join ( distRoot , '..' , 'src' , 'primordials' )
79+ const surface = loadPrimordialsSurface ( distRoot , srcPrimordialsDir )
8080
81- // Per-file specifier: walk up from the bundle to dist/, then down to
82- // primordials.js. We strip a leading './' replacement because Node's
83- // CJS resolver requires either an absolute path or one starting with
84- // `./`/`../`; bare 'primordials.js' would trigger a node_modules
85- // lookup. Forward-slash normalize for Windows.
86- const runtimePrimordialsAbs = path . join ( distRoot , 'primordials.js' )
87- const specifier = ( absFile : string ) => {
88- const rel = path . relative ( path . dirname ( absFile ) , runtimePrimordialsAbs )
81+ // Per-leaf specifier: walk up from the bundle to dist/, then down to
82+ // primordials/<leaf> .js. We strip a leading './' replacement because
83+ // Node's CJS resolver requires either an absolute path or one
84+ // starting with `./`/`../`; bare 'primordials/x .js' would trigger a
85+ // node_modules lookup. Forward-slash normalize for Windows.
86+ const leafSpecifier = ( absFile : string , leaf : string ) => {
87+ const target = path . join ( distRoot , 'primordials' , ` ${ leaf } .js` )
88+ const rel = path . relative ( path . dirname ( absFile ) , target )
8989 const normalized = rel . split ( path . sep ) . join ( '/' )
9090 return normalized . startsWith ( '.' ) ? normalized : `./${ normalized } `
9191 }
@@ -102,7 +102,18 @@ export async function transformPrimordials(
102102 exported : surface . exports ,
103103 apply : true ,
104104 includeGuessed : false ,
105- importStyle : { kind : 'cjs' , specifier, aliasPrefix : '_p_' } ,
105+ importStyle : {
106+ kind : 'cjs' ,
107+ // splitByLeaf is the active path; specifier is unused but
108+ // required by the type — pass a sentinel that would trip a
109+ // sanity check if accidentally used.
110+ specifier : ( ) => '<unused: splitByLeaf is set>' ,
111+ aliasPrefix : '_p_' ,
112+ splitByLeaf : {
113+ exportToLeaf : surface . exportToLeaf ,
114+ leafSpecifier,
115+ } ,
116+ } ,
106117 } )
107118
108119 if ( ! quiet && result . filesChanged > 0 ) {
0 commit comments