@@ -18,10 +18,9 @@ import type {
18
18
import assert from 'node:assert' ;
19
19
import { realpath } from 'node:fs/promises' ;
20
20
import * as path from 'node:path' ;
21
- import { pathToFileURL } from 'node:url' ;
22
21
import { maxWorkers } from '../../../utils/environment-options' ;
23
22
import { JavaScriptTransformer } from '../javascript-transformer' ;
24
- import { LoadResultCache } from '../load-result-cache' ;
23
+ import { LoadResultCache , createCachedLoad } from '../load-result-cache' ;
25
24
import { logCumulativeDurations , profileAsync , resetCumulativeDurations } from '../profiling' ;
26
25
import { BundleStylesheetOptions } from '../stylesheets/bundle-options' ;
27
26
import { AngularHostOptions } from './angular-host' ;
@@ -280,7 +279,7 @@ export function createCompilerPlugin(
280
279
try {
281
280
await profileAsync ( 'NG_EMIT_TS' , async ( ) => {
282
281
for ( const { filename, contents } of await compilation . emitAffectedFiles ( ) ) {
283
- typeScriptFileCache . set ( pathToFileURL ( filename ) . href , contents ) ;
282
+ typeScriptFileCache . set ( path . normalize ( filename ) , contents ) ;
284
283
}
285
284
} ) ;
286
285
} catch ( error ) {
@@ -323,7 +322,9 @@ export function createCompilerPlugin(
323
322
} ) ;
324
323
325
324
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
+ ) ;
327
328
328
329
// Skip TS load attempt if JS TypeScript compilation not enabled and file is JS
329
330
if ( shouldTsIgnoreJs && / \. [ c m ] ? j s $ / . test ( request ) ) {
@@ -334,7 +335,7 @@ export function createCompilerPlugin(
334
335
// the options cannot change and do not need to be represented in the key. If the
335
336
// cache is later stored to disk, then the options that affect transform output
336
337
// 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 ) ;
338
339
339
340
if ( contents === undefined ) {
340
341
// If the Angular compilation had errors the file may not have been emitted.
@@ -364,7 +365,7 @@ export function createCompilerPlugin(
364
365
) ;
365
366
366
367
// Store as the returned Uint8Array to allow caching the fully transformed code
367
- typeScriptFileCache . set ( pathToFileURL ( request ) . href , contents ) ;
368
+ typeScriptFileCache . set ( request , contents ) ;
368
369
}
369
370
370
371
return {
@@ -373,27 +374,25 @@ export function createCompilerPlugin(
373
374
} ;
374
375
} ) ;
375
376
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
+ ) ;
389
387
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
+ } ) ,
397
396
) ;
398
397
399
398
// Setup bundling of component templates and stylesheets when in JIT mode
@@ -531,18 +530,20 @@ function bundleWebWorker(
531
530
}
532
531
533
532
function createMissingFileError ( request : string , original : string , root : string ) : PartialMessage {
533
+ const relativeRequest = path . relative ( root , request ) ;
534
534
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.` ,
536
536
notes : [
537
537
{
538
538
text : `Ensure the file is part of the TypeScript program via the 'files' or 'include' property.` ,
539
539
} ,
540
540
] ,
541
541
} ;
542
542
543
- if ( request !== original ) {
543
+ const relativeOriginal = path . relative ( root , original ) ;
544
+ if ( relativeRequest !== relativeOriginal ) {
544
545
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 } '.` ,
546
547
} ) ;
547
548
}
548
549
0 commit comments