@socketsecurity/cli-with-sentry 1.0.10 → 1.0.12

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 (34) hide show
  1. package/dist/cli.js +182 -179
  2. package/dist/cli.js.map +1 -1
  3. package/dist/constants.js +3 -3
  4. package/dist/constants.js.map +1 -1
  5. package/dist/shadow-npm-bin.js +3 -4
  6. package/dist/shadow-npm-bin.js.map +1 -1
  7. package/dist/types/commands/fix/git.d.mts.map +1 -1
  8. package/dist/types/commands/fix/open-pr.d.mts.map +1 -1
  9. package/dist/types/commands/json/output-cmd-json.d.mts.map +1 -1
  10. package/dist/types/commands/manifest/cmd-manifest-gradle.d.mts.map +1 -1
  11. package/dist/types/commands/manifest/cmd-manifest-kotlin.d.mts.map +1 -1
  12. package/dist/types/commands/manifest/cmd-manifest-scala.d.mts.map +1 -1
  13. package/dist/types/commands/manifest/detect-manifest-actions.d.mts +1 -1
  14. package/dist/types/commands/manifest/detect-manifest-actions.d.mts.map +1 -1
  15. package/dist/types/commands/manifest/generate_auto_manifest.d.mts.map +1 -1
  16. package/dist/types/commands/optimize/ls-by-agent.d.mts.map +1 -1
  17. package/dist/types/commands/scan/suggest_branch_slug.d.mts.map +1 -1
  18. package/dist/types/commands/wrapper/remove-socket-wrapper.d.mts +1 -1
  19. package/dist/types/commands/wrapper/remove-socket-wrapper.d.mts.map +1 -1
  20. package/dist/types/shadow/npm/bin.d.mts.map +1 -1
  21. package/dist/types/utils/coana.d.mts.map +1 -1
  22. package/dist/types/utils/fs.d.mts +11 -1
  23. package/dist/types/utils/fs.d.mts.map +1 -1
  24. package/dist/types/utils/glob.d.mts.map +1 -1
  25. package/dist/types/utils/package-environment.d.mts.map +1 -1
  26. package/dist/types/utils/path-resolve.d.mts.map +1 -1
  27. package/dist/types/utils/socketjson.d.mts +1 -1
  28. package/dist/types/utils/socketjson.d.mts.map +1 -1
  29. package/dist/utils.js +34 -30
  30. package/dist/utils.js.map +1 -1
  31. package/dist/vendor.js +9 -9
  32. package/external/@coana-tech/cli/cli.mjs +16 -5
  33. package/external/@socketsecurity/registry/lib/spawn.js +47 -24
  34. package/package.json +6 -6
package/dist/utils.js CHANGED
@@ -158,7 +158,7 @@ async function globWithGitIgnore(patterns, options) {
158
158
  cwd,
159
159
  expandDirectories: true
160
160
  });
161
- const ignores = [...ignoredDirPatterns, ...(Array.isArray(projectIgnorePaths) ? ignoreFileLinesToGlobPatterns(projectIgnorePaths, path.join(cwd, '.gitignore'), cwd) : []), ...(await Promise.all(ignoreFiles.map(async filepath => ignoreFileToGlobPatterns(await fs.promises.readFile(filepath, 'utf8'), filepath, cwd)))).flat()];
161
+ const ignores = [...ignoredDirPatterns, ...(Array.isArray(projectIgnorePaths) ? ignoreFileLinesToGlobPatterns(projectIgnorePaths, path.join(cwd, '.gitignore'), cwd) : []), ...(await Promise.all(ignoreFiles.map(async filepath => ignoreFileToGlobPatterns((await safeReadFile(filepath)) ?? '', filepath, cwd)))).flat()];
162
162
  const hasNegatedPattern = ignores.some(p => p.charCodeAt(0) === 33 /*'!'*/);
163
163
  const globOptions = {
164
164
  absolute: true,
@@ -277,6 +277,15 @@ function safeReadFileSync(filepath, options) {
277
277
  } catch {}
278
278
  return undefined;
279
279
  }
280
+ function safeStatsSync(filepath, options) {
281
+ try {
282
+ return fs.statSync(filepath, {
283
+ throwIfNoEntry: false,
284
+ ...options
285
+ });
286
+ } catch {}
287
+ return undefined;
288
+ }
280
289
 
281
290
  const sensitiveConfigKeys = new Set(['apiToken']);
