6
6
* found in the LICENSE file at https://angular.io/license
7
7
*/
8
8
9
- import { join } from 'node:path' ;
9
+ import { join , relative } from 'node:path' ;
10
+ import { pathToFileURL } from 'node:url' ;
10
11
import { workerData } from 'node:worker_threads' ;
11
12
import { fileURLToPath } from 'url' ;
12
13
import { JavaScriptTransformer } from '../../tools/esbuild/javascript-transformer' ;
@@ -23,7 +24,7 @@ const { outputFiles, workspaceRoot } = workerData as {
23
24
24
25
const TRANSFORMED_FILES : Record < string , string > = { } ;
25
26
const 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 ;
27
28
28
29
const JAVASCRIPT_TRANSFORMER = new JavaScriptTransformer (
29
30
// Always enable JIT linking to support applications built with and without AOT.
@@ -44,7 +45,9 @@ export function resolve(
44
45
return {
45
46
format : 'module' ,
46
47
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 ,
48
51
} ;
49
52
}
50
53
}
@@ -60,8 +63,8 @@ export function resolve(
60
63
export async function load ( url : string , context : { format ?: string | null } , nextLoad : Function ) {
61
64
if ( isFileProtocol ( url ) ) {
62
65
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 ] ;
65
68
66
69
if ( source === undefined ) {
67
70
source = TRANSFORMED_FILES [ filePath ] = Buffer . from (
0 commit comments