socket 0.14.19 → 0.14.20
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/dist/cli.js +162 -66
- package/dist/npm-injection.js +2 -2
- package/dist/sdk.d.ts +3 -1
- package/dist/sdk.js +10 -3
- package/package.json +1 -1
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}`)
|
|
@@ -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'];
|
|
919
919
|
const numericCollator = new Intl.Collator(undefined, {
|
|
920
920
|
numeric: true,
|
|
921
921
|
sensitivity: 'base'
|
|
@@ -952,7 +952,7 @@ const LOCKS = {
|
|
|
952
952
|
'bun.lockb': 'bun',
|
|
953
953
|
'pnpm-lock.yaml': 'pnpm',
|
|
954
954
|
'pnpm-lock.yml': 'pnpm',
|
|
955
|
-
'yarn.lock': 'yarn',
|
|
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.
|
|
@@ -988,11 +988,12 @@ const readLockFileByAgent = (() => {
|
|
|
988
988
|
} catch {}
|
|
989
989
|
// To print a Yarn lockfile to your console without writing it to disk use `bun bun.lockb`.
|
|
990
990
|
// https://bun.sh/guides/install/yarnlock
|
|
991
|
-
return (await _promiseSpawn$3(agentExecPath, [lockPath])).stdout;
|
|
991
|
+
return (await _promiseSpawn$3(agentExecPath, [lockPath])).stdout.trim();
|
|
992
992
|
}),
|
|
993
993
|
npm: wrapReader(async lockPath => await (0, _fs$1.readFileUtf8)(lockPath)),
|
|
994
994
|
pnpm: wrapReader(async lockPath => await (0, _fs$1.readFileUtf8)(lockPath)),
|
|
995
|
-
yarn: wrapReader(async lockPath => await (0, _fs$1.readFileUtf8)(lockPath))
|
|
995
|
+
'yarn/berry': wrapReader(async lockPath => await (0, _fs$1.readFileUtf8)(lockPath)),
|
|
996
|
+
'yarn/classic': wrapReader(async lockPath => await (0, _fs$1.readFileUtf8)(lockPath))
|
|
996
997
|
};
|
|
997
998
|
})();
|
|
998
999
|
async function detect({
|
|
@@ -1007,10 +1008,11 @@ async function detect({
|
|
|
1007
1008
|
cwd
|
|
1008
1009
|
});
|
|
1009
1010
|
const pkgPath = (0, _fs$1.existsSync)(pkgJsonPath) ? _nodePath$3.dirname(pkgJsonPath) : undefined;
|
|
1010
|
-
const
|
|
1011
|
+
const editablePkgJson = pkgPath ? await _packageJson$1.load(pkgPath) : undefined;
|
|
1012
|
+
const pkgJson = editablePkgJson?.content;
|
|
1011
1013
|
// Read Corepack `packageManager` field in package.json:
|
|
1012
1014
|
// https://nodejs.org/api/packages.html#packagemanager
|
|
1013
|
-
const pkgManager = (0, _strings$1.isNonEmptyString)(pkgJson?.
|
|
1015
|
+
const pkgManager = (0, _strings$1.isNonEmptyString)(pkgJson?.packageManager) ? pkgJson.packageManager : undefined;
|
|
1014
1016
|
let agent;
|
|
1015
1017
|
let agentVersion;
|
|
1016
1018
|
if (pkgManager) {
|
|
@@ -1020,7 +1022,7 @@ async function detect({
|
|
|
1020
1022
|
const version = pkgManager.slice(atSignIndex + 1);
|
|
1021
1023
|
if (version && AGENTS.includes(name)) {
|
|
1022
1024
|
agent = name;
|
|
1023
|
-
agentVersion = version;
|
|
1025
|
+
agentVersion = _semver$1.coerce(version) ?? undefined;
|
|
1024
1026
|
}
|
|
1025
1027
|
}
|
|
1026
1028
|
}
|
|
@@ -1034,6 +1036,18 @@ async function detect({
|
|
|
1034
1036
|
const agentExecPath = (await _which(agent, {
|
|
1035
1037
|
nothrow: true
|
|
1036
1038
|
})) ?? agent;
|
|
1039
|
+
if (agentVersion === undefined) {
|
|
1040
|
+
try {
|
|
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 {}
|
|
1047
|
+
}
|
|
1048
|
+
if (agent === 'yarn/classic' && (agentVersion?.major ?? 0) > 1) {
|
|
1049
|
+
agent = 'yarn/berry';
|
|
1050
|
+
}
|
|
1037
1051
|
const targets = {
|
|
1038
1052
|
browser: false,
|
|
1039
1053
|
node: true
|
|
@@ -1041,18 +1055,18 @@ async function detect({
|
|
|
1041
1055
|
let lockSrc;
|
|
1042
1056
|
let minimumNodeVersion = maintainedNodeVersions.previous;
|
|
1043
1057
|
if (pkgJson) {
|
|
1044
|
-
const browserField = pkgJson.
|
|
1058
|
+
const browserField = pkgJson.browser;
|
|
1045
1059
|
if ((0, _strings$1.isNonEmptyString)(browserField) || (0, _objects$1.isObjectObject)(browserField)) {
|
|
1046
1060
|
targets.browser = true;
|
|
1047
1061
|
}
|
|
1048
|
-
const nodeRange = pkgJson.
|
|
1062
|
+
const nodeRange = pkgJson.engines?.['node'];
|
|
1049
1063
|
if ((0, _strings$1.isNonEmptyString)(nodeRange)) {
|
|
1050
1064
|
const coerced = _semver$1.coerce(nodeRange);
|
|
1051
1065
|
if (coerced && _semver$1.lt(coerced, minimumNodeVersion)) {
|
|
1052
1066
|
minimumNodeVersion = coerced.version;
|
|
1053
1067
|
}
|
|
1054
1068
|
}
|
|
1055
|
-
const browserslistQuery = pkgJson
|
|
1069
|
+
const browserslistQuery = pkgJson['browserslist'];
|
|
1056
1070
|
if (Array.isArray(browserslistQuery)) {
|
|
1057
1071
|
const browserslistTargets = _browserslist(browserslistQuery).map(s => s.toLowerCase()).toSorted(alphaNumericComparator);
|
|
1058
1072
|
const browserslistNodeTargets = browserslistTargets.filter(v => v.startsWith('node ')).map(v => v.slice(5 /*'node '.length*/));
|
|
@@ -1078,7 +1092,7 @@ async function detect({
|
|
|
1078
1092
|
lockPath,
|
|
1079
1093
|
lockSrc,
|
|
1080
1094
|
minimumNodeVersion,
|
|
1081
|
-
pkgJson,
|
|
1095
|
+
pkgJson: editablePkgJson,
|
|
1082
1096
|
pkgPath,
|
|
1083
1097
|
supported: targets.browser || targets.node,
|
|
1084
1098
|
targets
|
|
@@ -1180,10 +1194,11 @@ var _registry = require$$5$1;
|
|
|
1180
1194
|
var _meow$m = _interopRequireDefault$n(vendor.build);
|
|
1181
1195
|
var _npmPackageArg = require$$7;
|
|
1182
1196
|
var _ora$i = _interopRequireDefault$n(vendor.ora);
|
|
1183
|
-
var _pacote = require$$
|
|
1197
|
+
var _pacote = require$$0$1;
|
|
1184
1198
|
var _semver = require$$3;
|
|
1185
1199
|
var _tinyglobby = require$$11;
|
|
1186
1200
|
var _yaml = require$$12;
|
|
1201
|
+
var _constants = sdk.constants;
|
|
1187
1202
|
var _flags$j = flags$1;
|
|
1188
1203
|
var _formatting$k = formatting;
|
|
1189
1204
|
var _fs = fs;
|
|
@@ -1193,18 +1208,21 @@ var _promises2 = promises;
|
|
|
1193
1208
|
var _regexps = regexps;
|
|
1194
1209
|
var _sorts$1 = sorts;
|
|
1195
1210
|
var _strings = strings;
|
|
1211
|
+
//import cacache from 'cacache'
|
|
1212
|
+
|
|
1213
|
+
//import { packumentCache, pacoteCachePath } from '../constants'
|
|
1214
|
+
|
|
1196
1215
|
const COMMAND_TITLE = 'Socket Optimize';
|
|
1197
1216
|
const OVERRIDES_FIELD_NAME = 'overrides';
|
|
1198
1217
|
const PNPM_WORKSPACE = 'pnpm-workspace';
|
|
1199
1218
|
const RESOLUTIONS_FIELD_NAME = 'resolutions';
|
|
1200
1219
|
const distPath$1 = __dirname;
|
|
1201
1220
|
const manifestNpmOverrides = (0, _registry.getManifestData)('npm');
|
|
1202
|
-
const packumentCache = new Map();
|
|
1203
1221
|
const getOverridesDataByAgent = {
|
|
1204
1222
|
bun(pkgJson) {
|
|
1205
1223
|
const overrides = pkgJson?.resolutions ?? {};
|
|
1206
1224
|
return {
|
|
1207
|
-
type: 'yarn',
|
|
1225
|
+
type: 'yarn/berry',
|
|
1208
1226
|
overrides
|
|
1209
1227
|
};
|
|
1210
1228
|
},
|
|
@@ -1228,10 +1246,19 @@ const getOverridesDataByAgent = {
|
|
|
1228
1246
|
},
|
|
1229
1247
|
// Yarn resolutions documentation:
|
|
1230
1248
|
// https://yarnpkg.com/configuration/manifest#resolutions
|
|
1231
|
-
yarn(pkgJson) {
|
|
1249
|
+
'yarn/berry'(pkgJson) {
|
|
1232
1250
|
const overrides = pkgJson?.resolutions ?? {};
|
|
1233
1251
|
return {
|
|
1234
|
-
type: 'yarn',
|
|
1252
|
+
type: 'yarn/berry',
|
|
1253
|
+
overrides
|
|
1254
|
+
};
|
|
1255
|
+
},
|
|
1256
|
+
// Yarn resolutions documentation:
|
|
1257
|
+
// https://classic.yarnpkg.com/en/docs/selective-version-resolutions
|
|
1258
|
+
'yarn/classic'(pkgJson) {
|
|
1259
|
+
const overrides = pkgJson?.resolutions ?? {};
|
|
1260
|
+
return {
|
|
1261
|
+
type: 'yarn/classic',
|
|
1235
1262
|
overrides
|
|
1236
1263
|
};
|
|
1237
1264
|
}
|
|
@@ -1264,7 +1291,8 @@ const lockIncludesByAgent = (() => {
|
|
|
1264
1291
|
// name@
|
|
1265
1292
|
`(?<=^\\s*)(?:(['/])${escapedName}\\1|${escapedName}(?=[:@]))`, 'm').test(lockSrc);
|
|
1266
1293
|
},
|
|
1267
|
-
yarn
|
|
1294
|
+
'yarn/berry': yarn,
|
|
1295
|
+
'yarn/classic': yarn
|
|
1268
1296
|
};
|
|
1269
1297
|
})();
|
|
1270
1298
|
const updateManifestByAgent = {
|
|
@@ -1286,7 +1314,12 @@ const updateManifestByAgent = {
|
|
|
1286
1314
|
}
|
|
1287
1315
|
});
|
|
1288
1316
|
},
|
|
1289
|
-
yarn(pkgJson, overrides) {
|
|
1317
|
+
'yarn/berry'(pkgJson, overrides) {
|
|
1318
|
+
pkgJson.update({
|
|
1319
|
+
[RESOLUTIONS_FIELD_NAME]: overrides
|
|
1320
|
+
});
|
|
1321
|
+
},
|
|
1322
|
+
'yarn/classic'(pkgJson, overrides) {
|
|
1290
1323
|
pkgJson.update({
|
|
1291
1324
|
[RESOLUTIONS_FIELD_NAME]: overrides
|
|
1292
1325
|
});
|
|
@@ -1310,8 +1343,10 @@ const lsByAgent = {
|
|
|
1310
1343
|
} = await _promiseSpawn$2(agentExecPath, ['ls', '--parseable', '--omit', 'dev', '--all'], {
|
|
1311
1344
|
cwd
|
|
1312
1345
|
});
|
|
1346
|
+
stdout = stdout.trim();
|
|
1313
1347
|
stdout = stdout.replaceAll(cwd, '');
|
|
1314
|
-
|
|
1348
|
+
stdout = rootPath === cwd ? stdout : stdout.replaceAll(rootPath, '');
|
|
1349
|
+
return stdout.replaceAll('\\', '/');
|
|
1315
1350
|
} catch {}
|
|
1316
1351
|
return '';
|
|
1317
1352
|
},
|
|
@@ -1322,35 +1357,44 @@ const lsByAgent = {
|
|
|
1322
1357
|
} = await _promiseSpawn$2(agentExecPath, ['ls', '--parseable', '--prod', '--depth', 'Infinity'], {
|
|
1323
1358
|
cwd
|
|
1324
1359
|
});
|
|
1360
|
+
stdout = stdout.trim();
|
|
1325
1361
|
stdout = stdout.replaceAll(cwd, '');
|
|
1326
|
-
|
|
1362
|
+
stdout = rootPath === cwd ? stdout : stdout.replaceAll(rootPath, '');
|
|
1363
|
+
return stdout.replaceAll('\\', '/');
|
|
1327
1364
|
} catch {}
|
|
1328
1365
|
return '';
|
|
1329
1366
|
},
|
|
1330
|
-
async yarn(agentExecPath, cwd, _rootPath) {
|
|
1367
|
+
async 'yarn/berry'(agentExecPath, cwd, _rootPath) {
|
|
1331
1368
|
try {
|
|
1332
1369
|
return (
|
|
1333
1370
|
// Yarn Berry does not support filtering by production packages yet.
|
|
1334
1371
|
// https://github.com/yarnpkg/berry/issues/5117
|
|
1335
1372
|
(await _promiseSpawn$2(agentExecPath, ['info', '--recursive', '--name-only'], {
|
|
1336
1373
|
cwd
|
|
1337
|
-
})).stdout
|
|
1374
|
+
})).stdout.trim()
|
|
1338
1375
|
);
|
|
1339
1376
|
} catch {}
|
|
1377
|
+
return '';
|
|
1378
|
+
},
|
|
1379
|
+
async 'yarn/classic'(agentExecPath, cwd, _rootPath) {
|
|
1340
1380
|
try {
|
|
1341
1381
|
// However, Yarn Classic does support it.
|
|
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
|
|
1342
1385
|
return (await _promiseSpawn$2(agentExecPath, ['list', '--prod'], {
|
|
1343
1386
|
cwd
|
|
1344
|
-
})).stdout;
|
|
1387
|
+
})).stdout.trim();
|
|
1345
1388
|
} catch {}
|
|
1346
1389
|
return '';
|
|
1347
1390
|
}
|
|
1348
1391
|
};
|
|
1349
1392
|
const depsIncludesByAgent = {
|
|
1350
|
-
bun: (stdout, name) => stdout.includes(name),
|
|
1351
|
-
npm: (stdout, name) => stdout.includes(name),
|
|
1352
|
-
pnpm: (stdout, name) => stdout.includes(name),
|
|
1353
|
-
yarn: (stdout, name) => stdout.includes(name)
|
|
1393
|
+
bun: (stdout, name) => stdout.includes(` ${name}@`),
|
|
1394
|
+
npm: (stdout, name) => stdout.includes(`/${name}\n`),
|
|
1395
|
+
pnpm: (stdout, name) => stdout.includes(`/${name}\n`),
|
|
1396
|
+
'yarn/berry': (stdout, name) => stdout.includes(` ${name}@`),
|
|
1397
|
+
'yarn/classic': (stdout, name) => stdout.includes(` ${name}@`)
|
|
1354
1398
|
};
|
|
1355
1399
|
function getDependencyEntries(pkgJson) {
|
|
1356
1400
|
const {
|
|
@@ -1420,11 +1464,15 @@ async function addOverrides({
|
|
|
1420
1464
|
rootPath
|
|
1421
1465
|
}, state = {
|
|
1422
1466
|
added: new Set(),
|
|
1467
|
+
spinner: undefined,
|
|
1423
1468
|
updated: new Set()
|
|
1424
1469
|
}) {
|
|
1425
1470
|
if (editablePkgJson === undefined) {
|
|
1426
1471
|
editablePkgJson = await _packageJson.load(pkgPath);
|
|
1427
1472
|
}
|
|
1473
|
+
const {
|
|
1474
|
+
spinner
|
|
1475
|
+
} = state;
|
|
1428
1476
|
const pkgJson = editablePkgJson.content;
|
|
1429
1477
|
const isRoot = pkgPath === rootPath;
|
|
1430
1478
|
const isLockScanned = isRoot && !prod;
|
|
@@ -1437,9 +1485,11 @@ async function addOverrides({
|
|
|
1437
1485
|
if (pkgJson['private'] || isWorkspace) {
|
|
1438
1486
|
overridesDataObjects.push(getOverridesDataByAgent[agent](pkgJson));
|
|
1439
1487
|
} else {
|
|
1440
|
-
overridesDataObjects.push(getOverridesDataByAgent['npm'](pkgJson), getOverridesDataByAgent['yarn'](pkgJson));
|
|
1488
|
+
overridesDataObjects.push(getOverridesDataByAgent['npm'](pkgJson), getOverridesDataByAgent['yarn/classic'](pkgJson));
|
|
1489
|
+
}
|
|
1490
|
+
if (spinner) {
|
|
1491
|
+
spinner.text = `Adding overrides${isRoot ? '' : ` to ${_nodePath$2.relative(rootPath, pkgPath)}`}...`;
|
|
1441
1492
|
}
|
|
1442
|
-
const spinner = isRoot ? (0, _ora$i.default)('Fetching override manifests...').start() : undefined;
|
|
1443
1493
|
const depAliasMap = new Map();
|
|
1444
1494
|
// Chunk package names to process them in parallel 3 at a time.
|
|
1445
1495
|
await (0, _promises2.pEach)(manifestEntries, 3, async ({
|
|
@@ -1520,7 +1570,8 @@ async function addOverrides({
|
|
|
1520
1570
|
if (workspaces) {
|
|
1521
1571
|
const wsPkgJsonPaths = await (0, _tinyglobby.glob)(workspaces.map(workspaceToGlobPattern), {
|
|
1522
1572
|
absolute: true,
|
|
1523
|
-
cwd: pkgPath
|
|
1573
|
+
cwd: pkgPath,
|
|
1574
|
+
ignore: ['**/node_modules/**', '**/bower_components/**']
|
|
1524
1575
|
});
|
|
1525
1576
|
// Chunk package names to process them in parallel 3 at a time.
|
|
1526
1577
|
await (0, _promises2.pEach)(wsPkgJsonPaths, 3, async wsPkgJsonPath => {
|
|
@@ -1536,6 +1587,10 @@ async function addOverrides({
|
|
|
1536
1587
|
pkgPath: _nodePath$2.dirname(wsPkgJsonPath),
|
|
1537
1588
|
prod,
|
|
1538
1589
|
rootPath
|
|
1590
|
+
}, {
|
|
1591
|
+
added: new Set(),
|
|
1592
|
+
spinner,
|
|
1593
|
+
updated: new Set()
|
|
1539
1594
|
});
|
|
1540
1595
|
for (const regPkgName of added) {
|
|
1541
1596
|
state.added.add(regPkgName);
|
|
@@ -1545,8 +1600,7 @@ async function addOverrides({
|
|
|
1545
1600
|
}
|
|
1546
1601
|
});
|
|
1547
1602
|
}
|
|
1548
|
-
|
|
1549
|
-
if (state.added.size || state.updated.size) {
|
|
1603
|
+
if (state.added.size > 0 || state.updated.size > 0) {
|
|
1550
1604
|
editablePkgJson.update(Object.fromEntries(depEntries));
|
|
1551
1605
|
for (const {
|
|
1552
1606
|
overrides,
|
|
@@ -1558,10 +1612,39 @@ async function addOverrides({
|
|
|
1558
1612
|
}
|
|
1559
1613
|
return state;
|
|
1560
1614
|
}
|
|
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
|
+
|
|
1561
1644
|
async function fetchPackageManifest(pkgNameOrId, options) {
|
|
1562
1645
|
const pacoteOptions = {
|
|
1563
1646
|
...options,
|
|
1564
|
-
packumentCache,
|
|
1647
|
+
packumentCache: _constants.packumentCache,
|
|
1565
1648
|
preferOffline: true
|
|
1566
1649
|
};
|
|
1567
1650
|
const {
|
|
@@ -1596,6 +1679,7 @@ const optimize = optimize$1.optimize = {
|
|
|
1596
1679
|
const {
|
|
1597
1680
|
agent,
|
|
1598
1681
|
agentExecPath,
|
|
1682
|
+
agentVersion,
|
|
1599
1683
|
lockSrc,
|
|
1600
1684
|
lockPath,
|
|
1601
1685
|
minimumNodeVersion,
|
|
@@ -1617,53 +1701,64 @@ const optimize = optimize$1.optimize = {
|
|
|
1617
1701
|
console.log(`✘ ${COMMAND_TITLE}: No ${lockName} found`);
|
|
1618
1702
|
return;
|
|
1619
1703
|
}
|
|
1704
|
+
if (lockSrc.trim() === '') {
|
|
1705
|
+
console.log(`✘ ${COMMAND_TITLE}: ${lockName} is empty`);
|
|
1706
|
+
return;
|
|
1707
|
+
}
|
|
1620
1708
|
if (pkgPath === undefined) {
|
|
1621
1709
|
console.log(`✘ ${COMMAND_TITLE}: No package.json found`);
|
|
1622
1710
|
return;
|
|
1623
1711
|
}
|
|
1712
|
+
if (prod && (agent === 'bun' || agent === 'yarn/berry')) {
|
|
1713
|
+
console.log(`✘ ${COMMAND_TITLE}: --prod not supported for ${agent}${agentVersion ? `@${agentVersion.toString()}` : ''}`);
|
|
1714
|
+
return;
|
|
1715
|
+
}
|
|
1624
1716
|
if (lockPath && _nodePath$2.relative(cwd, lockPath).startsWith('.')) {
|
|
1625
1717
|
console.log(`⚠️ ${COMMAND_TITLE}: Package ${lockName} found at ${lockPath}`);
|
|
1626
1718
|
}
|
|
1719
|
+
const spinner = (0, _ora$i.default)('Socket optimizing...');
|
|
1627
1720
|
const state = {
|
|
1628
1721
|
added: new Set(),
|
|
1722
|
+
spinner,
|
|
1629
1723
|
updated: new Set()
|
|
1630
1724
|
};
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1725
|
+
spinner.start();
|
|
1726
|
+
const nodeRange = `>=${minimumNodeVersion}`;
|
|
1727
|
+
const manifestEntries = manifestNpmOverrides.filter(({
|
|
1728
|
+
1: data
|
|
1729
|
+
}) => _semver.satisfies(_semver.coerce(data.engines.node), nodeRange));
|
|
1730
|
+
await addOverrides({
|
|
1731
|
+
agent,
|
|
1732
|
+
agentExecPath,
|
|
1733
|
+
lockSrc,
|
|
1734
|
+
manifestEntries,
|
|
1735
|
+
pin,
|
|
1736
|
+
pkgJson,
|
|
1737
|
+
pkgPath,
|
|
1738
|
+
prod,
|
|
1739
|
+
rootPath: pkgPath
|
|
1740
|
+
}, state);
|
|
1741
|
+
spinner.stop();
|
|
1648
1742
|
const pkgJsonChanged = state.added.size > 0 || state.updated.size > 0;
|
|
1649
|
-
if (
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1743
|
+
if (pkgJsonChanged) {
|
|
1744
|
+
if (state.updated.size > 0) {
|
|
1745
|
+
console.log(`Updated ${state.updated.size} Socket.dev optimized overrides ${state.added.size ? '.' : '🚀'}`);
|
|
1746
|
+
}
|
|
1747
|
+
if (state.added.size > 0) {
|
|
1748
|
+
console.log(`Added ${state.added.size} Socket.dev optimized overrides 🚀`);
|
|
1749
|
+
}
|
|
1750
|
+
} else {
|
|
1656
1751
|
console.log('Congratulations! Already Socket.dev optimized 🎉');
|
|
1657
1752
|
}
|
|
1658
1753
|
const isNpm = agent === 'npm';
|
|
1659
1754
|
if (isNpm || pkgJsonChanged) {
|
|
1660
1755
|
// Always update package-lock.json until the npm overrides PR lands:
|
|
1661
1756
|
// https://github.com/npm/cli/pull/7025
|
|
1662
|
-
|
|
1757
|
+
spinner.start(`Updating ${lockName}...`);
|
|
1663
1758
|
try {
|
|
1664
1759
|
if (isNpm) {
|
|
1665
1760
|
const wrapperPath = _nodePath$2.join(distPath$1, 'npm-cli.js');
|
|
1666
|
-
await _promiseSpawn$2(process.execPath, [wrapperPath, 'install'], {
|
|
1761
|
+
await _promiseSpawn$2(process.execPath, [wrapperPath, 'install', '--no-audit', '--no-fund'], {
|
|
1667
1762
|
stdio: 'pipe',
|
|
1668
1763
|
env: {
|
|
1669
1764
|
...process.env,
|
|
@@ -1671,6 +1766,7 @@ const optimize = optimize$1.optimize = {
|
|
|
1671
1766
|
}
|
|
1672
1767
|
});
|
|
1673
1768
|
} else {
|
|
1769
|
+
// All package managers support the "install" command.
|
|
1674
1770
|
await _promiseSpawn$2(agentExecPath, ['install'], {
|
|
1675
1771
|
stdio: 'pipe'
|
|
1676
1772
|
});
|
|
@@ -2545,7 +2641,7 @@ Object.defineProperty(create$3, "__esModule", {
|
|
|
2545
2641
|
value: true
|
|
2546
2642
|
});
|
|
2547
2643
|
create$3.create = void 0;
|
|
2548
|
-
var _nodeProcess = require$$0$
|
|
2644
|
+
var _nodeProcess = require$$0$2;
|
|
2549
2645
|
var _promises$1 = require$$2$3;
|
|
2550
2646
|
var _chalk$e = _interopRequireDefault$f(vendor.source);
|
|
2551
2647
|
var _meow$e = _interopRequireDefault$f(vendor.build);
|
|
@@ -4414,7 +4510,7 @@ Object.defineProperty(get$1, "__esModule", {
|
|
|
4414
4510
|
});
|
|
4415
4511
|
get$1.get = void 0;
|
|
4416
4512
|
var _nodeFs$1 = require$$0;
|
|
4417
|
-
var _nodeUtil = require$$0$
|
|
4513
|
+
var _nodeUtil = require$$0$3;
|
|
4418
4514
|
var _chalk$1 = _interopRequireDefault$2(vendor.source);
|
|
4419
4515
|
var _meow$1 = _interopRequireDefault$2(vendor.build);
|
|
4420
4516
|
var _ora$1 = _interopRequireDefault$2(vendor.ora);
|
package/dist/npm-injection.js
CHANGED
|
@@ -17,7 +17,7 @@ var require$$1$1 = require('node:net');
|
|
|
17
17
|
var require$$2 = require('node:os');
|
|
18
18
|
var require$$6 = require('../package.json');
|
|
19
19
|
var pathResolve = require('./path-resolve.js');
|
|
20
|
-
var require$$
|
|
20
|
+
var require$$0$1 = require('pacote');
|
|
21
21
|
|
|
22
22
|
var npmInjection$1 = {};
|
|
23
23
|
|
|
@@ -444,7 +444,7 @@ let tarball;
|
|
|
444
444
|
try {
|
|
445
445
|
tarball = require(_nodePath$1.join(npmNmPath, 'pacote')).tarball;
|
|
446
446
|
} catch {
|
|
447
|
-
tarball = require$$
|
|
447
|
+
tarball = require$$0$1.tarball;
|
|
448
448
|
}
|
|
449
449
|
const Arborist = require(arboristClassPath);
|
|
450
450
|
const Edge = require(arboristEdgeClassPath);
|
package/dist/sdk.d.ts
CHANGED
|
@@ -14,7 +14,9 @@ declare const API_V0_URL = "https://api.socket.dev/v0";
|
|
|
14
14
|
declare const ENV: Readonly<{
|
|
15
15
|
UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE: boolean;
|
|
16
16
|
}>;
|
|
17
|
+
declare const packumentCache: Map<any, any>;
|
|
18
|
+
declare const pacoteCachePath: any;
|
|
17
19
|
declare const FREE_API_KEY = "sktsec_t_--RAN5U4ivauy4w37-6aoKyYPDt5ZbaT5JBVMqiwKo_api";
|
|
18
20
|
declare function getDefaultKey(): string | undefined;
|
|
19
21
|
declare function setupSdk(apiKey?: string | undefined, apiBaseUrl?: string | undefined, proxy?: string | undefined): Promise<SocketSdk>;
|
|
20
|
-
export { hasOwn, isObject, isObjectObject, objectSome, pick, createDebugLogger, isErrnoException, stringJoinWithSeparateFinalSeparator, API_V0_URL, ENV, FREE_API_KEY, getDefaultKey, setupSdk };
|
|
22
|
+
export { hasOwn, isObject, isObjectObject, objectSome, pick, createDebugLogger, isErrnoException, stringJoinWithSeparateFinalSeparator, API_V0_URL, ENV, packumentCache, pacoteCachePath, FREE_API_KEY, getDefaultKey, setupSdk };
|
package/dist/sdk.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var require$$0 = require('pacote');
|
|
3
4
|
var vendor = require('./vendor.js');
|
|
4
5
|
var require$$1$1 = require('node:fs/promises');
|
|
5
6
|
var require$$1 = require('node:path');
|
|
6
7
|
var require$$1$2 = require('@inquirer/prompts');
|
|
7
8
|
var require$$4 = require('@socketsecurity/sdk');
|
|
8
9
|
var require$$5 = require('hpagent');
|
|
9
|
-
var require$$0 = require('node:fs');
|
|
10
|
+
var require$$0$1 = require('node:fs');
|
|
10
11
|
var require$$2 = require('node:os');
|
|
11
12
|
|
|
12
13
|
var errors = {};
|
|
@@ -30,7 +31,8 @@ var constants = {};
|
|
|
30
31
|
Object.defineProperty(constants, "__esModule", {
|
|
31
32
|
value: true
|
|
32
33
|
});
|
|
33
|
-
constants.ENV = constants.API_V0_URL = void 0;
|
|
34
|
+
constants.pacoteCachePath = constants.packumentCache = constants.ENV = constants.API_V0_URL = void 0;
|
|
35
|
+
var _pacote = require$$0;
|
|
34
36
|
function envAsBoolean(value) {
|
|
35
37
|
return typeof value === 'string' && (value === '1' || value.toLowerCase() === 'true');
|
|
36
38
|
}
|
|
@@ -39,6 +41,11 @@ constants.ENV = Object.freeze({
|
|
|
39
41
|
// Flag set by the optimize command to bypass the packagesHaveRiskyIssues check.
|
|
40
42
|
UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE: envAsBoolean(process.env['UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE'])
|
|
41
43
|
});
|
|
44
|
+
constants.packumentCache = new Map();
|
|
45
|
+
const {
|
|
46
|
+
constructor: PacoteFetcherBase
|
|
47
|
+
} = Reflect.getPrototypeOf(_pacote.RegistryFetcher.prototype);
|
|
48
|
+
constants.pacoteCachePath = new PacoteFetcherBase(/*dummy package spec*/'x', {}).cache;
|
|
42
49
|
|
|
43
50
|
var chalkMarkdown = {};
|
|
44
51
|
|
|
@@ -189,7 +196,7 @@ Object.defineProperty(settings$1, "__esModule", {
|
|
|
189
196
|
});
|
|
190
197
|
settings$1.getSetting = getSetting;
|
|
191
198
|
settings$1.updateSetting = updateSetting;
|
|
192
|
-
var _nodeFs = require$$0;
|
|
199
|
+
var _nodeFs = require$$0$1;
|
|
193
200
|
var _nodeOs = require$$2;
|
|
194
201
|
var _nodePath$1 = require$$1;
|
|
195
202
|
var _ora = _interopRequireDefault$1(vendor.ora);
|