MCPcopy
hub / github.com/Fission-AI/OpenSpec / main

Function main

scripts/pack-version-check.mjs:48–103  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

46}
47
48function main() {
49 const pkg = JSON.parse(readFileSync(path.join(process.cwd(), 'package.json'), 'utf-8'));
50 const expected = pkg.version;
51
52 let work;
53 let tgzPath;
54
55 try {
56 log(`Packing @fission-ai/openspec@${expected}...`);
57 const filename = npmPack();
58 tgzPath = path.resolve(filename);
59 log(`Created: ${tgzPath}`);
60
61 work = mkdtempSync(path.join(tmpdir(), 'openspec-pack-check-'));
62 log(`Temp dir: ${work}`);
63
64 // Make a tiny project
65 writeFileSync(
66 path.join(work, 'package.json'),
67 JSON.stringify({ name: 'pack-check', private: true }, null, 2)
68 );
69
70 // Try to avoid noisy output and speed up
71 const env = {
72 ...process.env,
73 npm_config_loglevel: 'silent',
74 npm_config_audit: 'false',
75 npm_config_fund: 'false',
76 npm_config_progress: 'false',
77 };
78
79 // Install the tarball
80 run('npm', ['install', tgzPath, '--silent', '--no-audit', '--no-fund'], { cwd: work, env });
81
82 // Run the installed CLI via Node to avoid bin resolution/platform issues
83 const binRel = path.join('node_modules', '@fission-ai', 'openspec', 'bin', 'openspec.js');
84 const actual = run(process.execPath, [binRel, '--version'], { cwd: work }).trim();
85
86 if (actual !== expected) {
87 throw new Error(
88 `Packed CLI version mismatch: expected ${expected}, got ${actual}. ` +
89 'Ensure the dist is built and the CLI reads version from package.json.'
90 );
91 }
92
93 log('Version check passed.');
94 } finally {
95 // Always attempt cleanup
96 if (work) {
97 try { rmSync(work, { recursive: true, force: true }); } catch {}
98 }
99 if (tgzPath) {
100 try { rmSync(tgzPath, { force: true }); } catch {}
101 }
102 }
103}
104
105try {

Callers 1

Calls 3

logFunction · 0.85
npmPackFunction · 0.85
runFunction · 0.85

Tested by

no test coverage detected