## Summary Reverts two commits that broke CJS package handling in dev mode: - Reverts #3793 (CJS detection regex fix) - Reverts #3767 (removal of Babel CJS→ESM transform) The simplified CJS shim introduced in #3767 has two fundamental issues: 1. **Detection**: the heuristic (`code.includes("export ")`) is fooled by comments containing "export" 2. **Named exports**: the shim only provides `export default module.exports`, so `import { trace } from "@opentelemetry/api"` returns `undefined` (#3797) The Babel-based transform handled both correctly. Bringing it back until we can replace it with a proper solution using `deno_ast`'s CJS parser.
27 lines
974 B
TypeScript
27 lines
974 B
TypeScript
import { expect } from "@std/expect";
|
|
import { fresh } from "../src/mod.ts";
|
|
import type { Plugin } from "vite";
|
|
|
|
Deno.test("fresh plugin - sets server.watch.ignored patterns", () => {
|
|
const plugins = fresh() as Plugin[];
|
|
const freshPlugin = plugins.find((p) => p.name === "fresh");
|
|
expect(freshPlugin).toBeDefined();
|
|
|
|
// Call the config hook as Vite would during dev
|
|
// deno-lint-ignore no-explicit-any
|
|
const configFn = freshPlugin!.config as any;
|
|
const result = configFn({}, { command: "serve" });
|
|
|
|
const ignored = result?.server?.watch?.ignored;
|
|
expect(ignored).toBeDefined();
|
|
expect(Array.isArray(ignored)).toBe(true);
|
|
|
|
// Should ignore temp files, editor swap files, and Vite timestamp files
|
|
expect(ignored).toContain("**/*.tmp.*");
|
|
expect(ignored).toContain("**/*.timestamp-*");
|
|
expect(ignored).toContain("**/*.swp");
|
|
expect(ignored).toContain("**/*.swo");
|
|
expect(ignored).toContain("**/*~");
|
|
expect(ignored).toContain("**/.#*");
|
|
});
|