@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.
@@ -900,19 +900,20 @@ class GitHub {
900
900
  case 'push':
901
901
  return this.prNumber ? 'diff' : 'main';
902
902
  case 'pull_request':
903
- // This env variable needs to be set in the GitHub action.
904
- // Add this code below to GitHub action:
905
- // - steps:
906
- // - name: Get PR State
907
- // if: github.event_name == 'pull_request'
908
- // run: echo "EVENT_ACTION=${{ github.event.action }}" >> $GITHUB_ENV
909
- const eventAction = process.env['EVENT_ACTION'];
910
- if (!eventAction) {
911
- throw new Error('Missing event action');
912
- }
913
- if (['opened', 'synchronize'].includes(eventAction)) {
914
- return 'diff';
915
- } else {
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 emiting the banner over stderr
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['SOCKET_CLI_VERSION_HASH']".
1525
- "0.14.58:f270068:05655527:pub";
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';
@@ -2255,30 +2256,45 @@ async function run$x(argv, importMeta, {
2255
2256
  }
2256
2257
 
2257
2258
  const {
2258
- NPM: NPM$g,
2259
+ NPM: NPM$f,
2259
2260
  NPX: NPX$3,
2260
- PNPM: PNPM$a
2261
+ PACKAGE_LOCK_JSON,
2262
+ PNPM: PNPM$a,
2263
+ YARN: YARN$1,
2264
+ YARN_LOCK
2261
2265
  } = constants;
2262
- const nodejsPlatformTypes = new Set(['javascript', 'js', 'nodejs', NPM$g, PNPM$a, 'ts', 'tsx', 'typescript']);
2263
- async function runCycloneDX(yargv) {
2266
+ const nodejsPlatformTypes = new Set(['javascript', 'js', 'nodejs', NPM$f, PNPM$a, 'ts', 'tsx', 'typescript']);
2267
+ async function runCycloneDX(yargvWithYes) {
2264
2268
  let cleanupPackageLock = false;
2265
- if (yargv.type !== 'yarn' && nodejsPlatformTypes.has(yargv.type) && fs.existsSync('./yarn.lock')) {
2266
- if (fs.existsSync('./package-lock.json')) {
2267
- yargv.type = NPM$g;
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}`)) {
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, ['synp@1.9.14', '--', '--source-file', './yarn.lock'], 2);
2273
- yargv.type = NPM$g;
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}`]);
2287
+ yargv.type = NPM$f;
2274
2288
  cleanupPackageLock = true;
2275
2289
  } catch {}
2276
2290
  }
2277
2291
  }
2278
- await shadowBin(NPX$3, ['@cyclonedx/cdxgen@11.2.0', '--', ...argvToArray(yargv)], 2);
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('./package-lock.json');
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']) return ['--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 === '--') continue;
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
- argv: argv.filter(s => s !== '--help' && s !== '-h'),
2416
- // Don't let meow take over --help
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: convert to meow
2482
+ // TODO: Convert to meow.
2435
2483
  const yargv = {
2436
2484
  ...yargsParse(argv, yargsConfig)
2437
- }; // as Record<string, unknown>;
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
 
@@ -2791,7 +2838,7 @@ const cmdDiffScan = {
2791
2838
  };
2792
2839
 
2793
2840
  const {
2794
- NPM: NPM$f
2841
+ NPM: NPM$e
2795
2842
  } = constants;
