Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

chore(web,docs): stop next dev from leaving generated files to commit (MUL-9812) (#11155)

Jiayuan Zhang40fa53accfdf
diff --git a/.gitignore b/.gitignore
index b15bb63032..69f7b1b4f0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,6 +7,8 @@ dist
# build outputs
.turbo
.next
+# Written by next dev / build / typegen, with paths that differ between them.
+next-env.d.ts
out
build
bin
diff --git a/apps/docs/next-env.d.ts b/apps/docs/next-env.d.ts
deleted file mode 100644
index ce4e94a6b1..0000000000
--- a/apps/docs/next-env.d.ts
+++ /dev/null
@@ -1,7 +0,0 @@
-/// <reference types="next" />
-/// <reference types="next/image-types/global" />
-import "./.next/types/routes.d.ts";
-import "./.next/types/root-params.d.ts";
-
-// NOTE: This file should not be edited
-// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.
diff --git a/apps/docs/next.config.mjs b/apps/docs/next.config.mjs
index 84b148b96d..01e40853e3 100644
--- a/apps/docs/next.config.mjs
+++ b/apps/docs/next.config.mjs
@@ -5,6 +5,9 @@ const withMDX = createMDX();
/** @type {import('next').NextConfig} */
const config = {
reactStrictMode: true,
+ // Otherwise `next dev` writes a generic apps/docs/AGENTS.md; agent guidance
+ // lives in the root AGENTS.md.
+ agentRules: false,
basePath: "/docs",
// Visiting http://host/ (outside basePath) would otherwise 404 — redirect
// to the docs root. basePath: false makes the source and destination
diff --git a/apps/docs/package.json b/apps/docs/package.json
index fba03ce2d3..69f1bf83ac 100644
--- a/apps/docs/package.json
+++ b/apps/docs/package.json
@@ -8,6 +8,7 @@
"build": "next build",
"start": "next start",
"typecheck": "tsc --noEmit",
+ "typegen": "next typegen",
"test": "vitest run",
"mdx": "fumadocs-mdx",
"postinstall": "fumadocs-mdx"
diff --git a/apps/web/next-env.d.ts b/apps/web/next-env.d.ts
deleted file mode 100644
index a419cbe4e3..0000000000
--- a/apps/web/next-env.d.ts
+++ /dev/null
@@ -1,7 +0,0 @@
-/// <reference types="next" />
-/// <reference types="next/image-types/global" />
-import "./.next/dev/types/routes.d.ts";
-import "./.next/dev/types/root-params.d.ts";
-
-// NOTE: This file should not be edited
-// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.
diff --git a/apps/web/next.config.ts b/apps/web/next.config.ts
index b402d199bf..3251f19ce0 100644
--- a/apps/web/next.config.ts
+++ b/apps/web/next.config.ts
@@ -40,6 +40,9 @@ const allowedDevOrigins = process.env.CORS_ALLOWED_ORIGINS
const nextConfig: NextConfig = {
...(process.env.STANDALONE === "true" ? { output: "standalone" as const } : {}),
+ // Otherwise `next dev` writes a generic apps/web/AGENTS.md; agent guidance
+ // lives in the root AGENTS.md.
+ agentRules: false,
transpilePackages: ["@multica/core", "@multica/ui", "@multica/views", "@multica/ee"],
experimental: {
// Workspace pages are client components over TanStack Query, so a route's
diff --git a/apps/web/package.json b/apps/web/package.json
index 0ec54e57a0..53365f8376 100644
--- a/apps/web/package.json
+++ b/apps/web/package.json
@@ -8,6 +8,7 @@
"build": "next build",
"start": "next start",
"typecheck": "tsc --noEmit",
+ "typegen": "next typegen",
"lint": "eslint .",
"test": "vitest run",
"mdx": "fumadocs-mdx",
diff --git a/scripts/web-prod.mjs b/scripts/web-prod.mjs
index 02601511c7..b7b525e85c 100644
--- a/scripts/web-prod.mjs
+++ b/scripts/web-prod.mjs
@@ -19,8 +19,7 @@
* environment's web port, not a free one, because the API accepts realtime
* WebSockets only from FRONTEND_ORIGIN; on any other port /ws is refused
* with 403. So the dev web server is stopped for the duration and started
- * again afterwards, also on Ctrl-C and when the command fails. The build
- * rewrites apps/web/next-env.d.ts, which is restored after it.
+ * again afterwards, also on Ctrl-C and when the command fails.
*
* With a command after `--`, the command runs once the server answers, with
* WEB_PROD_URL set to it, and its exit code becomes this script's. Without
@@ -31,13 +30,12 @@
* the daemon ends that environment once its web port stops answering.
*/
import { execFileSync, spawn, spawnSync } from "node:child_process";
-import { closeSync, existsSync, openSync, readFileSync, writeFileSync } from "node:fs";
+import { closeSync, existsSync, openSync, readFileSync } from "node:fs";
import { join } from "node:path";
const repoRoot = execFileSync("git", ["rev-parse", "--show-toplevel"]).toString().trim();
const webDir = join(repoRoot, "apps", "web");
const devEnv = join(repoRoot, "scripts", "dev-env.sh");
-const nextEnvFile = join(webDir, "next-env.d.ts");
const argv = process.argv.slice(2);
const separator = argv.indexOf("--");
@@ -93,23 +91,18 @@ function listenerPid(port) {
}
async function build(track) {
- const original = readFileSync(nextEnvFile);
log("building apps/web for production (same-origin API)");
- try {
- // REMOTE_API_URL is a runtime setting: at build time it breaks
- // prerendering. Empty rather than unset, so next.config.ts's dotenv
- // does not read it back from the root .env.
- const buildEnv = { ...env, NEXT_PUBLIC_API_URL: "", NEXT_PUBLIC_WS_URL: "", REMOTE_API_URL: "", NEXT_TELEMETRY_DISABLED: "1" };
- const builder = spawn("pnpm", ["--filter", "@multica/web", "build"], { cwd: repoRoot, env: buildEnv, stdio: "inherit" });
- track(builder);
- const code = await new Promise((done) => {
- builder.on("error", () => done(127));
- builder.on("exit", (exitCode, signal) => done(signal ? 1 : exitCode ?? 1));
- });
- if (code !== 0) throw new Error("the web build failed");
- } finally {
- writeFileSync(nextEnvFile, original);
- }
+ // REMOTE_API_URL is a runtime setting: at build time it breaks
+ // prerendering. Empty rather than unset, so next.config.ts's dotenv
+ // does not read it back from the root .env.
+ const buildEnv = { ...env, NEXT_PUBLIC_API_URL: "", NEXT_PUBLIC_WS_URL: "", REMOTE_API_URL: "", NEXT_TELEMETRY_DISABLED: "1" };
+ const builder = spawn("pnpm", ["--filter", "@multica/web", "build"], { cwd: repoRoot, env: buildEnv, stdio: "inherit" });
+ track(builder);
+ const code = await new Promise((done) => {
+ builder.on("error", () => done(127));
+ builder.on("exit", (exitCode, signal) => done(signal ? 1 : exitCode ?? 1));
+ });
+ if (code !== 0) throw new Error("the web build failed");
}
const exited = (child) => child.exitCode !== null || child.signalCode !== null;
diff --git a/turbo.json b/turbo.json
index e5c03f61d8..f5c95f0ae5 100644
--- a/turbo.json
+++ b/turbo.json
@@ -34,8 +34,18 @@
"mdx": {
"outputs": [".source/**"]
},
+ // `next-env.d.ts` is untracked (Next rewrites it with different paths in
+ // dev and build), yet `tsc` needs it for Next's image and stylesheet module
+ // types, so a fresh checkout has to generate it before `typecheck`.
+ // `next typegen` loads next.config, which regenerates `.source/` and
+ // `.next/types/` just as `next build` does; `build` depends on it too so
+ // the two never write those trees at the same time.
+ "typegen": {
+ "dependsOn": ["mdx"],
+ "outputs": ["next-env.d.ts", ".next/types/**"]
+ },
"build": {
- "dependsOn": ["^build", "mdx"],
+ "dependsOn": ["^build", "mdx", "typegen"],
// No explicit `inputs`: turbo's default (every git-tracked file in the
// package) is the only safe hash source now that the cache is actually
// restored in CI. The previous narrow glob list matched neither
@@ -66,7 +76,7 @@
"passThroughEnv": ["VITE_DEV_TOOLBAR"]
},
"typecheck": {
- "dependsOn": ["^typecheck", "mdx"]
+ "dependsOn": ["^typecheck", "mdx", "typegen"]
},
// Hash-only transit task. No package implements a `cache-inputs` script,
// so every node resolves to <NONEXISTENT> and nothing is ever executed --