@socketsecurity/cli 0.14.35 → 0.14.37
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/cli.js +11 -7
- package/bin/npm-cli.js +2 -2
- package/bin/npx-cli.js +2 -2
- package/dist/constants.js +66 -22
- package/dist/module-sync/cli.js +212 -173
- package/dist/module-sync/constants.d.ts +9 -0
- package/dist/module-sync/constants.d.ts.map +1 -1
- package/dist/module-sync/npm-injection.js +1 -1
- package/dist/module-sync/path-resolve.d.ts +6 -1
- package/dist/module-sync/path-resolve.js +31 -4
- package/dist/module-sync/shadow-bin.d.ts +1 -1
- package/dist/module-sync/shadow-bin.js +17 -23
- package/dist/require/cli.js +212 -173
- package/dist/require/constants.d.ts.map +1 -1
- package/dist/require/npm-injection.js +1 -1
- package/dist/require/path-resolve.js +31 -4
- package/dist/require/shadow-bin.js +17 -23
- package/package.json +12 -12
package/dist/require/cli.js
CHANGED
|
@@ -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
|
|
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',
|
|
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 =
|
|
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 =
|
|
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$
|
|
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$
|
|
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$
|
|
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$
|
|
685
|
+
const description$4 = 'Socket API logout';
|
|
685
686
|
const logout = {
|
|
686
|
-
description: description$
|
|
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$
|
|
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
|
-
|
|
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:
|
|
728
|
-
async run(argv
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
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
|
-
|
|
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:
|
|
756
|
-
async run(argv
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
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,17 @@ async function readFileUtf8(filepath, options) {
|
|
|
815
784
|
});
|
|
816
785
|
}
|
|
817
786
|
|
|
818
|
-
const
|
|
787
|
+
const {
|
|
788
|
+
BINARY_LOCK_EXT,
|
|
789
|
+
BUN: BUN$1,
|
|
790
|
+
LOCK_EXT: LOCK_EXT$1,
|
|
791
|
+
NPM: NPM$2,
|
|
792
|
+
PNPM: PNPM$1,
|
|
793
|
+
VLT: VLT$1,
|
|
794
|
+
YARN_BERRY: YARN_BERRY$1,
|
|
795
|
+
YARN_CLASSIC: YARN_CLASSIC$1
|
|
796
|
+
} = constants;
|
|
797
|
+
const AGENTS = [BUN$1, NPM$2, PNPM$1, YARN_BERRY$1, YARN_CLASSIC$1, VLT$1];
|
|
819
798
|
const {
|
|
820
799
|
compare: alphanumericComparator
|
|
821
800
|
} = new Intl.Collator(undefined, {
|
|
@@ -838,56 +817,64 @@ async function getAgentVersion(agentExecPath, cwd) {
|
|
|
838
817
|
} catch {}
|
|
839
818
|
return result;
|
|
840
819
|
}
|
|
820
|
+
|
|
821
|
+
// The order of LOCKS properties IS significant as it affects iteration order.
|
|
841
822
|
const LOCKS = {
|
|
842
|
-
|
|
823
|
+
[`bun${LOCK_EXT$1}`]: BUN$1,
|
|
824
|
+
[`bun${BINARY_LOCK_EXT}`]: BUN$1,
|
|
843
825
|
// If both package-lock.json and npm-shrinkwrap.json are present in the root
|
|
844
826
|
// of a project, npm-shrinkwrap.json will take precedence and package-lock.json
|
|
845
827
|
// will be ignored.
|
|
846
828
|
// https://docs.npmjs.com/cli/v10/configuring-npm/package-lock-json#package-lockjson-vs-npm-shrinkwrapjson
|
|
847
|
-
'npm-shrinkwrap.json':
|
|
848
|
-
'package-lock.json':
|
|
849
|
-
'pnpm-lock.yaml':
|
|
850
|
-
'pnpm-lock.yml':
|
|
851
|
-
|
|
852
|
-
'vlt-lock.json':
|
|
853
|
-
//
|
|
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_EXT$1}`]: YARN_CLASSIC$1,
|
|
834
|
+
'vlt-lock.json': VLT$1,
|
|
835
|
+
// Lastly, look for a hidden lock file which is present if .npmrc has package-lock=false:
|
|
854
836
|
// https://docs.npmjs.com/cli/v10/configuring-npm/package-lock-json#hidden-lockfiles
|
|
855
837
|
//
|
|
856
838
|
// Unlike the other LOCKS keys this key contains a directory AND filename so
|
|
857
839
|
// it has to be handled differently.
|
|
858
|
-
'node_modules/.package-lock.json':
|
|
840
|
+
'node_modules/.package-lock.json': NPM$2
|
|
859
841
|
};
|
|
860
842
|
const readLockFileByAgent = (() => {
|
|
861
843
|
function wrapReader(reader) {
|
|
862
|
-
return async (
|
|
844
|
+
return async (...args) => {
|
|
863
845
|
try {
|
|
864
|
-
return await reader(
|
|
846
|
+
return await reader(...args);
|
|
865
847
|
} catch {}
|
|
866
848
|
return undefined;
|
|
867
849
|
};
|
|
868
850
|
}
|
|
851
|
+
const binaryReader = wrapReader(readFileBinary);
|
|
869
852
|
const defaultReader = wrapReader(async lockPath => await readFileUtf8(lockPath));
|
|
870
853
|
return {
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
} catch {
|
|
876
|
-
return undefined;
|
|
854
|
+
[BUN$1]: wrapReader(async (lockPath, agentExecPath) => {
|
|
855
|
+
const ext = path.extname(lockPath);
|
|
856
|
+
if (ext === LOCK_EXT$1) {
|
|
857
|
+
return await defaultReader(lockPath);
|
|
877
858
|
}
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
859
|
+
if (ext === BINARY_LOCK_EXT) {
|
|
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();
|
|
870
|
+
}
|
|
871
|
+
return undefined;
|
|
885
872
|
}),
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
873
|
+
[NPM$2]: defaultReader,
|
|
874
|
+
[PNPM$1]: defaultReader,
|
|
875
|
+
[VLT$1]: defaultReader,
|
|
876
|
+
[YARN_BERRY$1]: defaultReader,
|
|
877
|
+
[YARN_CLASSIC$1]: defaultReader
|
|
891
878
|
};
|
|
892
879
|
})();
|
|
893
880
|
async function detect({
|
|
@@ -897,7 +884,8 @@ async function detect({
|
|
|
897
884
|
let lockPath = await findUp(Object.keys(LOCKS), {
|
|
898
885
|
cwd
|
|
899
886
|
});
|
|
900
|
-
|
|
887
|
+
let lockBasename = lockPath ? path.basename(lockPath) : undefined;
|
|
888
|
+
const isHiddenLockFile = lockBasename === '.package-lock.json';
|
|
901
889
|
const pkgJsonPath = lockPath ? path.resolve(lockPath, `${isHiddenLockFile ? '../' : ''}../package.json`) : await findUp('package.json', {
|
|
902
890
|
cwd
|
|
903
891
|
});
|
|
@@ -922,20 +910,20 @@ async function detect({
|
|
|
922
910
|
}
|
|
923
911
|
}
|
|
924
912
|
}
|
|
925
|
-
if (agent === undefined && !isHiddenLockFile && typeof pkgJsonPath === 'string' && typeof
|
|
926
|
-
agent = LOCKS[
|
|
913
|
+
if (agent === undefined && !isHiddenLockFile && typeof pkgJsonPath === 'string' && typeof lockBasename === 'string') {
|
|
914
|
+
agent = LOCKS[lockBasename];
|
|
927
915
|
}
|
|
928
916
|
if (agent === undefined) {
|
|
929
|
-
agent =
|
|
917
|
+
agent = NPM$2;
|
|
930
918
|
onUnknown?.(pkgManager);
|
|
931
919
|
}
|
|
932
920
|
const agentExecPath = await getAgentExecPath(agent);
|
|
933
|
-
const npmExecPath = agent ===
|
|
921
|
+
const npmExecPath = agent === NPM$2 ? agentExecPath : await getAgentExecPath(NPM$2);
|
|
934
922
|
if (agentVersion === undefined) {
|
|
935
923
|
agentVersion = await getAgentVersion(agentExecPath, cwd);
|
|
936
924
|
}
|
|
937
|
-
if (agent ===
|
|
938
|
-
agent =
|
|
925
|
+
if (agent === YARN_CLASSIC$1 && (agentVersion?.major ?? 0) > 1) {
|
|
926
|
+
agent = YARN_BERRY$1;
|
|
939
927
|
}
|
|
940
928
|
const targets = {
|
|
941
929
|
browser: false,
|
|
@@ -943,7 +931,7 @@ async function detect({
|
|
|
943
931
|
};
|
|
944
932
|
let lockSrc;
|
|
945
933
|
// Lazily access constants.maintainedNodeVersions.
|
|
946
|
-
let minimumNodeVersion =
|
|
934
|
+
let minimumNodeVersion = constants.maintainedNodeVersions.previous;
|
|
947
935
|
if (pkgJson) {
|
|
948
936
|
const browserField = pkgJson.browser;
|
|
949
937
|
if (strings.isNonEmptyString(browserField) || objects.isObjectObject(browserField)) {
|
|
@@ -971,15 +959,17 @@ async function detect({
|
|
|
971
959
|
}
|
|
972
960
|
}
|
|
973
961
|
// Lazily access constants.maintainedNodeVersions.
|
|
974
|
-
targets.node =
|
|
962
|
+
targets.node = constants.maintainedNodeVersions.some(v => semver.satisfies(v, `>=${minimumNodeVersion}`));
|
|
975
963
|
lockSrc = typeof lockPath === 'string' ? await readLockFileByAgent[agent](lockPath, agentExecPath) : undefined;
|
|
976
964
|
} else {
|
|
965
|
+
lockBasename = undefined;
|
|
977
966
|
lockPath = undefined;
|
|
978
967
|
}
|
|
979
968
|
return {
|
|
980
969
|
agent,
|
|
981
970
|
agentExecPath,
|
|
982
971
|
agentVersion,
|
|
972
|
+
lockBasename,
|
|
983
973
|
lockPath,
|
|
984
974
|
lockSrc,
|
|
985
975
|
minimumNodeVersion,
|
|
@@ -992,7 +982,14 @@ async function detect({
|
|
|
992
982
|
}
|
|
993
983
|
|
|
994
984
|
const {
|
|
985
|
+
BUN,
|
|
986
|
+
LOCK_EXT,
|
|
987
|
+
NPM: NPM$1,
|
|
988
|
+
PNPM,
|
|
995
989
|
UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE,
|
|
990
|
+
VLT,
|
|
991
|
+
YARN_BERRY,
|
|
992
|
+
YARN_CLASSIC,
|
|
996
993
|
abortSignal: abortSignal$2,
|
|
997
994
|
execPath,
|
|
998
995
|
rootBinPath
|
|
@@ -1000,63 +997,68 @@ const {
|
|
|
1000
997
|
const COMMAND_TITLE = 'Socket Optimize';
|
|
1001
998
|
const OVERRIDES_FIELD_NAME = 'overrides';
|
|
1002
999
|
const NPM_OVERRIDE_PR_URL = 'https://github.com/npm/cli/pull/7025';
|
|
1003
|
-
const PNPM_FIELD_NAME =
|
|
1004
|
-
const PNPM_WORKSPACE =
|
|
1000
|
+
const PNPM_FIELD_NAME = PNPM;
|
|
1001
|
+
const PNPM_WORKSPACE = `${PNPM}-workspace`;
|
|
1005
1002
|
const RESOLUTIONS_FIELD_NAME = 'resolutions';
|
|
1006
|
-
const manifestNpmOverrides = registry.getManifestData(
|
|
1003
|
+
const manifestNpmOverrides = registry.getManifestData(NPM$1);
|
|
1007
1004
|
const getOverridesDataByAgent = {
|
|
1008
|
-
|
|
1005
|
+
[BUN](pkgJson) {
|
|
1009
1006
|
const overrides = pkgJson?.resolutions ?? {};
|
|
1010
1007
|
return {
|
|
1011
|
-
type:
|
|
1008
|
+
type: YARN_BERRY,
|
|
1012
1009
|
overrides
|
|
1013
1010
|
};
|
|
1014
1011
|
},
|
|
1015
1012
|
// npm overrides documentation:
|
|
1016
1013
|
// https://docs.npmjs.com/cli/v10/configuring-npm/package-json#overrides
|
|
1017
|
-
|
|
1014
|
+
[NPM$1](pkgJson) {
|
|
1018
1015
|
const overrides = pkgJson?.overrides ?? {};
|
|
1019
1016
|
return {
|
|
1020
|
-
type:
|
|
1017
|
+
type: NPM$1,
|
|
1021
1018
|
overrides
|
|
1022
1019
|
};
|
|
1023
1020
|
},
|
|
1024
1021
|
// pnpm overrides documentation:
|
|
1025
1022
|
// https://pnpm.io/package_json#pnpmoverrides
|
|
1026
|
-
|
|
1023
|
+
[PNPM](pkgJson) {
|
|
1027
1024
|
const overrides = pkgJson?.pnpm?.overrides ?? {};
|
|
1028
1025
|
return {
|
|
1029
|
-
type:
|
|
1026
|
+
type: PNPM,
|
|
1030
1027
|
overrides
|
|
1031
1028
|
};
|
|
1032
1029
|
},
|
|
1033
|
-
|
|
1030
|
+
[VLT](pkgJson) {
|
|
1034
1031
|
const overrides = pkgJson?.overrides ?? {};
|
|
1035
1032
|
return {
|
|
1036
|
-
type:
|
|
1033
|
+
type: VLT,
|
|
1037
1034
|
overrides
|
|
1038
1035
|
};
|
|
1039
1036
|
},
|
|
1040
1037
|
// Yarn resolutions documentation:
|
|
1041
1038
|
// https://yarnpkg.com/configuration/manifest#resolutions
|
|
1042
|
-
|
|
1039
|
+
[YARN_BERRY](pkgJson) {
|
|
1043
1040
|
const overrides = pkgJson?.resolutions ?? {};
|
|
1044
1041
|
return {
|
|
1045
|
-
type:
|
|
1042
|
+
type: YARN_BERRY,
|
|
1046
1043
|
overrides
|
|
1047
1044
|
};
|
|
1048
1045
|
},
|
|
1049
1046
|
// Yarn resolutions documentation:
|
|
1050
1047
|
// https://classic.yarnpkg.com/en/docs/selective-version-resolutions
|
|
1051
|
-
|
|
1048
|
+
[YARN_CLASSIC](pkgJson) {
|
|
1052
1049
|
const overrides = pkgJson?.resolutions ?? {};
|
|
1053
1050
|
return {
|
|
1054
|
-
type:
|
|
1051
|
+
type: YARN_CLASSIC,
|
|
1055
1052
|
overrides
|
|
1056
1053
|
};
|
|
1057
1054
|
}
|
|
1058
1055
|
};
|
|
1059
1056
|
const lockIncludesByAgent = (() => {
|
|
1057
|
+
function npmLockIncludes(lockSrc, name) {
|
|
1058
|
+
// Detects the package name in the following cases:
|
|
1059
|
+
// "name":
|
|
1060
|
+
return lockSrc.includes(`"${name}":`);
|
|
1061
|
+
}
|
|
1060
1062
|
function yarnLockIncludes(lockSrc, name) {
|
|
1061
1063
|
const escapedName = regexps.escapeRegExp(name);
|
|
1062
1064
|
return new RegExp(
|
|
@@ -1068,13 +1070,16 @@ const lockIncludesByAgent = (() => {
|
|
|
1068
1070
|
`(?<=(?:^\\s*|,\\s*)"?)${escapedName}(?=@)`, 'm').test(lockSrc);
|
|
1069
1071
|
}
|
|
1070
1072
|
return {
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
//
|
|
1074
|
-
//
|
|
1075
|
-
|
|
1073
|
+
[BUN](lockSrc, name, lockBasename) {
|
|
1074
|
+
// This is a bit counterintuitive. When lockBasename ends with a .lockb
|
|
1075
|
+
// we treat it as a yarn.lock. When lockBasename ends with a .lock we
|
|
1076
|
+
// treat it as a package-lock.json. The bun.lock format is not identical
|
|
1077
|
+
// package-lock.json, however it close enough for npmLockIncludes to work.
|
|
1078
|
+
const lockScanner = lockBasename?.endsWith(LOCK_EXT) ? npmLockIncludes : yarnLockIncludes;
|
|
1079
|
+
return lockScanner(lockSrc, name);
|
|
1076
1080
|
},
|
|
1077
|
-
|
|
1081
|
+
[NPM$1]: npmLockIncludes,
|
|
1082
|
+
[PNPM](lockSrc, name) {
|
|
1078
1083
|
const escapedName = regexps.escapeRegExp(name);
|
|
1079
1084
|
return new RegExp(
|
|
1080
1085
|
// Detects the package name in the following cases:
|
|
@@ -1084,13 +1089,13 @@ const lockIncludesByAgent = (() => {
|
|
|
1084
1089
|
// name@
|
|
1085
1090
|
`(?<=^\\s*)(?:(['/])${escapedName}\\1|${escapedName}(?=[:@]))`, 'm').test(lockSrc);
|
|
1086
1091
|
},
|
|
1087
|
-
|
|
1092
|
+
[VLT](lockSrc, name) {
|
|
1088
1093
|
// Detects the package name in the following cases:
|
|
1089
1094
|
// "name"
|
|
1090
1095
|
return lockSrc.includes(`"${name}"`);
|
|
1091
1096
|
},
|
|
1092
|
-
|
|
1093
|
-
|
|
1097
|
+
[YARN_BERRY]: yarnLockIncludes,
|
|
1098
|
+
[YARN_CLASSIC]: yarnLockIncludes
|
|
1094
1099
|
};
|
|
1095
1100
|
})();
|
|
1096
1101
|
const updateManifestByAgent = (() => {
|
|
@@ -1150,16 +1155,16 @@ const updateManifestByAgent = (() => {
|
|
|
1150
1155
|
let insertIndex = -1;
|
|
1151
1156
|
let isPlacingHigher = false;
|
|
1152
1157
|
if (field === OVERRIDES_FIELD_NAME) {
|
|
1153
|
-
insertIndex = getLowestEntryIndex(entries, [
|
|
1158
|
+
insertIndex = getLowestEntryIndex(entries, [RESOLUTIONS_FIELD_NAME]);
|
|
1154
1159
|
if (insertIndex === -1) {
|
|
1155
1160
|
isPlacingHigher = true;
|
|
1156
|
-
insertIndex = getHighestEntryIndex(entries, [...depFields,
|
|
1161
|
+
insertIndex = getHighestEntryIndex(entries, [...depFields, PNPM]);
|
|
1157
1162
|
}
|
|
1158
1163
|
} else if (field === RESOLUTIONS_FIELD_NAME) {
|
|
1159
1164
|
isPlacingHigher = true;
|
|
1160
|
-
insertIndex = getHighestEntryIndex(entries, [...depFields,
|
|
1165
|
+
insertIndex = getHighestEntryIndex(entries, [...depFields, OVERRIDES_FIELD_NAME, PNPM]);
|
|
1161
1166
|
} else if (field === PNPM_FIELD_NAME) {
|
|
1162
|
-
insertIndex = getLowestEntryIndex(entries, [
|
|
1167
|
+
insertIndex = getLowestEntryIndex(entries, [OVERRIDES_FIELD_NAME, RESOLUTIONS_FIELD_NAME]);
|
|
1163
1168
|
if (insertIndex === -1) {
|
|
1164
1169
|
isPlacingHigher = true;
|
|
1165
1170
|
insertIndex = getHighestEntryIndex(entries, depFields);
|
|
@@ -1187,14 +1192,14 @@ const updateManifestByAgent = (() => {
|
|
|
1187
1192
|
updatePkgJson(editablePkgJson, RESOLUTIONS_FIELD_NAME, overrides);
|
|
1188
1193
|
}
|
|
1189
1194
|
return {
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1195
|
+
[BUN]: updateResolutions,
|
|
1196
|
+
[NPM$1]: updateOverrides,
|
|
1197
|
+
[PNPM](editablePkgJson, overrides) {
|
|
1193
1198
|
updatePkgJson(editablePkgJson, PNPM_FIELD_NAME, overrides);
|
|
1194
1199
|
},
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1200
|
+
[VLT]: updateOverrides,
|
|
1201
|
+
[YARN_BERRY]: updateResolutions,
|
|
1202
|
+
[YARN_CLASSIC]: updateResolutions
|
|
1198
1203
|
};
|
|
1199
1204
|
})();
|
|
1200
1205
|
const lsByAgent = (() => {
|
|
@@ -1248,7 +1253,7 @@ const lsByAgent = (() => {
|
|
|
1248
1253
|
return cleanupQueryStdout(stdout);
|
|
1249
1254
|
}
|
|
1250
1255
|
return {
|
|
1251
|
-
async
|
|
1256
|
+
async [BUN](agentExecPath, cwd) {
|
|
1252
1257
|
try {
|
|
1253
1258
|
// Bun does not support filtering by production packages yet.
|
|
1254
1259
|
// https://github.com/oven-sh/bun/issues/8283
|
|
@@ -1258,17 +1263,17 @@ const lsByAgent = (() => {
|
|
|
1258
1263
|
} catch {}
|
|
1259
1264
|
return '';
|
|
1260
1265
|
},
|
|
1261
|
-
async
|
|
1266
|
+
async [NPM$1](agentExecPath, cwd) {
|
|
1262
1267
|
return await npmQuery(agentExecPath, cwd);
|
|
1263
1268
|
},
|
|
1264
|
-
async
|
|
1269
|
+
async [PNPM](agentExecPath, cwd, options) {
|
|
1265
1270
|
const {
|
|
1266
1271
|
npmExecPath
|
|
1267
1272
|
} = {
|
|
1268
1273
|
__proto__: null,
|
|
1269
1274
|
...options
|
|
1270
1275
|
};
|
|
1271
|
-
if (npmExecPath && npmExecPath !==
|
|
1276
|
+
if (npmExecPath && npmExecPath !== NPM$1) {
|
|
1272
1277
|
const result = await npmQuery(npmExecPath, cwd);
|
|
1273
1278
|
if (result) {
|
|
1274
1279
|
return result;
|
|
@@ -1282,7 +1287,7 @@ const lsByAgent = (() => {
|
|
|
1282
1287
|
} catch {}
|
|
1283
1288
|
return parseableToQueryStdout(stdout);
|
|
1284
1289
|
},
|
|
1285
|
-
async
|
|
1290
|
+
async [VLT](agentExecPath, cwd) {
|
|
1286
1291
|
let stdout = '';
|
|
1287
1292
|
try {
|
|
1288
1293
|
stdout = (await spawn(agentExecPath, ['ls', '--view', 'human', ':not(.dev)'], {
|
|
@@ -1291,7 +1296,7 @@ const lsByAgent = (() => {
|
|
|
1291
1296
|
} catch {}
|
|
1292
1297
|
return cleanupQueryStdout(stdout);
|
|
1293
1298
|
},
|
|
1294
|
-
async
|
|
1299
|
+
async [YARN_BERRY](agentExecPath, cwd) {
|
|
1295
1300
|
try {
|
|
1296
1301
|
return (
|
|
1297
1302
|
// Yarn Berry does not support filtering by production packages yet.
|
|
@@ -1303,7 +1308,7 @@ const lsByAgent = (() => {
|
|
|
1303
1308
|
} catch {}
|
|
1304
1309
|
return '';
|
|
1305
1310
|
},
|
|
1306
|
-
async
|
|
1311
|
+
async [YARN_CLASSIC](agentExecPath, cwd) {
|
|
1307
1312
|
try {
|
|
1308
1313
|
// However, Yarn Classic does support it.
|
|
1309
1314
|
// https://github.com/yarnpkg/yarn/releases/tag/v1.0.0
|
|
@@ -1325,12 +1330,12 @@ const depsIncludesByAgent = (() => {
|
|
|
1325
1330
|
return stdout.includes(`"${name}"`);
|
|
1326
1331
|
}
|
|
1327
1332
|
return {
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1333
|
+
[BUN]: matchHumanStdout,
|
|
1334
|
+
[NPM$1]: matchQueryStdout,
|
|
1335
|
+
[PNPM]: matchQueryStdout,
|
|
1336
|
+
[VLT]: matchQueryStdout,
|
|
1337
|
+
[YARN_BERRY]: matchHumanStdout,
|
|
1338
|
+
[YARN_CLASSIC]: matchHumanStdout
|
|
1334
1339
|
};
|
|
1335
1340
|
})();
|
|
1336
1341
|
function createActionMessage(verb, overrideCount, workspaceCount) {
|
|
@@ -1361,7 +1366,7 @@ function getDependencyEntries(pkgJson) {
|
|
|
1361
1366
|
}
|
|
1362
1367
|
async function getWorkspaceGlobs(agent, pkgPath, pkgJson) {
|
|
1363
1368
|
let workspacePatterns;
|
|
1364
|
-
if (agent ===
|
|
1369
|
+
if (agent === PNPM) {
|
|
1365
1370
|
for (const workspacePath of [path.join(pkgPath, `${PNPM_WORKSPACE}.yaml`), path.join(pkgPath, `${PNPM_WORKSPACE}.yml`)]) {
|
|
1366
1371
|
if (existsSync(workspacePath)) {
|
|
1367
1372
|
try {
|
|
@@ -1411,6 +1416,7 @@ function createAddOverridesState(initials) {
|
|
|
1411
1416
|
async function addOverrides({
|
|
1412
1417
|
agent,
|
|
1413
1418
|
agentExecPath,
|
|
1419
|
+
lockBasename,
|
|
1414
1420
|
lockSrc,
|
|
1415
1421
|
manifestEntries,
|
|
1416
1422
|
npmExecPath,
|
|
@@ -1436,20 +1442,24 @@ async function addOverrides({
|
|
|
1436
1442
|
const workspaceName = path.relative(rootPath, pkgPath);
|
|
1437
1443
|
const workspaceGlobs = await getWorkspaceGlobs(agent, pkgPath, pkgJson);
|
|
1438
1444
|
const isWorkspace = !!workspaceGlobs;
|
|
1439
|
-
if (isWorkspace && agent ===
|
|
1445
|
+
if (isWorkspace && agent === PNPM && npmExecPath === NPM$1 && !state.warnedPnpmWorkspaceRequiresNpm) {
|
|
1440
1446
|
state.warnedPnpmWorkspaceRequiresNpm = true;
|
|
1441
1447
|
console.warn(`⚠️ ${COMMAND_TITLE}: pnpm workspace support requires \`npm ls\`, falling back to \`pnpm list\``);
|
|
1442
1448
|
}
|
|
1443
1449
|
const thingToScan = isLockScanned ? lockSrc : await lsByAgent[agent](agentExecPath, pkgPath, {
|
|
1444
1450
|
npmExecPath
|
|
1445
1451
|
});
|
|
1452
|
+
// The AgentDepsIncludesFn and AgentLockIncludesFn types overlap in their
|
|
1453
|
+
// first two parameters. AgentLockIncludesFn accepts an optional third
|
|
1454
|
+
// parameter which AgentDepsIncludesFn will ignore so we cast thingScanner
|
|
1455
|
+
// as an AgentLockIncludesFn type.
|
|
1446
1456
|
const thingScanner = isLockScanned ? lockIncludesByAgent[agent] : depsIncludesByAgent[agent];
|
|
1447
1457
|
const depEntries = getDependencyEntries(pkgJson);
|
|
1448
1458
|
const overridesDataObjects = [];
|
|
1449
1459
|
if (pkgJson['private'] || isWorkspace) {
|
|
1450
1460
|
overridesDataObjects.push(getOverridesDataByAgent[agent](pkgJson));
|
|
1451
1461
|
} else {
|
|
1452
|
-
overridesDataObjects.push(getOverridesDataByAgent
|
|
1462
|
+
overridesDataObjects.push(getOverridesDataByAgent[NPM$1](pkgJson), getOverridesDataByAgent[YARN_CLASSIC](pkgJson));
|
|
1453
1463
|
}
|
|
1454
1464
|
if (spinner) {
|
|
1455
1465
|
spinner.text = `Adding overrides${workspaceName ? ` to ${workspaceName}` : ''}...`;
|
|
@@ -1498,13 +1508,13 @@ async function addOverrides({
|
|
|
1498
1508
|
type
|
|
1499
1509
|
}) => {
|
|
1500
1510
|
const overrideExists = objects.hasOwn(overrides, origPkgName);
|
|
1501
|
-
if (overrideExists || thingScanner(thingToScan, origPkgName)) {
|
|
1511
|
+
if (overrideExists || thingScanner(thingToScan, origPkgName, lockBasename)) {
|
|
1502
1512
|
const oldSpec = overrideExists ? overrides[origPkgName] : undefined;
|
|
1503
1513
|
const depAlias = depAliasMap.get(origPkgName);
|
|
1504
|
-
const regSpecStartsLike =
|
|
1514
|
+
const regSpecStartsLike = `${NPM$1}:${regPkgName}@`;
|
|
1505
1515
|
let newSpec = `${regSpecStartsLike}^${pin ? version : major}`;
|
|
1506
1516
|
let thisVersion = version;
|
|
1507
|
-
if (depAlias && type ===
|
|
1517
|
+
if (depAlias && type === NPM$1) {
|
|
1508
1518
|
// With npm one may not set an override for a package that one directly
|
|
1509
1519
|
// depends on unless both the dependency and the override itself share
|
|
1510
1520
|
// the exact same spec. To make this limitation easier to deal with,
|
|
@@ -1528,10 +1538,6 @@ async function addOverrides({
|
|
|
1528
1538
|
overrides[origPkgName] = newSpec;
|
|
1529
1539
|
const addedOrUpdated = overrideExists ? 'updated' : 'added';
|
|
1530
1540
|
state[addedOrUpdated].add(regPkgName);
|
|
1531
|
-
if (workspaceName) {
|
|
1532
|
-
const addedOrUpdatedIn = overrideExists ? 'updatedInWorkspaces' : 'addedInWorkspaces';
|
|
1533
|
-
state[addedOrUpdatedIn].add(workspaceName);
|
|
1534
|
-
}
|
|
1535
1541
|
}
|
|
1536
1542
|
}
|
|
1537
1543
|
});
|
|
@@ -1548,6 +1554,7 @@ async function addOverrides({
|
|
|
1548
1554
|
const otherState = await addOverrides({
|
|
1549
1555
|
agent,
|
|
1550
1556
|
agentExecPath,
|
|
1557
|
+
lockBasename,
|
|
1551
1558
|
lockSrc,
|
|
1552
1559
|
manifestEntries,
|
|
1553
1560
|
npmExecPath,
|
|
@@ -1595,6 +1602,7 @@ const optimize = {
|
|
|
1595
1602
|
agent,
|
|
1596
1603
|
agentExecPath,
|
|
1597
1604
|
agentVersion,
|
|
1605
|
+
lockBasename,
|
|
1598
1606
|
lockPath,
|
|
1599
1607
|
lockSrc,
|
|
1600
1608
|
minimumNodeVersion,
|
|
@@ -1612,12 +1620,12 @@ const optimize = {
|
|
|
1612
1620
|
console.error(`✖️ ${COMMAND_TITLE}: No supported Node or browser range detected`);
|
|
1613
1621
|
return;
|
|
1614
1622
|
}
|
|
1615
|
-
if (agent ===
|
|
1623
|
+
if (agent === VLT) {
|
|
1616
1624
|
console.error(`✖️ ${COMMAND_TITLE}: ${agent} does not support overrides. Soon, though ⚡`);
|
|
1617
1625
|
return;
|
|
1618
1626
|
}
|
|
1619
|
-
const lockName = lockPath ?
|
|
1620
|
-
if (lockSrc === undefined) {
|
|
1627
|
+
const lockName = lockPath ? lockBasename : 'lock file';
|
|
1628
|
+
if (lockBasename === undefined || lockSrc === undefined) {
|
|
1621
1629
|
console.error(`✖️ ${COMMAND_TITLE}: No ${lockName} found`);
|
|
1622
1630
|
return;
|
|
1623
1631
|
}
|
|
@@ -1629,7 +1637,7 @@ const optimize = {
|
|
|
1629
1637
|
console.error(`✖️ ${COMMAND_TITLE}: No package.json found`);
|
|
1630
1638
|
return;
|
|
1631
1639
|
}
|
|
1632
|
-
if (prod && (agent ===
|
|
1640
|
+
if (prod && (agent === BUN || agent === YARN_BERRY)) {
|
|
1633
1641
|
console.error(`✖️ ${COMMAND_TITLE}: --prod not supported for ${agent}${agentVersion ? `@${agentVersion.toString()}` : ''}`);
|
|
1634
1642
|
return;
|
|
1635
1643
|
}
|
|
@@ -1650,6 +1658,7 @@ const optimize = {
|
|
|
1650
1658
|
await addOverrides({
|
|
1651
1659
|
agent,
|
|
1652
1660
|
agentExecPath,
|
|
1661
|
+
lockBasename,
|
|
1653
1662
|
lockSrc,
|
|
1654
1663
|
manifestEntries,
|
|
1655
1664
|
npmExecPath,
|
|
@@ -1673,7 +1682,7 @@ const optimize = {
|
|
|
1673
1682
|
} else {
|
|
1674
1683
|
console.log('Congratulations! Already Socket.dev optimized 🎉');
|
|
1675
1684
|
}
|
|
1676
|
-
const isNpm = agent ===
|
|
1685
|
+
const isNpm = agent === NPM$1;
|
|
1677
1686
|
if (isNpm || pkgJsonChanged) {
|
|
1678
1687
|
// Always update package-lock.json until the npm overrides PR lands:
|
|
1679
1688
|
// https://github.com/npm/cli/pull/7025
|
|
@@ -1806,14 +1815,16 @@ Plan: ${o?.plan}
|
|
|
1806
1815
|
}
|
|
1807
1816
|
|
|
1808
1817
|
const {
|
|
1818
|
+
NPM,
|
|
1809
1819
|
abortSignal: abortSignal$1
|
|
1810
1820
|
} = constants;
|
|
1821
|
+
const binName$1 = NPM;
|
|
1811
1822
|
const rawNpm = {
|
|
1812
|
-
description:
|
|
1823
|
+
description: `Temporarily disable the Socket ${binName$1} wrapper`,
|
|
1813
1824
|
async run(argv, importMeta, {
|
|
1814
1825
|
parentName
|
|
1815
1826
|
}) {
|
|
1816
|
-
await setupCommand$j(`${parentName} raw
|
|
1827
|
+
await setupCommand$j(`${parentName} raw-${binName$1}`, rawNpm.description, argv, importMeta);
|
|
1817
1828
|
}
|
|
1818
1829
|
};
|
|
1819
1830
|
async function setupCommand$j(name, description, argv, importMeta) {
|
|
@@ -1823,7 +1834,7 @@ async function setupCommand$j(name, description, argv, importMeta) {
|
|
|
1823
1834
|
};
|
|
1824
1835
|
const cli = vendor.meow(`
|
|
1825
1836
|
Usage
|
|
1826
|
-
$ ${name}
|
|
1837
|
+
$ ${name} <${binName$1} command>
|
|
1827
1838
|
|
|
1828
1839
|
Options
|
|
1829
1840
|
${printFlagList(flags, 6)}
|
|
@@ -1844,13 +1855,26 @@ async function setupCommand$j(name, description, argv, importMeta) {
|
|
|
1844
1855
|
cli.showHelp();
|
|
1845
1856
|
return;
|
|
1846
1857
|
}
|
|
1847
|
-
const
|
|
1858
|
+
const {
|
|
1859
|
+
path: binPath
|
|
1860
|
+
} = await pathResolve.findBinPathDetails(binName$1);
|
|
1861
|
+
if (!binPath) {
|
|
1862
|
+
// The exit code 127 indicates that the command or binary being executed
|
|
1863
|
+
// could not be found.
|
|
1864
|
+
console.error(`Socket unable to locate ${binName$1}; ensure it is available in the PATH environment variable.`);
|
|
1865
|
+
process.exit(127);
|
|
1866
|
+
}
|
|
1867
|
+
const spawnPromise = spawn(binPath, argv, {
|
|
1848
1868
|
signal: abortSignal$1,
|
|
1849
1869
|
stdio: 'inherit'
|
|
1850
1870
|
});
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1871
|
+
// See https://nodejs.org/api/all.html#all_child_process_event-exit.
|
|
1872
|
+
spawnPromise.process.on('exit', (code, signalName) => {
|
|
1873
|
+
if (abortSignal$1.aborted) {
|
|
1874
|
+
return;
|
|
1875
|
+
}
|
|
1876
|
+
if (signalName) {
|
|
1877
|
+
process.kill(process.pid, signalName);
|
|
1854
1878
|
} else if (code !== null) {
|
|
1855
1879
|
process.exit(code);
|
|
1856
1880
|
}
|
|
@@ -1859,14 +1883,16 @@ async function setupCommand$j(name, description, argv, importMeta) {
|
|
|
1859
1883
|
}
|
|
1860
1884
|
|
|
1861
1885
|
const {
|
|
1886
|
+
NPX,
|
|
1862
1887
|
abortSignal
|
|
1863
1888
|
} = constants;
|
|
1889
|
+
const binName = NPX;
|
|
1864
1890
|
const rawNpx = {
|
|
1865
|
-
description:
|
|
1891
|
+
description: `Temporarily disable the Socket ${binName} wrapper`,
|
|
1866
1892
|
async run(argv, importMeta, {
|
|
1867
1893
|
parentName
|
|
1868
1894
|
}) {
|
|
1869
|
-
await setupCommand$i(`${parentName} raw
|
|
1895
|
+
await setupCommand$i(`${parentName} raw-${binName}`, rawNpx.description, argv, importMeta);
|
|
1870
1896
|
}
|
|
1871
1897
|
};
|
|
1872
1898
|
async function setupCommand$i(name, description, argv, importMeta) {
|
|
@@ -1876,7 +1902,7 @@ async function setupCommand$i(name, description, argv, importMeta) {
|
|
|
1876
1902
|
};
|
|
1877
1903
|
const cli = vendor.meow(`
|
|
1878
1904
|
Usage
|
|
1879
|
-
$ ${name}
|
|
1905
|
+
$ ${name} <${binName} command>
|
|
1880
1906
|
|
|
1881
1907
|
Options
|
|
1882
1908
|
${printFlagList(flags, 6)}
|
|
@@ -1897,13 +1923,26 @@ async function setupCommand$i(name, description, argv, importMeta) {
|
|
|
1897
1923
|
cli.showHelp();
|
|
1898
1924
|
return;
|
|
1899
1925
|
}
|
|
1900
|
-
const
|
|
1926
|
+
const {
|
|
1927
|
+
path: binPath
|
|
1928
|
+
} = await pathResolve.findBinPathDetails(binName);
|
|
1929
|
+
if (!binPath) {
|
|
1930
|
+
// The exit code 127 indicates that the command or binary being executed
|
|
1931
|
+
// could not be found.
|
|
1932
|
+
console.error(`Socket unable to locate ${binName}; ensure it is available in the PATH environment variable.`);
|
|
1933
|
+
process.exit(127);
|
|
1934
|
+
}
|
|
1935
|
+
const spawnPromise = spawn(binPath, argv, {
|
|
1901
1936
|
signal: abortSignal,
|
|
1902
1937
|
stdio: 'inherit'
|
|
1903
1938
|
});
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1939
|
+
// See https://nodejs.org/api/all.html#all_child_process_event-exit.
|
|
1940
|
+
spawnPromise.process.on('exit', (code, signalName) => {
|
|
1941
|
+
if (abortSignal.aborted) {
|
|
1942
|
+
return;
|
|
1943
|
+
}
|
|
1944
|
+
if (signalName) {
|
|
1945
|
+
process.kill(process.pid, signalName);
|
|
1907
1946
|
} else if (code !== null) {
|
|
1908
1947
|
process.exit(code);
|
|
1909
1948
|
}
|
|
@@ -3693,7 +3732,7 @@ const dependencies = {
|
|
|
3693
3732
|
}) {
|
|
3694
3733
|
const name = parentName + ' dependencies';
|
|
3695
3734
|
const input = setupCommand$3(name, dependencies.description, argv, importMeta);
|
|
3696
|
-
|
|
3735
|
+
{
|
|
3697
3736
|
await searchDeps(input);
|
|
3698
3737
|
}
|
|
3699
3738
|
}
|
|
@@ -4262,7 +4301,7 @@ const threatFeed = {
|
|
|
4262
4301
|
}) {
|
|
4263
4302
|
const name = `${parentName} threat-feed`;
|
|
4264
4303
|
const input = setupCommand(name, threatFeed.description, argv, importMeta);
|
|
4265
|
-
|
|
4304
|
+
{
|
|
4266
4305
|
const apiKey = sdk.getDefaultKey();
|
|
4267
4306
|
if (!apiKey) {
|
|
4268
4307
|
throw new sdk.AuthError('User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.');
|