@socketsecurity/cli-with-sentry 1.0.41 → 1.0.43

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
@@ -3812,9 +3812,9 @@ function getOverridesData(pkgEnvDetails, pkgJson) {
3812
3812
 
3813
3813
  const noopHandler = () => {};
3814
3814
  async function agentFix(pkgEnvDetails, actualTree, alertsMap, installer, {
3815
- beforeInstall = noopHandler,
3816
- // eslint-disable-next-line sort-destructure-keys/sort-destructure-keys
3817
3815
  afterInstall = noopHandler,
3816
+ afterUpdate = noopHandler,
3817
+ beforeInstall = noopHandler,
3818
3818
  revertInstall = noopHandler
3819
3819
  }, fixConfig) {
3820
3820
  const {
@@ -3882,6 +3882,13 @@ async function agentFix(pkgEnvDetails, actualTree, alertsMap, installer, {
3882
3882
  spinner?.dedent();
3883
3883
  packumentCache.clear();
3884
3884
  };
3885
+ const getModifiedFiles = async (cwd = process.cwd()) => {
3886
+ const unstagedCResult = await gitUnstagedModifiedFiles(cwd);
3887
+ return unstagedCResult.ok ? unstagedCResult.data.filter(filepath => {
3888
+ const basename = path.basename(filepath);
3889
+ return basename === 'package.json' || basename === pkgEnvDetails.lockName;
3890
+ }) : [];
3891
+ };
3885
3892
  const handleInstallFail = () => {
3886
3893
  cleanupInfoEntriesLoop();
3887
3894
  return {
@@ -3890,6 +3897,9 @@ async function agentFix(pkgEnvDetails, actualTree, alertsMap, installer, {
3890
3897
  cause: `Unexpected condition: ${pkgEnvDetails.agent} install failed`
3891
3898
  };
3892
3899
  };
3900
+ const hasModifiedFiles = async (cwd = process.cwd()) => {
3901
+ return (await getModifiedFiles(cwd)).length > 0;
3902
+ };
3893
3903
  spinner?.stop();
3894
3904
  infoEntriesLoop: for (let i = 0, {
3895
3905
  length
@@ -4041,13 +4051,11 @@ async function agentFix(pkgEnvDetails, actualTree, alertsMap, installer, {
4041
4051
  });
4042
4052
 
4043
4053
  // eslint-disable-next-line no-await-in-loop
4044
- const unstagedCResult = await gitUnstagedModifiedFiles(cwd);
4045
- const moddedFilepaths = unstagedCResult.ok ? unstagedCResult.data.filter(filepath => {
4046
- const basename = path.basename(filepath);
4047
- return basename === 'package.json' || basename === pkgEnvDetails.lockName;
4048
- }) : [];
4049
- if (!moddedFilepaths.length) {
4050
- logger.logger.warn('Unexpected condition: Nothing to commit, skipping PR creation.');
4054
+ await afterUpdate(editablePkgJson, packument, oldVersion, newVersion, vulnerableVersionRange, fixConfig);
4055
+
4056
+ // eslint-disable-next-line no-await-in-loop
4057
+ if (!(await hasModifiedFiles(cwd))) {
4058
+ debug.debugFn('notice', 'skip: nothing to commit, skipping PR creation');
4051
4059
  // Reset things just in case.
4052
4060
  if (fixEnv.isCi) {
4053
4061
  // eslint-disable-next-line no-await-in-loop
@@ -4057,11 +4065,6 @@ async function agentFix(pkgEnvDetails, actualTree, alertsMap, installer, {
4057
4065
  }
4058
4066
  continue infosLoop;
4059
4067
  }
4060
-
4061
- // eslint-disable-next-line no-await-in-loop
4062
- const pkgJsonSrc = await fs$1.promises.readFile(editablePkgJson.filename, 'utf8');
4063
- // eslint-disable-next-line no-await-in-loop
4064
- const lockSrc = await utils.readLockfile(pkgEnvDetails.lockPath);
4065
4068
  if (!hasAnnouncedWorkspace) {
4066
4069
  hasAnnouncedWorkspace = true;
4067
4070
  workspaceLogCallCount = logger.logger.logCallCount;
@@ -4102,15 +4105,12 @@ async function agentFix(pkgEnvDetails, actualTree, alertsMap, installer, {
4102
4105
 
4103
4106
  // Check repoInfo to make TypeScript happy.
4104
4107
  if (!errored && fixEnv.isCi && fixEnv.repoInfo) {
4105
- // Rewrite files in case the install reverted them.
4106
- // eslint-disable-next-line no-await-in-loop
4107
- await fs$1.promises.writeFile(editablePkgJson.filename, pkgJsonSrc, 'utf8');
4108
- // eslint-disable-next-line no-await-in-loop
4109
- await fs$1.promises.writeFile(pkgEnvDetails.lockPath, lockSrc, 'utf8');
4110
4108
  try {
4111
4109
  if (
4112
4110
  // eslint-disable-next-line no-await-in-loop
4113
- !(await gitCreateAndPushBranch(branch, getSocketCommitMessage(oldPurl, newVersion, workspace), moddedFilepaths, {
4111
+ !(await gitCreateAndPushBranch(branch, getSocketCommitMessage(oldPurl, newVersion, workspace),
4112
+ // eslint-disable-next-line no-await-in-loop
4113
+ await getModifiedFiles(cwd), {
4114
4114
  cwd,
4115
4115
  email: fixEnv.gitEmail,
4116
4116
  user: fixEnv.gitUser
@@ -4328,7 +4328,7 @@ async function npmFix(pkgEnvDetails, fixConfig) {
4328
4328
  }
4329
4329
  let revertData;
4330
4330
  return await agentFix(pkgEnvDetails, actualTree, alertsMap, install$1, {
4331
- async beforeInstall(editablePkgJson, packument, oldVersion, newVersion) {
4331
+ async beforeInstall(editablePkgJson) {
4332
4332
  revertData = {
4333
4333
  ...(editablePkgJson.content.dependencies && {
4334
4334
  dependencies: {
@@ -4346,15 +4346,20 @@ async function npmFix(pkgEnvDetails, fixConfig) {
4346
4346
  }
4347
4347
  })
4348
4348
  };
4349
- const arb = new shadowNpmInject.Arborist({
4350
- path: pkgEnvDetails.pkgPath,
4351
- ...flatConfig
4352
- });
4353
- const idealTree = await arb.buildIdealTree();
4354
- const node = shadowNpmInject.findPackageNode(idealTree, packument.name, oldVersion);
4355
- if (node) {
4356
- shadowNpmInject.updateNode(node, newVersion, packument.versions[newVersion]);
4357
- await arb.reify();
4349
+ },
4350
+ async afterUpdate(editablePkgJson, packument, oldVersion, newVersion) {
4351
+ const isWorkspaceRoot = editablePkgJson.filename === pkgEnvDetails.editablePkgJson.filename;
4352
+ if (isWorkspaceRoot) {
4353
+ const arb = new shadowNpmInject.Arborist({
4354
+ path: pkgEnvDetails.pkgPath,
4355
+ ...flatConfig
4356
+ });
4357
+ const idealTree = await arb.buildIdealTree();
4358
+ const node = shadowNpmInject.findPackageNode(idealTree, packument.name, oldVersion);
4359
+ if (node) {
4360
+ shadowNpmInject.updateNode(node, newVersion, packument.versions[newVersion]);
4361
+ await arb.reify();
4362
+ }
4358
4363
  }
4359
4364
  },
4360
4365
  async revertInstall(editablePkgJson) {
@@ -14305,5 +14310,5 @@ void (async () => {
14305
14310
  await utils.captureException(e);
14306
14311
  }
14307
14312
  })();
14308
- //# debugId=61ea85e2-e40e-4ae7-ba74-ed9c4d21ffab
14313
+ //# debugId=54a399b0-5fc6-4a0b-ac22-11952f37b9d5
14309
14314
  //# sourceMappingURL=cli.js.map