@socketsecurity/cli-with-sentry 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 +29 -37
- package/dist/constants.js.map +1 -1
- package/dist/instrument-with-sentry.js +5 -5
- package/dist/instrument-with-sentry.js.map +1 -1
- package/dist/module-sync/cli.js +197 -152
- 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 +16 -11
- 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 +197 -152
- 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:c743c9e6: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,19 @@ function safeNpmInstall(options) {
|
|
|
2986
3010
|
...constants.nodeHardenFlags,
|
|
2987
3011
|
// Lazily access constants.nodeNoWarningsFlags.
|
|
2988
3012
|
...constants.nodeNoWarningsFlags,
|
|
2989
|
-
// Lazily access
|
|
2990
|
-
...(
|
|
3013
|
+
// Lazily access true.
|
|
3014
|
+
...(['--require',
|
|
2991
3015
|
// Lazily access constants.distInstrumentWithSentryPath.
|
|
2992
|
-
constants.distInstrumentWithSentryPath]
|
|
3016
|
+
constants.distInstrumentWithSentryPath] ), '--require',
|
|
2993
3017
|
// Lazily access constants.distShadowNpmInjectPath.
|
|
2994
3018
|
constants.distShadowNpmInjectPath, agentExecPath, 'install',
|
|
2995
3019
|
// Avoid code paths for 'audit' and 'fund'.
|
|
2996
3020
|
'--no-audit', '--no-fund',
|
|
2997
|
-
// Add
|
|
2998
|
-
// when running the command with recent versions of npm.
|
|
3021
|
+
// Add '--no-progress' to fix input being swallowed by the npm spinner.
|
|
2999
3022
|
'--no-progress',
|
|
3000
|
-
// Add '--loglevel=
|
|
3023
|
+
// Add '--loglevel=silent' if a loglevel flag is not provided and the
|
|
3001
3024
|
// SOCKET_CLI_DEBUG environment variable is not truthy.
|
|
3002
|
-
...logLevelArgs, ...
|
|
3025
|
+
...logLevelArgs, ...binArgs, ...otherArgs], {
|
|
3003
3026
|
spinner,
|
|
3004
3027
|
// Set stdio to include 'ipc'.
|
|
3005
3028
|
// See https://github.com/nodejs/node/blob/v23.6.0/lib/child_process.js#L161-L166
|
|
@@ -3173,9 +3196,11 @@ async function pnpmFix(pkgEnvDetails, cwd, options) {
|
|
|
3173
3196
|
const {
|
|
3174
3197
|
BINARY_LOCK_EXT,
|
|
3175
3198
|
BUN: BUN$5,
|
|
3199
|
+
HIDDEN_PACKAGE_LOCK_JSON,
|
|
3176
3200
|
LOCK_EXT: LOCK_EXT$1,
|
|
3177
3201
|
NPM: NPM$b,
|
|
3178
3202
|
NPM_BUGGY_OVERRIDES_PATCHED_VERSION: NPM_BUGGY_OVERRIDES_PATCHED_VERSION$1,
|
|
3203
|
+
PACKAGE_JSON,
|
|
3179
3204
|
PNPM: PNPM$8,
|
|
3180
3205
|
VLT: VLT$5,
|
|
3181
3206
|
YARN,
|
|
@@ -3277,8 +3302,8 @@ async function detectPackageEnvironment({
|
|
|
3277
3302
|
cwd
|
|
3278
3303
|
});
|
|
3279
3304
|
let lockName = lockPath ? path.basename(lockPath) : undefined;
|
|
3280
|
-
const isHiddenLockFile = lockName ===
|
|
3281
|
-
const pkgJsonPath = lockPath ? path.resolve(lockPath, `${isHiddenLockFile ? '../' : ''}
|
|
3305
|
+
const isHiddenLockFile = lockName === HIDDEN_PACKAGE_LOCK_JSON;
|
|
3306
|
+
const pkgJsonPath = lockPath ? path.resolve(lockPath, `${isHiddenLockFile ? '../' : ''}../${PACKAGE_JSON}`) : await shadowNpmInject.findUp(PACKAGE_JSON, {
|
|
3282
3307
|
cwd
|
|
3283
3308
|
});
|
|
3284
3309
|
const pkgPath = pkgJsonPath && fs.existsSync(pkgJsonPath) ? path.dirname(pkgJsonPath) : undefined;
|
|
@@ -3410,7 +3435,7 @@ async function detectAndValidatePackageEnvironment(cwd, options) {
|
|
|
3410
3435
|
return;
|
|
3411
3436
|
}
|
|
3412
3437
|
if (details.pkgPath === undefined) {
|
|
3413
|
-
logger?.fail(cmdPrefixMessage(cmdName,
|
|
3438
|
+
logger?.fail(cmdPrefixMessage(cmdName, `No ${PACKAGE_JSON} found`));
|
|
3414
3439
|
return;
|
|
3415
3440
|
}
|
|
3416
3441
|
if (prod && (details.agent === BUN$5 || details.agent === YARN_BERRY$5)) {
|
|
@@ -3427,7 +3452,7 @@ const {
|
|
|
3427
3452
|
NPM: NPM$a,
|
|
3428
3453
|
PNPM: PNPM$7
|
|
3429
3454
|
} = constants;
|
|
3430
|
-
const CMD_NAME$
|
|
3455
|
+
const CMD_NAME$2 = 'socket fix';
|
|
3431
3456
|
async function runFix() {
|
|
3432
3457
|
// Lazily access constants.spinner.
|
|
3433
3458
|
const {
|
|
@@ -3436,7 +3461,7 @@ async function runFix() {
|
|
|
3436
3461
|
spinner.start();
|
|
3437
3462
|
const cwd = process.cwd();
|
|
3438
3463
|
const pkgEnvDetails = await detectAndValidatePackageEnvironment(cwd, {
|
|
3439
|
-
cmdName: CMD_NAME$
|
|
3464
|
+
cmdName: CMD_NAME$2,
|
|
3440
3465
|
logger: logger.logger
|
|
3441
3466
|
});
|
|
3442
3467
|
if (!pkgEnvDetails) {
|
|
@@ -3927,9 +3952,11 @@ async function convertGradleToMaven(target, bin, _out, verbose, gradleOpts) {
|
|
|
3927
3952
|
logger.logger.groupEnd();
|
|
3928
3953
|
}
|
|
3929
3954
|
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
|
-
//
|
|
3955
|
+
// Run sbt with the init script we provide which should yield zero or more
|
|
3956
|
+
// pom files. We have to figure out where to store those pom files such that
|
|
3957
|
+
// we can upload them and predict them through the GitHub API. We could do a
|
|
3958
|
+
// .socket folder. We could do a socket.pom.gz with all the poms, although
|
|
3959
|
+
// I'd prefer something plain-text if it is to be committed.
|
|
3933
3960
|
|
|
3934
3961
|
// Note: init.gradle will be exported by .config/rollup.dist.config.mjs
|
|
3935
3962
|
const initLocation = path.join(constants.rootDistPath, 'init.gradle');
|
|
@@ -3976,7 +4003,7 @@ async function convertGradleToMaven(target, bin, _out, verbose, gradleOpts) {
|
|
|
3976
4003
|
// // Move the pom file to ...? initial cwd? loc will be an absolute path, or dump to stdout
|
|
3977
4004
|
// if (out === '-') {
|
|
3978
4005
|
// spinner.start('Result:\n```')
|
|
3979
|
-
// spinner.log(await safeReadFile(loc
|
|
4006
|
+
// spinner.log(await safeReadFile(loc))
|
|
3980
4007
|
// spinner.log('```')
|
|
3981
4008
|
// spinner.successAndStop(`OK`)
|
|
3982
4009
|
// } else {
|
|
@@ -4211,7 +4238,7 @@ async function convertSbtToMaven(target, bin, out, verbose, sbtOpts) {
|
|
|
4211
4238
|
// TODO: maybe we can add an option to target a specific file to dump to stdout
|
|
4212
4239
|
if (out === '-' && poms.length === 1) {
|
|
4213
4240
|
logger.logger.log('Result:\n```');
|
|
4214
|
-
logger.logger.log(await shadowNpmInject.safeReadFile(poms[0]
|
|
4241
|
+
logger.logger.log(await shadowNpmInject.safeReadFile(poms[0]));
|
|
4215
4242
|
logger.logger.log('```');
|
|
4216
4243
|
logger.logger.success(`OK`);
|
|
4217
4244
|
} else if (out === '-') {
|
|
@@ -4930,7 +4957,7 @@ async function getWorkspaceGlobs(agent, pkgPath, pkgJson) {
|
|
|
4930
4957
|
if (agent === PNPM$4) {
|
|
4931
4958
|
for (const workspacePath of [path.join(pkgPath, `${PNPM_WORKSPACE}.yaml`), path.join(pkgPath, `${PNPM_WORKSPACE}.yml`)]) {
|
|
4932
4959
|
// eslint-disable-next-line no-await-in-loop
|
|
4933
|
-
const yml = await shadowNpmInject.safeReadFile(workspacePath
|
|
4960
|
+
const yml = await shadowNpmInject.safeReadFile(workspacePath);
|
|
4934
4961
|
if (yml) {
|
|
4935
4962
|
try {
|
|
4936
4963
|
workspacePatterns = yaml.parse(yml)?.packages;
|
|
@@ -5138,34 +5165,6 @@ async function lsYarnClassic(agentExecPath, cwd) {
|
|
|
5138
5165
|
}
|
|
5139
5166
|
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
5167
|
|
|
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
5168
|
const {
|
|
5170
5169
|
BUN,
|
|
5171
5170
|
NPM: NPM$2,
|
|
@@ -5176,7 +5175,6 @@ const {
|
|
|
5176
5175
|
YARN_BERRY,
|
|
5177
5176
|
YARN_CLASSIC: YARN_CLASSIC$1
|
|
5178
5177
|
} = constants;
|
|
5179
|
-
const PNPM_FIELD_NAME = PNPM$1;
|
|
5180
5178
|
const depFields = ['dependencies', 'devDependencies', 'peerDependencies', 'peerDependenciesMeta', 'optionalDependencies', 'bundleDependencies'];
|
|
5181
5179
|
function getEntryIndexes(entries, keys) {
|
|
5182
5180
|
return keys.map(n => entries.findIndex(p => p[0] === n)).filter(n => n !== -1).sort((a, b) => a - b);
|
|
@@ -5187,26 +5185,30 @@ function getLowestEntryIndex(entries, keys) {
|
|
|
5187
5185
|
function getHighestEntryIndex(entries, keys) {
|
|
5188
5186
|
return getEntryIndexes(entries, keys).at(-1) ?? -1;
|
|
5189
5187
|
}
|
|
5190
|
-
function
|
|
5188
|
+
function updatePkgJsonField(editablePkgJson, field, value) {
|
|
5191
5189
|
const {
|
|
5192
5190
|
content: pkgJson
|
|
5193
5191
|
} = editablePkgJson;
|
|
5194
5192
|
const oldValue = pkgJson[field];
|
|
5195
5193
|
if (oldValue) {
|
|
5196
5194
|
// The field already exists so we simply update the field value.
|
|
5197
|
-
if (field ===
|
|
5195
|
+
if (field === PNPM$1) {
|
|
5196
|
+
const isPnpmObj = objects.isObject(oldValue);
|
|
5198
5197
|
if (objects.hasKeys(value)) {
|
|
5199
5198
|
editablePkgJson.update({
|
|
5200
5199
|
[field]: {
|
|
5201
|
-
...(
|
|
5202
|
-
overrides:
|
|
5200
|
+
...(isPnpmObj ? oldValue : {}),
|
|
5201
|
+
overrides: {
|
|
5202
|
+
...(isPnpmObj ? oldValue[OVERRIDES] : {}),
|
|
5203
|
+
...value
|
|
5204
|
+
}
|
|
5203
5205
|
}
|
|
5204
5206
|
});
|
|
5205
5207
|
} else {
|
|
5206
5208
|
// Properties with undefined values are omitted when saved as JSON.
|
|
5207
|
-
editablePkgJson.update(objects.hasKeys(
|
|
5209
|
+
editablePkgJson.update(objects.hasKeys(oldValue) ? {
|
|
5208
5210
|
[field]: {
|
|
5209
|
-
...(
|
|
5211
|
+
...(isPnpmObj ? oldValue : {}),
|
|
5210
5212
|
overrides: undefined
|
|
5211
5213
|
}
|
|
5212
5214
|
} : {
|
|
@@ -5225,7 +5227,7 @@ function updatePkgJson(editablePkgJson, field, value) {
|
|
|
5225
5227
|
}
|
|
5226
5228
|
return;
|
|
5227
5229
|
}
|
|
5228
|
-
if ((field === OVERRIDES || field ===
|
|
5230
|
+
if ((field === OVERRIDES || field === PNPM$1 || field === RESOLUTIONS) && !objects.hasKeys(value)) {
|
|
5229
5231
|
return;
|
|
5230
5232
|
}
|
|
5231
5233
|
// Since the field doesn't exist we want to insert it into the package.json
|
|
@@ -5243,7 +5245,7 @@ function updatePkgJson(editablePkgJson, field, value) {
|
|
|
5243
5245
|
} else if (field === RESOLUTIONS) {
|
|
5244
5246
|
isPlacingHigher = true;
|
|
5245
5247
|
insertIndex = getHighestEntryIndex(entries, [...depFields, OVERRIDES, PNPM$1]);
|
|
5246
|
-
} else if (field ===
|
|
5248
|
+
} else if (field === PNPM$1) {
|
|
5247
5249
|
insertIndex = getLowestEntryIndex(entries, [OVERRIDES, RESOLUTIONS]);
|
|
5248
5250
|
if (insertIndex === -1) {
|
|
5249
5251
|
isPlacingHigher = true;
|
|
@@ -5262,26 +5264,28 @@ function updatePkgJson(editablePkgJson, field, value) {
|
|
|
5262
5264
|
} else if (isPlacingHigher) {
|
|
5263
5265
|
insertIndex += 1;
|
|
5264
5266
|
}
|
|
5265
|
-
entries.splice(insertIndex, 0, [field,
|
|
5267
|
+
entries.splice(insertIndex, 0, [field, field === PNPM$1 ? {
|
|
5268
|
+
[OVERRIDES]: value
|
|
5269
|
+
} : value]);
|
|
5266
5270
|
editablePkgJson.fromJSON(`${JSON.stringify(Object.fromEntries(entries), null, 2)}\n`);
|
|
5267
5271
|
}
|
|
5268
|
-
function
|
|
5269
|
-
|
|
5272
|
+
function updateOverridesField(editablePkgJson, overrides) {
|
|
5273
|
+
updatePkgJsonField(editablePkgJson, OVERRIDES, overrides);
|
|
5270
5274
|
}
|
|
5271
|
-
function
|
|
5272
|
-
|
|
5275
|
+
function updateResolutionsField(editablePkgJson, overrides) {
|
|
5276
|
+
updatePkgJsonField(editablePkgJson, RESOLUTIONS, overrides);
|
|
5273
5277
|
}
|
|
5274
|
-
function
|
|
5275
|
-
|
|
5278
|
+
function updatePnpmField(editablePkgJson, overrides) {
|
|
5279
|
+
updatePkgJsonField(editablePkgJson, PNPM$1, overrides);
|
|
5276
5280
|
}
|
|
5277
|
-
const updateManifestByAgent = new Map([[BUN,
|
|
5281
|
+
const updateManifestByAgent = new Map([[BUN, updateResolutionsField], [NPM$2, updateOverridesField], [PNPM$1, updatePnpmField], [VLT, updateOverridesField], [YARN_BERRY, updateResolutionsField], [YARN_CLASSIC$1, updateResolutionsField]]);
|
|
5278
5282
|
|
|
5279
5283
|
const {
|
|
5280
5284
|
NPM: NPM$1,
|
|
5281
5285
|
PNPM,
|
|
5282
5286
|
YARN_CLASSIC
|
|
5283
5287
|
} = constants;
|
|
5284
|
-
const CMD_NAME = 'socket optimize';
|
|
5288
|
+
const CMD_NAME$1 = 'socket optimize';
|
|
5285
5289
|
const manifestNpmOverrides = registry.getManifestData(NPM$1);
|
|
5286
5290
|
async function addOverrides(pkgPath, pkgEnvDetails, options) {
|
|
5287
5291
|
const {
|
|
@@ -5319,24 +5323,17 @@ async function addOverrides(pkgPath, pkgEnvDetails, options) {
|
|
|
5319
5323
|
const {
|
|
5320
5324
|
content: pkgJson
|
|
5321
5325
|
} = editablePkgJson;
|
|
5322
|
-
const isRoot = pkgPath === rootPath;
|
|
5323
|
-
const isLockScanned = isRoot && !prod;
|
|
5324
5326
|
const workspaceName = path.relative(rootPath, pkgPath);
|
|
5325
5327
|
const workspaceGlobs = await getWorkspaceGlobs(agent, pkgPath, pkgJson);
|
|
5328
|
+
const isRoot = pkgPath === rootPath;
|
|
5329
|
+
const isLockScanned = isRoot && !prod;
|
|
5326
5330
|
const isWorkspace = !!workspaceGlobs;
|
|
5327
|
-
if (isWorkspace && agent === PNPM &&
|
|
5331
|
+
if (isWorkspace && agent === PNPM &&
|
|
5332
|
+
// npmExecPath will === the agent name IF it CANNOT be resolved.
|
|
5333
|
+
npmExecPath === NPM$1 && !state.warnedPnpmWorkspaceRequiresNpm) {
|
|
5328
5334
|
state.warnedPnpmWorkspaceRequiresNpm = true;
|
|
5329
|
-
logger?.warn(cmdPrefixMessage(CMD_NAME,
|
|
5335
|
+
logger?.warn(cmdPrefixMessage(CMD_NAME$1, `${agent} workspace support requires \`npm ls\`, falling back to \`${agent} list\``));
|
|
5330
5336
|
}
|
|
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
5337
|
const overridesDataObjects = [];
|
|
5341
5338
|
if (pkgJson['private'] || isWorkspace) {
|
|
5342
5339
|
overridesDataObjects.push(overridesDataByAgent.get(agent)(pkgJson));
|
|
@@ -5345,10 +5342,12 @@ async function addOverrides(pkgPath, pkgEnvDetails, options) {
|
|
|
5345
5342
|
}
|
|
5346
5343
|
spinner?.setText(`Adding overrides${workspaceName ? ` to ${workspaceName}` : ''}...`);
|
|
5347
5344
|
const depAliasMap = new Map();
|
|
5345
|
+
const depEntries = getDependencyEntries(pkgJson);
|
|
5348
5346
|
const nodeRange = `>=${pkgEnvDetails.minimumNodeVersion}`;
|
|
5349
5347
|
const manifestEntries = manifestNpmOverrides.filter(({
|
|
5350
5348
|
1: data
|
|
5351
5349
|
}) => semver.satisfies(semver.coerce(data.engines.node), nodeRange));
|
|
5350
|
+
|
|
5352
5351
|
// Chunk package names to process them in parallel 3 at a time.
|
|
5353
5352
|
await promises.pEach(manifestEntries, 3, async ({
|
|
5354
5353
|
1: data
|
|
@@ -5385,6 +5384,14 @@ async function addOverrides(pkgPath, pkgEnvDetails, options) {
|
|
|
5385
5384
|
}
|
|
5386
5385
|
}
|
|
5387
5386
|
if (isRoot) {
|
|
5387
|
+
// The AgentDepsIncludesFn and AgentLockIncludesFn types overlap in their
|
|
5388
|
+
// first two parameters. AgentLockIncludesFn accepts an optional third
|
|
5389
|
+
// parameter which AgentDepsIncludesFn will ignore so we cast thingScanner
|
|
5390
|
+
// as an AgentLockIncludesFn type.
|
|
5391
|
+
const thingScanner = isLockScanned ? lockfileIncludesByAgent.get(agent) : depsIncludesByAgent.get(agent);
|
|
5392
|
+
const thingToScan = isLockScanned ? lockSrc : await lsByAgent.get(agent)(agentExecPath, pkgPath, {
|
|
5393
|
+
npmExecPath
|
|
5394
|
+
});
|
|
5388
5395
|
// Chunk package names to process them in parallel 3 at a time.
|
|
5389
5396
|
await promises.pEach(overridesDataObjects, 3, async ({
|
|
5390
5397
|
overrides,
|
|
@@ -5461,6 +5468,44 @@ async function addOverrides(pkgPath, pkgEnvDetails, options) {
|
|
|
5461
5468
|
}
|
|
5462
5469
|
return state;
|
|
5463
5470
|
}
|
|
5471
|
+
|
|
5472
|
+
const {
|
|
5473
|
+
NPM_BUGGY_OVERRIDES_PATCHED_VERSION
|
|
5474
|
+
} = constants;
|
|
5475
|
+
async function updateLockfile(pkgEnvDetails, options) {
|
|
5476
|
+
const {
|
|
5477
|
+
cmdName = '',
|
|
5478
|
+
logger,
|
|
5479
|
+
spinner
|
|
5480
|
+
} = {
|
|
5481
|
+
__proto__: null,
|
|
5482
|
+
...options
|
|
5483
|
+
};
|
|
5484
|
+
const isSpinning = !!spinner?.isSpinning;
|
|
5485
|
+
if (!isSpinning) {
|
|
5486
|
+
spinner?.start();
|
|
5487
|
+
}
|
|
5488
|
+
spinner?.setText(`Updating ${pkgEnvDetails.lockName}...`);
|
|
5489
|
+
try {
|
|
5490
|
+
await runAgentInstall(pkgEnvDetails, {
|
|
5491
|
+
spinner
|
|
5492
|
+
});
|
|
5493
|
+
if (pkgEnvDetails.features.npmBuggyOverrides) {
|
|
5494
|
+
logger?.log(`💡 Re-run ${cmdName ? `${cmdName} ` : ''}whenever ${pkgEnvDetails.lockName} changes.\n This can be skipped for ${pkgEnvDetails.agent} >=${NPM_BUGGY_OVERRIDES_PATCHED_VERSION}.`);
|
|
5495
|
+
}
|
|
5496
|
+
} catch (e) {
|
|
5497
|
+
spinner?.stop();
|
|
5498
|
+
logger?.fail(cmdPrefixMessage(cmdName, `${pkgEnvDetails.agent} install failed to update ${pkgEnvDetails.lockName}`));
|
|
5499
|
+
logger?.error(e);
|
|
5500
|
+
}
|
|
5501
|
+
if (isSpinning) {
|
|
5502
|
+
spinner?.start();
|
|
5503
|
+
} else {
|
|
5504
|
+
spinner?.stop();
|
|
5505
|
+
}
|
|
5506
|
+
}
|
|
5507
|
+
|
|
5508
|
+
const CMD_NAME = 'socket optimize';
|
|
5464
5509
|
function createActionMessage(verb, overrideCount, workspaceCount) {
|
|
5465
5510
|
return `${verb} ${overrideCount} Socket.dev optimized ${words.pluralize('override', overrideCount)}${workspaceCount ? ` in ${workspaceCount} ${words.pluralize('workspace', workspaceCount)}` : ''}`;
|
|
5466
5511
|
}
|
|
@@ -5484,10 +5529,17 @@ async function applyOptimization(cwd, pin, prod) {
|
|
|
5484
5529
|
prod,
|
|
5485
5530
|
spinner
|
|
5486
5531
|
});
|
|
5487
|
-
spinner.stop();
|
|
5488
5532
|
const addedCount = state.added.size;
|
|
5489
5533
|
const updatedCount = state.updated.size;
|
|
5490
5534
|
const pkgJsonChanged = addedCount > 0 || updatedCount > 0;
|
|
5535
|
+
if (pkgJsonChanged || pkgEnvDetails.features.npmBuggyOverrides) {
|
|
5536
|
+
await updateLockfile(pkgEnvDetails, {
|
|
5537
|
+
cmdName: CMD_NAME,
|
|
5538
|
+
logger: logger.logger,
|
|
5539
|
+
spinner
|
|
5540
|
+
});
|
|
5541
|
+
}
|
|
5542
|
+
spinner.stop();
|
|
5491
5543
|
if (pkgJsonChanged) {
|
|
5492
5544
|
if (updatedCount > 0) {
|
|
5493
5545
|
logger.logger?.log(`${createActionMessage('Updated', updatedCount, state.updatedInWorkspaces.size)}${addedCount ? '.' : '🚀'}`);
|
|
@@ -5498,13 +5550,6 @@ async function applyOptimization(cwd, pin, prod) {
|
|
|
5498
5550
|
} else {
|
|
5499
5551
|
logger.logger?.log('Congratulations! Already Socket.dev optimized 🎉');
|
|
5500
5552
|
}
|
|
5501
|
-
if (pkgJsonChanged || pkgEnvDetails.features.npmBuggyOverrides) {
|
|
5502
|
-
await updateLockfile(pkgEnvDetails, {
|
|
5503
|
-
cmdName: CMD_NAME,
|
|
5504
|
-
logger: logger.logger,
|
|
5505
|
-
spinner
|
|
5506
|
-
});
|
|
5507
|
-
}
|
|
5508
5553
|
}
|
|
5509
5554
|
|
|
5510
5555
|
const {
|
|
@@ -8237,15 +8282,15 @@ async function run(argv, importMeta, {
|
|
|
8237
8282
|
}
|
|
8238
8283
|
|
|
8239
8284
|
const {
|
|
8240
|
-
SOCKET_CLI_BIN_NAME
|
|
8241
|
-
rootPkgJsonPath
|
|
8285
|
+
SOCKET_CLI_BIN_NAME
|
|
8242
8286
|
} = constants;
|
|
8243
8287
|
|
|
8244
8288
|
// TODO: Add autocompletion using https://socket.dev/npm/package/omelette
|
|
8245
8289
|
void (async () => {
|
|
8246
8290
|
await vendor.updater({
|
|
8247
8291
|
name: SOCKET_CLI_BIN_NAME,
|
|
8248
|
-
|
|
8292
|
+
// The '@rollup/plugin-replace' will replace "process.env['INLINED_SOCKET_CLI_VERSION']".
|
|
8293
|
+
version: "0.14.60",
|
|
8249
8294
|
ttl: 86_400_000 /* 24 hours in milliseconds */
|
|
8250
8295
|
});
|
|
8251
8296
|
try {
|
|
@@ -8312,5 +8357,5 @@ void (async () => {
|
|
|
8312
8357
|
await shadowNpmInject.captureException(e);
|
|
8313
8358
|
}
|
|
8314
8359
|
})();
|
|
8315
|
-
//# debugId=
|
|
8360
|
+
//# debugId=96a268e4-5b2f-482d-b6b4-fd911a70dc9f
|
|
8316
8361
|
//# sourceMappingURL=cli.js.map
|