@socketsecurity/cli 0.14.84 → 0.14.86

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.
@@ -912,7 +912,7 @@ function emitBanner(name) {
912
912
  logger.logger.error(getAsciiHeader(name))
913
913
  }
914
914
  function getAsciiHeader(command) {
915
- const cliVersion = '0.14.84:15b8c69:1f9b94e1:pub' // The '@rollup/plugin-replace' will replace "process.env['INLINED_SOCKET_CLI_VERSION_HASH']".
915
+ const cliVersion = '0.14.86:69093e9:6be0e47e:pub' // The '@rollup/plugin-replace' will replace "process.env['INLINED_SOCKET_CLI_VERSION_HASH']".
916
916
  const nodeVersion = process$1.version
917
917
  const apiToken = shadowNpmInject.getDefaultToken()
918
918
  const shownToken = apiToken ? getLastFiveOfApiToken(apiToken) : 'no'
@@ -3942,10 +3942,14 @@ async function npmFix(
3942
3942
  continue
3943
3943
  }
3944
3944
  const oldSpec = `${name}@${oldVersion}`
3945
+ let targetVersion
3946
+ let failed = false
3947
+ let installed = false
3948
+ let saved = false
3945
3949
  if (
3946
3950
  shadowNpmInject.updateNode(node, packument, vulnerableVersionRange)
3947
3951
  ) {
3948
- const targetVersion = node.package.version
3952
+ targetVersion = node.package.version
3949
3953
  const fixSpec = `${name}@^${targetVersion}`
3950
3954
  const revertData = {
3951
3955
  ...(pkgJson.dependencies
@@ -3965,8 +3969,6 @@ async function npmFix(
3965
3969
  : undefined)
3966
3970
  }
3967
3971
  spinner?.info(`Installing ${fixSpec}`)
3968
- let saved = false
3969
- let installed = false
3970
3972
  try {
3971
3973
  shadowNpmInject.updatePackageJsonFromNode(
3972
3974
  editablePkgJson,
@@ -3993,20 +3995,8 @@ async function npmFix(
3993
3995
  }
3994
3996
  spinner?.successAndStop(`Fixed ${name}`)
3995
3997
  spinner?.start()
3996
- // Lazily access constants.ENV[CI].
3997
- if (constants.ENV[CI$1]) {
3998
- // eslint-disable-next-line no-await-in-loop
3999
- const prResponse = await openGitHubPullRequest(
4000
- name,
4001
- targetVersion,
4002
- cwd
4003
- )
4004
- if (autoMerge) {
4005
- // eslint-disable-next-line no-await-in-loop
4006
- await enableAutoMerge(prResponse.data)
4007
- }
4008
- }
4009
3998
  } catch {
3999
+ failed = true
4010
4000
  spinner?.error(`Reverting ${fixSpec}`)
4011
4001
  if (saved) {
4012
4002
  editablePkgJson.update(revertData)
@@ -4022,8 +4012,35 @@ async function npmFix(
4022
4012
  spinner?.failAndStop(`Failed to fix ${oldSpec}`)
4023
4013
  }
4024
4014
  } else {
4015
+ failed = true
4025
4016
  spinner?.failAndStop(`Could not patch ${oldSpec}`)
4026
4017
  }
4018
+ if (
4019
+ !failed &&
4020
+ // Check targetVersion to make TypeScript happy.
4021
+ targetVersion &&
4022
+ // Lazily access constants.ENV[CI].
4023
+ constants.ENV[CI$1]
4024
+ ) {
4025
+ let prResponse
4026
+ try {
4027
+ // eslint-disable-next-line no-await-in-loop
4028
+ prResponse = await openGitHubPullRequest(name, targetVersion, cwd)
4029
+ } catch (e) {
4030
+ logger.logger.error('Failed to open pull request', e)
4031
+ }
4032
+ if (prResponse && autoMerge) {
4033
+ try {
4034
+ // eslint-disable-next-line no-await-in-loop
4035
+ await enableAutoMerge(prResponse.data)
4036
+ } catch (e) {
4037
+ logger.logger.error(
4038
+ 'Failed to enable auto-merge in pull request',
4039
+ e
4040
+ )
4041
+ }
4042
+ }
4043
+ }
4027
4044
  }
4028
4045
  }
4029
4046
  }
@@ -4207,7 +4224,7 @@ function runAgentInstall(pkgEnvDetails, options) {
4207
4224
  ...options
4208
4225
  }
4209
4226
  const skipNodeHardenFlags =
4210
- pkgEnvDetails.agent === PNPM$a && pkgEnvDetails.agentVersion.major < 11
4227
+ agent === PNPM$a && pkgEnvDetails.agentVersion.major < 11
4211
4228
  return spawn.spawn(agentExecPath, ['install', ...args], {
4212
4229
  spinner,
4213
4230
  stdio: 'inherit',
@@ -4228,8 +4245,15 @@ function runAgentInstall(pkgEnvDetails, options) {
4228
4245
  }
4229
4246
 
4230
4247
  const { CI, NPM: NPM$c, OVERRIDES: OVERRIDES$2, PNPM: PNPM$9 } = constants
4248
+ async function getActualTree(cwd = process.cwd()) {
4249
+ const arb = new shadowNpmInject.SafeArborist({
4250
+ path: cwd,
4251
+ ...shadowNpmInject.SAFE_ARBORIST_REIFY_OPTIONS_OVERRIDES
4252
+ })
4253
+ return await arb.loadActual()
4254
+ }
4231
4255
  async function install(pkgEnvDetails, options) {
4232
- const { spinner } = {
4256
+ const { cwd, spinner } = {
4233
4257
  __proto__: null,
4234
4258
  ...options
4235
4259
  }
@@ -4238,6 +4262,7 @@ async function install(pkgEnvDetails, options) {
4238
4262
  spinner,
4239
4263
  stdio: debug.isDebug() ? 'inherit' : 'ignore'
4240
4264
  })
4265
+ return await getActualTree(cwd)
4241
4266
  }
4242
4267
  async function pnpmFix(
4243
4268
  pkgEnvDetails,
@@ -4267,11 +4292,7 @@ async function pnpmFix(
4267
4292
  editable: true
4268
4293
  })
4269
4294
  const { content: pkgJson } = editablePkgJson
4270
- const arb = new shadowNpmInject.SafeArborist({
4271
- path: cwd,
4272
- ...shadowNpmInject.SAFE_ARBORIST_REIFY_OPTIONS_OVERRIDES
4273
- })
4274
- await arb.loadActual()
4295
+ let actualTree = await getActualTree(cwd)
4275
4296
  for (const { 0: name, 1: infos } of infoByPkg) {
4276
4297
  if (registry.getManifestData(NPM$c, name)) {
4277
4298
  spinner?.info(`Skipping ${name}. Socket Optimize package exists.`)
@@ -4279,7 +4300,7 @@ async function pnpmFix(
4279
4300
  }
4280
4301
  const specs = arrays.arrayUnique(
4281
4302
  shadowNpmInject
4282
- .findPackageNodes(arb.actualTree, name)
4303
+ .findPackageNodes(actualTree, name)
4283
4304
  .map(n => `${n.name}@${n.version}`)
4284
4305
  )
4285
4306
  const packument =
@@ -4299,7 +4320,7 @@ async function pnpmFix(
4299
4320
  vulnerableVersionRange
4300
4321
  } of infos) {
4301
4322
  const node = shadowNpmInject.findPackageNode(
4302
- arb.actualTree,
4323
+ actualTree,
4303
4324
  name,
4304
4325
  oldVersion
4305
4326
  )
@@ -4316,6 +4337,9 @@ async function pnpmFix(
4316
4337
  const targetPackument = targetVersion
4317
4338
  ? packument.versions[targetVersion]
4318
4339
  : undefined
4340
+ let failed = false
4341
+ let installed = false
4342
+ let saved = false
4319
4343
  if (targetVersion && targetPackument) {
4320
4344
  const oldPnpm = pkgJson[PNPM$9]
4321
4345
  const pnpmKeyCount = oldPnpm ? Object.keys(oldPnpm).length : 0
@@ -4365,13 +4389,11 @@ async function pnpmFix(
4365
4389
  : undefined)
4366
4390
  }
4367
4391
  spinner?.info(`Installing ${fixSpec}`)
4368
- let saved = false
4369
- let installed = false
4370
4392
  try {
4371
4393
  editablePkgJson.update(updateData)
4372
4394
  shadowNpmInject.updatePackageJsonFromNode(
4373
4395
  editablePkgJson,
4374
- arb.actualTree,
4396
+ actualTree,
4375
4397
  node,
4376
4398
  rangeStyle
4377
4399
  )
@@ -4380,7 +4402,7 @@ async function pnpmFix(
4380
4402
  saved = true
4381
4403
 
4382
4404
  // eslint-disable-next-line no-await-in-loop
4383
- await install(pkgEnvDetails, {
4405
+ actualTree = await install(pkgEnvDetails, {
4384
4406
  spinner
4385
4407
  })
4386
4408
  installed = true
@@ -4394,21 +4416,8 @@ async function pnpmFix(
4394
4416
  }
4395
4417
  spinner?.successAndStop(`Fixed ${name}`)
4396
4418
  spinner?.start()
4397
-
4398
- // Lazily access constants.ENV[CI].
4399
- if (constants.ENV[CI]) {
4400
- // eslint-disable-next-line no-await-in-loop
4401
- const prResponse = await openGitHubPullRequest(
4402
- name,
4403
- targetVersion,
4404
- cwd
4405
- )
4406
- if (autoMerge) {
4407
- // eslint-disable-next-line no-await-in-loop
4408
- await enableAutoMerge(prResponse.data)
4409
- }
4410
- }
4411
4419
  } catch (e) {
4420
+ failed = true
4412
4421
  spinner?.error(`Reverting ${fixSpec}`, e)
4413
4422
  if (saved) {
4414
4423
  editablePkgJson.update(revertData)
@@ -4417,18 +4426,42 @@ async function pnpmFix(
4417
4426
  }
4418
4427
  if (installed) {
4419
4428
  // eslint-disable-next-line no-await-in-loop
4420
- await install(pkgEnvDetails, {
4429
+ actualTree = await install(pkgEnvDetails, {
4421
4430
  spinner
4422
4431
  })
4423
- arb.actualTree = null
4424
- // eslint-disable-next-line no-await-in-loop
4425
- await arb.loadActual()
4426
4432
  }
4427
4433
  spinner?.failAndStop(`Failed to fix ${oldSpec}`)
4428
4434
  }
4429
4435
  } else {
4436
+ failed = true
4430
4437
  spinner?.failAndStop(`Could not patch ${oldSpec}`)
4431
4438
  }
4439
+ if (
4440
+ !failed &&
4441
+ // Check targetVersion to make TypeScript happy.
4442
+ targetVersion &&
4443
+ // Lazily access constants.ENV[CI].
4444
+ constants.ENV[CI]
4445
+ ) {
4446
+ let prResponse
4447
+ try {
4448
+ // eslint-disable-next-line no-await-in-loop
4449
+ prResponse = await openGitHubPullRequest(name, targetVersion, cwd)
4450
+ } catch (e) {
4451
+ logger.logger.error('Failed to open pull request', e)
4452
+ }
4453
+ if (prResponse && autoMerge) {
4454
+ try {
4455
+ // eslint-disable-next-line no-await-in-loop
4456
+ await enableAutoMerge(prResponse.data)
4457
+ } catch (e) {
4458
+ logger.logger.error(
4459
+ 'Failed to enable auto-merge in pull request',
4460
+ e
4461
+ )
4462
+ }
4463
+ }
4464
+ }
4432
4465
  }
4433
4466
  }
4434
4467
  }
@@ -11304,7 +11337,7 @@ void (async () => {
11304
11337
  await vendor.updater({
11305
11338
  name: SOCKET_CLI_BIN_NAME,
11306
11339
  // The '@rollup/plugin-replace' will replace "process.env['INLINED_SOCKET_CLI_VERSION']".
11307
- version: '0.14.84',
11340
+ version: '0.14.86',
11308
11341
  ttl: 86_400_000 /* 24 hours in milliseconds */
11309
11342
  })
11310
11343
  try {
@@ -11372,5 +11405,5 @@ void (async () => {
11372
11405
  await shadowNpmInject.captureException(e)
11373
11406
  }
11374
11407
  })()
11375
- //# debugId=42e1277a-9cf1-4b82-8e9e-c6c083a2dab
11408
+ //# debugId=358951ff-4438-4565-a758-09112312f1b8
11376
11409
  //# sourceMappingURL=cli.js.map