fix(dev): dev release manifest를 파일로 쓰지 않고 메모리에서 낸다

문제
깨끗한 clone의 FE-GATE-008에서 dev server를 쓰는 capability e2e가
"requestfailed:GET:/release-manifest.json:net::ERR_ABORTED"로 1~4건씩
떨어졌다(세 번 중 세 번, 부하 9~30). 플러그인(db5728b)이 dev server 시작
때 .generated/frontend-runtime/에 manifest를 쓰는데, polling 감시
(CHOKIDAR_USEPOLLING=1)가 그 새 파일을 서버가 뜬 뒤에 보고 부팅 중인 페이지를
다시 불러오면 진행 중인 manifest 요청이 끊긴다고 본다. 플러그인을 넣기 전
같은 부하의 회차들은 66건 모두 통과했다.

고른 방법
- 자식 프로세스가 manifest를 stdout으로 내고, 플러그인은 그 문자열을
  메모리에 두고 낸다. 파일을 쓰지 않으므로 감시가 볼 것이 없다.
  devReleaseManifest(source)가 문자열을 돌려준다.

위험·한계
- 원인을 감시 이벤트로 직접 관측하지는 않았다(추론). 수정 뒤 재실행으로
  확인한다.

검증
- tests/unit/dev-release-manifest.test.ts 2건, check:types, lint 통과.

Refs: docs/reviews/2026-11-03-maturity-review/README.md 14.5 X4
This commit is contained in:
DongHyeonka
2026-11-05 03:12:27 +09:00
parent 2e4595e2ff
commit 0eba0821bd
3 changed files with 18 additions and 37 deletions
+7 -15
View File
@@ -1,24 +1,17 @@
import { execFileSync } from "node:child_process";
import { readFileSync } from "node:fs";
import path from "node:path";
import type { Plugin } from "vite";
/**
* Generated at dev server start, beside the build's generated contract set and
* ignored with it. Not under src/: the removal drills scan src/ for the
* sample's names, and this copies the placeholder's route chunks.
*/
export const DEV_RELEASE_MANIFEST_PATH = ".generated/frontend-runtime/dev-release-manifest.json";
/**
* Serve only. The dev server answers the runtime's release-manifest request
* with scripts/write-dev-release-manifest.ts's output instead of the committed
* placeholder, so a feature that `create:feature` just added boots in
* `corepack pnpm dev` and in the dev-server browser tests. The manifest is
* written in a child process because it imports the installed feature
* declarations, which this config must not load. A build never uses it: the
* built manifest comes from scripts/generate-build-manifest.ts.
* built once in a child process at server start, because it imports the
* installed feature declarations, which this config must not load, and kept
* in memory: no file is written for the server's watcher to see. A build never
* uses it: the built manifest comes from scripts/generate-build-manifest.ts.
*/
export function devReleaseManifestPlugin(repositoryRoot = process.cwd()): Plugin {
return {
@@ -27,12 +20,11 @@ export function devReleaseManifestPlugin(repositoryRoot = process.cwd()): Plugin
// from a server, so they skip the child process.
apply: (_config, env) => env.command === "serve" && !process.env["VITEST"],
configureServer(server) {
execFileSync(
const manifest = execFileSync(
process.execPath,
[path.join(repositoryRoot, "scripts/write-dev-release-manifest.ts")],
{ cwd: repositoryRoot, stdio: "inherit" },
{ cwd: repositoryRoot, encoding: "utf8", stdio: ["ignore", "pipe", "inherit"] },
);
const manifest = path.join(repositoryRoot, DEV_RELEASE_MANIFEST_PATH);
server.middlewares.use((request, response, next) => {
const pathname = new URL(request.url ?? "/", "http://dev.invalid").pathname;
if (request.method !== "GET" || !pathname.endsWith("/release-manifest.json")) {
@@ -41,7 +33,7 @@ export function devReleaseManifestPlugin(repositoryRoot = process.cwd()): Plugin
}
response.setHeader("content-type", "application/json");
response.setHeader("cache-control", "no-store");
response.end(readFileSync(manifest));
response.end(manifest);
});
},
};
+8 -11
View File
@@ -1,27 +1,24 @@
import { mkdir, readFile, writeFile } from "node:fs/promises";
import { dirname } from "node:path";
import { readFile } from "node:fs/promises";
import { buildContractSet } from "./generate-contract-set.ts";
import { DEV_RELEASE_MANIFEST_PATH } from "./lib/dev-release-manifest.ts";
/**
* The release manifest the dev server serves: the committed placeholder
* (public/release-manifest.json) with the contract set of the features
* installed now. Boot checks that set against the installed declarations, so
* a placeholder with a fixed set refused every app with one more feature
* (CONTRACT_SET_PACKAGE_MISSING) until someone edited it by hand. The output
* is generated and ignored, as .generated/ is.
* (CONTRACT_SET_PACKAGE_MISSING) until someone edited it by hand.
*/
export async function writeDevReleaseManifest(
export async function devReleaseManifest(
source = "public/release-manifest.json",
output = DEV_RELEASE_MANIFEST_PATH,
): Promise<void> {
): Promise<string> {
const manifest = JSON.parse(await readFile(source, "utf8")) as Record<string, unknown>;
manifest["contractSet"] = buildContractSet();
await mkdir(dirname(output), { recursive: true });
await writeFile(output, `${JSON.stringify(manifest, null, 2)}\n`, "utf8");
return `${JSON.stringify(manifest, null, 2)}\n`;
}
// Printed, not written: a file the dev server's watcher picks up after the
// server started could reload a page while it is booting.
if (process.argv[1]?.endsWith("write-dev-release-manifest.ts")) {
await writeDevReleaseManifest();
process.stdout.write(await devReleaseManifest());
}