socket 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.
@@ -915,7 +915,7 @@ function emitBanner(name) {
915
915
  logger.logger.error(getAsciiHeader(name))
916
916
  }
917
917
  function getAsciiHeader(command) {
918
- const cliVersion = '0.14.84:15b8c69:ff509e18:pub' // The '@rollup/plugin-replace' will replace "process.env['INLINED_SOCKET_CLI_VERSION_HASH']".
918
+ const cliVersion = '0.14.86:69093e9:cea7b31b:pub' // The '@rollup/plugin-replace' will replace "process.env['INLINED_SOCKET_CLI_VERSION_HASH']".
919
919
  const nodeVersion = process$1.version
920
920
  const apiToken = shadowNpmInject.getDefaultToken()
921
921
  const shownToken = apiToken ? getLastFiveOfApiToken(apiToken) : 'no'
@@ -3945,10 +3945,14 @@ async function npmFix(
3945
3945
  continue
3946
3946
  }
3947
3947
  const oldSpec = `${name}@${oldVersion}`
3948
+ let targetVersion
3949
+ let failed = false
3950
+ let installed = false
3951
+ let saved = false
3948
3952
  if (
3949
3953
  shadowNpmInject.updateNode(node, packument, vulnerableVersionRange)
3950
3954
  ) {
3951
- const targetVersion = node.package.version
3955
+ targetVersion = node.package.version
3952
3956
  const fixSpec = `${name}@^${targetVersion}`
3953
3957
  const revertData = {
3954
3958
  ...(pkgJson.dependencies
@@ -3968,8 +3972,6 @@ async function npmFix(
3968
3972
  : undefined)
3969
3973
  }
3970
3974
  spinner?.info(`Installing ${fixSpec}`)
3971
- let saved = false
3972
- let installed = false
3973
3975
  try {
3974
3976
  shadowNpmInject.updatePackageJsonFromNode(
3975
3977
  editablePkgJson,
@@ -3996,20 +3998,8 @@ async function npmFix(
3996
3998
  }
3997
3999
  spinner?.successAndStop(`Fixed ${name}`)
3998
4000
  spinner?.start()
3999
- // Lazily access constants.ENV[CI].
4000
- if (constants.ENV[CI$1]) {
4001
- // eslint-disable-next-line no-await-in-loop
4002
- const prResponse = await openGitHubPullRequest(
4003
- name,
4004
- targetVersion,
4005
- cwd
4006
- )
4007
- if (autoMerge) {
4008
- // eslint-disable-next-line no-await-in-loop
4009
- await enableAutoMerge(prResponse.data)
4010
- }
4011
- }
4012
4001
  } catch {
4002
+ failed = true
4013
4003
  spinner?.error(`Reverting ${fixSpec}`)
4014
4004
  if (saved) {
4015
4005
  editablePkgJson.update(revertData)
@@ -4025,8 +4015,35 @@ async function npmFix(
4025
4015
  spinner?.failAndStop(`Failed to fix ${oldSpec}`)
4026
4016
  }
4027
4017
  } else {
4018
+ failed = true
4028
4019
  spinner?.failAndStop(`Could not patch ${oldSpec}`)
4029
4020
  }
4021
+ if (
4022
+ !failed &&
4023
+ // Check targetVersion to make TypeScript happy.
4024
+ targetVersion &&
4025
+ // Lazily access constants.ENV[CI].
4026
+ constants.ENV[CI$1]
4027
+ ) {
4028
+ let prResponse
4029
+ try {
4030
+ // eslint-disable-next-line no-await-in-loop
4031
+ prResponse = await openGitHubPullRequest(name, targetVersion, cwd)
4032
+ } catch (e) {
4033
+ logger.logger.error('Failed to open pull request', e)
4034
+ }
4035
+ if (prResponse && autoMerge) {
4036
+ try {
4037
+ // eslint-disable-next-line no-await-in-loop
4038
+ await enableAutoMerge(prResponse.data)
4039
+ } catch (e) {
4040
+ logger.logger.error(
4041
+ 'Failed to enable auto-merge in pull request',
4042
+ e
4043
+ )
4044
+ }
4045
+ }
4046
+ }
4030
4047
  }
4031
4048
  }
4032
4049
  }
@@ -4210,7 +4227,7 @@ function runAgentInstall(pkgEnvDetails, options) {
4210
4227
  ...options
4211
4228
  }
4212
4229
  const skipNodeHardenFlags =
4213
- pkgEnvDetails.agent === PNPM$a && pkgEnvDetails.agentVersion.major < 11
4230
+ agent === PNPM$a && pkgEnvDetails.agentVersion.major < 11
4214
4231
  return spawn.spawn(agentExecPath, ['install', ...args], {
4215
4232
  spinner,
4216
4233
  stdio: 'inherit',
@@ -4231,8 +4248,15 @@ function runAgentInstall(pkgEnvDetails, options) {
4231
4248
  }
4232
4249
 
4233
4250
  const { CI, NPM: NPM$c, OVERRIDES: OVERRIDES$2, PNPM: PNPM$9 } = constants
4251
+ async function getActualTree(cwd = process.cwd()) {
4252
+ const arb = new shadowNpmInject.SafeArborist({
4253
+ path: cwd,
4254
+ ...shadowNpmInject.SAFE_ARBORIST_REIFY_OPTIONS_OVERRIDES
4255
+ })
4256
+ return await arb.loadActual()
4257
+ }
4234
4258
  async function install(pkgEnvDetails, options) {
4235
- const { spinner } = {
4259
+ const { cwd, spinner } = {
4236
4260
  __proto__: null,
4237
4261
  ...options
4238
4262
  }
@@ -4241,6 +4265,7 @@ async function install(pkgEnvDetails, options) {
4241
4265
  spinner,
4242
4266
  stdio: debug.isDebug() ? 'inherit' : 'ignore'
4243
4267
  })
4268
+ return await getActualTree(cwd)
4244
4269
  }
4245
4270
  async function pnpmFix(
4246
4271
  pkgEnvDetails,
@@ -4270,11 +4295,7 @@ async function pnpmFix(
4270
4295
  editable: true
4271
4296
  })
4272
4297
  const { content: pkgJson } = editablePkgJson
4273
- const arb = new shadowNpmInject.SafeArborist({
4274
- path: cwd,
4275
- ...shadowNpmInject.SAFE_ARBORIST_REIFY_OPTIONS_OVERRIDES
4276
- })
4277
- await arb.loadActual()
4298
+ let actualTree = await getActualTree(cwd)
4278
4299
  for (const { 0: name, 1: infos } of infoByPkg) {
4279
4300
  if (registry.getManifestData(NPM$c, name)) {
4280
4301
  spinner?.info(`Skipping ${name}. Socket Optimize package exists.`)
@@ -4282,7 +4303,7 @@ async function pnpmFix(
4282
4303
  }
4283
4304
  const specs = arrays.arrayUnique(
4284
4305
  shadowNpmInject
4285
- .findPackageNodes(arb.actualTree, name)
4306
+ .findPackageNodes(actualTree, name)
4286
4307
  .map(n => `${n.name}@${n.version}`)
4287
4308
  )
4288
4309
  const packument =
@@ -4302,7 +4323,7 @@ async function pnpmFix(
4302
4323
  vulnerableVersionRange
4303
4324
  } of infos) {
4304
4325
  const node = shadowNpmInject.findPackageNode(
4305
- arb.actualTree,
4326
+ actualTree,
4306
4327
  name,
4307
4328
  oldVersion
4308
4329
  )
@@ -4319,6 +4340,9 @@ async function pnpmFix(
4319
4340
  const targetPackument = targetVersion
4320
4341
  ? packument.versions[targetVersion]
4321
4342
  : undefined
4343
+ let failed = false
4344
+ let installed = false
4345
+ let saved = false
4322
4346
  if (targetVersion && targetPackument) {
4323
4347
  const oldPnpm = pkgJson[PNPM$9]
4324
4348
  const pnpmKeyCount = oldPnpm ? Object.keys(oldPnpm).length : 0
@@ -4368,13 +4392,11 @@ async function pnpmFix(
4368
4392
  : undefined)
4369
4393
  }
4370
4394
  spinner?.info(`Installing ${fixSpec}`)
4371
- let saved = false
4372
- let installed = false
4373
4395
  try {
4374
4396
  editablePkgJson.update(updateData)
4375
4397
  shadowNpmInject.updatePackageJsonFromNode(
4376
4398
  editablePkgJson,
4377
- arb.actualTree,
4399
+ actualTree,
4378
4400
  node,
4379
4401
  rangeStyle
4380
4402
  )
@@ -4383,7 +4405,7 @@ async function pnpmFix(
4383
4405
  saved = true
4384
4406
 
4385
4407
  // eslint-disable-next-line no-await-in-loop
4386
- await install(pkgEnvDetails, {
4408
+ actualTree = await install(pkgEnvDetails, {
4387
4409
  spinner
4388
4410
  })
4389
4411
  installed = true
@@ -4397,21 +4419,8 @@ async function pnpmFix(
4397
4419
  }
4398
4420
  spinner?.successAndStop(`Fixed ${name}`)
4399
4421
  spinner?.start()
4400
-
4401
- // Lazily access constants.ENV[CI].
4402
- if (constants.ENV[CI]) {
4403
- // eslint-disable-next-line no-await-in-loop
4404
- const prResponse = await openGitHubPullRequest(
4405
- name,
4406
- targetVersion,
4407
- cwd
4408
- )
4409
- if (autoMerge) {
4410
- // eslint-disable-next-line no-await-in-loop
4411
- await enableAutoMerge(prResponse.data)
4412
- }
4413
- }
4414
4422
  } catch (e) {
4423
+ failed = true
4415
4424
  spinner?.error(`Reverting ${fixSpec}`, e)
4416
4425
  if (saved) {
4417
4426
  editablePkgJson.update(revertData)
@@ -4420,18 +4429,42 @@ async function pnpmFix(
4420
4429
  }
4421
4430
  if (installed) {
4422
4431
  // eslint-disable-next-line no-await-in-loop
4423
- await install(pkgEnvDetails, {
4432
+ actualTree = await install(pkgEnvDetails, {
4424
4433
  spinner
4425
4434
  })
4426
- arb.actualTree = null
4427
- // eslint-disable-next-line no-await-in-loop
4428
- await arb.loadActual()
4429
4435
  }
4430
4436
  spinner?.failAndStop(`Failed to fix ${oldSpec}`)
4431
4437
  }
4432
4438
  } else {
4439
+ failed = true
4433
4440
  spinner?.failAndStop(`Could not patch ${oldSpec}`)
4434
4441
  }
4442
+ if (
4443
+ !failed &&
4444
+ // Check targetVersion to make TypeScript happy.
4445
+ targetVersion &&
4446
+ // Lazily access constants.ENV[CI].
4447
+ constants.ENV[CI]
4448
+ ) {
4449
+ let prResponse
4450
+ try {
4451
+ // eslint-disable-next-line no-await-in-loop
4452
+ prResponse = await openGitHubPullRequest(name, targetVersion, cwd)
4453
+ } catch (e) {
4454
+ logger.logger.error('Failed to open pull request', e)
4455
+ }
4456
+ if (prResponse && autoMerge) {
4457
+ try {
4458
+ // eslint-disable-next-line no-await-in-loop
4459
+ await enableAutoMerge(prResponse.data)
4460
+ } catch (e) {
4461
+ logger.logger.error(
4462
+ 'Failed to enable auto-merge in pull request',
4463
+ e
4464
+ )
4465
+ }
4466
+ }
4467
+ }
4435
4468
  }
4436
4469
  }
4437
4470
  }
@@ -11305,7 +11338,7 @@ void (async () => {
11305
11338
  await updateNotifier({
11306
11339
  name: SOCKET_CLI_BIN_NAME,
11307
11340
  // The '@rollup/plugin-replace' will replace "process.env['INLINED_SOCKET_CLI_VERSION']".
11308
- version: '0.14.84',
11341
+ version: '0.14.86',
11309
11342
  ttl: 86_400_000 /* 24 hours in milliseconds */
11310
11343
  })
11311
11344
  try {
@@ -11373,5 +11406,5 @@ void (async () => {
11373
11406
  await shadowNpmInject.captureException(e)
11374
11407
  }
11375
11408
  })()
11376
- //# debugId=8e20edbd-ad70-43a9-bf34-76c706516a49
11409
+ //# debugId=b44c2f38-222e-45b9-a2a0-1f9508a26ae9
11377
11410
  //# sourceMappingURL=cli.js.map