@socketsecurity/cli-with-sentry 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:37077c67:pub' // The '@rollup/plugin-replace' will replace "process.env['INLINED_SOCKET_CLI_VERSION_HASH']".
915
+ const cliVersion = '0.14.86:69093e9:7f5177c3: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
  }
@@ -4211,7 +4228,7 @@ function runAgentInstall(pkgEnvDetails, options) {
4211
4228
  ...options
4212
4229
  }
4213
4230
  const skipNodeHardenFlags =
4214
- pkgEnvDetails.agent === PNPM$a && pkgEnvDetails.agentVersion.major < 11
4231
+ agent === PNPM$a && pkgEnvDetails.agentVersion.major < 11
4215
4232
  return spawn.spawn(agentExecPath, ['install', ...args], {
4216
4233
  spinner,
4217
4234
  stdio: 'inherit',
@@ -4232,8 +4249,15 @@ function runAgentInstall(pkgEnvDetails, options) {
4232
4249
  }
4233
4250
 
4234
4251
  const { CI, NPM: NPM$c, OVERRIDES: OVERRIDES$2, PNPM: PNPM$9 } = constants
4252
+ async function getActualTree(cwd = process.cwd()) {
4253
+ const arb = new shadowNpmInject.SafeArborist({
4254
+ path: cwd,
4255
+ ...shadowNpmInject.SAFE_ARBORIST_REIFY_OPTIONS_OVERRIDES
4256
+ })
4257
+ return await arb.loadActual()
4258
+ }
4235
4259
  async function install(pkgEnvDetails, options) {
4236
- const { spinner } = {
4260
+ const { cwd, spinner } = {
4237
4261
  __proto__: null,
4238
4262
  ...options
4239
4263
  }
@@ -4242,6 +4266,7 @@ async function install(pkgEnvDetails, options) {
4242
4266
  spinner,
4243
4267
  stdio: debug.isDebug() ? 'inherit' : 'ignore'
4244
4268
  })
4269
+ return await getActualTree(cwd)
4245
4270
  }
4246
4271
  async function pnpmFix(
4247
4272
  pkgEnvDetails,
@@ -4271,11 +4296,7 @@ async function pnpmFix(
4271
4296
  editable: true
4272
4297
  })
4273
4298
  const { content: pkgJson } = editablePkgJson
4274
- const arb = new shadowNpmInject.SafeArborist({
4275
- path: cwd,
4276
- ...shadowNpmInject.SAFE_ARBORIST_REIFY_OPTIONS_OVERRIDES
4277
- })
4278
- await arb.loadActual()
4299
+ let actualTree = await getActualTree(cwd)
4279
4300
  for (const { 0: name, 1: infos } of infoByPkg) {
4280
4301
  if (registry.getManifestData(NPM$c, name)) {
4281
4302
  spinner?.info(`Skipping ${name}. Socket Optimize package exists.`)
@@ -4283,7 +4304,7 @@ async function pnpmFix(
4283
4304
  }
4284
4305
  const specs = arrays.arrayUnique(
4285
4306
  shadowNpmInject
4286
- .findPackageNodes(arb.actualTree, name)
4307
+ .findPackageNodes(actualTree, name)
4287
4308
  .map(n => `${n.name}@${n.version}`)
4288
4309
  )
4289
4310
  const packument =
@@ -4303,7 +4324,7 @@ async function pnpmFix(
4303
4324
  vulnerableVersionRange
4304
4325
  } of infos) {
4305
4326
  const node = shadowNpmInject.findPackageNode(
4306
- arb.actualTree,
4327
+ actualTree,
4307
4328
  name,
4308
4329
  oldVersion
4309
4330
  )
@@ -4320,6 +4341,9 @@ async function pnpmFix(
4320
4341
  const targetPackument = targetVersion
4321
4342
  ? packument.versions[targetVersion]
4322
4343
  : undefined
4344
+ let failed = false
4345
+ let installed = false
4346
+ let saved = false
4323
4347
  if (targetVersion && targetPackument) {
4324
4348
  const oldPnpm = pkgJson[PNPM$9]
4325
4349
  const pnpmKeyCount = oldPnpm ? Object.keys(oldPnpm).length : 0
@@ -4369,13 +4393,11 @@ async function pnpmFix(
4369
4393
  : undefined)
4370
4394
  }
4371
4395
  spinner?.info(`Installing ${fixSpec}`)
4372
- let saved = false
4373
- let installed = false
4374
4396
  try {
4375
4397
  editablePkgJson.update(updateData)
4376
4398
  shadowNpmInject.updatePackageJsonFromNode(
4377
4399
  editablePkgJson,
4378
- arb.actualTree,
4400
+ actualTree,
4379
4401
  node,
4380
4402
  rangeStyle
4381
4403
  )
@@ -4384,7 +4406,7 @@ async function pnpmFix(
4384
4406
  saved = true
4385
4407
 
4386
4408
  // eslint-disable-next-line no-await-in-loop
4387
- await install(pkgEnvDetails, {
4409
+ actualTree = await install(pkgEnvDetails, {
4388
4410
  spinner
4389
4411
  })
4390
4412
  installed = true
@@ -4398,21 +4420,8 @@ async function pnpmFix(
4398
4420
  }
4399
4421
  spinner?.successAndStop(`Fixed ${name}`)
4400
4422
  spinner?.start()
4401
-
4402
- // Lazily access constants.ENV[CI].
4403
- if (constants.ENV[CI]) {
4404
- // eslint-disable-next-line no-await-in-loop
4405
- const prResponse = await openGitHubPullRequest(
4406
- name,
4407
- targetVersion,
4408
- cwd
4409
- )
4410
- if (autoMerge) {
4411
- // eslint-disable-next-line no-await-in-loop
4412
- await enableAutoMerge(prResponse.data)
4413
- }
4414
- }
4415
4423
  } catch (e) {
4424
+ failed = true
4416
4425
  spinner?.error(`Reverting ${fixSpec}`, e)
4417
4426
  if (saved) {
4418
4427
  editablePkgJson.update(revertData)
@@ -4421,18 +4430,42 @@ async function pnpmFix(
4421
4430
  }
4422
4431
  if (installed) {
4423
4432
  // eslint-disable-next-line no-await-in-loop
4424
- await install(pkgEnvDetails, {
4433
+ actualTree = await install(pkgEnvDetails, {
4425
4434
  spinner
4426
4435
  })
4427
- arb.actualTree = null
4428
- // eslint-disable-next-line no-await-in-loop
4429
- await arb.loadActual()
4430
4436
  }
4431
4437
  spinner?.failAndStop(`Failed to fix ${oldSpec}`)
4432
4438
  }
4433
4439
  } else {
4440
+ failed = true
4434
4441
  spinner?.failAndStop(`Could not patch ${oldSpec}`)
4435
4442
  }
4443
+ if (
4444
+ !failed &&
4445
+ // Check targetVersion to make TypeScript happy.
4446
+ targetVersion &&
4447
+ // Lazily access constants.ENV[CI].
4448
+ constants.ENV[CI]
4449
+ ) {
4450
+ let prResponse
4451
+ try {
4452
+ // eslint-disable-next-line no-await-in-loop
4453
+ prResponse = await openGitHubPullRequest(name, targetVersion, cwd)
4454
+ } catch (e) {
4455
+ logger.logger.error('Failed to open pull request', e)
4456
+ }
4457
+ if (prResponse && autoMerge) {
4458
+ try {
4459
+ // eslint-disable-next-line no-await-in-loop
4460
+ await enableAutoMerge(prResponse.data)
4461
+ } catch (e) {
4462
+ logger.logger.error(
4463
+ 'Failed to enable auto-merge in pull request',
4464
+ e
4465
+ )
4466
+ }
4467
+ }
4468
+ }
4436
4469
  }
4437
4470
  }
4438
4471
  }
@@ -11308,7 +11341,7 @@ void (async () => {
11308
11341
  await vendor.updater({
11309
11342
  name: SOCKET_CLI_BIN_NAME,
11310
11343
  // The '@rollup/plugin-replace' will replace "process.env['INLINED_SOCKET_CLI_VERSION']".
11311
- version: '0.14.84',
11344
+ version: '0.14.86',
11312
11345
  ttl: 86_400_000 /* 24 hours in milliseconds */
11313
11346
  })
11314
11347
  try {
@@ -11376,5 +11409,5 @@ void (async () => {
11376
11409
  await shadowNpmInject.captureException(e)
11377
11410
  }
11378
11411
  })()
11379
- //# debugId=831b688d-1508-4066-a22d-2e166b1f82d1
11412
+ //# debugId=708624ad-8bb1-4c03-9aea-19bed2b49a26
11380
11413
  //# sourceMappingURL=cli.js.map