refactor: remove CJS and env var Babel transforms, let Vite handle natively (#3767)

## Summary

- **Replace Babel env var transforms with Vite's native `define`** —
`process.env.FRESH_PUBLIC_*` and `import.meta.env.FRESH_PUBLIC_*` now
use Vite's built-in `define` config. `Deno.env.get()` calls use a
lightweight regex-based transform (~10 lines vs 78-line Babel plugin).

- **Remove the 960-line CJS→ESM Babel transform** — Instead of
transforming CJS to ESM via Babel, let Vite handle CJS packages
natively:
- **Build mode**: Rollup's `@rollup/plugin-commonjs` handles CJS (always
has, but was bypassed by `deno.ts` loading through `@deno/loader`)
- **Dev mode**: A ~30-line CJS shim wraps `node_modules` CJS files with
`module`/`exports`/`require` so Vite's SSR module runner can evaluate
them
- `deno.ts` no longer attaches `meta.deno` to file:// resolved paths —
Vite loads them from disk directly

- **Remove `noDiscovery: true`** — Vite's dependency optimizer can now
pre-bundle CJS packages for the client

- **Fix React compat aliasing** — Apply `resolve.alias` (react →
preact/compat) in `deno.ts` before `@deno/loader` resolution, so the
alias works even when packages are non-external in SSR

Net: **~2,050 lines deleted**, ~150 lines added.

Fixes #3619, fixes #3653, fixes #3505, fixes #3478, fixes #3449.
This commit is contained in:
Bartek Iwańczuk
2026-04-25 14:40:11 +02:00
committed by GitHub
parent 13ed01fb40
commit b9a314ba1d
15 changed files with 190 additions and 2051 deletions
@@ -1 +0,0 @@
exports.value = "ok";
@@ -0,0 +1 @@
export const value = "ok";
@@ -1,8 +0,0 @@
"use strict";
// deno-lint-ignore no-var
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const assert_1 = __importDefault(require("assert"));
(0, assert_1.default)(true);
@@ -0,0 +1,2 @@
import assert from "node:assert";
assert(true);