fix: workaround vite treating npm: as built-ins (#3205)

Upstream fix: https://github.com/vitejs/vite/pull/20558
This commit is contained in:
Marvin Hagemeister
2025-08-08 00:22:54 +02:00
committed by GitHub
parent a084a2c536
commit 0664476e46
6 changed files with 143 additions and 39 deletions
@@ -0,0 +1,32 @@
import type { Plugin } from "vite";
import * as babel from "@babel/core";
import { cjsPlugin } from "./commonjs.ts";
import { npmWorkaround } from "./npm_workaround.ts";
export function patches(): Plugin {
return {
name: "fresh:patches",
applyToEnvironment() {
return true;
},
resolveId(id) {
if (id.startsWith("deno-npm:")) {
return id.slice("deno-".length);
}
},
transform(code, id) {
const res = babel.transformSync(code, {
filename: id,
babelrc: false,
plugins: [npmWorkaround, cjsPlugin],
});
if (res?.code) {
return {
code: res.code,
map: res.map,
};
}
},
};
}