From 84717804ae68f625b99b28cebde76e4a841746d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Smoli=C5=84ski?= Date: Tue, 1 Dec 2026 13:03:32 +0100 Subject: [PATCH] legacy:site: the same import-map entries in another order pass, and the old site is then built with its committed map Payload writes import-map entries in the order it meets them; 1.18.0's currentPassword field moves MaskedField three lines up. A new or a missing entry still fails. The typecheck and both builds run with the map the old site has, which proves an unedited site works without generate:importmap (the 1.18.0 notes say so). Co-Authored-By: Claude Opus 5.5 --- scripts/legacy-site-check.mjs | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/scripts/legacy-site-check.mjs b/scripts/legacy-site-check.mjs index a18bf7c..b068b3a 100644 --- a/scripts/legacy-site-check.mjs +++ b/scripts/legacy-site-check.mjs @@ -7,7 +7,7 @@ * tree. Nothing in it is changed. Then: * 1. the old commands run, by name and by file path (`bin/ipal-*.mjs`): `ipal-tokens --check`, `ipal-doctor` * (no error; the warnings are printed); the site's own 1.16 audit skill still finds the tokens command; - * 2. `payload generate:importmap` leaves the committed import map byte for byte as it was; + * 2. `payload generate:importmap` gives the same entries as the committed import map (byte for byte, or — since 1.18.0, on purpose — the same lines in another order; then the committed map is used for the checks below); * 3. `tsc --noEmit`: the old names still type-check; * 4. a production build with webpack and one with Turbopack. * @@ -18,7 +18,7 @@ * The folder (.legacy-site-, git-ignored) is removed at the end unless --keep. */ import { spawnSync } from 'node:child_process' -import { existsSync, mkdirSync, readFileSync, rmSync } from 'node:fs' +import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs' import path from 'node:path' import { fileURLToPath } from 'node:url' @@ -112,11 +112,23 @@ if (count('error').length) { const mapFile = path.join(site, 'src/app/(payload)/admin/importMap.js') const mapBefore = readFileSync(mapFile, 'utf8') sh('payload generate:importmap', 'pnpm', ['generate:importmap']) -if (readFileSync(mapFile, 'utf8') !== mapBefore) { - console.error('[legacy:site] ✗ the generated import map differs from the one the old site has committed') - finish(1) +const mapAfter = readFileSync(mapFile, 'utf8') +if (mapAfter === mapBefore) { + results.push('import map: unchanged') +} else { + // Payload writes the entries in the order it first meets them and never sorts, so a new field earlier in the + // config (1.18.0: currentPassword on the staff collection) can move an existing entry. The same entries in another + // order are allowed on purpose (1.18.0 notes: "generate:importmap moves one line; the committed map works too"); a + // new or a missing entry is not. + const entries = (text) => text.split('\n').map((line) => line.trim()).filter(Boolean).sort().join('\n') + if (entries(mapAfter) !== entries(mapBefore)) { + console.error('[legacy:site] ✗ the generated import map has other entries than the one the old site has committed') + finish(1) + } + // build and typecheck with the map the old site HAS: that it works unregenerated is the point + writeFileSync(mapFile, mapBefore) + results.push('import map: same entries, another order (the committed map is used below)') } -results.push('import map: unchanged') sh('tsc --noEmit (old names against the new types)', 'pnpm', ['typecheck']) results.push('typecheck: ok')