Skip to content

Commit bdec7f2

Browse files
authored
refactor: read installed version via readFileSync in emit-cli guard (#526)
1 parent 2c5a78b commit bdec7f2

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

scripts/refresh-global-emit-cli.mjs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
// and stay easy to filter in recall.
2525

2626
import { execFileSync, spawn } from 'node:child_process'
27-
import { lstatSync, existsSync } from 'node:fs'
27+
import { lstatSync, existsSync, readFileSync } from 'node:fs'
2828
import { join } from 'node:path'
2929
import { createHash } from 'node:crypto'
3030

@@ -82,7 +82,12 @@ if (!existsSync(cliJs)) fail(`${cliJs} missing from the installed package`)
8282
// Gate 3: signed smoke through the installed CLI, invoked the same way the
8383
// hook helper's primary strategy does (this node binary + cli.js path).
8484
const contextId = createHash('sha256').update('atrib:refresh-global-emit-cli').digest('hex').slice(0, 32)
85-
const installedVersion = JSON.parse(execFileSync('node', ['-p', `JSON.stringify(require(${JSON.stringify(join(pkgDir, 'package.json'))}).version)`], { encoding: 'utf8' }))
85+
let installedVersion
86+
try {
87+
installedVersion = JSON.parse(readFileSync(join(pkgDir, 'package.json'), 'utf8')).version
88+
} catch (e) {
89+
fail(`could not read installed package.json: ${e.message}`)
90+
}
8691
const envelope = JSON.stringify({
8792
event_type: 'observation',
8893
context_id: contextId,

0 commit comments

Comments
 (0)