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]>
135 lines
7.3 KiB
TypeScript
135 lines
7.3 KiB
TypeScript
import type { DoctorRule, RuleFinding } from '../types.js'
|
|
|
|
import { legacyEnvName } from '../../shared/envName.js'
|
|
import { configFile, DOCTOR_CONFIG_FILES } from '../project.js'
|
|
import { stripComments } from '../util.js'
|
|
|
|
/** The 16 skills shipped as `ipal-<name>` before 1.17.0 (now `iapl-<name>`). `iapl-skills` removes exactly these. */
|
|
export const LEGACY_SKILL_NAMES = [
|
|
'audit', 'block', 'collection', 'consent-check', 'debug', 'doctor', 'form', 'locale-add',
|
|
'migrate-fields', 'nav', 'plugin-gap', 'reference', 'seo-check', 'setup', 'site', 'upgrade',
|
|
].map((name) => `ipal-${name}`)
|
|
|
|
/** Exported names before 1.17.0 → the names since. Both work through 1.x. */
|
|
export const LEGACY_EXPORTS: Record<string, string> = {
|
|
IPAL_BREAKPOINTS: 'IAPL_BREAKPOINTS',
|
|
IPAL_TOKENS: 'IAPL_TOKENS',
|
|
IpalEnvFeatures: 'IaplEnvFeatures',
|
|
ipalEnvRules: 'iaplEnvRules',
|
|
IpalGlobalSlug: 'IaplGlobalSlug',
|
|
ipalKit: 'iapl',
|
|
IpalOptions: 'IaplOptions',
|
|
ipalT: 'iaplT',
|
|
IpalTokenName: 'IaplTokenName',
|
|
ipalVar: 'iaplVar',
|
|
}
|
|
|
|
/** Commands before 1.17.0 → the commands since. */
|
|
export const LEGACY_COMMANDS: Record<string, string> = {
|
|
'ipal-blocks': 'iapl-blocks',
|
|
'ipal-doctor': 'iapl-doctor',
|
|
'ipal-kit': 'iapl',
|
|
'ipal-skills': 'iapl-skills',
|
|
'ipal-tokens': 'iapl-tokens',
|
|
}
|
|
|
|
/** The plugin's runtime variables: `IAPL_<NAME>`, read as `IPAL_<NAME>` too. */
|
|
export const PLUGIN_ENV_NAMES = [
|
|
'IAPL_COOKIE_SCAN_TOKEN', 'IAPL_COOKIE_SCAN_URL', 'IAPL_DOCTOR_IMPORT_MAP', 'IAPL_DOCTOR_TOKEN',
|
|
'IAPL_IP_HEADER', 'IAPL_NOINDEX', 'IAPL_SEED_ALLOW_FULL', 'IAPL_SEED_ALLOW_PROD_UPDATE',
|
|
]
|
|
|
|
/**
|
|
* `legacy-names`: names from before the rename to IAPL (1.17.0) that the project still uses.
|
|
* Every one of them keeps working through 1.x, so this is information, not a defect: the project
|
|
* moves when its owner asks (the iapl-upgrade skill, "→ 1.17.0"). The two cases that are more
|
|
* than information are a warning: both doctor files present, and one variable set under both
|
|
* spellings with different values (the new spelling is the one read).
|
|
*/
|
|
export const legacyRules: DoctorRule[] = [
|
|
{
|
|
id: 'legacy-names',
|
|
check: (ctx) => {
|
|
const out: RuleFinding[] = []
|
|
const info = (message: string, fix: string, file?: string) => out.push({ ...(file ? { file } : {}), fix, message, severity: 'info' })
|
|
|
|
if (DOCTOR_CONFIG_FILES.every((name) => ctx.exists(name))) {
|
|
out.push({ fix: 'merge ipal-doctor.json into iapl-doctor.json and delete it', message: 'both iapl-doctor.json and ipal-doctor.json exist — only iapl-doctor.json is read', severity: 'warning' })
|
|
} else if (ctx.exists('ipal-doctor.json')) {
|
|
info('the doctor file has its name from before 1.17.0', 'optional: rename ipal-doctor.json to iapl-doctor.json', 'ipal-doctor.json')
|
|
}
|
|
|
|
for (const file of [configFile(ctx), ctx.exists(`${ctx.src}instrumentation.ts`) ? `${ctx.src}instrumentation.ts` : 'instrumentation.ts']) {
|
|
const code = file ? stripComments(ctx.read(file)) : ''
|
|
const used = Object.keys(LEGACY_EXPORTS).filter((name) => new RegExp(`\\b${name}\\b`).test(code))
|
|
if (used.length) {info(`uses ${used.join(', ')}`, `optional: ${used.map((name) => `${name} → ${LEGACY_EXPORTS[name]}`).join(', ')}`, file!)}
|
|
}
|
|
|
|
const scripts = Object.entries((ctx.pkg.scripts ?? {}))
|
|
const commands = Object.keys(LEGACY_COMMANDS).filter((name) => scripts.some(([, command]) => new RegExp(`(?<![\\w@/.-])${name}(?![\\w/-])`).test(command)))
|
|
if (commands.length) {info(`package.json scripts call ${commands.join(', ')}`, `optional: ${commands.map((name) => `${name} → ${LEGACY_COMMANDS[name]}`).join(', ')}`, 'package.json')}
|
|
|
|
for (const [label, env] of [['.env.example', ctx.env.example], ['.env', ctx.env.local], ['--env-file', ctx.env.prod]] as const) {
|
|
if (!env) {continue}
|
|
const old = PLUGIN_ENV_NAMES.filter((name) => env[legacyEnvName(name)!] !== undefined)
|
|
const clash = old.filter((name) => env[name] !== undefined && env[name] !== env[legacyEnvName(name)!])
|
|
if (clash.length) {out.push({ fix: `keep ${clash.join(', ')} and remove the IPAL_ spelling`, message: `${label}: ${clash.map((name) => `${name} and ${legacyEnvName(name)}`).join('; ')} are both set, with different values — the IAPL_ one is read`, severity: 'warning' })}
|
|
const only = old.filter((name) => !clash.includes(name) && env[name] === undefined)
|
|
if (only.length) {info(`${label} sets ${only.map((name) => legacyEnvName(name)).join(', ')}`, `optional: ${only.map((name) => `${legacyEnvName(name)} → ${name}`).join(', ')}`)}
|
|
}
|
|
|
|
const agents = `${ctx.read('AGENTS.md')}\n${ctx.read('CLAUDE.md')}`
|
|
if (/<!-- ipal-kit:start -->/.test(agents)) {info('the agent pointer block is the one from before 1.17.0', 'pnpm exec iapl-skills (rewrites the block in place)', 'AGENTS.md')}
|
|
if (/^[-* ]*ipal-audit-skip:/im.test(agents)) {info('ipal-audit-skip lines', 'optional: ipal-audit-skip → iapl-audit-skip', 'AGENTS.md')}
|
|
|
|
for (const dir of ['.agents/skills', '.claude/skills']) {
|
|
const old = ctx.list(dir).filter((name) => LEGACY_SKILL_NAMES.includes(name))
|
|
if (old.length) {info(`${old.length} skill folder(s) named ipal-* (from before 1.17.0)`, 'pnpm exec iapl-skills (installs iapl-*, removes these) and commit', dir)}
|
|
}
|
|
return out
|
|
},
|
|
docs: 'docs/agent/AGENT.md#names-iapl-and-ipal-kit',
|
|
group: 'agents',
|
|
source: 'static',
|
|
},
|
|
{
|
|
// The cookie the layout sets and the cookie the scanner declares must be the same one.
|
|
id: 'storage-names',
|
|
check: (ctx) => {
|
|
const cfg = stripComments(ctx.read(configFile(ctx) ?? ''))
|
|
const declared = /\bstorageNames\s*:\s*['"]iapl['"]/.test(cfg) ? 'iapl_vid' : 'ipal_vid'
|
|
const files: string[] = []
|
|
const walk = (dir: string, depth: number) => {
|
|
for (const name of ctx.list(dir)) {
|
|
if (files.length >= 600 || name === 'node_modules' || name.startsWith('.')) {continue}
|
|
if (/\.tsx$/.test(name)) {files.push(`${dir}/${name}`)}
|
|
else if (!name.includes('.') || /^\(.*\)$|^\[.*\]$/.test(name)) {if (depth < 8) {walk(`${dir}/${name}`, depth + 1)}}
|
|
}
|
|
}
|
|
walk(`${ctx.src}app`, 0)
|
|
walk(`${ctx.src}components`, 0)
|
|
const out: RuleFinding[] = []
|
|
for (const file of files) {
|
|
const code = stripComments(ctx.read(file))
|
|
// <SiteProviders … stats …>: a prop named stats anywhere after the tag opens (other props hold JSX, so the tag's end cannot be found by `>`)
|
|
if (!/<PageStats\b/.test(code) && !/<SiteProviders\b[\s\S]*?\sstats(?:\s*=|\s*\n|\s+[a-zA-Z/>])/.test(code)) {continue}
|
|
const set = /\bIAPL_VISITOR_COOKIE\b|['"]iapl_vid['"]/.test(code) ? 'iapl_vid' : /\bvisitorCookie\b/.test(code) ? null : 'ipal_vid'
|
|
if (set && set !== declared) {
|
|
out.push({
|
|
file,
|
|
fix: declared === 'iapl_vid'
|
|
? "pass visitorCookie={IAPL_VISITOR_COOKIE} (from '@intecion/ipal-kit/client') to <PageStats> / <SiteProviders stats={{ … }}>"
|
|
: "set iapl({ storageNames: 'iapl' }) in the config, or drop visitorCookie — one name per site (docs/stats.md)",
|
|
message: `the page sets the visitor cookie ${set}, the cookie scanner declares ${declared}`,
|
|
severity: 'warning',
|
|
})
|
|
}
|
|
}
|
|
return out
|
|
},
|
|
docs: 'docs/stats.md',
|
|
group: 'security',
|
|
source: 'static',
|
|
},
|
|
]
|