-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathruntime-core-lock.mjs
More file actions
40 lines (34 loc) · 1.3 KB
/
runtime-core-lock.mjs
File metadata and controls
40 lines (34 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import fs from 'node:fs';
import path from 'node:path';
import { spawnSync } from 'node:child_process';
import { fileURLToPath } from 'node:url';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const generatorScriptPath = path.join(__dirname, 'tools', 'generate_runtime_core_lock.py');
export const generateRuntimeCoreLock = ({ runtimePython, outputPath }) => {
if (!runtimePython?.absolute) {
throw new Error('Missing runtime Python executable for runtime core lock generation.');
}
if (!outputPath) {
throw new Error('Missing output path for runtime core lock generation.');
}
fs.mkdirSync(path.dirname(outputPath), { recursive: true });
const result = spawnSync(
runtimePython.absolute,
[generatorScriptPath, '--output', outputPath],
{
encoding: 'utf8',
stdio: ['ignore', 'pipe', 'pipe'],
windowsHide: true,
},
);
if (result.error) {
throw new Error(`Failed to generate runtime core lock: ${result.error.message}`);
}
if (result.status !== 0) {
const detail = result.stderr?.trim() || result.stdout?.trim() || `exit code ${result.status}`;
throw new Error(`Runtime core lock generation failed: ${detail}`);
}
if (!fs.existsSync(outputPath)) {
throw new Error(`Runtime core lock generator did not create ${outputPath}`);
}
};