Files
ipal-kit/scripts/legacy-site-check.mjs
T
Radosław SmolińskiandClaude Fable 5.2 38b903fcfa IAPL rename, review fixes I-1 to I-11
I-1  ipalEnvRules() keeps the IPAL_ rule names (IAPL_ as aliases); iaplEnvRules() the other way round; the IAPL_ value
     is the one checked when both are set
I-2  COOKIE_SCAN_URL_ENV / COOKIE_SCAN_TOKEN_ENV (and the internal SITE_NOINDEX_ENV) keep their old values;
     IAPL_COOKIE_SCAN_URL_ENV / IAPL_COOKIE_SCAN_TOKEN_ENV added
I-3  bin/ipal-*.mjs: five files that run the new ones (1.16's audit skill and CI call them by path); legacy:site checks it
I-4  storage-names sees <SiteProviders … stats> when a JSX prop comes first (the reference layout's shape)
I-5  AGENT.md: a text naming an ipal-<name> skill means iapl-<name> (the vendored ext-* skills)
I-6  leftover text in the skills-current message
I-7  iapl-skills removes the old pointer block when both are in AGENTS.md
I-8, I-11  changelog: the doctor's summary line, IAPL_DOCTOR_STATUS, --strict in CI until the skills are refreshed
I-9  env.md: an empty IAPL_ variable does not switch the IPAL_ one off
I-10 verifyLimit.keyPrefix undefined or empty is 'not given'

Co-Authored-By: Claude Fable 5.2 <[email protected]>
2026-11-25 18:45:36 +01:00

133 lines
7.1 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` leaves the committed import map byte for byte as it was;
* 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 } 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'])
if (readFileSync(mapFile, 'utf8') !== mapBefore) {
console.error('[legacy:site] ✗ the generated import map differs from the one the old site has committed')
finish(1)
}
results.push('import map: unchanged')
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)