The plugin's version is a constant: no package.json among a site's public assets
pluginVersion() named package.json relative to its own module. A bundler takes such a file for an asset: a Turbopack build of a site copied the plugin's whole package.json (dependency lists, scripts, the registry and repository addresses; no secret) to /_next/static/media/package.<hash>.json, served to anyone. Webpack kept it on the server side. The version now comes from src/version.ts (scripts/write-version.mjs, run by the `version` script; a test fails when it differs from package.json). A smoke test of the built site: nothing under .next/static is a package manifest. Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
co-authored by
Claude Fable 5.2
parent
bc0fa65fd7
commit
9a648b0498
@@ -0,0 +1,13 @@
|
||||
#!/usr/bin/env node
|
||||
// Writes the version from package.json into src/version.ts (see the comment there).
|
||||
// Runs as the `version` script of package.json; by hand: node scripts/write-version.mjs
|
||||
import { readFileSync, writeFileSync } from 'node:fs'
|
||||
|
||||
const root = new URL('../', import.meta.url)
|
||||
const { version } = JSON.parse(readFileSync(new URL('package.json', root), 'utf8'))
|
||||
const file = new URL('src/version.ts', root)
|
||||
const before = readFileSync(file, 'utf8')
|
||||
const after = before.replace(/export const PLUGIN_VERSION = '[^']*'/, `export const PLUGIN_VERSION = '${version}'`)
|
||||
if (after === before && !before.includes(`'${version}'`)) {throw new Error('src/version.ts: the PLUGIN_VERSION line was not found')}
|
||||
writeFileSync(file, after)
|
||||
console.log(`src/version.ts → ${version}`)
|
||||
Reference in New Issue
Block a user