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:
Radosław Smoliński
2026-10-29 16:30:24 +01:00
co-authored by Claude Opus 5.5
parent aa88e4ea39
commit e7e756a0d7
8 changed files with 55 additions and 11 deletions
+12
View File
@@ -3,6 +3,7 @@
// (dist/starter/template.json.gz): the kept files, the manifest and the lockfile without the plugin.
// Runs in prepublishOnly after `pnpm build`; fails when the reference site breaks a manifest rule.
import { execFileSync } from 'node:child_process'
import { mkdirSync, statSync, writeFileSync } from 'node:fs'
import { dirname, join } from 'node:path'
import { fileURLToPath, pathToFileURL } from 'node:url'
@@ -11,9 +12,20 @@ const root = join(dirname(fileURLToPath(import.meta.url)), '..')
const { bundleFlags, collectBundle, packBundle } = await import(pathToFileURL(join(root, 'dist', 'exports', 'starter.js')).href)
const bundle = collectBundle(join(root, 'reference'))
// provenance: the plugin commit this bundle was built from, so a generated site can be traced back (`-dirty` = uncommitted changes)
const git = (args) => {
try {
return execFileSync('git', args, { cwd: root, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }).trim()
} catch {
return ''
}
}
const head = git(['rev-parse', 'HEAD'])
bundle.source = { commit: head ? `${head}${git(['status', '--porcelain']) ? '-dirty' : ''}` : null }
const out = join(root, 'dist', 'starter', 'template.json.gz')
mkdirSync(dirname(out), { recursive: true })
writeFileSync(out, packBundle(bundle))
const raw = Object.values(bundle.files).reduce((sum, text) => sum + Buffer.byteLength(text), 0) + Buffer.byteLength(bundle.lockfile)
console.log(`starter bundle: ${Object.keys(bundle.files).length} files + lockfile, ${(raw / 1024).toFixed(0)} KB raw → ${(statSync(out).size / 1024).toFixed(0)} KB gzipped (${out.slice(root.length + 1)})`)
console.log(`flags used by the reference site: ${bundleFlags(bundle).join(', ')}`)
console.log(`source: ${bundle.source.commit ?? 'not a Git checkout'}`)