mirror of
https://github.com/hansjone/netxops.git
synced 2026-10-20 11:10:44 +08:00
Harden public package installation and release validation
This commit is contained in:
parent
9271494b37
commit
9b2166e5b6
41 changed files with 994 additions and 363 deletions
21
scripts/pack-release.mjs
Normal file
21
scripts/pack-release.mjs
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
import { createHash } from 'node:crypto'
|
||||
import { readFileSync, writeFileSync } from 'node:fs'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { join } from 'node:path'
|
||||
import { spawnSync } from 'node:child_process'
|
||||
import { root } from './build-integrity.mjs'
|
||||
import { npmRuntime } from './npm-cli.mjs'
|
||||
import { verifyRelease } from './verify-release.mjs'
|
||||
|
||||
const verified = verifyRelease()
|
||||
const { node, npm } = npmRuntime()
|
||||
const packed = spawnSync(node, [npm, 'pack', '--json', '--ignore-scripts', '--cache', join(tmpdir(), 'netxops-npm-cache')], {
|
||||
cwd: root, encoding: 'utf8', windowsHide: true,
|
||||
})
|
||||
if (packed.status !== 0) throw new Error(packed.stderr || String(packed.error))
|
||||
const info = JSON.parse(packed.stdout)[0]
|
||||
const file = join(root, info.filename)
|
||||
const sha = createHash('sha256').update(readFileSync(file)).digest('hex')
|
||||
writeFileSync(`${file}.sha256`, `${sha} ${info.filename}\n`)
|
||||
console.log(`Release ${verified.version}: ${info.files.length} files, ${(info.size / 1024).toFixed(1)} KiB`)
|
||||
console.log(`Package: ${file}\nSHA256: ${sha}`)
|
||||
Loading…
Add table
Add a link
Reference in a new issue