@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/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';
|
|
@@ -2257,28 +2258,43 @@ async function run$x(argv, importMeta, {
|
|
|
2257
2258
|
const {
|
|
2258
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
2266
|
const nodejsPlatformTypes = new Set(['javascript', 'js', 'nodejs', NPM$f, PNPM$a, 'ts', 'tsx', 'typescript']);
|
|
2263
|
-
async function runCycloneDX(
|
|
2267
|
+
async function runCycloneDX(yargvWithYes) {
|
|
2264
2268
|
let cleanupPackageLock = false;
|
|
2265
|
-
|
|
2266
|
-
|
|
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}`)) {
|
|
2267
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, [
|
|
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}`]);
|
|
2273
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
|
|
|
@@ -2935,30 +2982,7 @@ 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
|
-
function cmdPrefixMessage(cmdName, text) {
|
|
2956
|
-
const cmdPrefix = cmdName ? `${cmdName}: ` : '';
|
|
2957
|
-
return `${cmdPrefix}${text}`;
|
|
2958
|
-
}
|
|
2959
|
-
|
|
2960
2985
|
const {
|
|
2961
|
-
SOCKET_CLI_SENTRY_BUILD,
|
|
2962
2986
|
SOCKET_IPC_HANDSHAKE
|
|
2963
2987
|
} = constants;
|
|
2964
2988
|
function safeNpmInstall(options) {
|
|
@@ -2975,10 +2999,10 @@ function safeNpmInstall(options) {
|
|
|
2975
2999
|
const useIpc = objects.isObject(ipc);
|
|
2976
3000
|
const useDebug = debug.isDebug();
|
|
2977
3001
|
const terminatorPos = args.indexOf('--');
|
|
2978
|
-
const
|
|
3002
|
+
const binArgs = (terminatorPos === -1 ? args : args.slice(0, terminatorPos)).filter(a => !npm.isAuditFlag(a) && !npm.isFundFlag(a) && !npm.isProgressFlag(a));
|
|
2979
3003
|
const otherArgs = terminatorPos === -1 ? [] : args.slice(terminatorPos);
|
|
2980
|
-
const isSilent = !useDebug && !
|
|
2981
|
-
const logLevelArgs = isSilent ? ['--loglevel', '
|
|
3004
|
+
const isSilent = !useDebug && !binArgs.some(npm.isLoglevelFlag);
|
|
3005
|
+
const logLevelArgs = isSilent ? ['--loglevel', 'silent'] : [];
|
|
2982
3006
|
const spawnPromise = spawn.spawn(
|
|
2983
3007
|
// Lazily access constants.execPath.
|
|
2984
3008
|
constants.execPath, [
|
|
@@ -2986,20 +3010,17 @@ function safeNpmInstall(options) {
|
|
|
2986
3010
|
...constants.nodeHardenFlags,
|
|
2987
3011
|
// Lazily access constants.nodeNoWarningsFlags.
|
|
2988
3012
|
...constants.nodeNoWarningsFlags,
|
|
2989
|
-
// Lazily access
|
|
2990
|
-
...(
|
|
2991
|
-
// Lazily access constants.distInstrumentWithSentryPath.
|
|
2992
|
-
constants.distInstrumentWithSentryPath] : []), '--require',
|
|
3013
|
+
// Lazily access false.
|
|
3014
|
+
...([]), '--require',
|
|
2993
3015
|
// Lazily access constants.distShadowNpmInjectPath.
|
|
2994
3016
|
constants.distShadowNpmInjectPath, agentExecPath, 'install',
|
|
2995
3017
|
// Avoid code paths for 'audit' and 'fund'.
|
|
2996
3018
|
'--no-audit', '--no-fund',
|
|
2997
|
-
// Add
|
|
2998
|
-
// when running the command with recent versions of npm.
|
|
3019
|
+
// Add '--no-progress' to fix input being swallowed by the npm spinner.
|
|
2999
3020
|
'--no-progress',
|
|
3000
|
-
// Add '--loglevel=
|
|
3021
|
+
// Add '--loglevel=silent' if a loglevel flag is not provided and the
|
|
3001
3022
|
// SOCKET_CLI_DEBUG environment variable is not truthy.
|
|
3002
|
-
...logLevelArgs, ...
|
|
3023
|
+
...logLevelArgs, ...binArgs, ...otherArgs], {
|
|
3003
3024
|
spinner,
|
|
3004
3025
|
// Set stdio to include 'ipc'.
|
|
3005
3026
|
// See https://github.com/nodejs/node/blob/v23.6.0/lib/child_process.js#L161-L166
|
|
@@ -3173,9 +3194,11 @@ async function pnpmFix(pkgEnvDetails, cwd, options) {
|
|
|
3173
3194
|
const {
|
|
3174
3195
|
BINARY_LOCK_EXT,
|
|
3175
3196
|
BUN: BUN$5,
|
|
3197
|
+
HIDDEN_PACKAGE_LOCK_JSON,
|
|
3176
3198
|
LOCK_EXT: LOCK_EXT$1,
|
|
3177
3199
|
NPM: NPM$b,
|
|
3178
3200
|
NPM_BUGGY_OVERRIDES_PATCHED_VERSION: NPM_BUGGY_OVERRIDES_PATCHED_VERSION$1,
|
|
3201
|
+
PACKAGE_JSON,
|
|
3179
3202
|
PNPM: PNPM$8,
|
|
3180
3203
|
VLT: VLT$5,
|
|
3181
3204
|
YARN,
|
|
@@ -3277,8 +3300,8 @@ async function detectPackageEnvironment({
|
|
|
3277
3300
|
cwd
|
|
3278
3301
|
});
|
|
3279
3302
|
let lockName = lockPath ? path.basename(lockPath) : undefined;
|
|
3280
|
-
const isHiddenLockFile = lockName ===
|
|
3281
|
-
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, {
|
|
3282
3305
|
cwd
|
|
3283
3306
|
});
|
|
3284
3307
|
const pkgPath = pkgJsonPath && fs.existsSync(pkgJsonPath) ? path.dirname(pkgJsonPath) : undefined;
|
|
@@ -3410,7 +3433,7 @@ async function detectAndValidatePackageEnvironment(cwd, options) {
|
|
|
3410
3433
|
return;
|
|
3411
3434
|
}
|
|
3412
3435
|
if (details.pkgPath === undefined) {
|
|
3413
|
-
logger?.fail(cmdPrefixMessage(cmdName,
|
|
3436
|
+
logger?.fail(cmdPrefixMessage(cmdName, `No ${PACKAGE_JSON} found`));
|
|
3414
3437
|
return;
|
|
3415
3438
|
}
|
|
3416
3439
|
if (prod && (details.agent === BUN$5 || details.agent === YARN_BERRY$5)) {
|
|
@@ -3427,7 +3450,7 @@ const {
|
|
|
3427
3450
|
NPM: NPM$a,
|
|
3428
3451
|
PNPM: PNPM$7
|
|
3429
3452
|
} = constants;
|
|
3430
|
-
const CMD_NAME$
|
|
3453
|
+
const CMD_NAME$2 = 'socket fix';
|
|
3431
3454
|
async function runFix() {
|
|
3432
3455
|
// Lazily access constants.spinner.
|
|
3433
3456
|
const {
|
|
@@ -3436,7 +3459,7 @@ async function runFix() {
|
|
|
3436
3459
|
spinner.start();
|
|
3437
3460
|
const cwd = process.cwd();
|
|
3438
3461
|
const pkgEnvDetails = await detectAndValidatePackageEnvironment(cwd, {
|
|
3439
|
-
cmdName: CMD_NAME$
|
|
3462
|
+
cmdName: CMD_NAME$2,
|
|
3440
3463
|
logger: logger.logger
|
|
3441
3464
|
});
|
|
3442
3465
|
if (!pkgEnvDetails) {
|
|
@@ -3927,9 +3950,11 @@ async function convertGradleToMaven(target, bin, _out, verbose, gradleOpts) {
|
|
|
3927
3950
|
logger.logger.groupEnd();
|
|
3928
3951
|
}
|
|
3929
3952
|
try {
|
|
3930
|
-
// Run sbt with the init script we provide which should yield zero or more
|
|
3931
|
-
// We have to figure out where to store those pom files such that
|
|
3932
|
-
//
|
|
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.
|
|
3933
3958
|
|
|
3934
3959
|
// Note: init.gradle will be exported by .config/rollup.dist.config.mjs
|
|
3935
3960
|
const initLocation = path.join(constants.rootDistPath, 'init.gradle');
|
|
@@ -3976,7 +4001,7 @@ async function convertGradleToMaven(target, bin, _out, verbose, gradleOpts) {
|
|
|
3976
4001
|
// // Move the pom file to ...? initial cwd? loc will be an absolute path, or dump to stdout
|
|
3977
4002
|
// if (out === '-') {
|
|
3978
4003
|
// spinner.start('Result:\n```')
|
|
3979
|
-
// spinner.log(await safeReadFile(loc
|
|
4004
|
+
// spinner.log(await safeReadFile(loc))
|
|
3980
4005
|
// spinner.log('```')
|
|
3981
4006
|
// spinner.successAndStop(`OK`)
|
|
3982
4007
|
// } else {
|
|
@@ -4211,7 +4236,7 @@ async function convertSbtToMaven(target, bin, out, verbose, sbtOpts) {
|
|
|
4211
4236
|
// TODO: maybe we can add an option to target a specific file to dump to stdout
|
|
4212
4237
|
if (out === '-' && poms.length === 1) {
|
|
4213
4238
|
logger.logger.log('Result:\n```');
|
|
4214
|
-
logger.logger.log(await shadowNpmInject.safeReadFile(poms[0]
|
|
4239
|
+
logger.logger.log(await shadowNpmInject.safeReadFile(poms[0]));
|
|
4215
4240
|
logger.logger.log('```');
|
|
4216
4241
|
logger.logger.success(`OK`);
|
|
4217
4242
|
} else if (out === '-') {
|
|
@@ -4930,7 +4955,7 @@ async function getWorkspaceGlobs(agent, pkgPath, pkgJson) {
|
|
|
4930
4955
|
if (agent === PNPM$4) {
|
|
4931
4956
|
for (const workspacePath of [path.join(pkgPath, `${PNPM_WORKSPACE}.yaml`), path.join(pkgPath, `${PNPM_WORKSPACE}.yml`)]) {
|
|
4932
4957
|
// eslint-disable-next-line no-await-in-loop
|
|
4933
|
-
const yml = await shadowNpmInject.safeReadFile(workspacePath
|
|
4958
|
+
const yml = await shadowNpmInject.safeReadFile(workspacePath);
|
|
4934
4959
|
if (yml) {
|
|
4935
4960
|
try {
|
|
4936
4961
|
workspacePatterns = yaml.parse(yml)?.packages;
|
|
@@ -5138,34 +5163,6 @@ async function lsYarnClassic(agentExecPath, cwd) {
|
|
|
5138
5163
|
}
|
|
5139
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]]);
|
|
5140
5165
|
|
|
5141
|
-
const {
|
|
5142
|
-
NPM_BUGGY_OVERRIDES_PATCHED_VERSION
|
|
5143
|
-
} = constants;
|
|
5144
|
-
async function updateLockfile(pkgEnvDetails, options) {
|
|
5145
|
-
const {
|
|
5146
|
-
cmdName = '',
|
|
5147
|
-
logger,
|
|
5148
|
-
spinner
|
|
5149
|
-
} = {
|
|
5150
|
-
__proto__: null,
|
|
5151
|
-
...options
|
|
5152
|
-
};
|
|
5153
|
-
spinner?.start(`Updating ${pkgEnvDetails.lockName}...`);
|
|
5154
|
-
try {
|
|
5155
|
-
await runAgentInstall(pkgEnvDetails, {
|
|
5156
|
-
spinner
|
|
5157
|
-
});
|
|
5158
|
-
spinner?.stop();
|
|
5159
|
-
if (pkgEnvDetails.features.npmBuggyOverrides) {
|
|
5160
|
-
logger?.log(`💡 Re-run ${cmdName ? `${cmdName} ` : ''}whenever ${pkgEnvDetails.lockName} changes.\n This can be skipped for ${pkgEnvDetails.agent} >=${NPM_BUGGY_OVERRIDES_PATCHED_VERSION}.`);
|
|
5161
|
-
}
|
|
5162
|
-
} catch (e) {
|
|
5163
|
-
spinner?.stop();
|
|
5164
|
-
logger?.fail(cmdPrefixMessage(cmdName, `${pkgEnvDetails.agent} install failed to update ${pkgEnvDetails.lockName}`));
|
|
5165
|
-
logger?.error(e);
|
|
5166
|
-
}
|
|
5167
|
-
}
|
|
5168
|
-
|
|
5169
5166
|
const {
|
|
5170
5167
|
BUN,
|
|
5171
5168
|
NPM: NPM$2,
|
|
@@ -5176,7 +5173,6 @@ const {
|
|
|
5176
5173
|
YARN_BERRY,
|
|
5177
5174
|
YARN_CLASSIC: YARN_CLASSIC$1
|
|
5178
5175
|
} = constants;
|
|
5179
|
-
const PNPM_FIELD_NAME = PNPM$1;
|
|
5180
5176
|
const depFields = ['dependencies', 'devDependencies', 'peerDependencies', 'peerDependenciesMeta', 'optionalDependencies', 'bundleDependencies'];
|
|
5181
5177
|
function getEntryIndexes(entries, keys) {
|
|
5182
5178
|
return keys.map(n => entries.findIndex(p => p[0] === n)).filter(n => n !== -1).sort((a, b) => a - b);
|
|
@@ -5187,26 +5183,30 @@ function getLowestEntryIndex(entries, keys) {
|
|
|
5187
5183
|
function getHighestEntryIndex(entries, keys) {
|
|
5188
5184
|
return getEntryIndexes(entries, keys).at(-1) ?? -1;
|
|
5189
5185
|
}
|
|
5190
|
-
function
|
|
5186
|
+
function updatePkgJsonField(editablePkgJson, field, value) {
|
|
5191
5187
|
const {
|
|
5192
5188
|
content: pkgJson
|
|
5193
5189
|
} = editablePkgJson;
|
|
5194
5190
|
const oldValue = pkgJson[field];
|
|
5195
5191
|
if (oldValue) {
|
|
5196
5192
|
// The field already exists so we simply update the field value.
|
|
5197
|
-
if (field ===
|
|
5193
|
+
if (field === PNPM$1) {
|
|
5194
|
+
const isPnpmObj = objects.isObject(oldValue);
|
|
5198
5195
|
if (objects.hasKeys(value)) {
|
|
5199
5196
|
editablePkgJson.update({
|
|
5200
5197
|
[field]: {
|
|
5201
|
-
...(
|
|
5202
|
-
overrides:
|
|
5198
|
+
...(isPnpmObj ? oldValue : {}),
|
|
5199
|
+
overrides: {
|
|
5200
|
+
...(isPnpmObj ? oldValue[OVERRIDES] : {}),
|
|
5201
|
+
...value
|
|
5202
|
+
}
|
|
5203
5203
|
}
|
|
5204
5204
|
});
|
|
5205
5205
|
} else {
|
|
5206
5206
|
// Properties with undefined values are omitted when saved as JSON.
|
|
5207
|
-
editablePkgJson.update(objects.hasKeys(
|
|
5207
|
+
editablePkgJson.update(objects.hasKeys(oldValue) ? {
|
|
5208
5208
|
[field]: {
|
|
5209
|
-
...(
|
|
5209
|
+
...(isPnpmObj ? oldValue : {}),
|
|
5210
5210
|
overrides: undefined
|
|
5211
5211
|
}
|
|
5212
5212
|
} : {
|
|
@@ -5225,7 +5225,7 @@ function updatePkgJson(editablePkgJson, field, value) {
|
|
|
5225
5225
|
}
|
|
5226
5226
|
return;
|
|
5227
5227
|
}
|
|
5228
|
-
if ((field === OVERRIDES || field ===
|
|
5228
|
+
if ((field === OVERRIDES || field === PNPM$1 || field === RESOLUTIONS) && !objects.hasKeys(value)) {
|
|
5229
5229
|
return;
|
|
5230
5230
|
}
|
|
5231
5231
|
// Since the field doesn't exist we want to insert it into the package.json
|
|
@@ -5243,7 +5243,7 @@ function updatePkgJson(editablePkgJson, field, value) {
|
|
|
5243
5243
|
} else if (field === RESOLUTIONS) {
|
|
5244
5244
|
isPlacingHigher = true;
|
|
5245
5245
|
insertIndex = getHighestEntryIndex(entries, [...depFields, OVERRIDES, PNPM$1]);
|
|
5246
|
-
} else if (field ===
|
|
5246
|
+
} else if (field === PNPM$1) {
|
|
5247
5247
|
insertIndex = getLowestEntryIndex(entries, [OVERRIDES, RESOLUTIONS]);
|
|
5248
5248
|
if (insertIndex === -1) {
|
|
5249
5249
|
isPlacingHigher = true;
|
|
@@ -5262,26 +5262,28 @@ function updatePkgJson(editablePkgJson, field, value) {
|
|
|
5262
5262
|
} else if (isPlacingHigher) {
|
|
5263
5263
|
insertIndex += 1;
|
|
5264
5264
|
}
|
|
5265
|
-
entries.splice(insertIndex, 0, [field,
|
|
5265
|
+
entries.splice(insertIndex, 0, [field, field === PNPM$1 ? {
|
|
5266
|
+
[OVERRIDES]: value
|
|
5267
|
+
} : value]);
|
|
5266
5268
|
editablePkgJson.fromJSON(`${JSON.stringify(Object.fromEntries(entries), null, 2)}\n`);
|
|
5267
5269
|
}
|
|
5268
|
-
function
|
|
5269
|
-
|
|
5270
|
+
function updateOverridesField(editablePkgJson, overrides) {
|
|
5271
|
+
updatePkgJsonField(editablePkgJson, OVERRIDES, overrides);
|
|
5270
5272
|
}
|
|
5271
|
-
function
|
|
5272
|
-
|
|
5273
|
+
function updateResolutionsField(editablePkgJson, overrides) {
|
|
5274
|
+
updatePkgJsonField(editablePkgJson, RESOLUTIONS, overrides);
|
|
5273
5275
|
}
|
|
5274
|
-
function
|
|
5275
|
-
|
|
5276
|
+
function updatePnpmField(editablePkgJson, overrides) {
|
|
5277
|
+
updatePkgJsonField(editablePkgJson, PNPM$1, overrides);
|
|
5276
5278
|
}
|
|
5277
|
-
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]]);
|
|
5278
5280
|
|
|
5279
5281
|
const {
|
|
5280
5282
|
NPM: NPM$1,
|
|
5281
5283
|
PNPM,
|
|
5282
5284
|
YARN_CLASSIC
|
|
5283
5285
|
} = constants;
|
|
5284
|
-
const CMD_NAME = 'socket optimize';
|
|
5286
|
+
const CMD_NAME$1 = 'socket optimize';
|
|
5285
5287
|
const manifestNpmOverrides = registry.getManifestData(NPM$1);
|
|
5286
5288
|
async function addOverrides(pkgPath, pkgEnvDetails, options) {
|
|
5287
5289
|
const {
|
|
@@ -5319,24 +5321,17 @@ async function addOverrides(pkgPath, pkgEnvDetails, options) {
|
|
|
5319
5321
|
const {
|
|
5320
5322
|
content: pkgJson
|
|
5321
5323
|
} = editablePkgJson;
|
|
5322
|
-
const isRoot = pkgPath === rootPath;
|
|
5323
|
-
const isLockScanned = isRoot && !prod;
|
|
5324
5324
|
const workspaceName = path.relative(rootPath, pkgPath);
|
|
5325
5325
|
const workspaceGlobs = await getWorkspaceGlobs(agent, pkgPath, pkgJson);
|
|
5326
|
+
const isRoot = pkgPath === rootPath;
|
|
5327
|
+
const isLockScanned = isRoot && !prod;
|
|
5326
5328
|
const isWorkspace = !!workspaceGlobs;
|
|
5327
|
-
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) {
|
|
5328
5332
|
state.warnedPnpmWorkspaceRequiresNpm = true;
|
|
5329
|
-
logger?.warn(cmdPrefixMessage(CMD_NAME,
|
|
5333
|
+
logger?.warn(cmdPrefixMessage(CMD_NAME$1, `${agent} workspace support requires \`npm ls\`, falling back to \`${agent} list\``));
|
|
5330
5334
|
}
|
|
5331
|
-
const thingToScan = isLockScanned ? lockSrc : await lsByAgent.get(agent)(agentExecPath, pkgPath, {
|
|
5332
|
-
npmExecPath
|
|
5333
|
-
});
|
|
5334
|
-
// The AgentDepsIncludesFn and AgentLockIncludesFn types overlap in their
|
|
5335
|
-
// first two parameters. AgentLockIncludesFn accepts an optional third
|
|
5336
|
-
// parameter which AgentDepsIncludesFn will ignore so we cast thingScanner
|
|
5337
|
-
// as an AgentLockIncludesFn type.
|
|
5338
|
-
const thingScanner = isLockScanned ? lockfileIncludesByAgent.get(agent) : depsIncludesByAgent.get(agent);
|
|
5339
|
-
const depEntries = getDependencyEntries(pkgJson);
|
|
5340
5335
|
const overridesDataObjects = [];
|
|
5341
5336
|
if (pkgJson['private'] || isWorkspace) {
|
|
5342
5337
|
overridesDataObjects.push(overridesDataByAgent.get(agent)(pkgJson));
|
|
@@ -5345,10 +5340,12 @@ async function addOverrides(pkgPath, pkgEnvDetails, options) {
|
|
|
5345
5340
|
}
|
|
5346
5341
|
spinner?.setText(`Adding overrides${workspaceName ? ` to ${workspaceName}` : ''}...`);
|
|
5347
5342
|
const depAliasMap = new Map();
|
|
5343
|
+
const depEntries = getDependencyEntries(pkgJson);
|
|
5348
5344
|
const nodeRange = `>=${pkgEnvDetails.minimumNodeVersion}`;
|
|
5349
5345
|
const manifestEntries = manifestNpmOverrides.filter(({
|
|
5350
5346
|
1: data
|
|
5351
5347
|
}) => semver.satisfies(semver.coerce(data.engines.node), nodeRange));
|
|
5348
|
+
|
|
5352
5349
|
// Chunk package names to process them in parallel 3 at a time.
|
|
5353
5350
|
await promises.pEach(manifestEntries, 3, async ({
|
|
5354
5351
|
1: data
|
|
@@ -5385,6 +5382,14 @@ async function addOverrides(pkgPath, pkgEnvDetails, options) {
|
|
|
5385
5382
|
}
|
|
5386
5383
|
}
|
|
5387
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
|
+
});
|
|
5388
5393
|
// Chunk package names to process them in parallel 3 at a time.
|
|
5389
5394
|
await promises.pEach(overridesDataObjects, 3, async ({
|
|
5390
5395
|
overrides,
|
|
@@ -5461,6 +5466,44 @@ async function addOverrides(pkgPath, pkgEnvDetails, options) {
|
|
|
5461
5466
|
}
|
|
5462
5467
|
return state;
|
|
5463
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';
|
|
5464
5507
|
function createActionMessage(verb, overrideCount, workspaceCount) {
|
|
5465
5508
|
return `${verb} ${overrideCount} Socket.dev optimized ${words.pluralize('override', overrideCount)}${workspaceCount ? ` in ${workspaceCount} ${words.pluralize('workspace', workspaceCount)}` : ''}`;
|
|
5466
5509
|
}
|
|
@@ -5484,10 +5527,17 @@ async function applyOptimization(cwd, pin, prod) {
|
|
|
5484
5527
|
prod,
|
|
5485
5528
|
spinner
|
|
5486
5529
|
});
|
|
5487
|
-
spinner.stop();
|
|
5488
5530
|
const addedCount = state.added.size;
|
|
5489
5531
|
const updatedCount = state.updated.size;
|
|
5490
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();
|
|
5491
5541
|
if (pkgJsonChanged) {
|
|
5492
5542
|
if (updatedCount > 0) {
|
|
5493
5543
|
logger.logger?.log(`${createActionMessage('Updated', updatedCount, state.updatedInWorkspaces.size)}${addedCount ? '.' : '🚀'}`);
|
|
@@ -5498,13 +5548,6 @@ async function applyOptimization(cwd, pin, prod) {
|
|
|
5498
5548
|
} else {
|
|
5499
5549
|
logger.logger?.log('Congratulations! Already Socket.dev optimized 🎉');
|
|
5500
5550
|
}
|
|
5501
|
-
if (pkgJsonChanged || pkgEnvDetails.features.npmBuggyOverrides) {
|
|
5502
|
-
await updateLockfile(pkgEnvDetails, {
|
|
5503
|
-
cmdName: CMD_NAME,
|
|
5504
|
-
logger: logger.logger,
|
|
5505
|
-
spinner
|
|
5506
|
-
});
|
|
5507
|
-
}
|
|
5508
5551
|
}
|
|
5509
5552
|
|
|
5510
5553
|
const {
|
|
@@ -8237,15 +8280,15 @@ async function run(argv, importMeta, {
|
|
|
8237
8280
|
}
|
|
8238
8281
|
|
|
8239
8282
|
const {
|
|
8240
|
-
SOCKET_CLI_BIN_NAME
|
|
8241
|
-
rootPkgJsonPath
|
|
8283
|
+
SOCKET_CLI_BIN_NAME
|
|
8242
8284
|
} = constants;
|
|
8243
8285
|
|
|
8244
8286
|
// TODO: Add autocompletion using https://socket.dev/npm/package/omelette
|
|
8245
8287
|
void (async () => {
|
|
8246
8288
|
await vendor.updater({
|
|
8247
8289
|
name: SOCKET_CLI_BIN_NAME,
|
|
8248
|
-
|
|
8290
|
+
// The '@rollup/plugin-replace' will replace "process.env['INLINED_SOCKET_CLI_VERSION']".
|
|
8291
|
+
version: "0.14.60",
|
|
8249
8292
|
ttl: 86_400_000 /* 24 hours in milliseconds */
|
|
8250
8293
|
});
|
|
8251
8294
|
try {
|
|
@@ -8312,5 +8355,5 @@ void (async () => {
|
|
|
8312
8355
|
await shadowNpmInject.captureException(e);
|
|
8313
8356
|
}
|
|
8314
8357
|
})();
|
|
8315
|
-
//# debugId=
|
|
8358
|
+
//# debugId=a4fe81ae-a54c-4a9c-bd36-803984c36419
|
|
8316
8359
|
//# sourceMappingURL=cli.js.map
|