@socketsecurity/cli 0.14.35 → 0.14.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.
@@ -26,8 +26,8 @@ var sdk = require('./sdk.js');
26
26
  var prompts = require('@socketsecurity/registry/lib/prompts');
27
27
  var isInteractive = _socketInterop(require('is-interactive'));
28
28
  var terminalLink = _socketInterop(require('terminal-link'));
29
- var spawn = _socketInterop(require('@npmcli/promise-spawn'));
30
29
  var fs$1 = require('node:fs/promises');
30
+ var spawn = _socketInterop(require('@npmcli/promise-spawn'));
31
31
  var npa = _socketInterop(require('npm-package-arg'));
32
32
  var semver = _socketInterop(require('semver'));
33
33
  var tinyglobby = _socketInterop(require('tinyglobby'));
@@ -41,10 +41,9 @@ var strings = require('@socketsecurity/registry/lib/strings');
41
41
  var browserslist = _socketInterop(require('browserslist'));
42
42
  var which = _socketInterop(require('which'));
43
43
  var hyrious__bun_lockb = require('@socketregistry/hyrious__bun.lockb');
44
- var registryConstants = require('@socketsecurity/registry/lib/constants');
44
+ var pathResolve = require('./path-resolve.js');
45
45
  var betterAjvErrors = _socketInterop(require('@apideck/better-ajv-errors'));
46
46
  var config = require('@socketsecurity/config');
47
- var pathResolve = require('./path-resolve.js');
48
47
  var homedir = require('node:os');
49
48
  var readline = require('node:readline');
50
49
  var node_process = require('node:process');
@@ -59,6 +58,8 @@ var util = require('node:util');
59
58
  var TableWidget = _socketInterop(require('blessed-contrib/lib/widget/table'));
60
59
 
61
60
  const {
61
+ NPM: NPM$4,
62
+ PNPM: PNPM$2,
62
63
  cdxgenBinPath,
63
64
  synpBinPath
64
65
  } = constants;
@@ -71,7 +72,7 @@ const {
71
72
  } = process.env;
72
73
  const toLower = arg => arg.toLowerCase();
73
74
  const arrayToLower = arg => arg.map(toLower);
