Skip to content

Commit

Permalink
Respect import maps
Browse files Browse the repository at this point in the history
  • Loading branch information
PabloSzx committed Nov 26, 2021
1 parent a3d2d39 commit af75da4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/eleven-trees-nail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'bob-tsm': patch
---

Respect import maps
12 changes: 10 additions & 2 deletions packages/bob-tsm/src/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,16 @@ function check(fileurl: string): string | void {

const root = new URL('file:///' + process.cwd() + '/');
export const resolve: Resolve = async function (specifier, context, defaultResolve) {
// ignore "prefix:" and non-relative identifiers
if (/^\w+\:?/.test(specifier)) return defaultResolve(specifier, context, defaultResolve);
let defaultResolveResult: Awaited<ReturnType<Resolve>> | false = false;

try {
defaultResolveResult = await defaultResolve(specifier, context, defaultResolve);
} catch (err) {}

// ignore "prefix:", non-relative identifiers, and respect import maps
if (defaultResolveResult || /^\w+\:?/.test(specifier)) {
return defaultResolveResult || defaultResolve(specifier, context, defaultResolve);
}

let match: RegExpExecArray | null;
let idx: number, ext: Extension, path: string | void;
Expand Down

0 comments on commit af75da4

Please sign in to comment.