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