74
- const nodejsPlatformTypes = new Set(['javascript', 'js', 'nodejs', 'npm', 'pnpm', 'ts', 'tsx', 'typescript']);
75
+ const nodejsPlatformTypes = new Set(['javascript', 'js', 'nodejs', NPM$4, PNPM$2, 'ts', 'tsx', 'typescript']);
75
76
  const yargsConfig = {
76
77
  configuration: {
77
78
  'camel-case-expansion': false,
@@ -182,13 +183,13 @@ const cdxgen = {
182
183
  let cleanupPackageLock = false;
183
184
  if (yargv.type !== 'yarn' && nodejsPlatformTypes.has(yargv.type) && fs.existsSync('./yarn.lock')) {
184
185
  if (fs.existsSync('./package-lock.json')) {
185
- yargv.type = 'npm';
186
+ yargv.type = NPM$4;
186
187
  } else {
187
188
  // Use synp to create a package-lock.json from the yarn.lock,
188
189
  // based on the node_modules folder, for a more accurate SBOM.
189
190
  try {
190
191
  await npm$1.runBin(await fs.promises.realpath(synpBinPath), ['--source-file', './yarn.lock']);
191
- yargv.type = 'npm';
192
+ yargv.type = NPM$4;
192
193
  cleanupPackageLock = true;
193
194
  } catch {}
194
195
  }
@@ -573,7 +574,7 @@ function formatScore(score) {
573
574
  const {
574
575
  SOCKET_PUBLIC_API_KEY
575
576
  } = constants;
576
- const description$7 = 'Socket API login';
577
+ const description$5 = 'Socket API login';
577
578
  const flags = {
578
579
  apiBaseUrl: {
579
580
  type: 'string',
@@ -588,7 +589,7 @@ function nonNullish(value) {
588
589
  return value !== null && value !== undefined;
589
590
  }
590
591
  const login = {
591
- description: description$7,
592
+ description: description$5,
592
593
  async run(argv, importMeta, {
593
594
  parentName
594
595
  }) {
@@ -609,7 +610,7 @@ const login = {
609
610
  $ ${name}
610
611
  `, {
611
612
  argv,
612
- description: description$7,
613
+ description: description$5,
613
614
  importMeta,
614
615
  flags
615
616
  });
@@ -685,9 +686,9 @@ const login = {
685
686
  }
686
687
  };
687
688
 
688
- const description$6 = 'Socket API logout';
689
+ const description$4 = 'Socket API logout';
689
690
  const logout = {
690
- description: description$6,
691
+ description: description$4,
691
692
  async run(argv, importMeta, {
692
693
  parentName
693
694
  }) {
@@ -702,7 +703,7 @@ const logout = {
702
703
  $ ${name}
703
704
  `, {
704
705
  argv,
705
- description: description$6,
706
+ description: description$4,
706
707
  importMeta
707
708
  });
708
709
  let showHelp = cli.flags['help'];
@@ -722,58 +723,26 @@ const logout = {
722
723
  };
723
724
 
724
725
  const {
725
- abortSignal: abortSignal$4,
726
- execPath: execPath$2,
727
- rootBinPath: rootBinPath$2
726
+ NPM: NPM$3
728
727
  } = constants;
729
- const description$5 = 'npm wrapper functionality';
730
728
  const npm = {
731
- description: description$5,
732
- async run(argv, _importMeta, _ctx) {
733
- const wrapperPath = path.join(rootBinPath$2, 'npm-cli.js');
734
- process.exitCode = 1;
735
- const spawnPromise = spawn(execPath$2, [
736
- // Lazily access constants.nodeNoWarningsFlags.
737
- ...constants.nodeNoWarningsFlags, wrapperPath, ...argv], {
738
- signal: abortSignal$4,
739
- stdio: 'inherit'
740
- });
741
- spawnPromise.process.on('exit', (code, signal) => {
742
- if (signal) {
743
- process.kill(process.pid, signal);
744
- } else if (code !== null) {
745
- process.exit(code);
746
- }
747
- });
748
- await spawnPromise;
729
+ description: `${NPM$3} wrapper functionality`,
730
+ async run(argv) {
731
+ // Lazily access constants.distPath.
732
+ const shadowBin = require(`${constants.distPath}/shadow-bin.js`);
733
+ await shadowBin(NPM$3, argv);
749
734
  }
750
735
  };
751
736
 
752
737
  const {
753
- abortSignal: abortSignal$3,
754
- execPath: execPath$1,
755
- rootBinPath: rootBinPath$1
738
+ NPX: NPX$1
756
739
  } = constants;
757
- const description$4 = 'npx wrapper functionality';
758
740
  const npx = {
759
- description: description$4,
760
- async run(argv, _importMeta, _ctx) {
761
- const wrapperPath = path.join(rootBinPath$1, 'npx-cli.js');
762
- process.exitCode = 1;
763
- const spawnPromise = spawn(execPath$1, [
764
- // Lazily access constants.nodeNoWarningsFlags.
765
- ...constants.nodeNoWarningsFlags, wrapperPath, ...argv], {
766
- abortSignal: abortSignal$3,
767
- stdio: 'inherit'
768
- });
769
- spawnPromise.process.on('exit', (code, signal) => {
770
- if (signal) {
771
- process.kill(process.pid, signal);
772
- } else if (code !== null) {
773
- process.exit(code);
774
- }
775
- });
776
- await spawnPromise;
741
+ description: `${NPX$1} wrapper functionality`,
742
+ async run(argv) {
743
+ // Lazily access constants.distPath.
744
+ const shadowBin = require(`${constants.distPath}/shadow-bin.js`);
745
+ await shadowBin(NPX$1, argv);
777
746
  }
778
747
  };
779
748
 
@@ -819,7 +788,15 @@ async function readFileUtf8(filepath, options) {
819
788
  });
820
789
  }
821
790
 
822
- const AGENTS = ['bun', 'npm', 'pnpm', 'yarn/berry', 'yarn/classic', 'vlt'];
791
+ const {
792
+ BUN: BUN$1,
793
+ NPM: NPM$2,
794
+ PNPM: PNPM$1,
795
+ VLT: VLT$1,
796
+ YARN_BERRY: YARN_BERRY$1,
797
+ YARN_CLASSIC: YARN_CLASSIC$1
798
+ } = constants;
799
+ const AGENTS = [BUN$1, NPM$2, PNPM$1, YARN_BERRY$1, YARN_CLASSIC$1, VLT$1];
823
800
  const {
824
801
  compare: alphanumericComparator
825
802
  } = new Intl.Collator(undefined, {
@@ -843,55 +820,60 @@ async function getAgentVersion(agentExecPath, cwd) {
843
820
  return result;
844
821
  }
845
822
  const LOCKS = {
846
- 'bun.lockb': 'bun',
823
+ 'bun.lock': BUN$1,
824
+ 'bun.lockb': BUN$1,
847
825
  // If both package-lock.json and npm-shrinkwrap.json are present in the root
848
826
  // of a project, npm-shrinkwrap.json will take precedence and package-lock.json
849
827
  // will be ignored.
850
828
  // https://docs.npmjs.com/cli/v10/configuring-npm/package-lock-json#package-lockjson-vs-npm-shrinkwrapjson
851
- 'npm-shrinkwrap.json': 'npm',
852
- 'package-lock.json': 'npm',
853
- 'pnpm-lock.yaml': 'pnpm',
854
- 'pnpm-lock.yml': 'pnpm',
855
- 'yarn.lock': 'yarn/classic',
856
- 'vlt-lock.json': 'vlt',
829
+ 'npm-shrinkwrap.json': NPM$2,
830
+ 'package-lock.json': NPM$2,
831
+ 'pnpm-lock.yaml': PNPM$1,
832
+ 'pnpm-lock.yml': PNPM$1,
833
+ 'yarn.lock': YARN_CLASSIC$1,
834
+ 'vlt-lock.json': VLT$1,
857
835
  // Look for a hidden lock file if .npmrc has package-lock=false:
858
836
  // https://docs.npmjs.com/cli/v10/configuring-npm/package-lock-json#hidden-lockfiles
859
837
  //
860
838
  // Unlike the other LOCKS keys this key contains a directory AND filename so
861
839
  // it has to be handled differently.
862
- 'node_modules/.package-lock.json': 'npm'
840
+ 'node_modules/.package-lock.json': NPM$2
863
841
  };
864
842
  const readLockFileByAgent = (() => {
865
843
  function wrapReader(reader) {
866
- return async (lockPath, agentExecPath) => {
844
+ return async (...args) => {
867
845
  try {
868
- return await reader(lockPath, agentExecPath);
846
+ return await reader(...args);
869
847
  } catch {}
870
848
  return undefined;
871
849
  };
872
850
  }
851
+ const binaryReader = wrapReader(readFileBinary);
873
852
  const defaultReader = wrapReader(async lockPath => await readFileUtf8(lockPath));
874
853
  return {
875
- bun: wrapReader(async (lockPath, agentExecPath) => {
876
- let lockBuffer;
877
- try {
878
- lockBuffer = await readFileBinary(lockPath);
879
- } catch {
880
- return undefined;
854
+ [BUN$1]: wrapReader(async (lockPath, agentExecPath) => {
855
+ const ext = path.extname(lockPath);
856
+ if (ext === '.lock') {
857
+ return await defaultReader(lockPath);
858
+ }
859
+ if (ext === '.lockb') {
860
+ const lockBuffer = await binaryReader(lockPath);
861
+ if (lockBuffer) {
862
+ try {
863
+ return hyrious__bun_lockb.parse(lockBuffer);
864
+ } catch {}
865
+ }
866
+ // To print a Yarn lockfile to your console without writing it to disk
867
+ // use `bun bun.lockb`.
868
+ // https://bun.sh/guides/install/yarnlock
869
+ return (await spawn(agentExecPath, [lockPath])).stdout.trim();
881
870
  }
882
- try {
883
- return hyrious__bun_lockb.parse(lockBuffer);
884
- } catch {}
885
- // To print a Yarn lockfile to your console without writing it to disk
886
- // use `bun bun.lockb`.
887
- // https://bun.sh/guides/install/yarnlock
888
- return (await spawn(agentExecPath, [lockPath])).stdout.trim();
889
871
  }),
890
- npm: defaultReader,
891
- pnpm: defaultReader,
892
- vlt: defaultReader,
893
- 'yarn/berry': defaultReader,
894
- 'yarn/classic': defaultReader
872
+ [NPM$2]: defaultReader,
873
+ [PNPM$1]: defaultReader,
874
+ [VLT$1]: defaultReader,
875
+ [YARN_BERRY$1]: defaultReader,
876
+ [YARN_CLASSIC$1]: defaultReader
895
877
  };
896
878
  })();
897
879
  async function detect({
@@ -901,7 +883,8 @@ async function detect({
901
883
  let lockPath = await findUp(Object.keys(LOCKS), {
902
884
  cwd
903
885
  });
904
- const isHiddenLockFile = lockPath?.endsWith('.package-lock.json') ?? false;
886
+ let lockBasename = lockPath ? path.basename(lockPath) : undefined;
887
+ const isHiddenLockFile = lockBasename === '.package-lock.json';
905
888
  const pkgJsonPath = lockPath ? path.resolve(lockPath, `${isHiddenLockFile ? '../' : ''}../package.json`) : await findUp('package.json', {
906
889
  cwd
907
890
  });
@@ -926,20 +909,20 @@ async function detect({
926
909
  }
927
910
  }
928
911
  }
929
- if (agent === undefined && !isHiddenLockFile && typeof pkgJsonPath === 'string' && typeof lockPath === 'string') {
930
- agent = LOCKS[path.basename(lockPath)];
912
+ if (agent === undefined && !isHiddenLockFile && typeof pkgJsonPath === 'string' && typeof lockBasename === 'string') {
913
+ agent = LOCKS[lockBasename];
931
914
  }
932
915
  if (agent === undefined) {
933
- agent = 'npm';
916
+ agent = NPM$2;
934
917
  onUnknown?.(pkgManager);
935
918
  }
936
919
  const agentExecPath = await getAgentExecPath(agent);
937
- const npmExecPath = agent === 'npm' ? agentExecPath : await getAgentExecPath('npm');
920
+ const npmExecPath = agent === NPM$2 ? agentExecPath : await getAgentExecPath(NPM$2);
938
921
  if (agentVersion === undefined) {
939
922
  agentVersion = await getAgentVersion(agentExecPath, cwd);
940
923
  }
941
- if (agent === 'yarn/classic' && (agentVersion?.major ?? 0) > 1) {
942
- agent = 'yarn/berry';
924
+ if (agent === YARN_CLASSIC$1 && (agentVersion?.major ?? 0) > 1) {
925
+ agent = YARN_BERRY$1;
943
926
  }
944
927
  const targets = {
945
928
  browser: false,
@@ -947,7 +930,7 @@ async function detect({
947
930
  };
948
931
  let lockSrc;
949
932
  // Lazily access constants.maintainedNodeVersions.
950
- let minimumNodeVersion = registryConstants.maintainedNodeVersions.previous;
933
+ let minimumNodeVersion = constants.maintainedNodeVersions.previous;
951
934
  if (pkgJson) {
952
935
  const browserField = pkgJson.browser;
953
936
  if (strings.isNonEmptyString(browserField) || objects.isObjectObject(browserField)) {
@@ -975,15 +958,17 @@ async function detect({
975
958
  }
976
959
  }
977
960
  // Lazily access constants.maintainedNodeVersions.
978
- targets.node = registryConstants.maintainedNodeVersions.some(v => semver.satisfies(v, `>=${minimumNodeVersion}`));
961
+ targets.node = constants.maintainedNodeVersions.some(v => semver.satisfies(v, `>=${minimumNodeVersion}`));
979
962
  lockSrc = typeof lockPath === 'string' ? await readLockFileByAgent[agent](lockPath, agentExecPath) : undefined;
980
963
  } else {
964
+ lockBasename = undefined;
981
965
  lockPath = undefined;
982
966
  }
983
967
  return {
984
968
  agent,
985
969
  agentExecPath,
986
970
  agentVersion,
971
+ lockBasename,
987
972
  lockPath,
988
973
  lockSrc,
989
974
  minimumNodeVersion,
@@ -996,7 +981,13 @@ async function detect({
996
981
  }
997
982
 
998
983
  const {
984
+ BUN,
985
+ NPM: NPM$1,
986
+ PNPM,
999
987
  UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE,
988
+ VLT,
989
+ YARN_BERRY,
990
+ YARN_CLASSIC,
1000
991
  abortSignal: abortSignal$2,
1001
992
  execPath,
1002
993
  rootBinPath
@@ -1004,63 +995,68 @@ const {
1004
995
  const COMMAND_TITLE = 'Socket Optimize';
1005
996
  const OVERRIDES_FIELD_NAME = 'overrides';
1006
997
  const NPM_OVERRIDE_PR_URL = 'https://github.com/npm/cli/pull/7025';
1007
- const PNPM_FIELD_NAME = 'pnpm';
1008
- const PNPM_WORKSPACE = 'pnpm-workspace';
998
+ const PNPM_FIELD_NAME = PNPM;
999
+ const PNPM_WORKSPACE = `${PNPM}-workspace`;
1009
1000
  const RESOLUTIONS_FIELD_NAME = 'resolutions';
1010
- const manifestNpmOverrides = registry.getManifestData('npm');
1001
+ const manifestNpmOverrides = registry.getManifestData(NPM$1);
1011
1002
  const getOverridesDataByAgent = {
1012
- bun(pkgJson) {
1003
+ [BUN](pkgJson) {
1013
1004
  const overrides = pkgJson?.resolutions ?? {};
1014
1005
  return {
1015
- type: 'yarn/berry',
1006
+ type: YARN_BERRY,
1016
1007
  overrides
1017
1008
  };
1018
1009
  },
1019
1010
  // npm overrides documentation:
1020
1011
  // https://docs.npmjs.com/cli/v10/configuring-npm/package-json#overrides
1021
- npm(pkgJson) {
1012
+ [NPM$1](pkgJson) {
1022
1013
  const overrides = pkgJson?.overrides ?? {};
1023
1014
  return {
1024
- type: 'npm',
1015
+ type: NPM$1,
1025
1016
  overrides
1026
1017
  };
1027
1018
  },
1028
1019
  // pnpm overrides documentation:
1029
1020
  // https://pnpm.io/package_json#pnpmoverrides
1030
- pnpm(pkgJson) {
1021
+ [PNPM](pkgJson) {
1031
1022
  const overrides = pkgJson?.pnpm?.overrides ?? {};
1032
1023
  return {
1033
- type: 'pnpm',
1024
+ type: PNPM,
1034
1025
  overrides
1035
1026
  };
1036
1027
  },
1037
- vlt(pkgJson) {
1028
+ [VLT](pkgJson) {
1038
1029
  const overrides = pkgJson?.overrides ?? {};
1039
1030
  return {
1040
- type: 'vlt',
1031
+ type: VLT,
1041
1032
  overrides
1042
1033
  };
1043
1034
  },
1044
1035
  // Yarn resolutions documentation:
1045
1036
  // https://yarnpkg.com/configuration/manifest#resolutions
1046
- 'yarn/berry'(pkgJson) {
1037
+ [YARN_BERRY](pkgJson) {
1047
1038
  const overrides = pkgJson?.resolutions ?? {};
1048
1039
  return {
1049
- type: 'yarn/berry',
1040
+ type: YARN_BERRY,
1050
1041
  overrides
1051
1042
  };
1052
1043
  },
1053
1044
  // Yarn resolutions documentation:
1054
1045
  // https://classic.yarnpkg.com/en/docs/selective-version-resolutions
1055
- 'yarn/classic'(pkgJson) {
1046
+ [YARN_CLASSIC](pkgJson) {
1056
1047
  const overrides = pkgJson?.resolutions ?? {};
1057
1048
  return {
1058
- type: 'yarn/classic',
1049
+ type: YARN_CLASSIC,
1059
1050
  overrides
1060
1051
  };
1061
1052
  }
1062
1053
  };
1063
1054
  const lockIncludesByAgent = (() => {
1055
+ function npmLockIncludes(lockSrc, name) {
1056
+ // Detects the package name in the following cases:
1057
+ // "name":
1058
+ return lockSrc.includes(`"${name}":`);
1059
+ }
1064
1060
  function yarnLockIncludes(lockSrc, name) {
1065
1061
  const escapedName = regexps.escapeRegExp(name);
1066
1062
  return new RegExp(
@@ -1072,13 +1068,11 @@ const lockIncludesByAgent = (() => {
1072
1068
  `(?<=(?:^\\s*|,\\s*)"?)${escapedName}(?=@)`, 'm').test(lockSrc);
1073
1069
  }
1074
1070
  return {
1075
- bun: yarnLockIncludes,
1076
- npm(lockSrc, name) {
1077
- // Detects the package name in the following cases:
1078
- // "name":
1079
- return lockSrc.includes(`"${name}":`);
1071
+ [BUN](lockSrc, name, lockBasename) {
1072
+ return (lockBasename === '.lock' ? npmLockIncludes : yarnLockIncludes)(lockSrc, name);
1080
1073
  },
1081
- pnpm(lockSrc, name) {
1074
+ [NPM$1]: npmLockIncludes,
1075
+ [PNPM](lockSrc, name) {
1082
1076
  const escapedName = regexps.escapeRegExp(name);
1083
1077
  return new RegExp(
1084
1078
  // Detects the package name in the following cases:
@@ -1088,13 +1082,13 @@ const lockIncludesByAgent = (() => {
1088
1082
  // name@
1089
1083
  `(?<=^\\s*)(?:(['/])${escapedName}\\1|${escapedName}(?=[:@]))`, 'm').test(lockSrc);
1090
1084
  },
1091
- vlt(lockSrc, name) {
1085
+ [VLT](lockSrc, name) {
1092
1086
  // Detects the package name in the following cases:
1093
1087
  // "name"
1094
1088
  return lockSrc.includes(`"${name}"`);
1095
1089
  },
1096
- 'yarn/berry': yarnLockIncludes,
1097
- 'yarn/classic': yarnLockIncludes
1090
+ [YARN_BERRY]: yarnLockIncludes,
1091
+ [YARN_CLASSIC]: yarnLockIncludes
1098
1092
  };
1099
1093
  })();
1100
1094
  const updateManifestByAgent = (() => {
@@ -1154,16 +1148,16 @@ const updateManifestByAgent = (() => {
1154
1148
  let insertIndex = -1;
1155
1149
  let isPlacingHigher = false;
1156
1150
  if (field === OVERRIDES_FIELD_NAME) {
1157
- insertIndex = getLowestEntryIndex(entries, ['resolutions']);
1151
+ insertIndex = getLowestEntryIndex(entries, [RESOLUTIONS_FIELD_NAME]);
1158
1152
  if (insertIndex === -1) {
1159
1153
  isPlacingHigher = true;
1160
- insertIndex = getHighestEntryIndex(entries, [...depFields, 'pnpm']);
1154
+ insertIndex = getHighestEntryIndex(entries, [...depFields, PNPM]);
1161
1155
  }
1162
1156
  } else if (field === RESOLUTIONS_FIELD_NAME) {
1163
1157
  isPlacingHigher = true;
1164
- insertIndex = getHighestEntryIndex(entries, [...depFields, 'overrides', 'pnpm']);
1158
+ insertIndex = getHighestEntryIndex(entries, [...depFields, OVERRIDES_FIELD_NAME, PNPM]);
1165
1159
  } else if (field === PNPM_FIELD_NAME) {
1166
- insertIndex = getLowestEntryIndex(entries, ['overrides', 'resolutions']);
1160
+ insertIndex = getLowestEntryIndex(entries, [OVERRIDES_FIELD_NAME, RESOLUTIONS_FIELD_NAME]);
1167
1161
  if (insertIndex === -1) {
1168
1162
  isPlacingHigher = true;
1169
1163
  insertIndex = getHighestEntryIndex(entries, depFields);
@@ -1191,14 +1185,14 @@ const updateManifestByAgent = (() => {
1191
1185
  updatePkgJson(editablePkgJson, RESOLUTIONS_FIELD_NAME, overrides);
1192
1186
  }
1193
1187
  return {
1194
- bun: updateResolutions,
1195
- npm: updateOverrides,
1196
- pnpm(editablePkgJson, overrides) {
1188
+ [BUN]: updateResolutions,
1189
+ [NPM$1]: updateOverrides,
1190
+ [PNPM](editablePkgJson, overrides) {
1197
1191
  updatePkgJson(editablePkgJson, PNPM_FIELD_NAME, overrides);
1198
1192
  },
1199
- vlt: updateOverrides,
1200
- 'yarn/berry': updateResolutions,
1201
- 'yarn/classic': updateResolutions
1193
+ [VLT]: updateOverrides,
1194
+ [YARN_BERRY]: updateResolutions,
1195
+ [YARN_CLASSIC]: updateResolutions
1202
1196
  };
1203
1197
  })();
1204
1198
  const lsByAgent = (() => {
@@ -1252,7 +1246,7 @@ const lsByAgent = (() => {
1252
1246
  return cleanupQueryStdout(stdout);
1253
1247
  }
1254
1248
  return {
1255
- async bun(agentExecPath, cwd) {
1249
+ async [BUN](agentExecPath, cwd) {
1256
1250
  try {
1257
1251
  // Bun does not support filtering by production packages yet.
1258
1252
  // https://github.com/oven-sh/bun/issues/8283
@@ -1262,17 +1256,17 @@ const lsByAgent = (() => {
1262
1256
  } catch {}
1263
1257
  return '';
1264
1258
  },
1265
- async npm(agentExecPath, cwd) {
1259
+ async [NPM$1](agentExecPath, cwd) {
1266
1260
  return await npmQuery(agentExecPath, cwd);
1267
1261
  },
1268
- async pnpm(agentExecPath, cwd, options) {
1262
+ async [PNPM](agentExecPath, cwd, options) {
1269
1263
  const {
1270
1264
  npmExecPath
1271
1265
  } = {
1272
1266
  __proto__: null,
1273
1267
  ...options
1274
1268
  };
1275
- if (npmExecPath && npmExecPath !== 'npm') {
1269
+ if (npmExecPath && npmExecPath !== NPM$1) {
1276
1270
  const result = await npmQuery(npmExecPath, cwd);
1277
1271
  if (result) {
1278
1272
  return result;
@@ -1286,7 +1280,7 @@ const lsByAgent = (() => {
1286
1280
  } catch {}
1287
1281
  return parseableToQueryStdout(stdout);
1288
1282
  },
1289
- async vlt(agentExecPath, cwd) {
1283
+ async [VLT](agentExecPath, cwd) {
1290
1284
  let stdout = '';
1291
1285
  try {
1292
1286
  stdout = (await spawn(agentExecPath, ['ls', '--view', 'human', ':not(.dev)'], {
@@ -1295,7 +1289,7 @@ const lsByAgent = (() => {
1295
1289
  } catch {}
1296
1290
  return cleanupQueryStdout(stdout);
1297
1291
  },
1298
- async 'yarn/berry'(agentExecPath, cwd) {
1292
+ async [YARN_BERRY](agentExecPath, cwd) {
1299
1293
  try {
1300
1294
  return (
1301
1295
  // Yarn Berry does not support filtering by production packages yet.
@@ -1307,7 +1301,7 @@ const lsByAgent = (() => {
1307
1301
  } catch {}
1308
1302
  return '';
1309
1303
  },
1310
- async 'yarn/classic'(agentExecPath, cwd) {
1304
+ async [YARN_CLASSIC](agentExecPath, cwd) {
1311
1305
  try {
1312
1306
  // However, Yarn Classic does support it.
1313
1307
  // https://github.com/yarnpkg/yarn/releases/tag/v1.0.0
@@ -1329,12 +1323,12 @@ const depsIncludesByAgent = (() => {
1329
1323
  return stdout.includes(`"${name}"`);
1330
1324
  }
1331
1325
  return {
1332
- bun: matchHumanStdout,
1333
- npm: matchQueryStdout,
1334
- pnpm: matchQueryStdout,
1335
- vlt: matchQueryStdout,
1336
- 'yarn/berry': matchHumanStdout,
1337
- 'yarn/classic': matchHumanStdout
1326
+ [BUN]: matchHumanStdout,
1327
+ [NPM$1]: matchQueryStdout,
1328
+ [PNPM]: matchQueryStdout,
1329
+ [VLT]: matchQueryStdout,
1330
+ [YARN_BERRY]: matchHumanStdout,
1331
+ [YARN_CLASSIC]: matchHumanStdout
1338
1332
  };
1339
1333
  })();
1340
1334
  function createActionMessage(verb, overrideCount, workspaceCount) {
@@ -1365,7 +1359,7 @@ function getDependencyEntries(pkgJson) {
1365
1359
  }
1366
1360
  async function getWorkspaceGlobs(agent, pkgPath, pkgJson) {
1367
1361
  let workspacePatterns;
1368
- if (agent === 'pnpm') {
1362
+ if (agent === PNPM) {
1369
1363
  for (const workspacePath of [path.join(pkgPath, `${PNPM_WORKSPACE}.yaml`), path.join(pkgPath, `${PNPM_WORKSPACE}.yml`)]) {
1370
1364
  if (existsSync(workspacePath)) {
1371
1365
  try {
@@ -1415,6 +1409,7 @@ function createAddOverridesState(initials) {
1415
1409
  async function addOverrides({
1416
1410
  agent,
1417
1411
  agentExecPath,
1412
+ lockBasename,
1418
1413
  lockSrc,
1419
1414
  manifestEntries,
1420
1415
  npmExecPath,
@@ -1440,7 +1435,7 @@ async function addOverrides({
1440
1435
  const workspaceName = path.relative(rootPath, pkgPath);
1441
1436
  const workspaceGlobs = await getWorkspaceGlobs(agent, pkgPath, pkgJson);
1442
1437
  const isWorkspace = !!workspaceGlobs;
1443
- if (isWorkspace && agent === 'pnpm' && npmExecPath === 'npm' && !state.warnedPnpmWorkspaceRequiresNpm) {
1438
+ if (isWorkspace && agent === PNPM && npmExecPath === NPM$1 && !state.warnedPnpmWorkspaceRequiresNpm) {
1444
1439
  state.warnedPnpmWorkspaceRequiresNpm = true;
1445
1440
  console.warn(`⚠️ ${COMMAND_TITLE}: pnpm workspace support requires \`npm ls\`, falling back to \`pnpm list\``);
1446
1441
  }
@@ -1453,7 +1448,7 @@ async function addOverrides({
1453
1448
  if (pkgJson['private'] || isWorkspace) {
1454
1449
  overridesDataObjects.push(getOverridesDataByAgent[agent](pkgJson));
1455
1450
  } else {
1456
- overridesDataObjects.push(getOverridesDataByAgent.npm(pkgJson), getOverridesDataByAgent['yarn/classic'](pkgJson));
1451
+ overridesDataObjects.push(getOverridesDataByAgent[NPM$1](pkgJson), getOverridesDataByAgent[YARN_CLASSIC](pkgJson));
1457
1452
  }
1458
1453
  if (spinner) {
1459
1454
  spinner.text = `Adding overrides${workspaceName ? ` to ${workspaceName}` : ''}...`;
@@ -1502,13 +1497,13 @@ async function addOverrides({
1502
1497
  type
1503
1498
  }) => {
1504
1499
  const overrideExists = objects.hasOwn(overrides, origPkgName);
1505
- if (overrideExists || thingScanner(thingToScan, origPkgName)) {
1500
+ if (overrideExists || thingScanner(thingToScan, origPkgName, lockBasename)) {
1506
1501
  const oldSpec = overrideExists ? overrides[origPkgName] : undefined;
1507
1502
  const depAlias = depAliasMap.get(origPkgName);
1508
- const regSpecStartsLike = `npm:${regPkgName}@`;
1503
+ const regSpecStartsLike = `${NPM$1}:${regPkgName}@`;
1509
1504
  let newSpec = `${regSpecStartsLike}^${pin ? version : major}`;
1510
1505
  let thisVersion = version;
1511
- if (depAlias && type === 'npm') {
1506
+ if (depAlias && type === NPM$1) {
1512
1507
  // With npm one may not set an override for a package that one directly
1513
1508
  // depends on unless both the dependency and the override itself share
1514
1509
  // the exact same spec. To make this limitation easier to deal with,
@@ -1532,10 +1527,6 @@ async function addOverrides({
1532
1527
  overrides[origPkgName] = newSpec;
1533
1528
  const addedOrUpdated = overrideExists ? 'updated' : 'added';
1534
1529
  state[addedOrUpdated].add(regPkgName);
1535
- if (workspaceName) {
1536
- const addedOrUpdatedIn = overrideExists ? 'updatedInWorkspaces' : 'addedInWorkspaces';
1537
- state[addedOrUpdatedIn].add(workspaceName);
1538
- }
1539
1530
  }
1540
1531
  }
1541
1532
  });
@@ -1552,6 +1543,7 @@ async function addOverrides({
1552
1543
  const otherState = await addOverrides({
1553
1544
  agent,
1554
1545
  agentExecPath,
1546
+ lockBasename,
1555
1547
  lockSrc,
1556
1548
  manifestEntries,
1557
1549
  npmExecPath,
@@ -1599,6 +1591,7 @@ const optimize = {
1599
1591
  agent,
1600
1592
  agentExecPath,
1601
1593
  agentVersion,
1594
+ lockBasename,
1602
1595
  lockPath,
1603
1596
  lockSrc,
1604
1597
  minimumNodeVersion,
@@ -1616,12 +1609,12 @@ const optimize = {
1616
1609
  console.error(`✖️ ${COMMAND_TITLE}: No supported Node or browser range detected`);
1617
1610
  return;
1618
1611
  }
1619
- if (agent === 'vlt') {
1612
+ if (agent === VLT) {
1620
1613
  console.error(`✖️ ${COMMAND_TITLE}: ${agent} does not support overrides. Soon, though ⚡`);
1621
1614
  return;
1622
1615
  }
1623
- const lockName = lockPath ? path.basename(lockPath) : 'lock file';
1624
- if (lockSrc === undefined) {
1616
+ const lockName = lockPath ? lockBasename : 'lock file';
1617
+ if (lockBasename === undefined || lockSrc === undefined) {
1625
1618
  console.error(`✖️ ${COMMAND_TITLE}: No ${lockName} found`);
1626
1619
  return;
1627
1620
  }
@@ -1633,7 +1626,7 @@ const optimize = {
1633
1626
  console.error(`✖️ ${COMMAND_TITLE}: No package.json found`);
1634
1627
  return;
1635
1628
  }
1636
- if (prod && (agent === 'bun' || agent === 'yarn/berry')) {
1629
+ if (prod && (agent === BUN || agent === YARN_BERRY)) {
1637
1630
  console.error(`✖️ ${COMMAND_TITLE}: --prod not supported for ${agent}${agentVersion ? `@${agentVersion.toString()}` : ''}`);
1638
1631
  return;
1639
1632
  }
@@ -1654,6 +1647,7 @@ const optimize = {
1654
1647
  await addOverrides({
1655
1648
  agent,
1656
1649
  agentExecPath,
1650
+ lockBasename,
1657
1651
  lockSrc,
1658
1652
  manifestEntries,
1659
1653
  npmExecPath,
@@ -1677,7 +1671,7 @@ const optimize = {
1677
1671
  } else {
1678
1672
  console.log('Congratulations! Already Socket.dev optimized 🎉');
1679
1673
  }
1680
- const isNpm = agent === 'npm';
1674
+ const isNpm = agent === NPM$1;
1681
1675
  if (isNpm || pkgJsonChanged) {
1682
1676
  // Always update package-lock.json until the npm overrides PR lands:
1683
1677
  // https://github.com/npm/cli/pull/7025
@@ -1810,14 +1804,16 @@ Plan: ${o?.plan}
1810
1804
  }
1811
1805
 
1812
1806
  const {
1807
+ NPM,
1813
1808
  abortSignal: abortSignal$1
1814
1809
  } = constants;
1810
+ const binName$1 = NPM;
1815
1811
  const rawNpm = {
1816
- description: 'Temporarily disable the Socket npm wrapper',
1812
+ description: `Temporarily disable the Socket ${binName$1} wrapper`,
1817
1813
  async run(argv, importMeta, {
1818
1814
  parentName
1819
1815
  }) {
1820
- await setupCommand$j(`${parentName} raw-npm`, rawNpm.description, argv, importMeta);
1816
+ await setupCommand$j(`${parentName} raw-${binName$1}`, rawNpm.description, argv, importMeta);
1821
1817
  }
1822
1818
  };
1823
1819
  async function setupCommand$j(name, description, argv, importMeta) {
@@ -1827,7 +1823,7 @@ async function setupCommand$j(name, description, argv, importMeta) {
1827
1823
  };
1828
1824
  const cli = meow(`
1829
1825
  Usage
1830
- $ ${name} <npm command>
1826
+ $ ${name} <${binName$1} command>
1831
1827
 
1832
1828
  Options
1833
1829
  ${printFlagList(flags, 6)}
@@ -1848,13 +1844,26 @@ async function setupCommand$j(name, description, argv, importMeta) {
1848
1844
  cli.showHelp();
1849
1845
  return;
1850
1846
  }
1851
- const spawnPromise = spawn('npm', argv, {
1847
+ const {
1848
+ path: binPath
1849
+ } = await pathResolve.findBinPathDetails(binName$1);
1850
+ if (!binPath) {
1851
+ // The exit code 127 indicates that the command or binary being executed
1852
+ // could not be found.
1853
+ console.error(`Socket unable to locate ${binName$1}; ensure it is available in the PATH environment variable.`);
1854
+ process.exit(127);
1855
+ }
1856
+ const spawnPromise = spawn(binPath, argv, {
1852
1857
  signal: abortSignal$1,
1853
1858
  stdio: 'inherit'
1854
1859
  });
1855
- spawnPromise.process.on('exit', (code, signal) => {
1856
- if (signal) {
1857
- process.kill(process.pid, signal);
1860
+ // See https://nodejs.org/api/all.html#all_child_process_event-exit.
1861
+ spawnPromise.process.on('exit', (code, signalName) => {
1862
+ if (abortSignal$1.aborted) {
1863
+ return;
1864
+ }
1865
+ if (signalName) {
1866
+ process.kill(process.pid, signalName);
1858
1867
  } else if (code !== null) {
1859
1868
  process.exit(code);
1860
1869
  }
@@ -1863,14 +1872,16 @@ async function setupCommand$j(name, description, argv, importMeta) {
1863
1872
  }
1864
1873
 
1865
1874
  const {
1875
+ NPX,
1866
1876
  abortSignal
1867
1877
  } = constants;
1878
+ const binName = NPX;
1868
1879
  const rawNpx = {
1869
- description: 'Temporarily disable the Socket npm/npx wrapper',
1880
+ description: `Temporarily disable the Socket ${binName} wrapper`,
1870
1881
  async run(argv, importMeta, {
1871
1882
  parentName
1872
1883
  }) {
1873
- await setupCommand$i(`${parentName} raw-npx`, rawNpx.description, argv, importMeta);
1884
+ await setupCommand$i(`${parentName} raw-${binName}`, rawNpx.description, argv, importMeta);
1874
1885
  }
1875
1886
  };
1876
1887
  async function setupCommand$i(name, description, argv, importMeta) {
@@ -1880,7 +1891,7 @@ async function setupCommand$i(name, description, argv, importMeta) {
1880
1891
  };
1881
1892
  const cli = meow(`
1882
1893
  Usage
1883
- $ ${name} <npx command>
1894
+ $ ${name} <${binName} command>
1884
1895
 
1885
1896
  Options
1886
1897
  ${printFlagList(flags, 6)}
@@ -1901,13 +1912,26 @@ async function setupCommand$i(name, description, argv, importMeta) {
1901
1912
  cli.showHelp();
1902
1913
  return;
1903
1914
  }
1904
- const spawnPromise = spawn('npx', [argv.join(' ')], {
1915
+ const {
1916
+ path: binPath
1917
+ } = await pathResolve.findBinPathDetails(binName);
1918
+ if (!binPath) {
1919
+ // The exit code 127 indicates that the command or binary being executed
1920
+ // could not be found.
1921
+ console.error(`Socket unable to locate ${binName}; ensure it is available in the PATH environment variable.`);
1922
+ process.exit(127);
1923
+ }
1924
+ const spawnPromise = spawn(binPath, argv, {
1905
1925
  signal: abortSignal,
1906
1926
  stdio: 'inherit'
1907
1927
  });
1908
- spawnPromise.process.on('exit', (code, signal) => {
1909
- if (signal) {
1910
- process.kill(process.pid, signal);
1928
+ // See https://nodejs.org/api/all.html#all_child_process_event-exit.
1929
+ spawnPromise.process.on('exit', (code, signalName) => {
1930
+ if (abortSignal.aborted) {
1931
+ return;
1932
+ }
1933
+ if (signalName) {
1934
+ process.kill(process.pid, signalName);
1911
1935
  } else if (code !== null) {
1912
1936
  process.exit(code);
1913
1937
  }