Revert "feat: Add experimental vite plugin (#3184)" (#3185)

This reverts commit a1571b76ed.

It broke fresh.deno.dev :S
This commit is contained in:
Marvin Hagemeister
2025-08-04 18:54:04 +02:00
committed by GitHub
parent a1571b76ed
commit 2f76a0a2aa
54 changed files with 742 additions and 2181 deletions
-71
View File
@@ -1,71 +0,0 @@
import { expect } from "@std/expect";
import {
waitForText,
withBrowser,
withChildProcessServer,
} from "../../tests/test_utils.tsx";
import { buildVite } from "./test_utils.ts";
Deno.test({
name: "vite build - launches",
fn: async () => {
await using res = await buildVite();
await withChildProcessServer(
res.tmp,
["serve", "-A", "--port", "0", "_fresh/server.js"],
async (address) => {
const res = await fetch(address);
const text = await res.text();
expect(text).toEqual("it works");
},
);
},
sanitizeOps: false,
sanitizeResources: false,
});
Deno.test({
name: "vite build - serves static files",
fn: async () => {
await using res = await buildVite();
await withChildProcessServer(
res.tmp,
["serve", "-A", "--port", "0", "_fresh/server.js"],
async (address) => {
const res = await fetch(`${address}/test_static/foo.txt`);
const text = await res.text();
expect(text).toEqual("it works");
},
);
},
sanitizeOps: false,
sanitizeResources: false,
});
Deno.test({
name: "vite build - loads islands",
fn: async () => {
await using res = await buildVite();
await withChildProcessServer(
res.tmp,
["serve", "-A", "--port", "0", "_fresh/server.js"],
async (address) => {
await withBrowser(async (page) => {
await page.goto(`${address}/tests/island_hooks`, {
waitUntil: "networkidle2",
});
await waitForText(page, "button", "count: 0");
await page.locator("button").click();
await waitForText(page, "button", "count: 1");
});
},
);
},
sanitizeOps: false,
sanitizeResources: false,
});
-83
View File
@@ -1,83 +0,0 @@
import * as path from "@std/path";
import { expect } from "@std/expect";
import { waitForText, withBrowser } from "../../tests/test_utils.tsx";
import { updateFile, withDevServer } from "./test_utils.ts";
Deno.test({
name: "vite dev - launches",
fn: async () => {
await withDevServer(async (address) => {
const res = await fetch(`${address}/tests/it_works`);
const text = await res.text();
expect(text).toContain("it works");
});
},
sanitizeResources: false,
sanitizeOps: false,
});
Deno.test({
name: "vite dev - serves static files",
fn: async () => {
await withDevServer(async (address) => {
const res = await fetch(`${address}/test_static/foo.txt`);
const text = await res.text();
expect(text).toContain("it works");
});
},
sanitizeResources: false,
sanitizeOps: false,
});
Deno.test({
name: "vite dev - loads islands",
fn: async () => {
await withDevServer(async (address) => {
await withBrowser(async (page) => {
await page.goto(`${address}/tests/island_hooks`, {
waitUntil: "networkidle2",
});
await waitForText(page, "button", "count: 0");
await page.locator("button").click();
await waitForText(page, "button", "count: 1");
});
});
},
sanitizeResources: false,
sanitizeOps: false,
});
Deno.test({
name: "vite dev - can apply HMR to islands (hooks)",
ignore: true, // Test is very flaky
fn: async () => {
await withDevServer(async (address, dir) => {
await withBrowser(async (page) => {
await page.goto(`${address}/tests/island_hooks`, {
waitUntil: "networkidle2",
});
await waitForText(page, "button", "count: 0");
await page.locator("button").click();
await waitForText(page, "button", "count: 1");
const island = path.join(
dir,
"islands",
"tests",
"CounterHooks.tsx",
);
await using _ = await updateFile(
island,
(text) => text.replace("count:", "hmr:"),
);
await waitForText(page, "button", "hmr: 1");
await page.locator("button").click();
await waitForText(page, "button", "hmr: 2");
});
});
},
sanitizeResources: false,
sanitizeOps: false,
});
-108
View File
@@ -1,108 +0,0 @@
import { createBuilder } from "vite";
import * as path from "@std/path";
import { walk } from "@std/fs/walk";
import { withTmpDir } from "../../src/test_utils.ts";
import { withChildProcessServer } from "../../tests/test_utils.tsx";
export const DEMO_DIR = path.join(import.meta.dirname!, "..", "demo");
export async function updateFile(
filePath: string,
fn: (text: string) => string | Promise<string>,
) {
const original = await Deno.readTextFile(filePath);
const result = await fn(original);
await Deno.writeTextFile(filePath, result);
return {
async [Symbol.asyncDispose]() {
await Deno.writeTextFile(filePath, original);
},
};
}
async function copyDir(from: string, to: string) {
const entries = walk(from, {
includeFiles: true,
includeDirs: false,
skip: [/([\\/]+(_fresh|node_modules|vendor)[\\/]+|[\\/]+vite\.config\.ts)/],
});
for await (const entry of entries) {
if (entry.isFile) {
const relative = path.relative(from, entry.path);
const target = path.join(to, relative);
try {
await Deno.mkdir(path.dirname(target), { recursive: true });
} catch (err) {
if (!(err instanceof Deno.errors.NotFound)) {
throw err;
}
}
await Deno.copyFile(entry.path, target);
}
}
}
export async function withDevServer(
fn: (address: string, dir: string) => void | Promise<void>,
) {
await using tmp = await withTmpDir({
dir: path.join(import.meta.dirname!, ".."),
prefix: "tmp_",
});
await copyDir(DEMO_DIR, tmp.dir);
await Deno.writeTextFile(
path.join(tmp.dir, "vite.config.ts"),
`import { defineConfig } from "vite";
import { fresh } from "@fresh/plugin-vite";
export default defineConfig({
plugins: [
fresh(),
],
});
`,
);
await withChildProcessServer(
tmp.dir,
["run", "-A", "npm:vite"],
(address) => fn(address, tmp.dir),
);
}
export async function buildVite() {
const tmp = await withTmpDir();
const builder = await createBuilder({
root: DEMO_DIR,
build: {
emptyOutDir: true,
},
environments: {
ssr: {
build: {
outDir: path.join(tmp.dir, "_fresh", "server"),
},
},
client: {
build: {
outDir: path.join(tmp.dir, "_fresh", "client"),
},
},
},
});
await builder.buildApp();
return {
tmp: tmp.dir,
async [Symbol.asyncDispose]() {
return await tmp[Symbol.asyncDispose]();
},
};
}