socket 0.14.92 → 0.14.94

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.
@@ -43,8 +43,8 @@ const arrays = require('@socketsecurity/registry/lib/arrays')
43
43
  const registry = require('@socketsecurity/registry')
44
44
  const npm = require('@socketsecurity/registry/lib/npm')
45
45
  const packages = require('@socketsecurity/registry/lib/packages')
46
- const rest = _socketInterop(require('@octokit/rest'))
47
46
  const spawn = require('@socketsecurity/registry/lib/spawn')
47
+ const rest = _socketInterop(require('@octokit/rest'))
48
48
  const lockfile_fs = _socketInterop(require('@pnpm/lockfile.fs'))
49
49
  const lockfile_detectDepTypes = _socketInterop(
50
50
  require('@pnpm/lockfile.detect-dep-types')
@@ -918,7 +918,7 @@ function emitBanner(name) {
918
918
  logger.logger.error(getAsciiHeader(name))
919
919
  }
920
920
  function getAsciiHeader(command) {
921
- const cliVersion = '0.14.92:5d5aa04:71fedd04:pub' // The '@rollup/plugin-replace' will replace "process.env['INLINED_SOCKET_CLI_VERSION_HASH']".
921
+ const cliVersion = '0.14.94:8a54136:931df7a9:pub' // The '@rollup/plugin-replace' will replace "process.env['INLINED_SOCKET_CLI_VERSION_HASH']".
922
922
  const nodeVersion = process$1.version
923
923
  const apiToken = shadowNpmInject.getDefaultToken()
924
924
  const shownToken = apiToken ? getLastFiveOfApiToken(apiToken) : 'no'
@@ -3715,26 +3715,7 @@ const cmdDiffScan = {
3715
3715
  }
3716
3716
  }
3717
3717
 
3718
- const {
3719
- GITHUB_ACTIONS,
3720
- GITHUB_REF_NAME,
3721
- GITHUB_REPOSITORY,
3722
- SOCKET_SECURITY_GITHUB_PAT
3723
- } = constants
3724
- async function branchExists(branch, cwd = process.cwd()) {
3725
- try {
3726
- await spawn.spawn(
3727
- 'git',
3728
- ['show-ref', '--verify', '--quiet', `refs/heads/${branch}`],
3729
- {
3730
- cwd,
3731
- stdio: 'ignore'
3732
- }
3733
- )
3734
- return true
3735
- } catch {}
3736
- return false
3737
- }
3718
+ const { GITHUB_REF_NAME } = constants
3738
3719
  async function checkoutBaseBranchIfAvailable(baseBranch, cwd = process.cwd()) {
3739
3720
  try {
3740
3721
  await spawn.spawn('git', ['checkout', baseBranch], {
@@ -3750,6 +3731,21 @@ async function checkoutBaseBranchIfAvailable(baseBranch, cwd = process.cwd()) {
3750
3731
  )
3751
3732
  }
3752
3733
  }
3734
+ function getBaseBranch() {
3735
+ // Lazily access constants.ENV[GITHUB_REF_NAME].
3736
+ return (
3737
+ constants.ENV[GITHUB_REF_NAME] ??
3738
+ // GitHub defaults to branch name "main"
3739
+ // 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
3740
+ 'main'
3741
+ )
3742
+ }
3743
+ function getSocketBranchName(name, version) {
3744
+ return `socket-fix-${name}-${version.replace(/\./g, '-')}`
3745
+ }
3746
+
3747
+ const { GITHUB_ACTIONS, GITHUB_REPOSITORY, SOCKET_SECURITY_GITHUB_PAT } =
3748
+ constants
3753
3749
  let _octokit
3754
3750
  function getOctokit() {
3755
3751
  if (_octokit === undefined) {
@@ -3811,12 +3807,10 @@ function getGitHubRepoInfo() {
3811
3807
  repo: ownerSlashRepo.slice(slashIndex + 1)
3812
3808
  }
3813
3809
  }
3814
- function getSocketBranchName(name, version) {
3815
- return `socket-fix-${name}-${version.replace(/\./g, '-')}`
3816
- }
3817
3810
  async function openGitHubPullRequest(
3818
3811
  owner,
3819
3812
  repo,
3813
+ baseBranch,
3820
3814
  branch,
3821
3815
  name,
3822
3816
  version,
@@ -3829,42 +3823,17 @@ async function openGitHubPullRequest(
3829
3823
  if (!pat) {
3830
3824
  throw new Error('Missing SOCKET_SECURITY_GITHUB_PAT environment variable')
3831
3825
  }
3832
- const baseBranch =
3833
- // Lazily access constants.ENV[GITHUB_REF_NAME].
3834
- constants.ENV[GITHUB_REF_NAME] ??
3835
- // GitHub defaults to branch name "main"
3836
- // 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
3837
- 'main'
3838
3826
  const commitMsg = `chore: upgrade ${name} to ${version}`
3839
3827
  const url = `https://x-access-token:${pat}@github.com/${owner}/${repo}`
3840
3828
  await spawn.spawn('git', ['remote', 'set-url', 'origin', url], {
3841
3829
  cwd
3842
3830
  })
3843
- if (await branchExists(branch, cwd)) {
3844
- logger.logger.warn(
3845
- `Branch "${branch}" already exists. Skipping creation.`
3846
- )
3847
- } else {
3848
- await checkoutBaseBranchIfAvailable(baseBranch, cwd)
3849
- await spawn.spawn('git', ['checkout', '-b', branch], {
3850
- cwd
3851
- })
3852
- await spawn.spawn('git', ['add', 'package.json', 'pnpm-lock.yaml'], {
3853
- cwd
3854
- })
3855
- await spawn.spawn('git', ['commit', '-m', commitMsg], {
3856
- cwd
3857
- })
3858
- await spawn.spawn('git', ['push', '--set-upstream', 'origin', branch], {
3859
- cwd
3860
- })
3861
- }
3862
3831
  const octokit = getOctokit()
3863
3832
  return await octokit.pulls.create({
3864
3833
  owner,
3865
3834
  repo,
3866
3835
  title: commitMsg,
3867
- head: branch,
3836
+ head: `${owner}:${branch}`,
3868
3837
  base: baseBranch,
3869
3838
  body: `[socket] Upgrade \`${name}\` to ${version}`
3870
3839
  })
@@ -3983,6 +3952,12 @@ async function npmFix(
3983
3952
  : undefined)
3984
3953
  }
3985
3954
  spinner?.info(`Installing ${fixSpec}`)
3955
+ const { owner, repo } = getGitHubRepoInfo()
3956
+ const baseBranch = getBaseBranch()
3957
+ const branch = getSocketBranchName(name, targetVersion)
3958
+
3959
+ // eslint-disable-next-line no-await-in-loop
3960
+ await checkoutBaseBranchIfAvailable(baseBranch, cwd)
3986
3961
  let installed = false
3987
3962
  let saved = false
3988
3963
  try {
@@ -4028,8 +4003,6 @@ async function npmFix(
4028
4003
  spinner?.failAndStop(`Failed to fix ${oldSpec}`)
4029
4004
  return
4030
4005
  }
4031
- const { owner, repo } = getGitHubRepoInfo()
4032
- const branch = getSocketBranchName(name, targetVersion)
4033
4006
  if (
4034
4007
  // Lazily access constants.ENV[CI].
4035
4008
  constants.ENV[CI$1] &&
@@ -4042,6 +4015,7 @@ async function npmFix(
4042
4015
  prResponse = await openGitHubPullRequest(
4043
4016
  owner,
4044
4017
  repo,
4018
+ baseBranch,
4045
4019
  branch,
4046
4020
  name,
4047
4021
  targetVersion,
@@ -4414,6 +4388,12 @@ async function pnpmFix(
4414
4388
  : undefined)
4415
4389
  }
4416
4390
  spinner?.info(`Installing ${fixSpec}`)
4391
+ const { owner, repo } = getGitHubRepoInfo()
4392
+ const baseBranch = getBaseBranch()
4393
+ const branch = getSocketBranchName(name, targetVersion)
4394
+
4395
+ // eslint-disable-next-line no-await-in-loop
4396
+ await checkoutBaseBranchIfAvailable(baseBranch, cwd)
4417
4397
  let installed = false
4418
4398
  let saved = false
4419
4399
  try {
@@ -4460,8 +4440,6 @@ async function pnpmFix(
4460
4440
  spinner?.failAndStop(`Failed to fix ${oldSpec}`)
4461
4441
  return
4462
4442
  }
4463
- const { owner, repo } = getGitHubRepoInfo()
4464
- const branch = getSocketBranchName(name, targetVersion)
4465
4443
  if (
4466
4444
  // Lazily access constants.ENV[CI].
4467
4445
  constants.ENV[CI] &&
@@ -4474,6 +4452,7 @@ async function pnpmFix(
4474
4452
  prResponse = await openGitHubPullRequest(
4475
4453
  owner,
4476
4454
  repo,
4455
+ baseBranch,
4477
4456
  branch,
4478
4457
  name,
4479
4458
  targetVersion,
@@ -11378,7 +11357,7 @@ void (async () => {
11378
11357
  await updateNotifier({
11379
11358
  name: SOCKET_CLI_BIN_NAME,
11380
11359
  // The '@rollup/plugin-replace' will replace "process.env['INLINED_SOCKET_CLI_VERSION']".
11381
- version: '0.14.92',
11360
+ version: '0.14.94',
11382
11361
  ttl: 86_400_000 /* 24 hours in milliseconds */
11383
11362
  })
11384
11363
  try {
@@ -11446,5 +11425,5 @@ void (async () => {
11446
11425
  await shadowNpmInject.captureException(e)
11447
11426
  }
11448
11427
  })()
11449
- //# debugId=64db5375-59c3-42aa-a735-1930e57bbe2
11428
+ //# debugId=2d759c1d-e112-45d0-b84d-e2f8bdac075e
11450
11429
  //# sourceMappingURL=cli.js.map