@@ -36,6 +36,7 @@ export default defineConfig({
3636 input : {
3737 index : './src/node/index.ts' ,
3838 'module-runner' : './src/module-runner/index.ts' ,
39+ internal : './src/node/internalIndex.ts' ,
3940 } ,
4041 output : {
4142 dir : './dist/node' ,
@@ -305,43 +306,46 @@ function replaceConfusingTypeNames(
305306 chunk : OutputChunk ,
306307 importBindings : ImportBindings [ ] ,
307308) {
308- for ( const modName in identifierReplacements ) {
309- const imp = importBindings . filter ( ( imp ) => imp . id === modName )
310- // Validate that `identifierReplacements` is not outdated if there's no match
311- if ( imp . length === 0 ) {
312- this . warn (
313- `${ chunk . fileName } does not import "${ modName } " for replacement` ,
314- )
315- process . exitCode = 1
316- continue
317- }
318-
319- const replacements = identifierReplacements [ modName ]
320- for ( const id in replacements ) {
309+ const isInternalEntry = chunk . fileName . startsWith ( 'internal.' )
310+ if ( ! isInternalEntry ) {
311+ for ( const modName in identifierReplacements ) {
312+ const imp = importBindings . filter ( ( imp ) => imp . id === modName )
321313 // Validate that `identifierReplacements` is not outdated if there's no match
322- if ( ! imp . some ( ( i ) => i . locals . includes ( id ) ) ) {
314+ if ( imp . length === 0 ) {
323315 this . warn (
324- `${ chunk . fileName } does not import "${ id } " from " ${ modName } " for replacement` ,
316+ `${ chunk . fileName } does not import "${ modName } " for replacement` ,
325317 )
326318 process . exitCode = 1
327319 continue
328320 }
329321
330- const betterId = replacements [ id ]
331- const regexEscapedId = escapeRegex ( id )
332- // If the better id accesses a namespace, the existing `Foo as Foo$1`
333- // named import cannot be replaced with `Foo as Namespace.Foo`, so we
334- // pre-emptively remove the whole named import
335- if ( betterId . includes ( '.' ) ) {
322+ const replacements = identifierReplacements [ modName ]
323+ for ( const id in replacements ) {
324+ // Validate that `identifierReplacements` is not outdated if there's no match
325+ if ( ! imp . some ( ( i ) => i . locals . includes ( id ) ) ) {
326+ this . warn (
327+ `${ chunk . fileName } does not import "${ id } " from "${ modName } " for replacement` ,
328+ )
329+ process . exitCode = 1
330+ continue
331+ }
332+
333+ const betterId = replacements [ id ]
334+ const regexEscapedId = escapeRegex ( id )
335+ // If the better id accesses a namespace, the existing `Foo as Foo$1`
336+ // named import cannot be replaced with `Foo as Namespace.Foo`, so we
337+ // pre-emptively remove the whole named import
338+ if ( betterId . includes ( '.' ) ) {
339+ chunk . code = chunk . code . replace (
340+ new RegExp ( `\\b\\w+\\b as ${ regexEscapedId } ,?\\s?` ) ,
341+ '' ,
342+ )
343+ }
336344 chunk . code = chunk . code . replace (
337- new RegExp ( `\\b\\w+\\b as ${ regexEscapedId } ,?\\s?` ) ,
338- '' ,
345+ new RegExp ( `\\b${ regexEscapedId } \\b` , 'g' ) ,
346+ betterId ,
339347 )
340348 }
341- chunk . code = chunk . code . replace (
342- new RegExp ( `\\b${ regexEscapedId } \\b` , 'g' ) ,
343- betterId ,
344- )
345349 }
346350 }
347351
@@ -361,16 +365,21 @@ function replaceConfusingTypeNames(
361365 )
362366 process . exitCode = 1
363367 }
364- const notUsedConfusingTypeNames = ignoreConfusingTypeNames . filter (
365- ( id ) => ! identifiers . includes ( id ) ,
366- )
367- // Validate that `identifierReplacements` is not outdated if there's no match
368- if ( notUsedConfusingTypeNames . length ) {
369- const notUsedStr = notUsedConfusingTypeNames
370- . map ( ( id ) => `\n- ${ id } ` )
371- . join ( '' )
372- this . warn ( `${ chunk . fileName } contains unused identifier names${ notUsedStr } ` )
373- process . exitCode = 1
368+
369+ if ( ! isInternalEntry ) {
370+ const notUsedConfusingTypeNames = ignoreConfusingTypeNames . filter (
371+ ( id ) => ! identifiers . includes ( id ) ,
372+ )
373+ // Validate that `identifierReplacements` is not outdated if there's no match
374+ if ( notUsedConfusingTypeNames . length ) {
375+ const notUsedStr = notUsedConfusingTypeNames
376+ . map ( ( id ) => `\n- ${ id } ` )
377+ . join ( '' )
378+ this . warn (
379+ `${ chunk . fileName } contains unused identifier names${ notUsedStr } ` ,
380+ )
381+ process . exitCode = 1
382+ }
374383 }
375384}
376385
0 commit comments