Skip to content

Commit c572023

Browse files
committed
fix: remaining fixes from PR 1025
- Add prebuild hook and generate-packages.mjs script to ensure template packages are generated before CLI build runs - Always copy cli.js to dist directory (required for dist/index.js to work) - Add Node.js CLI flags whitelist to prevent --help, --version, etc from being forwarded to Python CLI - Remove unused --prod flag from build script - Simplify cli.js copy to use copyFileSync directly instead of spawning node
1 parent 94f7852 commit c572023

File tree

4 files changed

+45
-16
lines changed

4 files changed

+45
-16
lines changed

packages/cli/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"logo-light.png"
1919
],
2020
"scripts": {
21+
"prebuild": "node scripts/generate-packages.mjs",
2122
"build": "node --max-old-space-size=8192 --import=./scripts/load.mjs scripts/build.mjs",
2223
"build:force": "node --max-old-space-size=8192 --import=./scripts/load.mjs scripts/build.mjs --force",
2324
"build:watch": "node --max-old-space-size=8192 --import=./scripts/load.mjs scripts/build.mjs --watch",

packages/cli/scripts/build.mjs

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
/**
22
* Build script for Socket CLI.
3-
* Options: --quiet, --verbose, --prod, --force, --watch
3+
* Options: --quiet, --verbose, --force, --watch
44
*/
55

6+
import { copyFileSync } from 'node:fs'
67
import { promises as fs } from 'node:fs'
78
import path from 'node:path'
89
import { fileURLToPath } from 'node:url'
@@ -97,7 +98,6 @@ async function main() {
9798
const verbose = isVerbose()
9899
const watch = process.argv.includes('--watch')
99100
const force = process.argv.includes('--force')
100-
const prod = process.argv.includes('--prod')
101101

102102
// Pass --force flag via environment variable.
103103
if (force) {
@@ -202,19 +202,6 @@ async function main() {
202202
command: 'node',
203203
args: [...NODE_MEMORY_FLAGS, '.config/esbuild.inject.config.mjs'],
204204
},
205-
// Copy CLI to dist for production builds.
206-
...(prod
207-
? [
208-
{
209-
name: 'Copy CLI to dist',
210-
command: 'node',
211-
args: [
212-
'-e',
213-
'require("fs").copyFileSync("build/cli.js", "dist/cli.js")',
214-
],
215-
},
216-
]
217-
: []),
218205
]
219206

220207
// Run build steps sequentially.
@@ -248,6 +235,9 @@ async function main() {
248235
}
249236
}
250237

238+
// Copy CLI bundle to dist (required for dist/index.js to work).
239+
copyFileSync('build/cli.js', 'dist/cli.js')
240+
251241
// Post-process: Fix node-gyp strings to prevent bundler issues.
252242
if (!quiet && verbose) {
253243
log.info('Post-processing build output...')
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* Generate template-based packages required for CLI build.
3+
* Runs the package generation scripts from package-builder.
4+
*/
5+
6+
import { spawn } from '@socketsecurity/lib/spawn'
7+
8+
const scripts = [
9+
'../package-builder/scripts/generate-cli-sentry-package.mjs',
10+
'../package-builder/scripts/generate-socket-package.mjs',
11+
'../package-builder/scripts/generate-socketbin-packages.mjs',
12+
]
13+
14+
for (const script of scripts) {
15+
const result = await spawn('node', [script], { stdio: 'inherit' })
16+
if (result.code !== 0) {
17+
process.exit(result.code)
18+
}
19+
}

packages/cli/src/utils/cli/with-subcommands.mts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,26 @@ export async function meowWithSubcommands(
615615

616616
// If first arg is a flag (starts with --), try Python CLI forwarding.
617617
// This enables: socket --repo owner/repo --target-path .
618-
if (commandOrAliasName?.startsWith('--')) {
618+
// Exception: Don't forward Node.js CLI built-in flags (help, version, etc).
619+
const nodeCliFlags = new Set([
620+
'--compact-header',
621+
'--config',
622+
'--dry-run',
623+
'--help',
624+
'--help-full',
625+
'--json',
626+
'--markdown',
627+
'--no-banner',
628+
'--no-spinner',
629+
'--nobanner',
630+
'--org',
631+
'--spinner',
632+
'--version',
633+
])
634+
if (
635+
commandOrAliasName?.startsWith('--') &&
636+
!nodeCliFlags.has(commandOrAliasName)
637+
) {
619638
const pythonResult = await spawnSocketPython(argv, {
620639
stdio: 'inherit',
621640
})

0 commit comments

Comments
 (0)