@socketsecurity/cli-with-sentry 0.15.14 → 0.15.15

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
@@ -3713,11 +3713,11 @@ async function npmFix(pkgEnvDetails, {
3713
3713
  infoEntriesLoop: for (let i = 0, {
3714
3714
  length
3715
3715
  } = sortedInfoEntries; i < length; i += 1) {
3716
+ const isLastInfoEntry = i === length - 1;
3716
3717
  const {
3717
3718
  0: name,
3718
3719
  1: infos
3719
3720
  } = sortedInfoEntries[i];
3720
- const isLastInfoEntry = i === length - 1;
3721
3721
  logger.logger.log(`Processing vulnerable package: ${name}`);
3722
3722
  logger.logger.indent();
3723
3723
  spinner?.indent();
@@ -3736,17 +3736,14 @@ async function npmFix(pkgEnvDetails, {
3736
3736
  const warningsForAfter = new Set();
3737
3737
 
3738
3738
  // eslint-disable-next-line no-unused-labels
3739
- for (const pkgJsonPath of pkgJsonPaths) {
3739
+ for (let j = 0, {
3740
+ length: length_j
3741
+ } = pkgJsonPaths; j < length_j; j += 1) {
3742
+ const isLastPkgJsonPath = j === length_j - 1;
3743
+ const pkgJsonPath = pkgJsonPaths[j];
3740
3744
  const pkgPath = path.dirname(pkgJsonPath);
3741
3745
  const isWorkspaceRoot = pkgJsonPath === pkgEnvDetails.editablePkgJson.filename;
3742
3746
  const workspaceName = isWorkspaceRoot ? 'root' : path.relative(rootPath, pkgPath);
3743
- logger.logger.log(`Checking workspace: ${workspaceName}`);
3744
- const workspaceLogCallCount = logger.logger.logCallCount;
3745
-
3746
- // eslint-disable-next-line no-await-in-loop
3747
- actualTree = await install$1(arb, {
3748
- cwd
3749
- });
3750
3747
  const oldVersions = arrays.arrayUnique(shadowInject.findPackageNodes(actualTree, name).map(n => n.target?.version ?? n.version).filter(Boolean));
3751
3748
  if (!oldVersions.length) {
3752
3749
  logger.logger.warn(`Unexpected condition: Lockfile entries not found for ${name}.\n`);
@@ -3762,12 +3759,21 @@ async function npmFix(pkgEnvDetails, {
3762
3759
  const editablePkgJson = await packages.readPackageJson(pkgJsonPath, {
3763
3760
  editable: true
3764
3761
  });
3762
+ let hasAnnouncedWorkspace = false;
3763
+ let workspaceLogCallCount = logger.logger.logCallCount;
3764
+ if (debug.isDebug()) {
3765
+ debug.debugLog(`Checking workspace: ${workspaceName}`);
3766
+ hasAnnouncedWorkspace = true;
3767
+ workspaceLogCallCount = logger.logger.logCallCount;
3768
+ }
3765
3769
  oldVersionsLoop: for (const oldVersion of oldVersions) {
3766
3770
  const oldId = `${name}@${oldVersion}`;
3767
3771
  const oldPurl = utils.idToPurl(oldId);
3768
3772
  const node = shadowInject.findPackageNode(actualTree, name, oldVersion);
3769
3773
  if (!node) {
3770
- logger.logger.warn(`Unexpected condition: Arborist node not found, skipping ${oldId}`);
3774
+ if (hasAnnouncedWorkspace) {
3775
+ logger.logger.warn(`Unexpected condition: Arborist node not found, skipping ${oldId}`);
3776
+ }
3771
3777
  continue oldVersionsLoop;
3772
3778
  }
3773
3779
  infosLoop: for (const {
@@ -3807,18 +3813,18 @@ async function npmFix(pkgEnvDetails, {
3807
3813
  if (!(await editablePkgJson.save({
3808
3814
  ignoreWhitespace: true
3809
3815
  }))) {
3810
- logger.logger.info(`${workspaceName}/package.json not changed, skipping`);
3816
+ debug.debugLog(`${workspaceName}/package.json not changed, skipping`);
3811
3817
  // Reset things just in case.
3812
3818
  if (isCi) {
3813
3819
  // eslint-disable-next-line no-await-in-loop
3814
3820
  await gitResetAndClean(baseBranch, cwd);
3815
- // eslint-disable-next-line no-await-in-loop
3816
- actualTree = await install$1(arb, {
3817
- cwd
3818
- });
3819
3821
  }
3820
3822
  continue infosLoop;
3821
3823
  }
3824
+ if (!hasAnnouncedWorkspace) {
3825
+ hasAnnouncedWorkspace = true;
3826
+ workspaceLogCallCount = logger.logger.logCallCount;
3827
+ }
3822
3828
  spinner?.start();
3823
3829
  spinner?.info(`Installing ${newId} in ${workspaceName}`);
3824
3830
  let error;
@@ -3844,6 +3850,16 @@ async function npmFix(pkgEnvDetails, {
3844
3850
  if (!errored && isCi) {
3845
3851
  const branch = getSocketBranchName(oldPurl, newVersion, workspaceName);
3846
3852
  try {
3853
+ const moddedFilepaths =
3854
+ // eslint-disable-next-line no-await-in-loop
3855
+ (await gitUnstagedModifiedFiles(cwd)).filter(p => {
3856
+ const basename = path.basename(p);
3857
+ return basename === 'package.json' || basename === 'package-lock.json';
3858
+ });
3859
+ if (!moddedFilepaths.length) {
3860
+ logger.logger.warn('Unexpected condition: Nothing to commit, skipping PR creation.');
3861
+ continue infosLoop;
3862
+ }
3847
3863
  const {
3848
3864
  owner,
3849
3865
  repo
@@ -3851,27 +3867,35 @@ async function npmFix(pkgEnvDetails, {
3851
3867
  // eslint-disable-next-line no-await-in-loop
3852
3868
  if (await prExistForBranch(owner, repo, branch)) {
3853
3869
  debug.debugLog(`Branch "${branch}" exists, skipping PR creation.`);
3870
+ // eslint-disable-next-line no-await-in-loop
3871
+ await gitResetAndClean(baseBranch, cwd);
3872
+ // eslint-disable-next-line no-await-in-loop
3873
+ actualTree = await install$1(arb, {
3874
+ cwd
3875
+ });
3854
3876
  continue infosLoop;
3855
3877
  }
3856
3878
  // eslint-disable-next-line no-await-in-loop
3857
3879
  if (await gitRemoteBranchExists(branch, cwd)) {
3858
3880
  debug.debugLog(`Remote branch "${branch}" exists, skipping PR creation.`);
3859
- continue infosLoop;
3860
- }
3861
- const moddedFilepaths =
3862
- // eslint-disable-next-line no-await-in-loop
3863
- (await gitUnstagedModifiedFiles(cwd)).filter(p => {
3864
- const basename = path.basename(p);
3865
- return basename === 'package.json' || basename === 'package-lock.json';
3866
- });
3867
- if (!moddedFilepaths.length) {
3868
- logger.logger.warn('Unexpected condition: Nothing to commit, skipping PR creation.');
3881
+ // eslint-disable-next-line no-await-in-loop
3882
+ await gitResetAndClean(baseBranch, cwd);
3883
+ // eslint-disable-next-line no-await-in-loop
3884
+ actualTree = await install$1(arb, {
3885
+ cwd
3886
+ });
3869
3887
  continue infosLoop;
3870
3888
  }
3871
3889
  if (
3872
3890
  // eslint-disable-next-line no-await-in-loop
3873
3891
  !(await gitCreateAndPushBranch(branch, getSocketCommitMessage(oldPurl, newVersion, workspaceName), moddedFilepaths, cwd))) {
3874
3892
  logger.logger.warn('Unexpected condition: Push failed, skipping PR creation.');
3893
+ // eslint-disable-next-line no-await-in-loop
3894
+ await gitResetAndClean(baseBranch, cwd);
3895
+ // eslint-disable-next-line no-await-in-loop
3896
+ actualTree = await install$1(arb, {
3897
+ cwd
3898
+ });
3875
3899
  continue infosLoop;
3876
3900
  }
3877
3901
  // eslint-disable-next-line no-await-in-loop
@@ -3928,7 +3952,7 @@ async function npmFix(pkgEnvDetails, {
3928
3952
  }
3929
3953
  }
3930
3954
  }
3931
- if (logger.logger.logCallCount > workspaceLogCallCount) {
3955
+ if (!isLastPkgJsonPath && logger.logger.logCallCount > workspaceLogCallCount) {
3932
3956
  logger.logger.log('');
3933
3957
  }
3934
3958
  }
@@ -4026,6 +4050,7 @@ async function pnpmFix(pkgEnvDetails, {
4026
4050
  });
4027
4051
  lockfile = await utils.readPnpmLockfile(lockfilePath);
4028
4052
  }
4053
+
4029
4054
  // Exit early if pnpm-lock.yaml is not found.
4030
4055
  if (!lockfile) {
4031
4056
  spinner?.stop();
@@ -4059,11 +4084,11 @@ async function pnpmFix(pkgEnvDetails, {
4059
4084
  infoEntriesLoop: for (let i = 0, {
4060
4085
  length
4061
4086
  } = sortedInfoEntries; i < length; i += 1) {
4087
+ const isLastInfoEntry = i === length - 1;
4062
4088
  const {
4063
4089
  0: name,
4064
4090
  1: infos
4065
4091
  } = sortedInfoEntries[i];
4066
- const isLastInfoEntry = i === length - 1;
4067
4092
  logger.logger.log(`Processing vulnerable package: ${name}`);
4068
4093
  logger.logger.indent();
4069
4094
  spinner?.indent();
@@ -4082,18 +4107,26 @@ async function pnpmFix(pkgEnvDetails, {
4082
4107
  const warningsForAfter = new Set();
4083
4108
 
4084
4109
  // eslint-disable-next-line no-unused-labels
4085
- for (const pkgJsonPath of pkgJsonPaths) {
4110
+ for (let j = 0, {
4111
+ length: length_j
4112
+ } = pkgJsonPaths; j < length_j; j += 1) {
4113
+ const isLastPkgJsonPath = j === length_j - 1;
4114
+ const pkgJsonPath = pkgJsonPaths[j];
4086
4115
  const pkgPath = path.dirname(pkgJsonPath);
4087
4116
  const isWorkspaceRoot = pkgJsonPath === pkgEnvDetails.editablePkgJson.filename;
4088
4117
  const workspaceName = isWorkspaceRoot ? 'root' : path.relative(rootPath, pkgPath);
4089
- logger.logger.log(`Checking workspace: ${workspaceName}`);
4090
- const workspaceLogCallCount = logger.logger.logCallCount;
4091
4118
 
4092
- // eslint-disable-next-line no-await-in-loop
4093
- actualTree = await install(pkgEnvDetails, {
4094
- cwd,
4095
- spinner
4096
- });
4119
+ // actualTree may not be defined on the first iteration of pkgJsonPathsLoop.
4120
+ if (!actualTree) {
4121
+ actualTree = fs$1.existsSync(path.join(rootPath, 'node_modules')) ?
4122
+ // eslint-disable-next-line no-await-in-loop
4123
+ await getActualTree(cwd) :
4124
+ // eslint-disable-next-line no-await-in-loop
4125
+ await install(pkgEnvDetails, {
4126
+ cwd,
4127
+ spinner
4128
+ });
4129
+ }
4097
4130
  const oldVersions = arrays.arrayUnique(shadowInject.findPackageNodes(actualTree, name).map(n => n.version).filter(Boolean));
4098
4131
  if (!oldVersions.length) {
4099
4132
  logger.logger.warn(`Unexpected condition: Lockfile entries not found for ${name}.\n`);
@@ -4109,15 +4142,24 @@ async function pnpmFix(pkgEnvDetails, {
4109
4142
  const editablePkgJson = await packages.readPackageJson(pkgJsonPath, {
4110
4143
  editable: true
4111
4144
  });
4112
- // Get current overrides for revert logic
4145
+ // Get current overrides for revert logic.
4113
4146
  const oldPnpmSection = editablePkgJson.content[PNPM$7];
4114
4147
  const oldOverrides = oldPnpmSection?.[OVERRIDES$2];
4148
+ let hasAnnouncedWorkspace = false;
4149
+ let workspaceLogCallCount = logger.logger.logCallCount;
4150
+ if (debug.isDebug()) {
4151
+ debug.debugLog(`Checking workspace: ${workspaceName}`);
4152
+ hasAnnouncedWorkspace = true;
4153
+ workspaceLogCallCount = logger.logger.logCallCount;
4154
+ }
4115
4155
  oldVersionsLoop: for (const oldVersion of oldVersions) {
4116
4156
  const oldId = `${name}@${oldVersion}`;
4117
4157
  const oldPurl = utils.idToPurl(oldId);
4118
4158
  const node = shadowInject.findPackageNode(actualTree, name, oldVersion);
4119
4159
  if (!node) {
4120
- logger.logger.warn(`Unexpected condition: Arborist node not found, skipping ${oldId}`);
4160
+ if (hasAnnouncedWorkspace) {
4161
+ logger.logger.warn(`Unexpected condition: Arborist node not found, skipping ${oldId}`);
4162
+ }
4121
4163
  continue oldVersionsLoop;
4122
4164
  }
4123
4165
  infosLoop: for (const {
@@ -4176,19 +4218,18 @@ async function pnpmFix(pkgEnvDetails, {
4176
4218
  if (!(await editablePkgJson.save({
4177
4219
  ignoreWhitespace: true
4178
4220
  }))) {
4179
- logger.logger.info(`${workspaceName}/package.json not changed, skipping`);
4221
+ debug.debugLog(`${workspaceName}/package.json not changed, skipping`);
4180
4222
  // Reset things just in case.
4181
4223
  if (isCi) {
4182
4224
  // eslint-disable-next-line no-await-in-loop
4183
4225
  await gitResetAndClean(baseBranch, cwd);
4184
- // eslint-disable-next-line no-await-in-loop
4185
- actualTree = await install(pkgEnvDetails, {
4186
- cwd,
4187
- spinner
4188
- });
4189
4226
  }
4190
4227
  continue infosLoop;
4191
4228
  }
4229
+ if (!hasAnnouncedWorkspace) {
4230
+ hasAnnouncedWorkspace = true;
4231
+ workspaceLogCallCount = logger.logger.logCallCount;
4232
+ }
4192
4233
  spinner?.start();
4193
4234
  spinner?.info(`Installing ${newId} in ${workspaceName}`);
4194
4235
  let error;
@@ -4216,6 +4257,16 @@ async function pnpmFix(pkgEnvDetails, {
4216
4257
  if (!errored && isCi) {
4217
4258
  const branch = getSocketBranchName(oldPurl, newVersion, workspaceName);
4218
4259
  try {
4260
+ const moddedFilepaths =
4261
+ // eslint-disable-next-line no-await-in-loop
4262
+ (await gitUnstagedModifiedFiles(cwd)).filter(p => {
4263
+ const basename = path.basename(p);
4264
+ return basename === 'package.json' || basename === 'pnpm-lock.yaml';
4265
+ });
4266
+ if (!moddedFilepaths.length) {
4267
+ logger.logger.warn('Unexpected condition: Nothing to commit, skipping PR creation.');
4268
+ continue infosLoop;
4269
+ }
4219
4270
  const {
4220
4271
  owner,
4221
4272
  repo
@@ -4223,27 +4274,38 @@ async function pnpmFix(pkgEnvDetails, {
4223
4274
  // eslint-disable-next-line no-await-in-loop
4224
4275
  if (await prExistForBranch(owner, repo, branch)) {
4225
4276
  debug.debugLog(`Branch "${branch}" exists, skipping PR creation.`);
4277
+ // eslint-disable-next-line no-await-in-loop
4278
+ await gitResetAndClean(baseBranch, cwd);
4279
+ // eslint-disable-next-line no-await-in-loop
4280
+ actualTree = await install(pkgEnvDetails, {
4281
+ cwd,
4282
+ spinner
4283
+ });
4226
4284
  continue infosLoop;
4227
4285
  }
4228
4286
  // eslint-disable-next-line no-await-in-loop
4229
4287
  if (await gitRemoteBranchExists(branch, cwd)) {
4230
4288
  debug.debugLog(`Remote branch "${branch}" exists, skipping PR creation.`);
4231
- continue infosLoop;
4232
- }
4233
- const moddedFilepaths =
4234
- // eslint-disable-next-line no-await-in-loop
4235
- (await gitUnstagedModifiedFiles(cwd)).filter(p => {
4236
- const basename = path.basename(p);
4237
- return basename === 'package.json' || basename === 'pnpm-lock.yaml';
4238
- });
4239
- if (!moddedFilepaths.length) {
4240
- logger.logger.warn('Unexpected condition: Nothing to commit, skipping PR creation.');
4289
+ // eslint-disable-next-line no-await-in-loop
4290
+ await gitResetAndClean(baseBranch, cwd);
4291
+ // eslint-disable-next-line no-await-in-loop
4292
+ actualTree = await install(pkgEnvDetails, {
4293
+ cwd,
4294
+ spinner
4295
+ });
4241
4296
  continue infosLoop;
4242
4297
  }
4243
4298
  if (
4244
4299
  // eslint-disable-next-line no-await-in-loop
4245
4300
  !(await gitCreateAndPushBranch(branch, getSocketCommitMessage(oldPurl, newVersion, workspaceName), moddedFilepaths, cwd))) {
4246
4301
  logger.logger.warn('Unexpected condition: Push failed, skipping PR creation.');
4302
+ // eslint-disable-next-line no-await-in-loop
4303
+ await gitResetAndClean(baseBranch, cwd);
4304
+ // eslint-disable-next-line no-await-in-loop
4305
+ actualTree = await install(pkgEnvDetails, {
4306
+ cwd,
4307
+ spinner
4308
+ });
4247
4309
  continue infosLoop;
4248
4310
  }
4249
4311
  // eslint-disable-next-line no-await-in-loop
@@ -4302,7 +4364,7 @@ async function pnpmFix(pkgEnvDetails, {
4302
4364
  }
4303
4365
  }
4304
4366
  }
4305
- if (logger.logger.logCallCount > workspaceLogCallCount) {
4367
+ if (!isLastPkgJsonPath && logger.logger.logCallCount > workspaceLogCallCount) {
4306
4368
  logger.logger.log('');
4307
4369
  }
4308
4370
  }
@@ -11535,5 +11597,5 @@ void (async () => {
11535
11597
  await utils.captureException(e);
11536
11598
  }
11537
11599
  })();
11538
- //# debugId=f795e75b-2414-4f4b-8612-273af979480d
11600
+ //# debugId=8c291e79-2d0e-444d-af3a-8be88558aeff
11539
11601
  //# sourceMappingURL=cli.js.map