Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
13 changes: 13 additions & 0 deletions src/commands/cli.test.mts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import constants, {
FLAG_CONFIG,
FLAG_DRY_RUN,
FLAG_HELP,
FLAG_VERSION,
} from '../constants.mts'

describe('socket root command', async () => {
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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',
Expand Down
17 changes: 15 additions & 2 deletions src/utils/meow-with-subcommands.mts
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ export async function meowWithSubcommands(
'optimize',
'organization',
'package',
//'patch',
'patch',
// PNPM,
'raw-npm',
'raw-npx',
Expand Down Expand Up @@ -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'])}`,
'',
Expand Down Expand Up @@ -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.
Expand Down
5 changes: 0 additions & 5 deletions test/utils.mts
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,6 @@ function normalizeBanner(str: string): string {
)
// Replace cwd path with "<redacted>".
.replace(/cwd: [^\n"]+/g, 'cwd: <redacted>')
// 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, '')
)
}

Expand Down
Loading