Skip to content

Commit

Permalink
fix: mapped directories in import map not resolved (#25)
Browse files Browse the repository at this point in the history
* fix: mapped directories in import map not resolved

* chore: simplify check
  • Loading branch information
marvinhagemeister authored Nov 27, 2024
1 parent 8957246 commit 1a986e8
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/resolver.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { exec } from "node:child_process";
import process from "node:process";
import { fileURLToPath } from "node:url";
import { execAsync } from "./utils.js";

export type DenoMediaType =
Expand Down Expand Up @@ -149,8 +150,8 @@ export async function resolveViteSpecifier(

// Check if we need to continue resolution
id = found.code.specifier;
if (!id.startsWith("http://") && !id.startsWith("https://")) {
return found.code.specifier;
if (id.startsWith("file://")) {
return fileURLToPath(id);
}
}

Expand Down
3 changes: 3 additions & 0 deletions tests/fixture/alias-mapped.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { value } from "mapped/main.ts";

console.log(value);
3 changes: 2 additions & 1 deletion tests/fixture/deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"@std/path": "jsr:@std/path@^1.0.6",
"import-map-alias": "./alias-target.ts",
"preact": "npm:preact@^10.24.0",
"preact-http": "https://esm.sh/preact"
"preact-http": "https://esm.sh/preact",
"mapped/": "mapped/"
}
}
1 change: 1 addition & 0 deletions tests/fixture/mapped/dep.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const dep = "it works";
3 changes: 3 additions & 0 deletions tests/fixture/mapped/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { dep } from "./dep.ts";

export const value = dep;
1 change: 1 addition & 0 deletions tests/fixture/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export default defineConfig({
formats: ["es"],
entry: {
importMapAlias: "alias.ts",
importMapAliasMapped: "alias-mapped.ts",
importMapNpm: "npm.ts",
importMapJsr: "jsr.ts",
importMapHttp: "http.ts",
Expand Down
4 changes: 4 additions & 0 deletions tests/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ describe("Deno plugin", () => {
await runTest(`importMapAlias.js`);
});

it("resolves alias mapped", async () => {
await runTest(`importMapAliasMapped.js`);
});

it("resolves npm:", async () => {
await runTest(`importMapNpm.js`);
});
Expand Down

0 comments on commit 1a986e8

Please sign in to comment.