@socketsecurity/cli-with-sentry 0.14.129 → 0.14.130

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -917,7 +917,7 @@ function emitBanner(name) {
917
917
  logger.logger.error(getAsciiHeader(name))
918
918
  }
919
919
  function getAsciiHeader(command) {
920
- const cliVersion = '0.14.129:a3be3d1:d8cba126:pub' // The '@rollup/plugin-replace' will replace "process.env['INLINED_SOCKET_CLI_VERSION_HASH']".
920
+ const cliVersion = '0.14.130:6d76a8a:3ff78b98:pub' // The '@rollup/plugin-replace' will replace "process.env['INLINED_SOCKET_CLI_VERSION_HASH']".
921
921
  const nodeVersion = process$1.version
922
922
  const apiToken = shadowNpmInject.getDefaultToken()
923
923
  const defaultOrg = shadowNpmInject.getConfigValue('defaultOrg')
@@ -3788,29 +3788,6 @@ async function gitBranchExists(branch, cwd = process.cwd()) {
3788
3788
  } catch {}
3789
3789
  return false
3790
3790
  }
3791
- async function gitCheckoutBaseBranchIfAvailable(
3792
- baseBranch,
3793
- cwd = process.cwd()
3794
- ) {
3795
- try {
3796
- await gitHardReset()
3797
- await spawn.spawn('git', ['fetch', '--depth=1', 'origin', baseBranch], {
3798
- cwd
3799
- })
3800
- await spawn.spawn('git', ['checkout', baseBranch], {
3801
- cwd
3802
- })
3803
- await spawn.spawn('git', ['reset', '--hard', `origin/${baseBranch}`], {
3804
- cwd
3805
- })
3806
- logger.logger.info(`Checked out and reset to ${baseBranch}`)
3807
- } catch (e) {
3808
- logger.logger.warn(
3809
- `Could not switch to ${baseBranch}. Proceeding with HEAD.`
3810
- )
3811
- debug.debugLog(e)
3812
- }
3813
- }
3814
3791
  async function gitCleanFdx(cwd = process.cwd()) {
3815
3792
  await spawn.spawn('git', ['clean', '-fdx'], {
3816
3793
  cwd
@@ -4005,45 +3982,69 @@ async function openGitHubPullRequest(
4005
3982
  throw new Error('Missing GITHUB_ACTIONS environment variable')
4006
3983
  }
4007
3984
 
3985
+ const CMD_NAME$1 = 'socket fix'
3986
+ const alertMapOptions = Object.freeze({
3987
+ consolidate: true,
3988
+ include: {
3989
+ existing: true,
3990
+ unfixable: false,
3991
+ upgradable: false
3992
+ },
3993
+ nothrow: true
3994
+ })
3995
+ function assignDefaultFixOptions(options) {
3996
+ if (options.autoPilot === undefined) {
3997
+ options.autoPilot = false
3998
+ }
3999
+ if (options.autoMerge === undefined) {
4000
+ options.autoMerge = !!options.autoPilot
4001
+ }
4002
+ if (options.cwd === undefined) {
4003
+ options.cwd = process.cwd()
4004
+ }
4005
+ if (options.rangeStyle === undefined) {
4006
+ options.rangeStyle = 'preserve'
4007
+ }
4008
+ if (options.test === undefined) {
4009
+ options.test = !!options.autoPilot || !!options.testScript
4010
+ }
4011
+ if (options.testScript === undefined) {
4012
+ options.testScript = 'test'
4013
+ }
4014
+ return options
4015
+ }
4016
+
4008
4017
  const { CI: CI$1, NPM: NPM$f } = constants
4009
4018
  async function install$1(idealTree, options) {
4010
4019
  const { cwd = process.cwd() } = {
4011
4020
  __proto__: null,
4012
4021
  ...options
4013
4022
  }
4014
- const arb2 = new shadowNpmInject.Arborist({
4023
+ const arb = new shadowNpmInject.Arborist({
4015
4024
  path: cwd
4016
4025
  })
4017
- arb2.idealTree = idealTree
4018
- await arb2.reify()
4026
+ arb.idealTree = idealTree
4027
+ await arb.reify()
4019
4028
  }
4020
4029
  async function npmFix(
4021
4030
  pkgEnvDetails,
4022
4031
  { autoMerge, cwd, purls, rangeStyle, spinner, test, testScript }
4023
4032
  ) {
4024
- const { pkgPath: rootPath } = pkgEnvDetails
4025
4033
  spinner?.start()
4034
+ const { pkgPath: rootPath } = pkgEnvDetails
4026
4035
  const arb = new shadowNpmInject.SafeArborist({
4027
4036
  path: rootPath,
4028
4037
  ...shadowNpmInject.SAFE_ARBORIST_REIFY_OPTIONS_OVERRIDES
4029
4038
  })
4030
4039
  // Calling arb.reify() creates the arb.diff object and nulls-out arb.idealTree.
4031
4040
  await arb.reify()
4032
- const alertMapOptions = {
4033
- consolidate: true,
4034
- include: {
4035
- existing: true,
4036
- unfixable: false,
4037
- upgradable: false
4038
- },
4039
- nothrow: true
4040
- }
4041
4041
  const alertsMap = purls.length
4042
4042
  ? await shadowNpmInject.getAlertsMapFromPurls(purls, alertMapOptions)
4043
4043
  : await shadowNpmInject.getAlertsMapFromArborist(arb, alertMapOptions)
4044
4044
  const infoByPkg = shadowNpmInject.getCveInfoByAlertsMap(alertsMap)
4045
4045
  if (!infoByPkg) {
4046
4046
  spinner?.stop()
4047
+ logger.logger.info('No fixable vulnerabilities found.')
4047
4048
  return
4048
4049
  }
4049
4050
 
@@ -4059,123 +4060,104 @@ async function npmFix(
4059
4060
  pkgEnvDetails.editablePkgJson.filename
4060
4061
  ]
4061
4062
  for (const { 0: name, 1: infos } of infoByPkg) {
4062
- const hasUpgrade = !!registry.getManifestData(NPM$f, name)
4063
- if (hasUpgrade) {
4064
- spinner?.info(`Skipping ${name}. Socket Optimize package exists.`)
4063
+ debug.debugLog(`Processing vulnerable package: ${name}`)
4064
+ if (registry.getManifestData(NPM$f, name)) {
4065
+ spinner?.info(`Socket Optimize package for ${name} exists, skipping`)
4066
+ continue
4067
+ }
4068
+ if (!infos.length) {
4069
+ debug.debugLog(`No vulnerability info found for ${name}`)
4065
4070
  continue
4066
4071
  }
4067
- arb.idealTree = null
4068
4072
  // eslint-disable-next-line no-await-in-loop
4069
- await arb.buildIdealTree()
4070
- const oldVersions = arrays.arrayUnique(
4071
- shadowNpmInject
4072
- .findPackageNodes(arb.idealTree, name)
4073
- .map(n => n.target?.version ?? n.version)
4074
- .filter(Boolean)
4075
- )
4076
- const packument =
4077
- oldVersions.length && infos.length
4078
- ? // eslint-disable-next-line no-await-in-loop
4079
- await packages.fetchPackagePackument(name)
4080
- : null
4073
+ const packument = await packages.fetchPackagePackument(name)
4081
4074
  if (!packument) {
4075
+ debug.debugLog(`No packument found for ${name}`)
4082
4076
  continue
4083
4077
  }
4084
- const failedSpecs = new Set()
4078
+ const availableVersions = Object.keys(packument.versions)
4085
4079
  const fixedSpecs = new Set()
4086
- const installedSpecs = new Set()
4087
- const testedSpecs = new Set()
4088
- const unavailableSpecs = new Set()
4089
- const revertedSpecs = new Set()
4090
4080
  for (const pkgJsonPath of pkgJsonPaths) {
4081
+ const pkgPath = path$1.dirname(pkgJsonPath)
4082
+ const isWorkspaceRoot =
4083
+ pkgJsonPath === pkgEnvDetails.editablePkgJson.filename
4084
+ const workspaceName = isWorkspaceRoot
4085
+ ? 'root'
4086
+ : path$1.relative(rootPath, pkgPath)
4087
+ debug.debugLog(`Checking workspace: ${workspaceName}`)
4088
+ arb.idealTree = null
4089
+ // eslint-disable-next-line no-await-in-loop
4090
+ await arb.buildIdealTree()
4091
+ const oldVersions = arrays.arrayUnique(
4092
+ shadowNpmInject
4093
+ .findPackageNodes(arb.idealTree, name)
4094
+ .map(n => n.target?.version ?? n.version)
4095
+ .filter(Boolean)
4096
+ )
4097
+ if (!oldVersions.length) {
4098
+ debug.debugLog(`Lockfile entries not found for ${name}`)
4099
+ continue
4100
+ }
4101
+
4102
+ // Always re-read the editable package.json to avoid stale mutations
4103
+ // across iterations.
4104
+ // eslint-disable-next-line no-await-in-loop
4105
+ const editablePkgJson = await packages.readPackageJson(pkgJsonPath, {
4106
+ editable: true
4107
+ })
4091
4108
  for (const oldVersion of oldVersions) {
4092
4109
  const oldSpec = `${name}@${oldVersion}`
4093
4110
  const oldPurl = `pkg:npm/${oldSpec}`
4111
+ const node = shadowNpmInject.findPackageNode(
4112
+ arb.idealTree,
4113
+ name,
4114
+ oldVersion
4115
+ )
4116
+ if (!node) {
4117
+ debug.debugLog(`Arborist node not found, skipping ${oldSpec}`)
4118
+ continue
4119
+ }
4094
4120
  for (const {
4095
4121
  firstPatchedVersionIdentifier,
4096
4122
  vulnerableVersionRange
4097
4123
  } of infos) {
4098
- const revertTree = arb.idealTree
4099
- arb.idealTree = null
4100
- // eslint-disable-next-line no-await-in-loop
4101
- await arb.buildIdealTree()
4102
- const node = shadowNpmInject.findPackageNode(
4103
- arb.idealTree,
4104
- name,
4105
- oldVersion
4124
+ const newVersion = shadowNpmInject.findBestPatchVersion(
4125
+ node,
4126
+ availableVersions,
4127
+ vulnerableVersionRange
4106
4128
  )
4107
- if (!node) {
4108
- debug.debugLog(
4109
- `Skipping ${oldSpec}, no node found in arborist.idealTree`,
4110
- pkgJsonPath
4111
- )
4112
- continue
4113
- }
4114
- if (
4115
- !shadowNpmInject.updateNode(node, packument, vulnerableVersionRange)
4116
- ) {
4117
- if (!unavailableSpecs.has(oldSpec)) {
4118
- unavailableSpecs.add(oldSpec)
4119
- spinner?.fail(`No update available for ${oldSpec}`)
4120
- }
4129
+ const newVersionPackument = newVersion
4130
+ ? packument.versions[newVersion]
4131
+ : undefined
4132
+ if (!(newVersion && newVersionPackument)) {
4133
+ spinner?.fail(`No update found for ${oldSpec}.`)
4121
4134
  continue
4122
4135
  }
4123
- const isWorkspaceRoot =
4124
- pkgJsonPath === pkgEnvDetails.editablePkgJson.filename
4125
- const workspaceName = isWorkspaceRoot
4126
- ? ''
4127
- : path$1.relative(rootPath, path$1.dirname(pkgJsonPath))
4128
- const workspaceDetails = workspaceName ? ` in ${workspaceName}` : ''
4129
- const editablePkgJson = isWorkspaceRoot
4130
- ? pkgEnvDetails.editablePkgJson
4131
- : // eslint-disable-next-line no-await-in-loop
4132
- await packages.readPackageJson(pkgJsonPath, {
4133
- editable: true
4134
- })
4135
- const newVersion = node.package.version
4136
4136
  const newVersionRange = shadowNpmInject.applyRange(
4137
4137
  oldVersion,
4138
4138
  newVersion,
4139
4139
  rangeStyle
4140
4140
  )
4141
4141
  const newSpec = `${name}@${newVersionRange}`
4142
- const newSpecKey = `${workspaceName ? `${workspaceName}>` : ''}${newSpec}`
4143
- const revertData = {
4144
- ...(editablePkgJson.content.dependencies
4145
- ? {
4146
- dependencies: editablePkgJson.content.dependencies
4147
- }
4148
- : undefined),
4149
- ...(editablePkgJson.content.optionalDependencies
4150
- ? {
4151
- optionalDependencies:
4152
- editablePkgJson.content.optionalDependencies
4153
- }
4154
- : undefined),
4155
- ...(editablePkgJson.content.peerDependencies
4156
- ? {
4157
- peerDependencies: editablePkgJson.content.peerDependencies
4158
- }
4159
- : undefined)
4142
+ const newSpecKey = `${workspaceName}:${newSpec}`
4143
+ if (fixedSpecs.has(newSpecKey)) {
4144
+ debug.debugLog(
4145
+ `Already fixed ${newSpec} in ${workspaceName}, skipping`
4146
+ )
4147
+ continue
4160
4148
  }
4161
- const branch = isCi
4162
- ? getSocketBranchName(oldPurl, newVersion, workspaceName)
4163
- : ''
4164
- const baseBranch = isCi ? getBaseGitBranch() : ''
4165
- const { owner, repo } = isCi
4166
- ? getGitHubEnvRepoInfo()
4167
- : {
4168
- owner: '',
4169
- repo: ''
4170
- }
4171
- const shouldOpenPr = isCi
4172
- ? // eslint-disable-next-line no-await-in-loop
4173
- !(await doesPullRequestExistForBranch(owner, repo, branch))
4174
- : false
4175
- if (isCi) {
4176
- // eslint-disable-next-line no-await-in-loop
4177
- await gitCheckoutBaseBranchIfAvailable(baseBranch, cwd)
4149
+ const revertData = {
4150
+ ...(editablePkgJson.content.dependencies && {
4151
+ dependencies: editablePkgJson.content.dependencies
4152
+ }),
4153
+ ...(editablePkgJson.content.optionalDependencies && {
4154
+ optionalDependencies: editablePkgJson.content.optionalDependencies
4155
+ }),
4156
+ ...(editablePkgJson.content.peerDependencies && {
4157
+ peerDependencies: editablePkgJson.content.peerDependencies
4158
+ })
4178
4159
  }
4160
+ shadowNpmInject.updateNode(node, newVersion, newVersionPackument)
4179
4161
  shadowNpmInject.updatePackageJsonFromNode(
4180
4162
  editablePkgJson,
4181
4163
  arb.idealTree,
@@ -4183,105 +4165,110 @@ async function npmFix(
4183
4165
  newVersion,
4184
4166
  rangeStyle
4185
4167
  )
4186
- let error
4187
- let errored = false
4188
- let saved = false
4189
-
4190
4168
  // eslint-disable-next-line no-await-in-loop
4191
- if (await editablePkgJson.save()) {
4192
- saved = true
4193
- }
4194
- if (!installedSpecs.has(newSpecKey)) {
4195
- testedSpecs.add(newSpecKey)
4196
- spinner?.info(`Installing ${newSpec}${workspaceDetails}`)
4169
+ if (!(await editablePkgJson.save())) {
4170
+ debug.debugLog(
4171
+ `Nothing changed for ${workspaceName}, skipping install`
4172
+ )
4173
+ continue
4197
4174
  }
4175
+ spinner?.info(`Installing ${newSpec} in ${workspaceName}`)
4176
+ let error
4177
+ let errored = false
4198
4178
  try {
4199
4179
  // eslint-disable-next-line no-await-in-loop
4200
4180
  await install$1(arb.idealTree, {
4201
4181
  cwd
4202
4182
  })
4203
4183
  if (test) {
4204
- if (!testedSpecs.has(newSpecKey)) {
4205
- testedSpecs.add(newSpecKey)
4206
- spinner?.info(`Testing ${newSpec}${workspaceDetails}`)
4207
- }
4184
+ spinner?.info(`Testing ${newSpec} in ${workspaceName}`)
4208
4185
  // eslint-disable-next-line no-await-in-loop
4209
4186
  await npm.runScript(testScript, [], {
4210
4187
  spinner,
4211
4188
  stdio: 'ignore'
4212
4189
  })
4213
4190
  }
4214
- if (!fixedSpecs.has(newSpecKey)) {
4215
- fixedSpecs.add(newSpecKey)
4216
- spinner?.successAndStop(`Fixed ${name}${workspaceDetails}`)
4217
- spinner?.start()
4218
- }
4191
+ fixedSpecs.add(newSpecKey)
4192
+ spinner?.successAndStop(`Fixed ${name} in ${workspaceName}`)
4193
+ spinner?.start()
4219
4194
  } catch (e) {
4220
- error = e
4221
4195
  errored = true
4196
+ error = e
4222
4197
  }
4223
- if (
4224
- !errored &&
4225
- shouldOpenPr &&
4226
- // eslint-disable-next-line no-await-in-loop
4227
- (await gitCreateAndPushBranchIfNeeded(
4228
- branch,
4229
- getSocketCommitMessage(oldPurl, newVersion, workspaceName),
4230
- cwd
4231
- ))
4232
- ) {
4233
- // eslint-disable-next-line no-await-in-loop
4234
- const prResponse = await openGitHubPullRequest(
4235
- owner,
4236
- repo,
4237
- baseBranch,
4238
- branch,
4198
+ const baseBranch = isCi ? getBaseGitBranch() : ''
4199
+ if (!errored && isCi) {
4200
+ const branch = getSocketBranchName(
4239
4201
  oldPurl,
4240
4202
  newVersion,
4241
- {
4242
- cwd,
4243
- workspaceName
4244
- }
4203
+ workspaceName
4245
4204
  )
4246
- if (prResponse) {
4247
- const { data } = prResponse
4248
- spinner?.info(`PR #${data.number} opened.`)
4249
- if (autoMerge) {
4205
+ try {
4206
+ const { owner, repo } = getGitHubEnvRepoInfo()
4207
+ if (
4250
4208
  // eslint-disable-next-line no-await-in-loop
4251
- await enableAutoMerge(data)
4209
+ (await doesPullRequestExistForBranch(owner, repo, branch)) ||
4210
+ // eslint-disable-next-line no-await-in-loop
4211
+ !(await gitCreateAndPushBranchIfNeeded(
4212
+ branch,
4213
+ getSocketCommitMessage(oldPurl, newVersion, workspaceName),
4214
+ cwd
4215
+ ))
4216
+ ) {
4217
+ continue
4252
4218
  }
4253
- }
4254
- }
4255
- if (errored || isCi) {
4256
- if (errored) {
4257
- if (!revertedSpecs.has(newSpecKey)) {
4258
- revertedSpecs.add(newSpecKey)
4259
- spinner?.error(`Reverting ${newSpec}${workspaceDetails}`, error)
4219
+ // eslint-disable-next-line no-await-in-loop
4220
+ const prResponse = await openGitHubPullRequest(
4221
+ owner,
4222
+ repo,
4223
+ baseBranch,
4224
+ branch,
4225
+ oldPurl,
4226
+ newVersion,
4227
+ {
4228
+ cwd,
4229
+ workspaceName
4230
+ }
4231
+ )
4232
+ if (prResponse) {
4233
+ const { data } = prResponse
4234
+ spinner?.info(`Opened PR #${data.number}.`)
4235
+ if (autoMerge) {
4236
+ // eslint-disable-next-line no-await-in-loop
4237
+ await enableAutoMerge(data)
4238
+ }
4260
4239
  }
4240
+ } catch (e) {
4241
+ error = e
4242
+ errored = true
4261
4243
  }
4262
- if (saved) {
4263
- editablePkgJson.update(revertData)
4264
- }
4244
+ }
4245
+ if (isCi) {
4265
4246
  // eslint-disable-next-line no-await-in-loop
4266
- await Promise.all([
4267
- shadowNpmInject.removeNodeModules(cwd),
4268
- ...(isCi
4269
- ? [gitCheckoutBaseBranchIfAvailable(baseBranch, cwd)]
4270
- : []),
4271
- ...(saved && !isCi ? [editablePkgJson.save()] : [])
4272
- ])
4247
+ await gitHardReset(baseBranch, cwd)
4248
+ // eslint-disable-next-line no-await-in-loop
4249
+ await gitCleanFdx(cwd)
4273
4250
  // eslint-disable-next-line no-await-in-loop
4274
- await install$1(revertTree, {
4251
+ await install$1(arb.idealTree, {
4275
4252
  cwd
4276
4253
  })
4277
- if (errored) {
4278
- if (!failedSpecs.has(newSpecKey)) {
4279
- failedSpecs.add(newSpecKey)
4280
- spinner?.failAndStop(
4281
- `Update failed for ${oldSpec}${workspaceDetails}`
4282
- )
4283
- }
4254
+ }
4255
+ if (errored) {
4256
+ if (!isCi) {
4257
+ editablePkgJson.update(revertData)
4258
+ // eslint-disable-next-line no-await-in-loop
4259
+ await Promise.all([
4260
+ shadowNpmInject.removeNodeModules(cwd),
4261
+ editablePkgJson.save()
4262
+ ])
4263
+ // eslint-disable-next-line no-await-in-loop
4264
+ await install$1(arb.idealTree, {
4265
+ cwd
4266
+ })
4284
4267
  }
4268
+ spinner?.failAndStop(
4269
+ `Update failed for ${oldSpec} in ${workspaceName}`,
4270
+ error
4271
+ )
4285
4272
  }
4286
4273
  }
4287
4274
  }
@@ -4439,25 +4426,29 @@ async function install(pkgEnvDetails, options) {
4439
4426
  })
4440
4427
  return await getActualTree(cwd)
4441
4428
  }
4429
+ async function readLockfile(pkgPath) {
4430
+ return await vendor.libExports$3.readWantedLockfile(pkgPath, {
4431
+ ignoreIncompatible: false
4432
+ })
4433
+ }
4442
4434
  async function pnpmFix(
4443
4435
  pkgEnvDetails,
4444
4436
  { autoMerge, cwd, purls, rangeStyle, spinner, test, testScript }
4445
4437
  ) {
4438
+ spinner?.start()
4446
4439
  const { pkgPath: rootPath } = pkgEnvDetails
4447
- const lockfile = await vendor.libExports$3.readWantedLockfile(rootPath, {
4448
- ignoreIncompatible: false
4449
- })
4440
+ let lockfile = await readLockfile(rootPath)
4450
4441
  if (!lockfile) {
4451
- return
4452
- }
4453
- const alertMapOptions = {
4454
- consolidate: true,
4455
- include: {
4456
- existing: true,
4457
- unfixable: false,
4458
- upgradable: false
4459
- },
4460
- nothrow: true
4442
+ await install(pkgEnvDetails, {
4443
+ cwd,
4444
+ spinner
4445
+ })
4446
+ lockfile = await readLockfile(rootPath)
4447
+ if (!lockfile) {
4448
+ spinner?.stop()
4449
+ logger.logger.error('Required pnpm-lock.yaml not found.')
4450
+ return
4451
+ }
4461
4452
  }
4462
4453
  const alertsMap = purls.length
4463
4454
  ? await shadowNpmInject.getAlertsMapFromPurls(purls, alertMapOptions)
@@ -4467,9 +4458,10 @@ async function pnpmFix(
4467
4458
  )
4468
4459
  const infoByPkg = shadowNpmInject.getCveInfoByAlertsMap(alertsMap)
4469
4460
  if (!infoByPkg) {
4461
+ spinner?.stop()
4462
+ logger.logger.info('No fixable vulnerabilities found.')
4470
4463
  return
4471
4464
  }
4472
- spinner?.start()
4473
4465
 
4474
4466
  // Lazily access constants.ENV[CI].
4475
4467
  const isCi = constants.ENV[CI]
@@ -4477,13 +4469,6 @@ async function pnpmFix(
4477
4469
  pkgEnvDetails.agent,
4478
4470
  rootPath
4479
4471
  )
4480
- const baseBranch = isCi ? getBaseGitBranch() : ''
4481
- const { owner, repo } = isCi
4482
- ? getGitHubEnvRepoInfo()
4483
- : {
4484
- owner: '',
4485
- repo: ''
4486
- }
4487
4472
  const pkgJsonPaths = [
4488
4473
  ...workspacePkgJsonPaths,
4489
4474
  // Process the workspace root last since it will add an override to package.json.
@@ -4492,44 +4477,52 @@ async function pnpmFix(
4492
4477
  for (const { 0: name, 1: infos } of infoByPkg) {
4493
4478
  debug.debugLog(`Processing vulnerable package: ${name}`)
4494
4479
  if (registry.getManifestData(NPM$c, name)) {
4495
- spinner?.info(`Skipping ${name}. Socket Optimize package exists.`)
4480
+ spinner?.info(`Socket Optimize package for ${name} exists, skipping`)
4496
4481
  continue
4497
4482
  }
4483
+ if (!infos.length) {
4484
+ debug.debugLog(`No vulnerability info found for ${name}`)
4485
+ continue
4486
+ }
4487
+ // eslint-disable-next-line no-await-in-loop
4488
+ const packument = await packages.fetchPackagePackument(name)
4489
+ if (!packument) {
4490
+ debug.debugLog(`No packument found for ${name}`)
4491
+ continue
4492
+ }
4493
+ const availableVersions = Object.keys(packument.versions)
4498
4494
  const fixedSpecs = new Set()
4499
4495
  for (const pkgJsonPath of pkgJsonPaths) {
4500
- debug.debugLog(`Checking workspace: ${pkgJsonPath}`)
4501
-
4502
- // eslint-disable-next-line no-await-in-loop
4503
- let actualTree = await getActualTree(cwd)
4496
+ const pkgPath = path$1.dirname(pkgJsonPath)
4504
4497
  const isWorkspaceRoot =
4505
4498
  pkgJsonPath === pkgEnvDetails.editablePkgJson.filename
4506
4499
  const workspaceName = isWorkspaceRoot
4507
4500
  ? 'root'
4508
- : path$1.relative(rootPath, path$1.dirname(pkgJsonPath))
4501
+ : path$1.relative(rootPath, pkgPath)
4502
+ debug.debugLog(`Checking workspace: ${workspaceName}`)
4509
4503
 
4510
- // Always re-read the editable package.json to avoid stale mutations across iterations
4511
4504
  // eslint-disable-next-line no-await-in-loop
4512
- const editablePkgJson = await packages.readPackageJson(pkgJsonPath, {
4513
- editable: true
4514
- })
4515
-
4516
- // Get current overrides for revert logic
4517
- const oldPnpmSection = editablePkgJson.content[PNPM$8]
4518
- const oldOverrides = oldPnpmSection?.[OVERRIDES$2]
4505
+ let actualTree = await getActualTree(cwd)
4519
4506
  const oldVersions = arrays.arrayUnique(
4520
4507
  shadowNpmInject
4521
4508
  .findPackageNodes(actualTree, name)
4522
4509
  .map(n => n.target?.version ?? n.version)
4523
4510
  .filter(Boolean)
4524
4511
  )
4525
- const packument =
4526
- oldVersions.length && infos.length
4527
- ? // eslint-disable-next-line no-await-in-loop
4528
- await packages.fetchPackagePackument(name)
4529
- : null
4530
- if (!packument) {
4512
+ if (!oldVersions.length) {
4513
+ debug.debugLog(`Lockfile entries not found for ${name}`)
4531
4514
  continue
4532
4515
  }
4516
+
4517
+ // Always re-read the editable package.json to avoid stale mutations
4518
+ // across iterations.
4519
+ // eslint-disable-next-line no-await-in-loop
4520
+ const editablePkgJson = await packages.readPackageJson(pkgJsonPath, {
4521
+ editable: true
4522
+ })
4523
+ // Get current overrides for revert logic
4524
+ const oldPnpmSection = editablePkgJson.content[PNPM$8]
4525
+ const oldOverrides = oldPnpmSection?.[OVERRIDES$2]
4533
4526
  for (const oldVersion of oldVersions) {
4534
4527
  const oldSpec = `${name}@${oldVersion}`
4535
4528
  const oldPurl = `pkg:npm/${oldSpec}`
@@ -4539,14 +4532,13 @@ async function pnpmFix(
4539
4532
  oldVersion
4540
4533
  )
4541
4534
  if (!node) {
4542
- debug.debugLog(`Skipping ${oldSpec}, no node found in ${pkgJsonPath}`)
4535
+ debug.debugLog(`Arborist node not found, skipping ${oldSpec}`)
4543
4536
  continue
4544
4537
  }
4545
4538
  for (const {
4546
4539
  firstPatchedVersionIdentifier,
4547
4540
  vulnerableVersionRange
4548
4541
  } of infos) {
4549
- const availableVersions = Object.keys(packument.versions)
4550
4542
  const newVersion = shadowNpmInject.findBestPatchVersion(
4551
4543
  node,
4552
4544
  availableVersions,
@@ -4556,7 +4548,7 @@ async function pnpmFix(
4556
4548
  ? packument.versions[newVersion]
4557
4549
  : undefined
4558
4550
  if (!(newVersion && newVersionPackument)) {
4559
- spinner?.fail(`No update available for ${oldSpec}`)
4551
+ spinner?.fail(`No update found for ${oldSpec}.`)
4560
4552
  continue
4561
4553
  }
4562
4554
  const overrideKey = `${name}@${vulnerableVersionRange}`
@@ -4612,28 +4604,27 @@ async function pnpmFix(
4612
4604
  if (updateData) {
4613
4605
  editablePkgJson.update(updateData)
4614
4606
  }
4615
- const modded = shadowNpmInject.updatePackageJsonFromNode(
4607
+ shadowNpmInject.updatePackageJsonFromNode(
4616
4608
  editablePkgJson,
4617
4609
  actualTree,
4618
4610
  node,
4619
4611
  newVersion,
4620
4612
  rangeStyle
4621
4613
  )
4622
- debug.debugLog(`Updated package.json from node: ${modded}`)
4623
-
4624
4614
  // eslint-disable-next-line no-await-in-loop
4625
4615
  if (!(await editablePkgJson.save())) {
4626
4616
  debug.debugLog(
4627
- `No changes saved for ${pkgJsonPath}, skipping install`
4617
+ `Nothing changed for ${workspaceName}, skipping install`
4628
4618
  )
4629
4619
  continue
4630
4620
  }
4631
4621
  spinner?.info(`Installing ${newSpec} in ${workspaceName}`)
4632
- let errored = false
4633
4622
  let error
4623
+ let errored = false
4634
4624
  try {
4635
4625
  // eslint-disable-next-line no-await-in-loop
4636
4626
  actualTree = await install(pkgEnvDetails, {
4627
+ cwd,
4637
4628
  spinner
4638
4629
  })
4639
4630
  if (test) {
@@ -4647,25 +4638,31 @@ async function pnpmFix(
4647
4638
  fixedSpecs.add(newSpecKey)
4648
4639
  spinner?.successAndStop(`Fixed ${name} in ${workspaceName}`)
4649
4640
  spinner?.start()
4641
+ } catch (e) {
4642
+ error = e
4643
+ errored = true
4644
+ }
4645
+ const baseBranch = isCi ? getBaseGitBranch() : ''
4646
+ if (!errored && isCi) {
4650
4647
  const branch = getSocketBranchName(
4651
4648
  oldPurl,
4652
4649
  newVersion,
4653
4650
  workspaceName
4654
4651
  )
4655
- const shouldOpenPr = isCi
4656
- ? // eslint-disable-next-line no-await-in-loop
4657
- !(await doesPullRequestExistForBranch(owner, repo, branch))
4658
- : false
4659
- if (
4660
- isCi &&
4661
- shouldOpenPr &&
4662
- // eslint-disable-next-line no-await-in-loop
4663
- (await gitCreateAndPushBranchIfNeeded(
4664
- branch,
4665
- getSocketCommitMessage(oldPurl, newVersion, workspaceName),
4666
- cwd
4667
- ))
4668
- ) {
4652
+ try {
4653
+ const { owner, repo } = getGitHubEnvRepoInfo()
4654
+ if (
4655
+ // eslint-disable-next-line no-await-in-loop
4656
+ (await doesPullRequestExistForBranch(owner, repo, branch)) ||
4657
+ // eslint-disable-next-line no-await-in-loop
4658
+ !(await gitCreateAndPushBranchIfNeeded(
4659
+ branch,
4660
+ getSocketCommitMessage(oldPurl, newVersion, workspaceName),
4661
+ cwd
4662
+ ))
4663
+ ) {
4664
+ continue
4665
+ }
4669
4666
  // eslint-disable-next-line no-await-in-loop
4670
4667
  const prResponse = await openGitHubPullRequest(
4671
4668
  owner,
@@ -4681,41 +4678,46 @@ async function pnpmFix(
4681
4678
  )
4682
4679
  if (prResponse) {
4683
4680
  const { data } = prResponse
4684
- spinner?.info(`PR #${data.number} opened.`)
4681
+ spinner?.info(`Opened PR #${data.number}.`)
4685
4682
  if (autoMerge) {
4686
4683
  // eslint-disable-next-line no-await-in-loop
4687
4684
  await enableAutoMerge(data)
4688
4685
  }
4689
4686
  }
4687
+ } catch (e) {
4688
+ error = e
4689
+ errored = true
4690
4690
  }
4691
- } catch (e) {
4692
- error = e
4693
- errored = true
4694
4691
  }
4695
- if (errored) {
4696
- editablePkgJson.update(revertData)
4692
+ if (isCi) {
4697
4693
  // eslint-disable-next-line no-await-in-loop
4698
- await Promise.all([
4699
- shadowNpmInject.removeNodeModules(cwd),
4700
- editablePkgJson.save()
4701
- ])
4694
+ await gitHardReset(baseBranch, cwd)
4695
+ // eslint-disable-next-line no-await-in-loop
4696
+ await gitCleanFdx(cwd)
4702
4697
  // eslint-disable-next-line no-await-in-loop
4703
4698
  actualTree = await install(pkgEnvDetails, {
4699
+ cwd,
4704
4700
  spinner
4705
4701
  })
4702
+ }
4703
+ if (errored) {
4704
+ if (!isCi) {
4705
+ editablePkgJson.update(revertData)
4706
+ // eslint-disable-next-line no-await-in-loop
4707
+ await Promise.all([
4708
+ shadowNpmInject.removeNodeModules(cwd),
4709
+ editablePkgJson.save()
4710
+ ])
4711
+ // eslint-disable-next-line no-await-in-loop
4712
+ actualTree = await install(pkgEnvDetails, {
4713
+ cwd,
4714
+ spinner
4715
+ })
4716
+ }
4706
4717
  spinner?.failAndStop(
4707
4718
  `Update failed for ${oldSpec} in ${workspaceName}`,
4708
4719
  error
4709
4720
  )
4710
- } else if (isCi) {
4711
- // eslint-disable-next-line no-await-in-loop
4712
- await gitHardReset(baseBranch, cwd)
4713
- // eslint-disable-next-line no-await-in-loop
4714
- await gitCleanFdx(cwd)
4715
- // eslint-disable-next-line no-await-in-loop
4716
- actualTree = await install(pkgEnvDetails, {
4717
- spinner
4718
- })
4719
4721
  }
4720
4722
  }
4721
4723
  }
@@ -4724,29 +4726,6 @@ async function pnpmFix(
4724
4726
  spinner?.stop()
4725
4727
  }
4726
4728
 
4727
- const CMD_NAME$1 = 'socket fix'
4728
- function assignDefaultFixOptions(options) {
4729
- if (options.autoPilot === undefined) {
4730
- options.autoPilot = false
4731
- }
4732
- if (options.autoMerge === undefined) {
4733
- options.autoMerge = !!options.autoPilot
4734
- }
4735
- if (options.cwd === undefined) {
4736
- options.cwd = process.cwd()
4737
- }
4738
- if (options.rangeStyle === undefined) {
4739
- options.rangeStyle = 'preserve'
4740
- }
4741
- if (options.test === undefined) {
4742
- options.test = !!options.autoPilot || !!options.testScript
4743
- }
4744
- if (options.testScript === undefined) {
4745
- options.testScript = 'test'
4746
- }
4747
- return options
4748
- }
4749
-
4750
4729
  const {
4751
4730
  BINARY_LOCK_EXT,
4752
4731
  BUN: BUN$5,
@@ -12289,7 +12268,7 @@ void (async () => {
12289
12268
  await vendor.updater({
12290
12269
  name: SOCKET_CLI_BIN_NAME,
12291
12270
  // The '@rollup/plugin-replace' will replace "process.env['INLINED_SOCKET_CLI_VERSION']".
12292
- version: '0.14.129',
12271
+ version: '0.14.130',
12293
12272
  ttl: 86_400_000 /* 24 hours in milliseconds */
12294
12273
  })
12295
12274
  try {
@@ -12357,5 +12336,5 @@ void (async () => {
12357
12336
  await shadowNpmInject.captureException(e)
12358
12337
  }
12359
12338
  })()
12360
- //# debugId=6bcb8bbd-6cbf-49de-b216-2e38923f18e6
12339
+ //# debugId=9c3b634f-d33b-4573-9062-a2ec1efd20c3
12361
12340
  //# sourceMappingURL=cli.js.map