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 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-12-01 13:03:32 +01:00
co-authored by Claude Opus 5.5
parent 1ba191e580
commit 84717804ae
+18 -6
View File
@@ -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-<tag>, 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')