Updates
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
#!/usr/bin/env node
|
||||
/**
|
||||
* Fail if bare-module-manifest.json and bare-module-manifest.data.mjs disagree.
|
||||
* Run from repo root: node scripts/verify-bare-module-manifest-data.mjs
|
||||
*/
|
||||
import { readFile } from 'node:fs/promises'
|
||||
import { dirname, join } from 'node:path'
|
||||
import { fileURLToPath, pathToFileURL } from 'node:url'
|
||||
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url))
|
||||
const root = join(__dirname, '..')
|
||||
const jsonPath = join(
|
||||
root,
|
||||
'packages/bare-os-booter/lib/bare-module-manifest.json'
|
||||
)
|
||||
const dataPath = join(
|
||||
root,
|
||||
'packages/bare-os-booter/lib/bare-module-manifest.data.mjs'
|
||||
)
|
||||
|
||||
function stableStringify(obj) {
|
||||
if (obj === null || typeof obj !== 'object') {
|
||||
return JSON.stringify(obj)
|
||||
}
|
||||
if (Array.isArray(obj)) {
|
||||
return '[' + obj.map((x) => stableStringify(x)).join(',') + ']'
|
||||
}
|
||||
const keys = Object.keys(obj).sort()
|
||||
return (
|
||||
'{' +
|
||||
keys
|
||||
.map((k) => JSON.stringify(k) + ':' + stableStringify(obj[k]))
|
||||
.join(',') +
|
||||
'}'
|
||||
)
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const jsonRaw = await readFile(jsonPath, 'utf8')
|
||||
const fromJson = JSON.parse(jsonRaw)
|
||||
const mod = await import(pathToFileURL(dataPath).href)
|
||||
const fromData = mod.default
|
||||
if (!fromData || typeof fromData !== 'object') {
|
||||
console.error(
|
||||
'[verify-bare-module-manifest-data] missing default export in',
|
||||
dataPath
|
||||
)
|
||||
process.exit(1)
|
||||
}
|
||||
const a = stableStringify(fromJson)
|
||||
const b = stableStringify(fromData)
|
||||
if (a !== b) {
|
||||
console.error(
|
||||
'[verify-bare-module-manifest-data] JSON and .data.mjs differ.\n' +
|
||||
'Run: node scripts/generate-bare-module-manifest-data.mjs\n' +
|
||||
'or: npm run sync:bare-manifest'
|
||||
)
|
||||
process.exit(1)
|
||||
}
|
||||
console.log('[verify-bare-module-manifest-data] ok')
|
||||
}
|
||||
|
||||
main().catch((e) => {
|
||||
console.error(e)
|
||||
process.exit(1)
|
||||
})
|
||||
Reference in New Issue
Block a user