Skip to content

Prep dry-run for fix command #495

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 30, 2025
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
4 changes: 2 additions & 2 deletions src/commands/analytics/cmd-analytics.mts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { getDefaultToken } from '../../utils/sdk.mts'

import type { CliCommandConfig } from '../../utils/meow-with-subcommands.mts'

const { DRY_RUN_BAIL_TEXT } = constants
const { DRY_RUN_BAILING_NOW } = constants

const config: CliCommandConfig = {
commandName: 'analytics',
Expand Down Expand Up @@ -211,7 +211,7 @@ async function run(
}

if (cli.flags['dryRun']) {
logger.log(DRY_RUN_BAIL_TEXT)
logger.log(DRY_RUN_BAILING_NOW)
return
}

Expand Down
4 changes: 2 additions & 2 deletions src/commands/audit-log/cmd-audit-log.mts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { getDefaultToken } from '../../utils/sdk.mts'

import type { CliCommandConfig } from '../../utils/meow-with-subcommands.mts'

const { DRY_RUN_BAIL_TEXT } = constants
const { DRY_RUN_BAILING_NOW } = constants

const config: CliCommandConfig = {
commandName: 'audit-log',
Expand Down Expand Up @@ -144,7 +144,7 @@ async function run(
}

if (cli.flags['dryRun']) {
logger.log(DRY_RUN_BAIL_TEXT)
logger.log(DRY_RUN_BAILING_NOW)
return
}

Expand Down
4 changes: 2 additions & 2 deletions src/commands/cdxgen/cmd-cdxgen.mts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { getFlagListOutput } from '../../utils/output-formatting.mts'

import type { CliCommandConfig } from '../../utils/meow-with-subcommands.mts'

const { DRY_RUN_BAIL_TEXT } = constants
const { DRY_RUN_BAILING_NOW } = constants

// TODO: convert yargs to meow. Or convert all the other things to yargs.
const toLower = (arg: string) => arg.toLowerCase()
Expand Down Expand Up @@ -168,7 +168,7 @@ async function run(
}

if (cli.flags['dryRun']) {
logger.log(DRY_RUN_BAIL_TEXT)
logger.log(DRY_RUN_BAILING_NOW)
return
}

Expand Down
4 changes: 2 additions & 2 deletions src/commands/ci/cmd-ci.mts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { meowOrExit } from '../../utils/meow-with-subcommands.mts'

import type { CliCommandConfig } from '../../utils/meow-with-subcommands.mts'

const { DRY_RUN_BAIL_TEXT } = constants
const { DRY_RUN_BAILING_NOW } = constants

const config: CliCommandConfig = {
commandName: 'ci',
Expand Down Expand Up @@ -48,7 +48,7 @@ async function run(
})

if (cli.flags['dryRun']) {
logger.log(DRY_RUN_BAIL_TEXT)
logger.log(DRY_RUN_BAILING_NOW)
return
}

Expand Down
4 changes: 2 additions & 2 deletions src/commands/config/cmd-config-auto.mts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { getFlagListOutput } from '../../utils/output-formatting.mts'
import type { LocalConfig } from '../../utils/config.mts'
import type { CliCommandConfig } from '../../utils/meow-with-subcommands.mts'

const { DRY_RUN_BAIL_TEXT } = constants
const { DRY_RUN_BAILING_NOW } = constants

const config: CliCommandConfig = {
commandName: 'auto',
Expand Down Expand Up @@ -90,7 +90,7 @@ async function run(
}

if (cli.flags['dryRun']) {
logger.log(DRY_RUN_BAIL_TEXT)
logger.log(DRY_RUN_BAILING_NOW)
return
}

Expand Down
4 changes: 2 additions & 2 deletions src/commands/config/cmd-config-get.mts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { getFlagListOutput } from '../../utils/output-formatting.mts'
import type { LocalConfig } from '../../utils/config.mts'
import type { CliCommandConfig } from '../../utils/meow-with-subcommands.mts'

const { DRY_RUN_BAIL_TEXT } = constants
const { DRY_RUN_BAILING_NOW } = constants

const config: CliCommandConfig = {
commandName: 'get',
Expand Down Expand Up @@ -85,7 +85,7 @@ async function run(
}

if (cli.flags['dryRun']) {
logger.log(DRY_RUN_BAIL_TEXT)
logger.log(DRY_RUN_BAILING_NOW)
return
}

Expand Down
4 changes: 2 additions & 2 deletions src/commands/config/cmd-config-list.mts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { getFlagListOutput } from '../../utils/output-formatting.mts'

import type { CliCommandConfig } from '../../utils/meow-with-subcommands.mts'

const { DRY_RUN_BAIL_TEXT } = constants
const { DRY_RUN_BAILING_NOW } = constants

const config: CliCommandConfig = {
commandName: 'list',
Expand Down Expand Up @@ -78,7 +78,7 @@ async function run(
}

if (cli.flags['dryRun']) {
logger.log(DRY_RUN_BAIL_TEXT)
logger.log(DRY_RUN_BAILING_NOW)
return
}

Expand Down
4 changes: 2 additions & 2 deletions src/commands/config/cmd-config-set.mts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { getFlagListOutput } from '../../utils/output-formatting.mts'
import type { LocalConfig } from '../../utils/config.mts'
import type { CliCommandConfig } from '../../utils/meow-with-subcommands.mts'

const { DRY_RUN_BAIL_TEXT } = constants
const { DRY_RUN_BAILING_NOW } = constants

const config: CliCommandConfig = {
commandName: 'set',
Expand Down Expand Up @@ -98,7 +98,7 @@ async function run(
}

if (cli.flags['dryRun']) {
logger.log(DRY_RUN_BAIL_TEXT)
logger.log(DRY_RUN_BAILING_NOW)
return
}

Expand Down
4 changes: 2 additions & 2 deletions src/commands/config/cmd-config-unset.mts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { getFlagListOutput } from '../../utils/output-formatting.mts'
import type { LocalConfig } from '../../utils/config.mts'
import type { CliCommandConfig } from '../../utils/meow-with-subcommands.mts'

const { DRY_RUN_BAIL_TEXT } = constants
const { DRY_RUN_BAILING_NOW } = constants

const config: CliCommandConfig = {
commandName: 'unset',
Expand Down Expand Up @@ -85,7 +85,7 @@ async function run(
}

if (cli.flags['dryRun']) {
logger.log(DRY_RUN_BAIL_TEXT)
logger.log(DRY_RUN_BAILING_NOW)
return
}

Expand Down
4 changes: 2 additions & 2 deletions src/commands/dependencies/cmd-dependencies.mts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { getDefaultToken } from '../../utils/sdk.mts'

import type { CliCommandConfig } from '../../utils/meow-with-subcommands.mts'

const { DRY_RUN_BAIL_TEXT } = constants
const { DRY_RUN_BAILING_NOW } = constants

const config: CliCommandConfig = {
commandName: 'dependencies',
Expand Down Expand Up @@ -97,7 +97,7 @@ async function run(
}

if (cli.flags['dryRun']) {
logger.log(DRY_RUN_BAIL_TEXT)
logger.log(DRY_RUN_BAILING_NOW)
return
}

Expand Down
4 changes: 2 additions & 2 deletions src/commands/diff-scan/cmd-diff-scan-get.mts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { getDefaultToken } from '../../utils/sdk.mts'

import type { CliCommandConfig } from '../../utils/meow-with-subcommands.mts'

const { DRY_RUN_BAIL_TEXT } = constants
const { DRY_RUN_BAILING_NOW } = constants

const config: CliCommandConfig = {
commandName: 'get',
Expand Down Expand Up @@ -152,7 +152,7 @@ async function run(
)

if (cli.flags['dryRun']) {
logger.log(DRY_RUN_BAIL_TEXT)
logger.log(DRY_RUN_BAILING_NOW)
return
}

Expand Down
9 changes: 0 additions & 9 deletions src/commands/fix/cmd-fix.mts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import terminalLink from 'terminal-link'

import { joinOr } from '@socketsecurity/registry/lib/arrays'
import { logger } from '@socketsecurity/registry/lib/logger'

import { runFix } from './run-fix.mts'
import constants from '../../constants.mts'
import { commonFlags } from '../../flags.mts'
import { getOutputKind } from '../../utils/get-output-kind.mts'
import { checkCommandInput } from '../../utils/handle-bad-input.mts'
Expand All @@ -15,8 +13,6 @@ import { RangeStyles } from '../../utils/semver.mts'
import type { CliCommandConfig } from '../../utils/meow-with-subcommands.mts'
import type { RangeStyle } from '../../utils/semver.mts'

const { DRY_RUN_BAIL_TEXT } = constants

const config: CliCommandConfig = {
commandName: 'fix',
description: 'Update dependencies with "fixable" Socket alerts',
Expand Down Expand Up @@ -113,11 +109,6 @@ async function run(
return
}

if (cli.flags['dryRun']) {
logger.log(DRY_RUN_BAIL_TEXT)
return
}

await runFix({
autoMerge: Boolean(cli.flags['autoMerge']),
autopilot: Boolean(cli.flags['autopilot']),
Expand Down
9 changes: 7 additions & 2 deletions src/commands/fix/cmd-fix.test.mts
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,18 @@
'should require args with just dry-run',
async cmd => {
const { code, stderr, stdout } = await invokeNpm(entryPath, cmd)
expect(stdout).toMatchInlineSnapshot(`"[DryRun]: Bailing now"`)
expect(stdout).toMatchInlineSnapshot(`

Check failure on line 65 in src/commands/fix/cmd-fix.test.mts

View workflow job for this annotation

GitHub Actions / Tests / Test (22, windows-latest)

src/commands/fix/cmd-fix.test.mts > socket fix > should require args with just dry-run: `fix --dry-run --config {"apiToken":"anything"}`

Error: Snapshot `socket fix > should require args with just dry-run: `fix --dry-run --config {"apiToken":"anything"}` 1` mismatched - Expected + Received - "\x1b[34mi\x1b[39m Fixing packages for npm - [DryRun]: Not saving" + "" ❯ src/commands/fix/cmd-fix.test.mts:65:22

Check failure on line 65 in src/commands/fix/cmd-fix.test.mts

View workflow job for this annotation

GitHub Actions / Tests / Test (23, windows-latest)

src/commands/fix/cmd-fix.test.mts > socket fix > should require args with just dry-run: `fix --dry-run --config {"apiToken":"anything"}`

Error: Snapshot `socket fix > should require args with just dry-run: `fix --dry-run --config {"apiToken":"anything"}` 1` mismatched - Expected + Received - "\x1b[34mi\x1b[39m Fixing packages for npm - [DryRun]: Not saving" + "" ❯ src/commands/fix/cmd-fix.test.mts:65:22
"\\x1b[34mi\\x1b[39m Fixing packages for npm
[DryRun]: Not saving"
`)
expect(`\n ${stderr}`).toMatchInlineSnapshot(`

Check failure on line 69 in src/commands/fix/cmd-fix.test.mts

View workflow job for this annotation

GitHub Actions / Tests / Test (22, ubuntu-latest)

src/commands/fix/cmd-fix.test.mts > socket fix > should require args with just dry-run: `fix --dry-run --config {"apiToken":"anything"}`

Error: Snapshot `socket fix > should require args with just dry-run: `fix --dry-run --config {"apiToken":"anything"}` 2` mismatched - Expected + Received @@ -2,6 +2,6 @@ _____ _ _ /--------------- | __|___ ___| |_ ___| |_ | Socket.dev CLI ver <redacted> |__ | * | _| '_| -_| _| | Node: <redacted>, API token set: <redacted> |_____|___|___|_,_|___|_|.dev | Command: `socket fix`, cwd: <redacted> - \x1b[33m\u203c\x1b[39m socket fix: Package package-lock.json found at /Users/jdalton/projects/socket-cli/package-lock.json" + \x1b[33m\u203c\x1b[39m socket fix: Package package-lock.json found at /home/runner/work/socket-cli/socket-cli/package-lock.json" ❯ src/commands/fix/cmd-fix.test.mts:69:32

Check failure on line 69 in src/commands/fix/cmd-fix.test.mts

View workflow job for this annotation

GitHub Actions / Tests / Test (23, ubuntu-latest)

src/commands/fix/cmd-fix.test.mts > socket fix > should require args with just dry-run: `fix --dry-run --config {"apiToken":"anything"}`

Error: Snapshot `socket fix > should require args with just dry-run: `fix --dry-run --config {"apiToken":"anything"}` 2` mismatched - Expected + Received @@ -2,6 +2,6 @@ _____ _ _ /--------------- | __|___ ___| |_ ___| |_ | Socket.dev CLI ver <redacted> |__ | * | _| '_| -_| _| | Node: <redacted>, API token set: <redacted> |_____|___|___|_,_|___|_|.dev | Command: `socket fix`, cwd: <redacted> - \x1b[33m\u203c\x1b[39m socket fix: Package package-lock.json found at /Users/jdalton/projects/socket-cli/package-lock.json" + \x1b[33m\u203c\x1b[39m socket fix: Package package-lock.json found at /home/runner/work/socket-cli/socket-cli/package-lock.json" ❯ src/commands/fix/cmd-fix.test.mts:69:32
"
_____ _ _ /---------------
| __|___ ___| |_ ___| |_ | Socket.dev CLI ver <redacted>
|__ | * | _| '_| -_| _| | Node: <redacted>, API token set: <redacted>
|_____|___|___|_,_|___|_|.dev | Command: \`socket fix\`, cwd: <redacted>"
|_____|___|___|_,_|___|_|.dev | Command: \`socket fix\`, cwd: <redacted>

\\x1b[33m\\u203c\\x1b[39m socket fix: Package package-lock.json found at /Users/jdalton/projects/socket-cli/package-lock.json"
`)

expect(code, 'dry-run should exit with code 0 if input ok').toBe(0)
Expand Down
8 changes: 6 additions & 2 deletions src/commands/fix/npm-fix.mts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ import type { SafeNode } from '../../shadow/npm/arborist/lib/node.mts'
import type { EnvDetails } from '../../utils/package-environment.mts'
import type { PackageJson } from '@socketsecurity/registry/lib/packages'

const { NPM } = constants
const { DRY_RUN_NOT_SAVING, NPM } = constants

type InstallOptions = {
cwd?: string | undefined
Expand All @@ -74,8 +74,12 @@ async function install(

export async function npmFix(
pkgEnvDetails: EnvDetails,
{ autoMerge, cwd, purls, rangeStyle, test, testScript }: NormalizedFixOptions
{ autoMerge, cwd, dryRun, purls, rangeStyle, test, testScript }: NormalizedFixOptions
) {
if (dryRun) {
logger.log(DRY_RUN_NOT_SAVING)
return
}
// Lazily access constants.spinner.
const { spinner } = constants

Expand Down
8 changes: 6 additions & 2 deletions src/commands/fix/pnpm-fix.mts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ import type { LockfileObject } from '@pnpm/lockfile.fs'
import type { PackageJson } from '@socketsecurity/registry/lib/packages'
import type { Spinner } from '@socketsecurity/registry/lib/spinner'

const { NPM, OVERRIDES, PNPM } = constants
const { DRY_RUN_NOT_SAVING, NPM, OVERRIDES, PNPM } = constants

async function getActualTree(cwd: string = process.cwd()): Promise<SafeNode> {
const arb = new SafeArborist({
Expand Down Expand Up @@ -93,8 +93,12 @@ async function readLockfile(pkgPath: string): Promise<LockfileObject | null> {

export async function pnpmFix(
pkgEnvDetails: EnvDetails,
{ autoMerge, cwd, purls, rangeStyle, test, testScript }: NormalizedFixOptions
{ autoMerge, cwd, dryRun, purls, rangeStyle, test, testScript }: NormalizedFixOptions
) {
if (dryRun) {
logger.log(DRY_RUN_NOT_SAVING)
return
}
// Lazily access constants.spinner.
const { spinner } = constants

Expand Down
4 changes: 2 additions & 2 deletions src/commands/info/cmd-info.mts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { getFlagListOutput } from '../../utils/output-formatting.mts'

import type { CliCommandConfig } from '../../utils/meow-with-subcommands.mts'

const { DRY_RUN_BAIL_TEXT } = constants
const { DRY_RUN_BAILING_NOW } = constants

const config: CliCommandConfig = {
commandName: 'info',
Expand Down Expand Up @@ -98,7 +98,7 @@ async function run(
versionSeparator < 1 ? 'latest' : rawPkgName.slice(versionSeparator + 1)

if (cli.flags['dryRun']) {
logger.log(DRY_RUN_BAIL_TEXT)
logger.log(DRY_RUN_BAILING_NOW)
return
}

Expand Down
4 changes: 2 additions & 2 deletions src/commands/login/cmd-login.mts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { getFlagListOutput } from '../../utils/output-formatting.mts'

import type { CliCommandConfig } from '../../utils/meow-with-subcommands.mts'

const { DRY_RUN_BAIL_TEXT } = constants
const { DRY_RUN_BAILING_NOW } = constants

const config: CliCommandConfig = {
commandName: 'login',
Expand Down Expand Up @@ -67,7 +67,7 @@ async function run(
const apiProxy = cli.flags['apiProxy'] as string | undefined

if (cli.flags['dryRun']) {
logger.log(DRY_RUN_BAIL_TEXT)
logger.log(DRY_RUN_BAILING_NOW)
return
}

Expand Down
4 changes: 2 additions & 2 deletions src/commands/logout/cmd-logout.mts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { meowOrExit } from '../../utils/meow-with-subcommands.mts'

import type { CliCommandConfig } from '../../utils/meow-with-subcommands.mts'

const { DRY_RUN_BAIL_TEXT } = constants
const { DRY_RUN_BAILING_NOW } = constants

const config: CliCommandConfig = {
commandName: 'logout',
Expand Down Expand Up @@ -43,7 +43,7 @@ async function run(
})

if (cli.flags['dryRun']) {
logger.log(DRY_RUN_BAIL_TEXT)
logger.log(DRY_RUN_BAILING_NOW)
return
}

Expand Down
10 changes: 5 additions & 5 deletions src/commands/manifest/cmd-manifest-auto.mts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { getFlagListOutput } from '../../utils/output-formatting.mts'

import type { CliCommandConfig } from '../../utils/meow-with-subcommands.mts'

const { DRY_RUN_BAIL_TEXT } = constants
const { DRY_RUN_BAILING_NOW } = constants

const config: CliCommandConfig = {
commandName: 'auto',
Expand Down Expand Up @@ -91,7 +91,7 @@ async function run(
}
subArgs.push(dir)
if (cli.flags['dryRun']) {
logger.log(DRY_RUN_BAIL_TEXT)
logger.log(DRY_RUN_BAILING_NOW)
return
}
await cmdManifestScala.run(subArgs, importMeta, { parentName })
Expand All @@ -105,7 +105,7 @@ async function run(
subArgs.push(cwd)
}
if (cli.flags['dryRun']) {
logger.log(DRY_RUN_BAIL_TEXT)
logger.log(DRY_RUN_BAILING_NOW)
return
}
await cmdManifestGradle.run(subArgs, importMeta, { parentName })
Expand All @@ -123,15 +123,15 @@ async function run(
// This command takes the TARGET as first arg.
subArgs.push(hasEnvyml ? envyml : hasEnvyaml ? envyaml : '')
if (cli.flags['dryRun']) {
logger.log(DRY_RUN_BAIL_TEXT)
logger.log(DRY_RUN_BAILING_NOW)
return
}
await cmdManifestConda.run(subArgs, importMeta, { parentName })
return
}

if (cli.flags['dryRun']) {
logger.log(DRY_RUN_BAIL_TEXT)
logger.log(DRY_RUN_BAILING_NOW)
return
}

Expand Down
Loading
Loading