@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/module-sync/cli.js
CHANGED
|
@@ -903,19 +903,20 @@ class GitHub {
|
|
|
903
903
|
case 'push':
|
|
904
904
|
return this.prNumber ? 'diff' : 'main';
|
|
905
905
|
case 'pull_request':
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
906
|
+
{
|
|
907
|
+
// This env variable needs to be set in the GitHub action.
|
|
908
|
+
// Add this code below to GitHub action:
|
|
909
|
+
// - steps:
|
|
910
|
+
// - name: Get PR State
|
|
911
|
+
// if: github.event_name == 'pull_request'
|
|
912
|
+
// run: echo "EVENT_ACTION=${{ github.event.action }}" >> $GITHUB_ENV
|
|
913
|
+
const eventAction = process.env['EVENT_ACTION'];
|
|
914
|
+
if (eventAction === 'opened' || eventAction === 'synchronize') {
|
|
915
|
+
return 'diff';
|
|
916
|
+
}
|
|
917
|
+
if (!eventAction) {
|
|
918
|
+
throw new Error('Missing event action');
|
|
919
|
+
}
|
|
919
920
|
logger.logger.log(`Pull request action: ${eventAction} is not supported`);
|
|
920
921
|
process.exit();
|
|
921
922
|
}
|
|
@@ -1518,14 +1519,14 @@ function emitBanner(name) {
|
|
|
1518
1519
|
// It also helps with debugging since it contains version and command details.
|
|
1519
1520
|
// Note: print over stderr to preserve stdout for flags like --json and
|
|
1520
1521
|
// --markdown. If we don't do this, you can't use --json in particular
|
|
1521
|
-
// and pipe the result to other tools. By
|
|
1522
|
+
// and pipe the result to other tools. By emitting the banner over stderr
|
|
1522
1523
|
// you can do something like `socket scan view xyz | jq | process`.
|
|
1523
1524
|
// The spinner also emits over stderr for example.
|
|
1524
1525
|
logger.logger.error(getAsciiHeader(name));
|
|
1525
1526
|
}
|
|
1526
1527
|
function getAsciiHeader(command) {
|
|
1527
|
-
const cliVersion = // The '@rollup/plugin-replace' will replace "process.env['
|
|
1528
|
-
"0.14.
|
|
1528
|
+
const cliVersion = // The '@rollup/plugin-replace' will replace "process.env['INLINED_SOCKET_CLI_VERSION_HASH']".
|
|
1529
|
+
"0.14.60:48319f6:78cf0eae:pub";
|
|
1529
1530
|
const nodeVersion = process.version;
|
|
1530
1531
|
const apiToken = shadowNpmInject.getSetting('apiToken');
|
|
1531
1532
|
const shownToken = apiToken ? getLastFiveOfApiToken(apiToken) : 'no';
|
|
@@ -2258,30 +2259,45 @@ async function run$x(argv, importMeta, {
|
|
|
2258
2259
|
}
|
|
2259
2260
|
|
|
2260
2261
|
const {
|
|
2261
|
-
NPM: NPM$
|
|
2262
|
+
NPM: NPM$f,
|
|
2262
2263
|
NPX: NPX$3,
|
|
2263
|
-
|
|
2264
|
+
PACKAGE_LOCK_JSON,
|
|
2265
|
+
PNPM: PNPM$a,
|
|
2266
|
+
YARN: YARN$1,
|
|
2267
|
+
YARN_LOCK
|
|
2264
2268
|
} = constants;
|
|
2265
|
-
const nodejsPlatformTypes = new Set(['javascript', 'js', 'nodejs', NPM$
|
|
2266
|
-
async function runCycloneDX(
|
|
2269
|
+
const nodejsPlatformTypes = new Set(['javascript', 'js', 'nodejs', NPM$f, PNPM$a, 'ts', 'tsx', 'typescript']);
|
|
2270
|
+
async function runCycloneDX(yargvWithYes) {
|
|
2267
2271
|
let cleanupPackageLock = false;
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2272
|
+
const {
|
|
2273
|
+
yes,
|
|
2274
|
+
...yargv
|
|
2275
|
+
} = {
|
|
2276
|
+
__proto__: null,
|
|
2277
|
+
...yargvWithYes
|
|
2278
|
+
};
|
|
2279
|
+
const yesArgs = yes ? ['--yes'] : [];
|
|
2280
|
+
if (yargv.type !== YARN$1 && nodejsPlatformTypes.has(yargv.type) && fs.existsSync(`./${YARN_LOCK}`)) {
|
|
2281
|
+
if (fs.existsSync(`./${PACKAGE_LOCK_JSON}`)) {
|
|
2282
|
+
yargv.type = NPM$f;
|
|
2271
2283
|
} else {
|
|
2272
2284
|
// Use synp to create a package-lock.json from the yarn.lock,
|
|
2273
2285
|
// based on the node_modules folder, for a more accurate SBOM.
|
|
2274
2286
|
try {
|
|
2275
|
-
await shadowBin(NPX$3, [
|
|
2276
|
-
|
|
2287
|
+
await shadowBin(NPX$3, [...yesArgs,
|
|
2288
|
+
// The '@rollup/plugin-replace' will replace "process.env['INLINED_SYNP_VERSION']".
|
|
2289
|
+
`synp@${"^1.9.14"}`, '--source-file', `./${YARN_LOCK}`]);
|
|
2290
|
+
yargv.type = NPM$f;
|
|
2277
2291
|
cleanupPackageLock = true;
|
|
2278
2292
|
} catch {}
|
|
2279
2293
|
}
|
|
2280
2294
|
}
|
|
2281
|
-
await shadowBin(NPX$3, [
|
|
2295
|
+
await shadowBin(NPX$3, [...yesArgs,
|
|
2296
|
+
// The '@rollup/plugin-replace' will replace "process.env['INLINED_CYCLONEDX_CDXGEN_VERSION']".
|
|
2297
|
+
`@cyclonedx/cdxgen@${"^11.2.1"}`, ...argvToArray(yargv)]);
|
|
2282
2298
|
if (cleanupPackageLock) {
|
|
2283
2299
|
try {
|
|
2284
|
-
await fs.promises.rm(
|
|
2300
|
+
await fs.promises.rm(`./${PACKAGE_LOCK_JSON}`);
|
|
2285
2301
|
} catch {}
|
|
2286
2302
|
}
|
|
2287
2303
|
const fullOutputPath = path.join(process$1.cwd(), yargv.output);
|
|
@@ -2290,13 +2306,17 @@ async function runCycloneDX(yargv) {
|
|
|
2290
2306
|
}
|
|
2291
2307
|
}
|
|
2292
2308
|
function argvToArray(argv) {
|
|
2293
|
-
if (argv['help'])
|
|
2309
|
+
if (argv['help']) {
|
|
2310
|
+
return ['--help'];
|
|
2311
|
+
}
|
|
2294
2312
|
const result = [];
|
|
2295
2313
|
for (const {
|
|
2296
2314
|
0: key,
|
|
2297
2315
|
1: value
|
|
2298
2316
|
} of Object.entries(argv)) {
|
|
2299
|
-
if (key === '_' || key === '--')
|
|
2317
|
+
if (key === '_' || key === '--') {
|
|
2318
|
+
continue;
|
|
2319
|
+
}
|
|
2300
2320
|
if (key === 'babel' || key === 'install-deps' || key === 'validate') {
|
|
2301
2321
|
// cdxgen documents no-babel, no-install-deps, and no-validate flags so
|
|
2302
2322
|
// use them when relevant.
|
|
@@ -2315,6 +2335,32 @@ function argvToArray(argv) {
|
|
|
2315
2335
|
return result;
|
|
2316
2336
|
}
|
|
2317
2337
|
|
|
2338
|
+
const helpFlags = new Set(['--help', '-h']);
|
|
2339
|
+
function cmdFlagsToString(args) {
|
|
2340
|
+
const result = [];
|
|
2341
|
+
for (let i = 0, {
|
|
2342
|
+
length
|
|
2343
|
+
} = args; i < length; i += 1) {
|
|
2344
|
+
if (args[i].startsWith('--')) {
|
|
2345
|
+
// Check if the next item exists and is NOT another flag.
|
|
2346
|
+
if (i + 1 < length && !args[i + 1].startsWith('--')) {
|
|
2347
|
+
result.push(`${args[i]}=${args[i + 1]}`);
|
|
2348
|
+
i += 1;
|
|
2349
|
+
} else {
|
|
2350
|
+
result.push(args[i]);
|
|
2351
|
+
}
|
|
2352
|
+
}
|
|
2353
|
+
}
|
|
2354
|
+
return result.join(' ');
|
|
2355
|
+
}
|
|
2356
|
+
function cmdPrefixMessage(cmdName, text) {
|
|
2357
|
+
const cmdPrefix = cmdName ? `${cmdName}: ` : '';
|
|
2358
|
+
return `${cmdPrefix}${text}`;
|
|
2359
|
+
}
|
|
2360
|
+
function isHelpFlag(cmdArg) {
|
|
2361
|
+
return helpFlags.has(cmdArg);
|
|
2362
|
+
}
|
|
2363
|
+
|
|
2318
2364
|
// import { meowOrExit } from '../../utils/meow-with-subcommands'
|
|
2319
2365
|
const {
|
|
2320
2366
|
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$v
|
|
@@ -2369,7 +2415,8 @@ const yargsConfig = {
|
|
|
2369
2415
|
recurse: ['r'],
|
|
2370
2416
|
'resolve-class': ['c'],
|
|
2371
2417
|
type: ['t'],
|
|
2372
|
-
version: ['v']
|
|
2418
|
+
version: ['v'],
|
|
2419
|
+
yes: ['y']
|
|
2373
2420
|
},
|
|
2374
2421
|
array: [{
|
|
2375
2422
|
key: 'author',
|
|
@@ -2387,7 +2434,10 @@ const yargsConfig = {
|
|
|
2387
2434
|
key: 'standard',
|
|
2388
2435
|
type: 'string'
|
|
2389
2436
|
}],
|
|
2390
|
-
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'
|
|
2437
|
+
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',
|
|
2438
|
+
// The --yes flag and -y alias map to the corresponding flag and alias of npx.
|
|
2439
|
+
// https://docs.npmjs.com/cli/v7/commands/npx#compatibility-with-older-npx-versions
|
|
2440
|
+
'yes'],
|
|
2391
2441
|
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']
|
|
2392
2442
|
};
|
|
2393
2443
|
const config$w = {
|
|
@@ -2415,14 +2465,12 @@ async function run$w(argv, importMeta, {
|
|
|
2415
2465
|
}) {
|
|
2416
2466
|
const cli = meowOrExit({
|
|
2417
2467
|
allowUnknownFlags: true,
|
|
2418
|
-
|
|
2419
|
-
|
|
2468
|
+
// Don't let meow take over --help.
|
|
2469
|
+
argv: argv.filter(a => !isHelpFlag(a)),
|
|
2420
2470
|
config: config$w,
|
|
2421
2471
|
importMeta,
|
|
2422
2472
|
parentName
|
|
2423
2473
|
});
|
|
2424
|
-
//
|
|
2425
|
-
//
|
|
2426
2474
|
// if (cli.input.length)
|
|
2427
2475
|
// logger.fail(
|
|
2428
2476
|
// stripIndents`
|
|
@@ -2434,11 +2482,10 @@ async function run$w(argv, importMeta, {
|
|
|
2434
2482
|
// return
|
|
2435
2483
|
// }
|
|
2436
2484
|
|
|
2437
|
-
// TODO:
|
|
2485
|
+
// TODO: Convert to meow.
|
|
2438
2486
|
const yargv = {
|
|
2439
2487
|
...yargsParse(argv, yargsConfig)
|
|
2440
|
-
};
|
|
2441
|
-
|
|
2488
|
+
};
|
|
2442
2489
|
const unknown = yargv._;
|
|
2443
2490
|
const {
|
|
2444
2491
|
length: unknownLength
|
|
@@ -2451,13 +2498,13 @@ async function run$w(argv, importMeta, {
|
|
|
2451
2498
|
logger.logger.fail(`Unknown ${words.pluralize('argument', unknownLength)}: ${yargv._.join(', ')}`);
|
|
2452
2499
|
return;
|
|
2453
2500
|
}
|
|
2454
|
-
if (yargv.output === undefined) {
|
|
2455
|
-
yargv.output = 'socket-cdx.json';
|
|
2456
|
-
}
|
|
2457
2501
|
if (cli.flags['dryRun']) {
|
|
2458
2502
|
logger.logger.log(DRY_RUN_BAIL_TEXT$v);
|
|
2459
2503
|
return;
|
|
2460
2504
|
}
|
|
2505
|
+
if (yargv.output === undefined) {
|
|
2506
|
+
yargv.output = 'socket-cdx.json';
|
|
2507
|
+
}
|
|
2461
2508
|
await runCycloneDX(yargv);
|
|
2462
2509
|
}
|
|
2463
2510
|
|
|
@@ -2794,7 +2841,7 @@ const cmdDiffScan = {
|
|
|
2794
2841
|
};
|
|
2795
2842
|
|
|
2796
2843
|
const {
|
|
2797
|
-
NPM: NPM$
|
|
2844
|
+
NPM: NPM$e
|
|
2798
2845
|
} = constants;
|
|
2799
2846
|
function isTopLevel(tree, node) {
|
|
2800
2847
|
return tree.children.get(node.name) === node;
|
|
@@ -2838,7 +2885,7 @@ async function npmFix(_pkgEnvDetails, cwd, options) {
|
|
|
2838
2885
|
// eslint-disable-next-line no-await-in-loop
|
|
2839
2886
|
await arb.buildIdealTree();
|
|
2840
2887
|
const tree = arb.idealTree;
|
|
2841
|
-
const hasUpgrade = !!registry.getManifestData(NPM$
|
|
2888
|
+
const hasUpgrade = !!registry.getManifestData(NPM$e, name);
|
|
2842
2889
|
if (hasUpgrade) {
|
|
2843
2890
|
spinner?.info(`Skipping ${name}. Socket Optimize package exists.`);
|
|
2844
2891
|
continue;
|
|
@@ -2938,24 +2985,6 @@ async function getAlertsMapFromPnpmLockfile(lockfile, options) {
|
|
|
2938
2985
|
return alertsByPkgId;
|
|
2939
2986
|
}
|
|
2940
2987
|
|
|
2941
|
-
function cmdFlagsToString(args) {
|
|
2942
|
-
const result = [];
|
|
2943
|
-
for (let i = 0, {
|
|
2944
|
-
length
|
|
2945
|
-
} = args; i < length; i += 1) {
|
|
2946
|
-
if (args[i].startsWith('--')) {
|
|
2947
|
-
// Check if the next item exists and is NOT another flag.
|
|
2948
|
-
if (i + 1 < length && !args[i + 1].startsWith('--')) {
|
|
2949
|
-
result.push(`${args[i]}=${args[i + 1]}`);
|
|
2950
|
-
i += 1;
|
|
2951
|
-
} else {
|
|
2952
|
-
result.push(args[i]);
|
|
2953
|
-
}
|
|
2954
|
-
}
|
|
2955
|
-
}
|
|
2956
|
-
return result.join(' ');
|
|
2957
|
-
}
|
|
2958
|
-
|
|
2959
2988
|
const {
|
|
2960
2989
|
SOCKET_IPC_HANDSHAKE
|
|
2961
2990
|
} = constants;
|
|
@@ -2973,27 +3002,28 @@ function safeNpmInstall(options) {
|
|
|
2973
3002
|
const useIpc = objects.isObject(ipc);
|
|
2974
3003
|
const useDebug = debug.isDebug();
|
|
2975
3004
|
const terminatorPos = args.indexOf('--');
|
|
2976
|
-
const
|
|
3005
|
+
const binArgs = (terminatorPos === -1 ? args : args.slice(0, terminatorPos)).filter(a => !npm.isAuditFlag(a) && !npm.isFundFlag(a) && !npm.isProgressFlag(a));
|
|
2977
3006
|
const otherArgs = terminatorPos === -1 ? [] : args.slice(terminatorPos);
|
|
2978
|
-
const isSilent = !useDebug && !
|
|
2979
|
-
const logLevelArgs = isSilent ? ['--loglevel', '
|
|
3007
|
+
const isSilent = !useDebug && !binArgs.some(npm.isLoglevelFlag);
|
|
3008
|
+
const logLevelArgs = isSilent ? ['--loglevel', 'silent'] : [];
|
|
2980
3009
|
const spawnPromise = spawn.spawn(
|
|
2981
3010
|
// Lazily access constants.execPath.
|
|
2982
3011
|
constants.execPath, [
|
|
2983
3012
|
// Lazily access constants.nodeHardenFlags.
|
|
2984
3013
|
...constants.nodeHardenFlags,
|
|
2985
3014
|
// Lazily access constants.nodeNoWarningsFlags.
|
|
2986
|
-
...constants.nodeNoWarningsFlags,
|
|
3015
|
+
...constants.nodeNoWarningsFlags,
|
|
3016
|
+
// Lazily access false.
|
|
3017
|
+
...([]), '--require',
|
|
2987
3018
|
// Lazily access constants.distShadowNpmInjectPath.
|
|
2988
3019
|
constants.distShadowNpmInjectPath, agentExecPath, 'install',
|
|
2989
3020
|
// Avoid code paths for 'audit' and 'fund'.
|
|
2990
3021
|
'--no-audit', '--no-fund',
|
|
2991
|
-
// Add
|
|
2992
|
-
// when running the command with recent versions of npm.
|
|
3022
|
+
// Add '--no-progress' to fix input being swallowed by the npm spinner.
|
|
2993
3023
|
'--no-progress',
|
|
2994
|
-
// Add '--loglevel=
|
|
3024
|
+
// Add '--loglevel=silent' if a loglevel flag is not provided and the
|
|
2995
3025
|
// SOCKET_CLI_DEBUG environment variable is not truthy.
|
|
2996
|
-
...logLevelArgs, ...
|
|
3026
|
+
...logLevelArgs, ...binArgs, ...otherArgs], {
|
|
2997
3027
|
spinner,
|
|
2998
3028
|
// Set stdio to include 'ipc'.
|
|
2999
3029
|
// See https://github.com/nodejs/node/blob/v23.6.0/lib/child_process.js#L161-L166
|
|
@@ -3014,7 +3044,7 @@ function safeNpmInstall(options) {
|
|
|
3014
3044
|
}
|
|
3015
3045
|
|
|
3016
3046
|
const {
|
|
3017
|
-
NPM: NPM$
|
|
3047
|
+
NPM: NPM$d
|
|
3018
3048
|
} = constants;
|
|
3019
3049
|
function runAgentInstall(pkgEnvDetails, options) {
|
|
3020
3050
|
const {
|
|
@@ -3022,7 +3052,7 @@ function runAgentInstall(pkgEnvDetails, options) {
|
|
|
3022
3052
|
agentExecPath
|
|
3023
3053
|
} = pkgEnvDetails;
|
|
3024
3054
|
// All package managers support the "install" command.
|
|
3025
|
-
if (agent === NPM$
|
|
3055
|
+
if (agent === NPM$d) {
|
|
3026
3056
|
return safeNpmInstall({
|
|
3027
3057
|
agentExecPath,
|
|
3028
3058
|
...options
|
|
@@ -3053,7 +3083,7 @@ function runAgentInstall(pkgEnvDetails, options) {
|
|
|
3053
3083
|
}
|
|
3054
3084
|
|
|
3055
3085
|
const {
|
|
3056
|
-
NPM: NPM$
|
|
3086
|
+
NPM: NPM$c,
|
|
3057
3087
|
OVERRIDES: OVERRIDES$2,
|
|
3058
3088
|
PNPM: PNPM$9
|
|
3059
3089
|
} = constants;
|
|
@@ -3101,7 +3131,7 @@ async function pnpmFix(pkgEnvDetails, cwd, options) {
|
|
|
3101
3131
|
1: infos
|
|
3102
3132
|
} of infoByPkg) {
|
|
3103
3133
|
const tree = arb.actualTree;
|
|
3104
|
-
const hasUpgrade = !!registry.getManifestData(NPM$
|
|
3134
|
+
const hasUpgrade = !!registry.getManifestData(NPM$c, name);
|
|
3105
3135
|
if (hasUpgrade) {
|
|
3106
3136
|
spinner?.info(`Skipping ${name}. Socket Optimize package exists.`);
|
|
3107
3137
|
continue;
|
|
@@ -3166,24 +3196,27 @@ async function pnpmFix(pkgEnvDetails, cwd, options) {
|
|
|
3166
3196
|
|
|
3167
3197
|
const {
|
|
3168
3198
|
BINARY_LOCK_EXT,
|
|
3169
|
-
BUN: BUN$
|
|
3199
|
+
BUN: BUN$5,
|
|
3200
|
+
HIDDEN_PACKAGE_LOCK_JSON,
|
|
3170
3201
|
LOCK_EXT: LOCK_EXT$1,
|
|
3171
|
-
NPM: NPM$
|
|
3202
|
+
NPM: NPM$b,
|
|
3203
|
+
NPM_BUGGY_OVERRIDES_PATCHED_VERSION: NPM_BUGGY_OVERRIDES_PATCHED_VERSION$1,
|
|
3204
|
+
PACKAGE_JSON,
|
|
3172
3205
|
PNPM: PNPM$8,
|
|
3173
|
-
VLT: VLT$
|
|
3206
|
+
VLT: VLT$5,
|
|
3174
3207
|
YARN,
|
|
3175
|
-
YARN_BERRY: YARN_BERRY$
|
|
3208
|
+
YARN_BERRY: YARN_BERRY$5,
|
|
3176
3209
|
YARN_CLASSIC: YARN_CLASSIC$6
|
|
3177
3210
|
} = constants;
|
|
3178
|
-
const AGENTS = [BUN$
|
|
3211
|
+
const AGENTS = [BUN$5, NPM$b, PNPM$8, YARN_BERRY$5, YARN_CLASSIC$6, VLT$5];
|
|
3179
3212
|
const binByAgent = {
|
|
3180
3213
|
__proto__: null,
|
|
3181
|
-
[BUN$
|
|
3182
|
-
[NPM$
|
|
3214
|
+
[BUN$5]: BUN$5,
|
|
3215
|
+
[NPM$b]: NPM$b,
|
|
3183
3216
|
[PNPM$8]: PNPM$8,
|
|
3184
|
-
[YARN_BERRY$
|
|
3217
|
+
[YARN_BERRY$5]: YARN,
|
|
3185
3218
|
[YARN_CLASSIC$6]: YARN,
|
|
3186
|
-
[VLT$
|
|
3219
|
+
[VLT$5]: VLT$5
|
|
3187
3220
|
};
|
|
3188
3221
|
async function getAgentExecPath(agent) {
|
|
3189
3222
|
const binName = binByAgent[agent];
|
|
@@ -3205,24 +3238,24 @@ async function getAgentVersion(agentExecPath, cwd) {
|
|
|
3205
3238
|
|
|
3206
3239
|
// The order of LOCKS properties IS significant as it affects iteration order.
|
|
3207
3240
|
const LOCKS = {
|
|
3208
|
-
[`bun${LOCK_EXT$1}`]: BUN$
|
|
3209
|
-
[`bun${BINARY_LOCK_EXT}`]: BUN$
|
|
3241
|
+
[`bun${LOCK_EXT$1}`]: BUN$5,
|
|
3242
|
+
[`bun${BINARY_LOCK_EXT}`]: BUN$5,
|
|
3210
3243
|
// If both package-lock.json and npm-shrinkwrap.json are present in the root
|
|
3211
3244
|
// of a project, npm-shrinkwrap.json will take precedence and package-lock.json
|
|
3212
3245
|
// will be ignored.
|
|
3213
3246
|
// https://docs.npmjs.com/cli/v10/configuring-npm/package-lock-json#package-lockjson-vs-npm-shrinkwrapjson
|
|
3214
|
-
'npm-shrinkwrap.json': NPM$
|
|
3215
|
-
'package-lock.json': NPM$
|
|
3247
|
+
'npm-shrinkwrap.json': NPM$b,
|
|
3248
|
+
'package-lock.json': NPM$b,
|
|
3216
3249
|
'pnpm-lock.yaml': PNPM$8,
|
|
3217
3250
|
'pnpm-lock.yml': PNPM$8,
|
|
3218
3251
|
[`yarn${LOCK_EXT$1}`]: YARN_CLASSIC$6,
|
|
3219
|
-
'vlt-lock.json': VLT$
|
|
3252
|
+
'vlt-lock.json': VLT$5,
|
|
3220
3253
|
// Lastly, look for a hidden lock file which is present if .npmrc has package-lock=false:
|
|
3221
3254
|
// https://docs.npmjs.com/cli/v10/configuring-npm/package-lock-json#hidden-lockfiles
|
|
3222
3255
|
//
|
|
3223
3256
|
// Unlike the other LOCKS keys this key contains a directory AND filename so
|
|
3224
3257
|
// it has to be handled differently.
|
|
3225
|
-
'node_modules/.package-lock.json': NPM$
|
|
3258
|
+
'node_modules/.package-lock.json': NPM$b
|
|
3226
3259
|
};
|
|
3227
3260
|
const readLockFileByAgent = (() => {
|
|
3228
3261
|
function wrapReader(reader) {
|
|
@@ -3236,7 +3269,7 @@ const readLockFileByAgent = (() => {
|
|
|
3236
3269
|
const binaryReader = wrapReader(shadowNpmInject.readFileBinary);
|
|
3237
3270
|
const defaultReader = wrapReader(async lockPath => await shadowNpmInject.readFileUtf8(lockPath));
|
|
3238
3271
|
return {
|
|
3239
|
-
[BUN$
|
|
3272
|
+
[BUN$5]: wrapReader(async (lockPath, agentExecPath) => {
|
|
3240
3273
|
const ext = path.extname(lockPath);
|
|
3241
3274
|
if (ext === LOCK_EXT$1) {
|
|
3242
3275
|
return await defaultReader(lockPath);
|
|
@@ -3255,10 +3288,10 @@ const readLockFileByAgent = (() => {
|
|
|
3255
3288
|
}
|
|
3256
3289
|
return undefined;
|
|
3257
3290
|
}),
|
|
3258
|
-
[NPM$
|
|
3291
|
+
[NPM$b]: defaultReader,
|
|
3259
3292
|
[PNPM$8]: defaultReader,
|
|
3260
|
-
[VLT$
|
|
3261
|
-
[YARN_BERRY$
|
|
3293
|
+
[VLT$5]: defaultReader,
|
|
3294
|
+
[YARN_BERRY$5]: defaultReader,
|
|
3262
3295
|
[YARN_CLASSIC$6]: defaultReader
|
|
3263
3296
|
};
|
|
3264
3297
|
})();
|
|
@@ -3270,8 +3303,8 @@ async function detectPackageEnvironment({
|
|
|
3270
3303
|
cwd
|
|
3271
3304
|
});
|
|
3272
3305
|
let lockName = lockPath ? path.basename(lockPath) : undefined;
|
|
3273
|
-
const isHiddenLockFile = lockName ===
|
|
3274
|
-
const pkgJsonPath = lockPath ? path.resolve(lockPath, `${isHiddenLockFile ? '../' : ''}
|
|
3306
|
+
const isHiddenLockFile = lockName === HIDDEN_PACKAGE_LOCK_JSON;
|
|
3307
|
+
const pkgJsonPath = lockPath ? path.resolve(lockPath, `${isHiddenLockFile ? '../' : ''}../${PACKAGE_JSON}`) : await shadowNpmInject.findUp(PACKAGE_JSON, {
|
|
3275
3308
|
cwd
|
|
3276
3309
|
});
|
|
3277
3310
|
const pkgPath = pkgJsonPath && fs.existsSync(pkgJsonPath) ? path.dirname(pkgJsonPath) : undefined;
|
|
@@ -3299,16 +3332,16 @@ async function detectPackageEnvironment({
|
|
|
3299
3332
|
agent = LOCKS[lockName];
|
|
3300
3333
|
}
|
|
3301
3334
|
if (agent === undefined) {
|
|
3302
|
-
agent = NPM$
|
|
3335
|
+
agent = NPM$b;
|
|
3303
3336
|
onUnknown?.(pkgManager);
|
|
3304
3337
|
}
|
|
3305
3338
|
const agentExecPath = await getAgentExecPath(agent);
|
|
3306
|
-
const npmExecPath = agent === NPM$
|
|
3339
|
+
const npmExecPath = agent === NPM$b ? agentExecPath : await getAgentExecPath(NPM$b);
|
|
3307
3340
|
if (agentVersion === undefined) {
|
|
3308
3341
|
agentVersion = await getAgentVersion(agentExecPath, cwd);
|
|
3309
3342
|
}
|
|
3310
3343
|
if (agent === YARN_CLASSIC$6 && (agentVersion?.major ?? 0) > 1) {
|
|
3311
|
-
agent = YARN_BERRY$
|
|
3344
|
+
agent = YARN_BERRY$5;
|
|
3312
3345
|
}
|
|
3313
3346
|
const targets = {
|
|
3314
3347
|
browser: false,
|
|
@@ -3350,6 +3383,8 @@ async function detectPackageEnvironment({
|
|
|
3350
3383
|
lockName = undefined;
|
|
3351
3384
|
lockPath = undefined;
|
|
3352
3385
|
}
|
|
3386
|
+
const pkgSupported = targets.browser || targets.node;
|
|
3387
|
+
const npmBuggyOverrides = agent === NPM$b && !!agentVersion && semver.lt(agentVersion, NPM_BUGGY_OVERRIDES_PATCHED_VERSION$1);
|
|
3353
3388
|
return {
|
|
3354
3389
|
agent,
|
|
3355
3390
|
agentExecPath,
|
|
@@ -3361,19 +3396,16 @@ async function detectPackageEnvironment({
|
|
|
3361
3396
|
npmExecPath,
|
|
3362
3397
|
pkgJson: editablePkgJson,
|
|
3363
3398
|
pkgPath,
|
|
3364
|
-
|
|
3399
|
+
pkgSupported,
|
|
3400
|
+
features: {
|
|
3401
|
+
npmBuggyOverrides
|
|
3402
|
+
},
|
|
3365
3403
|
targets
|
|
3366
3404
|
};
|
|
3367
3405
|
}
|
|
3368
|
-
|
|
3369
|
-
const {
|
|
3370
|
-
BUN: BUN$5,
|
|
3371
|
-
VLT: VLT$5,
|
|
3372
|
-
YARN_BERRY: YARN_BERRY$5
|
|
3373
|
-
} = constants;
|
|
3374
|
-
const COMMAND_TITLE$2 = 'Socket Optimize';
|
|
3375
3406
|
async function detectAndValidatePackageEnvironment(cwd, options) {
|
|
3376
3407
|
const {
|
|
3408
|
+
cmdName = '',
|
|
3377
3409
|
logger,
|
|
3378
3410
|
prod
|
|
3379
3411
|
} = {
|
|
@@ -3383,44 +3415,45 @@ async function detectAndValidatePackageEnvironment(cwd, options) {
|
|
|
3383
3415
|
const details = await detectPackageEnvironment({
|
|
3384
3416
|
cwd,
|
|
3385
3417
|
onUnknown(pkgManager) {
|
|
3386
|
-
logger?.warn(
|
|
3418
|
+
logger?.warn(cmdPrefixMessage(cmdName, `Unknown package manager${pkgManager ? ` ${pkgManager}` : ''}, defaulting to npm`));
|
|
3387
3419
|
}
|
|
3388
3420
|
});
|
|
3389
|
-
if (!details.
|
|
3390
|
-
logger?.fail(
|
|
3421
|
+
if (!details.pkgSupported) {
|
|
3422
|
+
logger?.fail(cmdPrefixMessage(cmdName, 'No supported Node or browser range detected'));
|
|
3391
3423
|
return;
|
|
3392
3424
|
}
|
|
3393
3425
|
if (details.agent === VLT$5) {
|
|
3394
|
-
logger?.fail(`${
|
|
3426
|
+
logger?.fail(cmdPrefixMessage(cmdName, `${details.agent} does not support overrides. Soon, though ⚡`));
|
|
3395
3427
|
return;
|
|
3396
3428
|
}
|
|
3397
3429
|
const lockName = details.lockName ?? 'lock file';
|
|
3398
3430
|
if (details.lockName === undefined || details.lockSrc === undefined) {
|
|
3399
|
-
logger?.fail(
|
|
3431
|
+
logger?.fail(cmdPrefixMessage(cmdName, `No ${lockName} found`));
|
|
3400
3432
|
return;
|
|
3401
3433
|
}
|
|
3402
3434
|
if (details.lockSrc.trim() === '') {
|
|
3403
|
-
logger?.fail(`${
|
|
3435
|
+
logger?.fail(cmdPrefixMessage(cmdName, `${lockName} is empty`));
|
|
3404
3436
|
return;
|
|
3405
3437
|
}
|
|
3406
3438
|
if (details.pkgPath === undefined) {
|
|
3407
|
-
logger?.fail(
|
|
3439
|
+
logger?.fail(cmdPrefixMessage(cmdName, `No ${PACKAGE_JSON} found`));
|
|
3408
3440
|
return;
|
|
3409
3441
|
}
|
|
3410
3442
|
if (prod && (details.agent === BUN$5 || details.agent === YARN_BERRY$5)) {
|
|
3411
|
-
logger?.fail(
|
|
3443
|
+
logger?.fail(cmdPrefixMessage(cmdName, `--prod not supported for ${details.agent}${details.agentVersion ? `@${details.agentVersion.version}` : ''}`));
|
|
3412
3444
|
return;
|
|
3413
3445
|
}
|
|
3414
3446
|
if (details.lockPath && path.relative(cwd, details.lockPath).startsWith('.')) {
|
|
3415
|
-
logger?.warn(
|
|
3447
|
+
logger?.warn(cmdPrefixMessage(cmdName, `Package ${lockName} found at ${details.lockPath}`));
|
|
3416
3448
|
}
|
|
3417
3449
|
return details;
|
|
3418
3450
|
}
|
|
3419
3451
|
|
|
3420
3452
|
const {
|
|
3421
|
-
NPM: NPM$
|
|
3453
|
+
NPM: NPM$a,
|
|
3422
3454
|
PNPM: PNPM$7
|
|
3423
3455
|
} = constants;
|
|
3456
|
+
const CMD_NAME$2 = 'socket fix';
|
|
3424
3457
|
async function runFix() {
|
|
3425
3458
|
// Lazily access constants.spinner.
|
|
3426
3459
|
const {
|
|
@@ -3429,6 +3462,7 @@ async function runFix() {
|
|
|
3429
3462
|
spinner.start();
|
|
3430
3463
|
const cwd = process.cwd();
|
|
3431
3464
|
const pkgEnvDetails = await detectAndValidatePackageEnvironment(cwd, {
|
|
3465
|
+
cmdName: CMD_NAME$2,
|
|
3432
3466
|
logger: logger.logger
|
|
3433
3467
|
});
|
|
3434
3468
|
if (!pkgEnvDetails) {
|
|
@@ -3436,7 +3470,7 @@ async function runFix() {
|
|
|
3436
3470
|
return;
|
|
3437
3471
|
}
|
|
3438
3472
|
switch (pkgEnvDetails.agent) {
|
|
3439
|
-
case NPM$
|
|
3473
|
+
case NPM$a:
|
|
3440
3474
|
{
|
|
3441
3475
|
await npmFix(pkgEnvDetails, cwd);
|
|
3442
3476
|
break;
|
|
@@ -3508,7 +3542,7 @@ async function fetchPackageInfo(pkgName, pkgVersion, includeAllIssues) {
|
|
|
3508
3542
|
}
|
|
3509
3543
|
|
|
3510
3544
|
const {
|
|
3511
|
-
NPM: NPM$
|
|
3545
|
+
NPM: NPM$9
|
|
3512
3546
|
} = registryConstants;
|
|
3513
3547
|
function formatScore(score) {
|
|
3514
3548
|
if (score > 80) {
|
|
@@ -3592,7 +3626,7 @@ function logPackageInfo({
|
|
|
3592
3626
|
logger.logger.log('Package has no issues');
|
|
3593
3627
|
}
|
|
3594
3628
|
const format = new shadowNpmInject.ColorOrMarkdown(outputKind === 'markdown');
|
|
3595
|
-
const url = shadowNpmInject.getSocketDevPackageOverviewUrl(NPM$
|
|
3629
|
+
const url = shadowNpmInject.getSocketDevPackageOverviewUrl(NPM$9, pkgName, pkgVersion);
|
|
3596
3630
|
logger.logger.log('\n');
|
|
3597
3631
|
if (pkgVersion === 'latest') {
|
|
3598
3632
|
logger.logger.log(`Detailed info on socket.dev: ${format.hyperlink(`${pkgName}`, url, {
|
|
@@ -3919,9 +3953,11 @@ async function convertGradleToMaven(target, bin, _out, verbose, gradleOpts) {
|
|
|
3919
3953
|
logger.logger.groupEnd();
|
|
3920
3954
|
}
|
|
3921
3955
|
try {
|
|
3922
|
-
// Run sbt with the init script we provide which should yield zero or more
|
|
3923
|
-
// We have to figure out where to store those pom files such that
|
|
3924
|
-
//
|
|
3956
|
+
// Run sbt with the init script we provide which should yield zero or more
|
|
3957
|
+
// pom files. We have to figure out where to store those pom files such that
|
|
3958
|
+
// we can upload them and predict them through the GitHub API. We could do a
|
|
3959
|
+
// .socket folder. We could do a socket.pom.gz with all the poms, although
|
|
3960
|
+
// I'd prefer something plain-text if it is to be committed.
|
|
3925
3961
|
|
|
3926
3962
|
// Note: init.gradle will be exported by .config/rollup.dist.config.mjs
|
|
3927
3963
|
const initLocation = path.join(constants.rootDistPath, 'init.gradle');
|
|
@@ -3968,7 +4004,7 @@ async function convertGradleToMaven(target, bin, _out, verbose, gradleOpts) {
|
|
|
3968
4004
|
// // Move the pom file to ...? initial cwd? loc will be an absolute path, or dump to stdout
|
|
3969
4005
|
// if (out === '-') {
|
|
3970
4006
|
// spinner.start('Result:\n```')
|
|
3971
|
-
// spinner.log(await safeReadFile(loc
|
|
4007
|
+
// spinner.log(await safeReadFile(loc))
|
|
3972
4008
|
// spinner.log('```')
|
|
3973
4009
|
// spinner.successAndStop(`OK`)
|
|
3974
4010
|
// } else {
|
|
@@ -4203,7 +4239,7 @@ async function convertSbtToMaven(target, bin, out, verbose, sbtOpts) {
|
|
|
4203
4239
|
// TODO: maybe we can add an option to target a specific file to dump to stdout
|
|
4204
4240
|
if (out === '-' && poms.length === 1) {
|
|
4205
4241
|
logger.logger.log('Result:\n```');
|
|
4206
|
-
logger.logger.log(await shadowNpmInject.safeReadFile(poms[0]
|
|
4242
|
+
logger.logger.log(await shadowNpmInject.safeReadFile(poms[0]));
|
|
4207
4243
|
logger.logger.log('```');
|
|
4208
4244
|
logger.logger.success(`OK`);
|
|
4209
4245
|
} else if (out === '-') {
|
|
@@ -4680,21 +4716,21 @@ async function run$l(argv, importMeta, {
|
|
|
4680
4716
|
}
|
|
4681
4717
|
|
|
4682
4718
|
const {
|
|
4683
|
-
NPM: NPM$
|
|
4719
|
+
NPM: NPM$8
|
|
4684
4720
|
} = constants;
|
|
4685
4721
|
async function wrapNpm(argv) {
|
|
4686
4722
|
// Lazily access constants.distShadowNpmBinPath.
|
|
4687
4723
|
const shadowBin = require(constants.distShadowNpmBinPath);
|
|
4688
|
-
await shadowBin(NPM$
|
|
4724
|
+
await shadowBin(NPM$8, argv);
|
|
4689
4725
|
}
|
|
4690
4726
|
|
|
4691
4727
|
const {
|
|
4692
4728
|
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$k,
|
|
4693
|
-
NPM: NPM$
|
|
4729
|
+
NPM: NPM$7
|
|
4694
4730
|
} = constants;
|
|
4695
4731
|
const config$k = {
|
|
4696
4732
|
commandName: 'npm',
|
|
4697
|
-
description: `${NPM$
|
|
4733
|
+
description: `${NPM$7} wrapper functionality`,
|
|
4698
4734
|
hidden: false,
|
|
4699
4735
|
flags: {},
|
|
4700
4736
|
help: (command, _config) => `
|
|
@@ -4809,7 +4845,7 @@ async function run$i(argv, importMeta, {
|
|
|
4809
4845
|
|
|
4810
4846
|
const {
|
|
4811
4847
|
BUN: BUN$4,
|
|
4812
|
-
NPM: NPM$
|
|
4848
|
+
NPM: NPM$6,
|
|
4813
4849
|
PNPM: PNPM$6,
|
|
4814
4850
|
VLT: VLT$4,
|
|
4815
4851
|
YARN_BERRY: YARN_BERRY$4,
|
|
@@ -4821,7 +4857,7 @@ function matchLsCmdViewHumanStdout(stdout, name) {
|
|
|
4821
4857
|
function matchQueryCmdStdout(stdout, name) {
|
|
4822
4858
|
return stdout.includes(`"${name}"`);
|
|
4823
4859
|
}
|
|
4824
|
-
const depsIncludesByAgent = new Map([[BUN$4, matchLsCmdViewHumanStdout], [NPM$
|
|
4860
|
+
const depsIncludesByAgent = new Map([[BUN$4, matchLsCmdViewHumanStdout], [NPM$6, matchQueryCmdStdout], [PNPM$6, matchQueryCmdStdout], [VLT$4, matchQueryCmdStdout], [YARN_BERRY$4, matchLsCmdViewHumanStdout], [YARN_CLASSIC$5, matchLsCmdViewHumanStdout]]);
|
|
4825
4861
|
|
|
4826
4862
|
function getDependencyEntries(pkgJson) {
|
|
4827
4863
|
const {
|
|
@@ -4849,7 +4885,7 @@ function getDependencyEntries(pkgJson) {
|
|
|
4849
4885
|
|
|
4850
4886
|
const {
|
|
4851
4887
|
BUN: BUN$3,
|
|
4852
|
-
NPM: NPM$
|
|
4888
|
+
NPM: NPM$5,
|
|
4853
4889
|
OVERRIDES: OVERRIDES$1,
|
|
4854
4890
|
PNPM: PNPM$5,
|
|
4855
4891
|
RESOLUTIONS: RESOLUTIONS$1,
|
|
@@ -4870,7 +4906,7 @@ function getOverridesDataBun(pkgJson) {
|
|
|
4870
4906
|
function getOverridesDataNpm(pkgJson) {
|
|
4871
4907
|
const overrides = pkgJson?.[OVERRIDES$1] ?? {};
|
|
4872
4908
|
return {
|
|
4873
|
-
type: NPM$
|
|
4909
|
+
type: NPM$5,
|
|
4874
4910
|
overrides
|
|
4875
4911
|
};
|
|
4876
4912
|
}
|
|
@@ -4911,7 +4947,7 @@ function getOverridesDataClassic(pkgJson) {
|
|
|
4911
4947
|
overrides
|
|
4912
4948
|
};
|
|
4913
4949
|
}
|
|
4914
|
-
const overridesDataByAgent = new Map([[BUN$3, getOverridesDataBun], [NPM$
|
|
4950
|
+
const overridesDataByAgent = new Map([[BUN$3, getOverridesDataBun], [NPM$5, getOverridesDataNpm], [PNPM$5, getOverridesDataPnpm], [VLT$3, getOverridesDataVlt], [YARN_BERRY$3, getOverridesDataYarn], [YARN_CLASSIC$4, getOverridesDataClassic]]);
|
|
4915
4951
|
|
|
4916
4952
|
const {
|
|
4917
4953
|
PNPM: PNPM$4
|
|
@@ -4922,7 +4958,7 @@ async function getWorkspaceGlobs(agent, pkgPath, pkgJson) {
|
|
|
4922
4958
|
if (agent === PNPM$4) {
|
|
4923
4959
|
for (const workspacePath of [path.join(pkgPath, `${PNPM_WORKSPACE}.yaml`), path.join(pkgPath, `${PNPM_WORKSPACE}.yml`)]) {
|
|
4924
4960
|
// eslint-disable-next-line no-await-in-loop
|
|
4925
|
-
const yml = await shadowNpmInject.safeReadFile(workspacePath
|
|
4961
|
+
const yml = await shadowNpmInject.safeReadFile(workspacePath);
|
|
4926
4962
|
if (yml) {
|
|
4927
4963
|
try {
|
|
4928
4964
|
workspacePatterns = yaml.parse(yml)?.packages;
|
|
@@ -4959,7 +4995,7 @@ function workspacePatternToGlobPattern(workspace) {
|
|
|
4959
4995
|
const {
|
|
4960
4996
|
BUN: BUN$2,
|
|
4961
4997
|
LOCK_EXT,
|
|
4962
|
-
NPM: NPM$
|
|
4998
|
+
NPM: NPM$4,
|
|
4963
4999
|
PNPM: PNPM$3,
|
|
4964
5000
|
VLT: VLT$2,
|
|
4965
5001
|
YARN_BERRY: YARN_BERRY$2,
|
|
@@ -5003,11 +5039,11 @@ function includesYarn(lockSrc, name) {
|
|
|
5003
5039
|
// , name@
|
|
5004
5040
|
`(?<=(?:^\\s*|,\\s*)"?)${escapedName}(?=@)`, 'm').test(lockSrc);
|
|
5005
5041
|
}
|
|
5006
|
-
const lockfileIncludesByAgent = new Map([[BUN$2, includesBun], [NPM$
|
|
5042
|
+
const lockfileIncludesByAgent = new Map([[BUN$2, includesBun], [NPM$4, includesNpm], [PNPM$3, includesPnpm], [VLT$2, includesVlt], [YARN_BERRY$2, includesYarn], [YARN_CLASSIC$3, includesYarn]]);
|
|
5007
5043
|
|
|
5008
5044
|
const {
|
|
5009
5045
|
BUN: BUN$1,
|
|
5010
|
-
NPM: NPM$
|
|
5046
|
+
NPM: NPM$3,
|
|
5011
5047
|
PNPM: PNPM$2,
|
|
5012
5048
|
VLT: VLT$1,
|
|
5013
5049
|
YARN_BERRY: YARN_BERRY$1,
|
|
@@ -5077,7 +5113,7 @@ async function lsNpm(agentExecPath, cwd) {
|
|
|
5077
5113
|
}
|
|
5078
5114
|
async function lsPnpm(agentExecPath, cwd, options) {
|
|
5079
5115
|
const npmExecPath = options?.npmExecPath;
|
|
5080
|
-
if (npmExecPath && npmExecPath !== NPM$
|
|
5116
|
+
if (npmExecPath && npmExecPath !== NPM$3) {
|
|
5081
5117
|
const result = await npmQuery(npmExecPath, cwd);
|
|
5082
5118
|
if (result) {
|
|
5083
5119
|
return result;
|
|
@@ -5128,35 +5164,7 @@ async function lsYarnClassic(agentExecPath, cwd) {
|
|
|
5128
5164
|
} catch {}
|
|
5129
5165
|
return '';
|
|
5130
5166
|
}
|
|
5131
|
-
const lsByAgent = new Map([[BUN$1, lsBun], [NPM$
|
|
5132
|
-
|
|
5133
|
-
const {
|
|
5134
|
-
NPM: NPM$3
|
|
5135
|
-
} = constants;
|
|
5136
|
-
const COMMAND_TITLE$1 = 'Socket Optimize';
|
|
5137
|
-
async function updateLockfile(pkgEnvDetails, options) {
|
|
5138
|
-
const {
|
|
5139
|
-
logger,
|
|
5140
|
-
spinner
|
|
5141
|
-
} = {
|
|
5142
|
-
__proto__: null,
|
|
5143
|
-
...options
|
|
5144
|
-
};
|
|
5145
|
-
spinner?.start(`Updating ${pkgEnvDetails.lockName}...`);
|
|
5146
|
-
try {
|
|
5147
|
-
await runAgentInstall(pkgEnvDetails, {
|
|
5148
|
-
spinner
|
|
5149
|
-
});
|
|
5150
|
-
spinner?.stop();
|
|
5151
|
-
if (pkgEnvDetails.agent === NPM$3) {
|
|
5152
|
-
logger?.log(`💡 Re-run ${COMMAND_TITLE$1} whenever ${pkgEnvDetails.lockName} changes.\n This can be skipped once npm v11.2.0 is released.`);
|
|
5153
|
-
}
|
|
5154
|
-
} catch (e) {
|
|
5155
|
-
spinner?.stop();
|
|
5156
|
-
logger?.fail(`${COMMAND_TITLE$1}: ${pkgEnvDetails.agent} install failed to update ${pkgEnvDetails.lockName}`);
|
|
5157
|
-
logger?.error(e);
|
|
5158
|
-
}
|
|
5159
|
-
}
|
|
5167
|
+
const lsByAgent = new Map([[BUN$1, lsBun], [NPM$3, lsNpm], [PNPM$2, lsPnpm], [VLT$1, lsVlt], [YARN_BERRY$1, lsYarnBerry], [YARN_CLASSIC$2, lsYarnClassic]]);
|
|
5160
5168
|
|
|
5161
5169
|
const {
|
|
5162
5170
|
BUN,
|
|
@@ -5168,7 +5176,6 @@ const {
|
|
|
5168
5176
|
YARN_BERRY,
|
|
5169
5177
|
YARN_CLASSIC: YARN_CLASSIC$1
|
|
5170
5178
|
} = constants;
|
|
5171
|
-
const PNPM_FIELD_NAME = PNPM$1;
|
|
5172
5179
|
const depFields = ['dependencies', 'devDependencies', 'peerDependencies', 'peerDependenciesMeta', 'optionalDependencies', 'bundleDependencies'];
|
|
5173
5180
|
function getEntryIndexes(entries, keys) {
|
|
5174
5181
|
return keys.map(n => entries.findIndex(p => p[0] === n)).filter(n => n !== -1).sort((a, b) => a - b);
|
|
@@ -5179,26 +5186,30 @@ function getLowestEntryIndex(entries, keys) {
|
|
|
5179
5186
|
function getHighestEntryIndex(entries, keys) {
|
|
5180
5187
|
return getEntryIndexes(entries, keys).at(-1) ?? -1;
|
|
5181
5188
|
}
|
|
5182
|
-
function
|
|
5189
|
+
function updatePkgJsonField(editablePkgJson, field, value) {
|
|
5183
5190
|
const {
|
|
5184
5191
|
content: pkgJson
|
|
5185
5192
|
} = editablePkgJson;
|
|
5186
5193
|
const oldValue = pkgJson[field];
|
|
5187
5194
|
if (oldValue) {
|
|
5188
5195
|
// The field already exists so we simply update the field value.
|
|
5189
|
-
if (field ===
|
|
5196
|
+
if (field === PNPM$1) {
|
|
5197
|
+
const isPnpmObj = objects.isObject(oldValue);
|
|
5190
5198
|
if (objects.hasKeys(value)) {
|
|
5191
5199
|
editablePkgJson.update({
|
|
5192
5200
|
[field]: {
|
|
5193
|
-
...(
|
|
5194
|
-
overrides:
|
|
5201
|
+
...(isPnpmObj ? oldValue : {}),
|
|
5202
|
+
overrides: {
|
|
5203
|
+
...(isPnpmObj ? oldValue[OVERRIDES] : {}),
|
|
5204
|
+
...value
|
|
5205
|
+
}
|
|
5195
5206
|
}
|
|
5196
5207
|
});
|
|
5197
5208
|
} else {
|
|
5198
5209
|
// Properties with undefined values are omitted when saved as JSON.
|
|
5199
|
-
editablePkgJson.update(objects.hasKeys(
|
|
5210
|
+
editablePkgJson.update(objects.hasKeys(oldValue) ? {
|
|
5200
5211
|
[field]: {
|
|
5201
|
-
...(
|
|
5212
|
+
...(isPnpmObj ? oldValue : {}),
|
|
5202
5213
|
overrides: undefined
|
|
5203
5214
|
}
|
|
5204
5215
|
} : {
|
|
@@ -5217,7 +5228,7 @@ function updatePkgJson(editablePkgJson, field, value) {
|
|
|
5217
5228
|
}
|
|
5218
5229
|
return;
|
|
5219
5230
|
}
|
|
5220
|
-
if ((field === OVERRIDES || field ===
|
|
5231
|
+
if ((field === OVERRIDES || field === PNPM$1 || field === RESOLUTIONS) && !objects.hasKeys(value)) {
|
|
5221
5232
|
return;
|
|
5222
5233
|
}
|
|
5223
5234
|
// Since the field doesn't exist we want to insert it into the package.json
|
|
@@ -5235,7 +5246,7 @@ function updatePkgJson(editablePkgJson, field, value) {
|
|
|
5235
5246
|
} else if (field === RESOLUTIONS) {
|
|
5236
5247
|
isPlacingHigher = true;
|
|
5237
5248
|
insertIndex = getHighestEntryIndex(entries, [...depFields, OVERRIDES, PNPM$1]);
|
|
5238
|
-
} else if (field ===
|
|
5249
|
+
} else if (field === PNPM$1) {
|
|
5239
5250
|
insertIndex = getLowestEntryIndex(entries, [OVERRIDES, RESOLUTIONS]);
|
|
5240
5251
|
if (insertIndex === -1) {
|
|
5241
5252
|
isPlacingHigher = true;
|
|
@@ -5254,26 +5265,28 @@ function updatePkgJson(editablePkgJson, field, value) {
|
|
|
5254
5265
|
} else if (isPlacingHigher) {
|
|
5255
5266
|
insertIndex += 1;
|
|
5256
5267
|
}
|
|
5257
|
-
entries.splice(insertIndex, 0, [field,
|
|
5268
|
+
entries.splice(insertIndex, 0, [field, field === PNPM$1 ? {
|
|
5269
|
+
[OVERRIDES]: value
|
|
5270
|
+
} : value]);
|
|
5258
5271
|
editablePkgJson.fromJSON(`${JSON.stringify(Object.fromEntries(entries), null, 2)}\n`);
|
|
5259
5272
|
}
|
|
5260
|
-
function
|
|
5261
|
-
|
|
5273
|
+
function updateOverridesField(editablePkgJson, overrides) {
|
|
5274
|
+
updatePkgJsonField(editablePkgJson, OVERRIDES, overrides);
|
|
5262
5275
|
}
|
|
5263
|
-
function
|
|
5264
|
-
|
|
5276
|
+
function updateResolutionsField(editablePkgJson, overrides) {
|
|
5277
|
+
updatePkgJsonField(editablePkgJson, RESOLUTIONS, overrides);
|
|
5265
5278
|
}
|
|
5266
|
-
function
|
|
5267
|
-
|
|
5279
|
+
function updatePnpmField(editablePkgJson, overrides) {
|
|
5280
|
+
updatePkgJsonField(editablePkgJson, PNPM$1, overrides);
|
|
5268
5281
|
}
|
|
5269
|
-
const updateManifestByAgent = new Map([[BUN,
|
|
5282
|
+
const updateManifestByAgent = new Map([[BUN, updateResolutionsField], [NPM$2, updateOverridesField], [PNPM$1, updatePnpmField], [VLT, updateOverridesField], [YARN_BERRY, updateResolutionsField], [YARN_CLASSIC$1, updateResolutionsField]]);
|
|
5270
5283
|
|
|
5271
5284
|
const {
|
|
5272
5285
|
NPM: NPM$1,
|
|
5273
5286
|
PNPM,
|
|
5274
5287
|
YARN_CLASSIC
|
|
5275
5288
|
} = constants;
|
|
5276
|
-
const
|
|
5289
|
+
const CMD_NAME$1 = 'socket optimize';
|
|
5277
5290
|
const manifestNpmOverrides = registry.getManifestData(NPM$1);
|
|
5278
5291
|
async function addOverrides(pkgPath, pkgEnvDetails, options) {
|
|
5279
5292
|
const {
|
|
@@ -5311,24 +5324,17 @@ async function addOverrides(pkgPath, pkgEnvDetails, options) {
|
|
|
5311
5324
|
const {
|
|
5312
5325
|
content: pkgJson
|
|
5313
5326
|
} = editablePkgJson;
|
|
5314
|
-
const isRoot = pkgPath === rootPath;
|
|
5315
|
-
const isLockScanned = isRoot && !prod;
|
|
5316
5327
|
const workspaceName = path.relative(rootPath, pkgPath);
|
|
5317
5328
|
const workspaceGlobs = await getWorkspaceGlobs(agent, pkgPath, pkgJson);
|
|
5329
|
+
const isRoot = pkgPath === rootPath;
|
|
5330
|
+
const isLockScanned = isRoot && !prod;
|
|
5318
5331
|
const isWorkspace = !!workspaceGlobs;
|
|
5319
|
-
if (isWorkspace && agent === PNPM &&
|
|
5332
|
+
if (isWorkspace && agent === PNPM &&
|
|
5333
|
+
// npmExecPath will === the agent name IF it CANNOT be resolved.
|
|
5334
|
+
npmExecPath === NPM$1 && !state.warnedPnpmWorkspaceRequiresNpm) {
|
|
5320
5335
|
state.warnedPnpmWorkspaceRequiresNpm = true;
|
|
5321
|
-
logger?.warn(`${
|
|
5336
|
+
logger?.warn(cmdPrefixMessage(CMD_NAME$1, `${agent} workspace support requires \`npm ls\`, falling back to \`${agent} list\``));
|
|
5322
5337
|
}
|
|
5323
|
-
const thingToScan = isLockScanned ? lockSrc : await lsByAgent.get(agent)(agentExecPath, pkgPath, {
|
|
5324
|
-
npmExecPath
|
|
5325
|
-
});
|
|
5326
|
-
// The AgentDepsIncludesFn and AgentLockIncludesFn types overlap in their
|
|
5327
|
-
// first two parameters. AgentLockIncludesFn accepts an optional third
|
|
5328
|
-
// parameter which AgentDepsIncludesFn will ignore so we cast thingScanner
|
|
5329
|
-
// as an AgentLockIncludesFn type.
|
|
5330
|
-
const thingScanner = isLockScanned ? lockfileIncludesByAgent.get(agent) : depsIncludesByAgent.get(agent);
|
|
5331
|
-
const depEntries = getDependencyEntries(pkgJson);
|
|
5332
5338
|
const overridesDataObjects = [];
|
|
5333
5339
|
if (pkgJson['private'] || isWorkspace) {
|
|
5334
5340
|
overridesDataObjects.push(overridesDataByAgent.get(agent)(pkgJson));
|
|
@@ -5337,10 +5343,12 @@ async function addOverrides(pkgPath, pkgEnvDetails, options) {
|
|
|
5337
5343
|
}
|
|
5338
5344
|
spinner?.setText(`Adding overrides${workspaceName ? ` to ${workspaceName}` : ''}...`);
|
|
5339
5345
|
const depAliasMap = new Map();
|
|
5346
|
+
const depEntries = getDependencyEntries(pkgJson);
|
|
5340
5347
|
const nodeRange = `>=${pkgEnvDetails.minimumNodeVersion}`;
|
|
5341
5348
|
const manifestEntries = manifestNpmOverrides.filter(({
|
|
5342
5349
|
1: data
|
|
5343
5350
|
}) => semver.satisfies(semver.coerce(data.engines.node), nodeRange));
|
|
5351
|
+
|
|
5344
5352
|
// Chunk package names to process them in parallel 3 at a time.
|
|
5345
5353
|
await promises.pEach(manifestEntries, 3, async ({
|
|
5346
5354
|
1: data
|
|
@@ -5377,6 +5385,14 @@ async function addOverrides(pkgPath, pkgEnvDetails, options) {
|
|
|
5377
5385
|
}
|
|
5378
5386
|
}
|
|
5379
5387
|
if (isRoot) {
|
|
5388
|
+
// The AgentDepsIncludesFn and AgentLockIncludesFn types overlap in their
|
|
5389
|
+
// first two parameters. AgentLockIncludesFn accepts an optional third
|
|
5390
|
+
// parameter which AgentDepsIncludesFn will ignore so we cast thingScanner
|
|
5391
|
+
// as an AgentLockIncludesFn type.
|
|
5392
|
+
const thingScanner = isLockScanned ? lockfileIncludesByAgent.get(agent) : depsIncludesByAgent.get(agent);
|
|
5393
|
+
const thingToScan = isLockScanned ? lockSrc : await lsByAgent.get(agent)(agentExecPath, pkgPath, {
|
|
5394
|
+
npmExecPath
|
|
5395
|
+
});
|
|
5380
5396
|
// Chunk package names to process them in parallel 3 at a time.
|
|
5381
5397
|
await promises.pEach(overridesDataObjects, 3, async ({
|
|
5382
5398
|
overrides,
|
|
@@ -5453,11 +5469,50 @@ async function addOverrides(pkgPath, pkgEnvDetails, options) {
|
|
|
5453
5469
|
}
|
|
5454
5470
|
return state;
|
|
5455
5471
|
}
|
|
5472
|
+
|
|
5473
|
+
const {
|
|
5474
|
+
NPM_BUGGY_OVERRIDES_PATCHED_VERSION
|
|
5475
|
+
} = constants;
|
|
5476
|
+
async function updateLockfile(pkgEnvDetails, options) {
|
|
5477
|
+
const {
|
|
5478
|
+
cmdName = '',
|
|
5479
|
+
logger,
|
|
5480
|
+
spinner
|
|
5481
|
+
} = {
|
|
5482
|
+
__proto__: null,
|
|
5483
|
+
...options
|
|
5484
|
+
};
|
|
5485
|
+
const isSpinning = !!spinner?.isSpinning;
|
|
5486
|
+
if (!isSpinning) {
|
|
5487
|
+
spinner?.start();
|
|
5488
|
+
}
|
|
5489
|
+
spinner?.setText(`Updating ${pkgEnvDetails.lockName}...`);
|
|
5490
|
+
try {
|
|
5491
|
+
await runAgentInstall(pkgEnvDetails, {
|
|
5492
|
+
spinner
|
|
5493
|
+
});
|
|
5494
|
+
if (pkgEnvDetails.features.npmBuggyOverrides) {
|
|
5495
|
+
logger?.log(`💡 Re-run ${cmdName ? `${cmdName} ` : ''}whenever ${pkgEnvDetails.lockName} changes.\n This can be skipped for ${pkgEnvDetails.agent} >=${NPM_BUGGY_OVERRIDES_PATCHED_VERSION}.`);
|
|
5496
|
+
}
|
|
5497
|
+
} catch (e) {
|
|
5498
|
+
spinner?.stop();
|
|
5499
|
+
logger?.fail(cmdPrefixMessage(cmdName, `${pkgEnvDetails.agent} install failed to update ${pkgEnvDetails.lockName}`));
|
|
5500
|
+
logger?.error(e);
|
|
5501
|
+
}
|
|
5502
|
+
if (isSpinning) {
|
|
5503
|
+
spinner?.start();
|
|
5504
|
+
} else {
|
|
5505
|
+
spinner?.stop();
|
|
5506
|
+
}
|
|
5507
|
+
}
|
|
5508
|
+
|
|
5509
|
+
const CMD_NAME = 'socket optimize';
|
|
5456
5510
|
function createActionMessage(verb, overrideCount, workspaceCount) {
|
|
5457
5511
|
return `${verb} ${overrideCount} Socket.dev optimized ${words.pluralize('override', overrideCount)}${workspaceCount ? ` in ${workspaceCount} ${words.pluralize('workspace', workspaceCount)}` : ''}`;
|
|
5458
5512
|
}
|
|
5459
5513
|
async function applyOptimization(cwd, pin, prod) {
|
|
5460
5514
|
const pkgEnvDetails = await detectAndValidatePackageEnvironment(cwd, {
|
|
5515
|
+
cmdName: CMD_NAME,
|
|
5461
5516
|
logger: logger.logger,
|
|
5462
5517
|
prod
|
|
5463
5518
|
});
|
|
@@ -5475,10 +5530,17 @@ async function applyOptimization(cwd, pin, prod) {
|
|
|
5475
5530
|
prod,
|
|
5476
5531
|
spinner
|
|
5477
5532
|
});
|
|
5478
|
-
spinner.stop();
|
|
5479
5533
|
const addedCount = state.added.size;
|
|
5480
5534
|
const updatedCount = state.updated.size;
|
|
5481
5535
|
const pkgJsonChanged = addedCount > 0 || updatedCount > 0;
|
|
5536
|
+
if (pkgJsonChanged || pkgEnvDetails.features.npmBuggyOverrides) {
|
|
5537
|
+
await updateLockfile(pkgEnvDetails, {
|
|
5538
|
+
cmdName: CMD_NAME,
|
|
5539
|
+
logger: logger.logger,
|
|
5540
|
+
spinner
|
|
5541
|
+
});
|
|
5542
|
+
}
|
|
5543
|
+
spinner.stop();
|
|
5482
5544
|
if (pkgJsonChanged) {
|
|
5483
5545
|
if (updatedCount > 0) {
|
|
5484
5546
|
logger.logger?.log(`${createActionMessage('Updated', updatedCount, state.updatedInWorkspaces.size)}${addedCount ? '.' : '🚀'}`);
|
|
@@ -5489,14 +5551,6 @@ async function applyOptimization(cwd, pin, prod) {
|
|
|
5489
5551
|
} else {
|
|
5490
5552
|
logger.logger?.log('Congratulations! Already Socket.dev optimized 🎉');
|
|
5491
5553
|
}
|
|
5492
|
-
if (pkgEnvDetails.agent === NPM$1 || pkgJsonChanged) {
|
|
5493
|
-
// Always update package-lock.json until the npm overrides PR lands:
|
|
5494
|
-
// https://github.com/npm/cli/pull/8089
|
|
5495
|
-
await updateLockfile(pkgEnvDetails, {
|
|
5496
|
-
logger: logger.logger,
|
|
5497
|
-
spinner
|
|
5498
|
-
});
|
|
5499
|
-
}
|
|
5500
5554
|
}
|
|
5501
5555
|
|
|
5502
5556
|
const {
|
|
@@ -8229,15 +8283,15 @@ async function run(argv, importMeta, {
|
|
|
8229
8283
|
}
|
|
8230
8284
|
|
|
8231
8285
|
const {
|
|
8232
|
-
|
|
8233
|
-
rootPkgJsonPath
|
|
8286
|
+
SOCKET_CLI_BIN_NAME
|
|
8234
8287
|
} = constants;
|
|
8235
8288
|
|
|
8236
8289
|
// TODO: Add autocompletion using https://socket.dev/npm/package/omelette
|
|
8237
8290
|
void (async () => {
|
|
8238
8291
|
await updateNotifier({
|
|
8239
|
-
name:
|
|
8240
|
-
|
|
8292
|
+
name: SOCKET_CLI_BIN_NAME,
|
|
8293
|
+
// The '@rollup/plugin-replace' will replace "process.env['INLINED_SOCKET_CLI_VERSION']".
|
|
8294
|
+
version: "0.14.60",
|
|
8241
8295
|
ttl: 86_400_000 /* 24 hours in milliseconds */
|
|
8242
8296
|
});
|
|
8243
8297
|
try {
|
|
@@ -8273,7 +8327,7 @@ void (async () => {
|
|
|
8273
8327
|
}
|
|
8274
8328
|
},
|
|
8275
8329
|
argv: process$1.argv.slice(2),
|
|
8276
|
-
name:
|
|
8330
|
+
name: SOCKET_CLI_BIN_NAME,
|
|
8277
8331
|
importMeta: {
|
|
8278
8332
|
url: `${node_url.pathToFileURL(__filename)}`
|
|
8279
8333
|
}
|
|
@@ -8297,12 +8351,12 @@ void (async () => {
|
|
|
8297
8351
|
} else {
|
|
8298
8352
|
errorTitle = 'Unexpected error with no details';
|
|
8299
8353
|
}
|
|
8300
|
-
logger.logger.fail(`${colors.bgRed(colors.white(errorTitle
|
|
8354
|
+
logger.logger.fail(`${colors.bgRed(colors.white(`${errorTitle}:`))} ${errorMessage}`);
|
|
8301
8355
|
if (errorBody) {
|
|
8302
8356
|
logger.logger.error(`\n${errorBody}`);
|
|
8303
8357
|
}
|
|
8304
8358
|
await shadowNpmInject.captureException(e);
|
|
8305
8359
|
}
|
|
8306
8360
|
})();
|
|
8307
|
-
//# debugId=
|
|
8361
|
+
//# debugId=ff887726-fbdd-4b6c-8ffd-41246bf58990
|
|
8308
8362
|
//# sourceMappingURL=cli.js.map
|