socket 1.0.34 → 1.0.36

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
@@ -3091,7 +3091,7 @@ function getSocketPullRequestTitle(purl, newVersion, workspace) {
3091
3091
  async function gitCleanFdx(cwd = process.cwd()) {
3092
3092
  const stdioIgnoreOptions = {
3093
3093
  cwd,
3094
- stdio: 'ignore'
3094
+ stdio: debug.isDebug('stdio') ? 'inherit' : 'ignore'
3095
3095
  };
3096
3096
  // TODO: propagate CResult?
3097
3097
  await spawn.spawn('git', ['clean', '-fdx'], stdioIgnoreOptions);
@@ -3109,16 +3109,8 @@ async function gitCreateAndPushBranch(branch, commitMsg, filepaths, options) {
3109
3109
  };
3110
3110
  const stdioIgnoreOptions = {
3111
3111
  cwd,
3112
- stdio: 'inherit'
3112
+ stdio: debug.isDebug('stdio') ? 'inherit' : 'ignore'
3113
3113
  };
3114
- logger.logger.dir({
3115
- branch,
3116
- user,
3117
- email,
3118
- cwd,
3119
- filepaths,
3120
- commitMsg
3121
- });
3122
3114
  try {
3123
3115
  await gitEnsureIdentity(user, email, cwd);
3124
3116
  await spawn.spawn('git', ['checkout', '-b', branch], stdioIgnoreOptions);
@@ -3127,14 +3119,10 @@ async function gitCreateAndPushBranch(branch, commitMsg, filepaths, options) {
3127
3119
  await spawn.spawn('git', ['push', '--force', '--set-upstream', 'origin', branch], stdioIgnoreOptions);
3128
3120
  return true;
3129
3121
  } catch (e) {
3130
- logger.logger.dir({
3122
+ debug.debugFn('error', `caught: git push --force --set-upstream origin ${branch} failed`);
3123
+ debug.debugDir('inspect', {
3131
3124
  error: e
3132
3125
  });
3133
- // debugFn(
3134
- // 'error',
3135
- // `caught: git push --force --set-upstream origin ${branch} failed`,
3136
- // )
3137
- // debugDir('inspect', { error: e })
3138
3126
  }
3139
3127
  try {
3140
3128
  // Will throw with exit code 1 if branch does not exist.
@@ -3183,7 +3171,7 @@ async function gitRepoInfo(cwd = process.cwd()) {
3183
3171
  async function gitEnsureIdentity(name, email, cwd = process.cwd()) {
3184
3172
  const stdioIgnoreOptions = {
3185
3173
  cwd,
3186
- stdio: 'ignore'
3174
+ stdio: debug.isDebug('stdio') ? 'inherit' : 'ignore'
3187
3175
  };
3188
3176
  const stdioPipeOptions = {
3189
3177
  cwd
@@ -3228,7 +3216,7 @@ async function gitResetAndClean(branch = 'HEAD', cwd = process.cwd()) {
3228
3216
  async function gitResetHard(branch = 'HEAD', cwd = process.cwd()) {
3229
3217
  const stdioIgnoreOptions = {
3230
3218
  cwd,
3231
- stdio: 'ignore'
3219
+ stdio: debug.isDebug('stdio') ? 'inherit' : 'ignore'
3232
3220
  };
3233
3221
  await spawn.spawn('git', ['reset', '--hard', branch], stdioIgnoreOptions);
3234
3222
  }
@@ -3238,13 +3226,10 @@ async function gitUnstagedModifiedFiles(cwd = process.cwd()) {
3238
3226
  cwd
3239
3227
  };
3240
3228
  const changedFilesDetails = (await spawn.spawn('git', ['diff', '--name-only'], stdioPipeOptions)).stdout;
3241
- const rawRelPaths = changedFilesDetails.split('\n') ?? [];
3242
- console.log({
3243
- rawRelPaths
3244
- });
3229
+ const relPaths = changedFilesDetails.split('\n') ?? [];
3245
3230
  return {
3246
3231
  ok: true,
3247
- data: rawRelPaths.map(p => path$1.normalizePath(p))
3232
+ data: relPaths.map(p => path$1.normalizePath(p))
3248
3233
  };
3249
3234
  } catch (e) {
3250
3235
  debug.debugFn('error', 'caught: git diff --name-only failed');
@@ -3644,7 +3629,7 @@ async function openPr(owner, repo, branch, purl, newVersion, options) {
3644
3629
  async function setGitRemoteGithubRepoUrl(owner, repo, token, cwd = process.cwd()) {
3645
3630
  const stdioIgnoreOptions = {
3646
3631
  cwd,
3647
- stdio: 'ignore'
3632
+ stdio: debug.isDebug('stdio') ? 'inherit' : 'ignore'
3648
3633
  };
3649
3634
  const {
3650
3635
  host
@@ -3936,10 +3921,7 @@ async function agentFix(pkgEnvDetails, actualTree, alertsMap, installer, {
3936
3921
  cwd,
3937
3922
  spinner
3938
3923
  });
3939
- const maybeLockSrc = maybeActualTree ?
3940
- // eslint-disable-next-line no-await-in-loop
3941
- await utils.readLockfile(pkgEnvDetails.lockPath) : null;
3942
- if (maybeActualTree && maybeLockSrc) {
3924
+ if (maybeActualTree && fs$1.existsSync(pkgEnvDetails.lockPath)) {
3943
3925
  actualTree = maybeActualTree;
3944
3926
  }
3945
3927
  }
@@ -4035,13 +4017,13 @@ async function agentFix(pkgEnvDetails, actualTree, alertsMap, installer, {
4035
4017
  shadowNpmInject.updatePackageJsonFromNode(editablePkgJson, actualTree, node, newVersion, rangeStyle);
4036
4018
 
4037
4019
  // eslint-disable-next-line no-await-in-loop
4038
- const res = await editablePkgJson.save({
4020
+ await editablePkgJson.save({
4039
4021
  ignoreWhitespace: true
4040
4022
  });
4041
4023
 
4042
4024
  // eslint-disable-next-line no-await-in-loop
4043
4025
  const unstagedCResult = await gitUnstagedModifiedFiles(cwd);
4044
- const moddedFilepaths = res && unstagedCResult.ok ? unstagedCResult.data.filter(filepath => {
4026
+ const moddedFilepaths = unstagedCResult.ok ? unstagedCResult.data.filter(filepath => {
4045
4027
  const basename = path.basename(filepath);
4046
4028
  return basename === 'package.json' || basename === pkgEnvDetails.lockName;
4047
4029
  }) : [];
@@ -4054,6 +4036,11 @@ async function agentFix(pkgEnvDetails, actualTree, alertsMap, installer, {
4054
4036
  }
4055
4037
  continue infosLoop;
4056
4038
  }
4039
+
4040
+ // eslint-disable-next-line no-await-in-loop
4041
+ const pkgJsonSrc = await fs$1.promises.readFile(editablePkgJson.filename, 'utf8');
4042
+ // eslint-disable-next-line no-await-in-loop
4043
+ const lockSrc = await utils.readLockfile(pkgEnvDetails.lockPath);
4057
4044
  if (!hasAnnouncedWorkspace) {
4058
4045
  hasAnnouncedWorkspace = true;
4059
4046
  workspaceLogCallCount = logger.logger.logCallCount;
@@ -4069,19 +4056,10 @@ async function agentFix(pkgEnvDetails, actualTree, alertsMap, installer, {
4069
4056
  cwd,
4070
4057
  spinner
4071
4058
  });
4072
- // eslint-disable-next-line no-await-in-loop
4073
- const unstagedCResult = await gitUnstagedModifiedFiles(cwd);
4074
- console.log('after installer', unstagedCResult);
4075
- const maybeLockSrc = maybeActualTree ?
4076
- // eslint-disable-next-line no-await-in-loop
4077
- await utils.readLockfile(pkgEnvDetails.lockPath) : null;
4078
- if (maybeActualTree && maybeLockSrc) {
4059
+ if (maybeActualTree && fs$1.existsSync(pkgEnvDetails.lockPath)) {
4079
4060
  actualTree = maybeActualTree;
4080
4061
  // eslint-disable-next-line no-await-in-loop
4081
4062
  await afterInstall(editablePkgJson, packument, oldVersion, newVersion, vulnerableVersionRange, fixConfig);
4082
- // eslint-disable-next-line no-await-in-loop
4083
- const unstagedCResult = await gitUnstagedModifiedFiles(cwd);
4084
- console.log('after afterInstall', unstagedCResult);
4085
4063
  if (test) {
4086
4064
  spinner?.info(`Testing ${newId} in ${workspace}.`);
4087
4065
  // eslint-disable-next-line no-await-in-loop
@@ -4103,12 +4081,11 @@ async function agentFix(pkgEnvDetails, actualTree, alertsMap, installer, {
4103
4081
 
4104
4082
  // Check repoInfo to make TypeScript happy.
4105
4083
  if (!errored && fixEnv.isCi && fixEnv.repoInfo) {
4084
+ // Rewrite files in case the install reverted them.
4106
4085
  // eslint-disable-next-line no-await-in-loop
4107
- const unstagedCResult = await gitUnstagedModifiedFiles(cwd);
4108
- const moddedFilepaths = unstagedCResult.ok ? unstagedCResult.data.filter(filepath => {
4109
- const basename = path.basename(filepath);
4110
- return basename === 'package.json' || basename === pkgEnvDetails.lockName;
4111
- }) : [];
4086
+ await fs$1.promises.writeFile(editablePkgJson.filename, pkgJsonSrc, 'utf8');
4087
+ // eslint-disable-next-line no-await-in-loop
4088
+ await fs$1.promises.writeFile(pkgEnvDetails.lockPath, lockSrc, 'utf8');
4112
4089
  try {
4113
4090
  if (
4114
4091
  // eslint-disable-next-line no-await-in-loop
@@ -4125,10 +4102,7 @@ async function agentFix(pkgEnvDetails, actualTree, alertsMap, installer, {
4125
4102
  cwd,
4126
4103
  spinner
4127
4104
  });
4128
- const maybeLockSrc = maybeActualTree ?
4129
- // eslint-disable-next-line no-await-in-loop
4130
- await utils.readLockfile(pkgEnvDetails.lockPath) : null;
4131
- if (maybeActualTree && maybeLockSrc) {
4105
+ if (maybeActualTree && fs$1.existsSync(pkgEnvDetails.lockPath)) {
4132
4106
  actualTree = maybeActualTree;
4133
4107
  continue infosLoop;
4134
4108
  }
@@ -4293,17 +4267,16 @@ async function npmFix(pkgEnvDetails, fixConfig) {
4293
4267
  spinner
4294
4268
  } = fixConfig;
4295
4269
  spinner?.start();
4296
- let arb;
4270
+ const flatConfig = await utils.getNpmConfig({
4271
+ npmVersion: pkgEnvDetails.agentVersion
4272
+ });
4297
4273
  let actualTree;
4298
4274
  let alertsMap;
4299
4275
  try {
4300
4276
  if (purls.length) {
4301
4277
  alertsMap = await utils.getAlertsMapFromPurls(purls, getFixAlertsMapOptions());
4302
4278
  } else {
4303
- const flatConfig = await utils.getNpmConfig({
4304
- npmVersion: pkgEnvDetails.agentVersion
4305
- });
4306
- arb = new shadowNpmInject.Arborist({
4279
+ const arb = new shadowNpmInject.Arborist({
4307
4280
  path: pkgEnvDetails.pkgPath,
4308
4281
  ...flatConfig
4309
4282
  });
@@ -4344,6 +4317,10 @@ async function npmFix(pkgEnvDetails, fixConfig) {
4344
4317
  }
4345
4318
  })
4346
4319
  };
4320
+ const arb = new shadowNpmInject.Arborist({
4321
+ path: pkgEnvDetails.pkgPath,
4322
+ ...flatConfig
4323
+ });
4347
4324
  const idealTree = await arb.buildIdealTree();
4348
4325
  const node = shadowNpmInject.findPackageNode(idealTree, packument.name, oldVersion);
4349
4326
  if (node) {
@@ -14289,5 +14266,5 @@ void (async () => {
14289
14266
  await utils.captureException(e);
14290
14267
  }
14291
14268
  })();
14292
- //# debugId=eee3dc45-f185-4d70-b82d-838c0ee9c156
14269
+ //# debugId=de722ff7-23df-4530-81e3-f05cc7c7a02e
14293
14270
  //# sourceMappingURL=cli.js.map