starter:gate: a fresh tarball every run and proof of which code made the site
pnpm's dlx cache is keyed by the spec, so the gate reused the previous run's plugin when the tarball path stayed the same. Each run now packs to a new file name and calls dlx with --config.dlx-cache-max-age=0. build:starter records the plugin commit in the bundle; ipal-kit create records the bundle's sha256 and that commit in .ipal/starter.json; the gate checks both, and the installed plugin, against the packed tarball. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
aa88e4ea39
commit
e7e756a0d7
@@ -19,6 +19,8 @@ export type StarterBundle = {
|
||||
lockfile: string
|
||||
manifest: StarterManifest
|
||||
schema: 1
|
||||
/** Where the bundle was built: the plugin commit (`-dirty` with uncommitted changes) — set by `pnpm build:starter`. */
|
||||
source?: { commit: null | string }
|
||||
}
|
||||
|
||||
const MANIFEST = 'starter.manifest.json'
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* convention (docs/project-starter.md). Run with `pnpm dlx @intecion/ipal-kit@<version> create <domain>`.
|
||||
*/
|
||||
import { spawnSync } from 'node:child_process'
|
||||
import { randomBytes } from 'node:crypto'
|
||||
import { createHash, randomBytes } from 'node:crypto'
|
||||
import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from 'node:fs'
|
||||
import { dirname, join, relative, resolve } from 'node:path'
|
||||
import { domainToASCII, fileURLToPath } from 'node:url'
|
||||
@@ -12,7 +12,7 @@ import type { SiteContext } from './generate.js'
|
||||
|
||||
import { databaseNamesFor } from '../env/databaseName.js'
|
||||
import { type StarterAnswers, validateAnswers } from './answers.js'
|
||||
import { collectBundle, type StarterBundle, unpackBundle } from './bundle.js'
|
||||
import { collectBundle, packBundle, type StarterBundle, unpackBundle } from './bundle.js'
|
||||
import { askInTerminal } from './prompts.js'
|
||||
import { renderSite } from './render.js'
|
||||
import { secretFindings } from './secrets.js'
|
||||
@@ -78,12 +78,20 @@ export function normalizeDomain(input: string): string {
|
||||
return ascii
|
||||
}
|
||||
|
||||
function loadBundle(): StarterBundle {
|
||||
/** The bundle and the sha256 of its packed bytes (recorded in the new site, so a check can tell which code ran). */
|
||||
function loadBundle(): { bundle: StarterBundle; sha256: string } {
|
||||
const packed = join(pkgRoot, 'dist', 'starter', 'template.json.gz')
|
||||
if (existsSync(packed)) {return unpackBundle(readFileSync(packed))}
|
||||
const sha = (data: Buffer) => createHash('sha256').update(data).digest('hex')
|
||||
if (existsSync(packed)) {
|
||||
const data = readFileSync(packed)
|
||||
return { bundle: unpackBundle(data), sha256: sha(data) }
|
||||
}
|
||||
// a checkout of the plugin repo: read the reference site directly
|
||||
const reference = join(pkgRoot, 'reference')
|
||||
if (existsSync(join(reference, 'starter.manifest.json'))) {return collectBundle(reference)}
|
||||
if (existsSync(join(reference, 'starter.manifest.json'))) {
|
||||
const bundle = collectBundle(reference)
|
||||
return { bundle, sha256: sha(packBundle(bundle)) }
|
||||
}
|
||||
throw new Error('no starter templates in this ipal-kit (dist/starter/template.json.gz) — use a released version')
|
||||
}
|
||||
|
||||
@@ -166,7 +174,9 @@ export async function runCreateCli(args: string[], log: Log = (line) => process.
|
||||
}
|
||||
let files: Record<string, string>
|
||||
try {
|
||||
files = renderSite(loadBundle(), answers, ctx)
|
||||
const { bundle, sha256 } = loadBundle()
|
||||
ctx.source = { bundleSha256: sha256, commit: bundle.source?.commit ?? null }
|
||||
files = renderSite(bundle, answers, ctx)
|
||||
} catch (error) {
|
||||
log(`ipal-kit create: ${(error as Error).message}`)
|
||||
return 1
|
||||
|
||||
@@ -13,6 +13,8 @@ export type SiteContext = {
|
||||
/** The exact ipal-kit version written into package.json. */
|
||||
pluginVersion: string
|
||||
serverUrl: string
|
||||
/** Which starter bundle made the site (recorded in `.ipal/starter.json`; the release gate compares it). */
|
||||
source?: { bundleSha256: string; commit: null | string }
|
||||
}
|
||||
|
||||
const q = (value: string) => `'${value.replace(/\\/g, '\\\\').replace(/'/g, "\\'")}'`
|
||||
|
||||
@@ -89,6 +89,6 @@ export function renderSite(bundle: StarterBundle, a: StarterAnswers, ctx: SiteCo
|
||||
}
|
||||
if (problems.length) {throw new Error(`rendering the site:\n ${problems.join('\n ')}`)}
|
||||
out['pnpm-lock.yaml'] = bundle.lockfile
|
||||
out['.ipal/starter.json'] = `${JSON.stringify({ answers: a, createdAt: ctx.date, domain: ctx.domain, ipalKit: ctx.pluginVersion }, null, 2)}\n`
|
||||
out['.ipal/starter.json'] = `${JSON.stringify({ answers: a, createdAt: ctx.date, domain: ctx.domain, ipalKit: ctx.pluginVersion, ...(ctx.source ? { source: ctx.source } : {}) }, null, 2)}\n`
|
||||
return out
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user