socket 0.14.19 → 0.14.21
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.js +413 -204
- package/dist/npm-cli.js +7 -7
- package/dist/npm-injection.js +224 -117
- package/dist/path-resolve.js +1 -1
- package/dist/sdk.d.ts +3 -1
- package/dist/sdk.js +10 -3
- package/package.json +13 -11
package/dist/cli.js
CHANGED
|
@@ -14,7 +14,7 @@ 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$$
|
|
17
|
+
var require$$0$1 = require('pacote');
|
|
18
18
|
var require$$3 = require('semver');
|
|
19
19
|
var require$$11 = require('tinyglobby');
|
|
20
20
|
var require$$12 = require('yaml');
|
|
@@ -26,12 +26,12 @@ var require$$3$1 = require('@socketsecurity/config');
|
|
|
26
26
|
var pathResolve = require('./path-resolve.js');
|
|
27
27
|
var require$$2$2 = require('node:os');
|
|
28
28
|
var require$$3$2 = require('node:readline');
|
|
29
|
-
var require$$0$
|
|
29
|
+
var require$$0$2 = require('node:process');
|
|
30
30
|
var require$$2$3 = require('node:readline/promises');
|
|
31
31
|
var require$$2$4 = require('chalk-table');
|
|
32
32
|
var require$$2$5 = require('blessed');
|
|
33
33
|
var require$$3$3 = require('blessed-contrib');
|
|
34
|
-
var require$$0$
|
|
34
|
+
var require$$0$3 = require('node:util');
|
|
35
35
|
|
|
36
36
|
var cli$1 = {};
|
|
37
37
|
|
|
@@ -285,7 +285,7 @@ apiHelpers.queryAPI = queryAPI;
|
|
|
285
285
|
var _chalk$i = _interopRequireDefault$r(vendor.source);
|
|
286
286
|
var _ponyCause$4 = require$$6;
|
|
287
287
|
var _errors$l = sdk.errors;
|
|
288
|
-
var _constants = sdk.constants;
|
|
288
|
+
var _constants$1 = sdk.constants;
|
|
289
289
|
function handleUnsuccessfulApiResponse(_name, result, spinner) {
|
|
290
290
|
const resultError = 'error' in result && result.error && typeof result.error === 'object' ? result.error : {};
|
|
291
291
|
const message = 'message' in resultError && typeof resultError.message === 'string' ? resultError.message : 'No error message returned';
|
|
@@ -315,7 +315,7 @@ async function handleAPIError(code) {
|
|
|
315
315
|
}
|
|
316
316
|
}
|
|
317
317
|
async function queryAPI(path, apiKey) {
|
|
318
|
-
return await fetch(`${_constants.API_V0_URL}/${path}`, {
|
|
318
|
+
return await fetch(`${_constants$1.API_V0_URL}/${path}`, {
|
|
319
319
|
method: 'GET',
|
|
320
320
|
headers: {
|
|
321
321
|
Authorization: 'Basic ' + btoa(`${apiKey}:${apiKey}`)
|
|
@@ -511,8 +511,8 @@ async function fetchPackageData(pkgName, pkgVersion, {
|
|
|
511
511
|
}
|
|
512
512
|
function formatPackageDataOutput({
|
|
513
513
|
data,
|
|
514
|
-
|
|
515
|
-
|
|
514
|
+
score,
|
|
515
|
+
severityCount
|
|
516
516
|
}, {
|
|
517
517
|
name,
|
|
518
518
|
outputJson,
|
|
@@ -915,7 +915,7 @@ var _which = require$$6$1;
|
|
|
915
915
|
var _fs$1 = fs;
|
|
916
916
|
var _objects$1 = sdk.objects;
|
|
917
917
|
var _strings$1 = strings;
|
|
918
|
-
const AGENTS = packageManagerDetector.AGENTS = ['bun', 'npm', 'pnpm', 'yarn'];
|
|
918
|
+
const AGENTS = packageManagerDetector.AGENTS = ['bun', 'npm', 'pnpm', 'yarn/berry', 'yarn/classic', 'vlt'];
|
|
919
919
|
const numericCollator = new Intl.Collator(undefined, {
|
|
920
920
|
numeric: true,
|
|
921
921
|
sensitivity: 'base'
|
|
@@ -923,6 +923,22 @@ const numericCollator = new Intl.Collator(undefined, {
|
|
|
923
923
|
const {
|
|
924
924
|
compare: alphaNumericComparator
|
|
925
925
|
} = numericCollator;
|
|
926
|
+
async function getAgentExecPath(agent) {
|
|
927
|
+
return (await _which(agent, {
|
|
928
|
+
nothrow: true
|
|
929
|
+
})) ?? agent;
|
|
930
|
+
}
|
|
931
|
+
async function getAgentVersion(agentExecPath, cwd) {
|
|
932
|
+
let result;
|
|
933
|
+
try {
|
|
934
|
+
result = _semver$1.coerce(
|
|
935
|
+
// All package managers support the "--version" flag.
|
|
936
|
+
(await _promiseSpawn$3(agentExecPath, ['--version'], {
|
|
937
|
+
cwd
|
|
938
|
+
})).stdout) ?? undefined;
|
|
939
|
+
} catch {}
|
|
940
|
+
return result;
|
|
941
|
+
}
|
|
926
942
|
const maintainedNodeVersions = (() => {
|
|
927
943
|
// Under the hood browserlist uses the node-releases package which is out of date:
|
|
928
944
|
// https://github.com/chicoxyzzy/node-releases/issues/37
|
|
@@ -950,15 +966,16 @@ const maintainedNodeVersions = (() => {
|
|
|
950
966
|
})();
|
|
951
967
|
const LOCKS = {
|
|
952
968
|
'bun.lockb': 'bun',
|
|
953
|
-
'pnpm-lock.yaml': 'pnpm',
|
|
954
|
-
'pnpm-lock.yml': 'pnpm',
|
|
955
|
-
'yarn.lock': 'yarn',
|
|
956
969
|
// If both package-lock.json and npm-shrinkwrap.json are present in the root
|
|
957
970
|
// of a project, npm-shrinkwrap.json will take precedence and package-lock.json
|
|
958
971
|
// will be ignored.
|
|
959
972
|
// https://docs.npmjs.com/cli/v10/configuring-npm/package-lock-json#package-lockjson-vs-npm-shrinkwrapjson
|
|
960
973
|
'npm-shrinkwrap.json': 'npm',
|
|
961
974
|
'package-lock.json': 'npm',
|
|
975
|
+
'pnpm-lock.yaml': 'pnpm',
|
|
976
|
+
'pnpm-lock.yml': 'pnpm',
|
|
977
|
+
'yarn.lock': 'yarn/classic',
|
|
978
|
+
'vlt-lock.json': 'vlt',
|
|
962
979
|
// Look for a hidden lock file if .npmrc has package-lock=false:
|
|
963
980
|
// https://docs.npmjs.com/cli/v10/configuring-npm/package-lock-json#hidden-lockfiles
|
|
964
981
|
//
|
|
@@ -975,6 +992,7 @@ const readLockFileByAgent = (() => {
|
|
|
975
992
|
return undefined;
|
|
976
993
|
};
|
|
977
994
|
}
|
|
995
|
+
const defaultReader = wrapReader(async lockPath => await (0, _fs$1.readFileUtf8)(lockPath));
|
|
978
996
|
return {
|
|
979
997
|
bun: wrapReader(async (lockPath, agentExecPath) => {
|
|
980
998
|
let lockBuffer;
|
|
@@ -986,13 +1004,16 @@ const readLockFileByAgent = (() => {
|
|
|
986
1004
|
try {
|
|
987
1005
|
return (0, _hyrious__bun.parse)(lockBuffer);
|
|
988
1006
|
} catch {}
|
|
989
|
-
// To print a Yarn lockfile to your console without writing it to disk
|
|
1007
|
+
// To print a Yarn lockfile to your console without writing it to disk
|
|
1008
|
+
// use `bun bun.lockb`.
|
|
990
1009
|
// https://bun.sh/guides/install/yarnlock
|
|
991
|
-
return (await _promiseSpawn$3(agentExecPath, [lockPath])).stdout;
|
|
1010
|
+
return (await _promiseSpawn$3(agentExecPath, [lockPath])).stdout.trim();
|
|
992
1011
|
}),
|
|
993
|
-
npm:
|
|
994
|
-
pnpm:
|
|
995
|
-
|
|
1012
|
+
npm: defaultReader,
|
|
1013
|
+
pnpm: defaultReader,
|
|
1014
|
+
vlt: defaultReader,
|
|
1015
|
+
'yarn/berry': defaultReader,
|
|
1016
|
+
'yarn/classic': defaultReader
|
|
996
1017
|
};
|
|
997
1018
|
})();
|
|
998
1019
|
async function detect({
|
|
@@ -1007,10 +1028,11 @@ async function detect({
|
|
|
1007
1028
|
cwd
|
|
1008
1029
|
});
|
|
1009
1030
|
const pkgPath = (0, _fs$1.existsSync)(pkgJsonPath) ? _nodePath$3.dirname(pkgJsonPath) : undefined;
|
|
1010
|
-
const
|
|
1031
|
+
const editablePkgJson = pkgPath ? await _packageJson$1.load(pkgPath) : undefined;
|
|
1032
|
+
const pkgJson = editablePkgJson?.content;
|
|
1011
1033
|
// Read Corepack `packageManager` field in package.json:
|
|
1012
1034
|
// https://nodejs.org/api/packages.html#packagemanager
|
|
1013
|
-
const pkgManager = (0, _strings$1.isNonEmptyString)(pkgJson?.
|
|
1035
|
+
const pkgManager = (0, _strings$1.isNonEmptyString)(pkgJson?.packageManager) ? pkgJson.packageManager : undefined;
|
|
1014
1036
|
let agent;
|
|
1015
1037
|
let agentVersion;
|
|
1016
1038
|
if (pkgManager) {
|
|
@@ -1020,7 +1042,7 @@ async function detect({
|
|
|
1020
1042
|
const version = pkgManager.slice(atSignIndex + 1);
|
|
1021
1043
|
if (version && AGENTS.includes(name)) {
|
|
1022
1044
|
agent = name;
|
|
1023
|
-
agentVersion = version;
|
|
1045
|
+
agentVersion = _semver$1.coerce(version) ?? undefined;
|
|
1024
1046
|
}
|
|
1025
1047
|
}
|
|
1026
1048
|
}
|
|
@@ -1031,9 +1053,14 @@ async function detect({
|
|
|
1031
1053
|
agent = 'npm';
|
|
1032
1054
|
onUnknown?.(pkgManager);
|
|
1033
1055
|
}
|
|
1034
|
-
const agentExecPath =
|
|
1035
|
-
|
|
1036
|
-
|
|
1056
|
+
const agentExecPath = await getAgentExecPath(agent);
|
|
1057
|
+
const npmExecPath = agent === 'npm' ? agentExecPath : await getAgentExecPath('npm');
|
|
1058
|
+
if (agentVersion === undefined) {
|
|
1059
|
+
agentVersion = await getAgentVersion(agentExecPath, cwd);
|
|
1060
|
+
}
|
|
1061
|
+
if (agent === 'yarn/classic' && (agentVersion?.major ?? 0) > 1) {
|
|
1062
|
+
agent = 'yarn/berry';
|
|
1063
|
+
}
|
|
1037
1064
|
const targets = {
|
|
1038
1065
|
browser: false,
|
|
1039
1066
|
node: true
|
|
@@ -1041,18 +1068,18 @@ async function detect({
|
|
|
1041
1068
|
let lockSrc;
|
|
1042
1069
|
let minimumNodeVersion = maintainedNodeVersions.previous;
|
|
1043
1070
|
if (pkgJson) {
|
|
1044
|
-
const browserField = pkgJson.
|
|
1071
|
+
const browserField = pkgJson.browser;
|
|
1045
1072
|
if ((0, _strings$1.isNonEmptyString)(browserField) || (0, _objects$1.isObjectObject)(browserField)) {
|
|
1046
1073
|
targets.browser = true;
|
|
1047
1074
|
}
|
|
1048
|
-
const nodeRange = pkgJson.
|
|
1075
|
+
const nodeRange = pkgJson.engines?.['node'];
|
|
1049
1076
|
if ((0, _strings$1.isNonEmptyString)(nodeRange)) {
|
|
1050
1077
|
const coerced = _semver$1.coerce(nodeRange);
|
|
1051
1078
|
if (coerced && _semver$1.lt(coerced, minimumNodeVersion)) {
|
|
1052
1079
|
minimumNodeVersion = coerced.version;
|
|
1053
1080
|
}
|
|
1054
1081
|
}
|
|
1055
|
-
const browserslistQuery = pkgJson
|
|
1082
|
+
const browserslistQuery = pkgJson['browserslist'];
|
|
1056
1083
|
if (Array.isArray(browserslistQuery)) {
|
|
1057
1084
|
const browserslistTargets = _browserslist(browserslistQuery).map(s => s.toLowerCase()).toSorted(alphaNumericComparator);
|
|
1058
1085
|
const browserslistNodeTargets = browserslistTargets.filter(v => v.startsWith('node ')).map(v => v.slice(5 /*'node '.length*/));
|
|
@@ -1078,7 +1105,8 @@ async function detect({
|
|
|
1078
1105
|
lockPath,
|
|
1079
1106
|
lockSrc,
|
|
1080
1107
|
minimumNodeVersion,
|
|
1081
|
-
|
|
1108
|
+
npmExecPath,
|
|
1109
|
+
pkgJson: editablePkgJson,
|
|
1082
1110
|
pkgPath,
|
|
1083
1111
|
supported: targets.browser || targets.node,
|
|
1084
1112
|
targets
|
|
@@ -1180,10 +1208,11 @@ var _registry = require$$5$1;
|
|
|
1180
1208
|
var _meow$m = _interopRequireDefault$n(vendor.build);
|
|
1181
1209
|
var _npmPackageArg = require$$7;
|
|
1182
1210
|
var _ora$i = _interopRequireDefault$n(vendor.ora);
|
|
1183
|
-
var _pacote = require$$
|
|
1211
|
+
var _pacote = require$$0$1;
|
|
1184
1212
|
var _semver = require$$3;
|
|
1185
1213
|
var _tinyglobby = require$$11;
|
|
1186
1214
|
var _yaml = require$$12;
|
|
1215
|
+
var _constants = sdk.constants;
|
|
1187
1216
|
var _flags$j = flags$1;
|
|
1188
1217
|
var _formatting$k = formatting;
|
|
1189
1218
|
var _fs = fs;
|
|
@@ -1193,18 +1222,21 @@ var _promises2 = promises;
|
|
|
1193
1222
|
var _regexps = regexps;
|
|
1194
1223
|
var _sorts$1 = sorts;
|
|
1195
1224
|
var _strings = strings;
|
|
1225
|
+
//import cacache from 'cacache'
|
|
1226
|
+
|
|
1227
|
+
//import { packumentCache, pacoteCachePath } from '../constants'
|
|
1228
|
+
|
|
1196
1229
|
const COMMAND_TITLE = 'Socket Optimize';
|
|
1197
1230
|
const OVERRIDES_FIELD_NAME = 'overrides';
|
|
1198
1231
|
const PNPM_WORKSPACE = 'pnpm-workspace';
|
|
1199
1232
|
const RESOLUTIONS_FIELD_NAME = 'resolutions';
|
|
1200
1233
|
const distPath$1 = __dirname;
|
|
1201
1234
|
const manifestNpmOverrides = (0, _registry.getManifestData)('npm');
|
|
1202
|
-
const packumentCache = new Map();
|
|
1203
1235
|
const getOverridesDataByAgent = {
|
|
1204
1236
|
bun(pkgJson) {
|
|
1205
1237
|
const overrides = pkgJson?.resolutions ?? {};
|
|
1206
1238
|
return {
|
|
1207
|
-
type: 'yarn',
|
|
1239
|
+
type: 'yarn/berry',
|
|
1208
1240
|
overrides
|
|
1209
1241
|
};
|
|
1210
1242
|
},
|
|
@@ -1226,18 +1258,34 @@ const getOverridesDataByAgent = {
|
|
|
1226
1258
|
overrides
|
|
1227
1259
|
};
|
|
1228
1260
|
},
|
|
1261
|
+
vlt(pkgJson) {
|
|
1262
|
+
const overrides = pkgJson?.overrides ?? {};
|
|
1263
|
+
return {
|
|
1264
|
+
type: 'vlt',
|
|
1265
|
+
overrides
|
|
1266
|
+
};
|
|
1267
|
+
},
|
|
1229
1268
|
// Yarn resolutions documentation:
|
|
1230
1269
|
// https://yarnpkg.com/configuration/manifest#resolutions
|
|
1231
|
-
yarn(pkgJson) {
|
|
1270
|
+
'yarn/berry'(pkgJson) {
|
|
1271
|
+
const overrides = pkgJson?.resolutions ?? {};
|
|
1272
|
+
return {
|
|
1273
|
+
type: 'yarn/berry',
|
|
1274
|
+
overrides
|
|
1275
|
+
};
|
|
1276
|
+
},
|
|
1277
|
+
// Yarn resolutions documentation:
|
|
1278
|
+
// https://classic.yarnpkg.com/en/docs/selective-version-resolutions
|
|
1279
|
+
'yarn/classic'(pkgJson) {
|
|
1232
1280
|
const overrides = pkgJson?.resolutions ?? {};
|
|
1233
1281
|
return {
|
|
1234
|
-
type: 'yarn',
|
|
1282
|
+
type: 'yarn/classic',
|
|
1235
1283
|
overrides
|
|
1236
1284
|
};
|
|
1237
1285
|
}
|
|
1238
1286
|
};
|
|
1239
1287
|
const lockIncludesByAgent = (() => {
|
|
1240
|
-
|
|
1288
|
+
function yarnLockIncludes(lockSrc, name) {
|
|
1241
1289
|
const escapedName = (0, _regexps.escapeRegExp)(name);
|
|
1242
1290
|
return new RegExp(
|
|
1243
1291
|
// Detects the package name in the following cases:
|
|
@@ -1246,9 +1294,9 @@ const lockIncludesByAgent = (() => {
|
|
|
1246
1294
|
// name@
|
|
1247
1295
|
// , name@
|
|
1248
1296
|
`(?<=(?:^\\s*|,\\s*)"?)${escapedName}(?=@)`, 'm').test(lockSrc);
|
|
1249
|
-
}
|
|
1297
|
+
}
|
|
1250
1298
|
return {
|
|
1251
|
-
bun:
|
|
1299
|
+
bun: yarnLockIncludes,
|
|
1252
1300
|
npm(lockSrc, name) {
|
|
1253
1301
|
// Detects the package name in the following cases:
|
|
1254
1302
|
// "name":
|
|
@@ -1264,94 +1312,179 @@ const lockIncludesByAgent = (() => {
|
|
|
1264
1312
|
// name@
|
|
1265
1313
|
`(?<=^\\s*)(?:(['/])${escapedName}\\1|${escapedName}(?=[:@]))`, 'm').test(lockSrc);
|
|
1266
1314
|
},
|
|
1267
|
-
|
|
1315
|
+
vlt(lockSrc, name) {
|
|
1316
|
+
// Detects the package name in the following cases:
|
|
1317
|
+
// "name"
|
|
1318
|
+
return lockSrc.includes(`"${name}"`);
|
|
1319
|
+
},
|
|
1320
|
+
'yarn/berry': yarnLockIncludes,
|
|
1321
|
+
'yarn/classic': yarnLockIncludes
|
|
1268
1322
|
};
|
|
1269
1323
|
})();
|
|
1270
|
-
const updateManifestByAgent = {
|
|
1271
|
-
|
|
1272
|
-
pkgJson.update({
|
|
1273
|
-
[RESOLUTIONS_FIELD_NAME]: overrides
|
|
1274
|
-
});
|
|
1275
|
-
},
|
|
1276
|
-
npm(pkgJson, overrides) {
|
|
1324
|
+
const updateManifestByAgent = (() => {
|
|
1325
|
+
function updateOverrides(pkgJson, overrides) {
|
|
1277
1326
|
pkgJson.update({
|
|
1278
1327
|
[OVERRIDES_FIELD_NAME]: overrides
|
|
1279
1328
|
});
|
|
1280
|
-
}
|
|
1281
|
-
|
|
1282
|
-
pkgJson.update({
|
|
1283
|
-
pnpm: {
|
|
1284
|
-
...pkgJson.content['pnpm'],
|
|
1285
|
-
[OVERRIDES_FIELD_NAME]: overrides
|
|
1286
|
-
}
|
|
1287
|
-
});
|
|
1288
|
-
},
|
|
1289
|
-
yarn(pkgJson, overrides) {
|
|
1329
|
+
}
|
|
1330
|
+
function updateResolutions(pkgJson, overrides) {
|
|
1290
1331
|
pkgJson.update({
|
|
1291
1332
|
[RESOLUTIONS_FIELD_NAME]: overrides
|
|
1292
1333
|
});
|
|
1293
1334
|
}
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
} catch {}
|
|
1304
|
-
return '';
|
|
1305
|
-
},
|
|
1306
|
-
async npm(agentExecPath, cwd, rootPath) {
|
|
1307
|
-
try {
|
|
1308
|
-
let {
|
|
1309
|
-
stdout
|
|
1310
|
-
} = await _promiseSpawn$2(agentExecPath, ['ls', '--parseable', '--omit', 'dev', '--all'], {
|
|
1311
|
-
cwd
|
|
1312
|
-
});
|
|
1313
|
-
stdout = stdout.replaceAll(cwd, '');
|
|
1314
|
-
return rootPath === cwd ? stdout : stdout.replaceAll(rootPath, '');
|
|
1315
|
-
} catch {}
|
|
1316
|
-
return '';
|
|
1317
|
-
},
|
|
1318
|
-
async pnpm(agentExecPath, cwd, rootPath) {
|
|
1319
|
-
try {
|
|
1320
|
-
let {
|
|
1321
|
-
stdout
|
|
1322
|
-
} = await _promiseSpawn$2(agentExecPath, ['ls', '--parseable', '--prod', '--depth', 'Infinity'], {
|
|
1323
|
-
cwd
|
|
1335
|
+
return {
|
|
1336
|
+
bun: updateResolutions,
|
|
1337
|
+
npm: updateOverrides,
|
|
1338
|
+
pnpm(pkgJson, overrides) {
|
|
1339
|
+
pkgJson.update({
|
|
1340
|
+
pnpm: {
|
|
1341
|
+
...pkgJson.content['pnpm'],
|
|
1342
|
+
[OVERRIDES_FIELD_NAME]: overrides
|
|
1343
|
+
}
|
|
1324
1344
|
});
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
}
|
|
1330
|
-
|
|
1345
|
+
},
|
|
1346
|
+
vlt: updateOverrides,
|
|
1347
|
+
'yarn/berry': updateResolutions,
|
|
1348
|
+
'yarn/classic': updateResolutions
|
|
1349
|
+
};
|
|
1350
|
+
})();
|
|
1351
|
+
const lsByAgent = (() => {
|
|
1352
|
+
function cleanupQueryStdout(stdout) {
|
|
1353
|
+
if (stdout === '') {
|
|
1354
|
+
return '';
|
|
1355
|
+
}
|
|
1356
|
+
let pkgs;
|
|
1331
1357
|
try {
|
|
1332
|
-
|
|
1333
|
-
// Yarn Berry does not support filtering by production packages yet.
|
|
1334
|
-
// https://github.com/yarnpkg/berry/issues/5117
|
|
1335
|
-
(await _promiseSpawn$2(agentExecPath, ['info', '--recursive', '--name-only'], {
|
|
1336
|
-
cwd
|
|
1337
|
-
})).stdout
|
|
1338
|
-
);
|
|
1358
|
+
pkgs = JSON.parse(stdout);
|
|
1339
1359
|
} catch {}
|
|
1360
|
+
if (!Array.isArray(pkgs)) {
|
|
1361
|
+
return '';
|
|
1362
|
+
}
|
|
1363
|
+
const names = new Set();
|
|
1364
|
+
for (const {
|
|
1365
|
+
_id,
|
|
1366
|
+
name,
|
|
1367
|
+
pkgid
|
|
1368
|
+
} of pkgs) {
|
|
1369
|
+
// `npm query` results may not have a "name" property, in which case we
|
|
1370
|
+
// fallback to "_id" and then "pkgid".
|
|
1371
|
+
// `vlt ls --view json` results always have a "name" property.
|
|
1372
|
+
const fallback = _id ?? pkgid ?? '';
|
|
1373
|
+
const resolvedName = name ?? fallback.slice(0, fallback.indexOf('@', 1));
|
|
1374
|
+
if (resolvedName) {
|
|
1375
|
+
names.add(resolvedName);
|
|
1376
|
+
}
|
|
1377
|
+
}
|
|
1378
|
+
return JSON.stringify([...names], null, 2);
|
|
1379
|
+
}
|
|
1380
|
+
function parseableToQueryStdout(stdout) {
|
|
1381
|
+
if (stdout === '') {
|
|
1382
|
+
return '';
|
|
1383
|
+
}
|
|
1384
|
+
// Convert the parseable stdout into a json array of unique names.
|
|
1385
|
+
// The matchAll regexp looks for a forward (posix) or backward (win32) slash
|
|
1386
|
+
// and matches one or more non-slashes until the newline.
|
|
1387
|
+
const names = new Set(stdout.matchAll(/(?<=[/\\])[^/\\]+(?=\n)/g));
|
|
1388
|
+
return JSON.stringify([...names], null, 2);
|
|
1389
|
+
}
|
|
1390
|
+
async function npmQuery(npmExecPath, cwd) {
|
|
1391
|
+
let stdout = '';
|
|
1340
1392
|
try {
|
|
1341
|
-
|
|
1342
|
-
return (await _promiseSpawn$2(agentExecPath, ['list', '--prod'], {
|
|
1393
|
+
stdout = (await _promiseSpawn$2(npmExecPath, ['query', ':not(.dev)'], {
|
|
1343
1394
|
cwd
|
|
1344
1395
|
})).stdout;
|
|
1345
1396
|
} catch {}
|
|
1346
|
-
return
|
|
1397
|
+
return cleanupQueryStdout(stdout);
|
|
1347
1398
|
}
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1399
|
+
return {
|
|
1400
|
+
async bun(agentExecPath, cwd) {
|
|
1401
|
+
try {
|
|
1402
|
+
// Bun does not support filtering by production packages yet.
|
|
1403
|
+
// https://github.com/oven-sh/bun/issues/8283
|
|
1404
|
+
return (await _promiseSpawn$2(agentExecPath, ['pm', 'ls', '--all'], {
|
|
1405
|
+
cwd
|
|
1406
|
+
})).stdout;
|
|
1407
|
+
} catch {}
|
|
1408
|
+
return '';
|
|
1409
|
+
},
|
|
1410
|
+
async npm(agentExecPath, cwd) {
|
|
1411
|
+
return await npmQuery(agentExecPath, cwd);
|
|
1412
|
+
},
|
|
1413
|
+
async pnpm(agentExecPath, cwd, options) {
|
|
1414
|
+
const {
|
|
1415
|
+
npmExecPath
|
|
1416
|
+
} = {
|
|
1417
|
+
__proto__: null,
|
|
1418
|
+
...options
|
|
1419
|
+
};
|
|
1420
|
+
if (npmExecPath && npmExecPath !== 'npm') {
|
|
1421
|
+
const result = await npmQuery(npmExecPath, cwd);
|
|
1422
|
+
if (result) {
|
|
1423
|
+
return result;
|
|
1424
|
+
}
|
|
1425
|
+
}
|
|
1426
|
+
let stdout = '';
|
|
1427
|
+
try {
|
|
1428
|
+
stdout = (await _promiseSpawn$2(agentExecPath, ['ls', '--parseable', '--prod', '--depth', 'Infinity'], {
|
|
1429
|
+
cwd
|
|
1430
|
+
})).stdout;
|
|
1431
|
+
} catch {}
|
|
1432
|
+
return parseableToQueryStdout(stdout);
|
|
1433
|
+
},
|
|
1434
|
+
async vlt(agentExecPath, cwd) {
|
|
1435
|
+
let stdout = '';
|
|
1436
|
+
try {
|
|
1437
|
+
stdout = (await _promiseSpawn$2(agentExecPath, ['ls', '--view', 'human', ':not(.dev)'], {
|
|
1438
|
+
cwd
|
|
1439
|
+
})).stdout;
|
|
1440
|
+
} catch {}
|
|
1441
|
+
return cleanupQueryStdout(stdout);
|
|
1442
|
+
},
|
|
1443
|
+
async 'yarn/berry'(agentExecPath, cwd) {
|
|
1444
|
+
try {
|
|
1445
|
+
return (
|
|
1446
|
+
// Yarn Berry does not support filtering by production packages yet.
|
|
1447
|
+
// https://github.com/yarnpkg/berry/issues/5117
|
|
1448
|
+
(await _promiseSpawn$2(agentExecPath, ['info', '--recursive', '--name-only'], {
|
|
1449
|
+
cwd
|
|
1450
|
+
})).stdout.trim()
|
|
1451
|
+
);
|
|
1452
|
+
} catch {}
|
|
1453
|
+
return '';
|
|
1454
|
+
},
|
|
1455
|
+
async 'yarn/classic'(agentExecPath, cwd) {
|
|
1456
|
+
try {
|
|
1457
|
+
// However, Yarn Classic does support it.
|
|
1458
|
+
// https://github.com/yarnpkg/yarn/releases/tag/v1.0.0
|
|
1459
|
+
// > Fix: Excludes dev dependencies from the yarn list output when the
|
|
1460
|
+
// environment is production
|
|
1461
|
+
return (await _promiseSpawn$2(agentExecPath, ['list', '--prod'], {
|
|
1462
|
+
cwd
|
|
1463
|
+
})).stdout.trim();
|
|
1464
|
+
} catch {}
|
|
1465
|
+
return '';
|
|
1466
|
+
}
|
|
1467
|
+
};
|
|
1468
|
+
})();
|
|
1469
|
+
const depsIncludesByAgent = (() => {
|
|
1470
|
+
function matchHumanStdout(stdout, name) {
|
|
1471
|
+
return stdout.includes(` ${name}@`);
|
|
1472
|
+
}
|
|
1473
|
+
function matchQueryStdout(stdout, name) {
|
|
1474
|
+
return stdout.includes(`"${name}"`);
|
|
1475
|
+
}
|
|
1476
|
+
return {
|
|
1477
|
+
bun: matchHumanStdout,
|
|
1478
|
+
npm: matchQueryStdout,
|
|
1479
|
+
pnpm: matchQueryStdout,
|
|
1480
|
+
vlt: matchQueryStdout,
|
|
1481
|
+
'yarn/berry': matchHumanStdout,
|
|
1482
|
+
'yarn/classic': matchHumanStdout
|
|
1483
|
+
};
|
|
1484
|
+
})();
|
|
1485
|
+
function createActionMessage(verb, overrideCount, workspaceCount) {
|
|
1486
|
+
return `${verb} ${overrideCount} Socket.dev optimized overrides${workspaceCount ? ` in ${workspaceCount} workspace${workspaceCount > 1 ? 's' : ''}` : ''}`;
|
|
1487
|
+
}
|
|
1355
1488
|
function getDependencyEntries(pkgJson) {
|
|
1356
1489
|
const {
|
|
1357
1490
|
dependencies,
|
|
@@ -1375,28 +1508,33 @@ function getDependencyEntries(pkgJson) {
|
|
|
1375
1508
|
1: o
|
|
1376
1509
|
}) => o);
|
|
1377
1510
|
}
|
|
1378
|
-
async function
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1511
|
+
async function getWorkspaceGlobs(agent, pkgPath, pkgJson) {
|
|
1512
|
+
let workspacePatterns;
|
|
1513
|
+
if (agent === 'pnpm') {
|
|
1514
|
+
for (const workspacePath of [_nodePath$2.join(pkgPath, `${PNPM_WORKSPACE}.yaml`), _nodePath$2.join(pkgPath, `${PNPM_WORKSPACE}.yml`)]) {
|
|
1515
|
+
if ((0, _fs.existsSync)(workspacePath)) {
|
|
1516
|
+
try {
|
|
1517
|
+
workspacePatterns = (0, _yaml.parse)(
|
|
1518
|
+
// eslint-disable-next-line no-await-in-loop
|
|
1519
|
+
await _promises$2.readFile(workspacePath, 'utf8'))?.packages;
|
|
1520
|
+
} catch {}
|
|
1521
|
+
if (workspacePatterns) {
|
|
1522
|
+
break;
|
|
1523
|
+
}
|
|
1391
1524
|
}
|
|
1392
1525
|
}
|
|
1526
|
+
} else {
|
|
1527
|
+
workspacePatterns = pkgJson['workspaces'];
|
|
1393
1528
|
}
|
|
1394
|
-
return undefined;
|
|
1529
|
+
return Array.isArray(workspacePatterns) ? workspacePatterns.filter(_strings.isNonEmptyString).map(workspacePatternToGlobPattern) : undefined;
|
|
1395
1530
|
}
|
|
1396
|
-
function
|
|
1531
|
+
function workspacePatternToGlobPattern(workspace) {
|
|
1397
1532
|
const {
|
|
1398
1533
|
length
|
|
1399
1534
|
} = workspace;
|
|
1535
|
+
if (!length) {
|
|
1536
|
+
return '';
|
|
1537
|
+
}
|
|
1400
1538
|
// If the workspace ends with "/"
|
|
1401
1539
|
if (workspace.charCodeAt(length - 1) === 47 /*'/'*/) {
|
|
1402
1540
|
return `${workspace}/*/package.json`;
|
|
@@ -1408,38 +1546,59 @@ function workspaceToGlobPattern(workspace) {
|
|
|
1408
1546
|
// Things like "packages/a" or "packages/*"
|
|
1409
1547
|
return `${workspace}/package.json`;
|
|
1410
1548
|
}
|
|
1549
|
+
function createAddOverridesState(initials) {
|
|
1550
|
+
return {
|
|
1551
|
+
added: new Set(),
|
|
1552
|
+
addedInWorkspaces: new Set(),
|
|
1553
|
+
spinner: undefined,
|
|
1554
|
+
updated: new Set(),
|
|
1555
|
+
updatedInWorkspaces: new Set(),
|
|
1556
|
+
warnedPnpmWorkspaceRequiresNpm: false,
|
|
1557
|
+
...initials
|
|
1558
|
+
};
|
|
1559
|
+
}
|
|
1411
1560
|
async function addOverrides({
|
|
1412
1561
|
agent,
|
|
1413
1562
|
agentExecPath,
|
|
1414
1563
|
lockSrc,
|
|
1415
1564
|
manifestEntries,
|
|
1565
|
+
npmExecPath,
|
|
1416
1566
|
pin,
|
|
1417
1567
|
pkgJson: editablePkgJson,
|
|
1418
1568
|
pkgPath,
|
|
1419
1569
|
prod,
|
|
1420
1570
|
rootPath
|
|
1421
|
-
}, state = {
|
|
1422
|
-
added: new Set(),
|
|
1423
|
-
updated: new Set()
|
|
1424
|
-
}) {
|
|
1571
|
+
}, state = createAddOverridesState()) {
|
|
1425
1572
|
if (editablePkgJson === undefined) {
|
|
1426
1573
|
editablePkgJson = await _packageJson.load(pkgPath);
|
|
1427
1574
|
}
|
|
1575
|
+
const {
|
|
1576
|
+
spinner
|
|
1577
|
+
} = state;
|
|
1428
1578
|
const pkgJson = editablePkgJson.content;
|
|
1429
1579
|
const isRoot = pkgPath === rootPath;
|
|
1430
1580
|
const isLockScanned = isRoot && !prod;
|
|
1431
|
-
const
|
|
1581
|
+
const workspaceName = _nodePath$2.relative(rootPath, pkgPath);
|
|
1582
|
+
const workspaceGlobs = await getWorkspaceGlobs(agent, pkgPath, pkgJson);
|
|
1583
|
+
const isWorkspace = !!workspaceGlobs;
|
|
1584
|
+
if (isWorkspace && agent === 'pnpm' && npmExecPath === 'npm' && !state.warnedPnpmWorkspaceRequiresNpm) {
|
|
1585
|
+
state.warnedPnpmWorkspaceRequiresNpm = true;
|
|
1586
|
+
console.log(`⚠️ ${COMMAND_TITLE}: pnpm workspace support requires \`npm ls\`, falling back to \`pnpm list\``);
|
|
1587
|
+
}
|
|
1588
|
+
const thingToScan = isLockScanned ? lockSrc : await lsByAgent[agent](agentExecPath, pkgPath, {
|
|
1589
|
+
npmExecPath
|
|
1590
|
+
});
|
|
1432
1591
|
const thingScanner = isLockScanned ? lockIncludesByAgent[agent] : depsIncludesByAgent[agent];
|
|
1433
1592
|
const depEntries = getDependencyEntries(pkgJson);
|
|
1434
|
-
const workspaces = await getWorkspaces(agent, pkgPath, pkgJson);
|
|
1435
|
-
const isWorkspace = !!workspaces;
|
|
1436
1593
|
const overridesDataObjects = [];
|
|
1437
1594
|
if (pkgJson['private'] || isWorkspace) {
|
|
1438
1595
|
overridesDataObjects.push(getOverridesDataByAgent[agent](pkgJson));
|
|
1439
1596
|
} else {
|
|
1440
|
-
overridesDataObjects.push(getOverridesDataByAgent
|
|
1597
|
+
overridesDataObjects.push(getOverridesDataByAgent.npm(pkgJson), getOverridesDataByAgent['yarn/classic'](pkgJson));
|
|
1598
|
+
}
|
|
1599
|
+
if (spinner) {
|
|
1600
|
+
spinner.text = `Adding overrides${workspaceName ? ` to ${workspaceName}` : ''}...`;
|
|
1441
1601
|
}
|
|
1442
|
-
const spinner = isRoot ? (0, _ora$i.default)('Fetching override manifests...').start() : undefined;
|
|
1443
1602
|
const depAliasMap = new Map();
|
|
1444
1603
|
// Chunk package names to process them in parallel 3 at a time.
|
|
1445
1604
|
await (0, _promises2.pEach)(manifestEntries, 3, async ({
|
|
@@ -1467,6 +1626,7 @@ async function addOverrides({
|
|
|
1467
1626
|
pkgSpec = `${regSpecStartsLike}^${version}`;
|
|
1468
1627
|
depObj[origPkgName] = pkgSpec;
|
|
1469
1628
|
state.added.add(regPkgName);
|
|
1629
|
+
state.addedInWorkspaces.add(workspaceName);
|
|
1470
1630
|
}
|
|
1471
1631
|
depAliasMap.set(origPkgName, {
|
|
1472
1632
|
id: pkgSpec,
|
|
@@ -1507,46 +1667,47 @@ async function addOverrides({
|
|
|
1507
1667
|
}
|
|
1508
1668
|
}
|
|
1509
1669
|
if (newSpec !== oldSpec) {
|
|
1670
|
+
overrides[origPkgName] = newSpec;
|
|
1510
1671
|
if (overrideExists) {
|
|
1511
1672
|
state.updated.add(regPkgName);
|
|
1673
|
+
state.updatedInWorkspaces.add(workspaceName);
|
|
1512
1674
|
} else {
|
|
1513
1675
|
state.added.add(regPkgName);
|
|
1676
|
+
state.addedInWorkspaces.add(workspaceName);
|
|
1514
1677
|
}
|
|
1515
|
-
overrides[origPkgName] = newSpec;
|
|
1516
1678
|
}
|
|
1517
1679
|
}
|
|
1518
1680
|
});
|
|
1519
1681
|
});
|
|
1520
|
-
if (
|
|
1521
|
-
const
|
|
1682
|
+
if (workspaceGlobs) {
|
|
1683
|
+
const workspacePkgJsonPaths = await (0, _tinyglobby.glob)(workspaceGlobs, {
|
|
1522
1684
|
absolute: true,
|
|
1523
|
-
cwd: pkgPath
|
|
1685
|
+
cwd: pkgPath,
|
|
1686
|
+
ignore: ['**/node_modules/**', '**/bower_components/**']
|
|
1524
1687
|
});
|
|
1525
1688
|
// Chunk package names to process them in parallel 3 at a time.
|
|
1526
|
-
await (0, _promises2.pEach)(
|
|
1527
|
-
const {
|
|
1528
|
-
added,
|
|
1529
|
-
updated
|
|
1530
|
-
} = await addOverrides({
|
|
1689
|
+
await (0, _promises2.pEach)(workspacePkgJsonPaths, 3, async workspacePkgJsonPath => {
|
|
1690
|
+
const otherState = await addOverrides({
|
|
1531
1691
|
agent,
|
|
1532
1692
|
agentExecPath,
|
|
1533
1693
|
lockSrc,
|
|
1534
1694
|
manifestEntries,
|
|
1695
|
+
npmExecPath,
|
|
1535
1696
|
pin,
|
|
1536
|
-
pkgPath: _nodePath$2.dirname(
|
|
1697
|
+
pkgPath: _nodePath$2.dirname(workspacePkgJsonPath),
|
|
1537
1698
|
prod,
|
|
1538
1699
|
rootPath
|
|
1539
|
-
}
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1700
|
+
}, createAddOverridesState({
|
|
1701
|
+
spinner
|
|
1702
|
+
}));
|
|
1703
|
+
for (const key of ['added', 'addedInWorkspaces', 'updated', 'updatedInWorkspaces']) {
|
|
1704
|
+
for (const value of otherState[key]) {
|
|
1705
|
+
state[key].add(value);
|
|
1706
|
+
}
|
|
1545
1707
|
}
|
|
1546
1708
|
});
|
|
1547
1709
|
}
|
|
1548
|
-
|
|
1549
|
-
if (state.added.size || state.updated.size) {
|
|
1710
|
+
if (state.added.size > 0 || state.updated.size > 0) {
|
|
1550
1711
|
editablePkgJson.update(Object.fromEntries(depEntries));
|
|
1551
1712
|
for (const {
|
|
1552
1713
|
overrides,
|
|
@@ -1558,10 +1719,39 @@ async function addOverrides({
|
|
|
1558
1719
|
}
|
|
1559
1720
|
return state;
|
|
1560
1721
|
}
|
|
1722
|
+
|
|
1723
|
+
// type ExtractOptions = pacote.Options & {
|
|
1724
|
+
// tmpPrefix?: string
|
|
1725
|
+
// [key: string]: any
|
|
1726
|
+
// }
|
|
1727
|
+
|
|
1728
|
+
// async function extractPackage(pkgNameOrId: string, options: ExtractOptions | undefined, callback: (tmpDirPath: string) => any) {
|
|
1729
|
+
// if (arguments.length === 2 && typeof options === 'function') {
|
|
1730
|
+
// callback = options
|
|
1731
|
+
// options = undefined
|
|
1732
|
+
// }
|
|
1733
|
+
// const { tmpPrefix, ...extractOptions } = { __proto__: null, ...options }
|
|
1734
|
+
// // cacache.tmp.withTmp DOES return a promise.
|
|
1735
|
+
// await cacache.tmp.withTmp(
|
|
1736
|
+
// pacoteCachePath,
|
|
1737
|
+
// { tmpPrefix },
|
|
1738
|
+
// // eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
1739
|
+
// async tmpDirPath => {
|
|
1740
|
+
// await pacote.extract(pkgNameOrId, tmpDirPath, {
|
|
1741
|
+
// __proto__: null,
|
|
1742
|
+
// packumentCache,
|
|
1743
|
+
// preferOffline: true,
|
|
1744
|
+
// ...<Omit<typeof extractOptions, '__proto__'>>extractOptions
|
|
1745
|
+
// })
|
|
1746
|
+
// await callback(tmpDirPath)
|
|
1747
|
+
// }
|
|
1748
|
+
// )
|
|
1749
|
+
// }
|
|
1750
|
+
|
|
1561
1751
|
async function fetchPackageManifest(pkgNameOrId, options) {
|
|
1562
1752
|
const pacoteOptions = {
|
|
1563
1753
|
...options,
|
|
1564
|
-
packumentCache,
|
|
1754
|
+
packumentCache: _constants.packumentCache,
|
|
1565
1755
|
preferOffline: true
|
|
1566
1756
|
};
|
|
1567
1757
|
const {
|
|
@@ -1596,9 +1786,11 @@ const optimize = optimize$1.optimize = {
|
|
|
1596
1786
|
const {
|
|
1597
1787
|
agent,
|
|
1598
1788
|
agentExecPath,
|
|
1599
|
-
|
|
1789
|
+
agentVersion,
|
|
1600
1790
|
lockPath,
|
|
1791
|
+
lockSrc,
|
|
1601
1792
|
minimumNodeVersion,
|
|
1793
|
+
npmExecPath,
|
|
1602
1794
|
pkgJson,
|
|
1603
1795
|
pkgPath,
|
|
1604
1796
|
supported
|
|
@@ -1612,67 +1804,84 @@ const optimize = optimize$1.optimize = {
|
|
|
1612
1804
|
console.log(`✘ ${COMMAND_TITLE}: No supported Node or browser range detected`);
|
|
1613
1805
|
return;
|
|
1614
1806
|
}
|
|
1807
|
+
if (agent === 'vlt') {
|
|
1808
|
+
console.log(`✘ ${COMMAND_TITLE}: ${agent} does not support overrides. Soon, though ⚡`);
|
|
1809
|
+
return;
|
|
1810
|
+
}
|
|
1615
1811
|
const lockName = lockPath ? _nodePath$2.basename(lockPath) : 'lock file';
|
|
1616
1812
|
if (lockSrc === undefined) {
|
|
1617
1813
|
console.log(`✘ ${COMMAND_TITLE}: No ${lockName} found`);
|
|
1618
1814
|
return;
|
|
1619
1815
|
}
|
|
1816
|
+
if (lockSrc.trim() === '') {
|
|
1817
|
+
console.log(`✘ ${COMMAND_TITLE}: ${lockName} is empty`);
|
|
1818
|
+
return;
|
|
1819
|
+
}
|
|
1620
1820
|
if (pkgPath === undefined) {
|
|
1621
1821
|
console.log(`✘ ${COMMAND_TITLE}: No package.json found`);
|
|
1622
1822
|
return;
|
|
1623
1823
|
}
|
|
1824
|
+
if (prod && (agent === 'bun' || agent === 'yarn/berry')) {
|
|
1825
|
+
console.log(`✘ ${COMMAND_TITLE}: --prod not supported for ${agent}${agentVersion ? `@${agentVersion.toString()}` : ''}`);
|
|
1826
|
+
return;
|
|
1827
|
+
}
|
|
1624
1828
|
if (lockPath && _nodePath$2.relative(cwd, lockPath).startsWith('.')) {
|
|
1625
1829
|
console.log(`⚠️ ${COMMAND_TITLE}: Package ${lockName} found at ${lockPath}`);
|
|
1626
1830
|
}
|
|
1627
|
-
const
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
};
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
}
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
if (
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1831
|
+
const spinner = (0, _ora$i.default)('Socket optimizing...');
|
|
1832
|
+
const state = createAddOverridesState({
|
|
1833
|
+
spinner
|
|
1834
|
+
});
|
|
1835
|
+
spinner.start();
|
|
1836
|
+
const nodeRange = `>=${minimumNodeVersion}`;
|
|
1837
|
+
const manifestEntries = manifestNpmOverrides.filter(({
|
|
1838
|
+
1: data
|
|
1839
|
+
}) => _semver.satisfies(_semver.coerce(data.engines.node), nodeRange));
|
|
1840
|
+
await addOverrides({
|
|
1841
|
+
agent,
|
|
1842
|
+
agentExecPath,
|
|
1843
|
+
lockSrc,
|
|
1844
|
+
manifestEntries,
|
|
1845
|
+
npmExecPath,
|
|
1846
|
+
pin,
|
|
1847
|
+
pkgJson,
|
|
1848
|
+
pkgPath,
|
|
1849
|
+
prod,
|
|
1850
|
+
rootPath: pkgPath
|
|
1851
|
+
}, state);
|
|
1852
|
+
spinner.stop();
|
|
1853
|
+
const addedCount = state.added.size;
|
|
1854
|
+
const updatedCount = state.updated.size;
|
|
1855
|
+
const pkgJsonChanged = addedCount > 0 || updatedCount > 0;
|
|
1856
|
+
if (pkgJsonChanged) {
|
|
1857
|
+
if (updatedCount > 0) {
|
|
1858
|
+
console.log(`${createActionMessage('Updated', updatedCount, state.updatedInWorkspaces.size)}${addedCount ? '.' : '🚀'}`);
|
|
1859
|
+
}
|
|
1860
|
+
if (addedCount > 0) {
|
|
1861
|
+
console.log(`${createActionMessage('Added', addedCount, state.addedInWorkspaces.size)} 🚀`);
|
|
1862
|
+
}
|
|
1863
|
+
} else {
|
|
1656
1864
|
console.log('Congratulations! Already Socket.dev optimized 🎉');
|
|
1657
1865
|
}
|
|
1658
1866
|
const isNpm = agent === 'npm';
|
|
1659
1867
|
if (isNpm || pkgJsonChanged) {
|
|
1660
1868
|
// Always update package-lock.json until the npm overrides PR lands:
|
|
1661
1869
|
// https://github.com/npm/cli/pull/7025
|
|
1662
|
-
|
|
1870
|
+
spinner.start(`Updating ${lockName}...`);
|
|
1663
1871
|
try {
|
|
1664
1872
|
if (isNpm) {
|
|
1665
1873
|
const wrapperPath = _nodePath$2.join(distPath$1, 'npm-cli.js');
|
|
1666
|
-
await _promiseSpawn$2(process.execPath, [wrapperPath, 'install'], {
|
|
1667
|
-
stdio: '
|
|
1874
|
+
await _promiseSpawn$2(process.execPath, [wrapperPath, 'install', '--no-audit', '--no-fund'], {
|
|
1875
|
+
stdio: 'ignore',
|
|
1668
1876
|
env: {
|
|
1669
1877
|
...process.env,
|
|
1670
1878
|
UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE: '1'
|
|
1671
1879
|
}
|
|
1672
1880
|
});
|
|
1673
1881
|
} else {
|
|
1882
|
+
// All package managers support the "install" command.
|
|
1674
1883
|
await _promiseSpawn$2(agentExecPath, ['install'], {
|
|
1675
|
-
stdio: '
|
|
1884
|
+
stdio: 'ignore'
|
|
1676
1885
|
});
|
|
1677
1886
|
}
|
|
1678
1887
|
spinner.stop();
|
|
@@ -2301,8 +2510,8 @@ async function meowWithSubcommands(subcommands, options) {
|
|
|
2301
2510
|
const {
|
|
2302
2511
|
aliases = {},
|
|
2303
2512
|
argv,
|
|
2304
|
-
name,
|
|
2305
2513
|
importMeta,
|
|
2514
|
+
name,
|
|
2306
2515
|
...additionalOptions
|
|
2307
2516
|
} = {
|
|
2308
2517
|
__proto__: null,
|
|
@@ -2430,8 +2639,8 @@ function setupCommand$f(name, description, argv, importMeta) {
|
|
|
2430
2639
|
return;
|
|
2431
2640
|
}
|
|
2432
2641
|
const {
|
|
2433
|
-
|
|
2434
|
-
|
|
2642
|
+
disable,
|
|
2643
|
+
enable
|
|
2435
2644
|
} = cli.flags;
|
|
2436
2645
|
let showHelp = cli.flags['help'];
|
|
2437
2646
|
if (!enable && !disable) {
|
|
@@ -2545,7 +2754,7 @@ Object.defineProperty(create$3, "__esModule", {
|
|
|
2545
2754
|
value: true
|
|
2546
2755
|
});
|
|
2547
2756
|
create$3.create = void 0;
|
|
2548
|
-
var _nodeProcess = require$$0$
|
|
2757
|
+
var _nodeProcess = require$$0$2;
|
|
2549
2758
|
var _promises$1 = require$$2$3;
|
|
2550
2759
|
var _chalk$e = _interopRequireDefault$f(vendor.source);
|
|
2551
2760
|
var _meow$e = _interopRequireDefault$f(vendor.build);
|
|
@@ -2678,8 +2887,8 @@ async function setupCommand$e(name, description, argv, importMeta) {
|
|
|
2678
2887
|
const debugLog = (0, _misc.createDebugLogger)(false);
|
|
2679
2888
|
const packagePaths = await (0, _pathResolve.getPackageFilesFullScans)(cwd, cli.input, supportedFiles, debugLog);
|
|
2680
2889
|
const {
|
|
2681
|
-
|
|
2682
|
-
|
|
2890
|
+
branch: branchName,
|
|
2891
|
+
repo: repoName
|
|
2683
2892
|
} = cli.flags;
|
|
2684
2893
|
if (!repoName || !branchName || !packagePaths.length) {
|
|
2685
2894
|
showHelp = true;
|
|
@@ -2709,14 +2918,14 @@ async function setupCommand$e(name, description, argv, importMeta) {
|
|
|
2709
2918
|
async function createFullScan(input, spinner, apiKey) {
|
|
2710
2919
|
const socketSdk = await (0, _sdk$e.setupSdk)(apiKey);
|
|
2711
2920
|
const {
|
|
2712
|
-
orgSlug,
|
|
2713
|
-
repoName,
|
|
2714
2921
|
branchName,
|
|
2715
2922
|
commitMessage,
|
|
2716
2923
|
defaultBranch,
|
|
2924
|
+
orgSlug,
|
|
2925
|
+
packagePaths,
|
|
2717
2926
|
pendingHead,
|
|
2718
|
-
|
|
2719
|
-
|
|
2927
|
+
repoName,
|
|
2928
|
+
tmp
|
|
2720
2929
|
} = input;
|
|
2721
2930
|
const result = await (0, _apiHelpers$e.handleApiCall)(socketSdk.createOrgFullScan(orgSlug, {
|
|
2722
2931
|
repo: repoName,
|
|
@@ -4021,8 +4230,8 @@ function setupCommand$3(name, description, argv, importMeta) {
|
|
|
4021
4230
|
});
|
|
4022
4231
|
const {
|
|
4023
4232
|
json: outputJson,
|
|
4024
|
-
markdown: outputMarkdown,
|
|
4025
4233
|
limit,
|
|
4234
|
+
markdown: outputMarkdown,
|
|
4026
4235
|
offset
|
|
4027
4236
|
} = cli.flags;
|
|
4028
4237
|
return {
|
|
@@ -4414,7 +4623,7 @@ Object.defineProperty(get$1, "__esModule", {
|
|
|
4414
4623
|
});
|
|
4415
4624
|
get$1.get = void 0;
|
|
4416
4625
|
var _nodeFs$1 = require$$0;
|
|
4417
|
-
var _nodeUtil = require$$0$
|
|
4626
|
+
var _nodeUtil = require$$0$3;
|
|
4418
4627
|
var _chalk$1 = _interopRequireDefault$2(vendor.source);
|
|
4419
4628
|
var _meow$1 = _interopRequireDefault$2(vendor.build);
|
|
4420
4629
|
var _ora$1 = _interopRequireDefault$2(vendor.ora);
|
|
@@ -4492,8 +4701,8 @@ function setupCommand$1(name, description, argv, importMeta) {
|
|
|
4492
4701
|
flags
|
|
4493
4702
|
});
|
|
4494
4703
|
const {
|
|
4495
|
-
|
|
4496
|
-
|
|
4704
|
+
after,
|
|
4705
|
+
before
|
|
4497
4706
|
} = cli.flags;
|
|
4498
4707
|
let showHelp = cli.flags['help'];
|
|
4499
4708
|
if (!before || !after) {
|
|
@@ -4519,10 +4728,10 @@ function setupCommand$1(name, description, argv, importMeta) {
|
|
|
4519
4728
|
};
|
|
4520
4729
|
}
|
|
4521
4730
|
async function getDiffScan({
|
|
4522
|
-
before,
|
|
4523
4731
|
after,
|
|
4524
|
-
|
|
4732
|
+
before,
|
|
4525
4733
|
file,
|
|
4734
|
+
orgSlug,
|
|
4526
4735
|
outputJson
|
|
4527
4736
|
}, spinner, apiKey) {
|
|
4528
4737
|
const response = await (0, _apiHelpers$1.queryAPI)(`${orgSlug}/full-scans/diff?before=${before}&after=${after}&preview`, apiKey);
|
|
@@ -4668,12 +4877,12 @@ function setupCommand(name, description, argv, importMeta) {
|
|
|
4668
4877
|
flags
|
|
4669
4878
|
});
|
|
4670
4879
|
const {
|
|
4880
|
+
direction,
|
|
4881
|
+
filter,
|
|
4671
4882
|
json: outputJson,
|
|
4672
4883
|
markdown: outputMarkdown,
|
|
4673
|
-
perPage: per_page,
|
|
4674
4884
|
page,
|
|
4675
|
-
|
|
4676
|
-
filter
|
|
4885
|
+
perPage: per_page
|
|
4677
4886
|
} = cli.flags;
|
|
4678
4887
|
return {
|
|
4679
4888
|
outputJson,
|
|
@@ -4685,11 +4894,11 @@ function setupCommand(name, description, argv, importMeta) {
|
|
|
4685
4894
|
};
|
|
4686
4895
|
}
|
|
4687
4896
|
async function fetchThreatFeed({
|
|
4688
|
-
per_page,
|
|
4689
|
-
page,
|
|
4690
4897
|
direction,
|
|
4691
4898
|
filter,
|
|
4692
|
-
outputJson
|
|
4899
|
+
outputJson,
|
|
4900
|
+
page,
|
|
4901
|
+
per_page
|
|
4693
4902
|
}, spinner, apiKey) {
|
|
4694
4903
|
const formattedQueryParams = formatQueryParams({
|
|
4695
4904
|
per_page,
|