@@ -18,10 +18,9 @@ import type {
1818import assert from 'node:assert' ;
1919import { realpath } from 'node:fs/promises' ;
2020import * as path from 'node:path' ;
21- import { pathToFileURL } from 'node:url' ;
2221import { maxWorkers } from '../../../utils/environment-options' ;
2322import { JavaScriptTransformer } from '../javascript-transformer' ;
24- import { LoadResultCache } from '../load-result-cache' ;
23+ import { LoadResultCache , createCachedLoad } from '../load-result-cache' ;
2524import { logCumulativeDurations , profileAsync , resetCumulativeDurations } from '../profiling' ;
2625import { BundleStylesheetOptions } from '../stylesheets/bundle-options' ;
2726import { AngularHostOptions } from './angular-host' ;
@@ -280,7 +279,7 @@ export function createCompilerPlugin(
280279 try {
281280 await profileAsync ( 'NG_EMIT_TS' , async ( ) => {
282281 for ( const { filename, contents } of await compilation . emitAffectedFiles ( ) ) {
283- typeScriptFileCache . set ( pathToFileURL ( filename ) . href , contents ) ;
282+ typeScriptFileCache . set ( path . normalize ( filename ) , contents ) ;
284283 }
285284 } ) ;
286285 } catch ( error ) {
@@ -323,7 +322,9 @@ export function createCompilerPlugin(
323322 } ) ;
324323
325324 build . onLoad ( { filter : / \. [ c m ] ? [ j t ] s x ? $ / } , async ( args ) => {
326- const request = pluginOptions . fileReplacements ?. [ args . path ] ?? args . path ;
325+ const request = path . normalize (
326+ pluginOptions . fileReplacements ?. [ path . normalize ( args . path ) ] ?? args . path ,
327+ ) ;
327328
328329 // Skip TS load attempt if JS TypeScript compilation not enabled and file is JS
329330 if ( shouldTsIgnoreJs && / \. [ c m ] ? j s $ / . test ( request ) ) {
@@ -334,7 +335,7 @@ export function createCompilerPlugin(
334335 // the options cannot change and do not need to be represented in the key. If the
335336 // cache is later stored to disk, then the options that affect transform output
336337 // would need to be added to the key as well as a check for any change of content.
337- let contents = typeScriptFileCache . get ( pathToFileURL ( request ) . href ) ;
338+ let contents = typeScriptFileCache . get ( request ) ;
338339
339340 if ( contents === undefined ) {
340341 // If the Angular compilation had errors the file may not have been emitted.
@@ -364,7 +365,7 @@ export function createCompilerPlugin(
364365 ) ;
365366
366367 // Store as the returned Uint8Array to allow caching the fully transformed code
367- typeScriptFileCache . set ( pathToFileURL ( request ) . href , contents ) ;
368+ typeScriptFileCache . set ( request , contents ) ;
368369 }
369370
370371 return {
@@ -373,27 +374,25 @@ export function createCompilerPlugin(
373374 } ;
374375 } ) ;
375376
376- build . onLoad ( { filter : / \. [ c m ] ? j s $ / } , ( args ) =>
377- profileAsync (
378- 'NG_EMIT_JS*' ,
379- async ( ) => {
380- // The filename is currently used as a cache key. Since the cache is memory only,
381- // the options cannot change and do not need to be represented in the key. If the
382- // cache is later stored to disk, then the options that affect transform output
383- // would need to be added to the key as well as a check for any change of content.
384- let contents = pluginOptions . sourceFileCache ?. babelFileCache . get ( args . path ) ;
385- if ( contents === undefined ) {
386- contents = await javascriptTransformer . transformFile ( args . path , pluginOptions . jit ) ;
387- pluginOptions . sourceFileCache ?. babelFileCache . set ( args . path , contents ) ;
388- }
377+ build . onLoad (
378+ { filter : / \. [ c m ] ? j s $ / } ,
379+ createCachedLoad ( pluginOptions . loadResultCache , async ( args ) => {
380+ return profileAsync (
381+ 'NG_EMIT_JS*' ,
382+ async ( ) => {
383+ const contents = await javascriptTransformer . transformFile (
384+ args . path ,
385+ pluginOptions . jit ,
386+ ) ;
389387
390- return {
391- contents,
392- loader : 'js' ,
393- } ;
394- } ,
395- true ,
396- ) ,
388+ return {
389+ contents,
390+ loader : 'js' ,
391+ } ;
392+ } ,
393+ true ,
394+ ) ;
395+ } ) ,
397396 ) ;
398397
399398 // Setup bundling of component templates and stylesheets when in JIT mode
@@ -531,18 +530,20 @@ function bundleWebWorker(
531530}
532531
533532function createMissingFileError ( request : string , original : string , root : string ) : PartialMessage {
533+ const relativeRequest = path . relative ( root , request ) ;
534534 const error = {
535- text : `File '${ path . relative ( root , request ) } ' is missing from the TypeScript compilation.` ,
535+ text : `File '${ relativeRequest } ' is missing from the TypeScript compilation.` ,
536536 notes : [
537537 {
538538 text : `Ensure the file is part of the TypeScript program via the 'files' or 'include' property.` ,
539539 } ,
540540 ] ,
541541 } ;
542542
543- if ( request !== original ) {
543+ const relativeOriginal = path . relative ( root , original ) ;
544+ if ( relativeRequest !== relativeOriginal ) {
544545 error . notes . push ( {
545- text : `File is requested from a file replacement of '${ path . relative ( root , original ) } '.` ,
546+ text : `File is requested from a file replacement of '${ relativeOriginal } '.` ,
546547 } ) ;
547548 }
548549
0 commit comments