1
1
import { statSync } from "node:fs" ;
2
- import { pathToFileURL } from "node:url" ;
3
2
import { joinURL } from "ufo" ;
4
3
import { isAbsolute , normalize } from "pathe" ;
5
4
import { moduleResolve } from "import-meta-resolve" ;
6
5
import { PackageJson , readPackageJSON } from "pkg-types" ;
7
- import { fileURLToPath , normalizeid } from "./utils" ;
6
+ import { fileURLToPath , pathToFileURL , normalizeid } from "./utils" ;
8
7
import { BUILTIN_MODULES } from "./_utils" ;
9
8
10
9
const DEFAULT_CONDITIONS_SET = new Set ( [ "node" , "import" ] ) ;
11
- const DEFAULT_URL = pathToFileURL ( process . cwd ( ) ) ;
12
10
const DEFAULT_EXTENSIONS = [ ".mjs" , ".cjs" , ".js" , ".json" ] ;
13
11
const NOT_FOUND_ERRORS = new Set ( [
14
12
"ERR_MODULE_NOT_FOUND" ,
@@ -66,7 +64,7 @@ function _resolve(id: string | URL, options: ResolveOptions = {}): string {
66
64
try {
67
65
const stat = statSync ( id ) ;
68
66
if ( stat . isFile ( ) ) {
69
- return pathToFileURL ( id ) . toString ( ) ;
67
+ return pathToFileURL ( id ) ;
70
68
}
71
69
} catch ( error ) {
72
70
if ( error . code !== "ENOENT" ) {
@@ -85,9 +83,9 @@ function _resolve(id: string | URL, options: ResolveOptions = {}): string {
85
83
Array . isArray ( options . url ) ? options . url : [ options . url ]
86
84
)
87
85
. filter ( Boolean )
88
- . map ( ( u ) => new URL ( normalizeid ( u . toString ( ) ) ) ) ;
86
+ . map ( ( url ) => new URL ( normalizeid ( url ! . toString ( ) ) ) ) ;
89
87
if ( _urls . length === 0 ) {
90
- _urls . push ( DEFAULT_URL ) ;
88
+ _urls . push ( new URL ( pathToFileURL ( process . cwd ( ) ) ) ) ;
91
89
}
92
90
const urls = [ ..._urls ] ;
93
91
for ( const url of _urls ) {
@@ -140,8 +138,7 @@ function _resolve(id: string | URL, options: ResolveOptions = {}): string {
140
138
throw error ;
141
139
}
142
140
143
- // Normalize (TODO: simplify)
144
- return pathToFileURL ( fileURLToPath ( resolved ) ) . toString ( ) ;
141
+ return pathToFileURL ( resolved ) ;
145
142
}
146
143
147
144
export function resolveSync ( id : string , options ?: ResolveOptions ) : string {
0 commit comments