Skip to content

Commit d7ec8c2

Browse files
committed
fix(smol): skip CLI bootstrap for basic Node.js operations
The smol binary's bootstrap was trying to download the Socket CLI on every invocation, including basic Node.js operations like: - node -e '...' (eval mode) - node --version - node --help - node (REPL) This broke the smoke test during build because: 1. Smoke test runs: node -e 'console.log("✓ Binary can execute JavaScript")' 2. Bootstrap intercepts and tries to download @socketsecurity/cli@^X.X.X 3. Package doesn't exist on npm yet (unpublished version) 4. Download fails → build fails Solution: Add shouldSkipCliBootstrap() check that detects: - Eval mode (-e, --eval) - Version/help flags (--version, -v, --help, -h) - REPL mode (no arguments) - Explicit skip (SOCKET_CLI_SKIP_BOOTSTRAP=1) When detected, bootstrap returns 0 and lets Node.js execute normally. This allows: - Smoke tests to pass during build - Using smol binary as a regular Node.js runtime - Testing/debugging without CLI download The CLI bootstrap still runs for actual CLI invocations.
1 parent c87d8fc commit d7ec8c2

File tree

1 file changed

+46
-2
lines changed

1 file changed

+46
-2
lines changed

packages/bootstrap/src/bootstrap-smol.mts

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,60 @@ import '@socketsecurity/cli/src/polyfills/intl-stub/index.mts'
1212

1313
import { findAndExecuteCli, getArgs } from './shared/bootstrap-shared.mjs'
1414

15+
/**
16+
* Check if Node.js is being used for non-CLI purposes.
17+
* Returns true if we should skip CLI bootstrap and let Node.js run normally.
18+
*/
19+
function shouldSkipCliBootstrap() {
20+
const args = process.execArgv.concat(getArgs())
21+
22+
// Skip if running in eval mode (node -e '...')
23+
if (args.includes('-e') || args.includes('--eval')) {
24+
return true
25+
}
26+
27+
// Skip if checking version
28+
if (args.includes('--version') || args.includes('-v')) {
29+
return true
30+
}
31+
32+
// Skip if printing help
33+
if (args.includes('--help') || args.includes('-h')) {
34+
return true
35+
}
36+
37+
// Skip if running REPL (no arguments)
38+
if (args.length === 0) {
39+
return true
40+
}
41+
42+
// Skip if SOCKET_CLI_SKIP_BOOTSTRAP is set (for testing/debugging)
43+
if (process.env.SOCKET_CLI_SKIP_BOOTSTRAP === '1' ||
44+
process.env.SOCKET_CLI_SKIP_BOOTSTRAP === 'true') {
45+
return true
46+
}
47+
48+
return false
49+
}
50+
1551
async function main() {
52+
// Skip bootstrap if Node.js is being used for non-CLI purposes.
53+
if (shouldSkipCliBootstrap()) {
54+
// Let Node.js continue with its normal execution.
55+
return 0
56+
}
57+
1658
const args = getArgs()
1759
return await findAndExecuteCli(args)
1860
}
1961

2062
// Run the bootstrap.
2163
main()
2264
.then((exitCode) => {
23-
// Exit with the code returned by the CLI.
24-
process.exit(exitCode)
65+
// Exit with the code returned by the CLI (or 0 if bootstrap was skipped).
66+
if (exitCode !== 0) {
67+
process.exit(exitCode)
68+
}
2569
})
2670
.catch((e) => {
2771
// Use process.stderr.write() directly to avoid console access during early bootstrap.

0 commit comments

Comments
 (0)