@socketsecurity/cli 0.14.58 → 0.14.60
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/cli.js +5 -5
- package/dist/constants.d.ts +13 -13
- package/dist/constants.js +38 -41
- package/dist/constants.js.map +1 -1
- package/dist/module-sync/cli.js +267 -213
- package/dist/module-sync/cli.js.map +1 -1
- package/dist/module-sync/shadow-bin.d.ts +1 -1
- package/dist/module-sync/shadow-bin.js +15 -12
- package/dist/module-sync/shadow-bin.js.map +1 -1
- package/dist/module-sync/shadow-npm-inject.js +51 -19
- package/dist/module-sync/shadow-npm-inject.js.map +1 -1
- package/dist/module-sync/shadow-npm-paths.js +15 -11
- package/dist/module-sync/shadow-npm-paths.js.map +1 -1
- package/dist/require/cli.js +267 -213
- package/dist/require/cli.js.map +1 -1
- package/dist/require/vendor.js +90 -5
- package/dist/require/vendor.js.map +1 -1
- package/package.json +18 -18
package/dist/require/cli.js
CHANGED
|
@@ -900,19 +900,20 @@ class GitHub {
|
|
|
900
900
|
case 'push':
|
|
901
901
|
return this.prNumber ? 'diff' : 'main';
|
|
902
902
|
case 'pull_request':
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
903
|
+
{
|
|
904
|
+
// This env variable needs to be set in the GitHub action.
|
|
905
|
+
// Add this code below to GitHub action:
|
|
906
|
+
// - steps:
|
|
907
|
+
// - name: Get PR State
|
|
908
|
+
// if: github.event_name == 'pull_request'
|
|
909
|
+
// run: echo "EVENT_ACTION=${{ github.event.action }}" >> $GITHUB_ENV
|
|
910
|
+
const eventAction = process.env['EVENT_ACTION'];
|
|
911
|
+
if (eventAction === 'opened' || eventAction === 'synchronize') {
|
|
912
|
+
return 'diff';
|
|
913
|
+
}
|
|
914
|
+
if (!eventAction) {
|
|
915
|
+
throw new Error('Missing event action');
|
|
916
|
+
}
|
|
916
917
|
logger.logger.log(`Pull request action: ${eventAction} is not supported`);
|
|
917
918
|
process.exit();
|
|
918
919
|
}
|
|
@@ -1515,14 +1516,14 @@ function emitBanner(name) {
|
|
|
1515
1516
|
// It also helps with debugging since it contains version and command details.
|
|
1516
1517
|
// Note: print over stderr to preserve stdout for flags like --json and
|
|
1517
1518
|
// --markdown. If we don't do this, you can't use --json in particular
|
|
1518
|
-
// and pipe the result to other tools. By
|
|
1519
|
+
// and pipe the result to other tools. By emitting the banner over stderr
|
|
1519
1520
|
// you can do something like `socket scan view xyz | jq | process`.
|
|
1520
1521
|
// The spinner also emits over stderr for example.
|
|
1521
1522
|
logger.logger.error(getAsciiHeader(name));
|
|
1522
1523
|
}
|
|
1523
1524
|
function getAsciiHeader(command) {
|
|
1524
|
-
const cliVersion = // The '@rollup/plugin-replace' will replace "process.env['
|
|
1525
|
-
"0.14.
|
|
1525
|
+
const cliVersion = // The '@rollup/plugin-replace' will replace "process.env['INLINED_SOCKET_CLI_VERSION_HASH']".
|
|
1526
|
+
"0.14.60:48319f6:78cf0eae:pub";
|
|
1526
1527
|
const nodeVersion = process.version;
|
|
1527
1528
|
const apiToken = shadowNpmInject.getSetting('apiToken');
|
|
1528
1529
|
const shownToken = apiToken ? getLastFiveOfApiToken(apiToken) : 'no';
|
|
@@ -2255,30 +2256,45 @@ async function run$x(argv, importMeta, {
|
|
|
2255
2256
|
}
|
|
2256
2257
|
|
|
2257
2258
|
const {
|
|
2258
|
-
NPM: NPM$
|
|
2259
|
+
NPM: NPM$f,
|
|
2259
2260
|
NPX: NPX$3,
|
|
2260
|
-
|
|
2261
|
+
PACKAGE_LOCK_JSON,
|
|
2262
|
+
PNPM: PNPM$a,
|
|
2263
|
+
YARN: YARN$1,
|
|
2264
|
+
YARN_LOCK
|
|
2261
2265
|
} = constants;
|
|
2262
|
-
const nodejsPlatformTypes = new Set(['javascript', 'js', 'nodejs', NPM$
|
|
2263
|
-
async function runCycloneDX(
|
|
2266
|
+
const nodejsPlatformTypes = new Set(['javascript', 'js', 'nodejs', NPM$f, PNPM$a, 'ts', 'tsx', 'typescript']);
|
|
2267
|
+
async function runCycloneDX(yargvWithYes) {
|
|
2264
2268
|
let cleanupPackageLock = false;
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2269
|
+
const {
|
|
2270
|
+
yes,
|
|
2271
|
+
...yargv
|
|
2272
|
+
} = {
|
|
2273
|
+
__proto__: null,
|
|
2274
|
+
...yargvWithYes
|
|
2275
|
+
};
|
|
2276
|
+
const yesArgs = yes ? ['--yes'] : [];
|
|
2277
|
+
if (yargv.type !== YARN$1 && nodejsPlatformTypes.has(yargv.type) && fs.existsSync(`./${YARN_LOCK}`)) {
|
|
2278
|
+
if (fs.existsSync(`./${PACKAGE_LOCK_JSON}`)) {
|
|
2279
|
+
yargv.type = NPM$f;
|
|
2268
2280
|
} else {
|
|
2269
2281
|
// Use synp to create a package-lock.json from the yarn.lock,
|
|
2270
2282
|
// based on the node_modules folder, for a more accurate SBOM.
|
|
2271
2283
|
try {
|
|
2272
|
-
await shadowBin(NPX$3, [
|
|
2273
|
-
|
|
2284
|
+
await shadowBin(NPX$3, [...yesArgs,
|
|
2285
|
+
// The '@rollup/plugin-replace' will replace "process.env['INLINED_SYNP_VERSION']".
|
|
2286
|
+
`synp@${"^1.9.14"}`, '--source-file', `./${YARN_LOCK}`]);
|
|
2287
|
+
yargv.type = NPM$f;
|
|
2274
2288
|
cleanupPackageLock = true;
|
|
2275
2289
|
} catch {}
|
|
2276
2290
|
}
|
|
2277
2291
|
}
|
|
2278
|
-
await shadowBin(NPX$3, [
|
|
2292
|
+
await shadowBin(NPX$3, [...yesArgs,
|
|
2293
|
+
// The '@rollup/plugin-replace' will replace "process.env['INLINED_CYCLONEDX_CDXGEN_VERSION']".
|
|
2294
|
+
`@cyclonedx/cdxgen@${"^11.2.1"}`, ...argvToArray(yargv)]);
|
|
2279
2295
|
if (cleanupPackageLock) {
|
|
2280
2296
|
try {
|
|
2281
|
-
await fs.promises.rm(
|
|
2297
|
+
await fs.promises.rm(`./${PACKAGE_LOCK_JSON}`);
|
|
2282
2298
|
} catch {}
|
|
2283
2299
|
}
|
|
2284
2300
|
const fullOutputPath = path.join(process$1.cwd(), yargv.output);
|
|
@@ -2287,13 +2303,17 @@ async function runCycloneDX(yargv) {
|
|
|
2287
2303
|
}
|
|
2288
2304
|
}
|
|
2289
2305
|
function argvToArray(argv) {
|
|
2290
|
-
if (argv['help'])
|
|
2306
|
+
if (argv['help']) {
|
|
2307
|
+
return ['--help'];
|
|
2308
|
+
}
|
|
2291
2309
|
const result = [];
|
|
2292
2310
|
for (const {
|
|
2293
2311
|
0: key,
|
|
2294
2312
|
1: value
|
|
2295
2313
|
} of Object.entries(argv)) {
|
|
2296
|
-
if (key === '_' || key === '--')
|
|
2314
|
+
if (key === '_' || key === '--') {
|
|
2315
|
+
continue;
|
|
2316
|
+
}
|
|
2297
2317
|
if (key === 'babel' || key === 'install-deps' || key === 'validate') {
|
|
2298
2318
|
// cdxgen documents no-babel, no-install-deps, and no-validate flags so
|
|
2299
2319
|
// use them when relevant.
|
|
@@ -2312,6 +2332,32 @@ function argvToArray(argv) {
|
|
|
2312
2332
|
return result;
|
|
2313
2333
|
}
|
|
2314
2334
|
|
|
2335
|
+
const helpFlags = new Set(['--help', '-h']);
|
|
2336
|
+
function cmdFlagsToString(args) {
|
|
2337
|
+
const result = [];
|
|
2338
|
+
for (let i = 0, {
|
|
2339
|
+
length
|
|
2340
|
+
} = args; i < length; i += 1) {
|
|
2341
|
+
if (args[i].startsWith('--')) {
|
|
2342
|
+
// Check if the next item exists and is NOT another flag.
|
|
2343
|
+
if (i + 1 < length && !args[i + 1].startsWith('--')) {
|
|
2344
|
+
result.push(`${args[i]}=${args[i + 1]}`);
|
|
2345
|
+
i += 1;
|
|
2346
|
+
} else {
|
|
2347
|
+
result.push(args[i]);
|
|
2348
|
+
}
|
|
2349
|
+
}
|
|
2350
|
+
}
|
|
2351
|
+
return result.join(' ');
|
|
2352
|
+
}
|
|
2353
|
+
function cmdPrefixMessage(cmdName, text) {
|
|
2354
|
+
const cmdPrefix = cmdName ? `${cmdName}: ` : '';
|
|
2355
|
+
return `${cmdPrefix}${text}`;
|
|
2356
|
+
}
|
|
2357
|
+
function isHelpFlag(cmdArg) {
|
|
2358
|
+
return helpFlags.has(cmdArg);
|
|
2359
|
+
}
|
|
2360
|
+
|
|
2315
2361
|
// import { meowOrExit } from '../../utils/meow-with-subcommands'
|
|
2316
2362
|
const {
|
|
2317
2363
|
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$v
|
|
@@ -2366,7 +2412,8 @@ const yargsConfig = {
|
|
|
2366
2412
|
recurse: ['r'],
|
|
2367
2413
|
'resolve-class': ['c'],
|
|
2368
2414
|
type: ['t'],
|
|
2369
|
-
version: ['v']
|
|
2415
|
+
version: ['v'],
|
|
2416
|
+
yes: ['y']
|
|
2370
2417
|
},
|
|
2371
2418
|
array: [{
|
|
2372
2419
|
key: 'author',
|
|
@@ -2384,7 +2431,10 @@ const yargsConfig = {
|
|
|
2384
2431
|
key: 'standard',
|
|
2385
2432
|
type: 'string'
|
|
2386
2433
|
}],
|
|
2387
|
-
boolean: ['auto-compositions', 'babel', 'deep', 'evidence', 'fail-on-error', 'generate-key-and-sign', 'help', 'include-formulation', 'include-crypto', 'install-deps', 'print', 'required-only', 'server', 'validate', 'version'
|
|
2434
|
+
boolean: ['auto-compositions', 'babel', 'deep', 'evidence', 'fail-on-error', 'generate-key-and-sign', 'help', 'include-formulation', 'include-crypto', 'install-deps', 'print', 'required-only', 'server', 'validate', 'version',
|
|
2435
|
+
// The --yes flag and -y alias map to the corresponding flag and alias of npx.
|
|
2436
|
+
// https://docs.npmjs.com/cli/v7/commands/npx#compatibility-with-older-npx-versions
|
|
2437
|
+
'yes'],
|
|
2388
2438
|
string: ['api-key', 'lifecycle', 'output', 'parent-project-id', 'profile', 'project-group', 'project-name', 'project-version', 'project-id', 'server-host', 'server-port', 'server-url', 'spec-version']
|
|
2389
2439
|
};
|
|
2390
2440
|
const config$w = {
|
|
@@ -2412,14 +2462,12 @@ async function run$w(argv, importMeta, {
|
|
|
2412
2462
|
}) {
|
|
2413
2463
|
const cli = meowOrExit({
|
|
2414
2464
|
allowUnknownFlags: true,
|
|
2415
|
-
|
|
2416
|
-
|
|
2465
|
+
// Don't let meow take over --help.
|
|
2466
|
+
argv: argv.filter(a => !isHelpFlag(a)),
|
|
2417
2467
|
config: config$w,
|
|
2418
2468
|
importMeta,
|
|
2419
2469
|
parentName
|
|
2420
2470
|
});
|
|
2421
|
-
//
|
|
2422
|
-
//
|
|
2423
2471
|
// if (cli.input.length)
|
|
2424
2472
|
// logger.fail(
|
|
2425
2473
|
// stripIndents`
|
|
@@ -2431,11 +2479,10 @@ async function run$w(argv, importMeta, {
|
|
|
2431
2479
|
// return
|
|
2432
2480
|
// }
|
|
2433
2481
|
|
|
2434
|
-
// TODO:
|
|
2482
|
+
// TODO: Convert to meow.
|
|
2435
2483
|
const yargv = {
|
|
2436
2484
|
...yargsParse(argv, yargsConfig)
|
|
2437
|
-
};
|
|
2438
|
-
|
|
2485
|
+
};
|
|
2439
2486
|
const unknown = yargv._;
|
|
2440
2487
|
const {
|
|
2441
2488
|
length: unknownLength
|
|
@@ -2448,13 +2495,13 @@ async function run$w(argv, importMeta, {
|
|
|
2448
2495
|
logger.logger.fail(`Unknown ${words.pluralize('argument', unknownLength)}: ${yargv._.join(', ')}`);
|
|
2449
2496
|
return;
|
|
2450
2497
|
}
|
|
2451
|
-
if (yargv.output === undefined) {
|
|
2452
|
-
yargv.output = 'socket-cdx.json';
|
|
2453
|
-
}
|
|
2454
2498
|
if (cli.flags['dryRun']) {
|
|
2455
2499
|
logger.logger.log(DRY_RUN_BAIL_TEXT$v);
|
|
2456
2500
|
return;
|
|
2457
2501
|
}
|
|
2502
|
+
if (yargv.output === undefined) {
|
|
2503
|
+
yargv.output = 'socket-cdx.json';
|
|
2504
|
+
}
|
|
2458
2505
|
await runCycloneDX(yargv);
|
|
2459
2506
|
}
|
|
2460
2507
|
|
|
@@ -2791,7 +2838,7 @@ const cmdDiffScan = {
|
|
|
2791
2838
|
};
|
|
2792
2839
|
|
|
2793
2840
|
const {
|
|
2794
|
-
NPM: NPM$
|
|
2841
|
+
NPM: NPM$e
|
|
2795
2842
|
} = constants;
|
|
2796
2843
|
function isTopLevel(tree, node) {
|
|
2797
2844
|
return tree.children.get(node.name) === node;
|
|
@@ -2835,7 +2882,7 @@ async function npmFix(_pkgEnvDetails, cwd, options) {
|
|
|
2835
2882
|
// eslint-disable-next-line no-await-in-loop
|
|
2836
2883
|
await arb.buildIdealTree();
|
|
2837
2884
|
const tree = arb.idealTree;
|
|
2838
|
-
const hasUpgrade = !!registry.getManifestData(NPM$
|
|
2885
|
+
const hasUpgrade = !!registry.getManifestData(NPM$e, name);
|
|
2839
2886
|
if (hasUpgrade) {
|
|
2840
2887
|
spinner?.info(`Skipping ${name}. Socket Optimize package exists.`);
|
|
2841
2888
|
continue;
|
|
@@ -2935,24 +2982,6 @@ async function getAlertsMapFromPnpmLockfile(lockfile, options) {
|
|
|
2935
2982
|
return alertsByPkgId;
|
|
2936
2983
|
}
|
|
2937
2984
|
|
|
2938
|
-
function cmdFlagsToString(args) {
|
|
2939
|
-
const result = [];
|
|
2940
|
-
for (let i = 0, {
|
|
2941
|
-
length
|
|
2942
|
-
} = args; i < length; i += 1) {
|
|
2943
|
-
if (args[i].startsWith('--')) {
|
|
2944
|
-
// Check if the next item exists and is NOT another flag.
|
|
2945
|
-
if (i + 1 < length && !args[i + 1].startsWith('--')) {
|
|
2946
|
-
result.push(`${args[i]}=${args[i + 1]}`);
|
|
2947
|
-
i += 1;
|
|
2948
|
-
} else {
|
|
2949
|
-
result.push(args[i]);
|
|
2950
|
-
}
|
|
2951
|
-
}
|
|
2952
|
-
}
|
|
2953
|
-
return result.join(' ');
|
|
2954
|
-
}
|
|
2955
|
-
|
|
2956
2985
|
const {
|
|
2957
2986
|
SOCKET_IPC_HANDSHAKE
|
|
2958
2987
|
} = constants;
|
|
@@ -2970,27 +2999,28 @@ function safeNpmInstall(options) {
|
|
|
2970
2999
|
const useIpc = objects.isObject(ipc);
|
|
2971
3000
|
const useDebug = debug.isDebug();
|
|
2972
3001
|
const terminatorPos = args.indexOf('--');
|
|
2973
|
-
const
|
|
3002
|
+
const binArgs = (terminatorPos === -1 ? args : args.slice(0, terminatorPos)).filter(a => !npm.isAuditFlag(a) && !npm.isFundFlag(a) && !npm.isProgressFlag(a));
|
|
2974
3003
|
const otherArgs = terminatorPos === -1 ? [] : args.slice(terminatorPos);
|
|
2975
|
-
const isSilent = !useDebug && !
|
|
2976
|
-
const logLevelArgs = isSilent ? ['--loglevel', '
|
|
3004
|
+
const isSilent = !useDebug && !binArgs.some(npm.isLoglevelFlag);
|
|
3005
|
+
const logLevelArgs = isSilent ? ['--loglevel', 'silent'] : [];
|
|
2977
3006
|
const spawnPromise = spawn.spawn(
|
|
2978
3007
|
// Lazily access constants.execPath.
|
|
2979
3008
|
constants.execPath, [
|
|
2980
3009
|
// Lazily access constants.nodeHardenFlags.
|
|
2981
3010
|
...constants.nodeHardenFlags,
|
|
2982
3011
|
// Lazily access constants.nodeNoWarningsFlags.
|
|
2983
|
-
...constants.nodeNoWarningsFlags,
|
|
3012
|
+
...constants.nodeNoWarningsFlags,
|
|
3013
|
+
// Lazily access false.
|
|
3014
|
+
...([]), '--require',
|
|
2984
3015
|
// Lazily access constants.distShadowNpmInjectPath.
|
|
2985
3016
|
constants.distShadowNpmInjectPath, agentExecPath, 'install',
|
|
2986
3017
|
// Avoid code paths for 'audit' and 'fund'.
|
|
2987
3018
|
'--no-audit', '--no-fund',
|
|
2988
|
-
// Add
|
|
2989
|
-
// when running the command with recent versions of npm.
|
|
3019
|
+
// Add '--no-progress' to fix input being swallowed by the npm spinner.
|
|
2990
3020
|
'--no-progress',
|
|
2991
|
-
// Add '--loglevel=
|
|
3021
|
+
// Add '--loglevel=silent' if a loglevel flag is not provided and the
|
|
2992
3022
|
// SOCKET_CLI_DEBUG environment variable is not truthy.
|
|
2993
|
-
...logLevelArgs, ...
|
|
3023
|
+
...logLevelArgs, ...binArgs, ...otherArgs], {
|
|
2994
3024
|
spinner,
|
|
2995
3025
|
// Set stdio to include 'ipc'.
|
|
2996
3026
|
// See https://github.com/nodejs/node/blob/v23.6.0/lib/child_process.js#L161-L166
|
|
@@ -3011,7 +3041,7 @@ function safeNpmInstall(options) {
|
|
|
3011
3041
|
}
|
|
3012
3042
|
|
|
3013
3043
|
const {
|
|
3014
|
-
NPM: NPM$
|
|
3044
|
+
NPM: NPM$d
|
|
3015
3045
|
} = constants;
|
|
3016
3046
|
function runAgentInstall(pkgEnvDetails, options) {
|
|
3017
3047
|
const {
|
|
@@ -3019,7 +3049,7 @@ function runAgentInstall(pkgEnvDetails, options) {
|
|
|
3019
3049
|
agentExecPath
|
|
3020
3050
|
} = pkgEnvDetails;
|
|
3021
3051
|
// All package managers support the "install" command.
|
|
3022
|
-
if (agent === NPM$
|
|
3052
|
+
if (agent === NPM$d) {
|
|
3023
3053
|
return safeNpmInstall({
|
|
3024
3054
|
agentExecPath,
|
|
3025
3055
|
...options
|
|
@@ -3050,7 +3080,7 @@ function runAgentInstall(pkgEnvDetails, options) {
|
|
|
3050
3080
|
}
|
|
3051
3081
|
|
|
3052
3082
|
const {
|
|
3053
|
-
NPM: NPM$
|
|
3083
|
+
NPM: NPM$c,
|
|
3054
3084
|
OVERRIDES: OVERRIDES$2,
|
|
3055
3085
|
PNPM: PNPM$9
|
|
3056
3086
|
} = constants;
|
|
@@ -3098,7 +3128,7 @@ async function pnpmFix(pkgEnvDetails, cwd, options) {
|
|
|
3098
3128
|
1: infos
|
|
3099
3129
|
} of infoByPkg) {
|
|
3100
3130
|
const tree = arb.actualTree;
|
|
3101
|
-
const hasUpgrade = !!registry.getManifestData(NPM$
|
|
3131
|
+
const hasUpgrade = !!registry.getManifestData(NPM$c, name);
|
|
3102
3132
|
if (hasUpgrade) {
|
|
3103
3133
|
spinner?.info(`Skipping ${name}. Socket Optimize package exists.`);
|
|
3104
3134
|
continue;
|
|
@@ -3163,24 +3193,27 @@ async function pnpmFix(pkgEnvDetails, cwd, options) {
|
|
|
3163
3193
|
|
|
3164
3194
|
const {
|
|
3165
3195
|
BINARY_LOCK_EXT,
|
|
3166
|
-
BUN: BUN$
|
|
3196
|
+
BUN: BUN$5,
|
|
3197
|
+
HIDDEN_PACKAGE_LOCK_JSON,
|
|
3167
3198
|
LOCK_EXT: LOCK_EXT$1,
|
|
3168
|
-
NPM: NPM$
|
|
3199
|
+
NPM: NPM$b,
|
|
3200
|
+
NPM_BUGGY_OVERRIDES_PATCHED_VERSION: NPM_BUGGY_OVERRIDES_PATCHED_VERSION$1,
|
|
3201
|
+
PACKAGE_JSON,
|
|
3169
3202
|
PNPM: PNPM$8,
|
|
3170
|
-
VLT: VLT$
|
|
3203
|
+
VLT: VLT$5,
|
|
3171
3204
|
YARN,
|
|
3172
|
-
YARN_BERRY: YARN_BERRY$
|
|
3205
|
+
YARN_BERRY: YARN_BERRY$5,
|
|
3173
3206
|
YARN_CLASSIC: YARN_CLASSIC$6
|
|
3174
3207
|
} = constants;
|
|
3175
|
-
const AGENTS = [BUN$
|
|
3208
|
+
const AGENTS = [BUN$5, NPM$b, PNPM$8, YARN_BERRY$5, YARN_CLASSIC$6, VLT$5];
|
|
3176
3209
|
const binByAgent = {
|
|
3177
3210
|
__proto__: null,
|
|
3178
|
-
[BUN$
|
|
3179
|
-
[NPM$
|
|
3211
|
+
[BUN$5]: BUN$5,
|
|
3212
|
+
[NPM$b]: NPM$b,
|
|
3180
3213
|
[PNPM$8]: PNPM$8,
|
|
3181
|
-
[YARN_BERRY$
|
|
3214
|
+
[YARN_BERRY$5]: YARN,
|
|
3182
3215
|
[YARN_CLASSIC$6]: YARN,
|
|
3183
|
-
[VLT$
|
|
3216
|
+
[VLT$5]: VLT$5
|
|
3184
3217
|
};
|
|
3185
3218
|
async function getAgentExecPath(agent) {
|
|
3186
3219
|
const binName = binByAgent[agent];
|
|
@@ -3202,24 +3235,24 @@ async function getAgentVersion(agentExecPath, cwd) {
|
|
|
3202
3235
|
|
|
3203
3236
|
// The order of LOCKS properties IS significant as it affects iteration order.
|
|
3204
3237
|
const LOCKS = {
|
|
3205
|
-
[`bun${LOCK_EXT$1}`]: BUN$
|
|
3206
|
-
[`bun${BINARY_LOCK_EXT}`]: BUN$
|
|
3238
|
+
[`bun${LOCK_EXT$1}`]: BUN$5,
|
|
3239
|
+
[`bun${BINARY_LOCK_EXT}`]: BUN$5,
|
|
3207
3240
|
// If both package-lock.json and npm-shrinkwrap.json are present in the root
|
|
3208
3241
|
// of a project, npm-shrinkwrap.json will take precedence and package-lock.json
|
|
3209
3242
|
// will be ignored.
|
|
3210
3243
|
// https://docs.npmjs.com/cli/v10/configuring-npm/package-lock-json#package-lockjson-vs-npm-shrinkwrapjson
|
|
3211
|
-
'npm-shrinkwrap.json': NPM$
|
|
3212
|
-
'package-lock.json': NPM$
|
|
3244
|
+
'npm-shrinkwrap.json': NPM$b,
|
|
3245
|
+
'package-lock.json': NPM$b,
|
|
3213
3246
|
'pnpm-lock.yaml': PNPM$8,
|
|
3214
3247
|
'pnpm-lock.yml': PNPM$8,
|
|
3215
3248
|
[`yarn${LOCK_EXT$1}`]: YARN_CLASSIC$6,
|
|
3216
|
-
'vlt-lock.json': VLT$
|
|
3249
|
+
'vlt-lock.json': VLT$5,
|
|
3217
3250
|
// Lastly, look for a hidden lock file which is present if .npmrc has package-lock=false:
|
|
3218
3251
|
// https://docs.npmjs.com/cli/v10/configuring-npm/package-lock-json#hidden-lockfiles
|
|
3219
3252
|
//
|
|
3220
3253
|
// Unlike the other LOCKS keys this key contains a directory AND filename so
|
|
3221
3254
|
// it has to be handled differently.
|
|
3222
|
-
'node_modules/.package-lock.json': NPM$
|
|
3255
|
+
'node_modules/.package-lock.json': NPM$b
|
|
3223
3256
|
};
|
|
3224
3257
|
const readLockFileByAgent = (() => {
|
|
3225
3258
|
function wrapReader(reader) {
|
|
@@ -3233,7 +3266,7 @@ const readLockFileByAgent = (() => {
|
|
|
3233
3266
|
const binaryReader = wrapReader(shadowNpmInject.readFileBinary);
|
|
3234
3267
|
const defaultReader = wrapReader(async lockPath => await shadowNpmInject.readFileUtf8(lockPath));
|
|
3235
3268
|
return {
|
|
3236
|
-
[BUN$
|
|
3269
|
+
[BUN$5]: wrapReader(async (lockPath, agentExecPath) => {
|
|
3237
3270
|
const ext = path.extname(lockPath);
|
|
3238
3271
|
if (ext === LOCK_EXT$1) {
|
|
3239
3272
|
return await defaultReader(lockPath);
|
|
@@ -3252,10 +3285,10 @@ const readLockFileByAgent = (() => {
|
|
|
3252
3285
|
}
|
|
3253
3286
|
return undefined;
|
|
3254
3287
|
}),
|
|
3255
|
-
[NPM$
|
|
3288
|
+
[NPM$b]: defaultReader,
|
|
3256
3289
|
[PNPM$8]: defaultReader,
|
|
3257
|
-
[VLT$
|
|
3258
|
-
[YARN_BERRY$
|
|
3290
|
+
[VLT$5]: defaultReader,
|
|
3291
|
+
[YARN_BERRY$5]: defaultReader,
|
|
3259
3292
|
[YARN_CLASSIC$6]: defaultReader
|
|
3260
3293
|
};
|
|
3261
3294
|
})();
|
|
@@ -3267,8 +3300,8 @@ async function detectPackageEnvironment({
|
|
|
3267
3300
|
cwd
|
|
3268
3301
|
});
|
|
3269
3302
|
let lockName = lockPath ? path.basename(lockPath) : undefined;
|
|
3270
|
-
const isHiddenLockFile = lockName ===
|
|
3271
|
-
const pkgJsonPath = lockPath ? path.resolve(lockPath, `${isHiddenLockFile ? '../' : ''}
|
|
3303
|
+
const isHiddenLockFile = lockName === HIDDEN_PACKAGE_LOCK_JSON;
|
|
3304
|
+
const pkgJsonPath = lockPath ? path.resolve(lockPath, `${isHiddenLockFile ? '../' : ''}../${PACKAGE_JSON}`) : await shadowNpmInject.findUp(PACKAGE_JSON, {
|
|
3272
3305
|
cwd
|
|
3273
3306
|
});
|
|
3274
3307
|
const pkgPath = pkgJsonPath && fs.existsSync(pkgJsonPath) ? path.dirname(pkgJsonPath) : undefined;
|
|
@@ -3296,16 +3329,16 @@ async function detectPackageEnvironment({
|
|
|
3296
3329
|
agent = LOCKS[lockName];
|
|
3297
3330
|
}
|
|
3298
3331
|
if (agent === undefined) {
|
|
3299
|
-
agent = NPM$
|
|
3332
|
+
agent = NPM$b;
|
|
3300
3333
|
onUnknown?.(pkgManager);
|
|
3301
3334
|
}
|
|
3302
3335
|
const agentExecPath = await getAgentExecPath(agent);
|
|
3303
|
-
const npmExecPath = agent === NPM$
|
|
3336
|
+
const npmExecPath = agent === NPM$b ? agentExecPath : await getAgentExecPath(NPM$b);
|
|
3304
3337
|
if (agentVersion === undefined) {
|
|
3305
3338
|
agentVersion = await getAgentVersion(agentExecPath, cwd);
|
|
3306
3339
|
}
|
|
3307
3340
|
if (agent === YARN_CLASSIC$6 && (agentVersion?.major ?? 0) > 1) {
|
|
3308
|
-
agent = YARN_BERRY$
|
|
3341
|
+
agent = YARN_BERRY$5;
|
|
3309
3342
|
}
|
|
3310
3343
|
const targets = {
|
|
3311
3344
|
browser: false,
|
|
@@ -3347,6 +3380,8 @@ async function detectPackageEnvironment({
|
|
|
3347
3380
|
lockName = undefined;
|
|
3348
3381
|
lockPath = undefined;
|
|
3349
3382
|
}
|
|
3383
|
+
const pkgSupported = targets.browser || targets.node;
|
|
3384
|
+
const npmBuggyOverrides = agent === NPM$b && !!agentVersion && semver.lt(agentVersion, NPM_BUGGY_OVERRIDES_PATCHED_VERSION$1);
|
|
3350
3385
|
return {
|
|
3351
3386
|
agent,
|
|
3352
3387
|
agentExecPath,
|
|
@@ -3358,19 +3393,16 @@ async function detectPackageEnvironment({
|
|
|
3358
3393
|
npmExecPath,
|
|
3359
3394
|
pkgJson: editablePkgJson,
|
|
3360
3395
|
pkgPath,
|
|
3361
|
-
|
|
3396
|
+
pkgSupported,
|
|
3397
|
+
features: {
|
|
3398
|
+
npmBuggyOverrides
|
|
3399
|
+
},
|
|
3362
3400
|
targets
|
|
3363
3401
|
};
|
|
3364
3402
|
}
|
|
3365
|
-
|
|
3366
|
-
const {
|
|
3367
|
-
BUN: BUN$5,
|
|
3368
|
-
VLT: VLT$5,
|
|
3369
|
-
YARN_BERRY: YARN_BERRY$5
|
|
3370
|
-
} = constants;
|
|
3371
|
-
const COMMAND_TITLE$2 = 'Socket Optimize';
|
|
3372
3403
|
async function detectAndValidatePackageEnvironment(cwd, options) {
|
|
3373
3404
|
const {
|
|
3405
|
+
cmdName = '',
|
|
3374
3406
|
logger,
|
|
3375
3407
|
prod
|
|
3376
3408
|
} = {
|
|
@@ -3380,44 +3412,45 @@ async function detectAndValidatePackageEnvironment(cwd, options) {
|
|
|
3380
3412
|
const details = await detectPackageEnvironment({
|
|
3381
3413
|
cwd,
|
|
3382
3414
|
onUnknown(pkgManager) {
|
|
3383
|
-
logger?.warn(
|
|
3415
|
+
logger?.warn(cmdPrefixMessage(cmdName, `Unknown package manager${pkgManager ? ` ${pkgManager}` : ''}, defaulting to npm`));
|
|
3384
3416
|
}
|
|
3385
3417
|
});
|
|
3386
|
-
if (!details.
|
|
3387
|
-
logger?.fail(
|
|
3418
|
+
if (!details.pkgSupported) {
|
|
3419
|
+
logger?.fail(cmdPrefixMessage(cmdName, 'No supported Node or browser range detected'));
|
|
3388
3420
|
return;
|
|
3389
3421
|
}
|
|
3390
3422
|
if (details.agent === VLT$5) {
|
|
3391
|
-
logger?.fail(`${
|
|
3423
|
+
logger?.fail(cmdPrefixMessage(cmdName, `${details.agent} does not support overrides. Soon, though ⚡`));
|
|
3392
3424
|
return;
|
|
3393
3425
|
}
|
|
3394
3426
|
const lockName = details.lockName ?? 'lock file';
|
|
3395
3427
|
if (details.lockName === undefined || details.lockSrc === undefined) {
|
|
3396
|
-
logger?.fail(
|
|
3428
|
+
logger?.fail(cmdPrefixMessage(cmdName, `No ${lockName} found`));
|
|
3397
3429
|
return;
|
|
3398
3430
|
}
|
|
3399
3431
|
if (details.lockSrc.trim() === '') {
|
|
3400
|
-
logger?.fail(`${
|
|
3432
|
+
logger?.fail(cmdPrefixMessage(cmdName, `${lockName} is empty`));
|
|
3401
3433
|
return;
|
|
3402
3434
|
}
|
|
3403
3435
|
if (details.pkgPath === undefined) {
|
|
3404
|
-
logger?.fail(
|
|
3436
|
+
logger?.fail(cmdPrefixMessage(cmdName, `No ${PACKAGE_JSON} found`));
|
|
3405
3437
|
return;
|
|
3406
3438
|
}
|
|
3407
3439
|
if (prod && (details.agent === BUN$5 || details.agent === YARN_BERRY$5)) {
|
|
3408
|
-
logger?.fail(
|
|
3440
|
+
logger?.fail(cmdPrefixMessage(cmdName, `--prod not supported for ${details.agent}${details.agentVersion ? `@${details.agentVersion.version}` : ''}`));
|
|
3409
3441
|
return;
|
|
3410
3442
|
}
|
|
3411
3443
|
if (details.lockPath && path.relative(cwd, details.lockPath).startsWith('.')) {
|
|
3412
|
-
logger?.warn(
|
|
3444
|
+
logger?.warn(cmdPrefixMessage(cmdName, `Package ${lockName} found at ${details.lockPath}`));
|
|
3413
3445
|
}
|
|
3414
3446
|
return details;
|
|
3415
3447
|
}
|
|
3416
3448
|
|
|
3417
3449
|
const {
|
|
3418
|
-
NPM: NPM$
|
|
3450
|
+
NPM: NPM$a,
|
|
3419
3451
|
PNPM: PNPM$7
|
|
3420
3452
|
} = constants;
|
|
3453
|
+
const CMD_NAME$2 = 'socket fix';
|
|
3421
3454
|
async function runFix() {
|
|
3422
3455
|
// Lazily access constants.spinner.
|
|
3423
3456
|
const {
|
|
@@ -3426,6 +3459,7 @@ async function runFix() {
|
|
|
3426
3459
|
spinner.start();
|
|
3427
3460
|
const cwd = process.cwd();
|
|
3428
3461
|
const pkgEnvDetails = await detectAndValidatePackageEnvironment(cwd, {
|
|
3462
|
+
cmdName: CMD_NAME$2,
|
|
3429
3463
|
logger: logger.logger
|
|
3430
3464
|
});
|
|
3431
3465
|
if (!pkgEnvDetails) {
|
|
@@ -3433,7 +3467,7 @@ async function runFix() {
|
|
|
3433
3467
|
return;
|
|
3434
3468
|
}
|
|
3435
3469
|
switch (pkgEnvDetails.agent) {
|
|
3436
|
-
case NPM$
|
|
3470
|
+
case NPM$a:
|
|
3437
3471
|
{
|
|
3438
3472
|
await npmFix(pkgEnvDetails, cwd);
|
|
3439
3473
|
break;
|
|
@@ -3505,7 +3539,7 @@ async function fetchPackageInfo(pkgName, pkgVersion, includeAllIssues) {
|
|
|
3505
3539
|
}
|
|
3506
3540
|
|
|
3507
3541
|
const {
|
|
3508
|
-
NPM: NPM$
|
|
3542
|
+
NPM: NPM$9
|
|
3509
3543
|
} = registryConstants;
|
|
3510
3544
|
function formatScore(score) {
|
|
3511
3545
|
if (score > 80) {
|
|
@@ -3589,7 +3623,7 @@ function logPackageInfo({
|
|
|
3589
3623
|
logger.logger.log('Package has no issues');
|
|
3590
3624
|
}
|
|
3591
3625
|
const format = new shadowNpmInject.ColorOrMarkdown(outputKind === 'markdown');
|
|
3592
|
-
const url = shadowNpmInject.getSocketDevPackageOverviewUrl(NPM$
|
|
3626
|
+
const url = shadowNpmInject.getSocketDevPackageOverviewUrl(NPM$9, pkgName, pkgVersion);
|
|
3593
3627
|
logger.logger.log('\n');
|
|
3594
3628
|
if (pkgVersion === 'latest') {
|
|
3595
3629
|
logger.logger.log(`Detailed info on socket.dev: ${format.hyperlink(`${pkgName}`, url, {
|
|
@@ -3916,9 +3950,11 @@ async function convertGradleToMaven(target, bin, _out, verbose, gradleOpts) {
|
|
|
3916
3950
|
logger.logger.groupEnd();
|
|
3917
3951
|
}
|
|
3918
3952
|
try {
|
|
3919
|
-
// Run sbt with the init script we provide which should yield zero or more
|
|
3920
|
-
// We have to figure out where to store those pom files such that
|
|
3921
|
-
//
|
|
3953
|
+
// Run sbt with the init script we provide which should yield zero or more
|
|
3954
|
+
// pom files. We have to figure out where to store those pom files such that
|
|
3955
|
+
// we can upload them and predict them through the GitHub API. We could do a
|
|
3956
|
+
// .socket folder. We could do a socket.pom.gz with all the poms, although
|
|
3957
|
+
// I'd prefer something plain-text if it is to be committed.
|
|
3922
3958
|
|
|
3923
3959
|
// Note: init.gradle will be exported by .config/rollup.dist.config.mjs
|
|
3924
3960
|
const initLocation = path.join(constants.rootDistPath, 'init.gradle');
|
|
@@ -3965,7 +4001,7 @@ async function convertGradleToMaven(target, bin, _out, verbose, gradleOpts) {
|
|
|
3965
4001
|
// // Move the pom file to ...? initial cwd? loc will be an absolute path, or dump to stdout
|
|
3966
4002
|
// if (out === '-') {
|
|
3967
4003
|
// spinner.start('Result:\n```')
|
|
3968
|
-
// spinner.log(await safeReadFile(loc
|
|
4004
|
+
// spinner.log(await safeReadFile(loc))
|
|
3969
4005
|
// spinner.log('```')
|
|
3970
4006
|
// spinner.successAndStop(`OK`)
|
|
3971
4007
|
// } else {
|
|
@@ -4200,7 +4236,7 @@ async function convertSbtToMaven(target, bin, out, verbose, sbtOpts) {
|
|
|
4200
4236
|
// TODO: maybe we can add an option to target a specific file to dump to stdout
|
|
4201
4237
|
if (out === '-' && poms.length === 1) {
|
|
4202
4238
|
logger.logger.log('Result:\n```');
|
|
4203
|
-
logger.logger.log(await shadowNpmInject.safeReadFile(poms[0]
|
|
4239
|
+
logger.logger.log(await shadowNpmInject.safeReadFile(poms[0]));
|
|
4204
4240
|
logger.logger.log('```');
|
|
4205
4241
|
logger.logger.success(`OK`);
|
|
4206
4242
|
} else if (out === '-') {
|
|
@@ -4677,21 +4713,21 @@ async function run$l(argv, importMeta, {
|
|
|
4677
4713
|
}
|
|
4678
4714
|
|
|
4679
4715
|
const {
|
|
4680
|
-
NPM: NPM$
|
|
4716
|
+
NPM: NPM$8
|
|
4681
4717
|
} = constants;
|
|
4682
4718
|
async function wrapNpm(argv) {
|
|
4683
4719
|
// Lazily access constants.distShadowNpmBinPath.
|
|
4684
4720
|
const shadowBin = require(constants.distShadowNpmBinPath);
|
|
4685
|
-
await shadowBin(NPM$
|
|
4721
|
+
await shadowBin(NPM$8, argv);
|
|
4686
4722
|
}
|
|
4687
4723
|
|
|
4688
4724
|
const {
|
|
4689
4725
|
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$k,
|
|
4690
|
-
NPM: NPM$
|
|
4726
|
+
NPM: NPM$7
|
|
4691
4727
|
} = constants;
|
|
4692
4728
|
const config$k = {
|
|
4693
4729
|
commandName: 'npm',
|
|
4694
|
-
description: `${NPM$
|
|
4730
|
+
description: `${NPM$7} wrapper functionality`,
|
|
4695
4731
|
hidden: false,
|
|
4696
4732
|
flags: {},
|
|
4697
4733
|
help: (command, _config) => `
|
|
@@ -4806,7 +4842,7 @@ async function run$i(argv, importMeta, {
|
|
|
4806
4842
|
|
|
4807
4843
|
const {
|
|
4808
4844
|
BUN: BUN$4,
|
|
4809
|
-
NPM: NPM$
|
|
4845
|
+
NPM: NPM$6,
|
|
4810
4846
|
PNPM: PNPM$6,
|
|
4811
4847
|
VLT: VLT$4,
|
|
4812
4848
|
YARN_BERRY: YARN_BERRY$4,
|
|
@@ -4818,7 +4854,7 @@ function matchLsCmdViewHumanStdout(stdout, name) {
|
|
|
4818
4854
|
function matchQueryCmdStdout(stdout, name) {
|
|
4819
4855
|
return stdout.includes(`"${name}"`);
|
|
4820
4856
|
}
|
|
4821
|
-
const depsIncludesByAgent = new Map([[BUN$4, matchLsCmdViewHumanStdout], [NPM$
|
|
4857
|
+
const depsIncludesByAgent = new Map([[BUN$4, matchLsCmdViewHumanStdout], [NPM$6, matchQueryCmdStdout], [PNPM$6, matchQueryCmdStdout], [VLT$4, matchQueryCmdStdout], [YARN_BERRY$4, matchLsCmdViewHumanStdout], [YARN_CLASSIC$5, matchLsCmdViewHumanStdout]]);
|
|
4822
4858
|
|
|
4823
4859
|
function getDependencyEntries(pkgJson) {
|
|
4824
4860
|
const {
|
|
@@ -4846,7 +4882,7 @@ function getDependencyEntries(pkgJson) {
|
|
|
4846
4882
|
|
|
4847
4883
|
const {
|
|
4848
4884
|
BUN: BUN$3,
|
|
4849
|
-
NPM: NPM$
|
|
4885
|
+
NPM: NPM$5,
|
|
4850
4886
|
OVERRIDES: OVERRIDES$1,
|
|
4851
4887
|
PNPM: PNPM$5,
|
|
4852
4888
|
RESOLUTIONS: RESOLUTIONS$1,
|
|
@@ -4867,7 +4903,7 @@ function getOverridesDataBun(pkgJson) {
|
|
|
4867
4903
|
function getOverridesDataNpm(pkgJson) {
|
|
4868
4904
|
const overrides = pkgJson?.[OVERRIDES$1] ?? {};
|
|
4869
4905
|
return {
|
|
4870
|
-
type: NPM$
|
|
4906
|
+
type: NPM$5,
|
|
4871
4907
|
overrides
|
|
4872
4908
|
};
|
|
4873
4909
|
}
|
|
@@ -4908,7 +4944,7 @@ function getOverridesDataClassic(pkgJson) {
|
|
|
4908
4944
|
overrides
|
|
4909
4945
|
};
|
|
4910
4946
|
}
|
|
4911
|
-
const overridesDataByAgent = new Map([[BUN$3, getOverridesDataBun], [NPM$
|
|
4947
|
+
const overridesDataByAgent = new Map([[BUN$3, getOverridesDataBun], [NPM$5, getOverridesDataNpm], [PNPM$5, getOverridesDataPnpm], [VLT$3, getOverridesDataVlt], [YARN_BERRY$3, getOverridesDataYarn], [YARN_CLASSIC$4, getOverridesDataClassic]]);
|
|
4912
4948
|
|
|
4913
4949
|
const {
|
|
4914
4950
|
PNPM: PNPM$4
|
|
@@ -4919,7 +4955,7 @@ async function getWorkspaceGlobs(agent, pkgPath, pkgJson) {
|
|
|
4919
4955
|
if (agent === PNPM$4) {
|
|
4920
4956
|
for (const workspacePath of [path.join(pkgPath, `${PNPM_WORKSPACE}.yaml`), path.join(pkgPath, `${PNPM_WORKSPACE}.yml`)]) {
|
|
4921
4957
|
// eslint-disable-next-line no-await-in-loop
|
|
4922
|
-
const yml = await shadowNpmInject.safeReadFile(workspacePath
|
|
4958
|
+
const yml = await shadowNpmInject.safeReadFile(workspacePath);
|
|
4923
4959
|
if (yml) {
|
|
4924
4960
|
try {
|
|
4925
4961
|
workspacePatterns = yaml.parse(yml)?.packages;
|
|
@@ -4956,7 +4992,7 @@ function workspacePatternToGlobPattern(workspace) {
|
|
|
4956
4992
|
const {
|
|
4957
4993
|
BUN: BUN$2,
|
|
4958
4994
|
LOCK_EXT,
|
|
4959
|
-
NPM: NPM$
|
|
4995
|
+
NPM: NPM$4,
|
|
4960
4996
|
PNPM: PNPM$3,
|
|
4961
4997
|
VLT: VLT$2,
|
|
4962
4998
|
YARN_BERRY: YARN_BERRY$2,
|
|
@@ -5000,11 +5036,11 @@ function includesYarn(lockSrc, name) {
|
|
|
5000
5036
|
// , name@
|
|
5001
5037
|
`(?<=(?:^\\s*|,\\s*)"?)${escapedName}(?=@)`, 'm').test(lockSrc);
|
|
5002
5038
|
}
|
|
5003
|
-
const lockfileIncludesByAgent = new Map([[BUN$2, includesBun], [NPM$
|
|
5039
|
+
const lockfileIncludesByAgent = new Map([[BUN$2, includesBun], [NPM$4, includesNpm], [PNPM$3, includesPnpm], [VLT$2, includesVlt], [YARN_BERRY$2, includesYarn], [YARN_CLASSIC$3, includesYarn]]);
|
|
5004
5040
|
|
|
5005
5041
|
const {
|
|
5006
5042
|
BUN: BUN$1,
|
|
5007
|
-
NPM: NPM$
|
|
5043
|
+
NPM: NPM$3,
|
|
5008
5044
|
PNPM: PNPM$2,
|
|
5009
5045
|
VLT: VLT$1,
|
|
5010
5046
|
YARN_BERRY: YARN_BERRY$1,
|
|
@@ -5074,7 +5110,7 @@ async function lsNpm(agentExecPath, cwd) {
|
|
|
5074
5110
|
}
|
|
5075
5111
|
async function lsPnpm(agentExecPath, cwd, options) {
|
|
5076
5112
|
const npmExecPath = options?.npmExecPath;
|
|
5077
|
-
if (npmExecPath && npmExecPath !== NPM$
|
|
5113
|
+
if (npmExecPath && npmExecPath !== NPM$3) {
|
|
5078
5114
|
const result = await npmQuery(npmExecPath, cwd);
|
|
5079
5115
|
if (result) {
|
|
5080
5116
|
return result;
|
|
@@ -5125,35 +5161,7 @@ async function lsYarnClassic(agentExecPath, cwd) {
|
|
|
5125
5161
|
} catch {}
|
|
5126
5162
|
return '';
|
|
5127
5163
|
}
|
|
5128
|
-
const lsByAgent = new Map([[BUN$1, lsBun], [NPM$
|
|
5129
|
-
|
|
5130
|
-
const {
|
|
5131
|
-
NPM: NPM$3
|
|
5132
|
-
} = constants;
|
|
5133
|
-
const COMMAND_TITLE$1 = 'Socket Optimize';
|
|
5134
|
-
async function updateLockfile(pkgEnvDetails, options) {
|
|
5135
|
-
const {
|
|
5136
|
-
logger,
|
|
5137
|
-
spinner
|
|
5138
|
-
} = {
|
|
5139
|
-
__proto__: null,
|
|
5140
|
-
...options
|
|
5141
|
-
};
|
|
5142
|
-
spinner?.start(`Updating ${pkgEnvDetails.lockName}...`);
|
|
5143
|
-
try {
|
|
5144
|
-
await runAgentInstall(pkgEnvDetails, {
|
|
5145
|
-
spinner
|
|
5146
|
-
});
|
|
5147
|
-
spinner?.stop();
|
|
5148
|
-
if (pkgEnvDetails.agent === NPM$3) {
|
|
5149
|
-
logger?.log(`💡 Re-run ${COMMAND_TITLE$1} whenever ${pkgEnvDetails.lockName} changes.\n This can be skipped once npm v11.2.0 is released.`);
|
|
5150
|
-
}
|
|
5151
|
-
} catch (e) {
|
|
5152
|
-
spinner?.stop();
|
|
5153
|
-
logger?.fail(`${COMMAND_TITLE$1}: ${pkgEnvDetails.agent} install failed to update ${pkgEnvDetails.lockName}`);
|
|
5154
|
-
logger?.error(e);
|
|
5155
|
-
}
|
|
5156
|
-
}
|
|
5164
|
+
const lsByAgent = new Map([[BUN$1, lsBun], [NPM$3, lsNpm], [PNPM$2, lsPnpm], [VLT$1, lsVlt], [YARN_BERRY$1, lsYarnBerry], [YARN_CLASSIC$2, lsYarnClassic]]);
|
|
5157
5165
|
|
|
5158
5166
|
const {
|
|
5159
5167
|
BUN,
|
|
@@ -5165,7 +5173,6 @@ const {
|
|
|
5165
5173
|
YARN_BERRY,
|
|
5166
5174
|
YARN_CLASSIC: YARN_CLASSIC$1
|
|
5167
5175
|
} = constants;
|
|
5168
|
-
const PNPM_FIELD_NAME = PNPM$1;
|
|
5169
5176
|
const depFields = ['dependencies', 'devDependencies', 'peerDependencies', 'peerDependenciesMeta', 'optionalDependencies', 'bundleDependencies'];
|
|
5170
5177
|
function getEntryIndexes(entries, keys) {
|
|
5171
5178
|
return keys.map(n => entries.findIndex(p => p[0] === n)).filter(n => n !== -1).sort((a, b) => a - b);
|
|
@@ -5176,26 +5183,30 @@ function getLowestEntryIndex(entries, keys) {
|
|
|
5176
5183
|
function getHighestEntryIndex(entries, keys) {
|
|
5177
5184
|
return getEntryIndexes(entries, keys).at(-1) ?? -1;
|
|
5178
5185
|
}
|
|
5179
|
-
function
|
|
5186
|
+
function updatePkgJsonField(editablePkgJson, field, value) {
|
|
5180
5187
|
const {
|
|
5181
5188
|
content: pkgJson
|
|
5182
5189
|
} = editablePkgJson;
|
|
5183
5190
|
const oldValue = pkgJson[field];
|
|
5184
5191
|
if (oldValue) {
|
|
5185
5192
|
// The field already exists so we simply update the field value.
|
|
5186
|
-
if (field ===
|
|
5193
|
+
if (field === PNPM$1) {
|
|
5194
|
+
const isPnpmObj = objects.isObject(oldValue);
|
|
5187
5195
|
if (objects.hasKeys(value)) {
|
|
5188
5196
|
editablePkgJson.update({
|
|
5189
5197
|
[field]: {
|
|
5190
|
-
...(
|
|
5191
|
-
overrides:
|
|
5198
|
+
...(isPnpmObj ? oldValue : {}),
|
|
5199
|
+
overrides: {
|
|
5200
|
+
...(isPnpmObj ? oldValue[OVERRIDES] : {}),
|
|
5201
|
+
...value
|
|
5202
|
+
}
|
|
5192
5203
|
}
|
|
5193
5204
|
});
|
|
5194
5205
|
} else {
|
|
5195
5206
|
// Properties with undefined values are omitted when saved as JSON.
|
|
5196
|
-
editablePkgJson.update(objects.hasKeys(
|
|
5207
|
+
editablePkgJson.update(objects.hasKeys(oldValue) ? {
|
|
5197
5208
|
[field]: {
|
|
5198
|
-
...(
|
|
5209
|
+
...(isPnpmObj ? oldValue : {}),
|
|
5199
5210
|
overrides: undefined
|
|
5200
5211
|
}
|
|
5201
5212
|
} : {
|
|
@@ -5214,7 +5225,7 @@ function updatePkgJson(editablePkgJson, field, value) {
|
|
|
5214
5225
|
}
|
|
5215
5226
|
return;
|
|
5216
5227
|
}
|
|
5217
|
-
if ((field === OVERRIDES || field ===
|
|
5228
|
+
if ((field === OVERRIDES || field === PNPM$1 || field === RESOLUTIONS) && !objects.hasKeys(value)) {
|
|
5218
5229
|
return;
|
|
5219
5230
|
}
|
|
5220
5231
|
// Since the field doesn't exist we want to insert it into the package.json
|
|
@@ -5232,7 +5243,7 @@ function updatePkgJson(editablePkgJson, field, value) {
|
|
|
5232
5243
|
} else if (field === RESOLUTIONS) {
|
|
5233
5244
|
isPlacingHigher = true;
|
|
5234
5245
|
insertIndex = getHighestEntryIndex(entries, [...depFields, OVERRIDES, PNPM$1]);
|
|
5235
|
-
} else if (field ===
|
|
5246
|
+
} else if (field === PNPM$1) {
|
|
5236
5247
|
insertIndex = getLowestEntryIndex(entries, [OVERRIDES, RESOLUTIONS]);
|
|
5237
5248
|
if (insertIndex === -1) {
|
|
5238
5249
|
isPlacingHigher = true;
|
|
@@ -5251,26 +5262,28 @@ function updatePkgJson(editablePkgJson, field, value) {
|
|
|
5251
5262
|
} else if (isPlacingHigher) {
|
|
5252
5263
|
insertIndex += 1;
|
|
5253
5264
|
}
|
|
5254
|
-
entries.splice(insertIndex, 0, [field,
|
|
5265
|
+
entries.splice(insertIndex, 0, [field, field === PNPM$1 ? {
|
|
5266
|
+
[OVERRIDES]: value
|
|
5267
|
+
} : value]);
|
|
5255
5268
|
editablePkgJson.fromJSON(`${JSON.stringify(Object.fromEntries(entries), null, 2)}\n`);
|
|
5256
5269
|
}
|
|
5257
|
-
function
|
|
5258
|
-
|
|
5270
|
+
function updateOverridesField(editablePkgJson, overrides) {
|
|
5271
|
+
updatePkgJsonField(editablePkgJson, OVERRIDES, overrides);
|
|
5259
5272
|
}
|
|
5260
|
-
function
|
|
5261
|
-
|
|
5273
|
+
function updateResolutionsField(editablePkgJson, overrides) {
|
|
5274
|
+
updatePkgJsonField(editablePkgJson, RESOLUTIONS, overrides);
|
|
5262
5275
|
}
|
|
5263
|
-
function
|
|
5264
|
-
|
|
5276
|
+
function updatePnpmField(editablePkgJson, overrides) {
|
|
5277
|
+
updatePkgJsonField(editablePkgJson, PNPM$1, overrides);
|
|
5265
5278
|
}
|
|
5266
|
-
const updateManifestByAgent = new Map([[BUN,
|
|
5279
|
+
const updateManifestByAgent = new Map([[BUN, updateResolutionsField], [NPM$2, updateOverridesField], [PNPM$1, updatePnpmField], [VLT, updateOverridesField], [YARN_BERRY, updateResolutionsField], [YARN_CLASSIC$1, updateResolutionsField]]);
|
|
5267
5280
|
|
|
5268
5281
|
const {
|
|
5269
5282
|
NPM: NPM$1,
|
|
5270
5283
|
PNPM,
|
|
5271
5284
|
YARN_CLASSIC
|
|
5272
5285
|
} = constants;
|
|
5273
|
-
const
|
|
5286
|
+
const CMD_NAME$1 = 'socket optimize';
|
|
5274
5287
|
const manifestNpmOverrides = registry.getManifestData(NPM$1);
|
|
5275
5288
|
async function addOverrides(pkgPath, pkgEnvDetails, options) {
|
|
5276
5289
|
const {
|
|
@@ -5308,24 +5321,17 @@ async function addOverrides(pkgPath, pkgEnvDetails, options) {
|
|
|
5308
5321
|
const {
|
|
5309
5322
|
content: pkgJson
|
|
5310
5323
|
} = editablePkgJson;
|
|
5311
|
-
const isRoot = pkgPath === rootPath;
|
|
5312
|
-
const isLockScanned = isRoot && !prod;
|
|
5313
5324
|
const workspaceName = path.relative(rootPath, pkgPath);
|
|
5314
5325
|
const workspaceGlobs = await getWorkspaceGlobs(agent, pkgPath, pkgJson);
|
|
5326
|
+
const isRoot = pkgPath === rootPath;
|
|
5327
|
+
const isLockScanned = isRoot && !prod;
|
|
5315
5328
|
const isWorkspace = !!workspaceGlobs;
|
|
5316
|
-
if (isWorkspace && agent === PNPM &&
|
|
5329
|
+
if (isWorkspace && agent === PNPM &&
|
|
5330
|
+
// npmExecPath will === the agent name IF it CANNOT be resolved.
|
|
5331
|
+
npmExecPath === NPM$1 && !state.warnedPnpmWorkspaceRequiresNpm) {
|
|
5317
5332
|
state.warnedPnpmWorkspaceRequiresNpm = true;
|
|
5318
|
-
logger?.warn(`${
|
|
5333
|
+
logger?.warn(cmdPrefixMessage(CMD_NAME$1, `${agent} workspace support requires \`npm ls\`, falling back to \`${agent} list\``));
|
|
5319
5334
|
}
|
|
5320
|
-
const thingToScan = isLockScanned ? lockSrc : await lsByAgent.get(agent)(agentExecPath, pkgPath, {
|
|
5321
|
-
npmExecPath
|
|
5322
|
-
});
|
|
5323
|
-
// The AgentDepsIncludesFn and AgentLockIncludesFn types overlap in their
|
|
5324
|
-
// first two parameters. AgentLockIncludesFn accepts an optional third
|
|
5325
|
-
// parameter which AgentDepsIncludesFn will ignore so we cast thingScanner
|
|
5326
|
-
// as an AgentLockIncludesFn type.
|
|
5327
|
-
const thingScanner = isLockScanned ? lockfileIncludesByAgent.get(agent) : depsIncludesByAgent.get(agent);
|
|
5328
|
-
const depEntries = getDependencyEntries(pkgJson);
|
|
5329
5335
|
const overridesDataObjects = [];
|
|
5330
5336
|
if (pkgJson['private'] || isWorkspace) {
|
|
5331
5337
|
overridesDataObjects.push(overridesDataByAgent.get(agent)(pkgJson));
|
|
@@ -5334,10 +5340,12 @@ async function addOverrides(pkgPath, pkgEnvDetails, options) {
|
|
|
5334
5340
|
}
|
|
5335
5341
|
spinner?.setText(`Adding overrides${workspaceName ? ` to ${workspaceName}` : ''}...`);
|
|
5336
5342
|
const depAliasMap = new Map();
|
|
5343
|
+
const depEntries = getDependencyEntries(pkgJson);
|
|
5337
5344
|
const nodeRange = `>=${pkgEnvDetails.minimumNodeVersion}`;
|
|
5338
5345
|
const manifestEntries = manifestNpmOverrides.filter(({
|
|
5339
5346
|
1: data
|
|
5340
5347
|
}) => semver.satisfies(semver.coerce(data.engines.node), nodeRange));
|
|
5348
|
+
|
|
5341
5349
|
// Chunk package names to process them in parallel 3 at a time.
|
|
5342
5350
|
await promises.pEach(manifestEntries, 3, async ({
|
|
5343
5351
|
1: data
|
|
@@ -5374,6 +5382,14 @@ async function addOverrides(pkgPath, pkgEnvDetails, options) {
|
|
|
5374
5382
|
}
|
|
5375
5383
|
}
|
|
5376
5384
|
if (isRoot) {
|
|
5385
|
+
// The AgentDepsIncludesFn and AgentLockIncludesFn types overlap in their
|
|
5386
|
+
// first two parameters. AgentLockIncludesFn accepts an optional third
|
|
5387
|
+
// parameter which AgentDepsIncludesFn will ignore so we cast thingScanner
|
|
5388
|
+
// as an AgentLockIncludesFn type.
|
|
5389
|
+
const thingScanner = isLockScanned ? lockfileIncludesByAgent.get(agent) : depsIncludesByAgent.get(agent);
|
|
5390
|
+
const thingToScan = isLockScanned ? lockSrc : await lsByAgent.get(agent)(agentExecPath, pkgPath, {
|
|
5391
|
+
npmExecPath
|
|
5392
|
+
});
|
|
5377
5393
|
// Chunk package names to process them in parallel 3 at a time.
|
|
5378
5394
|
await promises.pEach(overridesDataObjects, 3, async ({
|
|
5379
5395
|
overrides,
|
|
@@ -5450,11 +5466,50 @@ async function addOverrides(pkgPath, pkgEnvDetails, options) {
|
|
|
5450
5466
|
}
|
|
5451
5467
|
return state;
|
|
5452
5468
|
}
|
|
5469
|
+
|
|
5470
|
+
const {
|
|
5471
|
+
NPM_BUGGY_OVERRIDES_PATCHED_VERSION
|
|
5472
|
+
} = constants;
|
|
5473
|
+
async function updateLockfile(pkgEnvDetails, options) {
|
|
5474
|
+
const {
|
|
5475
|
+
cmdName = '',
|
|
5476
|
+
logger,
|
|
5477
|
+
spinner
|
|
5478
|
+
} = {
|
|
5479
|
+
__proto__: null,
|
|
5480
|
+
...options
|
|
5481
|
+
};
|
|
5482
|
+
const isSpinning = !!spinner?.isSpinning;
|
|
5483
|
+
if (!isSpinning) {
|
|
5484
|
+
spinner?.start();
|
|
5485
|
+
}
|
|
5486
|
+
spinner?.setText(`Updating ${pkgEnvDetails.lockName}...`);
|
|
5487
|
+
try {
|
|
5488
|
+
await runAgentInstall(pkgEnvDetails, {
|
|
5489
|
+
spinner
|
|
5490
|
+
});
|
|
5491
|
+
if (pkgEnvDetails.features.npmBuggyOverrides) {
|
|
5492
|
+
logger?.log(`💡 Re-run ${cmdName ? `${cmdName} ` : ''}whenever ${pkgEnvDetails.lockName} changes.\n This can be skipped for ${pkgEnvDetails.agent} >=${NPM_BUGGY_OVERRIDES_PATCHED_VERSION}.`);
|
|
5493
|
+
}
|
|
5494
|
+
} catch (e) {
|
|
5495
|
+
spinner?.stop();
|
|
5496
|
+
logger?.fail(cmdPrefixMessage(cmdName, `${pkgEnvDetails.agent} install failed to update ${pkgEnvDetails.lockName}`));
|
|
5497
|
+
logger?.error(e);
|
|
5498
|
+
}
|
|
5499
|
+
if (isSpinning) {
|
|
5500
|
+
spinner?.start();
|
|
5501
|
+
} else {
|
|
5502
|
+
spinner?.stop();
|
|
5503
|
+
}
|
|
5504
|
+
}
|
|
5505
|
+
|
|
5506
|
+
const CMD_NAME = 'socket optimize';
|
|
5453
5507
|
function createActionMessage(verb, overrideCount, workspaceCount) {
|
|
5454
5508
|
return `${verb} ${overrideCount} Socket.dev optimized ${words.pluralize('override', overrideCount)}${workspaceCount ? ` in ${workspaceCount} ${words.pluralize('workspace', workspaceCount)}` : ''}`;
|
|
5455
5509
|
}
|
|
5456
5510
|
async function applyOptimization(cwd, pin, prod) {
|
|
5457
5511
|
const pkgEnvDetails = await detectAndValidatePackageEnvironment(cwd, {
|
|
5512
|
+
cmdName: CMD_NAME,
|
|
5458
5513
|
logger: logger.logger,
|
|
5459
5514
|
prod
|
|
5460
5515
|
});
|
|
@@ -5472,10 +5527,17 @@ async function applyOptimization(cwd, pin, prod) {
|
|
|
5472
5527
|
prod,
|
|
5473
5528
|
spinner
|
|
5474
5529
|
});
|
|
5475
|
-
spinner.stop();
|
|
5476
5530
|
const addedCount = state.added.size;
|
|
5477
5531
|
const updatedCount = state.updated.size;
|
|
5478
5532
|
const pkgJsonChanged = addedCount > 0 || updatedCount > 0;
|
|
5533
|
+
if (pkgJsonChanged || pkgEnvDetails.features.npmBuggyOverrides) {
|
|
5534
|
+
await updateLockfile(pkgEnvDetails, {
|
|
5535
|
+
cmdName: CMD_NAME,
|
|
5536
|
+
logger: logger.logger,
|
|
5537
|
+
spinner
|
|
5538
|
+
});
|
|
5539
|
+
}
|
|
5540
|
+
spinner.stop();
|
|
5479
5541
|
if (pkgJsonChanged) {
|
|
5480
5542
|
if (updatedCount > 0) {
|
|
5481
5543
|
logger.logger?.log(`${createActionMessage('Updated', updatedCount, state.updatedInWorkspaces.size)}${addedCount ? '.' : '🚀'}`);
|
|
@@ -5486,14 +5548,6 @@ async function applyOptimization(cwd, pin, prod) {
|
|
|
5486
5548
|
} else {
|
|
5487
5549
|
logger.logger?.log('Congratulations! Already Socket.dev optimized 🎉');
|
|
5488
5550
|
}
|
|
5489
|
-
if (pkgEnvDetails.agent === NPM$1 || pkgJsonChanged) {
|
|
5490
|
-
// Always update package-lock.json until the npm overrides PR lands:
|
|
5491
|
-
// https://github.com/npm/cli/pull/8089
|
|
5492
|
-
await updateLockfile(pkgEnvDetails, {
|
|
5493
|
-
logger: logger.logger,
|
|
5494
|
-
spinner
|
|
5495
|
-
});
|
|
5496
|
-
}
|
|
5497
5551
|
}
|
|
5498
5552
|
|
|
5499
5553
|
const {
|
|
@@ -8226,15 +8280,15 @@ async function run(argv, importMeta, {
|
|
|
8226
8280
|
}
|
|
8227
8281
|
|
|
8228
8282
|
const {
|
|
8229
|
-
|
|
8230
|
-
rootPkgJsonPath
|
|
8283
|
+
SOCKET_CLI_BIN_NAME
|
|
8231
8284
|
} = constants;
|
|
8232
8285
|
|
|
8233
8286
|
// TODO: Add autocompletion using https://socket.dev/npm/package/omelette
|
|
8234
8287
|
void (async () => {
|
|
8235
8288
|
await vendor.updater({
|
|
8236
|
-
name:
|
|
8237
|
-
|
|
8289
|
+
name: SOCKET_CLI_BIN_NAME,
|
|
8290
|
+
// The '@rollup/plugin-replace' will replace "process.env['INLINED_SOCKET_CLI_VERSION']".
|
|
8291
|
+
version: "0.14.60",
|
|
8238
8292
|
ttl: 86_400_000 /* 24 hours in milliseconds */
|
|
8239
8293
|
});
|
|
8240
8294
|
try {
|
|
@@ -8270,7 +8324,7 @@ void (async () => {
|
|
|
8270
8324
|
}
|
|
8271
8325
|
},
|
|
8272
8326
|
argv: process$1.argv.slice(2),
|
|
8273
|
-
name:
|
|
8327
|
+
name: SOCKET_CLI_BIN_NAME,
|
|
8274
8328
|
importMeta: {
|
|
8275
8329
|
url: `${require$$0.pathToFileURL(__filename)}`
|
|
8276
8330
|
}
|
|
@@ -8294,12 +8348,12 @@ void (async () => {
|
|
|
8294
8348
|
} else {
|
|
8295
8349
|
errorTitle = 'Unexpected error with no details';
|
|
8296
8350
|
}
|
|
8297
|
-
logger.logger.fail(`${colors.bgRed(colors.white(errorTitle
|
|
8351
|
+
logger.logger.fail(`${colors.bgRed(colors.white(`${errorTitle}:`))} ${errorMessage}`);
|
|
8298
8352
|
if (errorBody) {
|
|
8299
8353
|
logger.logger.error(`\n${errorBody}`);
|
|
8300
8354
|
}
|
|
8301
8355
|
await shadowNpmInject.captureException(e);
|
|
8302
8356
|
}
|
|
8303
8357
|
})();
|
|
8304
|
-
//# debugId=
|
|
8358
|
+
//# debugId=a4fe81ae-a54c-4a9c-bd36-803984c36419
|
|
8305
8359
|
//# sourceMappingURL=cli.js.map
|