@socketsecurity/cli 0.14.59 → 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 +12 -13
- package/dist/constants.js +36 -41
- package/dist/constants.js.map +1 -1
- package/dist/module-sync/cli.js +196 -153
- 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 +196 -153
- 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';
|
|
@@ -2260,28 +2261,43 @@ async function run$x(argv, importMeta, {
|
|
|
2260
2261
|
const {
|
|
2261
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
2269
|
const nodejsPlatformTypes = new Set(['javascript', 'js', 'nodejs', NPM$f, PNPM$a, 'ts', 'tsx', 'typescript']);
|
|
2266
|
-
async function runCycloneDX(
|
|
2270
|
+
async function runCycloneDX(yargvWithYes) {
|
|
2267
2271
|
let cleanupPackageLock = false;
|
|
2268
|
-
|
|
2269
|
-
|
|
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}`)) {
|
|
2270
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, [
|
|
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}`]);
|
|
2276
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
|
|
|
@@ -2938,30 +2985,7 @@ 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
|
-
function cmdPrefixMessage(cmdName, text) {
|
|
2959
|
-
const cmdPrefix = cmdName ? `${cmdName}: ` : '';
|
|
2960
|
-
return `${cmdPrefix}${text}`;
|
|
2961
|
-
}
|
|
2962
|
-
|
|
2963
2988
|
const {
|
|
2964
|
-
SOCKET_CLI_SENTRY_BUILD,
|
|
2965
2989
|
SOCKET_IPC_HANDSHAKE
|
|
2966
2990
|
} = constants;
|
|
2967
2991
|
function safeNpmInstall(options) {
|
|
@@ -2978,10 +3002,10 @@ function safeNpmInstall(options) {
|
|
|
2978
3002
|
const useIpc = objects.isObject(ipc);
|
|
2979
3003
|
const useDebug = debug.isDebug();
|
|
2980
3004
|
const terminatorPos = args.indexOf('--');
|
|
2981
|
-
const
|
|
3005
|
+
const binArgs = (terminatorPos === -1 ? args : args.slice(0, terminatorPos)).filter(a => !npm.isAuditFlag(a) && !npm.isFundFlag(a) && !npm.isProgressFlag(a));
|
|
2982
3006
|
const otherArgs = terminatorPos === -1 ? [] : args.slice(terminatorPos);
|
|
2983
|
-
const isSilent = !useDebug && !
|
|
2984
|
-
const logLevelArgs = isSilent ? ['--loglevel', '
|
|
3007
|
+
const isSilent = !useDebug && !binArgs.some(npm.isLoglevelFlag);
|
|
3008
|
+
const logLevelArgs = isSilent ? ['--loglevel', 'silent'] : [];
|
|
2985
3009
|
const spawnPromise = spawn.spawn(
|
|
2986
3010
|
// Lazily access constants.execPath.
|
|
2987
3011
|
constants.execPath, [
|
|
@@ -2989,20 +3013,17 @@ function safeNpmInstall(options) {
|
|
|
2989
3013
|
...constants.nodeHardenFlags,
|
|
2990
3014
|
// Lazily access constants.nodeNoWarningsFlags.
|
|
2991
3015
|
...constants.nodeNoWarningsFlags,
|
|
2992
|
-
// Lazily access
|
|
2993
|
-
...(
|
|
2994
|
-
// Lazily access constants.distInstrumentWithSentryPath.
|
|
2995
|
-
constants.distInstrumentWithSentryPath] : []), '--require',
|
|
3016
|
+
// Lazily access false.
|
|
3017
|
+
...([]), '--require',
|
|
2996
3018
|
// Lazily access constants.distShadowNpmInjectPath.
|
|
2997
3019
|
constants.distShadowNpmInjectPath, agentExecPath, 'install',
|
|
2998
3020
|
// Avoid code paths for 'audit' and 'fund'.
|
|
2999
3021
|
'--no-audit', '--no-fund',
|
|
3000
|
-
// Add
|
|
3001
|
-
// when running the command with recent versions of npm.
|
|
3022
|
+
// Add '--no-progress' to fix input being swallowed by the npm spinner.
|
|
3002
3023
|
'--no-progress',
|
|
3003
|
-
// Add '--loglevel=
|
|
3024
|
+
// Add '--loglevel=silent' if a loglevel flag is not provided and the
|
|
3004
3025
|
// SOCKET_CLI_DEBUG environment variable is not truthy.
|
|
3005
|
-
...logLevelArgs, ...
|
|
3026
|
+
...logLevelArgs, ...binArgs, ...otherArgs], {
|
|
3006
3027
|
spinner,
|
|
3007
3028
|
// Set stdio to include 'ipc'.
|
|
3008
3029
|
// See https://github.com/nodejs/node/blob/v23.6.0/lib/child_process.js#L161-L166
|
|
@@ -3176,9 +3197,11 @@ async function pnpmFix(pkgEnvDetails, cwd, options) {
|
|
|
3176
3197
|
const {
|
|
3177
3198
|
BINARY_LOCK_EXT,
|
|
3178
3199
|
BUN: BUN$5,
|
|
3200
|
+
HIDDEN_PACKAGE_LOCK_JSON,
|
|
3179
3201
|
LOCK_EXT: LOCK_EXT$1,
|
|
3180
3202
|
NPM: NPM$b,
|
|
3181
3203
|
NPM_BUGGY_OVERRIDES_PATCHED_VERSION: NPM_BUGGY_OVERRIDES_PATCHED_VERSION$1,
|
|
3204
|
+
PACKAGE_JSON,
|
|
3182
3205
|
PNPM: PNPM$8,
|
|
3183
3206
|
VLT: VLT$5,
|
|
3184
3207
|
YARN,
|
|
@@ -3280,8 +3303,8 @@ async function detectPackageEnvironment({
|
|
|
3280
3303
|
cwd
|
|
3281
3304
|
});
|
|
3282
3305
|
let lockName = lockPath ? path.basename(lockPath) : undefined;
|
|
3283
|
-
const isHiddenLockFile = lockName ===
|
|
3284
|
-
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, {
|
|
3285
3308
|
cwd
|
|
3286
3309
|
});
|
|
3287
3310
|
const pkgPath = pkgJsonPath && fs.existsSync(pkgJsonPath) ? path.dirname(pkgJsonPath) : undefined;
|
|
@@ -3413,7 +3436,7 @@ async function detectAndValidatePackageEnvironment(cwd, options) {
|
|
|
3413
3436
|
return;
|
|
3414
3437
|
}
|
|
3415
3438
|
if (details.pkgPath === undefined) {
|
|
3416
|
-
logger?.fail(cmdPrefixMessage(cmdName,
|
|
3439
|
+
logger?.fail(cmdPrefixMessage(cmdName, `No ${PACKAGE_JSON} found`));
|
|
3417
3440
|
return;
|
|
3418
3441
|
}
|
|
3419
3442
|
if (prod && (details.agent === BUN$5 || details.agent === YARN_BERRY$5)) {
|
|
@@ -3430,7 +3453,7 @@ const {
|
|
|
3430
3453
|
NPM: NPM$a,
|
|
3431
3454
|
PNPM: PNPM$7
|
|
3432
3455
|
} = constants;
|
|
3433
|
-
const CMD_NAME$
|
|
3456
|
+
const CMD_NAME$2 = 'socket fix';
|
|
3434
3457
|
async function runFix() {
|
|
3435
3458
|
// Lazily access constants.spinner.
|
|
3436
3459
|
const {
|
|
@@ -3439,7 +3462,7 @@ async function runFix() {
|
|
|
3439
3462
|
spinner.start();
|
|
3440
3463
|
const cwd = process.cwd();
|
|
3441
3464
|
const pkgEnvDetails = await detectAndValidatePackageEnvironment(cwd, {
|
|
3442
|
-
cmdName: CMD_NAME$
|
|
3465
|
+
cmdName: CMD_NAME$2,
|
|
3443
3466
|
logger: logger.logger
|
|
3444
3467
|
});
|
|
3445
3468
|
if (!pkgEnvDetails) {
|
|
@@ -3930,9 +3953,11 @@ async function convertGradleToMaven(target, bin, _out, verbose, gradleOpts) {
|
|
|
3930
3953
|
logger.logger.groupEnd();
|
|
3931
3954
|
}
|
|
3932
3955
|
try {
|
|
3933
|
-
// Run sbt with the init script we provide which should yield zero or more
|
|
3934
|
-
// We have to figure out where to store those pom files such that
|
|
3935
|
-
//
|
|
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.
|
|
3936
3961
|
|
|
3937
3962
|
// Note: init.gradle will be exported by .config/rollup.dist.config.mjs
|
|
3938
3963
|
const initLocation = path.join(constants.rootDistPath, 'init.gradle');
|
|
@@ -3979,7 +4004,7 @@ async function convertGradleToMaven(target, bin, _out, verbose, gradleOpts) {
|
|
|
3979
4004
|
// // Move the pom file to ...? initial cwd? loc will be an absolute path, or dump to stdout
|
|
3980
4005
|
// if (out === '-') {
|
|
3981
4006
|
// spinner.start('Result:\n```')
|
|
3982
|
-
// spinner.log(await safeReadFile(loc
|
|
4007
|
+
// spinner.log(await safeReadFile(loc))
|
|
3983
4008
|
// spinner.log('```')
|
|
3984
4009
|
// spinner.successAndStop(`OK`)
|
|
3985
4010
|
// } else {
|
|
@@ -4214,7 +4239,7 @@ async function convertSbtToMaven(target, bin, out, verbose, sbtOpts) {
|
|
|
4214
4239
|
// TODO: maybe we can add an option to target a specific file to dump to stdout
|
|
4215
4240
|
if (out === '-' && poms.length === 1) {
|
|
4216
4241
|
logger.logger.log('Result:\n```');
|
|
4217
|
-
logger.logger.log(await shadowNpmInject.safeReadFile(poms[0]
|
|
4242
|
+
logger.logger.log(await shadowNpmInject.safeReadFile(poms[0]));
|
|
4218
4243
|
logger.logger.log('```');
|
|
4219
4244
|
logger.logger.success(`OK`);
|
|
4220
4245
|
} else if (out === '-') {
|
|
@@ -4933,7 +4958,7 @@ async function getWorkspaceGlobs(agent, pkgPath, pkgJson) {
|
|
|
4933
4958
|
if (agent === PNPM$4) {
|
|
4934
4959
|
for (const workspacePath of [path.join(pkgPath, `${PNPM_WORKSPACE}.yaml`), path.join(pkgPath, `${PNPM_WORKSPACE}.yml`)]) {
|
|
4935
4960
|
// eslint-disable-next-line no-await-in-loop
|
|
4936
|
-
const yml = await shadowNpmInject.safeReadFile(workspacePath
|
|
4961
|
+
const yml = await shadowNpmInject.safeReadFile(workspacePath);
|
|
4937
4962
|
if (yml) {
|
|
4938
4963
|
try {
|
|
4939
4964
|
workspacePatterns = yaml.parse(yml)?.packages;
|
|
@@ -5141,34 +5166,6 @@ async function lsYarnClassic(agentExecPath, cwd) {
|
|
|
5141
5166
|
}
|
|
5142
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]]);
|
|
5143
5168
|
|
|
5144
|
-
const {
|
|
5145
|
-
NPM_BUGGY_OVERRIDES_PATCHED_VERSION
|
|
5146
|
-
} = constants;
|
|
5147
|
-
async function updateLockfile(pkgEnvDetails, options) {
|
|
5148
|
-
const {
|
|
5149
|
-
cmdName = '',
|
|
5150
|
-
logger,
|
|
5151
|
-
spinner
|
|
5152
|
-
} = {
|
|
5153
|
-
__proto__: null,
|
|
5154
|
-
...options
|
|
5155
|
-
};
|
|
5156
|
-
spinner?.start(`Updating ${pkgEnvDetails.lockName}...`);
|
|
5157
|
-
try {
|
|
5158
|
-
await runAgentInstall(pkgEnvDetails, {
|
|
5159
|
-
spinner
|
|
5160
|
-
});
|
|
5161
|
-
spinner?.stop();
|
|
5162
|
-
if (pkgEnvDetails.features.npmBuggyOverrides) {
|
|
5163
|
-
logger?.log(`💡 Re-run ${cmdName ? `${cmdName} ` : ''}whenever ${pkgEnvDetails.lockName} changes.\n This can be skipped for ${pkgEnvDetails.agent} >=${NPM_BUGGY_OVERRIDES_PATCHED_VERSION}.`);
|
|
5164
|
-
}
|
|
5165
|
-
} catch (e) {
|
|
5166
|
-
spinner?.stop();
|
|
5167
|
-
logger?.fail(cmdPrefixMessage(cmdName, `${pkgEnvDetails.agent} install failed to update ${pkgEnvDetails.lockName}`));
|
|
5168
|
-
logger?.error(e);
|
|
5169
|
-
}
|
|
5170
|
-
}
|
|
5171
|
-
|
|
5172
5169
|
const {
|
|
5173
5170
|
BUN,
|
|
5174
5171
|
NPM: NPM$2,
|
|
@@ -5179,7 +5176,6 @@ const {
|
|
|
5179
5176
|
YARN_BERRY,
|
|
5180
5177
|
YARN_CLASSIC: YARN_CLASSIC$1
|
|
5181
5178
|
} = constants;
|
|
5182
|
-
const PNPM_FIELD_NAME = PNPM$1;
|
|
5183
5179
|
const depFields = ['dependencies', 'devDependencies', 'peerDependencies', 'peerDependenciesMeta', 'optionalDependencies', 'bundleDependencies'];
|
|
5184
5180
|
function getEntryIndexes(entries, keys) {
|
|
5185
5181
|
return keys.map(n => entries.findIndex(p => p[0] === n)).filter(n => n !== -1).sort((a, b) => a - b);
|
|
@@ -5190,26 +5186,30 @@ function getLowestEntryIndex(entries, keys) {
|
|
|
5190
5186
|
function getHighestEntryIndex(entries, keys) {
|
|
5191
5187
|
return getEntryIndexes(entries, keys).at(-1) ?? -1;
|
|
5192
5188
|
}
|
|
5193
|
-
function
|
|
5189
|
+
function updatePkgJsonField(editablePkgJson, field, value) {
|
|
5194
5190
|
const {
|
|
5195
5191
|
content: pkgJson
|
|
5196
5192
|
} = editablePkgJson;
|
|
5197
5193
|
const oldValue = pkgJson[field];
|
|
5198
5194
|
if (oldValue) {
|
|
5199
5195
|
// The field already exists so we simply update the field value.
|
|
5200
|
-
if (field ===
|
|
5196
|
+
if (field === PNPM$1) {
|
|
5197
|
+
const isPnpmObj = objects.isObject(oldValue);
|
|
5201
5198
|
if (objects.hasKeys(value)) {
|
|
5202
5199
|
editablePkgJson.update({
|
|
5203
5200
|
[field]: {
|
|
5204
|
-
...(
|
|
5205
|
-
overrides:
|
|
5201
|
+
...(isPnpmObj ? oldValue : {}),
|
|
5202
|
+
overrides: {
|
|
5203
|
+
...(isPnpmObj ? oldValue[OVERRIDES] : {}),
|
|
5204
|
+
...value
|
|
5205
|
+
}
|
|
5206
5206
|
}
|
|
5207
5207
|
});
|
|
5208
5208
|
} else {
|
|
5209
5209
|
// Properties with undefined values are omitted when saved as JSON.
|
|
5210
|
-
editablePkgJson.update(objects.hasKeys(
|
|
5210
|
+
editablePkgJson.update(objects.hasKeys(oldValue) ? {
|
|
5211
5211
|
[field]: {
|
|
5212
|
-
...(
|
|
5212
|
+
...(isPnpmObj ? oldValue : {}),
|
|
5213
5213
|
overrides: undefined
|
|
5214
5214
|
}
|
|
5215
5215
|
} : {
|
|
@@ -5228,7 +5228,7 @@ function updatePkgJson(editablePkgJson, field, value) {
|
|
|
5228
5228
|
}
|
|
5229
5229
|
return;
|
|
5230
5230
|
}
|
|
5231
|
-
if ((field === OVERRIDES || field ===
|
|
5231
|
+
if ((field === OVERRIDES || field === PNPM$1 || field === RESOLUTIONS) && !objects.hasKeys(value)) {
|
|
5232
5232
|
return;
|
|
5233
5233
|
}
|
|
5234
5234
|
// Since the field doesn't exist we want to insert it into the package.json
|
|
@@ -5246,7 +5246,7 @@ function updatePkgJson(editablePkgJson, field, value) {
|
|
|
5246
5246
|
} else if (field === RESOLUTIONS) {
|
|
5247
5247
|
isPlacingHigher = true;
|
|
5248
5248
|
insertIndex = getHighestEntryIndex(entries, [...depFields, OVERRIDES, PNPM$1]);
|
|
5249
|
-
} else if (field ===
|
|
5249
|
+
} else if (field === PNPM$1) {
|
|
5250
5250
|
insertIndex = getLowestEntryIndex(entries, [OVERRIDES, RESOLUTIONS]);
|
|
5251
5251
|
if (insertIndex === -1) {
|
|
5252
5252
|
isPlacingHigher = true;
|
|
@@ -5265,26 +5265,28 @@ function updatePkgJson(editablePkgJson, field, value) {
|
|
|
5265
5265
|
} else if (isPlacingHigher) {
|
|
5266
5266
|
insertIndex += 1;
|
|
5267
5267
|
}
|
|
5268
|
-
entries.splice(insertIndex, 0, [field,
|
|
5268
|
+
entries.splice(insertIndex, 0, [field, field === PNPM$1 ? {
|
|
5269
|
+
[OVERRIDES]: value
|
|
5270
|
+
} : value]);
|
|
5269
5271
|
editablePkgJson.fromJSON(`${JSON.stringify(Object.fromEntries(entries), null, 2)}\n`);
|
|
5270
5272
|
}
|
|
5271
|
-
function
|
|
5272
|
-
|
|
5273
|
+
function updateOverridesField(editablePkgJson, overrides) {
|
|
5274
|
+
updatePkgJsonField(editablePkgJson, OVERRIDES, overrides);
|
|
5273
5275
|
}
|
|
5274
|
-
function
|
|
5275
|
-
|
|
5276
|
+
function updateResolutionsField(editablePkgJson, overrides) {
|
|
5277
|
+
updatePkgJsonField(editablePkgJson, RESOLUTIONS, overrides);
|
|
5276
5278
|
}
|
|
5277
|
-
function
|
|
5278
|
-
|
|
5279
|
+
function updatePnpmField(editablePkgJson, overrides) {
|
|
5280
|
+
updatePkgJsonField(editablePkgJson, PNPM$1, overrides);
|
|
5279
5281
|
}
|
|
5280
|
-
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]]);
|
|
5281
5283
|
|
|
5282
5284
|
const {
|
|
5283
5285
|
NPM: NPM$1,
|
|
5284
5286
|
PNPM,
|
|
5285
5287
|
YARN_CLASSIC
|
|
5286
5288
|
} = constants;
|
|
5287
|
-
const CMD_NAME = 'socket optimize';
|
|
5289
|
+
const CMD_NAME$1 = 'socket optimize';
|
|
5288
5290
|
const manifestNpmOverrides = registry.getManifestData(NPM$1);
|
|
5289
5291
|
async function addOverrides(pkgPath, pkgEnvDetails, options) {
|
|
5290
5292
|
const {
|
|
@@ -5322,24 +5324,17 @@ async function addOverrides(pkgPath, pkgEnvDetails, options) {
|
|
|
5322
5324
|
const {
|
|
5323
5325
|
content: pkgJson
|
|
5324
5326
|
} = editablePkgJson;
|
|
5325
|
-
const isRoot = pkgPath === rootPath;
|
|
5326
|
-
const isLockScanned = isRoot && !prod;
|
|
5327
5327
|
const workspaceName = path.relative(rootPath, pkgPath);
|
|
5328
5328
|
const workspaceGlobs = await getWorkspaceGlobs(agent, pkgPath, pkgJson);
|
|
5329
|
+
const isRoot = pkgPath === rootPath;
|
|
5330
|
+
const isLockScanned = isRoot && !prod;
|
|
5329
5331
|
const isWorkspace = !!workspaceGlobs;
|
|
5330
|
-
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) {
|
|
5331
5335
|
state.warnedPnpmWorkspaceRequiresNpm = true;
|
|
5332
|
-
logger?.warn(cmdPrefixMessage(CMD_NAME,
|
|
5336
|
+
logger?.warn(cmdPrefixMessage(CMD_NAME$1, `${agent} workspace support requires \`npm ls\`, falling back to \`${agent} list\``));
|
|
5333
5337
|
}
|
|
5334
|
-
const thingToScan = isLockScanned ? lockSrc : await lsByAgent.get(agent)(agentExecPath, pkgPath, {
|
|
5335
|
-
npmExecPath
|
|
5336
|
-
});
|
|
5337
|
-
// The AgentDepsIncludesFn and AgentLockIncludesFn types overlap in their
|
|
5338
|
-
// first two parameters. AgentLockIncludesFn accepts an optional third
|
|
5339
|
-
// parameter which AgentDepsIncludesFn will ignore so we cast thingScanner
|
|
5340
|
-
// as an AgentLockIncludesFn type.
|
|
5341
|
-
const thingScanner = isLockScanned ? lockfileIncludesByAgent.get(agent) : depsIncludesByAgent.get(agent);
|
|
5342
|
-
const depEntries = getDependencyEntries(pkgJson);
|
|
5343
5338
|
const overridesDataObjects = [];
|
|
5344
5339
|
if (pkgJson['private'] || isWorkspace) {
|
|
5345
5340
|
overridesDataObjects.push(overridesDataByAgent.get(agent)(pkgJson));
|
|
@@ -5348,10 +5343,12 @@ async function addOverrides(pkgPath, pkgEnvDetails, options) {
|
|
|
5348
5343
|
}
|
|
5349
5344
|
spinner?.setText(`Adding overrides${workspaceName ? ` to ${workspaceName}` : ''}...`);
|
|
5350
5345
|
const depAliasMap = new Map();
|
|
5346
|
+
const depEntries = getDependencyEntries(pkgJson);
|
|
5351
5347
|
const nodeRange = `>=${pkgEnvDetails.minimumNodeVersion}`;
|
|
5352
5348
|
const manifestEntries = manifestNpmOverrides.filter(({
|
|
5353
5349
|
1: data
|
|
5354
5350
|
}) => semver.satisfies(semver.coerce(data.engines.node), nodeRange));
|
|
5351
|
+
|
|
5355
5352
|
// Chunk package names to process them in parallel 3 at a time.
|
|
5356
5353
|
await promises.pEach(manifestEntries, 3, async ({
|
|
5357
5354
|
1: data
|
|
@@ -5388,6 +5385,14 @@ async function addOverrides(pkgPath, pkgEnvDetails, options) {
|
|
|
5388
5385
|
}
|
|
5389
5386
|
}
|
|
5390
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
|
+
});
|
|
5391
5396
|
// Chunk package names to process them in parallel 3 at a time.
|
|
5392
5397
|
await promises.pEach(overridesDataObjects, 3, async ({
|
|
5393
5398
|
overrides,
|
|
@@ -5464,6 +5469,44 @@ async function addOverrides(pkgPath, pkgEnvDetails, options) {
|
|
|
5464
5469
|
}
|
|
5465
5470
|
return state;
|
|
5466
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';
|
|
5467
5510
|
function createActionMessage(verb, overrideCount, workspaceCount) {
|
|
5468
5511
|
return `${verb} ${overrideCount} Socket.dev optimized ${words.pluralize('override', overrideCount)}${workspaceCount ? ` in ${workspaceCount} ${words.pluralize('workspace', workspaceCount)}` : ''}`;
|
|
5469
5512
|
}
|
|
@@ -5487,10 +5530,17 @@ async function applyOptimization(cwd, pin, prod) {
|
|
|
5487
5530
|
prod,
|
|
5488
5531
|
spinner
|
|
5489
5532
|
});
|
|
5490
|
-
spinner.stop();
|
|
5491
5533
|
const addedCount = state.added.size;
|
|
5492
5534
|
const updatedCount = state.updated.size;
|
|
5493
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();
|
|
5494
5544
|
if (pkgJsonChanged) {
|
|
5495
5545
|
if (updatedCount > 0) {
|
|
5496
5546
|
logger.logger?.log(`${createActionMessage('Updated', updatedCount, state.updatedInWorkspaces.size)}${addedCount ? '.' : '🚀'}`);
|
|
@@ -5501,13 +5551,6 @@ async function applyOptimization(cwd, pin, prod) {
|
|
|
5501
5551
|
} else {
|
|
5502
5552
|
logger.logger?.log('Congratulations! Already Socket.dev optimized 🎉');
|
|
5503
5553
|
}
|
|
5504
|
-
if (pkgJsonChanged || pkgEnvDetails.features.npmBuggyOverrides) {
|
|
5505
|
-
await updateLockfile(pkgEnvDetails, {
|
|
5506
|
-
cmdName: CMD_NAME,
|
|
5507
|
-
logger: logger.logger,
|
|
5508
|
-
spinner
|
|
5509
|
-
});
|
|
5510
|
-
}
|
|
5511
5554
|
}
|
|
5512
5555
|
|
|
5513
5556
|
const {
|
|
@@ -8240,15 +8283,15 @@ async function run(argv, importMeta, {
|
|
|
8240
8283
|
}
|
|
8241
8284
|
|
|
8242
8285
|
const {
|
|
8243
|
-
SOCKET_CLI_BIN_NAME
|
|
8244
|
-
rootPkgJsonPath
|
|
8286
|
+
SOCKET_CLI_BIN_NAME
|
|
8245
8287
|
} = constants;
|
|
8246
8288
|
|
|
8247
8289
|
// TODO: Add autocompletion using https://socket.dev/npm/package/omelette
|
|
8248
8290
|
void (async () => {
|
|
8249
8291
|
await updateNotifier({
|
|
8250
8292
|
name: SOCKET_CLI_BIN_NAME,
|
|
8251
|
-
|
|
8293
|
+
// The '@rollup/plugin-replace' will replace "process.env['INLINED_SOCKET_CLI_VERSION']".
|
|
8294
|
+
version: "0.14.60",
|
|
8252
8295
|
ttl: 86_400_000 /* 24 hours in milliseconds */
|
|
8253
8296
|
});
|
|
8254
8297
|
try {
|
|
@@ -8315,5 +8358,5 @@ void (async () => {
|
|
|
8315
8358
|
await shadowNpmInject.captureException(e);
|
|
8316
8359
|
}
|
|
8317
8360
|
})();
|
|
8318
|
-
//# debugId=
|
|
8361
|
+
//# debugId=ff887726-fbdd-4b6c-8ffd-41246bf58990
|
|
8319
8362
|
//# sourceMappingURL=cli.js.map
|