From 01219b69d36d153d021d1c65cd19725922df027e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Smoli=C5=84ski?= Date: Wed, 25 Nov 2026 01:53:46 +0100 Subject: [PATCH] F-3: pnpm e2e:built puts the reference site's generated files back, also on failure Co-Authored-By: Claude Fable 5.2 --- scripts/e2e-built.mjs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/scripts/e2e-built.mjs b/scripts/e2e-built.mjs index aceb254..b97f953 100644 --- a/scripts/e2e-built.mjs +++ b/scripts/e2e-built.mjs @@ -13,10 +13,12 @@ * Needs what the reference site's "Production check" needs (reference/README.md): reference/.env with a local, * seeded database and the E2E_* test admin. The test admins are reset by Playwright's global setup. * Port: E2E_BASE_URL (default http://localhost:3100), the same value as NEXT_PUBLIC_SERVER_URL in reference/.env. + * The reference site's generated files (payload-types.ts, the import map) are put back as they were at the end, + * also when a step fails: the working tree is the same after the run. * Options: --only=webpack | --only=turbopack; --skip-plugin-build (dist and the injected copy are current). */ import { spawnSync } from 'node:child_process' -import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs' +import { existsSync, readdirSync, readFileSync, statSync, writeFileSync } from 'node:fs' import path from 'node:path' import { fileURLToPath } from 'node:url' @@ -48,6 +50,20 @@ if (!args.includes('--skip-plugin-build')) { run('build the plugin', 'pnpm', ['build'], root) run('refresh the plugin copy in the reference site', 'pnpm', ['install', '--ignore-workspace'], site) } +// The run starts Payload with the fixture's collections, and Payload rewrites the site's generated types then. The +// tree must be as it was after a required release step: the file is put back at the end — also when a step fails. +const generated = ['src/payload-types.ts', 'src/app/(payload)/admin/importMap.js'].map((rel) => path.join(site, rel)).filter((file) => existsSync(file)).map((file) => ({ before: readFileSync(file), file })) +const restore = () => { + for (const { before, file } of generated) { + if (!existsSync(file) || !readFileSync(file).equals(before)) { + writeFileSync(file, before) + console.log(`[e2e:built] restored ${path.relative(root, file)} (rewritten with the fixture's collections during the run)`) + } + } +} +process.on('exit', restore) +for (const signal of ['SIGINT', 'SIGTERM']) {process.on(signal, () => process.exit(130))} + const fixture = { E2E_LATE_STAFF: '1', NODE_OPTIONS: `${process.env.NODE_OPTIONS ?? ''} --max-old-space-size=3072`.trim() } const passed = [] for (const bundler of bundlers) {