@socketsecurity/cli-with-sentry 1.1.21 → 1.1.23

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.
Files changed (51) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/README.md +37 -56
  3. package/dist/cli.js +35 -25
  4. package/dist/cli.js.map +1 -1
  5. package/dist/constants.js +6 -3
  6. package/dist/constants.js.map +1 -1
  7. package/dist/flags.js +8 -8
  8. package/dist/flags.js.map +1 -1
  9. package/dist/npm-cli.js +6 -2
  10. package/dist/npm-cli.js.map +1 -1
  11. package/dist/pnpm-cli.js +6 -2
  12. package/dist/pnpm-cli.js.map +1 -1
  13. package/dist/shadow-npm-bin2.js +7 -3
  14. package/dist/shadow-npm-bin2.js.map +1 -1
  15. package/dist/shadow-pnpm-bin2.js +40 -36
  16. package/dist/shadow-pnpm-bin2.js.map +1 -1
  17. package/dist/shadow-yarn-bin.js +14 -7
  18. package/dist/shadow-yarn-bin.js.map +1 -1
  19. package/dist/tsconfig.dts.tsbuildinfo +1 -1
  20. package/dist/types/commands/ci/cmd-ci.d.mts.map +1 -1
  21. package/dist/types/commands/fix/cmd-fix.d.mts.map +1 -1
  22. package/dist/types/commands/fix/handle-fix.d.mts +2 -2
  23. package/dist/types/commands/fix/handle-fix.d.mts.map +1 -1
  24. package/dist/types/commands/fix/types.d.mts +1 -1
  25. package/dist/types/commands/fix/types.d.mts.map +1 -1
  26. package/dist/types/commands/scan/suggest_branch_slug.d.mts.map +1 -1
  27. package/dist/types/constants.d.mts +3 -1
  28. package/dist/types/constants.d.mts.map +1 -1
  29. package/dist/types/flags.d.mts.map +1 -1
  30. package/dist/types/sea/bootstrap.d.mts +2 -0
  31. package/dist/types/sea/bootstrap.d.mts.map +1 -0
  32. package/dist/types/sea/build-sea.d.mts +27 -0
  33. package/dist/types/sea/build-sea.d.mts.map +1 -0
  34. package/dist/types/shadow/common.d.mts +0 -8
  35. package/dist/types/shadow/common.d.mts.map +1 -1
  36. package/dist/types/shadow/npm-base.d.mts.map +1 -1
  37. package/dist/types/shadow/pnpm/bin.d.mts.map +1 -1
  38. package/dist/types/shadow/yarn/bin.d.mts.map +1 -1
  39. package/dist/types/utils/agent.d.mts.map +1 -1
  40. package/dist/types/utils/cmd.d.mts +25 -4
  41. package/dist/types/utils/cmd.d.mts.map +1 -1
  42. package/dist/types/utils/dlx.d.mts.map +1 -1
  43. package/dist/types/utils/extract-names.d.mts +15 -0
  44. package/dist/types/utils/extract-names.d.mts.map +1 -0
  45. package/dist/types/utils/git.d.mts.map +1 -1
  46. package/dist/types/utils/meow-with-subcommands.d.mts.map +1 -1
  47. package/dist/utils.js +90 -32
  48. package/dist/utils.js.map +1 -1
  49. package/dist/yarn-cli.js +6 -2
  50. package/dist/yarn-cli.js.map +1 -1
  51. package/package.json +4 -1
