@socketsecurity/cli-with-sentry 0.14.45 → 0.14.47

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.
@@ -26,11 +26,12 @@ var rest = _socketInterop(require('@octokit/rest'));
26
26
  var index = require('./index.js');
27
27
  var meow = _socketInterop(require('meow'));
28
28
  var objects = require('@socketsecurity/registry/lib/objects');
29
+ var regexps = require('@socketsecurity/registry/lib/regexps');
30
+ var constants = require('./constants.js');
29
31
  var fs$1 = require('node:fs/promises');
30
32
  var ScreenWidget = _socketInterop(require('blessed/lib/widgets/screen'));
31
33
  var contrib = _socketInterop(require('blessed-contrib'));
32
34
  var spinner = require('@socketsecurity/registry/lib/spinner');
33
- var constants = require('./constants2.js');
34
35
  var prompts = require('@socketsecurity/registry/lib/prompts');
35
36
  var yargsParse = _socketInterop(require('yargs-parser'));
36
37
  var words = require('@socketsecurity/registry/lib/words');
@@ -53,7 +54,6 @@ var index_cjs = require('@socketregistry/hyrious__bun.lockb/index.cjs');
53
54
  var sorts = require('@socketsecurity/registry/lib/sorts');
54
55
  var strings = require('@socketsecurity/registry/lib/strings');
55
56
  var yaml = _socketInterop(require('yaml'));
56
- var regexps = require('@socketsecurity/registry/lib/regexps');
57
57
  var npm$1 = require('./npm.js');
58
58
  var npmPaths = require('./npm-paths.js');
59
59
  var betterAjvErrors = _socketInterop(require('@apideck/better-ajv-errors'));
@@ -61,7 +61,6 @@ var config$A = require('@socketsecurity/config');
61
61
  var readline = require('node:readline/promises');
62
62
  var open = _socketInterop(require('open'));
63
63
  var TableWidget = _socketInterop(require('blessed-contrib/lib/widget/table'));
64
- var os = require('node:os');
65
64
  var readline$1 = require('node:readline');
66
65
 
67
66
  // https://github.com/SocketDev/socket-python-cli/blob/6d4fc56faee68d3a4764f1f80f84710635bdaf05/socketsecurity/core/classes.py
@@ -1321,6 +1320,11 @@ const commonFlags = {
1321
1320
  default: false,
1322
1321
  shortFlag: 'h',
1323
1322
  description: 'Print this help.'
1323
+ },
1324
+ dryRun: {
1325
+ type: 'boolean',
1326
+ default: false,
1327
+ description: 'Do input validation for a command and exit 0 when input is ok'
1324
1328
  }
1325
1329
  };
1326
1330
  const outputFlags = {
@@ -1350,10 +1354,9 @@ const validationFlags = {
1350
1354
  }
1351
1355
  };
1352
1356
 
