Skip to content

Commit 27c2910

Browse files
fix(vite): babel transform being applied for non-js files (denoland#3238)
1 parent 6dd250c commit 27c2910

File tree

6 files changed

+40
-4
lines changed

6 files changed

+40
-4
lines changed

deno.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { value } from "@marvinh-test/import-json";
2+
3+
export const handler = () => Response.json(value);

packages/plugin-vite/deno.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"@babel/core": "npm:@babel/core@^7.28.0",
2323
"@babel/preset-react": "npm:@babel/preset-react@^7.27.1",
2424
"@deno/loader": "jsr:@deno/loader@^0.3.2",
25+
"@marvinh-test/import-json": "jsr:@marvinh-test/import-json@^0.0.1",
2526
"@prefresh/vite": "npm:@prefresh/vite@^2.4.8",
2627
"@tailwindcss/vite": "npm:@tailwindcss/vite@^4.1.12",
2728
"@types/babel__core": "npm:@types/babel__core@^7.20.5",

packages/plugin-vite/src/plugins/deno.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -323,10 +323,7 @@ function babelTransform(
323323
isDev: boolean;
324324
},
325325
) {
326-
if (
327-
!isJsMediaType(options.media) &&
328-
!/^https?:\/\//.test(options.id)
329-
) {
326+
if (!isJsMediaType(options.media)) {
330327
return null;
331328
}
332329

packages/plugin-vite/tests/build_test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,3 +340,24 @@ Deno.test({
340340
sanitizeOps: false,
341341
sanitizeResources: false,
342342
});
343+
344+
Deno.test({
345+
name: "vite build - import json from jsr dependency",
346+
fn: async () => {
347+
await using res = await buildVite(DEMO_DIR);
348+
349+
await withChildProcessServer(
350+
{
351+
cwd: res.tmp,
352+
args: ["serve", "-A", "--port", "0", "_fresh/server.js"],
353+
},
354+
async (address) => {
355+
const res = await fetch(`${address}/tests/dep_json`);
356+
const json = await res.json();
357+
expect(json.name).toEqual("@marvinh-test/import-json");
358+
},
359+
);
360+
},
361+
sanitizeOps: false,
362+
sanitizeResources: false,
363+
});

packages/plugin-vite/tests/dev_server_test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,3 +238,16 @@ Deno.test({
238238
sanitizeResources: false,
239239
sanitizeOps: false,
240240
});
241+
242+
Deno.test({
243+
name: "vite dev - json from jsr dependency",
244+
fn: async () => {
245+
await withDevServer(DEMO_DIR, async (address) => {
246+
const res = await fetch(`${address}/tests/dep_json`);
247+
const json = await res.json();
248+
expect(json.name).toEqual("@marvinh-test/import-json");
249+
});
250+
},
251+
sanitizeResources: false,
252+
sanitizeOps: false,
253+
});

0 commit comments

Comments
 (0)