socket 1.0.70 → 1.0.72

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/bin/npm-cli.js CHANGED
@@ -6,5 +6,5 @@ const path = require('node:path')
6
6
  const rootPath = path.join(__dirname, '..')
7
7
  Module.enableCompileCache?.(path.join(rootPath, '.cache'))
8
8
 
9
- const shadowBin = require(path.join(rootPath, 'dist/shadow-bin.js'))
9
+ const shadowBin = require(path.join(rootPath, 'dist/shadow-npm-bin.js'))
10
10
  shadowBin('npm')
package/bin/npx-cli.js CHANGED
@@ -6,5 +6,5 @@ const path = require('node:path')
6
6
  const rootPath = path.join(__dirname, '..')
7
7
  Module.enableCompileCache?.(path.join(rootPath, '.cache'))
8
8
 
9
- const shadowBin = require(path.join(rootPath, 'dist/shadow-bin.js'))
9
+ const shadowBin = require(path.join(rootPath, 'dist/shadow-npm-bin.js'))
10
10
  shadowBin('npx')
package/dist/cli.js CHANGED
@@ -3994,12 +3994,12 @@ async function agentFix(pkgEnvDetails, actualTree, alertsMap, installer, {
3994
3994
  }
3995
3995
  continue infosLoop;
3996
3996
  }
3997
+ spinner?.start();
3997
3998
  if (!hasAnnouncedWorkspace) {
3998
3999
  hasAnnouncedWorkspace = true;
3999
4000
  workspaceLogCallCount = logger.logger.logCallCount;
4000
4001
  }
4001
4002
  const newId = `${name}@${utils.applyRange(refRange, newVersion, rangeStyle)}`;
4002
- spinner?.start();
4003
4003
  spinner?.info(`Installing ${newId} in ${workspace}.`);
4004
4004
  let error;
4005
4005
  let errored = false;
