66 * found in the LICENSE file at https://angular.io/license
77 */
88
9- import { join } from 'node:path' ;
9+ import { join , relative } from 'node:path' ;
10+ import { pathToFileURL } from 'node:url' ;
1011import { workerData } from 'node:worker_threads' ;
1112import { fileURLToPath } from 'url' ;
1213import { JavaScriptTransformer } from '../../tools/esbuild/javascript-transformer' ;
@@ -23,7 +24,7 @@ const { outputFiles, workspaceRoot } = workerData as {
2324
2425const TRANSFORMED_FILES : Record < string , string > = { } ;
2526const CHUNKS_REGEXP = / f i l e : \/ \/ \/ ( m a i n \. s e r v e r | c h u n k - \w + ) \. m j s / ;
26- const WORKSPACE_ROOT_FILE = new URL ( join ( workspaceRoot , 'index.mjs' ) , 'file:' ) . href ;
27+ const WORKSPACE_ROOT_FILE = pathToFileURL ( join ( workspaceRoot , 'index.mjs' ) ) . href ;
2728
2829const JAVASCRIPT_TRANSFORMER = new JavaScriptTransformer (
2930 // Always enable JIT linking to support applications built with and without AOT.
@@ -44,7 +45,9 @@ export function resolve(
4445 return {
4546 format : 'module' ,
4647 shortCircuit : true ,
47- url : new URL ( normalizedSpecifier , 'file:' ) . href ,
48+ // File URLs need to absolute. In Windows these also need to include the drive.
49+ // The `/` will be resolved to the drive letter.
50+ url : pathToFileURL ( '/' + normalizedSpecifier ) . href ,
4851 } ;
4952 }
5053 }
@@ -60,8 +63,8 @@ export function resolve(
6063export async function load ( url : string , context : { format ?: string | null } , nextLoad : Function ) {
6164 if ( isFileProtocol ( url ) ) {
6265 const filePath = fileURLToPath ( url ) ;
63- let source =
64- outputFiles [ filePath . slice ( 1 ) ] /* Remove leading slash */ ?? TRANSFORMED_FILES [ filePath ] ;
66+ // Remove '/' or drive letter for Windows that was added in the above 'resolve'.
67+ let source = outputFiles [ relative ( '/' , filePath ) ] ?? TRANSFORMED_FILES [ filePath ] ;
6568
6669 if ( source === undefined ) {
6770 source = TRANSFORMED_FILES [ filePath ] = Buffer . from (
0 commit comments