1353
- // Property names are picked such that the name is at the top when the props
1354
- // get ordered by alphabet while flags is near the bottom and the help text
1355
- // at the bottom, because they tend ot occupy the most lines of code.
1356
-
1357
+ const {
1358
+ SOCKET_CLI_SHOW_BANNER
1359
+ } = constants;
1357
1360
  async function meowWithSubcommands(subcommands, options) {
1358
1361
  const {
1359
1362
  aliases = {},
@@ -1366,12 +1369,12 @@ async function meowWithSubcommands(subcommands, options) {
1366
1369
  ...options
1367
1370
  };
1368
1371
  const [commandOrAliasName, ...rawCommandArgv] = argv;
1369
- // If we got at least some args, then lets find out if we can find a command
1372
+ // If we got at least some args, then lets find out if we can find a command.
1370
1373
  if (commandOrAliasName) {
1371
1374
  const alias = aliases[commandOrAliasName];
1372
- // First: Resolve argv data from alias if its an alias that's been given
1375
+ // First: Resolve argv data from alias if its an alias that's been given.
1373
1376
  const [commandName, ...commandArgv] = alias ? [...alias.argv, ...rawCommandArgv] : [commandOrAliasName, ...rawCommandArgv];
1374
- // Second: Find a command definition using that data
1377
+ // Second: Find a command definition using that data.
1375
1378
  const commandDefinition = commandName ? subcommands[commandName] : undefined;
1376
1379
  // Third: If a valid command has been found, then we run it...
1377
1380
  if (commandDefinition) {
@@ -1384,7 +1387,13 @@ async function meowWithSubcommands(subcommands, options) {
1384
1387
  ...commonFlags,
1385
1388
  ...additionalOptions.flags
1386
1389
  };
1387
- // ...else we provide basic instructions and help
1390
+ // ...else we provide basic instructions and help.
1391
+
1392
+ // Temp disable until we clear the --json and --markdown usage
1393
+ // Lazily access constants.ENV[SOCKET_CLI_SHOW_BANNER].
1394
+ if (constants.ENV[SOCKET_CLI_SHOW_BANNER]) {
1395
+ console.log(getAsciiHeader(name));
1396
+ }
1388
1397
  const cli = meow(`
1389
1398
  Usage
1390
1399
  $ ${name} <command>
@@ -1415,9 +1424,15 @@ async function meowWithSubcommands(subcommands, options) {
1415
1424
  argv,
1416
1425
  importMeta,
1417
1426
  ...additionalOptions,
1418
- flags
1427
+ flags,
1428
+ autoHelp: false // otherwise we can't exit(0)
1419
1429
  });
1420
- cli.showHelp();
1430
+ if (!cli.flags['help'] && cli.flags['dryRun']) {
1431
+ console.log('[DryRun]: noop, call a sub-command; ok');
1432
+ process.exitCode = 0;
1433
+ } else {
1434
+ cli.showHelp();
1435
+ }
1421
1436
  }
1422
1437
 
1423
1438
  /**
@@ -1432,19 +1447,40 @@ function meowOrExit({
1432
1447
  parentName
1433
1448
  }) {
1434
1449
  const command = `${parentName} ${config.commandName}`;
1435
- const help = config.help(command, config);
1436
-
1450
+ // Temp disable until we clear the --json and --markdown usage.
1451
+ // Lazily access constants.ENV[SOCKET_CLI_SHOW_BANNER].
1452
+ if (constants.ENV[SOCKET_CLI_SHOW_BANNER]) {
1453
+ console.log(getAsciiHeader(command));
1454
+ }
1437
1455
  // This exits if .printHelp() is called either by meow itself or by us.
1438
1456
  const cli = meow({
1439
1457
  argv,
1440
1458
  description: config.description,
1441
- help,
1459
+ help: config.help(command, config),
1442
1460
  importMeta,
1443
1461
  flags: config.flags,
1444
- allowUnknownFlags: Boolean(allowUnknownFlags)
1462
+ allowUnknownFlags: Boolean(allowUnknownFlags),
1463
+ autoHelp: false // otherwise we can't exit(0)
1445
1464
  });
1465
+ if (cli.flags['help']) {
1466
+ cli.showHelp();
1467
+ }
1446
1468
  return cli;
1447
1469
  }
1470
+ function getAsciiHeader(command) {
1471
+ const cliVersion = // The '@rollup/plugin-replace' will replace "process.env['SOCKET_CLI_VERSION_HASH']".
1472
+ "0.14.47:e0c97e0:714b50c6:pub";
1473
+ const nodeVersion = process.version;
1474
+ // Get the last 5 characters of the API token before the trailing "_api".
1475
+ const lastFiveCharsOfApiToken = index.getSetting('apiToken')?.slice(-9, -4) || 'no';
1476
+ const relCwd = process.cwd().replace(new RegExp(`^${regexps.escapeRegExp(constants.homePath)}`, 'i'), '~/');
1477
+ const body = `
1478
+ _____ _ _ /---------------
1479
+ | __|___ ___| |_ ___| |_ | Socket.dev CLI ver ${cliVersion}
1480
+ |__ | . | _| '_| -_| _| | Node: ${nodeVersion}, API token set: ${lastFiveCharsOfApiToken}
1481
+ |_____|___|___|_,_|___|_|.dev | Command: \`${command}\`, cwd: ${relCwd}`.trimStart();
1482
+ return ` ${body}\n`;
1483
+ }
1448
1484
 
1449
1485
  // https://github.com/SocketDev/socket-python-cli/blob/6d4fc56faee68d3a4764f1f80f84710635bdaf05/socketsecurity/socketcli.py
1450
1486
 
@@ -1471,12 +1507,11 @@ const config$z = {
1471
1507
  description: 'After marker'
1472
1508
  }
1473
1509
  },
1474
- help: (parentName, {
1475
- commandName,
1510
+ help: (command, {
1476
1511
  flags
1477
1512
  }) => `
1478
1513
  Usage
1479
- $ ${parentName} ${commandName} [options]
1514
+ $ ${command} [options]
1480
1515
 
1481
1516
  Options
1482
1517
  ${getFlagListOutput(flags, 6)}
@@ -1498,12 +1533,13 @@ async function run$z(argv, importMeta, {
1498
1533
  });
1499
1534
  const githubEventBefore = String(cli.flags['githubEventBefore'] || '');
1500
1535
  const githubEventAfter = String(cli.flags['githubEventAfter'] || '');
1536
+ if (cli.flags['dryRun']) return console.log('[DryRun] Bailing now');
1501
1537
  await runAction(githubEventBefore, githubEventAfter);
1502
1538
  }
1503
1539
 
1504
1540
  const {
1505
1541
  API_V0_URL
1506
- } = constants.constants;
1542
+ } = constants;
1507
1543
  function handleUnsuccessfulApiResponse(_name, result, spinner) {
1508
1544
  // SocketSdkErrorType['error'] is not typed.
1509
1545
  const resultErrorMessage = result.error?.message;
@@ -1763,12 +1799,11 @@ const config$y = {
1763
1799
  description: 'Path to a local file to save the output'
1764
1800
  }
1765
1801
  },
1766
- help: (parentName, {
1767
- commandName,
1802
+ help: (command, {
1768
1803
  flags
1769
1804
  }) => `
1770
1805
  Usage
1771
- $ ${parentName} ${commandName} --scope=<scope> --time=<time filter>
1806
+ $ ${command} --scope=<scope> --time=<time filter>
1772
1807
 
1773
1808
  Default parameters are set to show the organization-level analytics over the
1774
1809
  last 7 days.
@@ -1777,9 +1812,9 @@ const config$y = {
1777
1812
  ${getFlagListOutput(flags, 6)}
1778
1813
 
1779
1814
  Examples
1780
- $ ${parentName} ${commandName} --scope=org --time=7
1781
- $ ${parentName} ${commandName} --scope=org --time=30
1782
- $ ${parentName} ${commandName} --scope=repo --repo=test-repo --time=30
1815
+ $ ${command} --scope=org --time=7
1816
+ $ ${command} --scope=org --time=30
1817
+ $ ${command} --scope=repo --repo=test-repo --time=30
1783
1818
  `
1784
1819
  };
1785
1820
  const cmdAnalytics = {
@@ -1805,14 +1840,17 @@ async function run$y(argv, importMeta, {
1805
1840
  const badTime = time !== 7 && time !== 30 && time !== 90;
1806
1841
  const badRepo = scope === 'repo' && !repo;
1807
1842
  if (badScope || badTime || badRepo) {
1843
+ // Use exit status of 2 to indicate incorrect usage, generally invalid
1844
+ // options or missing arguments.
1845
+ // https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
1846
+ process.exitCode = 2;
1808
1847
  console.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
1809
1848
  - Scope must be "repo" or "org" ${badScope ? colors.red('(bad!)') : colors.green('(ok)')}\n
1810
1849
  - The time filter must either be 7, 30 or 90 ${badTime ? colors.red('(bad!)') : colors.green('(ok)')}\n
1811
- - Repository name using --repo when scope is "repo" ${badRepo ? colors.red('(bad!)') : colors.green('(ok)')}\n
1812
- `);
1813
- cli.showHelp();
1850
+ - Repository name using --repo when scope is "repo" ${badRepo ? colors.red('(bad!)') : colors.green('(ok)')}\n`);
1814
1851
  return;
1815
1852
  }
1853
+ if (cli.flags['dryRun']) return console.log('[DryRun] Bailing now');
1816
1854
  const apiToken = index.getDefaultToken();
1817
1855
  if (!apiToken) {
1818
1856
  throw new index.AuthError('User must be authenticated to run this command. To log in, run the command `socket login` and enter your API token.');
@@ -1932,12 +1970,15 @@ async function run$x(argv, importMeta, {
1932
1970
  const type = String(cli.flags['type'] || '');
1933
1971
  const [orgSlug = ''] = cli.input;
1934
1972
  if (!orgSlug) {
1973
+ // Use exit status of 2 to indicate incorrect usage, generally invalid
1974
+ // options or missing arguments.
1975
+ // https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
1976
+ process.exitCode = 2;
1935
1977
  console.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
1936
- - Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n
1937
- `);
1938
- config$x.help(parentName, config$x);
1978
+ - Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n`);
1939
1979
  return;
1940
1980
  }
1981
+ if (cli.flags['dryRun']) return console.log('[DryRun] Bailing now');
1941
1982
  const apiToken = index.getDefaultToken();
1942
1983
  if (!apiToken) {
1943
1984
  throw new index.AuthError('User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.');
@@ -1965,7 +2006,7 @@ const {
1965
2006
  PNPM: PNPM$8,
1966
2007
  cdxgenBinPath,
1967
2008
  synpBinPath
1968
- } = constants.constants;
2009
+ } = constants;
1969
2010
  const nodejsPlatformTypes = new Set(['javascript', 'js', 'nodejs', NPM$e, PNPM$8, 'ts', 'tsx', 'typescript']);
1970
2011
  async function runCycloneDX(yargv) {
1971
2012
  let cleanupPackageLock = false;
@@ -2028,7 +2069,6 @@ function argvToArray(argv) {
2028
2069
  }
2029
2070
 
2030
2071
  // import { meowOrExit } from '../../utils/meow-with-subcommands'
2031
-
2032
2072
  // TODO: convert yargs to meow. Or convert all the other things to yargs.
2033
2073
  const toLower = arg => arg.toLowerCase();
2034
2074
  const arrayToLower = arg => arg.map(toLower);
@@ -2100,23 +2140,36 @@ const yargsConfig = {
2100
2140
  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']
2101
2141
  };
2102
2142
  const config$w = {
2143
+ commandName: 'cdxgen',
2103
2144
  description: 'Create an SBOM with CycloneDX generator (cdxgen)',
2104
- hidden: false};
2145
+ hidden: false,
2146
+ flags: {
2147
+ // TODO: convert from yargsConfig
2148
+ },
2149
+ help: (command, config) => `
2150
+ Usage
2151
+ $ ${command} [options]
2152
+
2153
+ Options
2154
+ ${getFlagListOutput(config.flags, 6)}
2155
+ `
2156
+ };
2105
2157
  const cmdCdxgen = {
2106
2158
  description: config$w.description,
2107
2159
  hidden: config$w.hidden,
2108
2160
  run: run$w
2109
2161
  };
2110
- async function run$w(argv, _importMeta, {
2111
- parentName: _parentName
2162
+ async function run$w(argv, importMeta, {
2163
+ parentName
2112
2164
  }) {
2113
- // const cli = meowOrExit({
2114
- // allowUnknownFlags: true,
2115
- // argv,
2116
- // config,
2117
- // importMeta,
2118
- // parentName,
2119
- // })
2165
+ const cli = meowOrExit({
2166
+ allowUnknownFlags: true,
2167
+ argv: argv.filter(s => s !== '--help' && s !== '-h'),
2168
+ // Don't let meow take over --help
2169
+ config: config$w,
2170
+ importMeta,
2171
+ parentName
2172
+ });
2120
2173
  //
2121
2174
  //
2122
2175
  // if (cli.input.length)
@@ -2137,13 +2190,17 @@ async function run$w(argv, _importMeta, {
2137
2190
  length: unknownLength
2138
2191
  } = unknown;
2139
2192
  if (unknownLength) {
2140
- process$1.exitCode = 1;
2193
+ // Use exit status of 2 to indicate incorrect usage, generally invalid
2194
+ // options or missing arguments.
2195
+ // https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
2196
+ process$1.exitCode = 2;
2141
2197
  console.error(`Unknown ${words.pluralize('argument', unknownLength)}: ${yargv._.join(', ')}`);
2142
2198
  return;
2143
2199
  }
2144
2200
  if (yargv.output === undefined) {
2145
2201
  yargv.output = 'socket-cdx.json';
2146
2202
  }
2203
+ if (cli.flags['dryRun']) return console.log('[DryRun] Bailing now');
2147
2204
  await runCycloneDX(yargv);
2148
2205
  }
2149
2206
 
@@ -2246,6 +2303,7 @@ async function run$v(argv, importMeta, {
2246
2303
  importMeta,
2247
2304
  parentName
2248
2305
  });
2306
+ if (cli.flags['dryRun']) return console.log('[DryRun] Bailing now');
2249
2307
 
2250
2308
  // TODO: markdown flag is ignored
2251
2309
  await findDependencies({
@@ -2357,14 +2415,17 @@ async function run$u(argv, importMeta, {
2357
2415
  const after = String(cli.flags['after'] || '');
2358
2416
  const [orgSlug = ''] = cli.input;
2359
2417
  if (!before || !after || cli.input.length < 1) {
2418
+ // Use exit status of 2 to indicate incorrect usage, generally invalid
2419
+ // options or missing arguments.
2420
+ // https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
2421
+ process.exitCode = 2;
2360
2422
  console.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
2361
2423
  - Specify a before and after full scan ID ${!before && !after ? colors.red('(missing before and after!)') : !before ? colors.red('(missing before!)') : !after ? colors.red('(missing after!)') : colors.green('(ok)')}\n
2362
2424
  - To get full scans IDs, you can run the command "socket scan list <your org slug>".
2363
- - Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n}
2364
- `);
2365
- config$u.help(parentName, config$u);
2425
+ - Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n`);
2366
2426
  return;
2367
2427
  }
2428
+ if (cli.flags['dryRun']) return console.log('[DryRun] Bailing now');
2368
2429
  const apiToken = index.getDefaultToken();
2369
2430
  if (!apiToken) {
2370
2431
  throw new index.AuthError('User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.');
@@ -2401,7 +2462,7 @@ const cmdDiffScan = {
2401
2462
 
2402
2463
  const {
2403
2464
  NPM: NPM$d
2404
- } = constants.constants;
2465
+ } = constants;
2405
2466
  function isTopLevel(tree, node) {
2406
2467
  return tree.children.get(node.name) === node;
2407
2468
  }
@@ -2507,7 +2568,9 @@ const config$t = {
2507
2568
  commandName: 'fix',
2508
2569
  description: 'Fix "fixable" Socket alerts',
2509
2570
  hidden: true,
2510
- flags: {},
2571
+ flags: {
2572
+ ...commonFlags
2573
+ },
2511
2574
  help: (command, config) => `
2512
2575
  Usage
2513
2576
  $ ${command}
@@ -2524,12 +2587,13 @@ const cmdFix = {
2524
2587
  async function run$t(argv, importMeta, {
2525
2588
  parentName
2526
2589
  }) {
2527
- meowOrExit({
2590
+ const cli = meowOrExit({
2528
2591
  argv,
2529
2592
  config: config$t,
2530
2593
  importMeta,
2531
2594
  parentName
2532
2595
  });
2596
+ if (cli.flags['dryRun']) return console.log('[DryRun] Bailing now');
2533
2597
  await runFix();
2534
2598
  }
2535
2599
 
@@ -2778,23 +2842,21 @@ async function run$s(argv, importMeta, {
2778
2842
  importMeta,
2779
2843
  parentName
2780
2844
  });
2781
- if (cli.input.length > 1) {
2782
- throw new index.InputError('Only one package lookup supported at once');
2783
- }
2784
- const {
2785
- 0: rawPkgName = ''
2786
- } = cli.input;
2787
- let showHelp = cli.flags['help'];
2788
- if (!rawPkgName) {
2789
- showHelp = true;
2790
- }
2791
- if (showHelp) {
2792
- cli.showHelp();
2845
+ const [rawPkgName = ''] = cli.input;
2846
+ if (!rawPkgName || cli.input.length > 1) {
2847
+ // Use exit status of 2 to indicate incorrect usage, generally invalid
2848
+ // options or missing arguments.
2849
+ // https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
2850
+ process.exitCode = 2;
2851
+ console.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
2852
+ - Expecting a package name ${!rawPkgName ? colors.red('(missing!)') : colors.green('(ok)')}\n
2853
+ - Can only accept one package at a time ${cli.input.length > 1 ? colors.red('(got ' + cli.input.length + '!)') : colors.green('(ok)')}\n`);
2793
2854
  return;
2794
2855
  }
2795
2856
  const versionSeparator = rawPkgName.lastIndexOf('@');
2796
2857
  const pkgName = versionSeparator < 1 ? rawPkgName : rawPkgName.slice(0, versionSeparator);
2797
2858
  const pkgVersion = versionSeparator < 1 ? 'latest' : rawPkgName.slice(versionSeparator + 1);
2859
+ if (cli.flags['dryRun']) return console.log('[DryRun] Bailing now');
2798
2860
  await getPackageInfo({
2799
2861
  commandName: `${parentName} ${config$s.commandName}`,
2800
2862
  includeAllIssues: Boolean(cli.flags['all']),
@@ -2817,7 +2879,7 @@ function applyLogin(apiToken, enforcedOrgs, apiBaseUrl, apiProxy) {
2817
2879
 
2818
2880
  const {
2819
2881
  SOCKET_PUBLIC_API_TOKEN
2820
- } = constants.constants;
2882
+ } = constants;
2821
2883
  async function attemptLogin(apiBaseUrl, apiProxy) {
2822
2884
  const apiToken = (await prompts.password({
2823
2885
  message: `Enter your ${terminalLink('Socket.dev API key', 'https://docs.socket.dev/docs/api-keys')} (leave blank for a public key)`
@@ -2883,6 +2945,7 @@ const config$r = {
2883
2945
  description: 'Socket API login',
2884
2946
  hidden: false,
2885
2947
  flags: {
2948
+ ...commonFlags,
2886
2949
  apiBaseUrl: {
2887
2950
  type: 'string',
2888
2951
  description: 'API server to connect to for login'
@@ -2920,11 +2983,12 @@ async function run$r(argv, importMeta, {
2920
2983
  importMeta,
2921
2984
  parentName
2922
2985
  });
2986
+ let apiBaseUrl = cli.flags['apiBaseUrl'];
2987
+ let apiProxy = cli.flags['apiProxy'];
2988
+ if (cli.flags['dryRun']) return console.log('[DryRun] Bailing now');
2923
2989
  if (!isInteractive()) {
2924
2990
  throw new index.InputError('Cannot prompt for credentials in a non-interactive shell');
2925
2991
  }
2926
- let apiBaseUrl = cli.flags['apiBaseUrl'];
2927
- let apiProxy = cli.flags['apiProxy'];
2928
2992
  await attemptLogin(apiBaseUrl, apiProxy);
2929
2993
  }
2930
2994
 
@@ -2948,7 +3012,9 @@ const config$q = {
2948
3012
  commandName: 'logout',
2949
3013
  description: 'Socket API logout',
2950
3014
  hidden: false,
2951
- flags: {},
3015
+ flags: {
3016
+ ...commonFlags
3017
+ },
2952
3018
  help: (command, _config) => `
2953
3019
  Usage
2954
3020
  $ ${command}
@@ -2964,12 +3030,13 @@ const cmdLogout = {
2964
3030
  async function run$q(argv, importMeta, {
2965
3031
  parentName
2966
3032
  }) {
2967
- meowOrExit({
3033
+ const cli = meowOrExit({
2968
3034
  argv,
2969
3035
  config: config$q,
2970
3036
  importMeta,
2971
3037
  parentName
2972
3038
  });
3039
+ if (cli.flags['dryRun']) return console.log('[DryRun] Bailing now');
2973
3040
  attemptLogout();
2974
3041
  }
2975
3042
 
@@ -2999,7 +3066,7 @@ async function convertGradleToMaven(target, bin, _out, verbose, gradleOpts) {
2999
3066
  // 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.
3000
3067
 
3001
3068
  // Note: init.gradle will be exported by .config/rollup.dist.config.mjs
3002
- const initLocation = path.join(constants.constants.rootDistPath, 'init.gradle');
3069
+ const initLocation = path.join(constants.rootDistPath, 'init.gradle');
3003
3070
  const commandArgs = ['--init-script', initLocation, ...gradleOpts, 'pom'];
3004
3071
  if (verbose) {
3005
3072
  console.log('\n[VERBOSE] Executing:', bin, commandArgs);
@@ -3146,13 +3213,11 @@ const cmdManifestGradle = {
3146
3213
  async function run$p(argv, importMeta, {
3147
3214
  parentName
3148
3215
  }) {
3149
- // note: meow will exit if it prints the --help screen
3150
- const cli = meow(config$p.help(parentName, config$p), {
3151
- flags: config$p.flags,
3152
- argv: argv.length === 0 ? ['--help'] : argv,
3153
- description: config$p.description,
3154
- allowUnknownFlags: false,
3155
- importMeta
3216
+ const cli = meowOrExit({
3217
+ argv,
3218
+ config: config$p,
3219
+ importMeta,
3220
+ parentName
3156
3221
  });
3157
3222
  const verbose = Boolean(cli.flags['verbose']);
3158
3223
  if (verbose) {
@@ -3163,15 +3228,18 @@ async function run$p(argv, importMeta, {
3163
3228
  console.groupEnd();
3164
3229
  }
3165
3230
  const target = cli.input[0];
3166
- if (!target) {
3167
- // will exit.
3168
- new spinner.Spinner().start('Parsing...').error(`Failure: Missing DIR argument. See \`${parentName} ${config$p.commandName} --help\` for details.`);
3169
- process.exit(1);
3170
- }
3171
- if (cli.input.length > 1) {
3172
- // will exit.
3173
- new spinner.Spinner().start('Parsing...').error(`Failure: Can only accept one FILE or DIR, received ${cli.input.length} (make sure to escape spaces!). See \`${parentName} ${config$p.commandName} --help\` for details.`);
3174
- process.exit(1);
3231
+
3232
+ // TODO: I'm not sure it's feasible to parse source file from stdin. We could try, store contents in a file in some folder, target that folder... what would the file name be?
3233
+
3234
+ if (!target || target === '-' || cli.input.length > 1) {
3235
+ // Use exit status of 2 to indicate incorrect usage, generally invalid
3236
+ // options or missing arguments.
3237
+ // https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
3238
+ process.exitCode = 2;
3239
+ console.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
3240
+ - The DIR arg is required ${!target ? colors.red('(missing!)') : target === '-' ? colors.red('(stdin is not supported)') : colors.green('(ok)')}\n
3241
+ - Can only accept one DIR (make sure to escape spaces!) ${cli.input.length > 1 ? colors.red(`(received ${cli.input.length}!)`) : colors.green('(ok)')}\n`);
3242
+ return;
3175
3243
  }
3176
3244
  let bin;
3177
3245
  if (cli.flags['bin']) {
@@ -3186,12 +3254,6 @@ async function run$p(argv, importMeta, {
3186
3254
  if (cli.flags['stdout']) {
3187
3255
  out = '-';
3188
3256
  }
3189
-
3190
- // TODO: I'm not sure it's feasible to parse source file from stdin. We could try, store contents in a file in some folder, target that folder... what would the file name be?
3191
- if (target === '-') {
3192
- new spinner.Spinner().start('Parsing...').error(`Failure: Currently source code from stdin is not supported. See \`${parentName} ${config$p.commandName} --help\` for details.`);
3193
- process.exit(1);
3194
- }
3195
3257
  if (verbose) {
3196
3258
  console.group();
3197
3259
  console.log('- target:', target);
@@ -3203,6 +3265,7 @@ async function run$p(argv, importMeta, {
3203
3265
  if (cli.flags['gradleOpts']) {
3204
3266
  gradleOpts = cli.flags['gradleOpts'].split(' ').map(s => s.trim()).filter(Boolean);
3205
3267
  }
3268
+ if (cli.flags['dryRun']) return console.log('[DryRun] Bailing now');
3206
3269
  await convertGradleToMaven(target, bin, out, verbose, gradleOpts);
3207
3270
  }
3208
3271
 
@@ -3299,7 +3362,7 @@ async function convertSbtToMaven(target, bin, out, verbose, sbtOpts) {
3299
3362
  }
3300
3363
 
3301
3364
  const config$o = {
3302
- commandName: 'kotlin',
3365
+ commandName: 'scala',
3303
3366
  description: "[beta] Generate a manifest file (`pom.xml`) from Scala's `build.sbt` file",
3304
3367
  hidden: false,
3305
3368
  flags: {
@@ -3376,13 +3439,11 @@ async function run$o(argv, importMeta, {
3376
3439
  parentName
3377
3440
  }) {
3378
3441
  // console.log('scala', argv, parentName)
3379
- // note: meow will exit if it prints the --help screen
3380
- const cli = meow(config$o.help(parentName, config$o), {
3381
- flags: config$o.flags,
3382
- argv: argv.length === 0 ? ['--help'] : argv,
3383
- description: config$o.description,
3384
- allowUnknownFlags: false,
3385
- importMeta
3442
+ const cli = meowOrExit({
3443
+ argv,
3444
+ config: config$o,
3445
+ importMeta,
3446
+ parentName
3386
3447
  });
3387
3448
  const verbose = Boolean(cli.flags['verbose']);
3388
3449
  if (verbose) {
@@ -3393,15 +3454,18 @@ async function run$o(argv, importMeta, {
3393
3454
  console.groupEnd();
3394
3455
  }
3395
3456
  const target = cli.input[0];
3396
- if (!target) {
3397
- // will exit.
3398
- new spinner.Spinner().start('Parsing...').error(`Failure: Missing FILE|DIR argument. See \`${parentName} ${config$o.commandName} --help\` for details.`);
3399
- process.exit(1);
3400
- }
3401
- if (cli.input.length > 1) {
3402
- // will exit.
3403
- new spinner.Spinner().start('Parsing...').error(`Failure: Can only accept one FILE or DIR, received ${cli.input.length} (make sure to escape spaces!). See \`${parentName} ${config$o.commandName} --help\` for details.`);
3404
- process.exit(1);
3457
+
3458
+ // TODO: I'm not sure it's feasible to parse source file from stdin. We could try, store contents in a file in some folder, target that folder... what would the file name be?
3459
+
3460
+ if (!target || target === '-' || cli.input.length > 1) {
3461
+ // Use exit status of 2 to indicate incorrect usage, generally invalid
3462
+ // options or missing arguments.
3463
+ // https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
3464
+ process.exitCode = 2;
3465
+ console.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
3466
+ - The DIR or FILE arg is required ${!target ? colors.red('(missing!)') : target === '-' ? colors.red('(stdin is not supported)') : colors.green('(ok)')}\n
3467
+ - Can only accept one DIR or FILE (make sure to escape spaces!) ${cli.input.length > 1 ? colors.red(`(received ${cli.input.length}!)`) : colors.green('(ok)')}\n`);
3468
+ return;
3405
3469
  }
3406
3470
  let bin = 'sbt';
3407
3471
  if (cli.flags['bin']) {
@@ -3421,16 +3485,11 @@ async function run$o(argv, importMeta, {
3421
3485
  console.log('- out:', out);
3422
3486
  console.groupEnd();
3423
3487
  }
3424
-
3425
- // TODO: we can make `-` (accept from stdin) work by storing it into /tmp
3426
- if (target === '-') {
3427
- new spinner.Spinner().start('Parsing...').error(`Failure: Currently source code from stdin is not supported. See \`${parentName} ${config$o.commandName} --help\` for details.`);
3428
- process.exit(1);
3429
- }
3430
3488
  let sbtOpts = [];
3431
3489
  if (cli.flags['sbtOpts']) {
3432
3490
  sbtOpts = cli.flags['sbtOpts'].split(' ').map(s => s.trim()).filter(Boolean);
3433
3491
  }
3492
+ if (cli.flags['dryRun']) return console.log('[DryRun] Bailing now');
3434
3493
  await convertSbtToMaven(target, bin, out, verbose, sbtOpts);
3435
3494
  }
3436
3495
 
@@ -3471,12 +3530,11 @@ const cmdManifestAuto = {
3471
3530
  async function run$n(argv, importMeta, {
3472
3531
  parentName
3473
3532
  }) {
3474
- const cli = meow(config$n.help(parentName, config$n), {
3533
+ const cli = meowOrExit({
3475
3534
  argv,
3476
- description: config$n.description,
3535
+ config: config$n,
3477
3536
  importMeta,
3478
- flags: config$n.flags,
3479
- allowUnknownFlags: false
3537
+ parentName
3480
3538
  });
3481
3539
  const verbose = !!cli.flags['verbose'];
3482
3540
  const cwd = cli.flags['cwd'] ?? process.cwd();
@@ -3499,6 +3557,7 @@ async function run$n(argv, importMeta, {
3499
3557
  subArgs.push('--cwd', cwd);
3500
3558
  }
3501
3559
  subArgs.push(dir);
3560
+ if (cli.flags['dryRun']) return console.log('[DryRun] Bailing now');
3502
3561
  await cmdManifestScala.run(subArgs, importMeta, {
3503
3562
  parentName
3504
3563
  });
@@ -3510,11 +3569,13 @@ async function run$n(argv, importMeta, {
3510
3569
  // This command takes the cwd as first arg.
3511
3570
  subArgs.push(cwd);
3512
3571
  }
3572
+ if (cli.flags['dryRun']) return console.log('[DryRun] Bailing now');
3513
3573
  await cmdManifestGradle.run(subArgs, importMeta, {
3514
3574
  parentName
3515
3575
  });
3516
3576
  return;
3517
3577
  }
3578
+
3518
3579
  // Show new help screen and exit.
3519
3580
  meow(`
3520
3581
  $ ${parentName} ${config$n.commandName}
@@ -3619,13 +3680,11 @@ const cmdManifestKotlin = {
3619
3680
  async function run$m(argv, importMeta, {
3620
3681
  parentName
3621
3682
  }) {
3622
- // note: meow will exit if it prints the --help screen
3623
- const cli = meow(config$m.help(parentName, config$m), {
3624
- flags: config$m.flags,
3625
- argv: argv.length === 0 ? ['--help'] : argv,
3626
- description: config$m.description,
3627
- allowUnknownFlags: false,
3628
- importMeta
3683
+ const cli = meowOrExit({
3684
+ argv,
3685
+ config: config$m,
3686
+ importMeta,
3687
+ parentName
3629
3688
  });
3630
3689
  const verbose = Boolean(cli.flags['verbose']);
3631
3690
  if (verbose) {
@@ -3636,15 +3695,18 @@ async function run$m(argv, importMeta, {
3636
3695
  console.groupEnd();
3637
3696
  }
3638
3697
  const target = cli.input[0];
3639
- if (!target) {
3640
- // will exit.
3641
- new spinner.Spinner().start('Parsing...').error(`Failure: Missing DIR argument. See \`${parentName} ${config$m.commandName} --help\` for details.`);
3642
- process.exit(1);
3643
- }
3644
- if (cli.input.length > 1) {
3645
- // will exit.
3646
- new spinner.Spinner().start('Parsing...').error(`Failure: Can only accept one FILE or DIR, received ${cli.input.length} (make sure to escape spaces!). See \`${parentName} ${config$m.commandName} --help\` for details.`);
3647
- process.exit(1);
3698
+
3699
+ // TODO: I'm not sure it's feasible to parse source file from stdin. We could try, store contents in a file in some folder, target that folder... what would the file name be?
3700
+
3701
+ if (!target || target === '-' || cli.input.length > 1) {
3702
+ // Use exit status of 2 to indicate incorrect usage, generally invalid
3703
+ // options or missing arguments.
3704
+ // https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
3705
+ process.exitCode = 2;
3706
+ console.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
3707
+ - The DIR arg is required ${!target ? colors.red('(missing!)') : target === '-' ? colors.red('(stdin is not supported)') : colors.green('(ok)')}\n
3708
+ - Can only accept one DIR (make sure to escape spaces!) ${cli.input.length > 1 ? colors.red(`(received ${cli.input.length}!)`) : colors.green('(ok)')}\n`);
3709
+ return;
3648
3710
  }
3649
3711
  let bin;
3650
3712
  if (cli.flags['bin']) {
@@ -3659,12 +3721,6 @@ async function run$m(argv, importMeta, {
3659
3721
  if (cli.flags['stdout']) {
3660
3722
  out = '-';
3661
3723
  }
3662
-
3663
- // TODO: I'm not sure it's feasible to parse source file from stdin. We could try, store contents in a file in some folder, target that folder... what would the file name be?
3664
- if (target === '-') {
3665
- new spinner.Spinner().start('Parsing...').error(`Failure: Currently source code from stdin is not supported. See \`${parentName} ${config$m.commandName} --help\` for details.`);
3666
- process.exit(1);
3667
- }
3668
3724
  if (verbose) {
3669
3725
  console.group();
3670
3726
  console.log('- target:', target);
@@ -3676,6 +3732,7 @@ async function run$m(argv, importMeta, {
3676
3732
  if (cli.flags['gradleOpts']) {
3677
3733
  gradleOpts = cli.flags['gradleOpts'].split(' ').map(s => s.trim()).filter(Boolean);
3678
3734
  }
3735
+ if (cli.flags['dryRun']) return console.log('[DryRun] Bailing now');
3679
3736
  await convertGradleToMaven(target, bin, out, verbose, gradleOpts);
3680
3737
  }
3681
3738
 
@@ -3718,16 +3775,16 @@ async function run$l(argv, importMeta, {
3718
3775
  const {
3719
3776
  NPM: NPM$b,
3720
3777
  SHADOW_BIN: SHADOW_BIN$1
3721
- } = constants.constants;
3778
+ } = constants;
3722
3779
  async function wrapNpm(argv) {
3723
3780
  // Lazily access constants.distPath.
3724
- const shadowBin = require(`${constants.constants.distPath}/${SHADOW_BIN$1}.js`);
3781
+ const shadowBin = require(`${constants.distPath}/${SHADOW_BIN$1}.js`);
3725
3782
  await shadowBin(NPM$b, argv);
3726
3783
  }
3727
3784
 
3728
3785
  const {
3729
3786
  NPM: NPM$a
3730
- } = constants.constants;
3787
+ } = constants;
3731
3788
  const config$k = {
3732
3789
  commandName: 'npm',
3733
3790
  description: `${NPM$a} wrapper functionality`,
@@ -3746,29 +3803,30 @@ const cmdNpm = {
3746
3803
  async function run$k(argv, importMeta, {
3747
3804
  parentName
3748
3805
  }) {
3749
- meowOrExit({
3806
+ const cli = meowOrExit({
3750
3807
  allowUnknownFlags: true,
3751
3808
  argv,
3752
3809
  config: config$k,
3753
3810
  importMeta,
3754
3811
  parentName
3755
3812
  });
3813
+ if (cli.flags['dryRun']) return console.log('[DryRun] Bailing now');
3756
3814
  await wrapNpm(argv);
3757
3815
  }
3758
3816
 
3759
3817
  const {
3760
3818
  NPX: NPX$2,
3761
3819
  SHADOW_BIN
3762
- } = constants.constants;
3820
+ } = constants;
3763
3821
  async function wrapNpx(argv) {
3764
3822
  // Lazily access constants.distPath.
3765
- const shadowBin = require(`${constants.constants.distPath}/${SHADOW_BIN}.js`);
3823
+ const shadowBin = require(`${constants.distPath}/${SHADOW_BIN}.js`);
3766
3824
  await shadowBin(NPX$2, argv);
3767
3825
  }
3768
3826
 
3769
3827
  const {
3770
3828
  NPX: NPX$1
3771
- } = constants.constants;
3829
+ } = constants;
3772
3830
  const config$j = {
3773
3831
  commandName: 'npx',
3774
3832
  description: `${NPX$1} wrapper functionality`,
@@ -3787,13 +3845,14 @@ const cmdNpx = {
3787
3845
  async function run$j(argv, importMeta, {
3788
3846
  parentName
3789
3847
  }) {
3790
- meowOrExit({
3848
+ const cli = meowOrExit({
3791
3849
  allowUnknownFlags: true,
3792
3850
  argv,
3793
3851
  config: config$j,
3794
3852
  importMeta,
3795
3853
  parentName
3796
3854
  });
3855
+ if (cli.flags['dryRun']) return console.log('[DryRun] Bailing now');
3797
3856
  await wrapNpx(argv);
3798
3857
  }
3799
3858
 
@@ -3801,7 +3860,9 @@ const config$i = {
3801
3860
  commandName: 'oops',
3802
3861
  description: 'Trigger an intentional error (for development)',
3803
3862
  hidden: true,
3804
- flags: {},
3863
+ flags: {
3864
+ ...commonFlags
3865
+ },
3805
3866
  help: (parentName, config) => `
3806
3867
  Usage
3807
3868
  $ ${parentName} ${config.commandName}
@@ -3817,12 +3878,13 @@ const cmdOops = {
3817
3878
  async function run$i(argv, importMeta, {
3818
3879
  parentName
3819
3880
  }) {
3820
- meow(config$i.help(parentName, config$i), {
3881
+ const cli = meowOrExit({
3821
3882
  argv,
3822
- description: config$i.description,
3883
+ config: config$i,
3823
3884
  importMeta,
3824
- flags: config$i.flags
3885
+ parentName
3825
3886
  });
3887
+ if (cli.flags['dryRun']) return console.log('[DryRun] Bailing now');
3826
3888
  throw new Error('This error was intentionally left blank');
3827
3889
  }
3828
3890
 
@@ -3833,7 +3895,7 @@ const {
3833
3895
  VLT: VLT$6,
3834
3896
  YARN_BERRY: YARN_BERRY$6,
3835
3897
  YARN_CLASSIC: YARN_CLASSIC$6
3836
- } = constants.constants;
3898
+ } = constants;
3837
3899
  function matchHumanStdout(stdout, name) {
3838
3900
  return stdout.includes(` ${name}@`);
3839
3901
  }
@@ -3861,7 +3923,7 @@ const {
3861
3923
  YARN,
3862
3924
  YARN_BERRY: YARN_BERRY$5,
3863
3925
  YARN_CLASSIC: YARN_CLASSIC$5
3864
- } = constants.constants;
3926
+ } = constants;
3865
3927
  const AGENTS = [BUN$5, NPM$8, PNPM$6, YARN_BERRY$5, YARN_CLASSIC$5, VLT$5];
3866
3928
  const binByAgent = {
3867
3929
  __proto__: null,
@@ -4003,7 +4065,7 @@ async function detect({
4003
4065
  };
4004
4066
  let lockSrc;
4005
4067
  // Lazily access constants.maintainedNodeVersions.
4006
- let minimumNodeVersion = constants.constants.maintainedNodeVersions.previous;
4068
+ let minimumNodeVersion = constants.maintainedNodeVersions.previous;
4007
4069
  if (pkgJson) {
4008
4070
  const browserField = pkgJson.browser;
4009
4071
  if (strings.isNonEmptyString(browserField) || objects.isObjectObject(browserField)) {
@@ -4031,7 +4093,7 @@ async function detect({
4031
4093
  }
4032
4094
  }
4033
4095
  // Lazily access constants.maintainedNodeVersions.
4034
- targets.node = constants.constants.maintainedNodeVersions.some(v => semver.satisfies(v, `>=${minimumNodeVersion}`));
4096
+ targets.node = constants.maintainedNodeVersions.some(v => semver.satisfies(v, `>=${minimumNodeVersion}`));
4035
4097
  lockSrc = typeof lockPath === 'string' ? await readLockFileByAgent[agent](lockPath, agentExecPath) : undefined;
4036
4098
  } else {
4037
4099
  lockBasename = undefined;
@@ -4058,7 +4120,7 @@ const {
4058
4120
  NPM: NPM$7,
4059
4121
  VLT: VLT$4,
4060
4122
  YARN_BERRY: YARN_BERRY$4
4061
- } = constants.constants;
4123
+ } = constants;
4062
4124
  const COMMAND_TITLE$2 = 'Socket Optimize';
4063
4125
  const manifestNpmOverrides = registry.getManifestData(NPM$7);
4064
4126
  async function detectAndValidatePackageManager(cwd, prod) {
@@ -4158,7 +4220,7 @@ const {
4158
4220
  VLT: VLT$3,
4159
4221
  YARN_BERRY: YARN_BERRY$3,
4160
4222
  YARN_CLASSIC: YARN_CLASSIC$4
4161
- } = constants.constants;
4223
+ } = constants;
4162
4224
  function getOverridesDataBun(pkgJson) {
4163
4225
  const overrides = pkgJson?.[RESOLUTIONS$1] ?? {};
4164
4226
  return {
@@ -4226,7 +4288,7 @@ const getOverridesDataByAgent = {
4226
4288
 
4227
4289
  const {
4228
4290
  PNPM: PNPM$4
4229
- } = constants.constants;
4291
+ } = constants;
4230
4292
  const PNPM_WORKSPACE = `${PNPM$4}-workspace`;
4231
4293
  async function getWorkspaceGlobs(agent, pkgPath, pkgJson) {
4232
4294
  let workspacePatterns;
@@ -4275,7 +4337,7 @@ const {
4275
4337
  VLT: VLT$2,
4276
4338
  YARN_BERRY: YARN_BERRY$2,
4277
4339
  YARN_CLASSIC: YARN_CLASSIC$3
4278
- } = constants.constants;
4340
+ } = constants;
4279
4341
  function lockIncludesNpm(lockSrc, name) {
4280
4342
  // Detects the package name in the following cases:
4281
4343
  // "name":
@@ -4332,7 +4394,7 @@ const {
4332
4394
  VLT: VLT$1,
4333
4395
  YARN_BERRY: YARN_BERRY$1,
4334
4396
  YARN_CLASSIC: YARN_CLASSIC$2
4335
- } = constants.constants;
4397
+ } = constants;
4336
4398
  function cleanupQueryStdout(stdout) {
4337
4399
  if (stdout === '') {
4338
4400
  return '';
@@ -4464,7 +4526,7 @@ const {
4464
4526
  VLT,
4465
4527
  YARN_BERRY,
4466
4528
  YARN_CLASSIC: YARN_CLASSIC$1
4467
- } = constants.constants;
4529
+ } = constants;
4468
4530
  const PNPM_FIELD_NAME = PNPM$1;
4469
4531
  const depFields = ['dependencies', 'devDependencies', 'peerDependencies', 'peerDependenciesMeta', 'optionalDependencies', 'bundleDependencies'];
4470
4532
  function getEntryIndexes(entries, keys) {
@@ -4576,7 +4638,7 @@ const {
4576
4638
  NPM: NPM$2,
4577
4639
  SOCKET_CLI_SAFE_WRAPPER,
4578
4640
  abortSignal: abortSignal$2
4579
- } = constants.constants;
4641
+ } = constants;
4580
4642
  const COMMAND_TITLE$1 = 'Socket Optimize';
4581
4643
  const NPM_OVERRIDE_PR_URL = 'https://github.com/npm/cli/pull/7025';
4582
4644
  async function updatePackageLockJson(lockName, agentExecPath, agent, spinner) {
@@ -4617,7 +4679,7 @@ const {
4617
4679
  NPM: NPM$1,
4618
4680
  PNPM,
4619
4681
  YARN_CLASSIC
4620
- } = constants.constants;
4682
+ } = constants;
4621
4683
  const COMMAND_TITLE = 'Socket Optimize';
4622
4684
  async function applyOptimization(cwd, pin, prod) {
4623
4685
  const pkgMgrData = await detectAndValidatePackageManager(cwd, prod);
@@ -4855,7 +4917,7 @@ async function addOverrides({
4855
4917
  }
4856
4918
 
4857
4919
  const config$h = {
4858
- commandName: 'create',
4920
+ commandName: 'optimize',
4859
4921
  description: 'Optimize dependencies with @socketregistry overrides',
4860
4922
  hidden: false,
4861
4923
  flags: {
@@ -4898,6 +4960,7 @@ async function run$h(argv, importMeta, {
4898
4960
  parentName
4899
4961
  });
4900
4962
  const cwd = process$1.cwd();
4963
+ if (cli.flags['dryRun']) return console.log('[DryRun] Bailing now');
4901
4964
  await applyOptimization(cwd, Boolean(cli.flags['pin']), Boolean(cli.flags['prod']));
4902
4965
  }
4903
4966
 
@@ -4944,18 +5007,19 @@ const cmdOrganizations = {
4944
5007
  async function run$g(argv, importMeta, {
4945
5008
  parentName
4946
5009
  }) {
4947
- meowOrExit({
5010
+ const cli = meowOrExit({
4948
5011
  argv,
4949
5012
  config: config$g,
4950
5013
  importMeta,
4951
5014
  parentName
4952
5015
  });
5016
+ if (cli.flags['dryRun']) return console.log('[DryRun] Bailing now');
4953
5017
  await getOrganizations();
4954
5018
  }
4955
5019
 
4956
5020
  const {
4957
5021
  abortSignal: abortSignal$1
4958
- } = constants.constants;
5022
+ } = constants;
4959
5023
  async function runRawNpm(argv) {
4960
5024
  const spawnPromise = spawn(npmPaths.getNpmBinPath(), argv.slice(0), {
4961
5025
  signal: abortSignal$1,
@@ -4977,7 +5041,7 @@ async function runRawNpm(argv) {
4977
5041
 
4978
5042
  const {
4979
5043
  NPM
4980
- } = constants.constants;
5044
+ } = constants;
4981
5045
  const config$f = {
4982
5046
  commandName: 'raw-npm',
4983
5047
  description: `Temporarily disable the Socket ${NPM} wrapper`,
@@ -5002,19 +5066,20 @@ const cmdRawNpm = {
5002
5066
  async function run$f(argv, importMeta, {
5003
5067
  parentName
5004
5068
  }) {
5005
- meowOrExit({
5069
+ const cli = meowOrExit({
5006
5070
  allowUnknownFlags: true,
5007
5071
  argv,
5008
5072
  config: config$f,
5009
5073
  importMeta,
5010
5074
  parentName
5011
5075
  });
5076
+ if (cli.flags['dryRun']) return console.log('[DryRun] Bailing now');
5012
5077
  await runRawNpm(argv);
5013
5078
  }
5014
5079
 
5015
5080
  const {
5016
5081
  abortSignal
5017
- } = constants.constants;
5082
+ } = constants;
5018
5083
  async function runRawNpx(argv) {
5019
5084
  const spawnPromise = spawn(npmPaths.getNpxBinPath(), argv, {
5020
5085
  signal: abortSignal,
@@ -5036,7 +5101,7 @@ async function runRawNpx(argv) {
5036
5101
 
5037
5102
  const {
5038
5103
  NPX
5039
- } = constants.constants;
5104
+ } = constants;
5040
5105
  const config$e = {
5041
5106
  commandName: 'raw-npx',
5042
5107
  description: `Temporarily disable the Socket ${NPX} wrapper`,
@@ -5061,13 +5126,14 @@ const cmdRawNpx = {
5061
5126
  async function run$e(argv, importMeta, {
5062
5127
  parentName
5063
5128
  }) {
5064
- meowOrExit({
5129
+ const cli = meowOrExit({
5065
5130
  allowUnknownFlags: true,
5066
5131
  argv,
5067
5132
  config: config$e,
5068
5133
  importMeta,
5069
5134
  parentName
5070
5135
  });
5136
+ if (cli.flags['dryRun']) return console.log('[DryRun] Bailing now');
5071
5137
  await runRawNpx(argv);
5072
5138
  }
5073
5139
 
@@ -5263,15 +5329,15 @@ async function run$d(argv, importMeta, {
5263
5329
  const strict = Boolean(cli.flags['strict']);
5264
5330
  const includeAllIssues = Boolean(cli.flags['all']);
5265
5331
  const view = Boolean(cli.flags['view']);
5332
+
5333
+ // Note exiting earlier to skirt a hidden auth requirement
5334
+ if (cli.flags['dryRun']) return console.log('[DryRun] Bailing now');
5266
5335
  const socketConfig = await getSocketConfig(absoluteConfigPath);
5267
5336
  const result = await createReport(socketConfig, cli.input, {
5268
5337
  cwd,
5269
5338
  dryRun
5270
5339
  });
5271
5340
  const commandName = `${parentName} ${config$d.commandName}`;
5272
- if (dryRun && view) {
5273
- console.log('[dryrun] Ignoring view flag since no report was actually generated');
5274
- }
5275
5341
  if (result?.success) {
5276
5342
  if (view) {
5277
5343
  const reportId = result.data.id;
@@ -5332,13 +5398,16 @@ async function run$c(argv, importMeta, {
5332
5398
 
5333
5399
  // Validate the input.
5334
5400
  if (extraInput.length || !reportId) {
5401
+ // Use exit status of 2 to indicate incorrect usage, generally invalid
5402
+ // options or missing arguments.
5403
+ // https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
5404
+ process.exitCode = 2;
5335
5405
  console.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
5336
5406
  - Need at least one report ID ${!reportId ? colors.red('(missing!)') : colors.green('(ok)')}\n
5337
- - Can only handle a single report ID ${extraInput.length < 2 ? colors.red(`(received ${extraInput.length}!)`) : colors.green('(ok)')}\n
5338
- `);
5339
- cli.showHelp();
5407
+ - Can only handle a single report ID ${extraInput.length < 2 ? colors.red(`(received ${extraInput.length}!)`) : colors.green('(ok)')}\n`);
5340
5408
  return;
5341
5409
  }
5410
+ if (cli.flags['dryRun']) return console.log('[DryRun] Bailing now');
5342
5411
  await viewReport(reportId, {
5343
5412
  all: Boolean(cli.flags['all']),
5344
5413
  commandName: `${parentName} ${config$c.commandName}`,
@@ -5465,13 +5534,16 @@ async function run$b(argv, importMeta, {
5465
5534
  const repoName = cli.flags['repoName'];
5466
5535
  const [orgSlug = ''] = cli.input;
5467
5536
  if (!repoName || typeof repoName !== 'string' || !orgSlug) {
5537
+ // Use exit status of 2 to indicate incorrect usage, generally invalid
5538
+ // options or missing arguments.
5539
+ // https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
5540
+ process.exitCode = 2;
5468
5541
  console.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
5469
5542
  - Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n
5470
- - Repository name using --repoName ${!repoName ? colors.red('(missing!)') : typeof repoName !== 'string' ? colors.red('(invalid!)') : colors.green('(ok)')}\n
5471
- `);
5472
- cli.showHelp();
5543
+ - Repository name using --repoName ${!repoName ? colors.red('(missing!)') : typeof repoName !== 'string' ? colors.red('(invalid!)') : colors.green('(ok)')}\n`);
5473
5544
  return;
5474
5545
  }
5546
+ if (cli.flags['dryRun']) return console.log('[DryRun] Bailing now');
5475
5547
  const apiToken = index.getDefaultToken();
5476
5548
  if (!apiToken) {
5477
5549
  throw new index.AuthError('User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.');
@@ -5504,19 +5576,24 @@ async function deleteRepo(orgSlug, repoName, apiToken) {
5504
5576
  }
5505
5577
 
5506
5578
  const config$a = {
5507
- commandName: 'delete',
5579
+ commandName: 'del',
5508
5580
  description: 'Delete a repository in an organization',
5509
5581
  hidden: false,
5510
- flags: {},
5511
- help: (command, _config) => `
5582
+ flags: {
5583
+ ...commonFlags
5584
+ },
5585
+ help: (command, config) => `
5512
5586
  Usage
5513
5587
  $ ${command} <org slug> <repo slug>
5514
5588
 
5589
+ Options
5590
+ ${getFlagListOutput(config.flags, 6)}
5591
+
5515
5592
  Examples
5516
5593
  $ ${command} FakeOrg test-repo
5517
5594
  `
5518
5595
  };
5519
- const cmdReposDelete = {
5596
+ const cmdReposDel = {
5520
5597
  description: config$a.description,
5521
5598
  hidden: config$a.hidden,
5522
5599
  run: run$a
@@ -5532,14 +5609,17 @@ async function run$a(argv, importMeta, {
5532
5609
  });
5533
5610
  const [orgSlug = '', repoName = ''] = cli.input;
5534
5611
  if (!orgSlug || !repoName) {
5612
+ // Use exit status of 2 to indicate incorrect usage, generally invalid
5613
+ // options or missing arguments.
5614
+ // https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
5615
+ process.exitCode = 2;
5535
5616
  console.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
5536
5617
  - Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n
5537
5618
  - Repository name as the second argument ${!repoName ? colors.red('(missing!)') : typeof repoName !== 'string' ? colors.red('(invalid!)') : colors.green('(ok)')}\n
5538
- - At least one TARGET (e.g. \`.\` or \`./package.json\`
5539
- `);
5540
- cli.showHelp();
5619
+ - At least one TARGET (e.g. \`.\` or \`./package.json\`\n`);
5541
5620
  return;
5542
5621
  }
5622
+ if (cli.flags['dryRun']) return console.log('[DryRun] Bailing now');
5543
5623
  const apiToken = index.getDefaultToken();
5544
5624
  if (!apiToken) {
5545
5625
  throw new index.AuthError('User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.');
@@ -5655,13 +5735,16 @@ async function run$9(argv, importMeta, {
5655
5735
  });
5656
5736
  const [orgSlug = ''] = cli.input;
5657
5737
  if (!orgSlug) {
5738
+ // Use exit status of 2 to indicate incorrect usage, generally invalid
5739
+ // options or missing arguments.
5740
+ // https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
5741
+ process.exitCode = 2;
5658
5742
  console.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
5659
5743
  - Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n
5660
- - At least one TARGET (e.g. \`.\` or \`./package.json\`
5661
- `);
5662
- cli.showHelp();
5744
+ - At least one TARGET (e.g. \`.\` or \`./package.json\`\n`);
5663
5745
  return;
5664
5746
  }
5747
+ if (cli.flags['dryRun']) return console.log('[DryRun] Bailing now');
5665
5748
  const apiToken = index.getDefaultToken();
5666
5749
  if (!apiToken) {
5667
5750
  throw new index.AuthError('User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.');
@@ -5712,7 +5795,7 @@ async function updateRepo({
5712
5795
  }
5713
5796
 
5714
5797
  const config$8 = {
5715
- commandName: 'create',
5798
+ commandName: 'update',
5716
5799
  description: 'Update a repository in an organization',
5717
5800
  hidden: false,
5718
5801
  flags: {
@@ -5777,14 +5860,17 @@ async function run$8(argv, importMeta, {
5777
5860
  const repoName = cli.flags['repoName'];
5778
5861
  const [orgSlug = ''] = cli.input;
5779
5862
  if (!repoName || typeof repoName !== 'string' || !orgSlug) {
5863
+ // Use exit status of 2 to indicate incorrect usage, generally invalid
5864
+ // options or missing arguments.
5865
+ // https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
5866
+ process.exitCode = 2;
5780
5867
  console.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
5781
5868
  - Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n
5782
5869
  - Repository name using --repoName ${!repoName ? colors.red('(missing!)') : typeof repoName !== 'string' ? colors.red('(invalid!)') : colors.green('(ok)')}\n
5783
- - At least one TARGET (e.g. \`.\` or \`./package.json\`
5784
- `);
5785
- cli.showHelp();
5870
+ - At least one TARGET (e.g. \`.\` or \`./package.json\`\n`);
5786
5871
  return;
5787
5872
  }
5873
+ if (cli.flags['dryRun']) return console.log('[DryRun] Bailing now');
5788
5874
  const apiToken = index.getDefaultToken();
5789
5875
  if (!apiToken) {
5790
5876
  throw new index.AuthError('User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.');
@@ -5877,13 +5963,16 @@ async function run$7(argv, importMeta, {
5877
5963
  const repoName = cli.flags['repoName'];
5878
5964
  const [orgSlug = ''] = cli.input;
5879
5965
  if (!repoName || typeof repoName !== 'string' || !orgSlug) {
5966
+ // Use exit status of 2 to indicate incorrect usage, generally invalid
5967
+ // options or missing arguments.
5968
+ // https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
5969
+ process.exitCode = 2;
5880
5970
  console.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
5881
5971
  - Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n
5882
- - Repository name using --repoName ${!repoName ? colors.red('(missing!)') : typeof repoName !== 'string' ? colors.red('(invalid!)') : colors.green('(ok)')}\n
5883
- `);
5884
- cli.showHelp();
5972
+ - Repository name using --repoName ${!repoName ? colors.red('(missing!)') : typeof repoName !== 'string' ? colors.red('(invalid!)') : colors.green('(ok)')}\n`);
5885
5973
  return;
5886
5974
  }
5975
+ if (cli.flags['dryRun']) return console.log('[DryRun] Bailing now');
5887
5976
  const apiToken = index.getDefaultToken();
5888
5977
  if (!apiToken) {
5889
5978
  throw new index.AuthError('User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.');
@@ -5898,16 +5987,16 @@ const cmdRepos = {
5898
5987
  parentName
5899
5988
  }) {
5900
5989
  await meowWithSubcommands({
5901
- cmdReposCreate,
5902
- cmdReposView,
5903
- cmdReposList,
5904
- cmdReposDelete,
5905
- cmdReposUpdate
5990
+ create: cmdReposCreate,
5991
+ view: cmdReposView,
5992
+ list: cmdReposList,
5993
+ del: cmdReposDel,
5994
+ update: cmdReposUpdate
5906
5995
  }, {
5907
5996
  argv,
5908
5997
  description: description$1,
5909
5998
  importMeta,
5910
- name: `${parentName} repo`
5999
+ name: `${parentName} repos`
5911
6000
  });
5912
6001
  }
5913
6002
  };
@@ -5991,6 +6080,10 @@ const config$6 = {
5991
6080
  type: 'string',
5992
6081
  description: 'working directory, defaults to process.cwd()'
5993
6082
  },
6083
+ dryRun: {
6084
+ type: 'boolean',
6085
+ description: 'run input validation part of command without any concrete side effects'
6086
+ },
5994
6087
  pullRequest: {
5995
6088
  type: 'number',
5996
6089
  shortFlag: 'pr',
@@ -6053,6 +6146,9 @@ async function run$6(argv, importMeta, {
6053
6146
  });
6054
6147
  const [orgSlug = '', ...targets] = cli.input;
6055
6148
  const cwd = cli.flags['cwd'] && cli.flags['cwd'] !== 'process.cwd()' ? String(cli.flags['cwd']) : process$1.cwd();
6149
+
6150
+ // Note exiting earlier to skirt a hidden auth requirement
6151
+ if (cli.flags['dryRun']) return console.log('[DryRun] Bailing now');
6056
6152
  const socketSdk = await index.setupSdk();
6057
6153
  const supportedFiles = await socketSdk.getReportSupportedFiles().then(res => {
6058
6154
  if (!res.success) handleUnsuccessfulApiResponse('getReportSupportedFiles', res, new spinner.Spinner());
@@ -6069,12 +6165,15 @@ async function run$6(argv, importMeta, {
6069
6165
  repo: repoName
6070
6166
  } = cli.flags;
6071
6167
  if (!orgSlug || !repoName || !branchName || !packagePaths.length) {
6168
+ // Use exit status of 2 to indicate incorrect usage, generally invalid
6169
+ // options or missing arguments.
6170
+ // https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
6171
+ process$1.exitCode = 2;
6072
6172
  console.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
6073
6173
  - Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n
6074
6174
  - Repository name using --repo ${!repoName ? colors.red('(missing!)') : colors.green('(ok)')}\n
6075
6175
  - Branch name using --branch ${!branchName ? colors.red('(missing!)') : colors.green('(ok)')}\n
6076
- - At least one TARGET (e.g. \`.\` or \`./package.json\`) ${!packagePaths.length ? colors.red(targets.length > 0 ? '(TARGET' + (targets.length ? 's' : '') + ' contained no matching/supported files!)' : '(missing)') : colors.green('(ok)')}`);
6077
- config$6.help(parentName, config$6);
6176
+ - At least one TARGET (e.g. \`.\` or \`./package.json\`) ${!packagePaths.length ? colors.red(targets.length > 0 ? '(TARGET' + (targets.length ? 's' : '') + ' contained no matching/supported files!)' : '(missing)') : colors.green('(ok)')}\n`);
6078
6177
  return;
6079
6178
  }
6080
6179
  const apiToken = index.getDefaultToken();
@@ -6131,7 +6230,7 @@ const config$5 = {
6131
6230
  $ ${command} FakeOrg 000aaaa1-0000-0a0a-00a0-00a0000000a0
6132
6231
  `
6133
6232
  };
6134
- const cmdScanDelete = {
6233
+ const cmdScanDel = {
6135
6234
  description: config$5.description,
6136
6235
  hidden: config$5.hidden,
6137
6236
  run: run$5
@@ -6139,21 +6238,24 @@ const cmdScanDelete = {
6139
6238
  async function run$5(argv, importMeta, {
6140
6239
  parentName
6141
6240
  }) {
6142
- const cli = meow(config$5.help(parentName, config$5), {
6241
+ const cli = meowOrExit({
6143
6242
  argv,
6144
- description: config$5.description,
6243
+ config: config$5,
6145
6244
  importMeta,
6146
- flags: config$5.flags
6245
+ parentName
6147
6246
  });
6148
6247
  const [orgSlug = '', fullScanId = ''] = cli.input;
6149
6248
  if (!orgSlug || !fullScanId) {
6249
+ // Use exit status of 2 to indicate incorrect usage, generally invalid
6250
+ // options or missing arguments.
6251
+ // https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
6252
+ process.exitCode = 2;
6150
6253
  console.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
6151
6254
  - Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n
6152
- - Full Scan ID to delete as second argument ${!fullScanId ? colors.red('(missing!)') : colors.green('(ok)')}
6153
- `);
6154
- config$5.help(parentName, config$5);
6255
+ - Full Scan ID to delete as second argument ${!fullScanId ? colors.red('(missing!)') : colors.green('(ok)')}\n`);
6155
6256
  return;
6156
6257
  }
6258
+ if (cli.flags['dryRun']) return console.log('[DryRun] Bailing now');
6157
6259
  const apiToken = index.getDefaultToken();
6158
6260
  if (!apiToken) {
6159
6261
  throw new index.AuthError('User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.');
@@ -6267,19 +6369,23 @@ const cmdScanList = {
6267
6369
  async function run$4(argv, importMeta, {
6268
6370
  parentName
6269
6371
  }) {
6270
- const cli = meow(config$4.help(parentName, config$4), {
6372
+ const cli = meowOrExit({
6271
6373
  argv,
6272
- description: config$4.description,
6374
+ config: config$4,
6273
6375
  importMeta,
6274
- flags: config$4.flags
6376
+ parentName
6275
6377
  });
6276
6378
  const orgSlug = cli.input[0];
6277
6379
  if (!orgSlug) {
6380
+ // Use exit status of 2 to indicate incorrect usage, generally invalid
6381
+ // options or missing arguments.
6382
+ // https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
6383
+ process.exitCode = 2;
6278
6384
  console.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
6279
- - Org name as the argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}`);
6280
- config$4.help(parentName, config$4);
6385
+ - Org name as the argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n`);
6281
6386
  return;
6282
6387
  }
6388
+ if (cli.flags['dryRun']) return console.log('[DryRun] Bailing now');
6283
6389
  const apiToken = index.getDefaultToken();
6284
6390
  if (!apiToken) {
6285
6391
  throw new index.AuthError('User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.');
@@ -6341,21 +6447,24 @@ const cmdScanMetadata = {
6341
6447
  async function run$3(argv, importMeta, {
6342
6448
  parentName
6343
6449
  }) {
6344
- const cli = meow(config$3.help(parentName, config$3), {
6450
+ const cli = meowOrExit({
6345
6451
  argv,
6346
- description: config$3.description,
6452
+ config: config$3,
6347
6453
  importMeta,
6348
- flags: config$3.flags
6454
+ parentName
6349
6455
  });
6350
6456
  const [orgSlug = '', fullScanId = ''] = cli.input;
6351
6457
  if (!orgSlug || !fullScanId) {
6458
+ // Use exit status of 2 to indicate incorrect usage, generally invalid
6459
+ // options or missing arguments.
6460
+ // https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
6461
+ process.exitCode = 2;
6352
6462
  console.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
6353
6463
  - Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n
6354
- - Full Scan ID to inspect as second argument ${!fullScanId ? colors.red('(missing!)') : colors.green('(ok)')}
6355
- `);
6356
- config$3.help(parentName, config$3);
6464
+ - Full Scan ID to inspect as second argument ${!fullScanId ? colors.red('(missing!)') : colors.green('(ok)')}\n`);
6357
6465
  return;
6358
6466
  }
6467
+ if (cli.flags['dryRun']) return console.log('[DryRun] Bailing now');
6359
6468
  const apiToken = index.getDefaultToken();
6360
6469
  if (!apiToken) {
6361
6470
  throw new index.AuthError('User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.');
@@ -6406,21 +6515,24 @@ const cmdScanStream = {
6406
6515
  async function run$2(argv, importMeta, {
6407
6516
  parentName
6408
6517
  }) {
6409
- const cli = meow(config$2.help(parentName, config$2), {
6518
+ const cli = meowOrExit({
6410
6519
  argv,
6411
- description: config$2.description,
6520
+ config: config$2,
6412
6521
  importMeta,
6413
- flags: config$2.flags
6522
+ parentName
6414
6523
  });
6415
6524
  const [orgSlug = '', fullScanId = '', file = '-'] = cli.input;
6416
6525
  if (!orgSlug || !fullScanId) {
6526
+ // Use exit status of 2 to indicate incorrect usage, generally invalid
6527
+ // options or missing arguments.
6528
+ // https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
6529
+ process.exitCode = 2;
6417
6530
  console.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
6418
6531
  - Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n
6419
- - Full Scan ID to fetch as second argument ${!fullScanId ? colors.red('(missing!)') : colors.green('(ok)')}
6420
- `);
6421
- config$2.help(parentName, config$2);
6532
+ - Full Scan ID to fetch as second argument ${!fullScanId ? colors.red('(missing!)') : colors.green('(ok)')}\n`);
6422
6533
  return;
6423
6534
  }
6535
+ if (cli.flags['dryRun']) return console.log('[DryRun] Bailing now');
6424
6536
  const apiToken = index.getDefaultToken();
6425
6537
  if (!apiToken) {
6426
6538
  throw new index.AuthError('User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.');
@@ -6438,7 +6550,7 @@ const cmdScan = {
6438
6550
  create: cmdScanCreate,
6439
6551
  stream: cmdScanStream,
6440
6552
  list: cmdScanList,
6441
- del: cmdScanDelete,
6553
+ del: cmdScanDel,
6442
6554
  metadata: cmdScanMetadata
6443
6555
  }, {
6444
6556
  argv,
@@ -6583,6 +6695,7 @@ async function run$1(argv, importMeta, {
6583
6695
  importMeta,
6584
6696
  parentName
6585
6697
  });
6698
+ if (cli.flags['dryRun']) return console.log('[DryRun] Bailing now');
6586
6699
  const apiToken = index.getDefaultToken();
6587
6700
  if (!apiToken) {
6588
6701
  throw new index.AuthError('User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.');
@@ -6621,11 +6734,13 @@ function checkSocketWrapperSetup(file) {
6621
6734
  return false;
6622
6735
  }
6623
6736
 
6624
- const HOME_DIR$1 = os.homedir();
6625
- const BASH_FILE$1 = `${HOME_DIR$1}/.bashrc`;
6626
- const ZSH_BASH_FILE$1 = `${HOME_DIR$1}/.zshrc`;
6627
6737
  function postinstallWrapper() {
6628
- const socketWrapperEnabled = fs.existsSync(BASH_FILE$1) && checkSocketWrapperSetup(BASH_FILE$1) || fs.existsSync(ZSH_BASH_FILE$1) && checkSocketWrapperSetup(ZSH_BASH_FILE$1);
6738
+ // Lazily access constants.bashRcPath and constants.zshRcPath.
6739
+ const {
6740
+ bashRcPath,
6741
+ zshRcPath
6742
+ } = constants;
6743
+ const socketWrapperEnabled = fs.existsSync(bashRcPath) && checkSocketWrapperSetup(bashRcPath) || fs.existsSync(zshRcPath) && checkSocketWrapperSetup(zshRcPath);
6629
6744
  if (!socketWrapperEnabled) {
6630
6745
  installSafeNpm(`The Socket CLI is now successfully installed! 🎉
6631
6746
 
@@ -6651,12 +6766,17 @@ function installSafeNpm(query) {
6651
6766
  function askQuestion(rl, query) {
6652
6767
  rl.question(query, ans => {
6653
6768
  if (ans.toLowerCase() === 'y') {
6769
+ // Lazily access constants.bashRcPath and constants.zshRcPath.
6770
+ const {
6771
+ bashRcPath,
6772
+ zshRcPath
6773
+ } = constants;
6654
6774
  try {
6655
- if (fs.existsSync(BASH_FILE$1)) {
6656
- addSocketWrapper(BASH_FILE$1);
6775
+ if (fs.existsSync(bashRcPath)) {
6776
+ addSocketWrapper(bashRcPath);
6657
6777
  }
6658
- if (fs.existsSync(ZSH_BASH_FILE$1)) {
6659
- addSocketWrapper(ZSH_BASH_FILE$1);
6778
+ if (fs.existsSync(zshRcPath)) {
6779
+ addSocketWrapper(zshRcPath);
6660
6780
  }
6661
6781
  } catch (e) {
6662
6782
  throw new Error(`There was an issue setting up the alias: ${e}`);
@@ -6691,14 +6811,12 @@ function removeSocketWrapper(file) {
6691
6811
  });
6692
6812
  }
6693
6813
 
6694
- const HOME_DIR = os.homedir();
6695
- const BASH_FILE = `${HOME_DIR}/.bashrc`;
6696
- const ZSH_BASH_FILE = `${HOME_DIR}/.zshrc`;
6697
6814
  const config = {
6698
6815
  commandName: 'wrapper',
6699
6816
  description: 'Enable or disable the Socket npm/npx wrapper',
6700
6817
  hidden: false,
6701
6818
  flags: {
6819
+ ...commonFlags,
6702
6820
  enable: {
6703
6821
  type: 'boolean',
6704
6822
  default: false,
@@ -6742,31 +6860,42 @@ async function run(argv, importMeta, {
6742
6860
  parentName
6743
6861
  });
6744
6862
  const {
6745
- disable,
6746
6863
  enable
6747
6864
  } = cli.flags;
6748
- if (!enable && !disable) {
6749
- cli.showHelp();
6865
+ if (!enable && !cli.flags['disable']) {
6866
+ // Use exit status of 2 to indicate incorrect usage, generally invalid
6867
+ // options or missing arguments.
6868
+ // https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
6869
+ process.exitCode = 2;
6870
+ console.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required flags:\n
6871
+ - Must use --enabled or --disabled\n`);
6750
6872
  return;
6751
6873
  }
6874
+ if (cli.flags['dryRun']) {
6875
+ return console.log('[DryRun] Bailing now');
6876
+ }
6877
+
6878
+ // Lazily access constants.bashRcPath and constants.zshRcPath.
6879
+ const {
6880
+ bashRcPath,
6881
+ zshRcPath
6882
+ } = constants;
6752
6883
  if (enable) {
6753
- if (fs.existsSync(BASH_FILE)) {
6754
- const socketWrapperEnabled = checkSocketWrapperSetup(BASH_FILE);
6755
- !socketWrapperEnabled && addSocketWrapper(BASH_FILE);
6884
+ if (fs.existsSync(bashRcPath) && !checkSocketWrapperSetup(bashRcPath)) {
6885
+ addSocketWrapper(bashRcPath);
6756
6886
  }
6757
- if (fs.existsSync(ZSH_BASH_FILE)) {
6758
- const socketWrapperEnabled = checkSocketWrapperSetup(ZSH_BASH_FILE);
6759
- !socketWrapperEnabled && addSocketWrapper(ZSH_BASH_FILE);
6887
+ if (fs.existsSync(zshRcPath) && !checkSocketWrapperSetup(zshRcPath)) {
6888
+ addSocketWrapper(zshRcPath);
6760
6889
  }
6761
6890
  } else {
6762
- if (fs.existsSync(BASH_FILE)) {
6763
- removeSocketWrapper(BASH_FILE);
6891
+ if (fs.existsSync(bashRcPath)) {
6892
+ removeSocketWrapper(bashRcPath);
6764
6893
  }
6765
- if (fs.existsSync(ZSH_BASH_FILE)) {
6766
- removeSocketWrapper(ZSH_BASH_FILE);
6894
+ if (fs.existsSync(zshRcPath)) {
6895
+ removeSocketWrapper(zshRcPath);
6767
6896
  }
6768
6897
  }
6769
- if (!fs.existsSync(BASH_FILE) && !fs.existsSync(ZSH_BASH_FILE)) {
6898
+ if (!fs.existsSync(bashRcPath) && !fs.existsSync(zshRcPath)) {
6770
6899
  console.error('There was an issue setting up the alias in your bash profile');
6771
6900
  }
6772
6901
  }
@@ -6774,7 +6903,7 @@ async function run(argv, importMeta, {
6774
6903
  const {
6775
6904
  SOCKET,
6776
6905
  rootPkgJsonPath
6777
- } = constants.constants;
6906
+ } = constants;
6778
6907
 
6779
6908
  // TODO: Add autocompletion using https://socket.dev/npm/package/omelette
6780
6909
  void (async () => {
@@ -6847,5 +6976,5 @@ void (async () => {
6847
6976
  await index.captureException(e);
6848
6977
  }
6849
6978
  })();
6850
- //# debugId=76e0c507-52ca-4166-8d91-8d85877f5cf0
6979
+ //# debugId=8d83e3d2-7856-4690-abbd-43eee8e6533b
6851
6980
  //# sourceMappingURL=cli.js.map