282
291
  const supportedConfigKeys = new Map([['apiBaseUrl', 'Base URL of the API endpoint'], ['apiProxy', 'A proxy through which to access the API'], ['apiToken', 'The API token required to access most API endpoints'], ['defaultOrg', 'The default org slug to use; usually the org your API token has access to. When set, all orgSlug arguments are implied to be this value.'], ['enforcedOrgs', 'Orgs in this list have their security policies enforced on this machine'], ['skipAskToPersistDefaultOrg', 'This flag prevents the CLI from asking you to persist the org slug when you selected one interactively'], ['org', 'Alias for defaultOrg']]);
@@ -1668,9 +1677,7 @@ function findNpmPathSync(npmBinPath) {
1668
1677
  // Use existsSync here because statsSync, even with { throwIfNoEntry: false },
1669
1678
  // will throw an ENOTDIR error for paths like ./a-file-that-exists/a-directory-that-does-not.
1670
1679
  // See https://github.com/nodejs/node/issues/56993.
1671
- fs.existsSync(libNmNpmPath) && fs.statSync(libNmNpmPath, {
1672
- throwIfNoEntry: false
1673
- })?.isDirectory()) {
1680
+ fs.existsSync(libNmNpmPath) && safeStatsSync(libNmNpmPath)?.isDirectory()) {
1674
1681
  thePath = path.join(libNmNpmPath, NPM$4);
1675
1682
  }
1676
1683
  const nmPath = path.join(thePath, NODE_MODULES$1);