@@ -4327,6 +4327,7 @@ async function npmFix(pkgEnvDetails, fixConfig) {
4327
4327
  return await agentFix(pkgEnvDetails, actualTree, alertsMap, install$1, {
4328
4328
  async beforeInstall(editablePkgJson) {
4329
4329
  revertData = {
4330
+ // Track existing dependencies in the root package.json to revert to later.
4330
4331
  ...(editablePkgJson.content.dependencies && {
4331
4332
  dependencies: {
4332
4333
  ...editablePkgJson.content.dependencies
@@ -4345,24 +4346,34 @@ async function npmFix(pkgEnvDetails, fixConfig) {
4345
4346
  };
4346
4347
  },
4347
4348
  async afterUpdate(editablePkgJson, packument, oldVersion, newVersion) {
4348
- const isWorkspaceRoot = editablePkgJson.filename === pkgEnvDetails.editablePkgJson.filename;
4349
- if (isWorkspaceRoot) {
4350
- const arb = new shadowNpmInject.Arborist({
4351
- path: pkgEnvDetails.pkgPath,
4352
- ...flatConfig,
4353
- ...shadowNpmInject.SAFE_WITH_SAVE_ARBORIST_REIFY_OPTIONS_OVERRIDES
4354
- });
4355
- const idealTree = await arb.buildIdealTree();
4356
- const node = shadowNpmInject.findPackageNode(idealTree, packument.name, oldVersion);
4357
- if (node) {
4358
- shadowNpmInject.updateNode(node, newVersion, packument.versions[newVersion]);
4359
- await arb.reify();
4360
- }
4349
+ // Exit early if not the root workspace.
4350
+ if (editablePkgJson.filename !== pkgEnvDetails.editablePkgJson.filename) {
4351
+ return;
4352
+ }
4353
+ // Update package-lock.json using @npmcli/arborist.
4354
+ const arb = new shadowNpmInject.Arborist({
4355
+ path: pkgEnvDetails.pkgPath,
4356
+ ...flatConfig,
4357
+ ...shadowNpmInject.SAFE_WITH_SAVE_ARBORIST_REIFY_OPTIONS_OVERRIDES
4358
+ });
4359
+ // Build the ideal tree of nodes that are used to generated the saved
4360
+ // package-lock.json
4361
+ const idealTree = await arb.buildIdealTree();
4362
+ const node = shadowNpmInject.findPackageNode(idealTree, packument.name, oldVersion);
4363
+ if (node) {
4364
+ // Update the ideal tree node.
4365
+ shadowNpmInject.updateNode(node, newVersion, packument.versions[newVersion]);
4366
+ // Save package-lock.json lockfile.
4367
+ await arb.reify();
4361
4368
  }
4362
4369
  },
4363
4370
  async revertInstall(editablePkgJson) {
4364
4371
  if (revertData) {
4372
+ // Revert package.json.
4365
4373
  editablePkgJson.update(revertData);
4374
+ await editablePkgJson.save({
4375
+ ignoreWhitespace: true
4376
+ });
4366
4377
  }
4367
4378
  }
4368
4379
  }, fixConfig);
@@ -4449,9 +4460,7 @@ async function pnpmFix(pkgEnvDetails, fixConfig) {
4449
4460
  } = fixConfig;
4450
4461
  spinner?.start();
4451
4462
  let actualTree;
4452
- let {
4453
- lockSrc
4454
- } = pkgEnvDetails;
4463
+ let lockSrc = pkgEnvDetails.lockSrc;
4455
4464
  let lockfile = utils.parsePnpmLockfile(lockSrc);
4456
4465
  // Update pnpm-lock.yaml if its version is older than what the installed pnpm
4457
4466
  // produces.
@@ -4461,10 +4470,13 @@ async function pnpmFix(pkgEnvDetails, fixConfig) {
4461
4470
  cwd,
4462
4471
  spinner
4463
4472
  });
4464
- const maybeLockSrc = maybeActualTree ? await utils.readLockfile(pkgEnvDetails.lockPath) : null;
4465
- if (maybeActualTree && maybeLockSrc) {
4473
+ if (maybeActualTree) {
4474
+ lockSrc = (await utils.readLockfile(pkgEnvDetails.lockPath)) ?? '';
4475
+ } else {
4476
+ lockSrc = '';
4477
+ }
4478
+ if (lockSrc) {
4466
4479
  actualTree = maybeActualTree;
4467
- lockSrc = maybeLockSrc;
4468
4480
  lockfile = utils.parsePnpmLockfile(lockSrc);
4469
4481
  } else {
4470
4482
  lockfile = null;
@@ -4498,27 +4510,32 @@ async function pnpmFix(pkgEnvDetails, fixConfig) {
4498
4510
  }
4499
4511
  let revertData;
4500
4512
  let revertOverrides;
4501
- let revertOverridesSrc;
4513
+ let revertOverridesSrc = '';
4502
4514
  return await agentFix(pkgEnvDetails, actualTree, alertsMap, install, {
4503
4515
  async beforeInstall(editablePkgJson, packument, oldVersion, newVersion, vulnerableVersionRange, options) {
4504
- const isWorkspaceRoot = editablePkgJson.filename === pkgEnvDetails.editablePkgJson.filename;
4505
- // Get current overrides for revert logic.
4506
- const {
4507
- overrides: oldOverrides
4508
- } = getOverridesDataPnpm(pkgEnvDetails, editablePkgJson.content);
4509
- const oldPnpmSection = editablePkgJson.content[PNPM$6];
4510
- const overrideKey = `${packument.name}@${vulnerableVersionRange}`;
4511
- revertOverrides = undefined;
4512
- revertOverridesSrc = utils.extractOverridesFromPnpmLockSrc(lockSrc);
4513
- if (isWorkspaceRoot) {
4516
+ lockSrc = (await utils.readLockfile(pkgEnvDetails.lockPath)) ?? '';
4517
+
4518
+ // Update overrides for the root workspace.
4519
+ if (editablePkgJson.filename === pkgEnvDetails.editablePkgJson.filename) {
4520
+ const {
4521
+ overrides: oldOverrides
4522
+ } = getOverridesDataPnpm(pkgEnvDetails, editablePkgJson.content);
4523
+ const oldPnpmSection = editablePkgJson.content[PNPM$6];
4524
+ const overrideKey = `${packument.name}@${vulnerableVersionRange}`;
4525
+ revertOverridesSrc = utils.extractOverridesFromPnpmLockSrc(lockSrc);
4526
+ // Track existing overrides in the root package.json to revert to later.
4514
4527
  revertOverrides = {
4515
4528
  [PNPM$6]: oldPnpmSection ? {
4516
4529
  ...oldPnpmSection,
4517
4530
  [OVERRIDES$1]: require$$7.hasKeys(oldOverrides) ? {
4518
4531
  ...oldOverrides,
4519
4532
  [overrideKey]: undefined
4520
- } : undefined
4521
- } : undefined
4533
+ } :
4534
+ // Properties with undefined values are deleted when saved as JSON.
4535
+ undefined
4536
+ } :
4537
+ // Properties with undefined values are deleted when saved as JSON.
4538
+ undefined
4522
4539
  };
4523
4540
  // Update overrides in the root package.json so that when `pnpm install`
4524
4541
  // generates pnpm-lock.yaml it updates transitive dependencies too.
@@ -4531,9 +4548,15 @@ async function pnpmFix(pkgEnvDetails, fixConfig) {
4531
4548
  }
4532
4549
  }
4533
4550
  });
4551
+ } else {
4552
+ revertOverrides = undefined;
4553
+ revertOverridesSrc = '';
4534
4554
  }
4535
4555
  revertData = {
4556
+ // If "pnpm" or "pnpm.overrides" fields are undefined they will be
4557
+ // deleted when saved.
4536
4558
  ...revertOverrides,
4559
+ // Track existing dependencies in the root package.json to revert to later.
4537
4560
  ...(editablePkgJson.content.dependencies && {
4538
4561
  dependencies: {
4539
4562
  ...editablePkgJson.content.dependencies
@@ -4556,19 +4579,32 @@ async function pnpmFix(pkgEnvDetails, fixConfig) {
4556
4579
  // Revert overrides metadata in package.json now that pnpm-lock.yaml
4557
4580
  // has been updated.
4558
4581
  editablePkgJson.update(revertOverrides);
4582
+ await editablePkgJson.save({
4583
+ ignoreWhitespace: true
4584
+ });
4559
4585
  }
4560
- await editablePkgJson.save({
4561
- ignoreWhitespace: true
4562
- });
4563
- const updatedOverridesContent = utils.extractOverridesFromPnpmLockSrc(lockSrc);
4564
- if (updatedOverridesContent && revertOverridesSrc) {
4565
- lockSrc = lockSrc.replace(updatedOverridesContent, revertOverridesSrc);
4566
- await fs$1.promises.writeFile(pkgEnvDetails.lockPath, lockSrc, 'utf8');
4586
+ lockSrc = (await utils.readLockfile(pkgEnvDetails.lockPath)) ?? '';
4587
+ // Remove "overrides" block from pnpm-lock.yaml lockfile when processing
4588
+ // the root workspace.
4589
+ if (editablePkgJson.filename === pkgEnvDetails.editablePkgJson.filename) {
4590
+ const updatedOverridesContent = utils.extractOverridesFromPnpmLockSrc(lockSrc);
4591
+ if (updatedOverridesContent) {
4592
+ // Remove "overrides" block from pnpm-lock.yaml lockfile.
4593
+ lockSrc = lockSrc.replace(updatedOverridesContent, revertOverridesSrc);
4594
+ // Save pnpm-lock.yaml lockfile.
4595
+ await fs$1.promises.writeFile(pkgEnvDetails.lockPath, lockSrc, 'utf8');
4596
+ }
4567
4597
  }
4568
4598
  },
4569
4599
  async revertInstall(editablePkgJson) {
4570
4600
  if (revertData) {
4601
+ // Revert package.json.
4571
4602
  editablePkgJson.update(revertData);
4603
+ await editablePkgJson.save({
4604
+ ignoreWhitespace: true
4605
+ });
4606
+ // Revert pnpm-lock.yaml lockfile to be on the safe side.
4607
+ await fs$1.promises.writeFile(pkgEnvDetails.lockPath, lockSrc, 'utf8');
4572
4608
  }
4573
4609
  }
4574
4610
  }, fixConfig);
@@ -7480,7 +7516,7 @@ function updatePkgJsonField(editablePkgJson, field, value) {
7480
7516
  }
7481
7517
  });
7482
7518
  } else {
7483
- // Properties with undefined values are omitted when saved as JSON.
7519
+ // Properties with undefined values are deleted when saved as JSON.
7484
7520
  editablePkgJson.update(require$$7.hasKeys(oldValue) ? {
7485
7521
  [field]: {
7486
7522
  ...(isPnpmObj ? oldValue : {}),
@@ -7491,7 +7527,7 @@ function updatePkgJsonField(editablePkgJson, field, value) {
7491
7527
  });
7492
7528
  }
7493
7529
  } else if (field === OVERRIDES || field === RESOLUTIONS) {
7494
- // Properties with undefined values are omitted when saved as JSON.
7530
+ // Properties with undefined values are deleted when saved as JSON.
7495
7531
  editablePkgJson.update({
7496
7532
  [field]: require$$7.hasKeys(value) ? value : undefined
7497
7533
  });
@@ -14595,5 +14631,5 @@ void (async () => {
14595
14631
  await utils.captureException(e);
14596
14632
  }
14597
14633
  })();
14598
- //# debugId=c419b9c7-a1f4-4307-8197-19068fed4cd4
14634
+ //# debugId=e65f1be3-82a5-4c66-a17f-0c3cdbe8bf46
14599
14635
  //# sourceMappingURL=cli.js.map