Skip to content

Commit 9e38594

Browse files
committed
fix: always ignore errors in try mode
1 parent 04b7043 commit 9e38594

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed

src/resolve.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,6 @@ const DEFAULT_CONDITIONS_SET = /* #__PURE__ */ new Set(["node", "import"]);
88

99
const isWindows = /* #__PURE__ */ (() => process.platform === "win32")();
1010

11-
const NOT_FOUND_ERRORS = /* #__PURE__ */ new Set([
12-
"ERR_MODULE_NOT_FOUND",
13-
"ERR_UNSUPPORTED_DIR_IMPORT",
14-
"MODULE_NOT_FOUND",
15-
"ERR_PACKAGE_PATH_NOT_EXPORTED",
16-
"ERR_PACKAGE_IMPORT_NOT_DEFINED",
17-
]);
18-
1911
const globalCache = /* #__PURE__ */ (() =>
2012
// eslint-disable-next-line unicorn/no-unreadable-iife
2113
((globalThis as any)["__EXSOLVE_CACHE__"] ||= new Map()))() as Map<
@@ -268,10 +260,8 @@ function _tryModuleResolve(
268260
): URL | undefined {
269261
try {
270262
return moduleResolve(specifier, base, conditions);
271-
} catch (error: any) {
272-
if (!NOT_FOUND_ERRORS.has(error?.code)) {
273-
throw error;
274-
}
263+
} catch {
264+
// ignore
275265
}
276266
}
277267

test/resolve.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,11 @@ describe("resolveModulePath", () => {
177177
expect(resolveModulePath("fs", { try: true })).toBeUndefined();
178178
expect(resolveModulePath("node:fs", { try: true })).toBeUndefined();
179179
});
180+
181+
it("not throws error for invalid input when try", () => {
182+
expect(() => resolveModulePath(".foo", { try: true })).not.toThrow();
183+
expect(resolveModulePath(".foo", { try: true })).toBeUndefined();
184+
});
180185
});
181186

182187
describe.runIf(isWindows)("windows", () => {

0 commit comments

Comments
 (0)