diff --git a/package.json b/package.json index 63013558f..487712e4a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "socket", - "version": "1.1.74", + "version": "1.1.75", "description": "CLI for Socket.dev", "homepage": "https://github.com/SocketDev/socket-cli", "license": "MIT AND OFL-1.1", diff --git a/src/commands/cli.test.mts b/src/commands/cli.test.mts index 245418f9a..9b3986a75 100755 --- a/src/commands/cli.test.mts +++ b/src/commands/cli.test.mts @@ -6,6 +6,7 @@ import constants, { FLAG_CONFIG, FLAG_DRY_RUN, FLAG_HELP, + FLAG_VERSION, } from '../constants.mts' describe('socket root command', async () => { @@ -48,6 +49,7 @@ describe('socket root command', async () => { manifest Generate a dependency manifest for certain ecosystems npm Wraps npm with Socket security scanning npx Wraps npx with Socket security scanning + patch Apply, manage, and rollback Socket security patches for vulnerable dependencies raw-npm Run npm without the Socket wrapper raw-npx Run npx without the Socket wrapper @@ -87,6 +89,17 @@ describe('socket root command', async () => { }, ) + cmdit( + [FLAG_VERSION, FLAG_CONFIG, '{}'], + `should support ${FLAG_VERSION}`, + async cmd => { + const { code, stdout } = await spawnSocketCli(binCliPath, cmd) + // Version output should be a semver string. + expect(stdout).toMatch(/^\d+\.\d+\.\d+/) + expect(code, 'version should exit with code 0').toBe(0) + }, + ) + cmdit( ['mootools', FLAG_DRY_RUN, FLAG_CONFIG, '{"apiToken":"fakeToken"}'], 'should require args with just dry-run', diff --git a/src/utils/meow-with-subcommands.mts b/src/utils/meow-with-subcommands.mts index adf625be3..1b03f5315 100644 --- a/src/utils/meow-with-subcommands.mts +++ b/src/utils/meow-with-subcommands.mts @@ -553,7 +553,7 @@ export async function meowWithSubcommands( 'optimize', 'organization', 'package', - //'patch', + 'patch', // PNPM, 'raw-npm', 'raw-npx', @@ -612,6 +612,7 @@ export async function meowWithSubcommands( ` manifest ${description(subcommands['manifest'])}`, ` npm ${description(subcommands[NPM])}`, ` npx ${description(subcommands[NPX])}`, + ` patch ${description(subcommands['patch'])}`, ` raw-npm ${description(subcommands['raw-npm'])}`, ` raw-npx ${description(subcommands['raw-npx'])}`, '', @@ -743,9 +744,21 @@ export async function meowWithSubcommands( help: lines.map(l => indentString(l, HELP_INDENT)).join('\n'), }) - const { dryRun, help: helpFlag } = cli2.flags as { + const { + dryRun, + help: helpFlag, + version: versionFlag, + } = cli2.flags as { dryRun: boolean help: boolean + version: boolean + } + + // Handle --version: print version and exit successfully. + if (versionFlag) { + logger.log(constants.ENV.INLINED_SOCKET_CLI_VERSION) + process.exitCode = 0 + return } // ...else we provide basic instructions and help. diff --git a/test/utils.mts b/test/utils.mts index fd99d8bf0..5badbc0bf 100644 --- a/test/utils.mts +++ b/test/utils.mts @@ -78,11 +78,6 @@ function normalizeBanner(str: string): string { ) // Replace cwd path with "". .replace(/cwd: [^\n"]+/g, 'cwd: ') - // Strip "Received an unknown command: patch" error line that appears - // when socket-patch binary is not available in the test build. - // Also consume any leading whitespace on the next line so indentation - // stays consistent when the error line is absent. - .replace(/[^\n]*Received an unknown command: patch[^\n]*\n\s*/g, '') ) }