@socketsecurity/cli-with-sentry 0.15.24 → 0.15.25

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,9 +4279,7 @@ 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 {
@@ -4281,7 +4319,7 @@ async function npmFix(pkgEnvDetails, {
4281
4319
  if (!(await editablePkgJson.save({
4282
4320
  ignoreWhitespace: true
4283
4321
  }))) {
4284
- debug.debugLog(`${workspaceName}/package.json not changed, skipping.`);
4322
+ debug.debugLog(`${workspace}/package.json not changed, skipping.`);
4285
4323
  // Reset things just in case.
4286
4324
  if (isCi) {
4287
4325
  // eslint-disable-next-line no-await-in-loop
@@ -4294,7 +4332,7 @@ async function npmFix(pkgEnvDetails, {
4294
4332
  workspaceLogCallCount = logger.logger.logCallCount;
4295
4333
  }
4296
4334
  spinner?.start();
4297
- spinner?.info(`Installing ${newId} in ${workspaceName}.`);
4335
+ spinner?.info(`Installing ${newId} in ${workspace}.`);
4298
4336
  let error;
4299
4337
  let errored = false;
4300
4338
  try {
@@ -4305,14 +4343,14 @@ async function npmFix(pkgEnvDetails, {
4305
4343
  if (maybeActualTree) {
4306
4344
  actualTree = maybeActualTree;
4307
4345
  if (test) {
4308
- spinner?.info(`Testing ${newId} in ${workspaceName}.`);
4346
+ spinner?.info(`Testing ${newId} in ${workspace}.`);
4309
4347
  // eslint-disable-next-line no-await-in-loop
4310
4348
  await npm.runScript(testScript, [], {
4311
4349
  spinner,
4312
4350
  stdio: 'ignore'
4313
4351
  });
4314
4352
  }
4315
- spinner?.success(`Fixed ${name} in ${workspaceName}.`);
4353
+ spinner?.success(`Fixed ${name} in ${workspace}.`);
4316
4354
  } else {
4317
4355
  errored = true;
4318
4356
  }
@@ -4334,7 +4372,7 @@ async function npmFix(pkgEnvDetails, {
4334
4372
  continue infosLoop;
4335
4373
  }
4336
4374
  const repoInfo = getGitHubEnvRepoInfo();
4337
- const branch = getSocketBranchName(oldPurl, newVersion, workspaceName);
4375
+ const branch = getSocketBranchName(oldPurl, newVersion, workspace);
4338
4376
  let skipPr = false;
4339
4377
  if (
4340
4378
  // eslint-disable-next-line no-await-in-loop
@@ -4348,7 +4386,9 @@ async function npmFix(pkgEnvDetails, {
4348
4386
  debug.debugLog(`Remote branch "${branch}" exists, skipping PR creation.`);
4349
4387
  } else if (
4350
4388
  // eslint-disable-next-line no-await-in-loop
4351
- !(await gitCreateAndPushBranch(branch, getSocketCommitMessage(oldPurl, newVersion, workspaceName), moddedFilepaths, cwd))) {
4389
+ !(await gitCreateAndPushBranch(branch, getSocketCommitMessage(oldPurl, newVersion, workspace), moddedFilepaths, {
4390
+ cwd
4391
+ }))) {
4352
4392
  skipPr = true;
4353
4393
  logger.logger.warn('Unexpected condition: Push failed, skipping PR creation.');
4354
4394
  }
@@ -4369,14 +4409,15 @@ async function npmFix(pkgEnvDetails, {
4369
4409
  }
4370
4410
 
4371
4411
  // 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
4412
+ await Promise.allSettled([setGitRemoteGitHubRepoUrl(repoInfo.owner, repoInfo.repo, token, cwd), cleanupOpenPrs(repoInfo.owner, repoInfo.repo, newVersion, {
4413
+ purl: oldPurl,
4414
+ workspace
4374
4415
  })]);
4375
4416
  // eslint-disable-next-line no-await-in-loop
4376
4417
  const prResponse = await openPr(repoInfo.owner, repoInfo.repo, branch, oldPurl, newVersion, {
4377
4418
  baseBranch,
4378
4419
  cwd,
4379
- workspaceName
4420
+ workspace
4380
4421
  });
4381
4422
  if (prResponse) {
4382
4423
  const {
@@ -4442,7 +4483,7 @@ async function npmFix(pkgEnvDetails, {
4442
4483
  }
4443
4484
  actualTree = maybeActualTree;
4444
4485
  }
4445
- logger.logger.fail(`Update failed for ${oldId} in ${workspaceName}.`, error);
4486
+ logger.logger.fail(`Update failed for ${oldId} in ${workspace}.`, error);
4446
4487
  }
4447
4488
  if (++count >= limit) {
4448
4489
  logger.logger.dedent();
@@ -4478,7 +4519,7 @@ async function getActualTree(cwd = process.cwd()) {
4478
4519
  // folders. However, support is iffy resulting in unhappy path errors and hangs.
4479
4520
  // So, to avoid the unhappy path, we restrict our usage to --dry-run loading
4480
4521
  // of the node_modules folder.
4481
- const arb = new shadowInject.SafeArborist({
4522
+ const arb = new shadowInject.Arborist({
4482
4523
  path: cwd,
4483
4524
  ...shadowInject.SAFE_ARBORIST_REIFY_OPTIONS_OVERRIDES
4484
4525
  });
@@ -4550,7 +4591,7 @@ async function pnpmFix(pkgEnvDetails, {
4550
4591
  let lockfile = utils.parsePnpmLockfile(lockfileContent);
4551
4592
  // Update pnpm-lock.yaml if its version is older than what the installed pnpm
4552
4593
  // produces.
4553
- if (lockfileContent && pkgEnvDetails.agentVersion.major >= 10 && utils.parsePnpmLockfileVersion(lockfile?.lockfileVersion)?.major <= 6) {
4594
+ if (lockfileContent && pkgEnvDetails.agentVersion.major >= 10 && (utils.parsePnpmLockfileVersion(lockfile?.lockfileVersion)?.major ?? 0) <= 6) {
4554
4595
  const maybeActualTree = await install(pkgEnvDetails, {
4555
4596
  args: ['--lockfile-only'],
4556
4597
  cwd,
@@ -4643,7 +4684,7 @@ async function pnpmFix(pkgEnvDetails, {
4643
4684
  const pkgJsonPath = pkgJsonPaths[j];
4644
4685
  const pkgPath = path.dirname(pkgJsonPath);
4645
4686
  const isWorkspaceRoot = pkgJsonPath === pkgEnvDetails.editablePkgJson.filename;
4646
- const workspaceName = isWorkspaceRoot ? 'root' : path.relative(rootPath, pkgPath);
4687
+ const workspace = isWorkspaceRoot ? 'root' : path.relative(rootPath, pkgPath);
4647
4688
 
4648
4689
  // actualTree may not be defined on the first iteration of pkgJsonPathsLoop.
4649
4690
  if (!actualTree) {
@@ -4670,7 +4711,7 @@ async function pnpmFix(pkgEnvDetails, {
4670
4711
  }
4671
4712
  const oldVersions = arrays.arrayUnique(shadowInject.findPackageNodes(actualTree, name).map(n => n.version).filter(Boolean));
4672
4713
  if (!oldVersions.length) {
4673
- logger.logger.warn(`Unexpected condition: ${name} not found in node_modules.\n`);
4714
+ debug.debugLog(`${name} not found, skipping.\n`);
4674
4715
  // Skip to next package.
4675
4716
  logger.logger.dedent();
4676
4717
  spinner?.dedent();
@@ -4689,7 +4730,7 @@ async function pnpmFix(pkgEnvDetails, {
4689
4730
  let hasAnnouncedWorkspace = false;
4690
4731
  let workspaceLogCallCount = logger.logger.logCallCount;
4691
4732
  if (debug.isDebug()) {
4692
- debug.debugLog(`Checking workspace: ${workspaceName}`);
4733
+ debug.debugLog(`Checking workspace: ${workspace}`);
4693
4734
  hasAnnouncedWorkspace = true;
4694
4735
  workspaceLogCallCount = logger.logger.logCallCount;
4695
4736
  }
@@ -4698,9 +4739,7 @@ async function pnpmFix(pkgEnvDetails, {
4698
4739
  const oldPurl = utils.idToPurl(oldId);
4699
4740
  const node = shadowInject.findPackageNode(actualTree, name, oldVersion);
4700
4741
  if (!node) {
4701
- if (hasAnnouncedWorkspace) {
4702
- logger.logger.warn(`Unexpected condition: Arborist node not found, skipping ${oldId}.`);
4703
- }
4742
+ debug.debugLog(`${oldId} not found, skipping.`);
4704
4743
  continue oldVersionsLoop;
4705
4744
  }
4706
4745
  infosLoop: for (const {
@@ -4762,7 +4801,7 @@ async function pnpmFix(pkgEnvDetails, {
4762
4801
  if (!(await editablePkgJson.save({
4763
4802
  ignoreWhitespace: true
4764
4803
  }))) {
4765
- debug.debugLog(`${workspaceName}/package.json not changed, skipping.`);
4804
+ debug.debugLog(`${workspace}/package.json unchanged, skipping.`);
4766
4805
  // Reset things just in case.
4767
4806
  if (isCi) {
4768
4807
  // eslint-disable-next-line no-await-in-loop
@@ -4775,7 +4814,7 @@ async function pnpmFix(pkgEnvDetails, {
4775
4814
  workspaceLogCallCount = logger.logger.logCallCount;
4776
4815
  }
4777
4816
  spinner?.start();
4778
- spinner?.info(`Installing ${newId} in ${workspaceName}.`);
4817
+ spinner?.info(`Installing ${newId} in ${workspace}.`);
4779
4818
  let error;
4780
4819
  let errored = false;
4781
4820
  try {
@@ -4805,14 +4844,14 @@ async function pnpmFix(pkgEnvDetails, {
4805
4844
  await fs$1.promises.writeFile(lockfilePath, lockfileContent, 'utf8');
4806
4845
  }
4807
4846
  if (test) {
4808
- spinner?.info(`Testing ${newId} in ${workspaceName}.`);
4847
+ spinner?.info(`Testing ${newId} in ${workspace}.`);
4809
4848
  // eslint-disable-next-line no-await-in-loop
4810
4849
  await npm.runScript(testScript, [], {
4811
4850
  spinner,
4812
4851
  stdio: 'ignore'
4813
4852
  });
4814
4853
  }
4815
- spinner?.success(`Fixed ${name} in ${workspaceName}.`);
4854
+ spinner?.success(`Fixed ${name} in ${workspace}.`);
4816
4855
  } else {
4817
4856
  errored = true;
4818
4857
  }
@@ -4834,7 +4873,7 @@ async function pnpmFix(pkgEnvDetails, {
4834
4873
  continue infosLoop;
4835
4874
  }
4836
4875
  const repoInfo = getGitHubEnvRepoInfo();
4837
- const branch = getSocketBranchName(oldPurl, newVersion, workspaceName);
4876
+ const branch = getSocketBranchName(oldPurl, newVersion, workspace);
4838
4877
  let skipPr = false;
4839
4878
  if (
4840
4879
  // eslint-disable-next-line no-await-in-loop
@@ -4848,7 +4887,9 @@ async function pnpmFix(pkgEnvDetails, {
4848
4887
  debug.debugLog(`Remote branch "${branch}" exists, skipping PR creation.`);
4849
4888
  } else if (
4850
4889
  // eslint-disable-next-line no-await-in-loop
4851
- !(await gitCreateAndPushBranch(branch, getSocketCommitMessage(oldPurl, newVersion, workspaceName), moddedFilepaths, cwd))) {
4890
+ !(await gitCreateAndPushBranch(branch, getSocketCommitMessage(oldPurl, newVersion, workspace), moddedFilepaths, {
4891
+ cwd
4892
+ }))) {
4852
4893
  skipPr = true;
4853
4894
  logger.logger.warn('Unexpected condition: Push failed, skipping PR creation.');
4854
4895
  }
@@ -4874,14 +4915,15 @@ async function pnpmFix(pkgEnvDetails, {
4874
4915
  }
4875
4916
 
4876
4917
  // 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
4918
+ await Promise.allSettled([setGitRemoteGitHubRepoUrl(repoInfo.owner, repoInfo.repo, token, cwd), cleanupOpenPrs(repoInfo.owner, repoInfo.repo, newVersion, {
4919
+ purl: oldPurl,
4920
+ workspace
4879
4921
  })]);
4880
4922
  // eslint-disable-next-line no-await-in-loop
4881
4923
  const prResponse = await openPr(repoInfo.owner, repoInfo.repo, branch, oldPurl, newVersion, {
4882
4924
  baseBranch,
4883
4925
  cwd,
4884
- workspaceName
4926
+ workspace
4885
4927
  });
4886
4928
  if (prResponse) {
4887
4929
  const {
@@ -4958,7 +5000,7 @@ async function pnpmFix(pkgEnvDetails, {
4958
5000
  return;
4959
5001
  }
4960
5002
  }
4961
- logger.logger.fail(`Update failed for ${oldId} in ${workspaceName}.`, ...(error ? [error] : []));
5003
+ logger.logger.fail(`Update failed for ${oldId} in ${workspace}.`, ...(error ? [error] : []));
4962
5004
  }
4963
5005
  if (++count >= limit) {
4964
5006
  logger.logger.dedent();
@@ -7020,7 +7062,7 @@ async function addOverrides(pkgEnvDetails, pkgPath, options) {
7020
7062
  package: origPkgName,
7021
7063
  version
7022
7064
  } = data;
7023
- const major = vendor.semverExports.major(version);
7065
+ const major = utils.getMajor(version);
7024
7066
  const sockOverridePrefix = `${NPM$1}:${sockRegPkgName}@`;
7025
7067
  const sockOverrideSpec = `${sockOverridePrefix}${pin ? version : `^${major}`}`;
7026
7068
  for (const {
@@ -7041,7 +7083,7 @@ async function addOverrides(pkgEnvDetails, pkgPath, options) {
7041
7083
  !(thisSpec.startsWith(sockOverridePrefix) &&
7042
7084
  // Check the validity of the spec by passing it through npa and
7043
7085
  // seeing if it will coerce to a version.
7044
- vendor.semverExports.coerce(vendor.npaExports(thisSpec).rawSpec)?.version)) {
7086
+ vendor.semverExports.coerce(utils.npa(thisSpec).subSpec.rawSpec)?.version)) {
7045
7087
  thisSpec = sockOverrideSpec;
7046
7088
  depObj[origPkgName] = thisSpec;
7047
7089
  state.added.add(sockRegPkgName);
@@ -7085,16 +7127,16 @@ async function addOverrides(pkgEnvDetails, pkgPath, options) {
7085
7127
  } else if (typeof oldSpec === 'string') {
7086
7128
  const thisSpec = oldSpec.startsWith('$') ? depAlias || newSpec : oldSpec || newSpec;
7087
7129
  if (thisSpec.startsWith(sockOverridePrefix)) {
7088
- if (pin && vendor.semverExports.major(
7130
+ if (pin && utils.getMajor(
7089
7131
  // Check the validity of the spec by passing it through npa
7090
7132
  // and seeing if it will coerce to a version. semver.coerce
7091
7133
  // will strip leading v's, carets (^), comparators (<,<=,>,>=,=),
7092
7134
  // and tildes (~). If not coerced to a valid version then
7093
7135
  // default to the manifest entry version.
7094
- vendor.semverExports.coerce(vendor.npaExports(thisSpec).rawSpec)?.version ?? version) !== major) {
7136
+ vendor.semverExports.coerce(utils.npa(thisSpec).subSpec.rawSpec)?.version ?? version) !== major) {
7095
7137
  const otherVersion = (await packages.fetchPackageManifest(thisSpec))?.version;
7096
7138
  if (otherVersion && otherVersion !== version) {
7097
- newSpec = `${sockOverridePrefix}${pin ? otherVersion : `^${vendor.semverExports.major(otherVersion)}`}`;
7139
+ newSpec = `${sockOverridePrefix}${pin ? otherVersion : `^${utils.getMajor(otherVersion)}`}`;
7098
7140
  }
7099
7141
  }
7100
7142
  } else {
@@ -12652,5 +12694,5 @@ void (async () => {
12652
12694
  await utils.captureException(e);
12653
12695
  }
12654
12696
  })();
12655
- //# debugId=726ab9a5-2bd9-4713-bdc1-f8860b83f478
12697
+ //# debugId=ce95f80f-4315-4dd0-a8c9-3097f68b9b18
12656
12698
  //# sourceMappingURL=cli.js.map