Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: mapped directories in import map not resolved #25

Merged
merged 2 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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