@socketsecurity/cli-with-sentry 0.15.24 → 0.15.26

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
@@ -24,6 +24,7 @@ var sorts = require('../external/@socketsecurity/registry/lib/sorts');
24
24
  var path$1 = require('../external/@socketsecurity/registry/lib/path');
25
25
  var regexps = require('../external/@socketsecurity/registry/lib/regexps');
26
26
  var fs$2 = require('../external/@socketsecurity/registry/lib/fs');
27
+ var strings = require('../external/@socketsecurity/registry/lib/strings');
27
28
  var shadowInject = require('./shadow-inject.js');
28
29
  var objects = require('../external/@socketsecurity/registry/lib/objects');
29
30
  var registryConstants = require('../external/@socketsecurity/registry/lib/constants');
@@ -3590,8 +3591,6 @@ const cmdDiffScan = {
3590
3591
  }
3591
3592
  };
3592
3593
 
3593
- const GITHUB_ACTIONS_BOT_USERNAME = 'github-actions[bot]';
3594
- const GITHUB_ACTIONS_BOT_EMAIL = `${GITHUB_ACTIONS_BOT_USERNAME}@users.noreply.github.com`;
3595
3594
  function formatBranchName(name) {
3596
3595
  return name.replace(/[-_.\\/]+/g, '-').replace(/[^-a-zA-Z0-9]+/g, '').replace(/^-+|-+$/g, '');
3597
3596
  }
@@ -3609,17 +3608,25 @@ function getSocketBranchName(purl, newVersion, workspaceName) {
3609
3608
  const fullName = `${maybeWorkspaceName}${maybeNamespace}${formatBranchName(purlObj.name)}`;
3610
3609
  return `socket/${fullName}-${formatBranchName(newVersion)}`;
3611
3610
  }