2796
2843
  function isTopLevel(tree, node) {
2797
2844
  return tree.children.get(node.name) === node;
@@ -2835,7 +2882,7 @@ async function npmFix(_pkgEnvDetails, cwd, options) {
2835
2882
  // eslint-disable-next-line no-await-in-loop
2836
2883
  await arb.buildIdealTree();
2837
2884
  const tree = arb.idealTree;
2838
- const hasUpgrade = !!registry.getManifestData(NPM$f, name);
2885
+ const hasUpgrade = !!registry.getManifestData(NPM$e, name);
2839
2886
  if (hasUpgrade) {
2840
2887
  spinner?.info(`Skipping ${name}. Socket Optimize package exists.`);
2841
2888
  continue;
@@ -2935,24 +2982,6 @@ 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
-
2956
2985
  const {
2957
2986
  SOCKET_IPC_HANDSHAKE
2958
2987
  } = constants;
@@ -2970,27 +2999,30 @@ function safeNpmInstall(options) {
2970
2999
  const useIpc = objects.isObject(ipc);
2971
3000
  const useDebug = debug.isDebug();
2972
3001
  const terminatorPos = args.indexOf('--');
2973
- const npmArgs = (terminatorPos === -1 ? args : args.slice(0, terminatorPos)).filter(a => !npm.isAuditFlag(a) && !npm.isFundFlag(a) && !npm.isProgressFlag(a));
3002
+ const binArgs = (terminatorPos === -1 ? args : args.slice(0, terminatorPos)).filter(a => !npm.isAuditFlag(a) && !npm.isFundFlag(a) && !npm.isProgressFlag(a));
2974
3003
  const otherArgs = terminatorPos === -1 ? [] : args.slice(terminatorPos);
2975
- const isSilent = !useDebug && !npmArgs.some(npm.isLoglevelFlag);
2976
- const logLevelArgs = isSilent ? ['--loglevel', 'error'] : [];
3004
+ const isSilent = !useDebug && !binArgs.some(npm.isLoglevelFlag);
3005
+ const logLevelArgs = isSilent ? ['--loglevel', 'silent'] : [];
2977
3006
  const spawnPromise = spawn.spawn(
2978
3007
  // Lazily access constants.execPath.
2979
3008
  constants.execPath, [
2980
3009
  // Lazily access constants.nodeHardenFlags.
2981
3010
  ...constants.nodeHardenFlags,
2982
3011
  // Lazily access constants.nodeNoWarningsFlags.
2983
- ...constants.nodeNoWarningsFlags, '--require',
3012
+ ...constants.nodeNoWarningsFlags,
3013
+ // Lazily access true.
3014
+ ...(['--require',
3015
+ // Lazily access constants.distInstrumentWithSentryPath.
3016
+ constants.distInstrumentWithSentryPath] ), '--require',
2984
3017
  // Lazily access constants.distShadowNpmInjectPath.
2985
3018
  constants.distShadowNpmInjectPath, agentExecPath, 'install',
2986
3019
  // Avoid code paths for 'audit' and 'fund'.
2987
3020
  '--no-audit', '--no-fund',
2988
- // Add `--no-progress` flag to fix input being swallowed by the spinner
2989
- // when running the command with recent versions of npm.
3021
+ // Add '--no-progress' to fix input being swallowed by the npm spinner.
2990
3022
  '--no-progress',
2991
- // Add '--loglevel=error' if a loglevel flag is not provided and the
3023
+ // Add '--loglevel=silent' if a loglevel flag is not provided and the
2992
3024
  // SOCKET_CLI_DEBUG environment variable is not truthy.
2993
- ...logLevelArgs, ...npmArgs, ...otherArgs], {
3025
+ ...logLevelArgs, ...binArgs, ...otherArgs], {
2994
3026
  spinner,
2995
3027
  // Set stdio to include 'ipc'.
2996
3028
  // See https://github.com/nodejs/node/blob/v23.6.0/lib/child_process.js#L161-L166
@@ -3011,7 +3043,7 @@ function safeNpmInstall(options) {
3011
3043
  }
3012
3044
 
3013
3045
  const {
3014
- NPM: NPM$e
3046
+ NPM: NPM$d
3015
3047
  } = constants;
3016
3048
  function runAgentInstall(pkgEnvDetails, options) {
3017
3049
  const {
@@ -3019,7 +3051,7 @@ function runAgentInstall(pkgEnvDetails, options) {
3019
3051
  agentExecPath
3020
3052
  } = pkgEnvDetails;
3021
3053
  // All package managers support the "install" command.
3022
- if (agent === NPM$e) {
3054
+ if (agent === NPM$d) {
3023
3055
  return safeNpmInstall({
3024
3056
  agentExecPath,
3025
3057
  ...options
@@ -3050,7 +3082,7 @@ function runAgentInstall(pkgEnvDetails, options) {
3050
3082
  }
3051
3083
 
3052
3084
  const {
3053
- NPM: NPM$d,
3085
+ NPM: NPM$c,
3054
3086
  OVERRIDES: OVERRIDES$2,
3055
3087
  PNPM: PNPM$9
3056
3088
  } = constants;
@@ -3098,7 +3130,7 @@ async function pnpmFix(pkgEnvDetails, cwd, options) {
3098
3130
  1: infos
3099
3131
  } of infoByPkg) {
3100
3132
  const tree = arb.actualTree;
3101
- const hasUpgrade = !!registry.getManifestData(NPM$d, name);
3133
+ const hasUpgrade = !!registry.getManifestData(NPM$c, name);
3102
3134
  if (hasUpgrade) {
3103
3135
  spinner?.info(`Skipping ${name}. Socket Optimize package exists.`);
3104
3136
  continue;
@@ -3163,24 +3195,27 @@ async function pnpmFix(pkgEnvDetails, cwd, options) {
3163
3195
 
3164
3196
  const {
3165
3197
  BINARY_LOCK_EXT,
3166
- BUN: BUN$6,
3198
+ BUN: BUN$5,
3199
+ HIDDEN_PACKAGE_LOCK_JSON,
3167
3200
  LOCK_EXT: LOCK_EXT$1,
3168
- NPM: NPM$c,
3201
+ NPM: NPM$b,
3202
+ NPM_BUGGY_OVERRIDES_PATCHED_VERSION: NPM_BUGGY_OVERRIDES_PATCHED_VERSION$1,
3203
+ PACKAGE_JSON,
3169
3204
  PNPM: PNPM$8,
3170
- VLT: VLT$6,
3205
+ VLT: VLT$5,
3171
3206
  YARN,
3172
- YARN_BERRY: YARN_BERRY$6,
3207
+ YARN_BERRY: YARN_BERRY$5,
3173
3208
  YARN_CLASSIC: YARN_CLASSIC$6
3174
3209
  } = constants;
3175
- const AGENTS = [BUN$6, NPM$c, PNPM$8, YARN_BERRY$6, YARN_CLASSIC$6, VLT$6];
3210
+ const AGENTS = [BUN$5, NPM$b, PNPM$8, YARN_BERRY$5, YARN_CLASSIC$6, VLT$5];
3176
3211
  const binByAgent = {
3177
3212
  __proto__: null,
3178
- [BUN$6]: BUN$6,
3179
- [NPM$c]: NPM$c,
3213
+ [BUN$5]: BUN$5,
3214
+ [NPM$b]: NPM$b,
3180
3215
  [PNPM$8]: PNPM$8,
3181
- [YARN_BERRY$6]: YARN,
3216
+ [YARN_BERRY$5]: YARN,
3182
3217
  [YARN_CLASSIC$6]: YARN,
3183
- [VLT$6]: VLT$6
3218
+ [VLT$5]: VLT$5
3184
3219
  };
3185
3220
  async function getAgentExecPath(agent) {
3186
3221
  const binName = binByAgent[agent];
@@ -3202,24 +3237,24 @@ async function getAgentVersion(agentExecPath, cwd) {
3202
3237
 
3203
3238
  // The order of LOCKS properties IS significant as it affects iteration order.
3204
3239
  const LOCKS = {
3205
- [`bun${LOCK_EXT$1}`]: BUN$6,
3206
- [`bun${BINARY_LOCK_EXT}`]: BUN$6,
3240
+ [`bun${LOCK_EXT$1}`]: BUN$5,
3241
+ [`bun${BINARY_LOCK_EXT}`]: BUN$5,
3207
3242
  // If both package-lock.json and npm-shrinkwrap.json are present in the root
3208
3243
  // of a project, npm-shrinkwrap.json will take precedence and package-lock.json
3209
3244
  // will be ignored.
3210
3245
  // https://docs.npmjs.com/cli/v10/configuring-npm/package-lock-json#package-lockjson-vs-npm-shrinkwrapjson
3211
- 'npm-shrinkwrap.json': NPM$c,
3212
- 'package-lock.json': NPM$c,
3246
+ 'npm-shrinkwrap.json': NPM$b,
3247
+ 'package-lock.json': NPM$b,
3213
3248
  'pnpm-lock.yaml': PNPM$8,
3214
3249
  'pnpm-lock.yml': PNPM$8,
3215
3250
  [`yarn${LOCK_EXT$1}`]: YARN_CLASSIC$6,
3216
- 'vlt-lock.json': VLT$6,
3251
+ 'vlt-lock.json': VLT$5,
3217
3252
  // Lastly, look for a hidden lock file which is present if .npmrc has package-lock=false:
3218
3253
  // https://docs.npmjs.com/cli/v10/configuring-npm/package-lock-json#hidden-lockfiles
3219
3254
  //
3220
3255
  // Unlike the other LOCKS keys this key contains a directory AND filename so
3221
3256
  // it has to be handled differently.
3222
- 'node_modules/.package-lock.json': NPM$c
3257
+ 'node_modules/.package-lock.json': NPM$b
3223
3258
  };
3224
3259
  const readLockFileByAgent = (() => {
3225
3260
  function wrapReader(reader) {
@@ -3233,7 +3268,7 @@ const readLockFileByAgent = (() => {
3233
3268
  const binaryReader = wrapReader(shadowNpmInject.readFileBinary);
3234
3269
  const defaultReader = wrapReader(async lockPath => await shadowNpmInject.readFileUtf8(lockPath));
3235
3270
  return {
3236
- [BUN$6]: wrapReader(async (lockPath, agentExecPath) => {
3271
+ [BUN$5]: wrapReader(async (lockPath, agentExecPath) => {
3237
3272
  const ext = path.extname(lockPath);
3238
3273
  if (ext === LOCK_EXT$1) {
3239
3274
  return await defaultReader(lockPath);
@@ -3252,10 +3287,10 @@ const readLockFileByAgent = (() => {
3252
3287
  }
3253
3288
  return undefined;
3254
3289
  }),
3255
- [NPM$c]: defaultReader,
3290
+ [NPM$b]: defaultReader,
3256
3291
  [PNPM$8]: defaultReader,
3257
- [VLT$6]: defaultReader,
3258
- [YARN_BERRY$6]: defaultReader,
3292
+ [VLT$5]: defaultReader,
3293
+ [YARN_BERRY$5]: defaultReader,
3259
3294
  [YARN_CLASSIC$6]: defaultReader
3260
3295
  };
3261
3296
  })();
@@ -3267,8 +3302,8 @@ async function detectPackageEnvironment({
3267
3302
  cwd
3268
3303
  });
3269
3304
  let lockName = lockPath ? path.basename(lockPath) : undefined;
3270
- const isHiddenLockFile = lockName === '.package-lock.json';
3271
- const pkgJsonPath = lockPath ? path.resolve(lockPath, `${isHiddenLockFile ? '../' : ''}../package.json`) : await shadowNpmInject.findUp('package.json', {
3305
+ const isHiddenLockFile = lockName === HIDDEN_PACKAGE_LOCK_JSON;
3306
+ const pkgJsonPath = lockPath ? path.resolve(lockPath, `${isHiddenLockFile ? '../' : ''}../${PACKAGE_JSON}`) : await shadowNpmInject.findUp(PACKAGE_JSON, {
3272
3307
  cwd
3273
3308
  });
3274
3309
  const pkgPath = pkgJsonPath && fs.existsSync(pkgJsonPath) ? path.dirname(pkgJsonPath) : undefined;
@@ -3296,16 +3331,16 @@ async function detectPackageEnvironment({
3296
3331
  agent = LOCKS[lockName];
3297
3332
  }
3298
3333
  if (agent === undefined) {
3299
- agent = NPM$c;
3334
+ agent = NPM$b;
3300
3335
  onUnknown?.(pkgManager);
3301
3336
  }
3302
3337
  const agentExecPath = await getAgentExecPath(agent);
3303
- const npmExecPath = agent === NPM$c ? agentExecPath : await getAgentExecPath(NPM$c);
3338
+ const npmExecPath = agent === NPM$b ? agentExecPath : await getAgentExecPath(NPM$b);
3304
3339
  if (agentVersion === undefined) {
3305
3340
  agentVersion = await getAgentVersion(agentExecPath, cwd);
3306
3341
  }
3307
3342
  if (agent === YARN_CLASSIC$6 && (agentVersion?.major ?? 0) > 1) {
3308
- agent = YARN_BERRY$6;
3343
+ agent = YARN_BERRY$5;
3309
3344
  }
3310
3345
  const targets = {
3311
3346
  browser: false,
@@ -3347,6 +3382,8 @@ async function detectPackageEnvironment({
3347
3382
  lockName = undefined;
3348
3383
  lockPath = undefined;
3349
3384
  }
3385
+ const pkgSupported = targets.browser || targets.node;
3386
+ const npmBuggyOverrides = agent === NPM$b && !!agentVersion && semver.lt(agentVersion, NPM_BUGGY_OVERRIDES_PATCHED_VERSION$1);
3350
3387
  return {
3351
3388
  agent,
3352
3389
  agentExecPath,
@@ -3358,19 +3395,16 @@ async function detectPackageEnvironment({
3358
3395
  npmExecPath,
3359
3396
  pkgJson: editablePkgJson,
3360
3397
  pkgPath,
3361
- supported: targets.browser || targets.node,
3398
+ pkgSupported,
3399
+ features: {
3400
+ npmBuggyOverrides
3401
+ },
3362
3402
  targets
3363
3403
  };
3364
3404
  }
3365
-
3366
- const {
3367
- BUN: BUN$5,
3368
- VLT: VLT$5,
3369
- YARN_BERRY: YARN_BERRY$5
3370
- } = constants;
3371
- const COMMAND_TITLE$2 = 'Socket Optimize';
3372
3405
  async function detectAndValidatePackageEnvironment(cwd, options) {
3373
3406
  const {
3407
+ cmdName = '',
3374
3408
  logger,
3375
3409
  prod
3376
3410
  } = {
@@ -3380,44 +3414,45 @@ async function detectAndValidatePackageEnvironment(cwd, options) {
3380
3414
  const details = await detectPackageEnvironment({
3381
3415
  cwd,
3382
3416
  onUnknown(pkgManager) {
3383
- logger?.warn(`${COMMAND_TITLE$2}: Unknown package manager${pkgManager ? ` ${pkgManager}` : ''}, defaulting to npm`);
3417
+ logger?.warn(cmdPrefixMessage(cmdName, `Unknown package manager${pkgManager ? ` ${pkgManager}` : ''}, defaulting to npm`));
3384
3418
  }
3385
3419
  });
3386
- if (!details.supported) {
3387
- logger?.fail(`${COMMAND_TITLE$2}: No supported Node or browser range detected`);
3420
+ if (!details.pkgSupported) {
3421
+ logger?.fail(cmdPrefixMessage(cmdName, 'No supported Node or browser range detected'));
3388
3422
  return;
3389
3423
  }
3390
3424
  if (details.agent === VLT$5) {
3391
- logger?.fail(`${COMMAND_TITLE$2}: ${details.agent} does not support overrides. Soon, though ⚡`);
3425
+ logger?.fail(cmdPrefixMessage(cmdName, `${details.agent} does not support overrides. Soon, though ⚡`));
3392
3426
  return;
3393
3427
  }
3394
3428
  const lockName = details.lockName ?? 'lock file';
3395
3429
  if (details.lockName === undefined || details.lockSrc === undefined) {
3396
- logger?.fail(`${COMMAND_TITLE$2}: No ${lockName} found`);
3430
+ logger?.fail(cmdPrefixMessage(cmdName, `No ${lockName} found`));
3397
3431
  return;
3398
3432
  }
3399
3433
  if (details.lockSrc.trim() === '') {
3400
- logger?.fail(`${COMMAND_TITLE$2}: ${lockName} is empty`);
3434
+ logger?.fail(cmdPrefixMessage(cmdName, `${lockName} is empty`));
3401
3435
  return;
3402
3436
  }
3403
3437
  if (details.pkgPath === undefined) {
3404
- logger?.fail(`${COMMAND_TITLE$2}: No package.json found`);
3438
+ logger?.fail(cmdPrefixMessage(cmdName, `No ${PACKAGE_JSON} found`));
3405
3439
  return;
3406
3440
  }
3407
3441
  if (prod && (details.agent === BUN$5 || details.agent === YARN_BERRY$5)) {
3408
- logger?.fail(`${COMMAND_TITLE$2}: --prod not supported for ${details.agent}${details.agentVersion ? `@${details.agentVersion.toString()}` : ''}`);
3442
+ logger?.fail(cmdPrefixMessage(cmdName, `--prod not supported for ${details.agent}${details.agentVersion ? `@${details.agentVersion.version}` : ''}`));
3409
3443
  return;
3410
3444
  }
3411
3445
  if (details.lockPath && path.relative(cwd, details.lockPath).startsWith('.')) {
3412
- logger?.warn(`${COMMAND_TITLE$2}: Package ${lockName} found at ${details.lockPath}`);
3446
+ logger?.warn(cmdPrefixMessage(cmdName, `Package ${lockName} found at ${details.lockPath}`));
3413
3447
  }
3414
3448
  return details;
3415
3449
  }
3416
3450
 
3417
3451
  const {
3418
- NPM: NPM$b,
3452
+ NPM: NPM$a,
3419
3453
  PNPM: PNPM$7
3420
3454
  } = constants;
3455
+ const CMD_NAME$2 = 'socket fix';
3421
3456
  async function runFix() {
3422
3457
  // Lazily access constants.spinner.
3423
3458
  const {
@@ -3426,6 +3461,7 @@ async function runFix() {
3426
3461
  spinner.start();
3427
3462
  const cwd = process.cwd();
3428
3463
  const pkgEnvDetails = await detectAndValidatePackageEnvironment(cwd, {
3464
+ cmdName: CMD_NAME$2,
3429
3465
  logger: logger.logger
3430
3466
  });
3431
3467
  if (!pkgEnvDetails) {
@@ -3433,7 +3469,7 @@ async function runFix() {
3433
3469
  return;
3434
3470
  }
3435
3471
  switch (pkgEnvDetails.agent) {
3436
- case NPM$b:
3472
+ case NPM$a:
3437
3473
  {
3438
3474
  await npmFix(pkgEnvDetails, cwd);
3439
3475
  break;
@@ -3505,7 +3541,7 @@ async function fetchPackageInfo(pkgName, pkgVersion, includeAllIssues) {
3505
3541
  }
3506
3542
 
3507
3543
  const {
3508
- NPM: NPM$a
3544
+ NPM: NPM$9
3509
3545
  } = registryConstants;
3510
3546
  function formatScore(score) {
3511
3547
  if (score > 80) {
@@ -3589,7 +3625,7 @@ function logPackageInfo({
3589
3625
  logger.logger.log('Package has no issues');
3590
3626
  }
3591
3627
  const format = new shadowNpmInject.ColorOrMarkdown(outputKind === 'markdown');
3592
- const url = shadowNpmInject.getSocketDevPackageOverviewUrl(NPM$a, pkgName, pkgVersion);
3628
+ const url = shadowNpmInject.getSocketDevPackageOverviewUrl(NPM$9, pkgName, pkgVersion);
3593
3629
  logger.logger.log('\n');
3594
3630
  if (pkgVersion === 'latest') {
3595
3631
  logger.logger.log(`Detailed info on socket.dev: ${format.hyperlink(`${pkgName}`, url, {
@@ -3916,9 +3952,11 @@ async function convertGradleToMaven(target, bin, _out, verbose, gradleOpts) {
3916
3952
  logger.logger.groupEnd();
3917
3953
  }
3918
3954
  try {
3919
- // Run sbt with the init script we provide which should yield zero or more pom files.
3920
- // We have to figure out where to store those pom files such that we can upload them and predict them through the GitHub API.
3921
- // 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.
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.
3922
3960
 
3923
3961
  // Note: init.gradle will be exported by .config/rollup.dist.config.mjs
3924
3962
  const initLocation = path.join(constants.rootDistPath, 'init.gradle');
@@ -3965,7 +4003,7 @@ async function convertGradleToMaven(target, bin, _out, verbose, gradleOpts) {
3965
4003
  // // Move the pom file to ...? initial cwd? loc will be an absolute path, or dump to stdout
3966
4004
  // if (out === '-') {
3967
4005
  // spinner.start('Result:\n```')
3968
- // spinner.log(await safeReadFile(loc, 'utf8'))
4006
+ // spinner.log(await safeReadFile(loc))
3969
4007
  // spinner.log('```')
3970
4008
  // spinner.successAndStop(`OK`)
3971
4009
  // } else {
@@ -4200,7 +4238,7 @@ async function convertSbtToMaven(target, bin, out, verbose, sbtOpts) {
4200
4238
  // TODO: maybe we can add an option to target a specific file to dump to stdout
4201
4239
  if (out === '-' && poms.length === 1) {
4202
4240
  logger.logger.log('Result:\n```');
4203
- logger.logger.log(await shadowNpmInject.safeReadFile(poms[0], 'utf8'));
4241
+ logger.logger.log(await shadowNpmInject.safeReadFile(poms[0]));
4204
4242
  logger.logger.log('```');
4205
4243
  logger.logger.success(`OK`);
4206
4244
  } else if (out === '-') {
@@ -4677,21 +4715,21 @@ async function run$l(argv, importMeta, {
4677
4715
  }
4678
4716
 
4679
4717
  const {
4680
- NPM: NPM$9
4718
+ NPM: NPM$8
4681
4719
  } = constants;
4682
4720
  async function wrapNpm(argv) {
4683
4721
  // Lazily access constants.distShadowNpmBinPath.
4684
4722
  const shadowBin = require(constants.distShadowNpmBinPath);
4685
- await shadowBin(NPM$9, argv);
4723
+ await shadowBin(NPM$8, argv);
4686
4724
  }
4687
4725
 
4688
4726
  const {
4689
4727
  DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$k,
4690
- NPM: NPM$8
4728
+ NPM: NPM$7
4691
4729
  } = constants;
4692
4730
  const config$k = {
4693
4731
  commandName: 'npm',
4694
- description: `${NPM$8} wrapper functionality`,
4732
+ description: `${NPM$7} wrapper functionality`,
4695
4733
  hidden: false,
4696
4734
  flags: {},
4697
4735
  help: (command, _config) => `
@@ -4806,7 +4844,7 @@ async function run$i(argv, importMeta, {
4806
4844
 
4807
4845
  const {
4808
4846
  BUN: BUN$4,
4809
- NPM: NPM$7,
4847
+ NPM: NPM$6,
4810
4848
  PNPM: PNPM$6,
4811
4849
  VLT: VLT$4,
4812
4850
  YARN_BERRY: YARN_BERRY$4,
@@ -4818,7 +4856,7 @@ function matchLsCmdViewHumanStdout(stdout, name) {
4818
4856
  function matchQueryCmdStdout(stdout, name) {
4819
4857
  return stdout.includes(`"${name}"`);
4820
4858
  }
4821
- const depsIncludesByAgent = new Map([[BUN$4, matchLsCmdViewHumanStdout], [NPM$7, matchQueryCmdStdout], [PNPM$6, matchQueryCmdStdout], [VLT$4, matchQueryCmdStdout], [YARN_BERRY$4, matchLsCmdViewHumanStdout], [YARN_CLASSIC$5, matchLsCmdViewHumanStdout]]);
4859
+ const depsIncludesByAgent = new Map([[BUN$4, matchLsCmdViewHumanStdout], [NPM$6, matchQueryCmdStdout], [PNPM$6, matchQueryCmdStdout], [VLT$4, matchQueryCmdStdout], [YARN_BERRY$4, matchLsCmdViewHumanStdout], [YARN_CLASSIC$5, matchLsCmdViewHumanStdout]]);
4822
4860
 
4823
4861
  function getDependencyEntries(pkgJson) {
4824
4862
  const {
@@ -4846,7 +4884,7 @@ function getDependencyEntries(pkgJson) {
4846
4884
 
4847
4885
  const {
4848
4886
  BUN: BUN$3,
4849
- NPM: NPM$6,
4887
+ NPM: NPM$5,
4850
4888
  OVERRIDES: OVERRIDES$1,
4851
4889
  PNPM: PNPM$5,
4852
4890
  RESOLUTIONS: RESOLUTIONS$1,
@@ -4867,7 +4905,7 @@ function getOverridesDataBun(pkgJson) {
4867
4905
  function getOverridesDataNpm(pkgJson) {
4868
4906
  const overrides = pkgJson?.[OVERRIDES$1] ?? {};
4869
4907
  return {
4870
- type: NPM$6,
4908
+ type: NPM$5,
4871
4909
  overrides
4872
4910
  };
4873
4911
  }
@@ -4908,7 +4946,7 @@ function getOverridesDataClassic(pkgJson) {
4908
4946
  overrides
4909
4947
  };
4910
4948
  }
4911
- const overridesDataByAgent = new Map([[BUN$3, getOverridesDataBun], [NPM$6, getOverridesDataNpm], [PNPM$5, getOverridesDataPnpm], [VLT$3, getOverridesDataVlt], [YARN_BERRY$3, getOverridesDataYarn], [YARN_CLASSIC$4, getOverridesDataClassic]]);
4949
+ const overridesDataByAgent = new Map([[BUN$3, getOverridesDataBun], [NPM$5, getOverridesDataNpm], [PNPM$5, getOverridesDataPnpm], [VLT$3, getOverridesDataVlt], [YARN_BERRY$3, getOverridesDataYarn], [YARN_CLASSIC$4, getOverridesDataClassic]]);
4912
4950
 
4913
4951
  const {
4914
4952
  PNPM: PNPM$4
@@ -4919,7 +4957,7 @@ async function getWorkspaceGlobs(agent, pkgPath, pkgJson) {
4919
4957
  if (agent === PNPM$4) {
4920
4958
  for (const workspacePath of [path.join(pkgPath, `${PNPM_WORKSPACE}.yaml`), path.join(pkgPath, `${PNPM_WORKSPACE}.yml`)]) {
4921
4959
  // eslint-disable-next-line no-await-in-loop
4922
- const yml = await shadowNpmInject.safeReadFile(workspacePath, 'utf8');
4960
+ const yml = await shadowNpmInject.safeReadFile(workspacePath);
4923
4961
  if (yml) {
4924
4962
  try {
4925
4963
  workspacePatterns = yaml.parse(yml)?.packages;
@@ -4956,7 +4994,7 @@ function workspacePatternToGlobPattern(workspace) {
4956
4994
  const {
4957
4995
  BUN: BUN$2,
4958
4996
  LOCK_EXT,
4959
- NPM: NPM$5,
4997
+ NPM: NPM$4,
4960
4998
  PNPM: PNPM$3,
4961
4999
  VLT: VLT$2,
4962
5000
  YARN_BERRY: YARN_BERRY$2,
@@ -5000,11 +5038,11 @@ function includesYarn(lockSrc, name) {
5000
5038
  // , name@
5001
5039
  `(?<=(?:^\\s*|,\\s*)"?)${escapedName}(?=@)`, 'm').test(lockSrc);
5002
5040
  }
5003
- const lockfileIncludesByAgent = new Map([[BUN$2, includesBun], [NPM$5, includesNpm], [PNPM$3, includesPnpm], [VLT$2, includesVlt], [YARN_BERRY$2, includesYarn], [YARN_CLASSIC$3, includesYarn]]);
5041
+ const lockfileIncludesByAgent = new Map([[BUN$2, includesBun], [NPM$4, includesNpm], [PNPM$3, includesPnpm], [VLT$2, includesVlt], [YARN_BERRY$2, includesYarn], [YARN_CLASSIC$3, includesYarn]]);
5004
5042
 
5005
5043
  const {
5006
5044
  BUN: BUN$1,
5007
- NPM: NPM$4,
5045
+ NPM: NPM$3,
5008
5046
  PNPM: PNPM$2,
5009
5047
  VLT: VLT$1,
5010
5048
  YARN_BERRY: YARN_BERRY$1,
@@ -5074,7 +5112,7 @@ async function lsNpm(agentExecPath, cwd) {
5074
5112
  }
5075
5113
  async function lsPnpm(agentExecPath, cwd, options) {
5076
5114
  const npmExecPath = options?.npmExecPath;
5077
- if (npmExecPath && npmExecPath !== NPM$4) {
5115
+ if (npmExecPath && npmExecPath !== NPM$3) {
5078
5116
  const result = await npmQuery(npmExecPath, cwd);
5079
5117
  if (result) {
5080
5118
  return result;
@@ -5125,35 +5163,7 @@ async function lsYarnClassic(agentExecPath, cwd) {
5125
5163
  } catch {}
5126
5164
  return '';
5127
5165
  }
5128
- const lsByAgent = new Map([[BUN$1, lsBun], [NPM$4, lsNpm], [PNPM$2, lsPnpm], [VLT$1, lsVlt], [YARN_BERRY$1, lsYarnBerry], [YARN_CLASSIC$2, lsYarnClassic]]);
5129
-
5130
- const {
5131
- NPM: NPM$3
5132
- } = constants;
5133
- const COMMAND_TITLE$1 = 'Socket Optimize';
5134
- async function updateLockfile(pkgEnvDetails, options) {
5135
- const {
5136
- logger,
5137
- spinner
5138
- } = {
5139
- __proto__: null,
5140
- ...options
5141
- };
5142
- spinner?.start(`Updating ${pkgEnvDetails.lockName}...`);
5143
- try {
5144
- await runAgentInstall(pkgEnvDetails, {
5145
- spinner
5146
- });
5147
- spinner?.stop();
5148
- if (pkgEnvDetails.agent === NPM$3) {
5149
- logger?.log(`💡 Re-run ${COMMAND_TITLE$1} whenever ${pkgEnvDetails.lockName} changes.\n This can be skipped once npm v11.2.0 is released.`);
5150
- }
5151
- } catch (e) {
5152
- spinner?.stop();
5153
- logger?.fail(`${COMMAND_TITLE$1}: ${pkgEnvDetails.agent} install failed to update ${pkgEnvDetails.lockName}`);
5154
- logger?.error(e);
5155
- }
5156
- }
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]]);
5157
5167
 
5158
5168
  const {
5159
5169
  BUN,
@@ -5165,7 +5175,6 @@ const {
5165
5175
  YARN_BERRY,
5166
5176
  YARN_CLASSIC: YARN_CLASSIC$1
5167
5177
  } = constants;
5168
- const PNPM_FIELD_NAME = PNPM$1;
5169
5178
  const depFields = ['dependencies', 'devDependencies', 'peerDependencies', 'peerDependenciesMeta', 'optionalDependencies', 'bundleDependencies'];
5170
5179
  function getEntryIndexes(entries, keys) {
5171
5180
  return keys.map(n => entries.findIndex(p => p[0] === n)).filter(n => n !== -1).sort((a, b) => a - b);
@@ -5176,26 +5185,30 @@ function getLowestEntryIndex(entries, keys) {
5176
5185
  function getHighestEntryIndex(entries, keys) {
5177
5186
  return getEntryIndexes(entries, keys).at(-1) ?? -1;
5178
5187
  }
5179
- function updatePkgJson(editablePkgJson, field, value) {
5188
+ function updatePkgJsonField(editablePkgJson, field, value) {
5180
5189
  const {
5181
5190
  content: pkgJson
5182
5191
  } = editablePkgJson;
5183
5192
  const oldValue = pkgJson[field];
5184
5193
  if (oldValue) {
5185
5194
  // The field already exists so we simply update the field value.
5186
- if (field === PNPM_FIELD_NAME) {
5195
+ if (field === PNPM$1) {
5196
+ const isPnpmObj = objects.isObject(oldValue);
5187
5197
  if (objects.hasKeys(value)) {
5188
5198
  editablePkgJson.update({
5189
5199
  [field]: {
5190
- ...(objects.isObject(oldValue) ? oldValue : {}),
5191
- overrides: value
5200
+ ...(isPnpmObj ? oldValue : {}),
5201
+ overrides: {
5202
+ ...(isPnpmObj ? oldValue[OVERRIDES] : {}),
5203
+ ...value
5204
+ }
5192
5205
  }
5193
5206
  });
5194
5207
  } else {
5195
5208
  // Properties with undefined values are omitted when saved as JSON.
5196
- editablePkgJson.update(objects.hasKeys(pkgJson[field]) ? {
5209
+ editablePkgJson.update(objects.hasKeys(oldValue) ? {
5197
5210
  [field]: {
5198
- ...(objects.isObject(oldValue) ? oldValue : {}),
5211
+ ...(isPnpmObj ? oldValue : {}),
5199
5212
  overrides: undefined
5200
5213
  }
5201
5214
  } : {
@@ -5214,7 +5227,7 @@ function updatePkgJson(editablePkgJson, field, value) {
5214
5227
  }
5215
5228
  return;
5216
5229
  }
5217
- if ((field === OVERRIDES || field === PNPM_FIELD_NAME || field === RESOLUTIONS) && !objects.hasKeys(value)) {
5230
+ if ((field === OVERRIDES || field === PNPM$1 || field === RESOLUTIONS) && !objects.hasKeys(value)) {
5218
5231
  return;
5219
5232
  }
5220
5233
  // Since the field doesn't exist we want to insert it into the package.json
@@ -5232,7 +5245,7 @@ function updatePkgJson(editablePkgJson, field, value) {
5232
5245
  } else if (field === RESOLUTIONS) {
5233
5246
  isPlacingHigher = true;
5234
5247
  insertIndex = getHighestEntryIndex(entries, [...depFields, OVERRIDES, PNPM$1]);
5235
- } else if (field === PNPM_FIELD_NAME) {
5248
+ } else if (field === PNPM$1) {
5236
5249
  insertIndex = getLowestEntryIndex(entries, [OVERRIDES, RESOLUTIONS]);
5237
5250
  if (insertIndex === -1) {
5238
5251
  isPlacingHigher = true;
@@ -5251,26 +5264,28 @@ function updatePkgJson(editablePkgJson, field, value) {
5251
5264
  } else if (isPlacingHigher) {
5252
5265
  insertIndex += 1;
5253
5266
  }
5254
- entries.splice(insertIndex, 0, [field, value]);
5267
+ entries.splice(insertIndex, 0, [field, field === PNPM$1 ? {
5268
+ [OVERRIDES]: value
5269
+ } : value]);
5255
5270
  editablePkgJson.fromJSON(`${JSON.stringify(Object.fromEntries(entries), null, 2)}\n`);
5256
5271
  }
5257
- function updateOverrides(editablePkgJson, overrides) {
5258
- updatePkgJson(editablePkgJson, OVERRIDES, overrides);
5272
+ function updateOverridesField(editablePkgJson, overrides) {
5273
+ updatePkgJsonField(editablePkgJson, OVERRIDES, overrides);
5259
5274
  }
5260
- function updateResolutions(editablePkgJson, overrides) {
5261
- updatePkgJson(editablePkgJson, RESOLUTIONS, overrides);
5275
+ function updateResolutionsField(editablePkgJson, overrides) {
5276
+ updatePkgJsonField(editablePkgJson, RESOLUTIONS, overrides);
5262
5277
  }
5263
- function pnpmUpdatePkgJson(editablePkgJson, overrides) {
5264
- updatePkgJson(editablePkgJson, PNPM_FIELD_NAME, overrides);
5278
+ function updatePnpmField(editablePkgJson, overrides) {
5279
+ updatePkgJsonField(editablePkgJson, PNPM$1, overrides);
5265
5280
  }
5266
- const updateManifestByAgent = new Map([[BUN, updateResolutions], [NPM$2, updateOverrides], [PNPM$1, pnpmUpdatePkgJson], [VLT, updateOverrides], [YARN_BERRY, updateResolutions], [YARN_CLASSIC$1, updateResolutions]]);
5281
+ const updateManifestByAgent = new Map([[BUN, updateResolutionsField], [NPM$2, updateOverridesField], [PNPM$1, updatePnpmField], [VLT, updateOverridesField], [YARN_BERRY, updateResolutionsField], [YARN_CLASSIC$1, updateResolutionsField]]);
5267
5282
 
5268
5283
  const {
5269
5284
  NPM: NPM$1,
5270
5285
  PNPM,
5271
5286
  YARN_CLASSIC
5272
5287
  } = constants;
5273
- const COMMAND_TITLE = 'Socket Optimize';
5288
+ const CMD_NAME$1 = 'socket optimize';
5274
5289
  const manifestNpmOverrides = registry.getManifestData(NPM$1);
5275
5290
  async function addOverrides(pkgPath, pkgEnvDetails, options) {
5276
5291
  const {
@@ -5308,24 +5323,17 @@ async function addOverrides(pkgPath, pkgEnvDetails, options) {
5308
5323
  const {
5309
5324
  content: pkgJson
5310
5325
  } = editablePkgJson;
5311
- const isRoot = pkgPath === rootPath;
5312
- const isLockScanned = isRoot && !prod;
5313
5326
  const workspaceName = path.relative(rootPath, pkgPath);
5314
5327
  const workspaceGlobs = await getWorkspaceGlobs(agent, pkgPath, pkgJson);
5328
+ const isRoot = pkgPath === rootPath;
5329
+ const isLockScanned = isRoot && !prod;
5315
5330
  const isWorkspace = !!workspaceGlobs;
5316
- if (isWorkspace && agent === PNPM && npmExecPath === NPM$1 && !state.warnedPnpmWorkspaceRequiresNpm) {
5331
+ if (isWorkspace && agent === PNPM &&
5332
+ // npmExecPath will === the agent name IF it CANNOT be resolved.
5333
+ npmExecPath === NPM$1 && !state.warnedPnpmWorkspaceRequiresNpm) {
5317
5334
  state.warnedPnpmWorkspaceRequiresNpm = true;
5318
- logger?.warn(`${COMMAND_TITLE}: pnpm workspace support requires \`npm ls\`, falling back to \`pnpm list\``);
5335
+ logger?.warn(cmdPrefixMessage(CMD_NAME$1, `${agent} workspace support requires \`npm ls\`, falling back to \`${agent} list\``));
5319
5336
  }
5320
- const thingToScan = isLockScanned ? lockSrc : await lsByAgent.get(agent)(agentExecPath, pkgPath, {
5321
- npmExecPath
5322
- });
5323
- // The AgentDepsIncludesFn and AgentLockIncludesFn types overlap in their
5324
- // first two parameters. AgentLockIncludesFn accepts an optional third
5325
- // parameter which AgentDepsIncludesFn will ignore so we cast thingScanner
5326
- // as an AgentLockIncludesFn type.
5327
- const thingScanner = isLockScanned ? lockfileIncludesByAgent.get(agent) : depsIncludesByAgent.get(agent);
5328
- const depEntries = getDependencyEntries(pkgJson);
5329
5337
  const overridesDataObjects = [];
5330
5338
  if (pkgJson['private'] || isWorkspace) {
5331
5339
  overridesDataObjects.push(overridesDataByAgent.get(agent)(pkgJson));
@@ -5334,10 +5342,12 @@ async function addOverrides(pkgPath, pkgEnvDetails, options) {
5334
5342
  }
5335
5343
  spinner?.setText(`Adding overrides${workspaceName ? ` to ${workspaceName}` : ''}...`);
5336
5344
  const depAliasMap = new Map();
5345
+ const depEntries = getDependencyEntries(pkgJson);
5337
5346
  const nodeRange = `>=${pkgEnvDetails.minimumNodeVersion}`;
5338
5347
  const manifestEntries = manifestNpmOverrides.filter(({
5339
5348
  1: data
5340
5349
  }) => semver.satisfies(semver.coerce(data.engines.node), nodeRange));
5350
+
5341
5351
  // Chunk package names to process them in parallel 3 at a time.
5342
5352
  await promises.pEach(manifestEntries, 3, async ({
5343
5353
  1: data
@@ -5374,6 +5384,14 @@ async function addOverrides(pkgPath, pkgEnvDetails, options) {
5374
5384
  }
5375
5385
  }
5376
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
+ });
5377
5395
  // Chunk package names to process them in parallel 3 at a time.
5378
5396
  await promises.pEach(overridesDataObjects, 3, async ({
5379
5397
  overrides,
@@ -5450,11 +5468,50 @@ async function addOverrides(pkgPath, pkgEnvDetails, options) {
5450
5468
  }
5451
5469
  return state;
5452
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';
5453
5509
  function createActionMessage(verb, overrideCount, workspaceCount) {
5454
5510
  return `${verb} ${overrideCount} Socket.dev optimized ${words.pluralize('override', overrideCount)}${workspaceCount ? ` in ${workspaceCount} ${words.pluralize('workspace', workspaceCount)}` : ''}`;
5455
5511
  }
5456
5512
  async function applyOptimization(cwd, pin, prod) {
5457
5513
  const pkgEnvDetails = await detectAndValidatePackageEnvironment(cwd, {
5514
+ cmdName: CMD_NAME,
5458
5515
  logger: logger.logger,
5459
5516
  prod
5460
5517
  });
@@ -5472,10 +5529,17 @@ async function applyOptimization(cwd, pin, prod) {
5472
5529
  prod,
5473
5530
  spinner
5474
5531
  });
5475
- spinner.stop();
5476
5532
  const addedCount = state.added.size;
5477
5533
  const updatedCount = state.updated.size;
5478
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();
5479
5543
  if (pkgJsonChanged) {
5480
5544
  if (updatedCount > 0) {
5481
5545
  logger.logger?.log(`${createActionMessage('Updated', updatedCount, state.updatedInWorkspaces.size)}${addedCount ? '.' : '🚀'}`);
@@ -5486,14 +5550,6 @@ async function applyOptimization(cwd, pin, prod) {
5486
5550
  } else {
5487
5551
  logger.logger?.log('Congratulations! Already Socket.dev optimized 🎉');
5488
5552
  }
5489
- if (pkgEnvDetails.agent === NPM$1 || pkgJsonChanged) {
5490
- // Always update package-lock.json until the npm overrides PR lands:
5491
- // https://github.com/npm/cli/pull/8089
5492
- await updateLockfile(pkgEnvDetails, {
5493
- logger: logger.logger,
5494
- spinner
5495
- });
5496
- }
5497
5553
  }
5498
5554
 
5499
5555
  const {
@@ -8226,15 +8282,15 @@ async function run(argv, importMeta, {
8226
8282
  }
8227
8283
 
8228
8284
  const {
8229
- SOCKET,
8230
- rootPkgJsonPath
8285
+ SOCKET_CLI_BIN_NAME
8231
8286
  } = constants;
8232
8287
 
8233
8288
  // TODO: Add autocompletion using https://socket.dev/npm/package/omelette
8234
8289
  void (async () => {
8235
8290
  await vendor.updater({
8236
- name: SOCKET,
8237
- version: require(rootPkgJsonPath).version,
8291
+ name: SOCKET_CLI_BIN_NAME,
8292
+ // The '@rollup/plugin-replace' will replace "process.env['INLINED_SOCKET_CLI_VERSION']".
8293
+ version: "0.14.60",
8238
8294
  ttl: 86_400_000 /* 24 hours in milliseconds */
8239
8295
  });
8240
8296
  try {
@@ -8270,7 +8326,7 @@ void (async () => {
8270
8326
  }
8271
8327
  },
8272
8328
  argv: process$1.argv.slice(2),
8273
- name: SOCKET,
8329
+ name: SOCKET_CLI_BIN_NAME,
8274
8330
  importMeta: {
8275
8331
  url: `${require$$0.pathToFileURL(__filename)}`
8276
8332
  }
@@ -8294,12 +8350,12 @@ void (async () => {
8294
8350
  } else {
8295
8351
  errorTitle = 'Unexpected error with no details';
8296
8352
  }
8297
- logger.logger.fail(`${colors.bgRed(colors.white(errorTitle + ':'))} ${errorMessage}`);
8353
+ logger.logger.fail(`${colors.bgRed(colors.white(`${errorTitle}:`))} ${errorMessage}`);
8298
8354
  if (errorBody) {
8299
8355
  logger.logger.error(`\n${errorBody}`);
8300
8356
  }
8301
8357
  await shadowNpmInject.captureException(e);
8302
8358
  }
8303
8359
  })();
8304
- //# debugId=b5131c8e-e05e-4ce0-8d35-03afa5b09043
8360
+ //# debugId=96a268e4-5b2f-482d-b6b4-fd911a70dc9f
8305
8361
  //# sourceMappingURL=cli.js.map