@socketsecurity/cli-with-sentry 0.14.58 → 0.14.60

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