Files
ipal-kit/scripts/legacy-site-check.mjs
T
Radosław SmolińskiandClaude Opus 5.5 84717804ae 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]>
2026-12-01 13:03:32 +01:00

145 lines
8.0 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env node
/**
* pnpm legacy:site — a site written for the last release BEFORE the rename to IAPL works on this build, unedited.
*
* The reference site as it was at a tag (default v1.16.7: `ipalKit()`, `ipal-tokens`, `ipal-doctor.json`, `ipal-*`
* skills, the old pointer block) is unpacked next to the plugin and installed against the plugin built from this
* 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` 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.
*
* Needs: the plugin built (`pnpm build`; --skip-plugin-build when dist is current), the tag in the local repository.
* The builds read the database (static params), so DATABASE_URI must point at a reachable local MongoDB — an empty
* one is enough (default mongodb://127.0.0.1:27017/example-studiopl_dev, the reference site's local database).
* Options: --tag=v1.16.7 · --only=webpack|turbopack · --skip-build (steps 1–3 only) · --keep (leave the folder).
* 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, writeFileSync } from 'node:fs'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..')
const args = process.argv.slice(2)
const opt = (name, fallback) => args.find((a) => a.startsWith(`--${name}=`))?.slice(name.length + 3) ?? fallback
const tag = opt('tag', 'v1.16.7')
const only = opt('only')
const bundlers = ['webpack', 'turbopack'].filter((b) => !only || b === only)
const site = path.join(root, `.legacy-site-${tag.replace(/[^\w.-]/g, '_')}`)
const env = {
...process.env,
DATABASE_URI: process.env.DATABASE_URI ?? 'mongodb://127.0.0.1:27017/example-studiopl_dev',
NEXT_PUBLIC_SERVER_URL: process.env.NEXT_PUBLIC_SERVER_URL ?? 'http://localhost:3000',
NEXT_TELEMETRY_DISABLED: '1',
PAYLOAD_SECRET: process.env.PAYLOAD_SECRET ?? 'legacy-site-check-secret-0123456789abcdef',
}
const results = []
const sh = (label, command, commandArgs, { capture = false, cwd = site, allowFail = false } = {}) => {
console.log(`\n[legacy:site] ${label}`)
const res = spawnSync(command, commandArgs, { cwd, encoding: 'utf8', env, maxBuffer: 256 * 1024 * 1024, stdio: capture ? ['ignore', 'pipe', 'inherit'] : 'inherit' })
if (res.status !== 0 && !allowFail) {
console.error(`\n[legacy:site] ✗ FAILED: ${label}`)
finish(1)
}
return res
}
const finish = (code) => {
if (!args.includes('--keep')) {rmSync(site, { force: true, recursive: true })}
for (const line of results) {console.log(`[legacy:site] ${line}`)}
process.exit(code)
}
if (spawnSync('git', ['rev-parse', '--verify', '--quiet', `${tag}^{commit}`], { cwd: root }).status !== 0) {
console.error(`[legacy:site] tag ${tag} is not in this repository (git fetch --tags)`)
process.exit(2)
}
if (!args.includes('--skip-plugin-build')) {sh('build the plugin', 'pnpm', ['build'], { cwd: root })}
if (!existsSync(path.join(root, 'dist/index.js'))) {
console.error('[legacy:site] dist/ is missing — run pnpm build')
process.exit(2)
}
rmSync(site, { force: true, recursive: true })
mkdirSync(site, { recursive: true })
// reference/ of the tag, unpacked as a direct child of the plugin root: its "file:.." dependency is this tree.
const archive = spawnSync('sh', ['-c', `git archive ${tag} reference | tar -x --strip-components=1 -C "${site}"`], { cwd: root, stdio: 'inherit' })
if (archive.status !== 0) {finish(1)}
const config = readFileSync(path.join(site, 'src/payload.config.ts'), 'utf8')
if (!/\bipalKit\s*\(/.test(config)) {
console.error(`[legacy:site] ${tag}: the reference site does not call ipalKit() — pick a tag from before 1.17.0`)
finish(2)
}
sh('install the old site against this build', 'pnpm', ['install', '--ignore-workspace', '--no-frozen-lockfile'])
const installed = JSON.parse(readFileSync(path.join(site, 'node_modules/@intecion/ipal-kit/package.json'), 'utf8')).version
results.push(`site of ${tag}, plugin ${installed} from this tree`)
sh('old command: ipal-tokens --check', 'pnpm', ['exec', 'ipal-tokens', '--check'])
results.push('ipal-tokens --check: ok')
// 1.16's own audit skill and CI scripts call the commands by file path
sh('old file path: bin/ipal-tokens.mjs --check', 'node', ['node_modules/@intecion/ipal-kit/bin/ipal-tokens.mjs', '--check'])
sh('old file path: bin/ipal-doctor.mjs --help', 'node', ['node_modules/@intecion/ipal-kit/bin/ipal-doctor.mjs', '--help'], { capture: true })
const audit = sh("the old site's own audit skill (.agents/skills/ipal-audit, --quick)", 'bash', ['.agents/skills/ipal-audit/scripts/audit.sh', '--quick'], { allowFail: true, capture: true })
if (/ipal-tokens not installed/.test(audit.stdout)) {
console.error('[legacy:site] ✗ the 1.16 audit skill no longer finds bin/ipal-tokens.mjs')
finish(1)
}
results.push('old file paths (bin/ipal-*.mjs) and the 1.16 audit skill: ok')
const doctor = sh('old command: ipal-doctor (static, offline)', 'pnpm', ['exec', 'ipal-doctor', '.', '--offline', '--json'], { allowFail: true, capture: true })
let report
try {
report = JSON.parse(doctor.stdout)
} catch {
console.error(doctor.stdout)
console.error('[legacy:site] ✗ ipal-doctor did not print JSON')
finish(1)
}
const open = report.findings.filter((f) => !f.silenced)
const count = (severity) => open.filter((f) => f.severity === severity)
for (const f of open.filter((x) => x.severity !== 'info')) {console.log(` ${f.severity}: ${f.rule} — ${f.message}`)}
results.push(`ipal-doctor: ${count('error').length} error(s), ${count('warning').length} warning(s) [${[...new Set(count('warning').map((f) => f.rule))].join(', ')}], ${count('info').length} info [${[...new Set(count('info').map((f) => f.rule))].join(', ')}]`)
if (count('error').length) {
console.error('[legacy:site] ✗ the doctor reports an error on a site that had none')
finish(1)
}
const mapFile = path.join(site, 'src/app/(payload)/admin/importMap.js')
const mapBefore = readFileSync(mapFile, 'utf8')
sh('payload generate:importmap', 'pnpm', ['generate:importmap'])
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)')
}
sh('tsc --noEmit (old names against the new types)', 'pnpm', ['typecheck'])
results.push('typecheck: ok')
if (!args.includes('--skip-build')) {
for (const bundler of bundlers) {
rmSync(path.join(site, '.next'), { force: true, recursive: true })
sh(`production build, ${bundler}`, 'pnpm', ['exec', 'cross-env', 'NODE_OPTIONS=--max-old-space-size=3072', 'next', 'build', ...(bundler === 'webpack' ? ['--webpack'] : [])])
results.push(`build (${bundler}): ok`)
}
}
console.log('\n[legacy:site] ✓ the old site works on this build')
finish(0)