Skip to content

Commit bf6801d

Browse files
committed
Add version checks for Node.js and Python prerequisites
Enforces Node.js >=18 and Python >=3.8 requirements in code rather than just documenting them. Scripts now fail fast with helpful error messages if version requirements are not met.
1 parent ec5d37c commit bf6801d

File tree

2 files changed

+40
-6
lines changed

2 files changed

+40
-6
lines changed

scripts/wasm.mjs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,21 @@ const outputFile = path.join(externalDir, 'socket-ai-sync.mjs')
3030
const GITHUB_REPO = 'SocketDev/socket-cli'
3131
const WASM_ASSET_NAME = 'socket-ai-sync.mjs'
3232

33+
/**
34+
* Check Node.js version requirement.
35+
*/
36+
function checkNodeVersion() {
37+
const nodeVersion = process.versions.node
38+
const major = Number.parseInt(nodeVersion.split('.')[0], 10)
39+
40+
if (major < 18) {
41+
console.error('❌ Node.js version 18 or higher is required')
42+
console.error(` Current version: ${nodeVersion}`)
43+
console.error(' Please upgrade: https://nodejs.org/')
44+
process.exit(1)
45+
}
46+
}
47+
3348
/**
3449
* Show help message.
3550
*/
@@ -41,8 +56,8 @@ function showHelp() {
4156
4257
Commands:
4358
--build Build WASM bundle from source
44-
Requirements: Python 3.8+, Rust, wasm-pack, Homebrew (macOS)
45-
Time: ~10-20 minutes
59+
Requirements: Python 3.8+ (auto-installs packages, Rust, wasm-pack, binaryen)
60+
Time: ~10-20 minutes (first run), ~5 minutes (subsequent)
4661
Size: ~115MB output
4762
4863
--download Download pre-built WASM bundle from GitHub releases
@@ -279,6 +294,9 @@ async function downloadWasm() {
279294
* Main entry point.
280295
*/
281296
async function main() {
297+
// Check Node.js version first.
298+
checkNodeVersion()
299+
282300
const args = process.argv.slice(2)
283301

284302
if (args.length === 0 || args.includes('--help') || args.includes('-h')) {

scripts/wasm/convert-codet5.mjs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,18 @@ console.log('╚═════════════════════
6464
console.log('Step 1: Checking Python installation...\n')
6565

6666
let pythonCmd = 'python3'
67+
let pythonVersion = ''
6768
try {
6869
const pythonResult = await exec(pythonCmd, ['--version'])
69-
const pythonVersion = pythonResult.stdout.trim()
70-
console.log(`✓ Found ${pythonVersion}\n`)
70+
pythonVersion = pythonResult.stdout.trim()
71+
console.log(`✓ Found ${pythonVersion}`)
7172
} catch (_e) {
7273
// Try 'python' as fallback.
7374
try {
74-
await exec('python', ['--version'])
75+
const pythonResult = await exec('python', ['--version'])
76+
pythonVersion = pythonResult.stdout.trim()
7577
pythonCmd = 'python'
76-
console.log('✓ Found Python\n')
78+
console.log(`✓ Found ${pythonVersion}`)
7779
} catch {
7880
console.error('❌ Python 3 not found')
7981
console.error(
@@ -83,6 +85,20 @@ try {
8385
}
8486
}
8587

88+
// Check Python version (need 3.8+).
89+
const versionMatch = pythonVersion.match(/Python (\d+)\.(\d+)/)
90+
if (versionMatch) {
91+
const major = Number.parseInt(versionMatch[1], 10)
92+
const minor = Number.parseInt(versionMatch[2], 10)
93+
94+
if (major < 3 || (major === 3 && minor < 8)) {
95+
console.error(`❌ Python 3.8+ required, found ${pythonVersion}`)
96+
console.error(' Please upgrade: https://www.python.org/downloads/')
97+
process.exit(1)
98+
}
99+
}
100+
console.log()
101+
86102
// Step 2: Check and install required packages.
87103
console.log('Step 2: Checking required packages...\n')
88104

0 commit comments

Comments
 (0)