Skip to content

Commit 982a7a9

Browse files
committedFeb 21, 2024·
refactor(resolver): use pathToFileURL from mlly
1 parent cdcbcb7 commit 982a7a9

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed
 

‎src/resolve.ts

+5-8
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
import { statSync } from "node:fs";
2-
import { pathToFileURL } from "node:url";
32
import { joinURL } from "ufo";
43
import { isAbsolute, normalize } from "pathe";
54
import { moduleResolve } from "import-meta-resolve";
65
import { PackageJson, readPackageJSON } from "pkg-types";
7-
import { fileURLToPath, normalizeid } from "./utils";
6+
import { fileURLToPath, pathToFileURL, normalizeid } from "./utils";
87
import { BUILTIN_MODULES } from "./_utils";
98

109
const DEFAULT_CONDITIONS_SET = new Set(["node", "import"]);
11-
const DEFAULT_URL = pathToFileURL(process.cwd());
1210
const DEFAULT_EXTENSIONS = [".mjs", ".cjs", ".js", ".json"];
1311
const 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

147144
export function resolveSync(id: string, options?: ResolveOptions): string {

0 commit comments

Comments
 (0)
Please sign in to comment.