socket 0.14.95 → 0.14.97

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.
@@ -899,7 +899,7 @@ function emitBanner(name) {
899
899
  logger.logger.error(getAsciiHeader(name))
900
900
  }
901
901
  function getAsciiHeader(command) {
902
- const cliVersion = '0.14.95:3360fca:2f20c717:pub' // The '@rollup/plugin-replace' will replace "process.env['INLINED_SOCKET_CLI_VERSION_HASH']".
902
+ const cliVersion = '0.14.97:f7d4687:082655df:pub' // The '@rollup/plugin-replace' will replace "process.env['INLINED_SOCKET_CLI_VERSION_HASH']".
903
903
  const nodeVersion = process$1.version
904
904
  const apiToken = shadowNpmInject.getDefaultToken()
905
905
  const shownToken = apiToken ? getLastFiveOfApiToken(apiToken) : 'no'
@@ -3701,6 +3701,20 @@ const cmdDiffScan = {
3701
3701
  }
3702
3702
 
3703
3703
  const { GITHUB_REF_NAME } = constants
3704
+ async function branchExists(branch, cwd = process.cwd()) {
3705
+ try {
3706
+ await spawn.spawn(
3707
+ 'git',
3708
+ ['show-ref', '--verify', '--quiet', `refs/heads/${branch}`],
3709
+ {
3710
+ cwd,
3711
+ stdio: 'ignore'
3712
+ }
3713
+ )
3714
+ return true
3715
+ } catch {}
3716
+ return false
3717
+ }
3704
3718
  async function checkoutBaseBranchIfAvailable(baseBranch, cwd = process.cwd()) {
3705
3719
  try {
3706
3720
  await spawn.spawn('git', ['checkout', baseBranch], {
@@ -3716,6 +3730,29 @@ async function checkoutBaseBranchIfAvailable(baseBranch, cwd = process.cwd()) {
3716
3730
  )
3717
3731
  }
3718
3732
  }
3733
+ async function createAndPushBranchIfNeeded(
3734
+ branch,
3735
+ commitMsg,
3736
+ cwd = process.cwd()
3737
+ ) {
3738
+ if (await branchExists(branch, cwd)) {
3739
+ logger.logger.warn(`Branch "${branch}" already exists. Skipping creation.`)
3740
+ return false
3741
+ }
3742
+ await spawn.spawn('git', ['checkout', '-b', branch], {
3743
+ cwd
3744
+ })
3745
+ await spawn.spawn('git', ['add', 'package.json', 'pnpm-lock.yaml'], {
3746
+ cwd
3747
+ })
3748
+ await spawn.spawn('git', ['commit', '-m', commitMsg], {
3749
+ cwd
3750
+ })
3751
+ await spawn.spawn('git', ['push', '--set-upstream', 'origin', branch], {
3752
+ cwd
3753
+ })
3754
+ return true
3755
+ }
3719
3756
  function getBaseBranch() {
3720
3757
  // Lazily access constants.ENV[GITHUB_REF_NAME].
3721
3758
  return (
@@ -3808,7 +3845,6 @@ async function openGitHubPullRequest(
3808
3845
  if (!pat) {
3809
3846
  throw new Error('Missing SOCKET_SECURITY_GITHUB_PAT environment variable')
3810
3847
  }
3811
- const commitMsg = `chore: upgrade ${name} to ${version}`
3812
3848
  const url = `https://x-access-token:${pat}@github.com/${owner}/${repo}`
3813
3849
  await spawn.spawn('git', ['remote', 'set-url', 'origin', url], {
3814
3850
  cwd
@@ -3817,8 +3853,8 @@ async function openGitHubPullRequest(
3817
3853
  return await octokit.pulls.create({
3818
3854
  owner,
3819
3855
  repo,
3820
- title: commitMsg,
3821
- head: `${owner}:${branch}`,
3856
+ title: `chore: upgrade ${name} to ${version}`,
3857
+ head: branch,
3822
3858
  base: baseBranch,
3823
3859
  body: `[socket] Upgrade \`${name}\` to ${version}`
3824
3860
  })
@@ -3917,6 +3953,21 @@ async function npmFix(
3917
3953
  return
3918
3954
  }
3919
3955
  const targetVersion = node.package.version
3956
+ let branch
3957
+ let owner
3958
+ let repo
3959
+ let shouldOpenPr = false
3960
+ // Lazily access constants.ENV[CI].
3961
+ if (constants.ENV[CI$1]) {
3962
+ ;({ owner, repo } = getGitHubRepoInfo())
3963
+ branch = getSocketBranchName(name, targetVersion)
3964
+ // eslint-disable-next-line no-await-in-loop
3965
+ shouldOpenPr = !(await doesPullRequestExistForBranch(
3966
+ owner,
3967
+ repo,
3968
+ branch
3969
+ ))
3970
+ }
3920
3971
  const fixSpec = `${name}@^${targetVersion}`
3921
3972
  const revertData = {
3922
3973
  ...(editablePkgJson.content.dependencies
@@ -3937,9 +3988,7 @@ async function npmFix(
3937
3988
  : undefined)
3938
3989
  }
3939
3990
  spinner?.info(`Installing ${fixSpec}`)
3940
- const { owner, repo } = getGitHubRepoInfo()
3941
3991
  const baseBranch = getBaseBranch()
3942
- const branch = getSocketBranchName(name, targetVersion)
3943
3992
 
3944
3993
  // eslint-disable-next-line no-await-in-loop
3945
3994
  await checkoutBaseBranchIfAvailable(baseBranch, cwd)
@@ -3988,12 +4037,7 @@ async function npmFix(
3988
4037
  spinner?.failAndStop(`Failed to fix ${oldSpec}`)
3989
4038
  return
3990
4039
  }
3991
- if (
3992
- // Lazily access constants.ENV[CI].
3993
- constants.ENV[CI$1] &&
3994
- // eslint-disable-next-line no-await-in-loop
3995
- !(await doesPullRequestExistForBranch(owner, repo, branch))
3996
- ) {
4040
+ if (shouldOpenPr) {
3997
4041
  let prResponse
3998
4042
  try {
3999
4043
  // eslint-disable-next-line no-await-in-loop
@@ -4320,6 +4364,21 @@ async function pnpmFix(
4320
4364
  spinner?.failAndStop(`Could not patch ${oldSpec}`)
4321
4365
  return
4322
4366
  }
4367
+ let branch
4368
+ let owner
4369
+ let repo
4370
+ let shouldOpenPr = false
4371
+ // Lazily access constants.ENV[CI].
4372
+ if (constants.ENV[CI]) {
4373
+ ;({ owner, repo } = getGitHubRepoInfo())
4374
+ branch = getSocketBranchName(name, targetVersion)
4375
+ // eslint-disable-next-line no-await-in-loop
4376
+ shouldOpenPr = !(await doesPullRequestExistForBranch(
4377
+ owner,
4378
+ repo,
4379
+ branch
4380
+ ))
4381
+ }
4323
4382
  const oldPnpm = editablePkgJson.content[PNPM$9]
4324
4383
  const oldPnpmKeyCount = oldPnpm ? Object.keys(oldPnpm).length : 0
4325
4384
  const oldOverrides = oldPnpm?.[OVERRIDES$2]
@@ -4373,9 +4432,7 @@ async function pnpmFix(
4373
4432
  : undefined)
4374
4433
  }
4375
4434
  spinner?.info(`Installing ${fixSpec}`)
4376
- const { owner, repo } = getGitHubRepoInfo()
4377
4435
  const baseBranch = getBaseBranch()
4378
- const branch = getSocketBranchName(name, targetVersion)
4379
4436
 
4380
4437
  // eslint-disable-next-line no-await-in-loop
4381
4438
  await checkoutBaseBranchIfAvailable(baseBranch, cwd)
@@ -4425,12 +4482,13 @@ async function pnpmFix(
4425
4482
  spinner?.failAndStop(`Failed to fix ${oldSpec}`)
4426
4483
  return
4427
4484
  }
4428
- if (
4429
- // Lazily access constants.ENV[CI].
4430
- constants.ENV[CI] &&
4485
+ if (shouldOpenPr) {
4431
4486
  // eslint-disable-next-line no-await-in-loop
4432
- !(await doesPullRequestExistForBranch(owner, repo, branch))
4433
- ) {
4487
+ await createAndPushBranchIfNeeded(
4488
+ branch,
4489
+ `fix: upgrade ${name} to ${targetVersion}`,
4490
+ cwd
4491
+ )
4434
4492
  let prResponse
4435
4493
  try {
4436
4494
  // eslint-disable-next-line no-await-in-loop
@@ -11377,7 +11435,7 @@ void (async () => {
11377
11435
  await vendor.updater({
11378
11436
  name: SOCKET_CLI_BIN_NAME,
11379
11437
  // The '@rollup/plugin-replace' will replace "process.env['INLINED_SOCKET_CLI_VERSION']".
11380
- version: '0.14.95',
11438
+ version: '0.14.97',
11381
11439
  ttl: 86_400_000 /* 24 hours in milliseconds */
11382
11440
  })
11383
11441
  try {
@@ -11445,5 +11503,5 @@ void (async () => {
11445
11503
  await shadowNpmInject.captureException(e)
11446
11504
  }
11447
11505
  })()
11448
- //# debugId=9f53b90b-62bf-4628-b569-5d16084361e8
11506
+ //# debugId=53d9bce0-9bbb-40a0-bcce-f9bb6e02c76
11449
11507
  //# sourceMappingURL=cli.js.map