fix(vite): improve commonjs handling (#3336)

Fixes https://github.com/denoland/fresh/issues/3323
This commit is contained in:
Marvin Hagemeister
2025-09-04 12:59:13 +02:00
committed by GitHub
parent b94aab2a1a
commit 4138b8ca66
17 changed files with 1096 additions and 218 deletions
+34
View File
@@ -0,0 +1,34 @@
import type { Plugin } from "vite";
import * as path from "@std/path";
const SHIMS: Record<string, string> = {
"object.entries": path.join(
import.meta.dirname!,
"shims",
"object.entries",
"index.ts",
),
"supports-color": path.join(
import.meta.dirname!,
"shims",
"supports-color",
"index.ts",
),
};
export function shims(): Plugin {
return {
name: "fresh:shims",
resolveId: {
filter: {
id: /(object\.entries|supports-color)/,
},
handler(id) {
const resolved = SHIMS[id];
if (resolved !== undefined) {
return resolved;
}
},
},
};
}