@@ -1685,9 +1692,7 @@ function findNpmPathSync(npmBinPath) {
1685
1692
  // In practically all cases the npm path contains a node_modules folder:
1686
1693
  // /usr/local/share/npm/bin/npm/node_modules
1687
1694
  // C:\Program Files\nodejs\node_modules
1688
- fs.existsSync(nmPath) && fs.statSync(nmPath, {
1689
- throwIfNoEntry: false
1690
- })?.isDirectory() && (
1695
+ fs.existsSync(nmPath) && safeStatsSync(nmPath)?.isDirectory() && (
1691
1696
  // Optimistically look for the default location.
1692
1697
  path.basename(thePath) === NPM$4 ||
1693
1698
  // Chocolatey installs npm bins in the same directory as node bins.
@@ -1745,9 +1750,9 @@ function getDefaultSocketJson() {
1745
1750
  };
1746
1751
  }
1747
1752
  async function readSocketJson(cwd, defaultOnError = false) {
1748
- const filepath = path.join(cwd, 'socket.json');
1749
- if (!fs.existsSync(filepath)) {
1750
- debug.debugLog(`[DEBUG] File not found: ${filepath}`);
1753
+ const sockJsonPath = path.join(cwd, 'socket.json');
1754
+ if (!fs.existsSync(sockJsonPath)) {
1755
+ debug.debugFn(`miss: file not found ${sockJsonPath}`);
1751
1756
  return {
1752
1757
  ok: true,
1753
1758
  data: getDefaultSocketJson()
@@ -1755,12 +1760,12 @@ async function readSocketJson(cwd, defaultOnError = false) {
1755
1760
  }
1756
1761
  let json = null;
1757
1762
  try {
1758
- json = await fs.promises.readFile(filepath, 'utf8');
1763
+ json = await fs.promises.readFile(sockJsonPath, 'utf8');
1759
1764
  } catch (e) {
1760
1765
  debug.debugLog('[DEBUG] Raw error:');
1761
1766
  debug.debugLog(e);
1762
1767
  if (defaultOnError) {
1763
- logger.logger.warn('Warning: failed to parse file, using default');
1768
+ logger.logger.warn('Warning: failed to read file, using default');
1764
1769
  return {
1765
1770
  ok: true,
1766
1771
  data: getDefaultSocketJson()
@@ -1777,11 +1782,9 @@ async function readSocketJson(cwd, defaultOnError = false) {
1777
1782
  try {
1778
1783
  obj = JSON.parse(json);
1779
1784
  } catch {
1780
- debug.debugLog('[DEBUG] Failed to parse content as JSON');
1781
- debug.debugLog(`[DEBUG] File contents ${json?.length ?? 0}:`);
1782
- debug.debugLog(json);
1785
+ debug.debugFn('fail: parse JSON\n', json);
1783
1786
  if (defaultOnError) {
1784
- logger.logger.warn('Warning: failed to read file, using default');
1787
+ logger.logger.warn('Warning: failed to parse file, using default');
1785
1788
  return {
1786
1789
  ok: true,
1787
1790
  data: getDefaultSocketJson()
@@ -1790,7 +1793,7 @@ async function readSocketJson(cwd, defaultOnError = false) {
1790
1793
  return {
1791
1794
  ok: false,
1792
1795
  message: 'Failed to parse socket.json',
1793
- cause: 'It seems your socket.json did not contain valid JSON, please verify'
1796
+ cause: 'socket.json does not contain valid JSON, please verify'
1794
1797
  };
1795
1798
  }
1796
1799
  if (!obj) {
@@ -1809,15 +1812,13 @@ async function readSocketJson(cwd, defaultOnError = false) {
1809
1812
  data: obj
1810
1813
  };
1811
1814
  }
1812
- async function writeSocketJson(cwd, socketJson) {
1815
+ async function writeSocketJson(cwd, sockJson) {
1813
1816
  let json = '';
1814
1817
  try {
1815
- json = JSON.stringify(socketJson, null, 2);
1818
+ json = JSON.stringify(sockJson, null, 2);
1816
1819
  } catch (e) {
1817
- debug.debugLog('[DEBUG] JSON.stringify failed:');
1818
- debug.debugLog(e);
1819
- debug.debugLog('[DEBUG] Object:');
1820
- debug.debugLog(socketJson);
1820
+ debug.debugFn('fail: stringify JSON\n', e);
1821
+ debug.debugLog('[DEBUG] Object:\n', sockJson);
1821
1822
  return {
1822
1823
  ok: false,
1823
1824
  message: 'Failed to serialize to JSON',
@@ -2818,11 +2819,11 @@ async function spawnCoana(args, options, extra) {
2818
2819
  }, extra);
2819
2820
  return {
2820
2821
  ok: true,
2821
- data: strings.stripAnsi(output.stdout.trim())
2822
+ data: output.stdout
2822
2823
  };
2823
2824
  } catch (e) {
2824
2825
  const stderr = e?.stderr;
2825
- const message = stderr ? strings.stripAnsi(stderr.trim()) : e?.message;
2826
+ const message = stderr ? stderr : e?.message;
2826
2827
  return {
2827
2828
  ok: false,
2828
2829
  data: e,
@@ -2873,11 +2874,11 @@ const readLockFileByAgent = (() => {
2873
2874
  // To print a Yarn lockfile to your console without writing it to disk
2874
2875
  // use `bun bun.lockb`.
2875
2876
  // https://bun.sh/guides/install/yarnlock
2876
- return strings.stripAnsi((await spawn.spawn(agentExecPath, [lockPath], {
2877
+ return (await spawn.spawn(agentExecPath, [lockPath], {
2877
2878
  cwd,
2878
2879
  // Lazily access constants.WIN32.
2879
2880
  shell: constants.WIN32
2880
- })).stdout.trim());
2881
+ })).stdout;
2881
2882
  }
2882
2883
  return undefined;
2883
2884
  })], [NPM, defaultReader], [PNPM, defaultReader], [VLT, defaultReader], [YARN_BERRY, defaultReader], [YARN_CLASSIC, defaultReader]]);
@@ -2923,11 +2924,12 @@ async function getAgentVersion(agentExecPath, cwd) {
2923
2924
  // and tildes (~).
2924
2925
  vendor.semverExports.coerce(
2925
2926
  // All package managers support the "--version" flag.
2926
- strings.stripAnsi((await spawn.spawn(agentExecPath, ['--version'], {
2927
+
2928
+ (await spawn.spawn(agentExecPath, ['--version'], {
2927
2929
  cwd,
2928
2930
  // Lazily access constants.WIN32.
2929
2931
  shell: constants.WIN32
2930
- })).stdout.trim())) ?? undefined;
2932
+ })).stdout) ?? undefined;
2931
2933
  } catch (e) {
2932
2934
  debug.debugFn('catch: unexpected\n', e);
2933
2935
  }
@@ -3286,6 +3288,8 @@ exports.readSocketJson = readSocketJson;
3286
3288
  exports.removeNodeModules = removeNodeModules;
3287
3289
  exports.runAgentInstall = runAgentInstall;
3288
3290
  exports.safeReadFile = safeReadFile;
3291
+ exports.safeReadFileSync = safeReadFileSync;
3292
+ exports.safeStatsSync = safeStatsSync;
3289
3293
  exports.sensitiveConfigKeys = sensitiveConfigKeys;
3290
3294
  exports.serializeResultJson = serializeResultJson;
3291
3295
  exports.setupSdk = setupSdk;
@@ -3296,5 +3300,5 @@ exports.tildify = tildify;
3296
3300
  exports.updateConfigValue = updateConfigValue;
3297
3301
  exports.walkNestedMap = walkNestedMap;
3298
3302
  exports.writeSocketJson = writeSocketJson;
3299
- //# debugId=8f15309d-d08e-48ed-be22-b7f674429aeb
3303
+ //# debugId=b0db9c52-0a2c-4d67-9463-52ca8c06ff74
3300
3304
  //# sourceMappingURL=utils.js.map