@@ -453,36 +453,33 @@ export function createCompilerPlugin(
453453 async ( ) => {
454454 assert . ok ( fileEmitter , 'Invalid plugin execution order' ) ;
455455
456+ const request = pluginOptions . fileReplacements ?. [ args . path ] ?? args . path ;
457+
456458 // The filename is currently used as a cache key. Since the cache is memory only,
457459 // the options cannot change and do not need to be represented in the key. If the
458460 // cache is later stored to disk, then the options that affect transform output
459461 // would need to be added to the key as well as a check for any change of content.
460462 let contents = pluginOptions . sourceFileCache ?. typeScriptFileCache . get (
461- pathToFileURL ( args . path ) . href ,
463+ pathToFileURL ( request ) . href ,
462464 ) ;
463465
464466 if ( contents === undefined ) {
465- const typescriptResult = await fileEmitter (
466- pluginOptions . fileReplacements ?. [ args . path ] ?? args . path ,
467- ) ;
467+ const typescriptResult = await fileEmitter ( request ) ;
468468 if ( ! typescriptResult ) {
469469 // No TS result indicates the file is not part of the TypeScript program.
470470 // If allowJs is enabled and the file is JS then defer to the next load hook.
471- if ( compilerOptions . allowJs && / \. [ c m ] ? j s $ / . test ( args . path ) ) {
471+ if ( compilerOptions . allowJs && / \. [ c m ] ? j s $ / . test ( request ) ) {
472472 return undefined ;
473473 }
474474
475475 // Otherwise return an error
476476 return {
477477 errors : [
478- {
479- text : `File '${ args . path } ' is missing from the TypeScript compilation.` ,
480- notes : [
481- {
482- text : `Ensure the file is part of the TypeScript program via the 'files' or 'include' property.` ,
483- } ,
484- ] ,
485- } ,
478+ createMissingFileError (
479+ request ,
480+ args . path ,
481+ build . initialOptions . absWorkingDir ?? '' ,
482+ ) ,
486483 ] ,
487484 } ;
488485 }
@@ -494,13 +491,13 @@ export function createCompilerPlugin(
494491 // would need to be added to the key as well.
495492 contents = babelDataCache . get ( data ) ;
496493 if ( contents === undefined ) {
497- const transformedData = await transformWithBabel ( args . path , data , pluginOptions ) ;
494+ const transformedData = await transformWithBabel ( request , data , pluginOptions ) ;
498495 contents = Buffer . from ( transformedData , 'utf-8' ) ;
499496 babelDataCache . set ( data , contents ) ;
500497 }
501498
502499 pluginOptions . sourceFileCache ?. typeScriptFileCache . set (
503- pathToFileURL ( args . path ) . href ,
500+ pathToFileURL ( request ) . href ,
504501 contents ,
505502 ) ;
506503 }
@@ -687,3 +684,22 @@ function findAffectedFiles(
687684
688685 return affectedFiles ;
689686}
687+
688+ function createMissingFileError ( request : string , original : string , root : string ) : PartialMessage {
689+ const error = {
690+ text : `File '${ path . relative ( root , request ) } ' is missing from the TypeScript compilation.` ,
691+ notes : [
692+ {
693+ text : `Ensure the file is part of the TypeScript program via the 'files' or 'include' property.` ,
694+ } ,
695+ ] ,
696+ } ;
697+
698+ if ( request !== original ) {
699+ error . notes . push ( {
700+ text : `File is requested from a file replacement of '${ path . relative ( root , original ) } '.` ,
701+ } ) ;
702+ }
703+
704+ return error ;
705+ }
0 commit comments