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]>
32 lines
1.8 KiB
JavaScript
32 lines
1.8 KiB
JavaScript
#!/usr/bin/env node
|
|
// pnpm build:starter — packs reference/ into the starter bundle shipped in the tarball
|
|
// (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'
|
|
|
|
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'}`)
|