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

Commit

Permalink
fix: improve import map error (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
privatenumber committed Nov 30, 2022
1 parent 22d5576 commit 66c0edd
Show file tree
Hide file tree
Showing 7 changed files with 171 additions and 66 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"eslint": "^8.24.0",
"execa": "^6.1.0",
"get-node": "^13.2.0",
"manten": "^0.3.0",
"manten": "^0.5.0",
"pkgroll": "^1.4.0",
"semver": "^7.3.7",
"source-map-support": "^0.5.21",
Expand Down
120 changes: 62 additions & 58 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 13 additions & 4 deletions src/loaders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,21 @@ export const resolve: resolve = async function (
error instanceof Error
&& !recursiveCall
) {
if ((error as any).code === 'ERR_UNSUPPORTED_DIR_IMPORT') {
return await tryDirectory(specifier, context, defaultResolve);
const { code } = error as any;
if (code === 'ERR_UNSUPPORTED_DIR_IMPORT') {
try {
return await tryDirectory(specifier, context, defaultResolve);
} catch (error_) {
if ((error_ as any).code !== 'ERR_PACKAGE_IMPORT_NOT_DEFINED') {
throw error_;
}
}
}

if ((error as any).code === 'ERR_MODULE_NOT_FOUND') {
return await tryExtensions(specifier, context, defaultResolve);
if (code === 'ERR_MODULE_NOT_FOUND') {
try {
return await tryExtensions(specifier, context, defaultResolve);
} catch {}
}
}

Expand Down
13 changes: 12 additions & 1 deletion tests/fixtures/package-module/package.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
{
"type": "module"
"type": "module",
"imports": {
"#directory": "./lib/esm-ext-js",

"#directory-star": "./lib/esm-ext-js",
"#directory-star/*": "./lib/esm-ext-js/*",

"#file-star": "./lib/ts-ext-ts/index",
"#file-star*": "./lib/ts-ext-ts/index*",

"#non-existent": "./lib/non-existent"
}
}
4 changes: 4 additions & 0 deletions tests/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ const nodeVersions = [
import('./specs/data'),
node,
);
runTestSuite(
import('./specs/import-map'),
node,
);
});

runTestSuite(
Expand Down

0 comments on commit 66c0edd

Please sign in to comment.