@@ -573,8 +573,14 @@ The resolve hook returns the resolved file URL and module format for a
573
573
given module specifier and parent file URL:
574
574
575
575
` ` ` js
576
- const baseURL = new URL (` ${ process .cwd ()} /` , ' file://' );
577
-
576
+ import { URL , pathToFileURL } from ' url' ;
577
+ const baseURL = pathToFileURL (process .cwd ()).href ;
578
+
579
+ /**
580
+ * @param {string} specifier
581
+ * @param {string} parentModuleURL
582
+ * @param {function} defaultResolver
583
+ */
578
584
export async function resolve (specifier ,
579
585
parentModuleURL = baseURL ,
580
586
defaultResolver ) {
@@ -612,13 +618,21 @@ be written:
612
618
import path from ' path' ;
613
619
import process from ' process' ;
614
620
import Module from ' module' ;
621
+ import { URL , pathToFileURL } from ' url' ;
615
622
616
623
const builtins = Module .builtinModules ;
617
624
const JS_EXTENSIONS = new Set ([' .js' , ' .mjs' ]);
618
625
619
- const baseURL = new URL ( ` ${ process .cwd ()} / ` , ' file:// ' ) ;
626
+ const baseURL = pathToFileURL ( process .cwd ()). href ;
620
627
621
- export function resolve (specifier , parentModuleURL = baseURL , defaultResolve ) {
628
+ /**
629
+ * @param {string} specifier
630
+ * @param {string} parentModuleURL
631
+ * @param {function} defaultResolver
632
+ */
633
+ export async function resolve (specifier ,
634
+ parentModuleURL = baseURL ,
635
+ defaultResolver ) {
622
636
if (builtins .includes (specifier)) {
623
637
return {
624
638
url: specifier,
@@ -627,7 +641,7 @@ export function resolve(specifier, parentModuleURL = baseURL, defaultResolve) {
627
641
}
628
642
if (/ ^ \. {0,2} [/] / .test (specifier) !== true && ! specifier .startsWith (' file:' )) {
629
643
// For node_modules support:
630
- // return defaultResolve (specifier, parentModuleURL);
644
+ // return defaultResolver (specifier, parentModuleURL);
631
645
throw new Error (
632
646
` imports must begin with '/', './', or '../'; '${ specifier} ' does not` );
633
647
}
0 commit comments