11import { statSync } from "node:fs" ;
2- import { pathToFileURL } from "node:url" ;
32import { joinURL } from "ufo" ;
43import { isAbsolute , normalize } from "pathe" ;
54import { moduleResolve } from "import-meta-resolve" ;
65import { PackageJson , readPackageJSON } from "pkg-types" ;
7- import { fileURLToPath , normalizeid } from "./utils" ;
6+ import { fileURLToPath , pathToFileURL , normalizeid } from "./utils" ;
87import { BUILTIN_MODULES } from "./_utils" ;
98
109const DEFAULT_CONDITIONS_SET = new Set ( [ "node" , "import" ] ) ;
11- const DEFAULT_URL = pathToFileURL ( process . cwd ( ) ) ;
1210const DEFAULT_EXTENSIONS = [ ".mjs" , ".cjs" , ".js" , ".json" ] ;
1311const NOT_FOUND_ERRORS = new Set ( [
1412 "ERR_MODULE_NOT_FOUND" ,
@@ -66,7 +64,7 @@ function _resolve(id: string | URL, options: ResolveOptions = {}): string {
6664 try {
6765 const stat = statSync ( id ) ;
6866 if ( stat . isFile ( ) ) {
69- return pathToFileURL ( id ) . toString ( ) ;
67+ return pathToFileURL ( id ) ;
7068 }
7169 } catch ( error ) {
7270 if ( error . code !== "ENOENT" ) {
@@ -85,9 +83,9 @@ function _resolve(id: string | URL, options: ResolveOptions = {}): string {
8583 Array . isArray ( options . url ) ? options . url : [ options . url ]
8684 )
8785 . filter ( Boolean )
88- . map ( ( u ) => new URL ( normalizeid ( u . toString ( ) ) ) ) ;
86+ . map ( ( url ) => new URL ( normalizeid ( url ! . toString ( ) ) ) ) ;
8987 if ( _urls . length === 0 ) {
90- _urls . push ( DEFAULT_URL ) ;
88+ _urls . push ( new URL ( pathToFileURL ( process . cwd ( ) ) ) ) ;
9189 }
9290 const urls = [ ..._urls ] ;
9391 for ( const url of _urls ) {
@@ -140,8 +138,7 @@ function _resolve(id: string | URL, options: ResolveOptions = {}): string {
140138 throw error ;
141139 }
142140
143- // Normalize (TODO: simplify)
144- return pathToFileURL ( fileURLToPath ( resolved ) ) . toString ( ) ;
141+ return pathToFileURL ( resolved ) ;
145142}
146143
147144export function resolveSync ( id : string , options ?: ResolveOptions ) : string {
0 commit comments