Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"logo-light.png"
],
"scripts": {
"prebuild": "node scripts/generate-packages.mjs",
"build": "node --max-old-space-size=8192 --import=./scripts/load.mjs scripts/build.mjs",
"build:force": "node --max-old-space-size=8192 --import=./scripts/load.mjs scripts/build.mjs --force",
"build:watch": "node --max-old-space-size=8192 --import=./scripts/load.mjs scripts/build.mjs --watch",
Expand Down
20 changes: 5 additions & 15 deletions packages/cli/scripts/build.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/**
* Build script for Socket CLI.
* Options: --quiet, --verbose, --prod, --force, --watch
* Options: --quiet, --verbose, --force, --watch
*/

import { copyFileSync } from 'node:fs'
import { promises as fs } from 'node:fs'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
Expand Down Expand Up @@ -97,7 +98,6 @@ async function main() {
const verbose = isVerbose()
const watch = process.argv.includes('--watch')
const force = process.argv.includes('--force')
const prod = process.argv.includes('--prod')

// Pass --force flag via environment variable.
if (force) {
Expand Down Expand Up @@ -202,19 +202,6 @@ async function main() {
command: 'node',
args: [...NODE_MEMORY_FLAGS, '.config/esbuild.inject.config.mjs'],
},
// Copy CLI to dist for production builds.
...(prod
? [
{
name: 'Copy CLI to dist',
command: 'node',
args: [
'-e',
'require("fs").copyFileSync("build/cli.js", "dist/cli.js")',
],
},
]
: []),
]

// Run build steps sequentially.
Expand Down Expand Up @@ -248,6 +235,9 @@ async function main() {
}
}

// Copy CLI bundle to dist (required for dist/index.js to work).
copyFileSync('build/cli.js', 'dist/cli.js')

// Post-process: Fix node-gyp strings to prevent bundler issues.
if (!quiet && verbose) {
log.info('Post-processing build output...')
Expand Down
19 changes: 19 additions & 0 deletions packages/cli/scripts/generate-packages.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Generate template-based packages required for CLI build.
* Runs the package generation scripts from package-builder.
*/

import { spawn } from '@socketsecurity/lib/spawn'

const scripts = [
'../package-builder/scripts/generate-cli-sentry-package.mjs',
'../package-builder/scripts/generate-socket-package.mjs',
'../package-builder/scripts/generate-socketbin-packages.mjs',
]

for (const script of scripts) {
const result = await spawn('node', [script], { stdio: 'inherit' })
if (result.code !== 0) {
process.exit(result.code)
Comment thread
jdalton marked this conversation as resolved.
Outdated
}
}
21 changes: 20 additions & 1 deletion packages/cli/src/utils/cli/with-subcommands.mts
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,26 @@ export async function meowWithSubcommands(

// If first arg is a flag (starts with --), try Python CLI forwarding.
// This enables: socket --repo owner/repo --target-path .
if (commandOrAliasName?.startsWith('--')) {
// Exception: Don't forward Node.js CLI built-in flags (help, version, etc).
const nodeCliFlags = new Set([
'--compact-header',
'--config',
'--dry-run',
'--help',
'--help-full',
'--json',
'--markdown',
'--no-banner',
'--no-spinner',
'--nobanner',
'--org',
'--spinner',
'--version',
])
if (
commandOrAliasName?.startsWith('--') &&
!nodeCliFlags.has(commandOrAliasName)
) {
Comment thread
jdalton marked this conversation as resolved.
const pythonResult = await spawnSocketPython(argv, {
stdio: 'inherit',
})
Expand Down