package/dist/utils.js CHANGED
@@ -1270,7 +1270,7 @@ function socketDashboardLink(dashPath, text) {
1270
1270
  * @returns A terminal link to Socket.dev
1271
1271
  */
1272
1272
  function socketDevLink(text, urlPath) {
1273
- return vendor.terminalLinkExports(text ?? 'Socket.dev', `${constants.SOCKET_WEBSITE_URL}${urlPath || ''}`);
1273
+ return vendor.terminalLinkExports(text, `${constants.SOCKET_WEBSITE_URL}${urlPath}`);
1274
1274
  }
1275
1275
 
1276
1276
  /**
@@ -1585,9 +1585,9 @@ function getAsciiHeader(command, orgFlag, compactMode = false) {
1585
1585
  const versionHash = constants.default.ENV.INLINED_SOCKET_CLI_VERSION_HASH;
1586
1586
  const cliVersion = redacting ? REDACTED : require$$9.isDebug() ? versionHash : `v${fullVersion}`;
1587
1587
  const nodeVersion = redacting ? REDACTED : process.version;
1588
- const showNodeVersion = require$$9.isDebug();
1588
+ const showNodeVersion = !redacting && require$$9.isDebug();
1589
1589
  const defaultOrg = getConfigValueOrUndef(constants.CONFIG_KEY_DEFAULT_ORG);
1590
- const readOnlyConfig = isConfigFromFlag() ? '*' : '.';
1590
+ const configFromFlagDot = isConfigFromFlag() ? '*' : '.';
1591
1591
 
1592
1592
  // Token display with origin indicator.
1593
1593
  const tokenPrefix = getVisibleTokenPrefix();
@@ -1610,8 +1610,8 @@ function getAsciiHeader(command, orgFlag, compactMode = false) {
1610
1610
  // portability and paste-ability. "simple" ascii chars just work.
1611
1611
  const body = `
1612
1612
  _____ _ _ /---------------
1613
- | __|___ ___| |_ ___| |_ | ${socketDevLink()} CLI: ${cliVersion}
1614
- |__ | ${readOnlyConfig} | _| '_| -_| _| | ${showNodeVersion ? `Node: ${nodeVersion}, ` : ''}token: ${shownToken}, ${orgPart}
1613
+ | __|___ ___| |_ ___| |_ | CLI: ${cliVersion}
1614
+ |__ | ${configFromFlagDot} | _| '_| -_| _| | ${showNodeVersion ? `Node: ${nodeVersion}, ` : ''}token: ${shownToken}, ${orgPart}
1615
1615
  |_____|___|___|_,_|___|_|.dev | Command: \`${command}\`, cwd: ${relCwd}
1616
1616
  `.trim();
1617
1617
  // Note: logger will auto-append a newline.
@@ -1868,7 +1868,7 @@ async function meowWithSubcommands(config, options) {
1868
1868
  }
1869
1869
  const lines = ['', 'Usage', ` $ ${name} <command>`];
1870
1870
  if (isRootCommand) {
1871
- lines.push(` $ ${name} scan create${constants.FLAG_JSON}`, ` $ ${name} package score ${constants.NPM} lodash ${constants.FLAG_MARKDOWN}`);
1871
+ lines.push(` $ ${name} scan create ${constants.FLAG_JSON}`, ` $ ${name} package score ${constants.NPM} lodash ${constants.FLAG_MARKDOWN}`);
1872
1872
  }
1873
1873
  lines.push('');
1874
1874
  if (isRootCommand) {
@@ -1896,7 +1896,7 @@ async function meowWithSubcommands(config, options) {
1896
1896
  // test snapshots we use joinAnd.
1897
1897
  arrays.joinAnd(Array.from(commands).sort(sorts.naturalCompare).map(c => `'${c}'`)));
1898
1898
  }
1899
- lines.push('Note: All commands have their own --help', '', 'Main commands', ` socket login ${description(subcommands['login'])}`, ` socket scan create Create a new Socket scan and report`, ` socket npm/lodash@4.17.21 Request the Socket score of a package`, ` socket ci ${description(subcommands['ci'])}`, ``, 'Socket API', ` analytics ${description(subcommands['analytics'])}`, ` audit-log ${description(subcommands['audit-log'])}`, ` organization ${description(subcommands['organization'])}`, ` package ${description(subcommands['package'])}`, ` repository ${description(subcommands['repository'])}`, ` scan ${description(subcommands['scan'])}`, ` threat-feed ${description(subcommands['threat-feed'])}`, ``, 'Local tools', ` fix ${description(subcommands['fix'])}`, ` manifest ${description(subcommands['manifest'])}`, ` npm ${description(subcommands[constants.NPM])}`, ` npx ${description(subcommands[constants.NPX])}`, ` optimize ${description(subcommands['optimize'])}`, ` raw-npm ${description(subcommands['raw-npm'])}`, ` raw-npx ${description(subcommands['raw-npx'])}`, '', 'CLI configuration', ` config ${description(subcommands['config'])}`, ` install ${description(subcommands['install'])}`, ` login Socket API login and CLI setup`, ` logout ${description(subcommands['logout'])}`, ` uninstall ${description(subcommands['uninstall'])}`, ` wrapper ${description(subcommands['wrapper'])}`);
1899
+ lines.push('Note: All commands have their own --help', '', 'Main commands', ` socket login ${description(subcommands['login'])}`, ` socket scan create Create a new Socket scan and report`, ` socket npm/lodash@4.17.21 Request the Socket score of a package`, ` socket fix ${description(subcommands['fix'])}`, ` socket optimize ${description(subcommands['optimize'])}`, ` socket cdxgen ${description(subcommands['cdxgen'])}`, ` socket ci ${description(subcommands['ci'])}`, ``, 'Socket API', ` analytics ${description(subcommands['analytics'])}`, ` audit-log ${description(subcommands['audit-log'])}`, ` organization ${description(subcommands['organization'])}`, ` package ${description(subcommands['package'])}`, ` repository ${description(subcommands['repository'])}`, ` scan ${description(subcommands['scan'])}`, ` threat-feed ${description(subcommands['threat-feed'])}`, ``, 'Local tools', ` manifest ${description(subcommands['manifest'])}`, ` npm ${description(subcommands[constants.NPM])}`, ` npx ${description(subcommands[constants.NPX])}`, ` raw-npm ${description(subcommands['raw-npm'])}`, ` raw-npx ${description(subcommands['raw-npx'])}`, '', 'CLI configuration', ` config ${description(subcommands['config'])}`, ` install ${description(subcommands['install'])}`, ` login Socket API login and CLI setup`, ` logout ${description(subcommands['logout'])}`, ` uninstall ${description(subcommands['uninstall'])}`, ` wrapper ${description(subcommands['wrapper'])}`);
1900
1900
  } else {
1901
1901
  lines.push('Commands');
1902
1902
  lines.push(` ${getHelpListOutput({
@@ -2317,6 +2317,45 @@ async function getDefaultOrgSlug() {
2317
2317
  };
2318
2318
  }
2319
2319
 
2320
+ /**
2321
+ * Sanitizes a name to comply with repository naming constraints.
2322
+ * Constraints: 100 or less A-Za-z0-9 characters only with non-repeating,
2323
+ * non-leading or trailing ., _ or - only.
2324
+ *
2325
+ * @param name - The name to sanitize
2326
+ * @returns Sanitized name that complies with repository naming rules, or empty string if no valid characters
2327
+ */
2328
+ function sanitizeName(name) {
2329
+ if (!name) {
2330
+ return '';
2331
+ }
2332
+
2333
+ // Replace sequences of illegal characters with underscores.
2334
+ const sanitized = name
2335
+ // Replace any sequence of non-alphanumeric characters (except ., _, -) with underscore.
2336
+ .replace(/[^A-Za-z0-9._-]+/g, '_')
2337
+ // Replace sequences of multiple allowed special chars with single underscore.
2338
+ .replace(/[._-]{2,}/g, '_')
2339
+ // Remove leading special characters.
2340
+ .replace(/^[._-]+/, '')
2341
+ // Remove trailing special characters.
2342
+ .replace(/[._-]+$/, '')
2343
+ // Truncate to 100 characters max.
2344
+ .slice(0, 100);
2345
+ return sanitized;
2346
+ }
2347
+
2348
+ /**
2349
+ * Extracts and sanitizes a repository name.
2350
+ *
2351
+ * @param name - The repository name to extract and sanitize
2352
+ * @returns Sanitized repository name, or default repository name if empty
2353
+ */
2354
+ function extractName(name) {
2355
+ const sanitized = sanitizeName(name);
2356
+ return sanitized || constants.default.SOCKET_DEFAULT_REPOSITORY;
2357
+ }
2358
+
2320
2359
  /**
2321
2360
  * Git utilities for Socket CLI.
2322
2361
  * Provides git operations for repository management, branch handling, and commits.
@@ -2409,7 +2448,7 @@ async function getRepoInfo(cwd = process.cwd()) {
2409
2448
  }
2410
2449
  async function getRepoName(cwd = process.cwd()) {
2411
2450
  const repoInfo = await getRepoInfo(cwd);
2412
- return repoInfo?.repo ?? constants.default.SOCKET_DEFAULT_REPOSITORY;
2451
+ return repoInfo?.repo ? extractName(repoInfo.repo) : constants.default.SOCKET_DEFAULT_REPOSITORY;
2413
2452
  }
2414
2453
  async function gitBranch(cwd = process.cwd()) {
2415
2454
  const stdioPipeOptions = {
@@ -3313,8 +3352,8 @@ function isYarnBerry() {
3313
3352
  if (_isYarnBerry === undefined) {
3314
3353
  try {
3315
3354
  const yarnBinPath = getYarnBinPath();
3316
- const result = spawn.spawnSync(yarnBinPath, ['--version'], {
3317
- encoding: 'utf8',
3355
+ const result = spawn.spawnSync(yarnBinPath, [constants.FLAG_VERSION], {
3356
+ encoding: constants.UTF8,
3318
3357
  // On Windows, yarn is often a .cmd file that requires shell execution.
3319
3358
  // The spawn function from @socketsecurity/registry will handle this properly
3320
3359
  // when shell is true.
@@ -3425,10 +3464,6 @@ async function spawnDlx(packageSpec, args, options, spawnExtra) {
3425
3464
  npm_config_dlx_cache_max_age: '0'
3426
3465
  }
3427
3466
  };
3428
- // Add --ignore-scripts for extra security.
3429
- // While pnpm dlx allows the executed package's scripts by default,
3430
- // we disable them since coana/cdxgen/synp don't need postinstall scripts.
3431
- spawnArgs.push('--ignore-scripts');
3432
3467
  }
3433
3468
  if (silent) {
3434
3469
  spawnArgs.push(constants.FLAG_SILENT);
@@ -3955,6 +3990,19 @@ async function setGitRemoteGithubRepoUrl(owner, repo, token, cwd = process.cwd()
3955
3990
 
3956
3991
  const helpFlags = new Set([constants.FLAG_HELP, '-h']);
3957
3992
 
3993
+ /**
3994
+ * Convert flag values to array format for processing.
3995
+ */
3996
+ function cmdFlagValueToArray(value) {
3997
+ if (typeof value === 'string') {
3998
+ return value.trim().split(/, */).filter(Boolean);
3999
+ }
4000
+ if (Array.isArray(value)) {
4001
+ return value.flatMap(cmdFlagValueToArray);
4002
+ }
4003
+ return [];
4004
+ }
4005
+
3958
4006
  /**
3959
4007
  * Convert command arguments to a properly formatted string representation.
3960
4008
  */
@@ -3981,19 +4029,6 @@ function cmdFlagsToString(args) {
3981
4029
  return result.join(' ');
3982
4030
  }
3983
4031
 
3984
- /**
3985
- * Convert flag values to array format for processing.
3986
- */
3987
- function cmdFlagValueToArray(value) {
3988
- if (typeof value === 'string') {
3989
- return value.trim().split(/, */).filter(Boolean);
3990
- }
3991
- if (Array.isArray(value)) {
3992
- return value.flatMap(cmdFlagValueToArray);
3993
- }
3994
- return [];
3995
- }
3996
-
3997
4032
  /**
3998
4033
  * Add command name prefix to message text.
3999
4034
  */
@@ -4065,6 +4100,15 @@ function filterFlags(argv, flagsToFilter, exceptions) {
4065
4100
  return filtered;
4066
4101
  }
4067
4102
 
4103
+ /**
4104
+ * Check if command is an add command (adds new dependencies).
4105
+ * Supported by: pnpm, yarn.
4106
+ * Note: npm uses 'install' with package names instead of 'add'.
4107
+ */
4108
+ function isAddCommand(command) {
4109
+ return command === 'add';
4110
+ }
4111
+
4068
4112
  /**
4069
4113
  * Check if argument is a help flag.
4070
4114
  */
@@ -4072,6 +4116,14 @@ function isHelpFlag(cmdArg) {
4072
4116
  return helpFlags.has(cmdArg);
4073
4117
  }
4074
4118
 
4119
+ /**
4120
+ * Check if pnpm command requires lockfile scanning.
4121
+ * pnpm uses: install, i, update, up
4122
+ */
4123
+ function isPnpmLockfileScanCommand(command) {
4124
+ return command === 'install' || command === 'i' || command === 'update' || command === 'up';
4125
+ }
4126
+
4075
4127
  /**
4076
4128
  * Converts CVE IDs to GHSA IDs using GitHub API.
4077
4129
  */
@@ -4345,7 +4397,7 @@ function shadowNpmInstall(options) {
4345
4397
  const otherArgs = terminatorPos === -1 ? [] : args.slice(terminatorPos);
4346
4398
  const progressArg = rawBinArgs.findLast(agent.isNpmProgressFlag) !== '--no-progress';
4347
4399
  const isSilent = !useDebug && !binArgs.some(agent.isNpmLoglevelFlag);
4348
- const logLevelArgs = isSilent ? ['--loglevel', 'silent'] : [];
4400
+ const logLevelArgs = isSilent ? [constants.FLAG_LOGLEVEL, 'silent'] : [];
4349
4401
  const useIpc = require$$11.isObject(ipc);
4350
4402
 
4351
4403
  // Include 'ipc' in the spawnOpts.stdio when an options.ipc object is provided.
@@ -4366,7 +4418,7 @@ function shadowNpmInstall(options) {
4366
4418
  '--no-audit', '--no-fund',
4367
4419
  // Add '--no-progress' to fix input being swallowed by the npm spinner.
4368
4420
  '--no-progress',
4369
- // Add '--loglevel=silent' if a loglevel flag is not provided and the
4421
+ // Add 'FLAG_LOGLEVEL silent' if a loglevel flag is not provided and the
4370
4422
  // SOCKET_CLI_DEBUG environment variable is not truthy.
4371
4423
  ...logLevelArgs, ...binArgs, ...otherArgs], {
4372
4424
  ...spawnOpts,
@@ -4435,8 +4487,8 @@ function runAgentInstall(pkgEnvDetails, options) {
4435
4487
  const skipNodeHardenFlags = isPnpm && pkgEnvDetails.agentVersion.major < 11;
4436
4488
  // In CI mode, pnpm uses --frozen-lockfile by default, which prevents lockfile updates.
4437
4489
  // We need to explicitly disable it when updating the lockfile with overrides.
4438
- const isCi = constants.default.ENV['CI'];
4439
- const installArgs = isPnpm && isCi ? ['install', '--no-frozen-lockfile', ...args] : ['install', ...args];
4490
+ // Also add --config.confirmModulesPurge=false to avoid interactive prompts.
4491
+ const installArgs = isPnpm ? ['install', '--config.confirmModulesPurge=false', '--no-frozen-lockfile', ...args] : ['install', ...args];
4440
4492
  return spawn.spawn(agentExecPath, installArgs, {
4441
4493
  cwd: pkgPath,
4442
4494
  // On Windows, package managers are often .cmd files that require shell execution.
@@ -4449,6 +4501,10 @@ function runAgentInstall(pkgEnvDetails, options) {
4449
4501
  env: {
4450
4502
  ...process.env,
4451
4503
  ...constants.default.processEnv,
4504
+ // Set CI for pnpm to ensure non-interactive mode and consistent behavior.
4505
+ ...(isPnpm ? {
4506
+ CI: '1'
4507
+ } : {}),
4452
4508
  NODE_OPTIONS: cmdFlagsToString([...(skipNodeHardenFlags ? [] : constants.default.nodeHardenFlags), ...constants.default.nodeNoWarningsFlags]),
4453
4509
  ...require$$11.getOwn(spawnOpts, 'env')
4454
4510
  }
@@ -6016,8 +6072,10 @@ exports.installNpmLinks = installNpmLinks;
6016
6072
  exports.installNpxLinks = installNpxLinks;
6017
6073
  exports.installPnpmLinks = installPnpmLinks;
6018
6074
  exports.installYarnLinks = installYarnLinks;
6075
+ exports.isAddCommand = isAddCommand;
6019
6076
  exports.isConfigFromFlag = isConfigFromFlag;
6020
6077
  exports.isHelpFlag = isHelpFlag;
6078
+ exports.isPnpmLockfileScanCommand = isPnpmLockfileScanCommand;
6021
6079
  exports.isReportSupportedFile = isReportSupportedFile;
6022
6080
  exports.isSensitiveConfigKey = isSensitiveConfigKey;
6023
6081
  exports.isSupportedConfigKey = isSupportedConfigKey;
@@ -6060,5 +6118,5 @@ exports.updateConfigValue = updateConfigValue;
6060
6118
  exports.walkNestedMap = walkNestedMap;
6061
6119
  exports.webLink = webLink;
6062
6120
  exports.writeSocketJson = writeSocketJson;
6063
- //# debugId=aca3fb2c-1435-481e-a911-c0547052c313
6121
+ //# debugId=4869ae24-405b-42c5-8d8a-e03b6c950c8e
6064
6122
  //# sourceMappingURL=utils.js.map