3612
- function getSocketPrTitlePattern(purl, workspaceName) {
3613
- const purlObj = vendor.packageurlJsExports.PackageURL.fromString(purl);
3614
- const pkgFullName = utils.getPkgFullNameFromPurlObj(purlObj);
3615
- const workspaceDetails = workspaceName ? ` in ${regexps.escapeRegExp(workspaceName)}` : '';
3616
- return new RegExp(`Bump ${regexps.escapeRegExp(pkgFullName)} from ${regexps.escapeRegExp(purlObj.version)} to \\S+${workspaceDetails}`);
3611
+ function getSocketPrTitlePattern(options) {
3612
+ const {
3613
+ purl,
3614
+ workspace
3615
+ } = {
3616
+ __proto__: null,
3617
+ ...options
3618
+ };
3619
+ const purlObj = purl ? vendor.packageurlJsExports.PackageURL.fromString(purl) : null;
3620
+ const escapedPkgFullName = purlObj ? regexps.escapeRegExp(utils.getPkgFullNameFromPurlObj(purlObj)) : '\\S+';
3621
+ const escapedPkgVersion = purlObj ? regexps.escapeRegExp(purlObj.version) : '\\S+';
3622
+ const escapedWorkspaceDetails = workspace ? ` in ${regexps.escapeRegExp(workspace)}` : '';
3623
+ return new RegExp(`Bump ${escapedPkgFullName} from ${escapedPkgVersion} to \\S+${escapedWorkspaceDetails}`);
3617
3624
  }
3618
- function getSocketPullRequestTitle(purl, newVersion, workspaceName) {
3625
+ function getSocketPullRequestTitle(purl, toVersion, workspace) {
3619
3626
  const purlObj = vendor.packageurlJsExports.PackageURL.fromString(purl);
3620
3627
  const pkgFullName = utils.getPkgFullNameFromPurlObj(purlObj);
3621
- const workspaceDetails = workspaceName ? ` in ${workspaceName}` : '';
3622
- return `Bump ${pkgFullName} from ${purlObj.version} to ${newVersion}${workspaceDetails}`;
3628
+ const workspaceDetails = workspace ? ` in ${workspace}` : '';
3629
+ return `Bump ${pkgFullName} from ${purlObj.version} to ${toVersion}${workspaceDetails}`;
3623
3630
  }
3624
3631
  function getSocketPullRequestBody(purl, newVersion, workspaceName) {
3625
3632
  const purlObj = vendor.packageurlJsExports.PackageURL.fromString(purl);
@@ -3640,13 +3647,23 @@ async function gitCleanFdx(cwd = process.cwd()) {
3640
3647
  };
3641
3648
  await spawn.spawn('git', ['clean', '-fdx'], stdioIgnoreOptions);
3642
3649
  }
3643
- async function gitCreateAndPushBranch(branch, commitMsg, filepaths, cwd = process.cwd()) {
3650
+ async function gitCreateAndPushBranch(branch, commitMsg, filepaths, options) {
3651
+ const {
3652
+ cwd = process.cwd(),
3653
+ // Lazily access constants.ENV.SOCKET_CLI_GIT_USER_EMAIL.
3654
+ email = constants.ENV.SOCKET_CLI_GIT_USER_EMAIL,
3655
+ // Lazily access constants.ENV.SOCKET_CLI_GIT_USER_NAME.
3656
+ user = constants.ENV.SOCKET_CLI_GIT_USER_NAME
3657
+ } = {
3658
+ __proto__: null,
3659
+ ...options
3660
+ };
3644
3661
  const stdioIgnoreOptions = {
3645
3662
  cwd,
3646
3663
  stdio: 'ignore'
3647
3664
  };
3648
3665
  try {
3649
- await gitEnsureIdentity(cwd);
3666
+ await gitEnsureIdentity(user, email, cwd);
3650
3667
  await spawn.spawn('git', ['checkout', '-b', branch], stdioIgnoreOptions);
3651
3668
  await spawn.spawn('git', ['add', ...filepaths], stdioIgnoreOptions);
3652
3669
  await spawn.spawn('git', ['commit', '-m', commitMsg], stdioIgnoreOptions);
@@ -3658,7 +3675,7 @@ async function gitCreateAndPushBranch(branch, commitMsg, filepaths, cwd = proces
3658
3675
  } catch {}
3659
3676
  return false;
3660
3677
  }
3661
- async function gitEnsureIdentity(cwd = process.cwd()) {
3678
+ async function gitEnsureIdentity(name, email, cwd = process.cwd()) {
3662
3679
  const stdioIgnoreOptions = {
3663
3680
  cwd,
3664
3681
  stdio: 'ignore'
@@ -3666,19 +3683,27 @@ async function gitEnsureIdentity(cwd = process.cwd()) {
3666
3683
  const stdioPipeOptions = {
3667
3684
  cwd
3668
3685
  };
3669
- let hasUserName = false;
3670
- try {
3671
- hasUserName = !!(await spawn.spawn('git', ['config', '--get', 'user.name'], stdioPipeOptions)).stdout.trim();
3672
- } catch {}
3673
- if (!hasUserName) {
3674
- await spawn.spawn('git', ['config', 'user.name', GITHUB_ACTIONS_BOT_USERNAME], stdioIgnoreOptions);
3675
- }
3676
- let hasUserEmail = false;
3686
+ const identEntries = [['user.email', name], ['user.name', email]];
3687
+ await Promise.all(identEntries.map(async ({
3688
+ 0: prop,
3689
+ 1: value
3690
+ }) => {
3691
+ try {
3692
+ const output = await spawn.spawn('git', ['config', '--get', prop], stdioPipeOptions);
3693
+ if (output.stdout.trim() !== value) {
3694
+ await spawn.spawn('git', ['config', prop, value], stdioIgnoreOptions);
3695
+ }
3696
+ } catch {}
3697
+ }));
3698
+ }
3699
+ async function gitRemoteBranchExists(branch, cwd = process.cwd()) {
3700
+ const stdioPipeOptions = {
3701
+ cwd
3702
+ };
3677
3703
  try {
3678
- hasUserEmail = !!(await spawn.spawn('git', ['config', '--get', 'user.email'], stdioPipeOptions)).stdout.trim();
3679
- } catch {}
3680
- if (!hasUserEmail) {
3681
- await spawn.spawn('git', ['config', 'user.email', GITHUB_ACTIONS_BOT_EMAIL], stdioIgnoreOptions);
3704
+ return (await spawn.spawn('git', ['ls-remote', '--heads', 'origin', branch], stdioPipeOptions)).stdout.trim().length > 0;
3705
+ } catch {
3706
+ return false;
3682
3707
  }
3683
3708
  }
3684
3709
  async function gitResetAndClean(branch = 'HEAD', cwd = process.cwd()) {
@@ -3694,16 +3719,6 @@ async function gitResetHard(branch = 'HEAD', cwd = process.cwd()) {
3694
3719
  };
3695
3720
  await spawn.spawn('git', ['reset', '--hard', branch], stdioIgnoreOptions);
3696
3721
  }
3697
- async function gitRemoteBranchExists(branch, cwd = process.cwd()) {
3698
- const stdioPipeOptions = {
3699
- cwd
3700
- };
3701
- try {
3702
- return (await spawn.spawn('git', ['ls-remote', '--heads', 'origin', branch], stdioPipeOptions)).stdout.trim().length > 0;
3703
- } catch {
3704
- return false;
3705
- }
3706
- }
3707
3722
  async function gitUnstagedModifiedFiles(cwd = process.cwd()) {
3708
3723
  const stdioPipeOptions = {
3709
3724
  cwd
@@ -3775,115 +3790,25 @@ async function writeCache(key, data) {
3775
3790
  }
3776
3791
  await fs$2.writeJson(cacheJsonPath, data);
3777
3792
  }
3778
- async function cleanupOpenPrs(owner, repo, purl, newVersion, options) {
3779
- const {
3780
- workspaceName
3781
- } = {
3782
- __proto__: null,
3783
- ...options
3784
- };
3785
- const octokit = getOctokit();
3786
- const octokitGraphql = getOctokitGraphql();
3787
- const titlePattern = getSocketPrTitlePattern(purl, workspaceName);
3788
- const prMatches = [];
3789
- try {
3790
- // Optimistically fetch only the first 50 open PRs using GraphQL to minimize
3791
- // API quota usage. Fallback to REST if no matching PRs are found.
3792
- const gqlCacheKey = `${repo}-pr-graphql-snapshot`;
3793
- const gqlResp = await cacheFetch(gqlCacheKey, () => octokitGraphql(`
3794
- query($owner: String!, $repo: String!) {
3795
- repository(owner: $owner, name: $repo) {
3796
- pullRequests(first: 50, states: OPEN, orderBy: {field: CREATED_AT, direction: DESC}) {
3797
- nodes {
3798
- number
3799
- title
3800
- mergeStateStatus
3801
- headRefName
3802
- baseRefName
3803
- }
3804
- }
3805
- }
3806
- }
3807
- `, {
3808
- owner,
3809
- repo
3810
- }));
3811
- const nodes = gqlResp?.repository?.pullRequests?.nodes;
3812
- if (nodes) {
3813
- for (let i = 0, {
3814
- length
3815
- } = nodes; i < length; i += 1) {
3816
- const node = nodes[i];
3817
- if (titlePattern.test(node.title)) {
3818
- prMatches.push({
3819
- apiType: 'graphql',
3820
- cacheKey: gqlCacheKey,
3821
- data: gqlResp,
3822
- entry: node,
3823
- index: i,
3824
- parent: nodes,
3825
- props: node
3826
- });
3827
- }
3828
- }
3829
- }
3830
- } catch {}
3831
-
3832
- // Fallback to REST if GraphQL found no matching PRs.
3833
- let allOpenPrs;
3834
- if (!prMatches.length) {
3835
- const cacheKey = `${repo}-open-prs`;
3836
- try {
3837
- allOpenPrs = await cacheFetch(cacheKey, async () => await octokit.paginate(octokit.pulls.list, {
3838
- owner,
3839
- repo,
3840
- state: 'open',
3841
- per_page: 100
3842
- }));
3843
- } catch {}
3844
- if (allOpenPrs) {
3845
- for (let i = 0, {
3846
- length
3847
- } = allOpenPrs; i < length; i += 1) {
3848
- const pr = allOpenPrs[i];
3849
- if (titlePattern.test(pr.title)) {
3850
- prMatches.push({
3851
- apiType: 'rest',
3852
- cacheKey,
3853
- data: allOpenPrs,
3854
- entry: pr,
3855
- index: i,
3856
- parent: allOpenPrs,
3857
- props: {
3858
- baseRefName: pr.base.ref,
3859
- headRefName: pr.head.ref,
3860
- // Upper cased mergeable_state is equivalent to mergeStateStatus.
3861
- // https://docs.github.com/en/rest/pulls/pulls?apiVersion=2022-11-28#get-a-pull-request
3862
- mergeStateStatus: pr.mergeable_state?.toUpperCase?.() ?? 'UNKNOWN',
3863
- number: pr.number,
3864
- title: pr.title
3865
- }
3866
- });
3867
- }
3868
- }
3869
- }
3870
- }
3871
- if (!prMatches.length) {
3872
- return;
3793
+ async function cleanupOpenPrs(owner, repo, newVersion, options) {
3794
+ const contextualMatches = await getOpenSocketPrsWithContext(owner, repo, options);
3795
+ if (!contextualMatches.length) {
3796
+ return [];
3873
3797
  }
3874
3798
  const cachesToSave = new Map();
3875
- await Promise.allSettled(prMatches.map(async match => {
3876
- const {
3877
- props
3878
- } = match;
3879
- const versionText = /(?<= to )\S+/.exec(props.title)?.[0];
3799
+ const octokit = getOctokit();
3800
+ const settledMatches = await Promise.allSettled(contextualMatches.map(async ({
3801
+ context,
3802
+ match
3803
+ }) => {
3880
3804
  const {
3881
3805
  number: prNum
3882
- } = props;
3806
+ } = match;
3883
3807
  const prRef = `PR #${prNum}`;
3884
- const prVersion = vendor.semverExports.coerce(versionText);
3808
+ const prToVersionText = /(?<= to )\S+/.exec(match.title)?.[0];
3809
+ const prToVersion = vendor.semverExports.coerce(prToVersionText);
3885
3810
  // Close older PRs.
3886
- if (prVersion && vendor.semverExports.lt(prVersion, newVersion)) {
3811
+ if (prToVersion && vendor.semverExports.lt(prToVersion, newVersion)) {
3887
3812
  try {
3888
3813
  await octokit.pulls.update({
3889
3814
  owner,
@@ -3891,40 +3816,41 @@ async function cleanupOpenPrs(owner, repo, purl, newVersion, options) {
3891
3816
  pull_number: prNum,
3892
3817
  state: 'closed'
3893
3818
  });
3894
- debug.debugLog(`Closed ${prRef} for older version ${prVersion}.`);
3819
+ debug.debugLog(`Closed ${prRef} for older version ${prToVersion}.`);
3895
3820
  // Remove entry from parent object.
3896
- match.parent.splice(match.index, 1);
3821
+ context.parent.splice(context.index, 1);
3897
3822
  // Mark cache to be saved.
3898
- cachesToSave.set(match.cacheKey, match.data);
3823
+ cachesToSave.set(context.cacheKey, context.data);
3824
+ return null;
3899
3825
  } catch (e) {
3900
3826
  debug.debugLog(`Failed to close ${prRef}: ${e?.message || 'Unknown error'}`);
3901
- return;
3902
3827
  }
3903
3828
  }
3904
3829
  // Update stale PRs.
3905
3830
  // https://docs.github.com/en/graphql/reference/enums#mergestatestatus
3906
- if (props.mergeStateStatus === 'BEHIND') {
3831
+ if (match.mergeStateStatus === 'BEHIND') {
3907
3832
  try {
3908
3833
  await octokit.repos.merge({
3909
3834
  owner,
3910
3835
  repo,
3911
- base: props.headRefName,
3912
- head: props.baseRefName
3836
+ base: match.headRefName,
3837
+ head: match.baseRefName
3913
3838
  });
3914
3839
  debug.debugLog(`Updated stale ${prRef}.`);
3915
3840
  // Update entry entry.
3916
- if (match.apiType === 'graphql') {
3917
- match.entry.mergeStateStatus = 'CLEAN';
3918
- } else if (match.apiType === 'rest') {
3919
- match.entry.mergeable_state = 'clean';
3841
+ if (context.apiType === 'graphql') {
3842
+ context.entry.mergeStateStatus = 'CLEAN';
3843
+ } else if (context.apiType === 'rest') {
3844
+ context.entry.mergeable_state = 'clean';
3920
3845
  }
3921
3846
  // Mark cache to be saved.
3922
- cachesToSave.set(match.cacheKey, match.data);
3847
+ cachesToSave.set(context.cacheKey, context.data);
3923
3848
  } catch (e) {
3924
3849
  const message = e?.message || 'Unknown error';
3925
3850
  debug.debugLog(`Failed to update ${prRef}: ${message}`);
3926
3851
  }
3927
3852
  }
3853
+ return match;
3928
3854
  }));
3929
3855
  if (cachesToSave.size) {
3930
3856
  await Promise.allSettled([...cachesToSave].map(({
@@ -3932,6 +3858,8 @@ async function cleanupOpenPrs(owner, repo, purl, newVersion, options) {
3932
3858
  1: data
3933
3859
  }) => writeCache(key, data)));
3934
3860
  }
3861
+ const fulfilledMatches = settledMatches.filter(r => r.status === 'fulfilled' && r.value);
3862
+ return fulfilledMatches.map(r => r.value.match);
3935
3863
  }
3936
3864
  async function enablePrAutoMerge({
3937
3865
  node_id: prId
@@ -3986,10 +3914,122 @@ function getGitHubEnvRepoInfo() {
3986
3914
  repo: ownerSlashRepo.slice(slashIndex + 1)
3987
3915
  };
3988
3916
  }
3917
+ async function getOpenSocketPrsWithContext(owner, repo, options_) {
3918
+ const options = {
3919
+ __proto__: null,
3920
+ ...options_
3921
+ };
3922
+ const {
3923
+ author
3924
+ } = options;
3925
+ const checkAuthor = strings.isNonEmptyString(author);
3926
+ const octokit = getOctokit();
3927
+ const octokitGraphql = getOctokitGraphql();
3928
+ const titlePattern = getSocketPrTitlePattern(options);
3929
+ const contextualMatches = [];
3930
+ try {
3931
+ // Optimistically fetch only the first 50 open PRs using GraphQL to minimize
3932
+ // API quota usage. Fallback to REST if no matching PRs are found.
3933
+ const gqlCacheKey = `${repo}-pr-graphql-snapshot`;
3934
+ const gqlResp = await cacheFetch(gqlCacheKey, () => octokitGraphql(`
3935
+ query($owner: String!, $repo: String!) {
3936
+ repository(owner: $owner, name: $repo) {
3937
+ pullRequests(first: 50, states: OPEN, orderBy: {field: CREATED_AT, direction: DESC}) {
3938
+ nodes {
3939
+ author {
3940
+ login
3941
+ }
3942
+ baseRefName
3943
+ headRefName
3944
+ mergeStateStatus
3945
+ number
3946
+ title
3947
+ }
3948
+ }
3949
+ }
3950
+ }
3951
+ `, {
3952
+ owner,
3953
+ repo
3954
+ }));
3955
+ const nodes = gqlResp?.repository?.pullRequests?.nodes ?? [];
3956
+ for (let i = 0, {
3957
+ length
3958
+ } = nodes; i < length; i += 1) {
3959
+ const node = nodes[i];
3960
+ const login = node.author?.login;
3961
+ const matchesAuthor = checkAuthor ? login === author : true;
3962
+ if (matchesAuthor && titlePattern.test(node.title)) {
3963
+ contextualMatches.push({
3964
+ context: {
3965
+ apiType: 'graphql',
3966
+ cacheKey: gqlCacheKey,
3967
+ data: gqlResp,
3968
+ entry: node,
3969
+ index: i,
3970
+ parent: nodes
3971
+ },
3972
+ match: {
3973
+ ...node,
3974
+ author: login ?? '<unknown>'
3975
+ }
3976
+ });
3977
+ }
3978
+ }
3979
+ } catch {}
3980
+ if (contextualMatches.length) {
3981
+ return contextualMatches;
3982
+ }
3983
+
3984
+ // Fallback to REST if GraphQL found no matching PRs.
3985
+ let allOpenPrs;
3986
+ const cacheKey = `${repo}-open-prs`;
3987
+ try {
3988
+ allOpenPrs = await cacheFetch(cacheKey, async () => await octokit.paginate(octokit.pulls.list, {
3989
+ owner,
3990
+ repo,
3991
+ state: 'open',
3992
+ per_page: 100
3993
+ }));
3994
+ } catch {}
3995
+ if (!allOpenPrs) {
3996
+ return contextualMatches;
3997
+ }
3998
+ for (let i = 0, {
3999
+ length
4000
+ } = allOpenPrs; i < length; i += 1) {
4001
+ const pr = allOpenPrs[i];
4002
+ const login = pr.user?.login;
4003
+ const matchesAuthor = checkAuthor ? login === author : true;
4004
+ if (matchesAuthor && titlePattern.test(pr.title)) {
4005
+ contextualMatches.push({
4006
+ context: {
4007
+ apiType: 'rest',
4008
+ cacheKey,
4009
+ data: allOpenPrs,
4010
+ entry: pr,
4011
+ index: i,
4012
+ parent: allOpenPrs
4013
+ },
4014
+ match: {
4015
+ author: login ?? '<unknown>',
4016
+ baseRefName: pr.base.ref,
4017
+ headRefName: pr.head.ref,
4018
+ // Upper cased mergeable_state is equivalent to mergeStateStatus.
4019
+ // https://docs.github.com/en/rest/pulls/pulls?apiVersion=2022-11-28#get-a-pull-request
4020
+ mergeStateStatus: pr.mergeable_state?.toUpperCase?.() ?? 'UNKNOWN',
4021
+ number: pr.number,
4022
+ title: pr.title
4023
+ }
4024
+ });
4025
+ }
4026
+ }
4027
+ return contextualMatches;
4028
+ }
3989
4029
  async function openPr(owner, repo, branch, purl, newVersion, options) {
3990
4030
  const {
3991
4031
  baseBranch = 'main',
3992
- workspaceName
4032
+ workspace
3993
4033
  } = {
3994
4034
  __proto__: null,
3995
4035
  ...options
@@ -4004,10 +4044,10 @@ async function openPr(owner, repo, branch, purl, newVersion, options) {
4004
4044
  return await octokit.pulls.create({
4005
4045
  owner,
4006
4046
  repo,
4007
- title: getSocketPullRequestTitle(purl, newVersion, workspaceName),
4047
+ title: getSocketPullRequestTitle(purl, newVersion, workspace),
4008
4048
  head: branch,
4009
4049
  base: baseBranch,
4010
- body: getSocketPullRequestBody(purl, newVersion, workspaceName)
4050
+ body: getSocketPullRequestBody(purl, newVersion, workspace)
4011
4051
  });
4012
4052
  } catch (e) {
4013
4053
  let message = `Failed to open pull request`;
@@ -4134,7 +4174,7 @@ async function npmFix(pkgEnvDetails, {
4134
4174
  const {
4135
4175
  pkgPath: rootPath
4136
4176
  } = pkgEnvDetails;
4137
- const arb = new shadowInject.SafeArborist({
4177
+ const arb = new shadowInject.Arborist({
4138
4178
  path: rootPath,
4139
4179
  ...shadowInject.SAFE_ARBORIST_REIFY_OPTIONS_OVERRIDES
4140
4180
  });
@@ -4211,10 +4251,10 @@ async function npmFix(pkgEnvDetails, {
4211
4251
  const pkgJsonPath = pkgJsonPaths[j];
4212
4252
  const pkgPath = path.dirname(pkgJsonPath);
4213
4253
  const isWorkspaceRoot = pkgJsonPath === pkgEnvDetails.editablePkgJson.filename;
4214
- const workspaceName = isWorkspaceRoot ? 'root' : path.relative(rootPath, pkgPath);
4254
+ const workspace = isWorkspaceRoot ? 'root' : path.relative(rootPath, pkgPath);
4215
4255
  const oldVersions = arrays.arrayUnique(shadowInject.findPackageNodes(actualTree, name).map(n => n.target?.version ?? n.version).filter(Boolean));
4216
4256
  if (!oldVersions.length) {
4217
- logger.logger.warn(`Unexpected condition: ${name} not found in node_modules.\n`);
4257
+ debug.debugLog(`${name} not found, skipping.\n`);
4218
4258
  // Skip to next package.
4219
4259
  logger.logger.dedent();
4220
4260
  spinner?.dedent();
@@ -4230,7 +4270,7 @@ async function npmFix(pkgEnvDetails, {
4230
4270
  let hasAnnouncedWorkspace = false;
4231
4271
  let workspaceLogCallCount = logger.logger.logCallCount;
4232
4272
  if (debug.isDebug()) {
4233
- debug.debugLog(`Checking workspace: ${workspaceName}`);
4273
+ debug.debugLog(`Checking workspace: ${workspace}`);
4234
4274
  hasAnnouncedWorkspace = true;
4235
4275
  workspaceLogCallCount = logger.logger.logCallCount;
4236
4276
  }
@@ -4239,15 +4279,17 @@ async function npmFix(pkgEnvDetails, {
4239
4279
  const oldPurl = utils.idToPurl(oldId);
4240
4280
  const node = shadowInject.findPackageNode(actualTree, name, oldVersion);
4241
4281
  if (!node) {
4242
- if (hasAnnouncedWorkspace) {
4243
- logger.logger.warn(`Unexpected condition: Arborist node not found, skipping ${oldId}.`);
4244
- }
4282
+ debug.debugLog(`${oldId} not found, skipping.`);
4245
4283
  continue oldVersionsLoop;
4246
4284
  }
4247
4285
  infosLoop: for (const {
4248
4286
  firstPatchedVersionIdentifier,
4249
4287
  vulnerableVersionRange
4250
4288
  } of infos.values()) {
4289
+ if (vendor.semverExports.gte(oldVersion, firstPatchedVersionIdentifier)) {
4290
+ debug.debugLog(`${oldId} is >= ${firstPatchedVersionIdentifier}, skipping.`);
4291
+ continue infosLoop;
4292
+ }
4251
4293
  const newVersion = shadowInject.findBestPatchVersion(node, availableVersions, vulnerableVersionRange);
4252
4294
  const newVersionPackument = newVersion ? packument.versions[newVersion] : undefined;
4253
4295
  if (!(newVersion && newVersionPackument)) {
@@ -4281,7 +4323,7 @@ async function npmFix(pkgEnvDetails, {
4281
4323
  if (!(await editablePkgJson.save({
4282
4324
  ignoreWhitespace: true
4283
4325
  }))) {
4284
- debug.debugLog(`${workspaceName}/package.json not changed, skipping.`);
4326
+ debug.debugLog(`${workspace}/package.json not changed, skipping.`);
4285
4327
  // Reset things just in case.
4286
4328
  if (isCi) {
4287
4329
  // eslint-disable-next-line no-await-in-loop
@@ -4294,7 +4336,7 @@ async function npmFix(pkgEnvDetails, {
4294
4336
  workspaceLogCallCount = logger.logger.logCallCount;
4295
4337
  }
4296
4338
  spinner?.start();
4297
- spinner?.info(`Installing ${newId} in ${workspaceName}.`);
4339
+ spinner?.info(`Installing ${newId} in ${workspace}.`);
4298
4340
  let error;
4299
4341
  let errored = false;
4300
4342
  try {
@@ -4305,14 +4347,14 @@ async function npmFix(pkgEnvDetails, {
4305
4347
  if (maybeActualTree) {
4306
4348
  actualTree = maybeActualTree;
4307
4349
  if (test) {
4308
- spinner?.info(`Testing ${newId} in ${workspaceName}.`);
4350
+ spinner?.info(`Testing ${newId} in ${workspace}.`);
4309
4351
  // eslint-disable-next-line no-await-in-loop
4310
4352
  await npm.runScript(testScript, [], {
4311
4353
  spinner,
4312
4354
  stdio: 'ignore'
4313
4355
  });
4314
4356
  }
4315
- spinner?.success(`Fixed ${name} in ${workspaceName}.`);
4357
+ spinner?.success(`Fixed ${name} in ${workspace}.`);
4316
4358
  } else {
4317
4359
  errored = true;
4318
4360
  }
@@ -4334,7 +4376,7 @@ async function npmFix(pkgEnvDetails, {
4334
4376
  continue infosLoop;
4335
4377
  }
4336
4378
  const repoInfo = getGitHubEnvRepoInfo();
4337
- const branch = getSocketBranchName(oldPurl, newVersion, workspaceName);
4379
+ const branch = getSocketBranchName(oldPurl, newVersion, workspace);
4338
4380
  let skipPr = false;
4339
4381
  if (
4340
4382
  // eslint-disable-next-line no-await-in-loop
@@ -4348,7 +4390,9 @@ async function npmFix(pkgEnvDetails, {
4348
4390
  debug.debugLog(`Remote branch "${branch}" exists, skipping PR creation.`);
4349
4391
  } else if (
4350
4392
  // eslint-disable-next-line no-await-in-loop
4351
- !(await gitCreateAndPushBranch(branch, getSocketCommitMessage(oldPurl, newVersion, workspaceName), moddedFilepaths, cwd))) {
4393
+ !(await gitCreateAndPushBranch(branch, getSocketCommitMessage(oldPurl, newVersion, workspace), moddedFilepaths, {
4394
+ cwd
4395
+ }))) {
4352
4396
  skipPr = true;
4353
4397
  logger.logger.warn('Unexpected condition: Push failed, skipping PR creation.');
4354
4398
  }
@@ -4369,14 +4413,15 @@ async function npmFix(pkgEnvDetails, {
4369
4413
  }
4370
4414
 
4371
4415
  // eslint-disable-next-line no-await-in-loop
4372
- await Promise.allSettled([setGitRemoteGitHubRepoUrl(repoInfo.owner, repoInfo.repo, token, cwd), cleanupOpenPrs(repoInfo.owner, repoInfo.repo, oldPurl, newVersion, {
4373
- workspaceName
4416
+ await Promise.allSettled([setGitRemoteGitHubRepoUrl(repoInfo.owner, repoInfo.repo, token, cwd), cleanupOpenPrs(repoInfo.owner, repoInfo.repo, newVersion, {
4417
+ purl: oldPurl,
4418
+ workspace
4374
4419
  })]);
4375
4420
  // eslint-disable-next-line no-await-in-loop
4376
4421
  const prResponse = await openPr(repoInfo.owner, repoInfo.repo, branch, oldPurl, newVersion, {
4377
4422
  baseBranch,
4378
4423
  cwd,
4379
- workspaceName
4424
+ workspace
4380
4425
  });
4381
4426
  if (prResponse) {
4382
4427
  const {
@@ -4442,7 +4487,7 @@ async function npmFix(pkgEnvDetails, {
4442
4487
  }
4443
4488
  actualTree = maybeActualTree;
4444
4489
  }
4445
- logger.logger.fail(`Update failed for ${oldId} in ${workspaceName}.`, error);
4490
+ logger.logger.fail(`Update failed for ${oldId} in ${workspace}.`, error);
4446
4491
  }
4447
4492
  if (++count >= limit) {
4448
4493
  logger.logger.dedent();
@@ -4478,7 +4523,7 @@ async function getActualTree(cwd = process.cwd()) {
4478
4523
  // folders. However, support is iffy resulting in unhappy path errors and hangs.
4479
4524
  // So, to avoid the unhappy path, we restrict our usage to --dry-run loading
4480
4525
  // of the node_modules folder.
4481
- const arb = new shadowInject.SafeArborist({
4526
+ const arb = new shadowInject.Arborist({
4482
4527
  path: cwd,
4483
4528
  ...shadowInject.SAFE_ARBORIST_REIFY_OPTIONS_OVERRIDES
4484
4529
  });
@@ -4550,7 +4595,7 @@ async function pnpmFix(pkgEnvDetails, {
4550
4595
  let lockfile = utils.parsePnpmLockfile(lockfileContent);
4551
4596
  // Update pnpm-lock.yaml if its version is older than what the installed pnpm
4552
4597
  // produces.
4553
- if (lockfileContent && pkgEnvDetails.agentVersion.major >= 10 && utils.parsePnpmLockfileVersion(lockfile?.lockfileVersion)?.major <= 6) {
4598
+ if (lockfileContent && pkgEnvDetails.agentVersion.major >= 10 && (utils.parsePnpmLockfileVersion(lockfile?.lockfileVersion)?.major ?? 0) <= 6) {
4554
4599
  const maybeActualTree = await install(pkgEnvDetails, {
4555
4600
  args: ['--lockfile-only'],
4556
4601
  cwd,
@@ -4643,11 +4688,11 @@ async function pnpmFix(pkgEnvDetails, {
4643
4688
  const pkgJsonPath = pkgJsonPaths[j];
4644
4689
  const pkgPath = path.dirname(pkgJsonPath);
4645
4690
  const isWorkspaceRoot = pkgJsonPath === pkgEnvDetails.editablePkgJson.filename;
4646
- const workspaceName = isWorkspaceRoot ? 'root' : path.relative(rootPath, pkgPath);
4691
+ const workspace = isWorkspaceRoot ? 'root' : path.relative(rootPath, pkgPath);
4647
4692
 
4648
4693
  // actualTree may not be defined on the first iteration of pkgJsonPathsLoop.
4649
4694
  if (!actualTree) {
4650
- const maybeActualTree = fs$1.existsSync(path.join(rootPath, 'node_modules')) ?
4695
+ const maybeActualTree = isCi && fs$1.existsSync(path.join(rootPath, 'node_modules')) ?
4651
4696
  // eslint-disable-next-line no-await-in-loop
4652
4697
  await getActualTree(cwd) :
4653
4698
  // eslint-disable-next-line no-await-in-loop
@@ -4670,7 +4715,7 @@ async function pnpmFix(pkgEnvDetails, {
4670
4715
  }
4671
4716
  const oldVersions = arrays.arrayUnique(shadowInject.findPackageNodes(actualTree, name).map(n => n.version).filter(Boolean));
4672
4717
  if (!oldVersions.length) {
4673
- logger.logger.warn(`Unexpected condition: ${name} not found in node_modules.\n`);
4718
+ debug.debugLog(`${name} not found, skipping.\n`);
4674
4719
  // Skip to next package.
4675
4720
  logger.logger.dedent();
4676
4721
  spinner?.dedent();
@@ -4689,7 +4734,7 @@ async function pnpmFix(pkgEnvDetails, {
4689
4734
  let hasAnnouncedWorkspace = false;
4690
4735
  let workspaceLogCallCount = logger.logger.logCallCount;
4691
4736
  if (debug.isDebug()) {
4692
- debug.debugLog(`Checking workspace: ${workspaceName}`);
4737
+ debug.debugLog(`Checking workspace: ${workspace}`);
4693
4738
  hasAnnouncedWorkspace = true;
4694
4739
  workspaceLogCallCount = logger.logger.logCallCount;
4695
4740
  }
@@ -4698,15 +4743,17 @@ async function pnpmFix(pkgEnvDetails, {
4698
4743
  const oldPurl = utils.idToPurl(oldId);
4699
4744
  const node = shadowInject.findPackageNode(actualTree, name, oldVersion);
4700
4745
  if (!node) {
4701
- if (hasAnnouncedWorkspace) {
4702
- logger.logger.warn(`Unexpected condition: Arborist node not found, skipping ${oldId}.`);
4703
- }
4746
+ debug.debugLog(`${oldId} not found, skipping.`);
4704
4747
  continue oldVersionsLoop;
4705
4748
  }
4706
4749
  infosLoop: for (const {
4707
4750
  firstPatchedVersionIdentifier,
4708
4751
  vulnerableVersionRange
4709
4752
  } of infos.values()) {
4753
+ if (vendor.semverExports.gte(oldVersion, firstPatchedVersionIdentifier)) {
4754
+ debug.debugLog(`${oldId} is >= ${firstPatchedVersionIdentifier}, skipping.`);
4755
+ continue infosLoop;
4756
+ }
4710
4757
  const newVersion = shadowInject.findBestPatchVersion(node, availableVersions, vulnerableVersionRange);
4711
4758
  const newVersionPackument = newVersion ? packument.versions[newVersion] : undefined;
4712
4759
  if (!(newVersion && newVersionPackument)) {
@@ -4762,7 +4809,7 @@ async function pnpmFix(pkgEnvDetails, {
4762
4809
  if (!(await editablePkgJson.save({
4763
4810
  ignoreWhitespace: true
4764
4811
  }))) {
4765
- debug.debugLog(`${workspaceName}/package.json not changed, skipping.`);
4812
+ debug.debugLog(`${workspace}/package.json unchanged, skipping.`);
4766
4813
  // Reset things just in case.
4767
4814
  if (isCi) {
4768
4815
  // eslint-disable-next-line no-await-in-loop
@@ -4775,7 +4822,7 @@ async function pnpmFix(pkgEnvDetails, {
4775
4822
  workspaceLogCallCount = logger.logger.logCallCount;
4776
4823
  }
4777
4824
  spinner?.start();
4778
- spinner?.info(`Installing ${newId} in ${workspaceName}.`);
4825
+ spinner?.info(`Installing ${newId} in ${workspace}.`);
4779
4826
  let error;
4780
4827
  let errored = false;
4781
4828
  try {
@@ -4805,14 +4852,14 @@ async function pnpmFix(pkgEnvDetails, {
4805
4852
  await fs$1.promises.writeFile(lockfilePath, lockfileContent, 'utf8');
4806
4853
  }
4807
4854
  if (test) {
4808
- spinner?.info(`Testing ${newId} in ${workspaceName}.`);
4855
+ spinner?.info(`Testing ${newId} in ${workspace}.`);
4809
4856
  // eslint-disable-next-line no-await-in-loop
4810
4857
  await npm.runScript(testScript, [], {
4811
4858
  spinner,
4812
4859
  stdio: 'ignore'
4813
4860
  });
4814
4861
  }
4815
- spinner?.success(`Fixed ${name} in ${workspaceName}.`);
4862
+ spinner?.success(`Fixed ${name} in ${workspace}.`);
4816
4863
  } else {
4817
4864
  errored = true;
4818
4865
  }
@@ -4834,7 +4881,7 @@ async function pnpmFix(pkgEnvDetails, {
4834
4881
  continue infosLoop;
4835
4882
  }
4836
4883
  const repoInfo = getGitHubEnvRepoInfo();
4837
- const branch = getSocketBranchName(oldPurl, newVersion, workspaceName);
4884
+ const branch = getSocketBranchName(oldPurl, newVersion, workspace);
4838
4885
  let skipPr = false;
4839
4886
  if (
4840
4887
  // eslint-disable-next-line no-await-in-loop
@@ -4848,7 +4895,9 @@ async function pnpmFix(pkgEnvDetails, {
4848
4895
  debug.debugLog(`Remote branch "${branch}" exists, skipping PR creation.`);
4849
4896
  } else if (
4850
4897
  // eslint-disable-next-line no-await-in-loop
4851
- !(await gitCreateAndPushBranch(branch, getSocketCommitMessage(oldPurl, newVersion, workspaceName), moddedFilepaths, cwd))) {
4898
+ !(await gitCreateAndPushBranch(branch, getSocketCommitMessage(oldPurl, newVersion, workspace), moddedFilepaths, {
4899
+ cwd
4900
+ }))) {
4852
4901
  skipPr = true;
4853
4902
  logger.logger.warn('Unexpected condition: Push failed, skipping PR creation.');
4854
4903
  }
@@ -4874,14 +4923,15 @@ async function pnpmFix(pkgEnvDetails, {
4874
4923
  }
4875
4924
 
4876
4925
  // eslint-disable-next-line no-await-in-loop
4877
- await Promise.allSettled([setGitRemoteGitHubRepoUrl(repoInfo.owner, repoInfo.repo, token, cwd), cleanupOpenPrs(repoInfo.owner, repoInfo.repo, oldPurl, newVersion, {
4878
- workspaceName
4926
+ await Promise.allSettled([setGitRemoteGitHubRepoUrl(repoInfo.owner, repoInfo.repo, token, cwd), cleanupOpenPrs(repoInfo.owner, repoInfo.repo, newVersion, {
4927
+ purl: oldPurl,
4928
+ workspace
4879
4929
  })]);
4880
4930
  // eslint-disable-next-line no-await-in-loop
4881
4931
  const prResponse = await openPr(repoInfo.owner, repoInfo.repo, branch, oldPurl, newVersion, {
4882
4932
  baseBranch,
4883
4933
  cwd,
4884
- workspaceName
4934
+ workspace
4885
4935
  });
4886
4936
  if (prResponse) {
4887
4937
  const {
@@ -4958,7 +5008,7 @@ async function pnpmFix(pkgEnvDetails, {
4958
5008
  return;
4959
5009
  }
4960
5010
  }
4961
- logger.logger.fail(`Update failed for ${oldId} in ${workspaceName}.`, ...(error ? [error] : []));
5011
+ logger.logger.fail(`Update failed for ${oldId} in ${workspace}.`, ...(error ? [error] : []));
4962
5012
  }
4963
5013
  if (++count >= limit) {
4964
5014
  logger.logger.dedent();
@@ -7020,7 +7070,7 @@ async function addOverrides(pkgEnvDetails, pkgPath, options) {
7020
7070
  package: origPkgName,
7021
7071
  version
7022
7072
  } = data;
7023
- const major = vendor.semverExports.major(version);
7073
+ const major = utils.getMajor(version);
7024
7074
  const sockOverridePrefix = `${NPM$1}:${sockRegPkgName}@`;
7025
7075
  const sockOverrideSpec = `${sockOverridePrefix}${pin ? version : `^${major}`}`;
7026
7076
  for (const {
@@ -7041,7 +7091,7 @@ async function addOverrides(pkgEnvDetails, pkgPath, options) {
7041
7091
  !(thisSpec.startsWith(sockOverridePrefix) &&
7042
7092
  // Check the validity of the spec by passing it through npa and
7043
7093
  // seeing if it will coerce to a version.
7044
- vendor.semverExports.coerce(vendor.npaExports(thisSpec).rawSpec)?.version)) {
7094
+ vendor.semverExports.coerce(utils.npa(thisSpec).subSpec.rawSpec)?.version)) {
7045
7095
  thisSpec = sockOverrideSpec;
7046
7096
  depObj[origPkgName] = thisSpec;
7047
7097
  state.added.add(sockRegPkgName);
@@ -7085,16 +7135,16 @@ async function addOverrides(pkgEnvDetails, pkgPath, options) {
7085
7135
  } else if (typeof oldSpec === 'string') {
7086
7136
  const thisSpec = oldSpec.startsWith('$') ? depAlias || newSpec : oldSpec || newSpec;
7087
7137
  if (thisSpec.startsWith(sockOverridePrefix)) {
7088
- if (pin && vendor.semverExports.major(
7138
+ if (pin && utils.getMajor(
7089
7139
  // Check the validity of the spec by passing it through npa
7090
7140
  // and seeing if it will coerce to a version. semver.coerce
7091
7141
  // will strip leading v's, carets (^), comparators (<,<=,>,>=,=),
7092
7142
  // and tildes (~). If not coerced to a valid version then
7093
7143
  // default to the manifest entry version.
7094
- vendor.semverExports.coerce(vendor.npaExports(thisSpec).rawSpec)?.version ?? version) !== major) {
7144
+ vendor.semverExports.coerce(utils.npa(thisSpec).subSpec.rawSpec)?.version ?? version) !== major) {
7095
7145
  const otherVersion = (await packages.fetchPackageManifest(thisSpec))?.version;
7096
7146
  if (otherVersion && otherVersion !== version) {
7097
- newSpec = `${sockOverridePrefix}${pin ? otherVersion : `^${vendor.semverExports.major(otherVersion)}`}`;
7147
+ newSpec = `${sockOverridePrefix}${pin ? otherVersion : `^${utils.getMajor(otherVersion)}`}`;
7098
7148
  }
7099
7149
  }
7100
7150
  } else {
@@ -12652,5 +12702,5 @@ void (async () => {
12652
12702
  await utils.captureException(e);
12653
12703
  }
12654
12704
  })();
12655
- //# debugId=726ab9a5-2bd9-4713-bdc1-f8860b83f478
12705
+ //# debugId=fc951913-c543-4f4f-aef4-8c8e6d016539
12656
12706
  //# sourceMappingURL=cli.js.map