socket 0.14.123 → 0.14.125

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.123:ac83b62:9fc01fd8:pub' // The '@rollup/plugin-replace' will replace "process.env['INLINED_SOCKET_CLI_VERSION_HASH']".
920
+ const cliVersion = '0.14.125:11530dd:821f8925: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')
@@ -3739,7 +3739,7 @@ function getPkgNameFromPurlObj(purlObj) {
3739
3739
  function getBaseGitBranch() {
3740
3740
  // Lazily access constants.ENV[GITHUB_REF_NAME].
3741
3741
  return (
3742
- constants.ENV[GITHUB_REF_NAME] ??
3742
+ constants.ENV[GITHUB_REF_NAME] ||
3743
3743
  // GitHub defaults to branch name "main"
3744
3744
  // https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-branches#about-the-default-branch
3745
3745
  'main'
@@ -3858,16 +3858,6 @@ async function gitUnstagedModifiedFiles(cwd = process.cwd()) {
3858
3858
  const rawFiles = stdout?.trim().split('\n') ?? []
3859
3859
  return rawFiles.map(relPath => path.normalizePath(relPath))
3860
3860
  }
3861
- async function isInGitRepo(cwd = process.cwd()) {
3862
- try {
3863
- await spawn.spawn('git', ['rev-parse', '--is-inside-work-tree'], {
3864
- cwd,
3865
- stdio: 'ignore'
3866
- })
3867
- return true
3868
- } catch {}
3869
- return false
3870
- }
3871
3861
 
3872
3862
  const { GITHUB_ACTIONS, GITHUB_REPOSITORY, SOCKET_SECURITY_GITHUB_PAT } =
3873
3863
  constants
@@ -4054,10 +4044,10 @@ async function npmFix(
4054
4044
 
4055
4045
  // Lazily access constants.ENV[CI].
4056
4046
  const isCi = constants.ENV[CI$1]
4057
- const { 0: isRepo, 1: workspacePkgJsonPaths } = await Promise.all([
4058
- isInGitRepo(cwd),
4059
- shadowNpmInject.globWorkspace(pkgEnvDetails.agent, rootPath)
4060
- ])
4047
+ const workspacePkgJsonPaths = await shadowNpmInject.globWorkspace(
4048
+ pkgEnvDetails.agent,
4049
+ rootPath
4050
+ )
4061
4051
  const pkgJsonPaths = [
4062
4052
  ...workspacePkgJsonPaths,
4063
4053
  // Process the workspace root last since it will add an override to package.json.
@@ -4075,7 +4065,7 @@ async function npmFix(
4075
4065
  const oldVersions = arrays.arrayUnique(
4076
4066
  shadowNpmInject
4077
4067
  .findPackageNodes(arb.idealTree, name)
4078
- .map(n => n.version)
4068
+ .map(n => n.target?.version ?? n.version)
4079
4069
  .filter(Boolean)
4080
4070
  )
4081
4071
  const packument =
@@ -4190,7 +4180,6 @@ async function npmFix(
4190
4180
  )
4191
4181
  let error
4192
4182
  let errored = false
4193
- let installed = false
4194
4183
  let saved = false
4195
4184
 
4196
4185
  // eslint-disable-next-line no-await-in-loop
@@ -4206,7 +4195,6 @@ async function npmFix(
4206
4195
  await install$1(arb.idealTree, {
4207
4196
  cwd
4208
4197
  })
4209
- installed = true
4210
4198
  if (test) {
4211
4199
  if (!testedSpecs.has(newSpecKey)) {
4212
4200
  testedSpecs.add(newSpecKey)
@@ -4272,15 +4260,15 @@ async function npmFix(
4272
4260
  // eslint-disable-next-line no-await-in-loop
4273
4261
  await Promise.all([
4274
4262
  shadowNpmInject.removeNodeModules(cwd),
4275
- ...(isRepo ? [gitHardReset(cwd)] : []),
4276
- ...(saved && !isRepo ? [editablePkgJson.save()] : [])
4263
+ ...(isCi
4264
+ ? [gitCheckoutBaseBranchIfAvailable(baseBranch, cwd)]
4265
+ : []),
4266
+ ...(saved && !isCi ? [editablePkgJson.save()] : [])
4277
4267
  ])
4278
- if (!isRepo && installed) {
4279
- // eslint-disable-next-line no-await-in-loop
4280
- await install$1(revertTree, {
4281
- cwd
4282
- })
4283
- }
4268
+ // eslint-disable-next-line no-await-in-loop
4269
+ await install$1(revertTree, {
4270
+ cwd
4271
+ })
4284
4272
  if (errored) {
4285
4273
  if (!failedSpecs.has(newSpecKey)) {
4286
4274
  failedSpecs.add(newSpecKey)
@@ -4476,37 +4464,34 @@ async function pnpmFix(
4476
4464
 
4477
4465
  // Lazily access constants.ENV[CI].
4478
4466
  const isCi = constants.ENV[CI]
4479
- const { 0: isRepo, 1: workspacePkgJsonPaths } = await Promise.all([
4480
- isInGitRepo(cwd),
4481
- shadowNpmInject.globWorkspace(pkgEnvDetails.agent, rootPath)
4482
- ])
4467
+ const workspacePkgJsonPaths = await shadowNpmInject.globWorkspace(
4468
+ pkgEnvDetails.agent,
4469
+ rootPath
4470
+ )
4471
+ const baseBranch = isCi ? getBaseGitBranch() : ''
4472
+ const { owner, repo } = isCi
4473
+ ? getGitHubEnvRepoInfo()
4474
+ : {
4475
+ owner: '',
4476
+ repo: ''
4477
+ }
4483
4478
  const pkgJsonPaths = [
4484
4479
  ...workspacePkgJsonPaths,
4485
4480
  // Process the workspace root last since it will add an override to package.json.
4486
4481
  pkgEnvDetails.editablePkgJson.filename
4487
4482
  ]
4488
- let actualTree
4483
+ let actualTree = await getActualTree(cwd)
4489
4484
  for (const { 0: name, 1: infos } of infoByPkg) {
4490
4485
  if (registry.getManifestData(NPM$c, name)) {
4491
4486
  spinner?.info(`Skipping ${name}. Socket Optimize package exists.`)
4492
4487
  continue
4493
4488
  }
4494
- // eslint-disable-next-line no-await-in-loop
4495
- await Promise.all([
4496
- shadowNpmInject.removeNodeModules(cwd),
4497
- ...(isRepo ? [gitHardReset(cwd)] : [])
4498
- ])
4499
- // eslint-disable-next-line no-await-in-loop
4500
- actualTree = await install(pkgEnvDetails, {
4501
- spinner
4502
- })
4503
4489
  const oldVersions = arrays.arrayUnique(
4504
4490
  shadowNpmInject
4505
4491
  .findPackageNodes(actualTree, name)
4506
- .map(n => n.version)
4492
+ .map(n => n.target?.version ?? n.version)
4507
4493
  .filter(Boolean)
4508
4494
  )
4509
- debug.debugLog(name, 'oldVersions', oldVersions)
4510
4495
  const packument =
4511
4496
  oldVersions.length && infos.length
4512
4497
  ? // eslint-disable-next-line no-await-in-loop
@@ -4515,41 +4500,43 @@ async function pnpmFix(
4515
4500
  if (!packument) {
4516
4501
  continue
4517
4502
  }
4518
- const failedSpecs = new Set()
4519
4503
  const fixedSpecs = new Set()
4520
- const installedSpecs = new Set()
4521
- const testedSpecs = new Set()
4522
- const unavailableSpecs = new Set()
4523
- const revertedSpecs = new Set()
4524
4504
  for (const pkgJsonPath of pkgJsonPaths) {
4505
+ // Re-read actualTree to avoid lockfile state issues
4506
+ // eslint-disable-next-line no-await-in-loop
4507
+ actualTree = await getActualTree(cwd)
4508
+ const pkgPath = path$1.dirname(pkgJsonPath)
4509
+ const isWorkspaceRoot =
4510
+ pkgJsonPath === pkgEnvDetails.editablePkgJson.filename
4511
+ const workspaceName = isWorkspaceRoot
4512
+ ? 'root'
4513
+ : path$1.relative(rootPath, pkgPath)
4514
+ const editablePkgJson = isWorkspaceRoot
4515
+ ? pkgEnvDetails.editablePkgJson
4516
+ : // eslint-disable-next-line no-await-in-loop
4517
+ await packages.readPackageJson(pkgJsonPath, {
4518
+ editable: true
4519
+ })
4520
+
4521
+ // Get current overrides for revert logic
4522
+ const oldPnpmSection = editablePkgJson.content[PNPM$8]
4523
+ const oldOverrides = oldPnpmSection?.[OVERRIDES$2]
4525
4524
  for (const oldVersion of oldVersions) {
4526
4525
  const oldSpec = `${name}@${oldVersion}`
4527
4526
  const oldPurl = `pkg:npm/${oldSpec}`
4527
+ const node = shadowNpmInject.findPackageNode(
4528
+ actualTree,
4529
+ name,
4530
+ oldVersion
4531
+ )
4532
+ if (!node) {
4533
+ debug.debugLog(`Skipping ${oldSpec}, no node found in ${pkgJsonPath}`)
4534
+ continue
4535
+ }
4528
4536
  for (const {
4529
4537
  firstPatchedVersionIdentifier,
4530
4538
  vulnerableVersionRange
4531
4539
  } of infos) {
4532
- // eslint-disable-next-line no-await-in-loop
4533
- await Promise.all([
4534
- shadowNpmInject.removeNodeModules(cwd),
4535
- ...(isRepo ? [gitHardReset(cwd)] : [])
4536
- ])
4537
- // eslint-disable-next-line no-await-in-loop
4538
- actualTree = await install(pkgEnvDetails, {
4539
- spinner
4540
- })
4541
- const node = shadowNpmInject.findPackageNode(
4542
- actualTree,
4543
- name,
4544
- oldVersion
4545
- )
4546
- if (!node) {
4547
- debug.debugLog(
4548
- `Skipping ${oldSpec}, no node found in arborist.actualTree`,
4549
- pkgJsonPath
4550
- )
4551
- continue
4552
- }
4553
4540
  const availableVersions = Object.keys(packument.versions)
4554
4541
  const newVersion = shadowNpmInject.findBestPatchVersion(
4555
4542
  node,
@@ -4560,30 +4547,9 @@ async function pnpmFix(
4560
4547
  ? packument.versions[newVersion]
4561
4548
  : undefined
4562
4549
  if (!(newVersion && newVersionPackument)) {
4563
- if (!unavailableSpecs.has(oldSpec)) {
4564
- unavailableSpecs.add(oldSpec)
4565
- spinner?.fail(`No update available for ${oldSpec}`)
4566
- }
4550
+ spinner?.fail(`No update available for ${oldSpec}`)
4567
4551
  continue
4568
4552
  }
4569
- const isWorkspaceRoot =
4570
- pkgJsonPath === pkgEnvDetails.editablePkgJson.filename
4571
- const workspaceName = isWorkspaceRoot
4572
- ? ''
4573
- : path$1.relative(rootPath, path$1.dirname(pkgJsonPath))
4574
- const workspaceDetails = workspaceName ? ` in ${workspaceName}` : ''
4575
- const editablePkgJson = isWorkspaceRoot
4576
- ? pkgEnvDetails.editablePkgJson
4577
- : // eslint-disable-next-line no-await-in-loop
4578
- await packages.readPackageJson(pkgJsonPath, {
4579
- editable: true
4580
- })
4581
- const oldPnpm = editablePkgJson.content[PNPM$8]
4582
- const oldPnpmKeyCount = oldPnpm ? Object.keys(oldPnpm).length : 0
4583
- const oldOverrides = oldPnpm?.[OVERRIDES$2]
4584
- const oldOverridesCount = oldOverrides
4585
- ? Object.keys(oldOverrides).length
4586
- : 0
4587
4553
  const overrideKey = `${name}@${vulnerableVersionRange}`
4588
4554
  const newVersionRange = shadowNpmInject.applyRange(
4589
4555
  oldOverrides?.[overrideKey] ?? oldVersion,
@@ -4591,14 +4557,20 @@ async function pnpmFix(
4591
4557
  rangeStyle
4592
4558
  )
4593
4559
  const newSpec = `${name}@${newVersionRange}`
4594
- const newSpecKey = `${workspaceName ? `${workspaceName}>` : ''}${newSpec}`
4560
+ const newSpecKey = `${workspaceName}:${newSpec}`
4561
+ if (fixedSpecs.has(newSpecKey)) {
4562
+ debug.debugLog(
4563
+ `Already fixed ${newSpec} in ${workspaceName}, skipping`
4564
+ )
4565
+ continue
4566
+ }
4595
4567
  const updateData = isWorkspaceRoot
4596
4568
  ? {
4597
4569
  [PNPM$8]: {
4598
- ...oldPnpm,
4570
+ ...oldPnpmSection,
4599
4571
  [OVERRIDES$2]: {
4600
- [overrideKey]: newVersionRange,
4601
- ...oldOverrides
4572
+ ...oldOverrides,
4573
+ [overrideKey]: newVersionRange
4602
4574
  }
4603
4575
  }
4604
4576
  }
@@ -4606,54 +4578,27 @@ async function pnpmFix(
4606
4578
  const revertData = {
4607
4579
  ...(isWorkspaceRoot
4608
4580
  ? {
4609
- [PNPM$8]: oldPnpmKeyCount
4610
- ? {
4611
- ...oldPnpm,
4612
- [OVERRIDES$2]:
4613
- oldOverridesCount === 1
4614
- ? undefined
4615
- : {
4616
- [overrideKey]: undefined,
4617
- ...oldOverrides
4618
- }
4619
- }
4620
- : undefined
4581
+ [PNPM$8]: {
4582
+ ...oldPnpmSection,
4583
+ [OVERRIDES$2]:
4584
+ oldOverrides && Object.keys(oldOverrides).length > 1
4585
+ ? {
4586
+ ...oldOverrides,
4587
+ [overrideKey]: undefined
4588
+ }
4589
+ : undefined
4590
+ }
4621
4591
  }
4622
4592
  : {}),
4623
- ...(editablePkgJson.content.dependencies
4624
- ? {
4625
- dependencies: editablePkgJson.content.dependencies
4626
- }
4627
- : undefined),
4628
- ...(editablePkgJson.content.optionalDependencies
4629
- ? {
4630
- optionalDependencies:
4631
- editablePkgJson.content.optionalDependencies
4632
- }
4633
- : undefined),
4634
- ...(editablePkgJson.content.peerDependencies
4635
- ? {
4636
- peerDependencies: editablePkgJson.content.peerDependencies
4637
- }
4638
- : undefined)
4639
- }
4640
- const branch = isCi
4641
- ? getSocketBranchName(oldPurl, newVersion, workspaceName)
4642
- : ''
4643
- const baseBranch = isCi ? getBaseGitBranch() : ''
4644
- const { owner, repo } = isCi
4645
- ? getGitHubEnvRepoInfo()
4646
- : {
4647
- owner: '',
4648
- repo: ''
4649
- }
4650
- const shouldOpenPr = isCi
4651
- ? // eslint-disable-next-line no-await-in-loop
4652
- !(await doesPullRequestExistForBranch(owner, repo, branch))
4653
- : false
4654
- if (isCi) {
4655
- // eslint-disable-next-line no-await-in-loop
4656
- await gitCheckoutBaseBranchIfAvailable(baseBranch, cwd)
4593
+ ...(editablePkgJson.content.dependencies && {
4594
+ dependencies: editablePkgJson.content.dependencies
4595
+ }),
4596
+ ...(editablePkgJson.content.optionalDependencies && {
4597
+ optionalDependencies: editablePkgJson.content.optionalDependencies
4598
+ }),
4599
+ ...(editablePkgJson.content.peerDependencies && {
4600
+ peerDependencies: editablePkgJson.content.peerDependencies
4601
+ })
4657
4602
  }
4658
4603
  if (updateData) {
4659
4604
  editablePkgJson.update(updateData)
@@ -4666,107 +4611,99 @@ async function pnpmFix(
4666
4611
  rangeStyle
4667
4612
  )
4668
4613
  debug.debugLog(`Updated package.json from node: ${modded}`)
4669
- let error
4670
- let errored = false
4671
- let installed = false
4672
4614
 
4673
4615
  // eslint-disable-next-line no-await-in-loop
4674
4616
  if (!(await editablePkgJson.save())) {
4675
4617
  debug.debugLog(
4676
- `Skipping nothing changed in ${editablePkgJson.filename}`
4618
+ `No changes saved for ${pkgJsonPath}, skipping install`
4677
4619
  )
4678
4620
  continue
4679
4621
  }
4680
- if (!installedSpecs.has(newSpecKey)) {
4681
- installedSpecs.add(newSpecKey)
4682
- spinner?.info(`Installing ${newSpec}${workspaceDetails}`)
4683
- }
4622
+ spinner?.info(`Installing ${newSpec} in ${workspaceName}`)
4623
+ let errored = false
4624
+ let error
4684
4625
  try {
4685
4626
  // eslint-disable-next-line no-await-in-loop
4686
4627
  actualTree = await install(pkgEnvDetails, {
4687
4628
  spinner
4688
4629
  })
4689
- installed = true
4690
4630
  if (test) {
4691
- if (!testedSpecs.has(newSpecKey)) {
4692
- testedSpecs.add(newSpecKey)
4693
- spinner?.info(`Testing ${newSpec}${workspaceDetails}`)
4694
- }
4631
+ spinner?.info(`Testing ${newSpec} in ${workspaceName}`)
4695
4632
  // eslint-disable-next-line no-await-in-loop
4696
4633
  await npm.runScript(testScript, [], {
4697
4634
  spinner,
4698
4635
  stdio: 'ignore'
4699
4636
  })
4700
4637
  }
4701
- if (!fixedSpecs.has(newSpecKey)) {
4702
- fixedSpecs.add(newSpecKey)
4703
- spinner?.successAndStop(`Fixed ${name}${workspaceDetails}`)
4704
- spinner?.start()
4705
- }
4706
- } catch (e) {
4707
- error = e
4708
- errored = true
4709
- }
4710
- if (
4711
- !errored &&
4712
- shouldOpenPr &&
4713
- // eslint-disable-next-line no-await-in-loop
4714
- (await gitCreateAndPushBranchIfNeeded(
4715
- branch,
4716
- getSocketCommitMessage(oldPurl, newVersion, workspaceName),
4717
- cwd
4718
- ))
4719
- ) {
4720
- // eslint-disable-next-line no-await-in-loop
4721
- const prResponse = await openGitHubPullRequest(
4722
- owner,
4723
- repo,
4724
- baseBranch,
4725
- branch,
4638
+ fixedSpecs.add(newSpecKey)
4639
+ spinner?.successAndStop(`Fixed ${name} in ${workspaceName}`)
4640
+ spinner?.start()
4641
+ const branch = getSocketBranchName(
4726
4642
  oldPurl,
4727
4643
  newVersion,
4728
- {
4729
- cwd,
4730
- workspaceName
4731
- }
4644
+ workspaceName
4732
4645
  )
4733
- if (prResponse) {
4734
- const { data } = prResponse
4735
- spinner?.info(`PR #${data.number} opened.`)
4736
- if (autoMerge) {
4737
- // eslint-disable-next-line no-await-in-loop
4738
- await enableAutoMerge(data)
4646
+ const shouldOpenPr = isCi
4647
+ ? // eslint-disable-next-line no-await-in-loop
4648
+ !(await doesPullRequestExistForBranch(owner, repo, branch))
4649
+ : false
4650
+ if (
4651
+ isCi &&
4652
+ shouldOpenPr &&
4653
+ // eslint-disable-next-line no-await-in-loop
4654
+ (await gitCreateAndPushBranchIfNeeded(
4655
+ branch,
4656
+ getSocketCommitMessage(oldPurl, newVersion, workspaceName),
4657
+ cwd
4658
+ ))
4659
+ ) {
4660
+ // eslint-disable-next-line no-await-in-loop
4661
+ const prResponse = await openGitHubPullRequest(
4662
+ owner,
4663
+ repo,
4664
+ baseBranch,
4665
+ branch,
4666
+ oldPurl,
4667
+ newVersion,
4668
+ {
4669
+ cwd,
4670
+ workspaceName
4671
+ }
4672
+ )
4673
+ if (prResponse) {
4674
+ const { data } = prResponse
4675
+ spinner?.info(`PR #${data.number} opened.`)
4676
+ if (autoMerge) {
4677
+ // eslint-disable-next-line no-await-in-loop
4678
+ await enableAutoMerge(data)
4679
+ }
4739
4680
  }
4740
4681
  }
4682
+ } catch (e) {
4683
+ error = e
4684
+ errored = true
4741
4685
  }
4742
4686
  if (errored || isCi) {
4743
- if (errored) {
4744
- if (!revertedSpecs.has(newSpecKey)) {
4745
- revertedSpecs.add(newSpecKey)
4746
- spinner?.error(`Reverting ${newSpec}${workspaceDetails}`, error)
4747
- }
4748
- }
4749
4687
  editablePkgJson.update(revertData)
4688
+
4750
4689
  // eslint-disable-next-line no-await-in-loop
4751
4690
  await Promise.all([
4752
4691
  shadowNpmInject.removeNodeModules(cwd),
4753
- ...(isRepo
4754
- ? [gitHardReset(cwd)]
4755
- : installed
4756
- ? [editablePkgJson.save()]
4757
- : [])
4692
+ ...(isCi
4693
+ ? [gitCheckoutBaseBranchIfAvailable(baseBranch, cwd)]
4694
+ : []),
4695
+ ...(isCi ? [] : [editablePkgJson.save()])
4758
4696
  ])
4697
+
4759
4698
  // eslint-disable-next-line no-await-in-loop
4760
4699
  actualTree = await install(pkgEnvDetails, {
4761
4700
  spinner
4762
4701
  })
4763
4702
  if (errored) {
4764
- if (!failedSpecs.has(newSpecKey)) {
4765
- failedSpecs.add(newSpecKey)
4766
- spinner?.failAndStop(
4767
- `Update failed for ${oldSpec}${workspaceDetails}`
4768
- )
4769
- }
4703
+ spinner?.failAndStop(
4704
+ `Update failed for ${oldSpec} in ${workspaceName}`,
4705
+ error
4706
+ )
4770
4707
  }
4771
4708
  }
4772
4709
  }
@@ -12341,7 +12278,7 @@ void (async () => {
12341
12278
  await vendor.updater({
12342
12279
  name: SOCKET_CLI_BIN_NAME,
12343
12280
  // The '@rollup/plugin-replace' will replace "process.env['INLINED_SOCKET_CLI_VERSION']".
12344
- version: '0.14.123',
12281
+ version: '0.14.125',
12345
12282
  ttl: 86_400_000 /* 24 hours in milliseconds */
12346
12283
  })
12347
12284
  try {
@@ -12409,5 +12346,5 @@ void (async () => {
12409
12346
  await shadowNpmInject.captureException(e)
12410
12347
  }
12411
12348
  })()
12412
- //# debugId=5bad9b77-6e22-4b32-a047-7f16520f50a3
12349
+ //# debugId=8c8790a2-a162-431b-99ab-b980237160d8
12413
12350
  //# sourceMappingURL=cli.js.map