Skip to content
This repository was archived by the owner on Oct 18, 2023. It is now read-only.

Commit 66c0edd

Browse files
fix: improve import map error (#52)
1 parent 22d5576 commit 66c0edd

File tree

7 files changed

+171
-66
lines changed

7 files changed

+171
-66
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"eslint": "^8.24.0",
4545
"execa": "^6.1.0",
4646
"get-node": "^13.2.0",
47-
"manten": "^0.3.0",
47+
"manten": "^0.5.0",
4848
"pkgroll": "^1.4.0",
4949
"semver": "^7.3.7",
5050
"source-map-support": "^0.5.21",

pnpm-lock.yaml

Lines changed: 62 additions & 58 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/loaders.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,21 @@ export const resolve: resolve = async function (
163163
error instanceof Error
164164
&& !recursiveCall
165165
) {
166-
if ((error as any).code === 'ERR_UNSUPPORTED_DIR_IMPORT') {
167-
return await tryDirectory(specifier, context, defaultResolve);
166+
const { code } = error as any;
167+
if (code === 'ERR_UNSUPPORTED_DIR_IMPORT') {
168+
try {
169+
return await tryDirectory(specifier, context, defaultResolve);
170+
} catch (error_) {
171+
if ((error_ as any).code !== 'ERR_PACKAGE_IMPORT_NOT_DEFINED') {
172+
throw error_;
173+
}
174+
}
168175
}
169176

170-
if ((error as any).code === 'ERR_MODULE_NOT_FOUND') {
171-
return await tryExtensions(specifier, context, defaultResolve);
177+
if (code === 'ERR_MODULE_NOT_FOUND') {
178+
try {
179+
return await tryExtensions(specifier, context, defaultResolve);
180+
} catch {}
172181
}
173182
}
174183

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
11
{
2-
"type": "module"
2+
"type": "module",
3+
"imports": {
4+
"#directory": "./lib/esm-ext-js",
5+
6+
"#directory-star": "./lib/esm-ext-js",
7+
"#directory-star/*": "./lib/esm-ext-js/*",
8+
9+
"#file-star": "./lib/ts-ext-ts/index",
10+
"#file-star*": "./lib/ts-ext-ts/index*",
11+
12+
"#non-existent": "./lib/non-existent"
13+
}
314
}

tests/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ const nodeVersions = [
4242
import('./specs/data'),
4343
node,
4444
);
45+
runTestSuite(
46+
import('./specs/import-map'),
47+
node,
48+
);
4549
});
4650

4751
runTestSuite(

0 commit comments

Comments
 (0)