#!/usr/bin/env node // E2E fake `next` for the export app's build (release 18 S4). A site's and the // hub's build stage run compose for real, then ` build` in // export/ in place of `pnpm exec next build` (common/publish/build.ts) — which // in the editor's e2e would rebuild the export app beside its running dev // server, for a minute, to prove nothing about publishing. // // What a real `next build` of a static export leaves that the publish stages // read is `export/out`: the composed `public/` copied in (site.json and // corpus.json name the site — builtBundleProblem; the hub's tombstones — // builtHubProblem) and the rendered pages. This writes exactly that: the // composed public dir (EXPORT_PUBLIC_DIR, which the build step sets) copied to // ./out, and an index.html. Nothing is rendered. import { cpSync, existsSync, mkdirSync, rmSync, writeFileSync } from "node:fs"; import path from "node:path"; import { installFixtureWatchdog } from "./_watchdog.mjs"; installFixtureWatchdog(); const argv = process.argv.slice(2); if (argv[0] === "--version" || argv[0] === "-v") { process.stdout.write("Next.js v16.0.0 (fake)\n"); process.exit(0); } if (argv[0] !== "build") { process.stderr.write(`[fake-next] unsupported invocation: ${argv.join(" ")}\n`); process.exit(2); } const publicDir = process.env.EXPORT_PUBLIC_DIR?.trim() || path.resolve("public"); if (!existsSync(publicDir)) { process.stderr.write(`[fake-next] no public dir at ${publicDir}\n`); process.exit(1); } const out = path.resolve("out"); rmSync(out, { recursive: true, force: true }); mkdirSync(out, { recursive: true }); cpSync(publicDir, out, { recursive: true, dereference: true }); const mode = process.env.INSTANCE_MODE === "hub" ? "hub" : "site"; writeFileSync( path.join(out, "index.html"), `fake ${mode} build${mode}\n`, ); process.stdout.write(" ▲ Next.js 16 (fake)\n"); process.stdout.write(` ✓ Exported ${mode} from ${publicDir} to ${out}\n`);