@socketsecurity/cli-with-sentry 0.15.61 → 0.15.62

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.
package/dist/cli.js CHANGED
@@ -3660,29 +3660,64 @@ async function outputFixResult(result, outputKind) {
3660
3660
  function formatBranchName(name) {
3661
3661
  return name.replace(/[^-a-zA-Z0-9/._-]+/g, '+');
3662
3662
  }
3663
- function getBaseGitBranch() {
3664
- // Lazily access constants.ENV.GITHUB_REF_NAME.
3665
- return constants.ENV.GITHUB_REF_NAME ||
3663
+ function createSocketBranchParser(options) {
3664
+ const pattern = getSocketBranchPattern(options);
3665
+ return function parse(branch) {
3666
+ const match = pattern.exec(branch);
3667
+ if (!match) {
3668
+ return null;
3669
+ }
3670
+ const {
3671
+ 1: type,
3672
+ 2: workspace,
3673
+ 3: fullName,
3674
+ 4: version,
3675
+ 5: newVersion
3676
+ } = match;
3677
+ return {
3678
+ fullName,
3679
+ newVersion: vendor.semverExports.coerce(newVersion.replaceAll('+', '.'))?.version,
3680
+ type,
3681
+ workspace,
3682
+ version: vendor.semverExports.coerce(version.replaceAll('+', '.'))?.version
3683
+ };
3684
+ };
3685
+ }
3686
+ async function getBaseGitBranch(cwd = process.cwd()) {
3687
+ // Lazily access constants.ENV properties.
3688
+ const {
3689
+ GITHUB_BASE_REF,
3690
+ GITHUB_REF_NAME,
3691
+ GITHUB_REF_TYPE
3692
+ } = constants.ENV;
3693
+ // 1. In a pull request, this is always the base branch.
3694
+ if (GITHUB_BASE_REF) {
3695
+ return GITHUB_BASE_REF;
3696
+ }
3697
+ // 2. If it's a branch (not a tag), GITHUB_REF_TYPE should be 'branch'.
3698
+ if (GITHUB_REF_TYPE === 'branch' && GITHUB_REF_NAME) {
3699
+ return GITHUB_REF_NAME;
3700
+ }
3701
+ // 3. Try to resolve the default remote branch using 'git remote show origin'.
3702
+ // This handles detached HEADs or workflows triggered by tags/releases.
3703
+ try {
3704
+ const stdout = (await spawn.spawn('git', ['remote', 'show', 'origin'], {
3705
+ cwd
3706
+ })).stdout.trim();
3707
+ const match = /(?<=HEAD branch: ).+/.exec(stdout);
3708
+ if (match?.[0]) {
3709
+ return match[0].trim();
3710
+ }
3711
+ } catch {}
3666
3712
  // GitHub defaults to branch name "main"
3667
3713
  // 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
3668
- 'main';
3669
- }
3670
- function getSocketBranchPurlTypeComponent(purl) {
3671
- const purlObj = utils.getPurlObject(purl);
3672
- return formatBranchName(purlObj.type);
3714
+ return 'main';
3673
3715
  }
3674
3716
  function getSocketBranchFullNameComponent(pkgName) {
3675
3717
  const purlObj = utils.getPurlObject(typeof pkgName === 'string' && !pkgName.startsWith('pkg:') ? vendor.packageurlJsExports.PackageURL.fromString(`pkg:unknown/${pkgName}`) : pkgName);
3676
3718
  const fmtMaybeNamespace = purlObj.namespace ? `${formatBranchName(purlObj.namespace)}--` : '';
3677
3719
  return `${fmtMaybeNamespace}${formatBranchName(purlObj.name)}`;
3678
3720
  }
3679
- function getSocketBranchPackageVersionComponent(version) {
3680
- const purlObj = utils.getPurlObject(typeof version === 'string' && !version.startsWith('pkg:') ? vendor.packageurlJsExports.PackageURL.fromString(`pkg:unknown/unknown@${version}`) : version);
3681
- return formatBranchName(purlObj.version);
3682
- }
3683
- function getSocketBranchWorkspaceComponent(workspace) {
3684
- return workspace ? formatBranchName(workspace) : 'root';
3685
- }
3686
3721
  function getSocketBranchName(purl, newVersion, workspace) {
3687
3722
  const purlObj = utils.getPurlObject(purl);
3688
3723
  const fmtType = getSocketBranchPurlTypeComponent(purlObj);
@@ -3692,6 +3727,10 @@ function getSocketBranchName(purl, newVersion, workspace) {
3692
3727
  const fmtNewVersion = formatBranchName(newVersion);
3693
3728
  return `socket/${fmtType}/${fmtWorkspace}/${fmtFullName}_${fmtVersion}_${fmtNewVersion}`;
3694
3729
  }
3730
+ function getSocketBranchPackageVersionComponent(version) {
3731
+ const purlObj = utils.getPurlObject(typeof version === 'string' && !version.startsWith('pkg:') ? vendor.packageurlJsExports.PackageURL.fromString(`pkg:unknown/unknown@${version}`) : version);
3732
+ return formatBranchName(purlObj.version);
3733
+ }
3695
3734
  function getSocketBranchPattern(options) {
3696
3735
  const {
3697
3736
  newVersion,
@@ -3710,33 +3749,17 @@ function getSocketBranchPattern(options) {
3710
3749
  const escNewVersion = newVersion ? regexps.escapeRegExp(formatBranchName(newVersion)) : '[^_]+';
3711
3750
  return new RegExp(`^socket/(${escType})/(${escWorkspace})/(${escFullName})_(${escVersion})_(${escNewVersion})$`);
3712
3751
  }
3713
- function createSocketBranchParser(options) {
3714
- const pattern = getSocketBranchPattern(options);
3715
- return function parse(branch) {
3716
- const match = pattern.exec(branch);
3717
- if (!match) {
3718
- return null;
3719
- }
3720
- const {
3721
- 1: type,
3722
- 2: workspace,
3723
- 3: fullName,
3724
- 4: version,
3725
- 5: newVersion
3726
- } = match;
3727
- return {
3728
- fullName,
3729
- newVersion: vendor.semverExports.coerce(newVersion.replaceAll('+', '.'))?.version,
3730
- type,
3731
- workspace,
3732
- version: vendor.semverExports.coerce(version.replaceAll('+', '.'))?.version
3733
- };
3734
- };
3752
+ function getSocketBranchPurlTypeComponent(purl) {
3753
+ const purlObj = utils.getPurlObject(purl);
3754
+ return formatBranchName(purlObj.type);
3735
3755
  }
3736
- function getSocketPullRequestTitle(purl, newVersion, workspace) {
3756
+ function getSocketBranchWorkspaceComponent(workspace) {
3757
+ return workspace ? formatBranchName(workspace) : 'root';
3758
+ }
3759
+ function getSocketCommitMessage(purl, newVersion, workspace) {
3737
3760
  const purlObj = utils.getPurlObject(purl);
3738
3761
  const fullName = utils.getPkgFullNameFromPurl(purlObj);
3739
- return `Bump ${fullName} from ${purlObj.version} to ${newVersion}${workspace ? ` in ${workspace}` : ''}`;
3762
+ return `socket: Bump ${fullName} from ${purlObj.version} to ${newVersion}${workspace ? ` in ${workspace}` : ''}`;
3740
3763
  }
3741
3764
  function getSocketPullRequestBody(purl, newVersion, workspace) {
3742
3765
  const purlObj = utils.getPurlObject(purl);
@@ -3744,10 +3767,10 @@ function getSocketPullRequestBody(purl, newVersion, workspace) {
3744
3767
  const pkgOverviewUrl = utils.getSocketDevPackageOverviewUrlFromPurl(purlObj);
3745
3768
  return `Bump [${fullName}](${pkgOverviewUrl}) from ${purlObj.version} to ${newVersion}${workspace ? ` in ${workspace}` : ''}.`;
3746
3769
  }
3747
- function getSocketCommitMessage(purl, newVersion, workspace) {
3770
+ function getSocketPullRequestTitle(purl, newVersion, workspace) {
3748
3771
  const purlObj = utils.getPurlObject(purl);
3749
3772
  const fullName = utils.getPkgFullNameFromPurl(purlObj);
3750
- return `socket: Bump ${fullName} from ${purlObj.version} to ${newVersion}${workspace ? ` in ${workspace}` : ''}`;
3773
+ return `Bump ${fullName} from ${purlObj.version} to ${newVersion}${workspace ? ` in ${workspace}` : ''}`;
3751
3774
  }
3752
3775
  async function gitCleanFdx(cwd = process.cwd()) {
3753
3776
  const stdioIgnoreOptions = {
@@ -3780,7 +3803,7 @@ async function gitCreateAndPushBranch(branch, commitMsg, filepaths, options) {
3780
3803
  await spawn.spawn('git', ['push', '--force', '--set-upstream', 'origin', branch], stdioIgnoreOptions);
3781
3804
  return true;
3782
3805
  } catch (e) {
3783
- debug.debugFn('catch: unexpected\n', e);
3806
+ debug.debugFn(`catch: git push --force --set-upstream origin ${branch} failed\n`, e);
3784
3807
  }
3785
3808
  try {
3786
3809
  // Will throw with exit code 1 if branch does not exist.
@@ -3788,6 +3811,38 @@ async function gitCreateAndPushBranch(branch, commitMsg, filepaths, options) {
3788
3811
  } catch {}
3789
3812
  return false;
3790
3813
  }
3814
+ async function gitRepoInfo(cwd = process.cwd()) {
3815
+ try {
3816
+ const remoteUrl = (await spawn.spawn('git', ['remote', 'get-url', 'origin'], {
3817
+ cwd
3818
+ })).stdout.trim();
3819
+ // 1. Handle SSH-style, e.g. git@github.com:owner/repo.git
3820
+ const sshMatch = /^git@[^:]+:([^/]+)\/(.+?)(?:\.git)?$/.exec(remoteUrl);
3821
+ if (sshMatch) {
3822
+ return {
3823
+ owner: sshMatch[1],
3824
+ repo: sshMatch[2]
3825
+ };
3826
+ }
3827
+ // 2. Handle HTTPS/URL-style, e.g. https://github.com/owner/repo.git
3828
+ try {
3829
+ const parsed = new URL(remoteUrl);
3830
+ const segments = parsed.pathname.split('/');
3831
+ const owner = segments.at(-2);
3832
+ const repo = segments.at(-1)?.replace(/\.git$/, '');
3833
+ if (owner && repo) {
3834
+ return {
3835
+ owner,
3836
+ repo
3837
+ };
3838
+ }
3839
+ } catch {}
3840
+ debug.debugFn('git: unmatched git remote URL format', remoteUrl);
3841
+ } catch (e) {
3842
+ debug.debugFn('catch: git remote get-url origin failed\n', e);
3843
+ }
3844
+ return null;
3845
+ }
3791
3846
  async function gitEnsureIdentity(name, email, cwd = process.cwd()) {
3792
3847
  const stdioIgnoreOptions = {
3793
3848
  cwd,
@@ -3810,7 +3865,7 @@ async function gitEnsureIdentity(name, email, cwd = process.cwd()) {
3810
3865
  try {
3811
3866
  await spawn.spawn('git', ['config', prop, value], stdioIgnoreOptions);
3812
3867
  } catch (e) {
3813
- debug.debugFn('catch: unexpected\n', e);
3868
+ debug.debugFn(`catch: git config ${prop} ${value} failed\n`, e);
3814
3869
  }
3815
3870
  }
3816
3871
  }));
@@ -4075,24 +4130,6 @@ async function enablePrAutoMerge({
4075
4130
  enabled: false
4076
4131
  };
4077
4132
  }
4078
- function getGithubEnvRepoInfo() {
4079
- // Lazily access constants.ENV.GITHUB_REPOSITORY.
4080
- const {
4081
- GITHUB_REPOSITORY
4082
- } = constants.ENV;
4083
- if (!GITHUB_REPOSITORY) {
4084
- debug.debugFn('miss: GITHUB_REPOSITORY env var');
4085
- }
4086
- const ownerSlashRepo = GITHUB_REPOSITORY;
4087
- const slashIndex = ownerSlashRepo.indexOf('/');
4088
- if (slashIndex === -1) {
4089
- return null;
4090
- }
4091
- return {
4092
- owner: ownerSlashRepo.slice(0, slashIndex),
4093
- repo: ownerSlashRepo.slice(slashIndex + 1)
4094
- };
4095
- }
4096
4133
  async function getOpenSocketPrs(owner, repo, options) {
4097
4134
  return (await getOpenSocketPrsWithContext(owner, repo, options)).map(d => d.match);
4098
4135
  }
@@ -4218,11 +4255,6 @@ async function openPr(owner, repo, branch, purl, newVersion, options) {
4218
4255
  __proto__: null,
4219
4256
  ...options
4220
4257
  };
4221
- // Lazily access constants.ENV.GITHUB_ACTIONS.
4222
- if (!constants.ENV.GITHUB_ACTIONS) {
4223
- debug.debugFn('miss: GITHUB_ACTIONS env var');
4224
- return null;
4225
- }
4226
4258
  const purlObj = utils.getPurlObject(purl);
4227
4259
  const octokit = getOctokit();
4228
4260
  try {
@@ -4274,19 +4306,48 @@ async function setGitRemoteGithubRepoUrl(owner, repo, token, cwd = process.cwd()
4274
4306
  }
4275
4307
  }
4276
4308
 
4277
- function getCiEnv() {
4309
+ async function getEnvRepoInfo(cwd) {
4310
+ // Lazily access constants.ENV.GITHUB_REPOSITORY.
4311
+ const {
4312
+ GITHUB_REPOSITORY
4313
+ } = constants.ENV;
4314
+ if (!GITHUB_REPOSITORY) {
4315
+ debug.debugFn('miss: GITHUB_REPOSITORY env var');
4316
+ }
4317
+ const ownerSlashRepo = GITHUB_REPOSITORY;
4318
+ const slashIndex = ownerSlashRepo.indexOf('/');
4319
+ if (slashIndex !== -1) {
4320
+ return {
4321
+ owner: ownerSlashRepo.slice(0, slashIndex),
4322
+ repo: ownerSlashRepo.slice(slashIndex + 1)
4323
+ };
4324
+ }
4325
+ return await gitRepoInfo(cwd);
4326
+ }
4327
+ async function getCiEnv() {
4278
4328
  const gitEmail = constants.ENV.SOCKET_CLI_GIT_USER_EMAIL;
4279
4329
  const gitUser = constants.ENV.SOCKET_CLI_GIT_USER_NAME;
4280
4330
  const githubToken = constants.ENV.SOCKET_CLI_GITHUB_TOKEN;
4281
- const isCi = !!(constants.ENV.CI && constants.ENV.GITHUB_ACTIONS && constants.ENV.GITHUB_REPOSITORY && gitEmail && gitUser && githubToken);
4282
- return isCi ? {
4331
+ const isCi = !!(constants.ENV.CI && gitEmail && gitUser && githubToken);
4332
+ if (!isCi) {
4333
+ return null;
4334
+ }
4335
+ const baseBranch = await getBaseGitBranch();
4336
+ if (!baseBranch) {
4337
+ return null;
4338
+ }
4339
+ const repoInfo = await getEnvRepoInfo();
4340
+ if (!repoInfo) {
4341
+ return null;
4342
+ }
4343
+ return {
4283
4344
  gitEmail,
4284
4345
  gitUser,
4285
4346
  githubToken,
4286
- repoInfo: getGithubEnvRepoInfo(),
4287
- baseBranch: getBaseGitBranch(),
4347
+ repoInfo,
4348
+ baseBranch,
4288
4349
  branchParser: createSocketBranchParser()
4289
- } : null;
4350
+ };
4290
4351
  }
4291
4352
  async function getOpenPrsForEnvironment(env) {
4292
4353
  return env ? await getOpenSocketPrs(env.repoInfo.owner, env.repoInfo.repo, {
@@ -4346,7 +4407,7 @@ async function npmFix(pkgEnvDetails, {
4346
4407
  pkgPath: rootPath
4347
4408
  } = pkgEnvDetails;
4348
4409
  spinner?.start();
4349
- const ciEnv = getCiEnv();
4410
+ const ciEnv = await getCiEnv();
4350
4411
  const openPrs = ciEnv ? await getOpenPrsForEnvironment(ciEnv) : [];
4351
4412
  let count = 0;
4352
4413
  const arb = new shadowNpmInject.Arborist({
@@ -4461,6 +4522,7 @@ async function npmFix(pkgEnvDetails, {
4461
4522
  const editablePkgJson = await packages.readPackageJson(pkgJsonPath, {
4462
4523
  editable: true
4463
4524
  });
4525
+ const fixedVersions = new Set();
4464
4526
  let hasAnnouncedWorkspace = false;
4465
4527
  let workspaceLogCallCount = logger.logger.logCallCount;
4466
4528
  if (debug.isDebug()) {
@@ -4486,6 +4548,9 @@ async function npmFix(pkgEnvDetails, {
4486
4548
  warningsForAfter.add(`${oldId} not updated: requires >=${firstPatchedVersionIdentifier}`);
4487
4549
  continue infosLoop;
4488
4550
  }
4551
+ if (fixedVersions.has(newVersion)) {
4552
+ continue infosLoop;
4553
+ }
4489
4554
  if (vendor.semverExports.gte(oldVersion, newVersion)) {
4490
4555
  debug.debugFn(`skip: ${oldId} is >= ${newVersion}`);
4491
4556
  continue infosLoop;
@@ -4557,6 +4622,7 @@ async function npmFix(pkgEnvDetails, {
4557
4622
  });
4558
4623
  }
4559
4624
  spinner?.success(`Fixed ${name} in ${workspace}.`);
4625
+ fixedVersions.add(newVersion);
4560
4626
  } else {
4561
4627
  errored = true;
4562
4628
  }
@@ -4783,7 +4849,7 @@ async function pnpmFix(pkgEnvDetails, {
4783
4849
  pkgPath: rootPath
4784
4850
  } = pkgEnvDetails;
4785
4851
  spinner?.start();
4786
- const ciEnv = getCiEnv();
4852
+ const ciEnv = await getCiEnv();
4787
4853
  const openPrs = ciEnv ? await getOpenPrsForEnvironment(ciEnv) : [];
4788
4854
  let count = 0;
4789
4855
  let actualTree;
@@ -4963,6 +5029,8 @@ async function pnpmFix(pkgEnvDetails, {
4963
5029
  const editablePkgJson = await packages.readPackageJson(pkgJsonPath, {
4964
5030
  editable: true
4965
5031
  });
5032
+ const fixedVersions = new Set();
5033
+
4966
5034
  // Get current overrides for revert logic.
4967
5035
  const oldPnpmSection = editablePkgJson.content[PNPM$7];
4968
5036
  const oldOverrides = oldPnpmSection?.[OVERRIDES$2];
@@ -4991,6 +5059,9 @@ async function pnpmFix(pkgEnvDetails, {
4991
5059
  warningsForAfter.add(`${oldId} not updated: requires >=${firstPatchedVersionIdentifier}`);
4992
5060
  continue infosLoop;
4993
5061
  }
5062
+ if (fixedVersions.has(newVersion)) {
5063
+ continue infosLoop;
5064
+ }
4994
5065
  if (vendor.semverExports.gte(oldVersion, newVersion)) {
4995
5066
  debug.debugFn(`skip: ${oldId} is >= ${newVersion}`);
4996
5067
  continue infosLoop;
@@ -5103,6 +5174,7 @@ async function pnpmFix(pkgEnvDetails, {
5103
5174
  });
5104
5175
  }
5105
5176
  spinner?.success(`Fixed ${name} in ${workspace}.`);
5177
+ fixedVersions.add(newVersion);
5106
5178
  } else {
5107
5179
  errored = true;
5108
5180
  }
@@ -14640,5 +14712,5 @@ void (async () => {
14640
14712
  await utils.captureException(e);
14641
14713
  }
14642
14714
  })();
14643
- //# debugId=f55e6ed3-61c1-4ff4-b932-f2758fcef19
14715
+ //# debugId=ff4cb15e-6c8d-4702-a71b-9fdebd5e1b1
14644
14716
  //# sourceMappingURL=cli.js.map