Skip to content

Commit 441621d

Browse files
fix: keep resolved root dir paths as is
1 parent 592e243 commit 441621d

File tree

6 files changed

+35
-2
lines changed

6 files changed

+35
-2
lines changed

src/resolver.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { execFile } from "node:child_process";
22
import process from "node:process";
3+
import path from "node:path";
34
import { fileURLToPath } from "node:url";
45
import { execAsync } from "./utils.js";
56

@@ -182,7 +183,12 @@ export async function resolveViteSpecifier(
182183
cache.set(resolved.id, resolved);
183184

184185
// Vite can load this
185-
if (resolved.loader === null) return resolved.id;
186+
if (
187+
resolved.loader === null ||
188+
!path.relative(root, resolved.id).startsWith(".")
189+
) {
190+
return resolved.id;
191+
}
186192

187193
// We must load it
188194
return toDenoSpecifier(resolved.loader, id, resolved.id);

tests/fixture/deno.lock

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

tests/fixture/mapped/foo.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// will be transformed by a plugin
2+
export const value = "it doesn't work";

tests/fixture/resolveInRootDir.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { value } from "mapped/foo.ts";
2+
3+
console.log(value);

tests/fixture/vite.config.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
import { defineConfig } from "vite";
22
import deno from "../../src/index";
3+
import path from "node:path";
34

45
export default defineConfig({
5-
plugins: [deno()],
6+
plugins: [deno(), {
7+
name: "mapped-transform",
8+
// @ts-ignore not sure
9+
transform(code, id) {
10+
if (id.startsWith("\0")) return;
11+
if (!id.includes("mapped") || path.basename(id) !== "foo.ts") return;
12+
13+
return code.replace("it doesn't work", "it works");
14+
},
15+
}],
616
build: {
717
lib: {
818
formats: ["es"],
@@ -17,6 +27,7 @@ export default defineConfig({
1727
inlineNpm: "inlineNpm.ts",
1828
inlineJsr: "inlineJsr.ts",
1929
inlineHttp: "inlineHttp.ts",
30+
resolveInRootDir: "resolveInRootDir.ts",
2031
},
2132
},
2233
},

tests/plugin.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,9 @@ describe("Deno plugin", () => {
6161
await runTest(`inlineHttp.js`);
6262
});
6363
});
64+
65+
// https://github.com/denoland/deno-vite-plugin/issues/42
66+
it("resolve to file in root dir", async () => {
67+
await runTest(`resolveInRootDir.js`);
68+
});
6469
});

0 commit comments

Comments
 (0)