@socketsecurity/cli 0.14.20 → 0.14.22
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/README.md +2 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +367 -399
- package/dist/link.js +2 -2
- package/dist/npm-cli.js +7 -7
- package/dist/npm-injection.js +238 -122
- package/dist/path-resolve.js +3 -3
- package/dist/sdk.d.ts +1 -10
- package/dist/sdk.js +5 -51
- package/dist/vendor.js +1673 -2374
- package/package.json +21 -35
- package/dist/vendor.d.ts +0 -0
package/dist/cli.js
CHANGED
|
@@ -14,24 +14,23 @@ var require$$1$4 = require('node:fs/promises');
|
|
|
14
14
|
var require$$1$3 = require('@npmcli/package-json');
|
|
15
15
|
var require$$5$1 = require('@socketsecurity/registry');
|
|
16
16
|
var require$$7 = require('npm-package-arg');
|
|
17
|
-
var require$$0$1 = require('pacote');
|
|
18
17
|
var require$$3 = require('semver');
|
|
19
|
-
var require$$
|
|
20
|
-
var require$$
|
|
18
|
+
var require$$10$1 = require('tinyglobby');
|
|
19
|
+
var require$$11 = require('yaml');
|
|
21
20
|
var require$$2 = require('@socketregistry/hyrious__bun.lockb');
|
|
22
|
-
var require$$
|
|
23
|
-
var require$$
|
|
21
|
+
var require$$10 = require('browserslist');
|
|
22
|
+
var require$$8 = require('which');
|
|
24
23
|
var require$$2$1 = require('@apideck/better-ajv-errors');
|
|
25
24
|
var require$$3$1 = require('@socketsecurity/config');
|
|
26
25
|
var pathResolve = require('./path-resolve.js');
|
|
27
26
|
var require$$2$2 = require('node:os');
|
|
28
27
|
var require$$3$2 = require('node:readline');
|
|
29
|
-
var require$$0$
|
|
28
|
+
var require$$0$1 = require('node:process');
|
|
30
29
|
var require$$2$3 = require('node:readline/promises');
|
|
31
30
|
var require$$2$4 = require('chalk-table');
|
|
32
31
|
var require$$2$5 = require('blessed');
|
|
33
32
|
var require$$3$3 = require('blessed-contrib');
|
|
34
|
-
var require$$0$
|
|
33
|
+
var require$$0$2 = require('node:util');
|
|
35
34
|
|
|
36
35
|
var cli$1 = {};
|
|
37
36
|
|
|
@@ -325,13 +324,36 @@ async function queryAPI(path, apiKey) {
|
|
|
325
324
|
|
|
326
325
|
var formatIssues = {};
|
|
327
326
|
|
|
327
|
+
var objects = {};
|
|
328
|
+
|
|
329
|
+
Object.defineProperty(objects, "__esModule", {
|
|
330
|
+
value: true
|
|
331
|
+
});
|
|
332
|
+
objects.objectSome = objectSome;
|
|
333
|
+
objects.pick = pick;
|
|
334
|
+
function objectSome(obj) {
|
|
335
|
+
for (const key in obj) {
|
|
336
|
+
if (obj[key]) {
|
|
337
|
+
return true;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
return false;
|
|
341
|
+
}
|
|
342
|
+
function pick(input, keys) {
|
|
343
|
+
const result = {};
|
|
344
|
+
for (const key of keys) {
|
|
345
|
+
result[key] = input[key];
|
|
346
|
+
}
|
|
347
|
+
return result;
|
|
348
|
+
}
|
|
349
|
+
|
|
328
350
|
Object.defineProperty(formatIssues, "__esModule", {
|
|
329
351
|
value: true
|
|
330
352
|
});
|
|
331
353
|
formatIssues.formatSeverityCount = formatSeverityCount;
|
|
332
354
|
formatIssues.getSeverityCount = getSeverityCount;
|
|
333
355
|
var _misc$2 = sdk.misc;
|
|
334
|
-
var _objects$
|
|
356
|
+
var _objects$4 = objects;
|
|
335
357
|
const SEVERITIES_BY_ORDER = ['critical', 'high', 'middle', 'low'];
|
|
336
358
|
function getDesiredSeverities(lowestToInclude) {
|
|
337
359
|
const result = [];
|
|
@@ -353,7 +375,7 @@ function formatSeverityCount(severityCount) {
|
|
|
353
375
|
return (0, _misc$2.stringJoinWithSeparateFinalSeparator)(summary);
|
|
354
376
|
}
|
|
355
377
|
function getSeverityCount(issues, lowestToInclude) {
|
|
356
|
-
const severityCount = (0, _objects$
|
|
378
|
+
const severityCount = (0, _objects$4.pick)({
|
|
357
379
|
low: 0,
|
|
358
380
|
middle: 0,
|
|
359
381
|
high: 0,
|
|
@@ -417,7 +439,7 @@ var _chalkMarkdown$3 = sdk.chalkMarkdown;
|
|
|
417
439
|
var _errors$k = sdk.errors;
|
|
418
440
|
var _formatIssues$1 = formatIssues;
|
|
419
441
|
var _formatting$m = formatting;
|
|
420
|
-
var _objects$
|
|
442
|
+
var _objects$3 = objects;
|
|
421
443
|
var _sdk$j = sdk.sdk;
|
|
422
444
|
const info = info$1.info = {
|
|
423
445
|
description: 'Look up info regarding a package',
|
|
@@ -511,8 +533,8 @@ async function fetchPackageData(pkgName, pkgVersion, {
|
|
|
511
533
|
}
|
|
512
534
|
function formatPackageDataOutput({
|
|
513
535
|
data,
|
|
514
|
-
|
|
515
|
-
|
|
536
|
+
score,
|
|
537
|
+
severityCount
|
|
516
538
|
}, {
|
|
517
539
|
name,
|
|
518
540
|
outputJson,
|
|
@@ -533,7 +555,7 @@ function formatPackageDataOutput({
|
|
|
533
555
|
License: Math.floor(score.license.score * 100)
|
|
534
556
|
};
|
|
535
557
|
Object.entries(scoreResult).map(score => console.log(`- ${score[0]}: ${formatScore(score[1])}`));
|
|
536
|
-
if ((0, _objects$
|
|
558
|
+
if ((0, _objects$3.objectSome)(severityCount)) {
|
|
537
559
|
const issueSummary = (0, _formatIssues$1.formatSeverityCount)(severityCount);
|
|
538
560
|
console.log('\n');
|
|
539
561
|
spinner[strict ? 'fail' : 'succeed'](`Package has these issues: ${issueSummary}`);
|
|
@@ -557,7 +579,7 @@ function formatPackageDataOutput({
|
|
|
557
579
|
console.log(_chalk$h.default.dim('\nOr rerun', _chalk$h.default.italic(name), 'using the', _chalk$h.default.italic('--json'), 'flag to get full JSON output'));
|
|
558
580
|
}
|
|
559
581
|
}
|
|
560
|
-
if (strict && (0, _objects$
|
|
582
|
+
if (strict && (0, _objects$3.objectSome)(severityCount)) {
|
|
561
583
|
process.exit(1);
|
|
562
584
|
}
|
|
563
585
|
}
|
|
@@ -890,16 +912,6 @@ async function readFileUtf8(filepath, options) {
|
|
|
890
912
|
|
|
891
913
|
var packageManagerDetector = {};
|
|
892
914
|
|
|
893
|
-
var strings = {};
|
|
894
|
-
|
|
895
|
-
Object.defineProperty(strings, "__esModule", {
|
|
896
|
-
value: true
|
|
897
|
-
});
|
|
898
|
-
strings.isNonEmptyString = isNonEmptyString;
|
|
899
|
-
function isNonEmptyString(value) {
|
|
900
|
-
return typeof value === 'string' && value.length > 0;
|
|
901
|
-
}
|
|
902
|
-
|
|
903
915
|
Object.defineProperty(packageManagerDetector, "__esModule", {
|
|
904
916
|
value: true
|
|
905
917
|
});
|
|
@@ -909,56 +921,48 @@ var _nodePath$3 = require$$1;
|
|
|
909
921
|
var _packageJson$1 = require$$1$3;
|
|
910
922
|
var _hyrious__bun = require$$2;
|
|
911
923
|
var _promiseSpawn$3 = require$$1$1;
|
|
912
|
-
var _browserslist = require$$
|
|
924
|
+
var _browserslist = require$$10;
|
|
913
925
|
var _semver$1 = require$$3;
|
|
914
|
-
var _which = require$$
|
|
926
|
+
var _which = require$$8;
|
|
927
|
+
var _constants = vendor.constants_1;
|
|
928
|
+
var _objects$2 = vendor.objects;
|
|
929
|
+
var _strings$1 = vendor.strings;
|
|
915
930
|
var _fs$1 = fs;
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
931
|
+
const AGENTS = packageManagerDetector.AGENTS = ['bun', 'npm', 'pnpm', 'yarn/berry', 'yarn/classic', 'vlt'];
|
|
932
|
+
const {
|
|
933
|
+
compare: alphaNumericComparator
|
|
934
|
+
} = new Intl.Collator(undefined, {
|
|
920
935
|
numeric: true,
|
|
921
936
|
sensitivity: 'base'
|
|
922
937
|
});
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
const queryPrev = query.at(0) ?? manualPrev;
|
|
940
|
-
const queryCurr = query.at(1) ?? manualCurr;
|
|
941
|
-
const queryNext = query.at(2) ?? manualNext;
|
|
942
|
-
const previous = _semver$1.maxSatisfying([queryPrev, manualPrev], `^${_semver$1.major(queryPrev)}`);
|
|
943
|
-
const current = _semver$1.maxSatisfying([queryCurr, manualCurr], `^${_semver$1.major(queryCurr)}`);
|
|
944
|
-
const next = _semver$1.maxSatisfying([queryNext, manualNext], `^${_semver$1.major(queryNext)}`);
|
|
945
|
-
return Object.freeze(Object.assign([previous, current, next], {
|
|
946
|
-
previous,
|
|
947
|
-
current,
|
|
948
|
-
next
|
|
949
|
-
}));
|
|
950
|
-
})();
|
|
938
|
+
async function getAgentExecPath(agent) {
|
|
939
|
+
return (await _which(agent, {
|
|
940
|
+
nothrow: true
|
|
941
|
+
})) ?? agent;
|
|
942
|
+
}
|
|
943
|
+
async function getAgentVersion(agentExecPath, cwd) {
|
|
944
|
+
let result;
|
|
945
|
+
try {
|
|
946
|
+
result = _semver$1.coerce(
|
|
947
|
+
// All package managers support the "--version" flag.
|
|
948
|
+
(await _promiseSpawn$3(agentExecPath, ['--version'], {
|
|
949
|
+
cwd
|
|
950
|
+
})).stdout) ?? undefined;
|
|
951
|
+
} catch {}
|
|
952
|
+
return result;
|
|
953
|
+
}
|
|
951
954
|
const LOCKS = {
|
|
952
955
|
'bun.lockb': 'bun',
|
|
953
|
-
'pnpm-lock.yaml': 'pnpm',
|
|
954
|
-
'pnpm-lock.yml': 'pnpm',
|
|
955
|
-
'yarn.lock': 'yarn/classic',
|
|
956
956
|
// If both package-lock.json and npm-shrinkwrap.json are present in the root
|
|
957
957
|
// of a project, npm-shrinkwrap.json will take precedence and package-lock.json
|
|
958
958
|
// will be ignored.
|
|
959
959
|
// https://docs.npmjs.com/cli/v10/configuring-npm/package-lock-json#package-lockjson-vs-npm-shrinkwrapjson
|
|
960
960
|
'npm-shrinkwrap.json': 'npm',
|
|
961
961
|
'package-lock.json': 'npm',
|
|
962
|
+
'pnpm-lock.yaml': 'pnpm',
|
|
963
|
+
'pnpm-lock.yml': 'pnpm',
|
|
964
|
+
'yarn.lock': 'yarn/classic',
|
|
965
|
+
'vlt-lock.json': 'vlt',
|
|
962
966
|
// Look for a hidden lock file if .npmrc has package-lock=false:
|
|
963
967
|
// https://docs.npmjs.com/cli/v10/configuring-npm/package-lock-json#hidden-lockfiles
|
|
964
968
|
//
|
|
@@ -975,6 +979,7 @@ const readLockFileByAgent = (() => {
|
|
|
975
979
|
return undefined;
|
|
976
980
|
};
|
|
977
981
|
}
|
|
982
|
+
const defaultReader = wrapReader(async lockPath => await (0, _fs$1.readFileUtf8)(lockPath));
|
|
978
983
|
return {
|
|
979
984
|
bun: wrapReader(async (lockPath, agentExecPath) => {
|
|
980
985
|
let lockBuffer;
|
|
@@ -986,14 +991,16 @@ const readLockFileByAgent = (() => {
|
|
|
986
991
|
try {
|
|
987
992
|
return (0, _hyrious__bun.parse)(lockBuffer);
|
|
988
993
|
} catch {}
|
|
989
|
-
// To print a Yarn lockfile to your console without writing it to disk
|
|
994
|
+
// To print a Yarn lockfile to your console without writing it to disk
|
|
995
|
+
// use `bun bun.lockb`.
|
|
990
996
|
// https://bun.sh/guides/install/yarnlock
|
|
991
997
|
return (await _promiseSpawn$3(agentExecPath, [lockPath])).stdout.trim();
|
|
992
998
|
}),
|
|
993
|
-
npm:
|
|
994
|
-
pnpm:
|
|
995
|
-
|
|
996
|
-
'yarn/
|
|
999
|
+
npm: defaultReader,
|
|
1000
|
+
pnpm: defaultReader,
|
|
1001
|
+
vlt: defaultReader,
|
|
1002
|
+
'yarn/berry': defaultReader,
|
|
1003
|
+
'yarn/classic': defaultReader
|
|
997
1004
|
};
|
|
998
1005
|
})();
|
|
999
1006
|
async function detect({
|
|
@@ -1033,17 +1040,10 @@ async function detect({
|
|
|
1033
1040
|
agent = 'npm';
|
|
1034
1041
|
onUnknown?.(pkgManager);
|
|
1035
1042
|
}
|
|
1036
|
-
const agentExecPath =
|
|
1037
|
-
|
|
1038
|
-
})) ?? agent;
|
|
1043
|
+
const agentExecPath = await getAgentExecPath(agent);
|
|
1044
|
+
const npmExecPath = agent === 'npm' ? agentExecPath : await getAgentExecPath('npm');
|
|
1039
1045
|
if (agentVersion === undefined) {
|
|
1040
|
-
|
|
1041
|
-
agentVersion = _semver$1.coerce(
|
|
1042
|
-
// All package managers support the "--version" flag.
|
|
1043
|
-
(await _promiseSpawn$3(agentExecPath, ['--version'], {
|
|
1044
|
-
cwd
|
|
1045
|
-
})).stdout) ?? undefined;
|
|
1046
|
-
} catch {}
|
|
1046
|
+
agentVersion = await getAgentVersion(agentExecPath, cwd);
|
|
1047
1047
|
}
|
|
1048
1048
|
if (agent === 'yarn/classic' && (agentVersion?.major ?? 0) > 1) {
|
|
1049
1049
|
agent = 'yarn/berry';
|
|
@@ -1053,10 +1053,11 @@ async function detect({
|
|
|
1053
1053
|
node: true
|
|
1054
1054
|
};
|
|
1055
1055
|
let lockSrc;
|
|
1056
|
-
|
|
1056
|
+
// Lazily access constants.maintainedNodeVersions.
|
|
1057
|
+
let minimumNodeVersion = _constants.maintainedNodeVersions.previous;
|
|
1057
1058
|
if (pkgJson) {
|
|
1058
1059
|
const browserField = pkgJson.browser;
|
|
1059
|
-
if ((0, _strings$1.isNonEmptyString)(browserField) || (0, _objects$
|
|
1060
|
+
if ((0, _strings$1.isNonEmptyString)(browserField) || (0, _objects$2.isObjectObject)(browserField)) {
|
|
1060
1061
|
targets.browser = true;
|
|
1061
1062
|
}
|
|
1062
1063
|
const nodeRange = pkgJson.engines?.['node'];
|
|
@@ -1080,7 +1081,8 @@ async function detect({
|
|
|
1080
1081
|
}
|
|
1081
1082
|
}
|
|
1082
1083
|
}
|
|
1083
|
-
|
|
1084
|
+
// Lazily access constants.maintainedNodeVersions.
|
|
1085
|
+
targets.node = _constants.maintainedNodeVersions.some(v => _semver$1.satisfies(v, `>=${minimumNodeVersion}`));
|
|
1084
1086
|
lockSrc = typeof lockPath === 'string' ? await readLockFileByAgent[agent](lockPath, agentExecPath) : undefined;
|
|
1085
1087
|
} else {
|
|
1086
1088
|
lockPath = undefined;
|
|
@@ -1092,6 +1094,7 @@ async function detect({
|
|
|
1092
1094
|
lockPath,
|
|
1093
1095
|
lockSrc,
|
|
1094
1096
|
minimumNodeVersion,
|
|
1097
|
+
npmExecPath,
|
|
1095
1098
|
pkgJson: editablePkgJson,
|
|
1096
1099
|
pkgPath,
|
|
1097
1100
|
supported: targets.browser || targets.node,
|
|
@@ -1099,88 +1102,6 @@ async function detect({
|
|
|
1099
1102
|
};
|
|
1100
1103
|
}
|
|
1101
1104
|
|
|
1102
|
-
var promises = {};
|
|
1103
|
-
|
|
1104
|
-
var arrays = {};
|
|
1105
|
-
|
|
1106
|
-
Object.defineProperty(arrays, "__esModule", {
|
|
1107
|
-
value: true
|
|
1108
|
-
});
|
|
1109
|
-
arrays.arrayChunk = arrayChunk;
|
|
1110
|
-
arrays.arrayUnique = arrayUnique;
|
|
1111
|
-
function arrayChunk(arr, size = 2) {
|
|
1112
|
-
const {
|
|
1113
|
-
length
|
|
1114
|
-
} = arr;
|
|
1115
|
-
const chunkSize = Math.min(length, size);
|
|
1116
|
-
const chunks = [];
|
|
1117
|
-
for (let i = 0; i < length; i += chunkSize) {
|
|
1118
|
-
chunks.push(arr.slice(i, i + chunkSize));
|
|
1119
|
-
}
|
|
1120
|
-
return chunks;
|
|
1121
|
-
}
|
|
1122
|
-
function arrayUnique(arr) {
|
|
1123
|
-
return [...new Set(arr)];
|
|
1124
|
-
}
|
|
1125
|
-
|
|
1126
|
-
Object.defineProperty(promises, "__esModule", {
|
|
1127
|
-
value: true
|
|
1128
|
-
});
|
|
1129
|
-
promises.pEach = pEach;
|
|
1130
|
-
promises.pEachChunk = pEachChunk;
|
|
1131
|
-
var _arrays = arrays;
|
|
1132
|
-
async function pEach(array, concurrency, callbackFn, options) {
|
|
1133
|
-
await pEachChunk((0, _arrays.arrayChunk)(array, concurrency), callbackFn, options);
|
|
1134
|
-
}
|
|
1135
|
-
async function pEachChunk(chunks, callbackFn, options) {
|
|
1136
|
-
const {
|
|
1137
|
-
signal
|
|
1138
|
-
} = {
|
|
1139
|
-
__proto__: null,
|
|
1140
|
-
...options
|
|
1141
|
-
};
|
|
1142
|
-
for (const chunk of chunks) {
|
|
1143
|
-
if (signal?.aborted) {
|
|
1144
|
-
return;
|
|
1145
|
-
}
|
|
1146
|
-
// eslint-disable-next-line no-await-in-loop
|
|
1147
|
-
await Promise.all(chunk.map(value => signal?.aborted ? undefined : callbackFn(value, {
|
|
1148
|
-
signal
|
|
1149
|
-
})));
|
|
1150
|
-
}
|
|
1151
|
-
}
|
|
1152
|
-
|
|
1153
|
-
var regexps = {};
|
|
1154
|
-
|
|
1155
|
-
Object.defineProperty(regexps, "__esModule", {
|
|
1156
|
-
value: true
|
|
1157
|
-
});
|
|
1158
|
-
regexps.escapeRegExp = escapeRegExp;
|
|
1159
|
-
// Inlined "escape-string-regexp":
|
|
1160
|
-
// https://socket.dev/npm/package/escape-string-regexp/overview/5.0.0
|
|
1161
|
-
// MIT License
|
|
1162
|
-
// Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
|
|
1163
|
-
function escapeRegExp(string) {
|
|
1164
|
-
// Escape characters with special meaning either inside or outside character sets.
|
|
1165
|
-
// Use a simple backslash escape when it’s always valid, and a `\xnn` escape when the simpler form would be disallowed by Unicode patterns’ stricter grammar.
|
|
1166
|
-
return string.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&').replace(/-/g, '\\x2d');
|
|
1167
|
-
}
|
|
1168
|
-
|
|
1169
|
-
var sorts = {};
|
|
1170
|
-
|
|
1171
|
-
Object.defineProperty(sorts, "__esModule", {
|
|
1172
|
-
value: true
|
|
1173
|
-
});
|
|
1174
|
-
sorts.localeCompare = void 0;
|
|
1175
|
-
sorts.toSortedObject = toSortedObject;
|
|
1176
|
-
const {
|
|
1177
|
-
compare: localeCompare
|
|
1178
|
-
} = new Intl.Collator();
|
|
1179
|
-
sorts.localeCompare = localeCompare;
|
|
1180
|
-
function toSortedObject(object, comparator = localeCompare) {
|
|
1181
|
-
return Object.fromEntries(Object.entries(object).sort((a, b) => comparator(a[0], b[0])));
|
|
1182
|
-
}
|
|
1183
|
-
|
|
1184
1105
|
var _interopRequireDefault$n = vendor.interopRequireDefault.default;
|
|
1185
1106
|
Object.defineProperty(optimize$1, "__esModule", {
|
|
1186
1107
|
value: true
|
|
@@ -1194,24 +1115,20 @@ var _registry = require$$5$1;
|
|
|
1194
1115
|
var _meow$m = _interopRequireDefault$n(vendor.build);
|
|
1195
1116
|
var _npmPackageArg = require$$7;
|
|
1196
1117
|
var _ora$i = _interopRequireDefault$n(vendor.ora);
|
|
1197
|
-
var _pacote = require$$0$1;
|
|
1198
1118
|
var _semver = require$$3;
|
|
1199
|
-
var _tinyglobby = require$$
|
|
1200
|
-
var _yaml = require$$
|
|
1201
|
-
var
|
|
1119
|
+
var _tinyglobby = require$$10$1;
|
|
1120
|
+
var _yaml = require$$11;
|
|
1121
|
+
var _packages = vendor.packages;
|
|
1202
1122
|
var _flags$j = flags$1;
|
|
1203
1123
|
var _formatting$k = formatting;
|
|
1204
1124
|
var _fs = fs;
|
|
1205
|
-
var _objects =
|
|
1125
|
+
var _objects$1 = vendor.objects;
|
|
1206
1126
|
var _packageManagerDetector = packageManagerDetector;
|
|
1207
|
-
var _promises2 = promises;
|
|
1208
|
-
var _regexps = regexps;
|
|
1209
|
-
var
|
|
1210
|
-
var _strings = strings;
|
|
1127
|
+
var _promises2 = vendor.promises;
|
|
1128
|
+
var _regexps = vendor.regexps;
|
|
1129
|
+
var _strings = vendor.strings;
|
|
1211
1130
|
//import cacache from 'cacache'
|
|
1212
1131
|
|
|
1213
|
-
//import { packumentCache, pacoteCachePath } from '../constants'
|
|
1214
|
-
|
|
1215
1132
|
const COMMAND_TITLE = 'Socket Optimize';
|
|
1216
1133
|
const OVERRIDES_FIELD_NAME = 'overrides';
|
|
1217
1134
|
const PNPM_WORKSPACE = 'pnpm-workspace';
|
|
@@ -1244,6 +1161,13 @@ const getOverridesDataByAgent = {
|
|
|
1244
1161
|
overrides
|
|
1245
1162
|
};
|
|
1246
1163
|
},
|
|
1164
|
+
vlt(pkgJson) {
|
|
1165
|
+
const overrides = pkgJson?.overrides ?? {};
|
|
1166
|
+
return {
|
|
1167
|
+
type: 'vlt',
|
|
1168
|
+
overrides
|
|
1169
|
+
};
|
|
1170
|
+
},
|
|
1247
1171
|
// Yarn resolutions documentation:
|
|
1248
1172
|
// https://yarnpkg.com/configuration/manifest#resolutions
|
|
1249
1173
|
'yarn/berry'(pkgJson) {
|
|
@@ -1264,7 +1188,7 @@ const getOverridesDataByAgent = {
|
|
|
1264
1188
|
}
|
|
1265
1189
|
};
|
|
1266
1190
|
const lockIncludesByAgent = (() => {
|
|
1267
|
-
|
|
1191
|
+
function yarnLockIncludes(lockSrc, name) {
|
|
1268
1192
|
const escapedName = (0, _regexps.escapeRegExp)(name);
|
|
1269
1193
|
return new RegExp(
|
|
1270
1194
|
// Detects the package name in the following cases:
|
|
@@ -1273,9 +1197,9 @@ const lockIncludesByAgent = (() => {
|
|
|
1273
1197
|
// name@
|
|
1274
1198
|
// , name@
|
|
1275
1199
|
`(?<=(?:^\\s*|,\\s*)"?)${escapedName}(?=@)`, 'm').test(lockSrc);
|
|
1276
|
-
}
|
|
1200
|
+
}
|
|
1277
1201
|
return {
|
|
1278
|
-
bun:
|
|
1202
|
+
bun: yarnLockIncludes,
|
|
1279
1203
|
npm(lockSrc, name) {
|
|
1280
1204
|
// Detects the package name in the following cases:
|
|
1281
1205
|
// "name":
|
|
@@ -1291,111 +1215,181 @@ const lockIncludesByAgent = (() => {
|
|
|
1291
1215
|
// name@
|
|
1292
1216
|
`(?<=^\\s*)(?:(['/])${escapedName}\\1|${escapedName}(?=[:@]))`, 'm').test(lockSrc);
|
|
1293
1217
|
},
|
|
1294
|
-
|
|
1295
|
-
|
|
1218
|
+
vlt(lockSrc, name) {
|
|
1219
|
+
// Detects the package name in the following cases:
|
|
1220
|
+
// "name"
|
|
1221
|
+
return lockSrc.includes(`"${name}"`);
|
|
1222
|
+
},
|
|
1223
|
+
'yarn/berry': yarnLockIncludes,
|
|
1224
|
+
'yarn/classic': yarnLockIncludes
|
|
1296
1225
|
};
|
|
1297
1226
|
})();
|
|
1298
|
-
const updateManifestByAgent = {
|
|
1299
|
-
|
|
1300
|
-
pkgJson.update({
|
|
1301
|
-
[RESOLUTIONS_FIELD_NAME]: overrides
|
|
1302
|
-
});
|
|
1303
|
-
},
|
|
1304
|
-
npm(pkgJson, overrides) {
|
|
1227
|
+
const updateManifestByAgent = (() => {
|
|
1228
|
+
function updateOverrides(pkgJson, overrides) {
|
|
1305
1229
|
pkgJson.update({
|
|
1306
1230
|
[OVERRIDES_FIELD_NAME]: overrides
|
|
1307
1231
|
});
|
|
1308
|
-
}
|
|
1309
|
-
|
|
1310
|
-
pkgJson.update({
|
|
1311
|
-
pnpm: {
|
|
1312
|
-
...pkgJson.content['pnpm'],
|
|
1313
|
-
[OVERRIDES_FIELD_NAME]: overrides
|
|
1314
|
-
}
|
|
1315
|
-
});
|
|
1316
|
-
},
|
|
1317
|
-
'yarn/berry'(pkgJson, overrides) {
|
|
1318
|
-
pkgJson.update({
|
|
1319
|
-
[RESOLUTIONS_FIELD_NAME]: overrides
|
|
1320
|
-
});
|
|
1321
|
-
},
|
|
1322
|
-
'yarn/classic'(pkgJson, overrides) {
|
|
1232
|
+
}
|
|
1233
|
+
function updateResolutions(pkgJson, overrides) {
|
|
1323
1234
|
pkgJson.update({
|
|
1324
1235
|
[RESOLUTIONS_FIELD_NAME]: overrides
|
|
1325
1236
|
});
|
|
1326
1237
|
}
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
} catch {}
|
|
1337
|
-
return '';
|
|
1338
|
-
},
|
|
1339
|
-
async npm(agentExecPath, cwd, rootPath) {
|
|
1340
|
-
try {
|
|
1341
|
-
let {
|
|
1342
|
-
stdout
|
|
1343
|
-
} = await _promiseSpawn$2(agentExecPath, ['ls', '--parseable', '--omit', 'dev', '--all'], {
|
|
1344
|
-
cwd
|
|
1345
|
-
});
|
|
1346
|
-
stdout = stdout.trim();
|
|
1347
|
-
stdout = stdout.replaceAll(cwd, '');
|
|
1348
|
-
stdout = rootPath === cwd ? stdout : stdout.replaceAll(rootPath, '');
|
|
1349
|
-
return stdout.replaceAll('\\', '/');
|
|
1350
|
-
} catch {}
|
|
1351
|
-
return '';
|
|
1352
|
-
},
|
|
1353
|
-
async pnpm(agentExecPath, cwd, rootPath) {
|
|
1354
|
-
try {
|
|
1355
|
-
let {
|
|
1356
|
-
stdout
|
|
1357
|
-
} = await _promiseSpawn$2(agentExecPath, ['ls', '--parseable', '--prod', '--depth', 'Infinity'], {
|
|
1358
|
-
cwd
|
|
1238
|
+
return {
|
|
1239
|
+
bun: updateResolutions,
|
|
1240
|
+
npm: updateOverrides,
|
|
1241
|
+
pnpm(pkgJson, overrides) {
|
|
1242
|
+
pkgJson.update({
|
|
1243
|
+
pnpm: {
|
|
1244
|
+
...pkgJson.content['pnpm'],
|
|
1245
|
+
[OVERRIDES_FIELD_NAME]: overrides
|
|
1246
|
+
}
|
|
1359
1247
|
});
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1248
|
+
},
|
|
1249
|
+
vlt: updateOverrides,
|
|
1250
|
+
'yarn/berry': updateResolutions,
|
|
1251
|
+
'yarn/classic': updateResolutions
|
|
1252
|
+
};
|
|
1253
|
+
})();
|
|
1254
|
+
const lsByAgent = (() => {
|
|
1255
|
+
function cleanupQueryStdout(stdout) {
|
|
1256
|
+
if (stdout === '') {
|
|
1257
|
+
return '';
|
|
1258
|
+
}
|
|
1259
|
+
let pkgs;
|
|
1368
1260
|
try {
|
|
1369
|
-
|
|
1370
|
-
// Yarn Berry does not support filtering by production packages yet.
|
|
1371
|
-
// https://github.com/yarnpkg/berry/issues/5117
|
|
1372
|
-
(await _promiseSpawn$2(agentExecPath, ['info', '--recursive', '--name-only'], {
|
|
1373
|
-
cwd
|
|
1374
|
-
})).stdout.trim()
|
|
1375
|
-
);
|
|
1261
|
+
pkgs = JSON.parse(stdout);
|
|
1376
1262
|
} catch {}
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1263
|
+
if (!Array.isArray(pkgs)) {
|
|
1264
|
+
return '';
|
|
1265
|
+
}
|
|
1266
|
+
const names = new Set();
|
|
1267
|
+
for (const {
|
|
1268
|
+
_id,
|
|
1269
|
+
name,
|
|
1270
|
+
pkgid
|
|
1271
|
+
} of pkgs) {
|
|
1272
|
+
// `npm query` results may not have a "name" property, in which case we
|
|
1273
|
+
// fallback to "_id" and then "pkgid".
|
|
1274
|
+
// `vlt ls --view json` results always have a "name" property.
|
|
1275
|
+
const fallback = _id ?? pkgid ?? '';
|
|
1276
|
+
const resolvedName = name ?? fallback.slice(0, fallback.indexOf('@', 1));
|
|
1277
|
+
// Add package names, except for those under the `@types` scope as those
|
|
1278
|
+
// are known to only be dev dependencies.
|
|
1279
|
+
if (resolvedName && !resolvedName.startsWith('@types/')) {
|
|
1280
|
+
names.add(resolvedName);
|
|
1281
|
+
}
|
|
1282
|
+
}
|
|
1283
|
+
return JSON.stringify([...names], null, 2);
|
|
1284
|
+
}
|
|
1285
|
+
function parseableToQueryStdout(stdout) {
|
|
1286
|
+
if (stdout === '') {
|
|
1287
|
+
return '';
|
|
1288
|
+
}
|
|
1289
|
+
// Convert the parseable stdout into a json array of unique names.
|
|
1290
|
+
// The matchAll regexp looks for a forward (posix) or backward (win32) slash
|
|
1291
|
+
// and matches one or more non-slashes until the newline.
|
|
1292
|
+
const names = new Set(stdout.matchAll(/(?<=[/\\])[^/\\]+(?=\n)/g));
|
|
1293
|
+
return JSON.stringify([...names], null, 2);
|
|
1294
|
+
}
|
|
1295
|
+
async function npmQuery(npmExecPath, cwd) {
|
|
1296
|
+
let stdout = '';
|
|
1380
1297
|
try {
|
|
1381
|
-
|
|
1382
|
-
// https://github.com/yarnpkg/yarn/releases/tag/v1.0.0
|
|
1383
|
-
// > Fix: Excludes dev dependencies from the yarn list output when the
|
|
1384
|
-
// environment is production
|
|
1385
|
-
return (await _promiseSpawn$2(agentExecPath, ['list', '--prod'], {
|
|
1298
|
+
stdout = (await _promiseSpawn$2(npmExecPath, ['query', ':not(.dev)'], {
|
|
1386
1299
|
cwd
|
|
1387
|
-
})).stdout
|
|
1300
|
+
})).stdout;
|
|
1388
1301
|
} catch {}
|
|
1389
|
-
return
|
|
1302
|
+
return cleanupQueryStdout(stdout);
|
|
1390
1303
|
}
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
};
|
|
1304
|
+
return {
|
|
1305
|
+
async bun(agentExecPath, cwd) {
|
|
1306
|
+
try {
|
|
1307
|
+
// Bun does not support filtering by production packages yet.
|
|
1308
|
+
// https://github.com/oven-sh/bun/issues/8283
|
|
1309
|
+
return (await _promiseSpawn$2(agentExecPath, ['pm', 'ls', '--all'], {
|
|
1310
|
+
cwd
|
|
1311
|
+
})).stdout;
|
|
1312
|
+
} catch {}
|
|
1313
|
+
return '';
|
|
1314
|
+
},
|
|
1315
|
+
async npm(agentExecPath, cwd) {
|
|
1316
|
+
return await npmQuery(agentExecPath, cwd);
|
|
1317
|
+
},
|
|
1318
|
+
async pnpm(agentExecPath, cwd, options) {
|
|
1319
|
+
const {
|
|
1320
|
+
npmExecPath
|
|
1321
|
+
} = {
|
|
1322
|
+
__proto__: null,
|
|
1323
|
+
...options
|
|
1324
|
+
};
|
|
1325
|
+
if (npmExecPath && npmExecPath !== 'npm') {
|
|
1326
|
+
const result = await npmQuery(npmExecPath, cwd);
|
|
1327
|
+
if (result) {
|
|
1328
|
+
return result;
|
|
1329
|
+
}
|
|
1330
|
+
}
|
|
1331
|
+
let stdout = '';
|
|
1332
|
+
try {
|
|
1333
|
+
stdout = (await _promiseSpawn$2(agentExecPath, ['ls', '--parseable', '--prod', '--depth', 'Infinity'], {
|
|
1334
|
+
cwd
|
|
1335
|
+
})).stdout;
|
|
1336
|
+
} catch {}
|
|
1337
|
+
return parseableToQueryStdout(stdout);
|
|
1338
|
+
},
|
|
1339
|
+
async vlt(agentExecPath, cwd) {
|
|
1340
|
+
let stdout = '';
|
|
1341
|
+
try {
|
|
1342
|
+
stdout = (await _promiseSpawn$2(agentExecPath, ['ls', '--view', 'human', ':not(.dev)'], {
|
|
1343
|
+
cwd
|
|
1344
|
+
})).stdout;
|
|
1345
|
+
} catch {}
|
|
1346
|
+
return cleanupQueryStdout(stdout);
|
|
1347
|
+
},
|
|
1348
|
+
async 'yarn/berry'(agentExecPath, cwd) {
|
|
1349
|
+
try {
|
|
1350
|
+
return (
|
|
1351
|
+
// Yarn Berry does not support filtering by production packages yet.
|
|
1352
|
+
// https://github.com/yarnpkg/berry/issues/5117
|
|
1353
|
+
(await _promiseSpawn$2(agentExecPath, ['info', '--recursive', '--name-only'], {
|
|
1354
|
+
cwd
|
|
1355
|
+
})).stdout.trim()
|
|
1356
|
+
);
|
|
1357
|
+
} catch {}
|
|
1358
|
+
return '';
|
|
1359
|
+
},
|
|
1360
|
+
async 'yarn/classic'(agentExecPath, cwd) {
|
|
1361
|
+
try {
|
|
1362
|
+
// However, Yarn Classic does support it.
|
|
1363
|
+
// https://github.com/yarnpkg/yarn/releases/tag/v1.0.0
|
|
1364
|
+
// > Fix: Excludes dev dependencies from the yarn list output when the
|
|
1365
|
+
// environment is production
|
|
1366
|
+
return (await _promiseSpawn$2(agentExecPath, ['list', '--prod'], {
|
|
1367
|
+
cwd
|
|
1368
|
+
})).stdout.trim();
|
|
1369
|
+
} catch {}
|
|
1370
|
+
return '';
|
|
1371
|
+
}
|
|
1372
|
+
};
|
|
1373
|
+
})();
|
|
1374
|
+
const depsIncludesByAgent = (() => {
|
|
1375
|
+
function matchHumanStdout(stdout, name) {
|
|
1376
|
+
return stdout.includes(` ${name}@`);
|
|
1377
|
+
}
|
|
1378
|
+
function matchQueryStdout(stdout, name) {
|
|
1379
|
+
return stdout.includes(`"${name}"`);
|
|
1380
|
+
}
|
|
1381
|
+
return {
|
|
1382
|
+
bun: matchHumanStdout,
|
|
1383
|
+
npm: matchQueryStdout,
|
|
1384
|
+
pnpm: matchQueryStdout,
|
|
1385
|
+
vlt: matchQueryStdout,
|
|
1386
|
+
'yarn/berry': matchHumanStdout,
|
|
1387
|
+
'yarn/classic': matchHumanStdout
|
|
1388
|
+
};
|
|
1389
|
+
})();
|
|
1390
|
+
function createActionMessage(verb, overrideCount, workspaceCount) {
|
|
1391
|
+
return `${verb} ${overrideCount} Socket.dev optimized overrides${workspaceCount ? ` in ${workspaceCount} workspace${workspaceCount > 1 ? 's' : ''}` : ''}`;
|
|
1392
|
+
}
|
|
1399
1393
|
function getDependencyEntries(pkgJson) {
|
|
1400
1394
|
const {
|
|
1401
1395
|
dependencies,
|
|
@@ -1419,28 +1413,33 @@ function getDependencyEntries(pkgJson) {
|
|
|
1419
1413
|
1: o
|
|
1420
1414
|
}) => o);
|
|
1421
1415
|
}
|
|
1422
|
-
async function
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1416
|
+
async function getWorkspaceGlobs(agent, pkgPath, pkgJson) {
|
|
1417
|
+
let workspacePatterns;
|
|
1418
|
+
if (agent === 'pnpm') {
|
|
1419
|
+
for (const workspacePath of [_nodePath$2.join(pkgPath, `${PNPM_WORKSPACE}.yaml`), _nodePath$2.join(pkgPath, `${PNPM_WORKSPACE}.yml`)]) {
|
|
1420
|
+
if ((0, _fs.existsSync)(workspacePath)) {
|
|
1421
|
+
try {
|
|
1422
|
+
workspacePatterns = (0, _yaml.parse)(
|
|
1423
|
+
// eslint-disable-next-line no-await-in-loop
|
|
1424
|
+
await _promises$2.readFile(workspacePath, 'utf8'))?.packages;
|
|
1425
|
+
} catch {}
|
|
1426
|
+
if (workspacePatterns) {
|
|
1427
|
+
break;
|
|
1428
|
+
}
|
|
1435
1429
|
}
|
|
1436
1430
|
}
|
|
1431
|
+
} else {
|
|
1432
|
+
workspacePatterns = pkgJson['workspaces'];
|
|
1437
1433
|
}
|
|
1438
|
-
return undefined;
|
|
1434
|
+
return Array.isArray(workspacePatterns) ? workspacePatterns.filter(_strings.isNonEmptyString).map(workspacePatternToGlobPattern) : undefined;
|
|
1439
1435
|
}
|
|
1440
|
-
function
|
|
1436
|
+
function workspacePatternToGlobPattern(workspace) {
|
|
1441
1437
|
const {
|
|
1442
1438
|
length
|
|
1443
1439
|
} = workspace;
|
|
1440
|
+
if (!length) {
|
|
1441
|
+
return '';
|
|
1442
|
+
}
|
|
1444
1443
|
// If the workspace ends with "/"
|
|
1445
1444
|
if (workspace.charCodeAt(length - 1) === 47 /*'/'*/) {
|
|
1446
1445
|
return `${workspace}/*/package.json`;
|
|
@@ -1452,21 +1451,29 @@ function workspaceToGlobPattern(workspace) {
|
|
|
1452
1451
|
// Things like "packages/a" or "packages/*"
|
|
1453
1452
|
return `${workspace}/package.json`;
|
|
1454
1453
|
}
|
|
1454
|
+
function createAddOverridesState(initials) {
|
|
1455
|
+
return {
|
|
1456
|
+
added: new Set(),
|
|
1457
|
+
addedInWorkspaces: new Set(),
|
|
1458
|
+
spinner: undefined,
|
|
1459
|
+
updated: new Set(),
|
|
1460
|
+
updatedInWorkspaces: new Set(),
|
|
1461
|
+
warnedPnpmWorkspaceRequiresNpm: false,
|
|
1462
|
+
...initials
|
|
1463
|
+
};
|
|
1464
|
+
}
|
|
1455
1465
|
async function addOverrides({
|
|
1456
1466
|
agent,
|
|
1457
1467
|
agentExecPath,
|
|
1458
1468
|
lockSrc,
|
|
1459
1469
|
manifestEntries,
|
|
1470
|
+
npmExecPath,
|
|
1460
1471
|
pin,
|
|
1461
1472
|
pkgJson: editablePkgJson,
|
|
1462
1473
|
pkgPath,
|
|
1463
1474
|
prod,
|
|
1464
1475
|
rootPath
|
|
1465
|
-
}, state = {
|
|
1466
|
-
added: new Set(),
|
|
1467
|
-
spinner: undefined,
|
|
1468
|
-
updated: new Set()
|
|
1469
|
-
}) {
|
|
1476
|
+
}, state = createAddOverridesState()) {
|
|
1470
1477
|
if (editablePkgJson === undefined) {
|
|
1471
1478
|
editablePkgJson = await _packageJson.load(pkgPath);
|
|
1472
1479
|
}
|
|
@@ -1476,19 +1483,26 @@ async function addOverrides({
|
|
|
1476
1483
|
const pkgJson = editablePkgJson.content;
|
|
1477
1484
|
const isRoot = pkgPath === rootPath;
|
|
1478
1485
|
const isLockScanned = isRoot && !prod;
|
|
1479
|
-
const
|
|
1486
|
+
const workspaceName = _nodePath$2.relative(rootPath, pkgPath);
|
|
1487
|
+
const workspaceGlobs = await getWorkspaceGlobs(agent, pkgPath, pkgJson);
|
|
1488
|
+
const isWorkspace = !!workspaceGlobs;
|
|
1489
|
+
if (isWorkspace && agent === 'pnpm' && npmExecPath === 'npm' && !state.warnedPnpmWorkspaceRequiresNpm) {
|
|
1490
|
+
state.warnedPnpmWorkspaceRequiresNpm = true;
|
|
1491
|
+
console.log(`⚠️ ${COMMAND_TITLE}: pnpm workspace support requires \`npm ls\`, falling back to \`pnpm list\``);
|
|
1492
|
+
}
|
|
1493
|
+
const thingToScan = isLockScanned ? lockSrc : await lsByAgent[agent](agentExecPath, pkgPath, {
|
|
1494
|
+
npmExecPath
|
|
1495
|
+
});
|
|
1480
1496
|
const thingScanner = isLockScanned ? lockIncludesByAgent[agent] : depsIncludesByAgent[agent];
|
|
1481
1497
|
const depEntries = getDependencyEntries(pkgJson);
|
|
1482
|
-
const workspaces = await getWorkspaces(agent, pkgPath, pkgJson);
|
|
1483
|
-
const isWorkspace = !!workspaces;
|
|
1484
1498
|
const overridesDataObjects = [];
|
|
1485
1499
|
if (pkgJson['private'] || isWorkspace) {
|
|
1486
1500
|
overridesDataObjects.push(getOverridesDataByAgent[agent](pkgJson));
|
|
1487
1501
|
} else {
|
|
1488
|
-
overridesDataObjects.push(getOverridesDataByAgent
|
|
1502
|
+
overridesDataObjects.push(getOverridesDataByAgent.npm(pkgJson), getOverridesDataByAgent['yarn/classic'](pkgJson));
|
|
1489
1503
|
}
|
|
1490
1504
|
if (spinner) {
|
|
1491
|
-
spinner.text = `Adding overrides${
|
|
1505
|
+
spinner.text = `Adding overrides${workspaceName ? ` to ${workspaceName}` : ''}...`;
|
|
1492
1506
|
}
|
|
1493
1507
|
const depAliasMap = new Map();
|
|
1494
1508
|
// Chunk package names to process them in parallel 3 at a time.
|
|
@@ -1517,6 +1531,7 @@ async function addOverrides({
|
|
|
1517
1531
|
pkgSpec = `${regSpecStartsLike}^${version}`;
|
|
1518
1532
|
depObj[origPkgName] = pkgSpec;
|
|
1519
1533
|
state.added.add(regPkgName);
|
|
1534
|
+
state.addedInWorkspaces.add(workspaceName);
|
|
1520
1535
|
}
|
|
1521
1536
|
depAliasMap.set(origPkgName, {
|
|
1522
1537
|
id: pkgSpec,
|
|
@@ -1529,7 +1544,7 @@ async function addOverrides({
|
|
|
1529
1544
|
overrides,
|
|
1530
1545
|
type
|
|
1531
1546
|
}) => {
|
|
1532
|
-
const overrideExists = (0, _objects.hasOwn)(overrides, origPkgName);
|
|
1547
|
+
const overrideExists = (0, _objects$1.hasOwn)(overrides, origPkgName);
|
|
1533
1548
|
if (overrideExists || thingScanner(thingToScan, origPkgName)) {
|
|
1534
1549
|
const oldSpec = overrideExists ? overrides[origPkgName] : undefined;
|
|
1535
1550
|
const depAlias = depAliasMap.get(origPkgName);
|
|
@@ -1549,7 +1564,7 @@ async function addOverrides({
|
|
|
1549
1564
|
const thisSpec = oldSpec.startsWith('$') ? depAlias?.id ?? newSpec : oldSpec ?? newSpec;
|
|
1550
1565
|
if (thisSpec.startsWith(regSpecStartsLike)) {
|
|
1551
1566
|
if (pin) {
|
|
1552
|
-
thisVersion = _semver.major(_semver.coerce(_npmPackageArg(thisSpec).rawSpec)?.version ?? version) === major ? version : (await fetchPackageManifest(thisSpec))?.version ?? version;
|
|
1567
|
+
thisVersion = _semver.major(_semver.coerce(_npmPackageArg(thisSpec).rawSpec)?.version ?? version) === major ? version : (await (0, _packages.fetchPackageManifest)(thisSpec))?.version ?? version;
|
|
1553
1568
|
}
|
|
1554
1569
|
newSpec = `${regSpecStartsLike}^${pin ? thisVersion : _semver.major(thisVersion)}`;
|
|
1555
1570
|
} else {
|
|
@@ -1557,46 +1572,43 @@ async function addOverrides({
|
|
|
1557
1572
|
}
|
|
1558
1573
|
}
|
|
1559
1574
|
if (newSpec !== oldSpec) {
|
|
1575
|
+
overrides[origPkgName] = newSpec;
|
|
1560
1576
|
if (overrideExists) {
|
|
1561
1577
|
state.updated.add(regPkgName);
|
|
1578
|
+
state.updatedInWorkspaces.add(workspaceName);
|
|
1562
1579
|
} else {
|
|
1563
1580
|
state.added.add(regPkgName);
|
|
1581
|
+
state.addedInWorkspaces.add(workspaceName);
|
|
1564
1582
|
}
|
|
1565
|
-
overrides[origPkgName] = newSpec;
|
|
1566
1583
|
}
|
|
1567
1584
|
}
|
|
1568
1585
|
});
|
|
1569
1586
|
});
|
|
1570
|
-
if (
|
|
1571
|
-
const
|
|
1587
|
+
if (workspaceGlobs) {
|
|
1588
|
+
const workspacePkgJsonPaths = await (0, _tinyglobby.glob)(workspaceGlobs, {
|
|
1572
1589
|
absolute: true,
|
|
1573
1590
|
cwd: pkgPath,
|
|
1574
1591
|
ignore: ['**/node_modules/**', '**/bower_components/**']
|
|
1575
1592
|
});
|
|
1576
1593
|
// Chunk package names to process them in parallel 3 at a time.
|
|
1577
|
-
await (0, _promises2.pEach)(
|
|
1578
|
-
const {
|
|
1579
|
-
added,
|
|
1580
|
-
updated
|
|
1581
|
-
} = await addOverrides({
|
|
1594
|
+
await (0, _promises2.pEach)(workspacePkgJsonPaths, 3, async workspacePkgJsonPath => {
|
|
1595
|
+
const otherState = await addOverrides({
|
|
1582
1596
|
agent,
|
|
1583
1597
|
agentExecPath,
|
|
1584
1598
|
lockSrc,
|
|
1585
1599
|
manifestEntries,
|
|
1600
|
+
npmExecPath,
|
|
1586
1601
|
pin,
|
|
1587
|
-
pkgPath: _nodePath$2.dirname(
|
|
1602
|
+
pkgPath: _nodePath$2.dirname(workspacePkgJsonPath),
|
|
1588
1603
|
prod,
|
|
1589
1604
|
rootPath
|
|
1590
|
-
}, {
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
}
|
|
1598
|
-
for (const regPkgName of updated) {
|
|
1599
|
-
state.updated.add(regPkgName);
|
|
1605
|
+
}, createAddOverridesState({
|
|
1606
|
+
spinner
|
|
1607
|
+
}));
|
|
1608
|
+
for (const key of ['added', 'addedInWorkspaces', 'updated', 'updatedInWorkspaces']) {
|
|
1609
|
+
for (const value of otherState[key]) {
|
|
1610
|
+
state[key].add(value);
|
|
1611
|
+
}
|
|
1600
1612
|
}
|
|
1601
1613
|
});
|
|
1602
1614
|
}
|
|
@@ -1606,62 +1618,12 @@ async function addOverrides({
|
|
|
1606
1618
|
overrides,
|
|
1607
1619
|
type
|
|
1608
1620
|
} of overridesDataObjects) {
|
|
1609
|
-
updateManifestByAgent[type](editablePkgJson, (0,
|
|
1621
|
+
updateManifestByAgent[type](editablePkgJson, (0, _objects$1.toSortedObject)(overrides));
|
|
1610
1622
|
}
|
|
1611
1623
|
await editablePkgJson.save();
|
|
1612
1624
|
}
|
|
1613
1625
|
return state;
|
|
1614
1626
|
}
|
|
1615
|
-
|
|
1616
|
-
// type ExtractOptions = pacote.Options & {
|
|
1617
|
-
// tmpPrefix?: string
|
|
1618
|
-
// [key: string]: any
|
|
1619
|
-
// }
|
|
1620
|
-
|
|
1621
|
-
// async function extractPackage(pkgNameOrId: string, options: ExtractOptions | undefined, callback: (tmpDirPath: string) => any) {
|
|
1622
|
-
// if (arguments.length === 2 && typeof options === 'function') {
|
|
1623
|
-
// callback = options
|
|
1624
|
-
// options = undefined
|
|
1625
|
-
// }
|
|
1626
|
-
// const { tmpPrefix, ...extractOptions } = { __proto__: null, ...options }
|
|
1627
|
-
// // cacache.tmp.withTmp DOES return a promise.
|
|
1628
|
-
// await cacache.tmp.withTmp(
|
|
1629
|
-
// pacoteCachePath,
|
|
1630
|
-
// { tmpPrefix },
|
|
1631
|
-
// // eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
1632
|
-
// async tmpDirPath => {
|
|
1633
|
-
// await pacote.extract(pkgNameOrId, tmpDirPath, {
|
|
1634
|
-
// __proto__: null,
|
|
1635
|
-
// packumentCache,
|
|
1636
|
-
// preferOffline: true,
|
|
1637
|
-
// ...<Omit<typeof extractOptions, '__proto__'>>extractOptions
|
|
1638
|
-
// })
|
|
1639
|
-
// await callback(tmpDirPath)
|
|
1640
|
-
// }
|
|
1641
|
-
// )
|
|
1642
|
-
// }
|
|
1643
|
-
|
|
1644
|
-
async function fetchPackageManifest(pkgNameOrId, options) {
|
|
1645
|
-
const pacoteOptions = {
|
|
1646
|
-
...options,
|
|
1647
|
-
packumentCache: _constants.packumentCache,
|
|
1648
|
-
preferOffline: true
|
|
1649
|
-
};
|
|
1650
|
-
const {
|
|
1651
|
-
signal
|
|
1652
|
-
} = pacoteOptions;
|
|
1653
|
-
if (signal?.aborted) {
|
|
1654
|
-
return null;
|
|
1655
|
-
}
|
|
1656
|
-
let result;
|
|
1657
|
-
try {
|
|
1658
|
-
result = await _pacote.manifest(pkgNameOrId, pacoteOptions);
|
|
1659
|
-
} catch {}
|
|
1660
|
-
if (signal?.aborted) {
|
|
1661
|
-
return null;
|
|
1662
|
-
}
|
|
1663
|
-
return result;
|
|
1664
|
-
}
|
|
1665
1627
|
const optimize = optimize$1.optimize = {
|
|
1666
1628
|
description: 'Optimize dependencies with @socketregistry overrides',
|
|
1667
1629
|
async run(argv, importMeta, {
|
|
@@ -1680,9 +1642,10 @@ const optimize = optimize$1.optimize = {
|
|
|
1680
1642
|
agent,
|
|
1681
1643
|
agentExecPath,
|
|
1682
1644
|
agentVersion,
|
|
1683
|
-
lockSrc,
|
|
1684
1645
|
lockPath,
|
|
1646
|
+
lockSrc,
|
|
1685
1647
|
minimumNodeVersion,
|
|
1648
|
+
npmExecPath,
|
|
1686
1649
|
pkgJson,
|
|
1687
1650
|
pkgPath,
|
|
1688
1651
|
supported
|
|
@@ -1696,6 +1659,10 @@ const optimize = optimize$1.optimize = {
|
|
|
1696
1659
|
console.log(`✘ ${COMMAND_TITLE}: No supported Node or browser range detected`);
|
|
1697
1660
|
return;
|
|
1698
1661
|
}
|
|
1662
|
+
if (agent === 'vlt') {
|
|
1663
|
+
console.log(`✘ ${COMMAND_TITLE}: ${agent} does not support overrides. Soon, though ⚡`);
|
|
1664
|
+
return;
|
|
1665
|
+
}
|
|
1699
1666
|
const lockName = lockPath ? _nodePath$2.basename(lockPath) : 'lock file';
|
|
1700
1667
|
if (lockSrc === undefined) {
|
|
1701
1668
|
console.log(`✘ ${COMMAND_TITLE}: No ${lockName} found`);
|
|
@@ -1717,11 +1684,9 @@ const optimize = optimize$1.optimize = {
|
|
|
1717
1684
|
console.log(`⚠️ ${COMMAND_TITLE}: Package ${lockName} found at ${lockPath}`);
|
|
1718
1685
|
}
|
|
1719
1686
|
const spinner = (0, _ora$i.default)('Socket optimizing...');
|
|
1720
|
-
const state = {
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
updated: new Set()
|
|
1724
|
-
};
|
|
1687
|
+
const state = createAddOverridesState({
|
|
1688
|
+
spinner
|
|
1689
|
+
});
|
|
1725
1690
|
spinner.start();
|
|
1726
1691
|
const nodeRange = `>=${minimumNodeVersion}`;
|
|
1727
1692
|
const manifestEntries = manifestNpmOverrides.filter(({
|
|
@@ -1732,6 +1697,7 @@ const optimize = optimize$1.optimize = {
|
|
|
1732
1697
|
agentExecPath,
|
|
1733
1698
|
lockSrc,
|
|
1734
1699
|
manifestEntries,
|
|
1700
|
+
npmExecPath,
|
|
1735
1701
|
pin,
|
|
1736
1702
|
pkgJson,
|
|
1737
1703
|
pkgPath,
|
|
@@ -1739,13 +1705,15 @@ const optimize = optimize$1.optimize = {
|
|
|
1739
1705
|
rootPath: pkgPath
|
|
1740
1706
|
}, state);
|
|
1741
1707
|
spinner.stop();
|
|
1742
|
-
const
|
|
1708
|
+
const addedCount = state.added.size;
|
|
1709
|
+
const updatedCount = state.updated.size;
|
|
1710
|
+
const pkgJsonChanged = addedCount > 0 || updatedCount > 0;
|
|
1743
1711
|
if (pkgJsonChanged) {
|
|
1744
|
-
if (
|
|
1745
|
-
console.log(
|
|
1712
|
+
if (updatedCount > 0) {
|
|
1713
|
+
console.log(`${createActionMessage('Updated', updatedCount, state.updatedInWorkspaces.size)}${addedCount ? '.' : '🚀'}`);
|
|
1746
1714
|
}
|
|
1747
|
-
if (
|
|
1748
|
-
console.log(
|
|
1715
|
+
if (addedCount > 0) {
|
|
1716
|
+
console.log(`${createActionMessage('Added', addedCount, state.addedInWorkspaces.size)} 🚀`);
|
|
1749
1717
|
}
|
|
1750
1718
|
} else {
|
|
1751
1719
|
console.log('Congratulations! Already Socket.dev optimized 🎉');
|
|
@@ -1759,7 +1727,7 @@ const optimize = optimize$1.optimize = {
|
|
|
1759
1727
|
if (isNpm) {
|
|
1760
1728
|
const wrapperPath = _nodePath$2.join(distPath$1, 'npm-cli.js');
|
|
1761
1729
|
await _promiseSpawn$2(process.execPath, [wrapperPath, 'install', '--no-audit', '--no-fund'], {
|
|
1762
|
-
stdio: '
|
|
1730
|
+
stdio: 'ignore',
|
|
1763
1731
|
env: {
|
|
1764
1732
|
...process.env,
|
|
1765
1733
|
UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE: '1'
|
|
@@ -1768,7 +1736,7 @@ const optimize = optimize$1.optimize = {
|
|
|
1768
1736
|
} else {
|
|
1769
1737
|
// All package managers support the "install" command.
|
|
1770
1738
|
await _promiseSpawn$2(agentExecPath, ['install'], {
|
|
1771
|
-
stdio: '
|
|
1739
|
+
stdio: 'ignore'
|
|
1772
1740
|
});
|
|
1773
1741
|
}
|
|
1774
1742
|
spinner.stop();
|
|
@@ -2391,14 +2359,14 @@ Object.defineProperty(meowWithSubcommands$1, "__esModule", {
|
|
|
2391
2359
|
meowWithSubcommands$1.meowWithSubcommands = meowWithSubcommands;
|
|
2392
2360
|
var _meow$g = _interopRequireDefault$h(vendor.build);
|
|
2393
2361
|
var _formatting$f = formatting;
|
|
2394
|
-
var
|
|
2362
|
+
var _objects = vendor.objects;
|
|
2395
2363
|
var _flags$e = flags$1;
|
|
2396
2364
|
async function meowWithSubcommands(subcommands, options) {
|
|
2397
2365
|
const {
|
|
2398
2366
|
aliases = {},
|
|
2399
2367
|
argv,
|
|
2400
|
-
name,
|
|
2401
2368
|
importMeta,
|
|
2369
|
+
name,
|
|
2402
2370
|
...additionalOptions
|
|
2403
2371
|
} = {
|
|
2404
2372
|
__proto__: null,
|
|
@@ -2430,8 +2398,8 @@ async function meowWithSubcommands(subcommands, options) {
|
|
|
2430
2398
|
|
|
2431
2399
|
Commands
|
|
2432
2400
|
${(0, _formatting$f.printHelpList)({
|
|
2433
|
-
...(0,
|
|
2434
|
-
...(0,
|
|
2401
|
+
...(0, _objects.toSortedObject)(subcommands),
|
|
2402
|
+
...(0, _objects.toSortedObject)(aliases)
|
|
2435
2403
|
}, 6)}
|
|
2436
2404
|
|
|
2437
2405
|
Options
|
|
@@ -2526,8 +2494,8 @@ function setupCommand$f(name, description, argv, importMeta) {
|
|
|
2526
2494
|
return;
|
|
2527
2495
|
}
|
|
2528
2496
|
const {
|
|
2529
|
-
|
|
2530
|
-
|
|
2497
|
+
disable,
|
|
2498
|
+
enable
|
|
2531
2499
|
} = cli.flags;
|
|
2532
2500
|
let showHelp = cli.flags['help'];
|
|
2533
2501
|
if (!enable && !disable) {
|
|
@@ -2641,7 +2609,7 @@ Object.defineProperty(create$3, "__esModule", {
|
|
|
2641
2609
|
value: true
|
|
2642
2610
|
});
|
|
2643
2611
|
create$3.create = void 0;
|
|
2644
|
-
var _nodeProcess = require$$0$
|
|
2612
|
+
var _nodeProcess = require$$0$1;
|
|
2645
2613
|
var _promises$1 = require$$2$3;
|
|
2646
2614
|
var _chalk$e = _interopRequireDefault$f(vendor.source);
|
|
2647
2615
|
var _meow$e = _interopRequireDefault$f(vendor.build);
|
|
@@ -2774,8 +2742,8 @@ async function setupCommand$e(name, description, argv, importMeta) {
|
|
|
2774
2742
|
const debugLog = (0, _misc.createDebugLogger)(false);
|
|
2775
2743
|
const packagePaths = await (0, _pathResolve.getPackageFilesFullScans)(cwd, cli.input, supportedFiles, debugLog);
|
|
2776
2744
|
const {
|
|
2777
|
-
|
|
2778
|
-
|
|
2745
|
+
branch: branchName,
|
|
2746
|
+
repo: repoName
|
|
2779
2747
|
} = cli.flags;
|
|
2780
2748
|
if (!repoName || !branchName || !packagePaths.length) {
|
|
2781
2749
|
showHelp = true;
|
|
@@ -2805,14 +2773,14 @@ async function setupCommand$e(name, description, argv, importMeta) {
|
|
|
2805
2773
|
async function createFullScan(input, spinner, apiKey) {
|
|
2806
2774
|
const socketSdk = await (0, _sdk$e.setupSdk)(apiKey);
|
|
2807
2775
|
const {
|
|
2808
|
-
orgSlug,
|
|
2809
|
-
repoName,
|
|
2810
2776
|
branchName,
|
|
2811
2777
|
commitMessage,
|
|
2812
2778
|
defaultBranch,
|
|
2779
|
+
orgSlug,
|
|
2780
|
+
packagePaths,
|
|
2813
2781
|
pendingHead,
|
|
2814
|
-
|
|
2815
|
-
|
|
2782
|
+
repoName,
|
|
2783
|
+
tmp
|
|
2816
2784
|
} = input;
|
|
2817
2785
|
const result = await (0, _apiHelpers$e.handleApiCall)(socketSdk.createOrgFullScan(orgSlug, {
|
|
2818
2786
|
repo: repoName,
|
|
@@ -4117,8 +4085,8 @@ function setupCommand$3(name, description, argv, importMeta) {
|
|
|
4117
4085
|
});
|
|
4118
4086
|
const {
|
|
4119
4087
|
json: outputJson,
|
|
4120
|
-
markdown: outputMarkdown,
|
|
4121
4088
|
limit,
|
|
4089
|
+
markdown: outputMarkdown,
|
|
4122
4090
|
offset
|
|
4123
4091
|
} = cli.flags;
|
|
4124
4092
|
return {
|
|
@@ -4510,7 +4478,7 @@ Object.defineProperty(get$1, "__esModule", {
|
|
|
4510
4478
|
});
|
|
4511
4479
|
get$1.get = void 0;
|
|
4512
4480
|
var _nodeFs$1 = require$$0;
|
|
4513
|
-
var _nodeUtil = require$$0$
|
|
4481
|
+
var _nodeUtil = require$$0$2;
|
|
4514
4482
|
var _chalk$1 = _interopRequireDefault$2(vendor.source);
|
|
4515
4483
|
var _meow$1 = _interopRequireDefault$2(vendor.build);
|
|
4516
4484
|
var _ora$1 = _interopRequireDefault$2(vendor.ora);
|
|
@@ -4588,8 +4556,8 @@ function setupCommand$1(name, description, argv, importMeta) {
|
|
|
4588
4556
|
flags
|
|
4589
4557
|
});
|
|
4590
4558
|
const {
|
|
4591
|
-
|
|
4592
|
-
|
|
4559
|
+
after,
|
|
4560
|
+
before
|
|
4593
4561
|
} = cli.flags;
|
|
4594
4562
|
let showHelp = cli.flags['help'];
|
|
4595
4563
|
if (!before || !after) {
|
|
@@ -4615,10 +4583,10 @@ function setupCommand$1(name, description, argv, importMeta) {
|
|
|
4615
4583
|
};
|
|
4616
4584
|
}
|
|
4617
4585
|
async function getDiffScan({
|
|
4618
|
-
before,
|
|
4619
4586
|
after,
|
|
4620
|
-
|
|
4587
|
+
before,
|
|
4621
4588
|
file,
|
|
4589
|
+
orgSlug,
|
|
4622
4590
|
outputJson
|
|
4623
4591
|
}, spinner, apiKey) {
|
|
4624
4592
|
const response = await (0, _apiHelpers$1.queryAPI)(`${orgSlug}/full-scans/diff?before=${before}&after=${after}&preview`, apiKey);
|
|
@@ -4764,12 +4732,12 @@ function setupCommand(name, description, argv, importMeta) {
|
|
|
4764
4732
|
flags
|
|
4765
4733
|
});
|
|
4766
4734
|
const {
|
|
4735
|
+
direction,
|
|
4736
|
+
filter,
|
|
4767
4737
|
json: outputJson,
|
|
4768
4738
|
markdown: outputMarkdown,
|
|
4769
|
-
perPage: per_page,
|
|
4770
4739
|
page,
|
|
4771
|
-
|
|
4772
|
-
filter
|
|
4740
|
+
perPage: per_page
|
|
4773
4741
|
} = cli.flags;
|
|
4774
4742
|
return {
|
|
4775
4743
|
outputJson,
|
|
@@ -4781,11 +4749,11 @@ function setupCommand(name, description, argv, importMeta) {
|
|
|
4781
4749
|
};
|
|
4782
4750
|
}
|
|
4783
4751
|
async function fetchThreatFeed({
|
|
4784
|
-
per_page,
|
|
4785
|
-
page,
|
|
4786
4752
|
direction,
|
|
4787
4753
|
filter,
|
|
4788
|
-
outputJson
|
|
4754
|
+
outputJson,
|
|
4755
|
+
page,
|
|
4756
|
+
per_page
|
|
4789
4757
|
}, spinner, apiKey) {
|
|
4790
4758
|
const formattedQueryParams = formatQueryParams({
|
|
4791
4759
|
per_page,
|