@socketsecurity/cli-with-sentry 0.15.43 → 0.15.44

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 (55) hide show
  1. package/dist/cli.js +592 -455
  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-inject.js +10 -3
  6. package/dist/shadow-inject.js.map +1 -1
  7. package/dist/types/commands/fix/git.d.mts +12 -5
  8. package/dist/types/commands/fix/git.d.mts.map +1 -1
  9. package/dist/types/commands/fix/npm-fix.d.mts.map +1 -1
  10. package/dist/types/commands/fix/open-pr.d.mts +2 -4
  11. package/dist/types/commands/fix/open-pr.d.mts.map +1 -1
  12. package/dist/types/commands/fix/pnpm-fix.d.mts.map +1 -1
  13. package/dist/types/commands/package/output-purls-shallow-score.d.mts +2 -2
  14. package/dist/types/commands/package/output-purls-shallow-score.d.mts.map +1 -1
  15. package/dist/types/commands/scan/cmd-scan-reach.d.mts +10 -0
  16. package/dist/types/commands/scan/cmd-scan-reach.d.mts.map +1 -0
  17. package/dist/types/commands/scan/cmd-scan.d.mts.map +1 -1
  18. package/dist/types/commands/scan/fetch-report-data.d.mts +2 -2
  19. package/dist/types/commands/scan/fetch-report-data.d.mts.map +1 -1
  20. package/dist/types/commands/scan/fetch-scan.d.mts +2 -2
  21. package/dist/types/commands/scan/fetch-scan.d.mts.map +1 -1
  22. package/dist/types/commands/scan/generate-report.d.mts +2 -2
  23. package/dist/types/commands/scan/generate-report.d.mts.map +1 -1
  24. package/dist/types/commands/scan/handle-reach-scan.d.mts +3 -0
  25. package/dist/types/commands/scan/handle-reach-scan.d.mts.map +1 -0
  26. package/dist/types/commands/scan/output-scan-reach.d.mts +3 -0
  27. package/dist/types/commands/scan/output-scan-reach.d.mts.map +1 -0
  28. package/dist/types/commands/scan/output-scan-report.d.mts +2 -2
  29. package/dist/types/commands/scan/output-scan-report.d.mts.map +1 -1
  30. package/dist/types/commands/scan/output-scan-view.d.mts +2 -2
  31. package/dist/types/commands/scan/output-scan-view.d.mts.map +1 -1
  32. package/dist/types/commands/scan/scan-reachability.d.mts +3 -0
  33. package/dist/types/commands/scan/scan-reachability.d.mts.map +1 -0
  34. package/dist/types/commands/wrapper/cmd-wrapper.d.mts.map +1 -1
  35. package/dist/types/shadow/npm/arborist-helpers.d.mts +2 -2
  36. package/dist/types/shadow/npm/arborist-helpers.d.mts.map +1 -1
  37. package/dist/types/utils/alert/artifact.d.mts +1 -0
  38. package/dist/types/utils/alert/artifact.d.mts.map +1 -1
  39. package/dist/types/utils/alerts-map.d.mts +3 -3
  40. package/dist/types/utils/alerts-map.d.mts.map +1 -1
  41. package/dist/types/utils/api.d.mts.map +1 -1
  42. package/dist/types/utils/fs.d.mts.map +1 -1
  43. package/dist/types/utils/glob.d.mts.map +1 -1
  44. package/dist/types/utils/purl.d.mts +95 -1
  45. package/dist/types/utils/purl.d.mts.map +1 -1
  46. package/dist/types/utils/socket-package-alert.d.mts +7 -6
  47. package/dist/types/utils/socket-package-alert.d.mts.map +1 -1
  48. package/dist/types/utils/socket-url.d.mts +4 -6
  49. package/dist/types/utils/socket-url.d.mts.map +1 -1
  50. package/dist/types/utils/spec.d.mts +2 -1
  51. package/dist/types/utils/spec.d.mts.map +1 -1
  52. package/dist/utils.js +167 -149
  53. package/dist/utils.js.map +1 -1
  54. package/dist/vendor.js +11381 -7009
  55. package/package.json +10 -10
package/dist/utils.js CHANGED
@@ -21,10 +21,11 @@ var spawn = require('../external/@socketsecurity/registry/lib/spawn');
21
21
  var npm = require('../external/@socketsecurity/registry/lib/npm');
22
22
  var words = require('../external/@socketsecurity/registry/lib/words');
23
23
  var fs$1 = require('../external/@socketsecurity/registry/lib/fs');
24
+ var require$$7 = require('../external/@socketsecurity/registry/lib/promises');
24
25
 
25
26
  var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
26
27
  const {
27
- NPM: NPM$6,
28
+ NPM: NPM$5,
28
29
  PNPM: PNPM$2
29
30
  } = constants;
30
31
  const PNPM_WORKSPACE = `${PNPM$2}-workspace`;
@@ -135,7 +136,7 @@ function workspacePatternToGlobPattern(workspace) {
135
136
  return `${workspace}/package.json`;
136
137
  }
137
138
  async function filterGlobResultToSupportedFiles(entries, supportedFiles) {
138
- const patterns = ['golang', NPM$6, 'maven', 'pypi', 'gem', 'nuget'].reduce((r, n) => {
139
+ const patterns = ['golang', NPM$5, 'maven', 'pypi', 'gem', 'nuget'].reduce((r, n) => {
139
140
  const supported = supportedFiles[n];
140
141
  r.push(...(supported ? Object.values(supported).map(p => `**/${p.pattern}`) : []));
141
142
  return r;
@@ -180,9 +181,11 @@ async function globWithGitIgnore(patterns, options) {
180
181
  return absolute ? filtered.map(p => path.resolve(cwd, p)) : filtered;
181
182
  }
182
183
  async function globNodeModules(cwd = process.cwd()) {
183
- return await vendor.distExports.glob('**/node_modules/**', {
184
+ return await vendor.distExports.glob('**/node_modules', {
184
185
  absolute: true,
185
- cwd
186
+ cwd,
187
+ expandDirectories: false,
188
+ onlyDirectories: true
186
189
  });
187
190
  }
188
191
  async function globWorkspace(agent, cwd = process.cwd()) {
@@ -203,7 +206,12 @@ const {
203
206
  } = constants;
204
207
  async function removeNodeModules(cwd = process.cwd()) {
205
208
  const nodeModulesPaths = await globNodeModules(cwd);
206
- await Promise.all(nodeModulesPaths.map(p => fs$1.remove(p)));
209
+ await require$$7.pEach(nodeModulesPaths, 3, p => fs$1.remove(p, {
210
+ force: true,
211
+ recursive: true
212
+ }), {
213
+ retries: 3
214
+ });
207
215
  }
208
216
  async function findUp(name, {
209
217
  cwd = process.cwd(),
@@ -1202,8 +1210,8 @@ async function meowWithSubcommands(subcommands, options) {
1202
1210
  delete subcommands['info'];
1203
1211
  delete subcommands['report'];
1204
1212
  }
1205
- function formatCommandsForHelp() {
1206
- if (!isTestingV1()) {
1213
+ function formatCommandsForHelp(isRootCommand) {
1214
+ if (!isRootCommand || !isTestingV1()) {
1207
1215
  return getHelpListOutput({
1208
1216
  ...objects.toSortedObject(Object.fromEntries(Object.entries(subcommands).filter(({
1209
1217
  1: subcommand
@@ -1283,7 +1291,7 @@ async function meowWithSubcommands(subcommands, options) {
1283
1291
  $ ${name} <command>
1284
1292
 
1285
1293
  ${isRootCommand && isTestingV1() ? '' : ' Commands'}
1286
- ${formatCommandsForHelp()}
1294
+ ${formatCommandsForHelp(isRootCommand)}
1287
1295
 
1288
1296
  ${isRootCommand && isTestingV1() ? ' Options' : ' Options'}${isRootCommand ? ' (Note: all CLI commands have these flags even when not displayed in their help)\n' : ''}
1289
1297
  ${getFlagListOutput(flags, 6, isTestingV1() ? {
@@ -1489,7 +1497,7 @@ async function determineOrgSlug(orgFlag, firstArg, interactive, dryRun) {
1489
1497
 
1490
1498
  const {
1491
1499
  NODE_MODULES: NODE_MODULES$1,
1492
- NPM: NPM$5,
1500
+ NPM: NPM$4,
1493
1501
  shadowBinPath
1494
1502
  } = constants;
1495
1503
  function findBinPathDetailsSync(binName) {
@@ -1524,7 +1532,7 @@ function findNpmPathSync(npmBinPath) {
1524
1532
  } = constants;
1525
1533
  let thePath = npmBinPath;
1526
1534
  while (true) {
1527
- const libNmNpmPath = path.join(thePath, 'lib', NODE_MODULES$1, NPM$5);
1535
+ const libNmNpmPath = path.join(thePath, 'lib', NODE_MODULES$1, NPM$4);
1528
1536
  // mise puts its npm bin in a path like:
1529
1537
  // /Users/SomeUsername/.local/share/mise/installs/node/vX.X.X/bin/npm.
1530
1538
  // HOWEVER, the location of the npm install is:
@@ -1536,7 +1544,7 @@ function findNpmPathSync(npmBinPath) {
1536
1544
  fs.existsSync(libNmNpmPath) && fs.statSync(libNmNpmPath, {
1537
1545
  throwIfNoEntry: false
1538
1546
  })?.isDirectory()) {
1539
- thePath = path.join(libNmNpmPath, NPM$5);
1547
+ thePath = path.join(libNmNpmPath, NPM$4);
1540
1548
  }
1541
1549
  const nmPath = path.join(thePath, NODE_MODULES$1);
1542
1550
  if (
@@ -1554,9 +1562,9 @@ function findNpmPathSync(npmBinPath) {
1554
1562
  throwIfNoEntry: false
1555
1563
  })?.isDirectory() && (
1556
1564
  // Optimistically look for the default location.
1557
- path.basename(thePath) === NPM$5 ||
1565
+ path.basename(thePath) === NPM$4 ||
1558
1566
  // Chocolatey installs npm bins in the same directory as node bins.
1559
- WIN32 && fs.existsSync(path.join(thePath, `${NPM$5}.cmd`)))) {
1567
+ WIN32 && fs.existsSync(path.join(thePath, `${NPM$4}.cmd`)))) {
1560
1568
  return thePath;
1561
1569
  }
1562
1570
  const parent = path.dirname(thePath);
@@ -1594,7 +1602,7 @@ async function getPackageFilesForScan(cwd, inputPaths, supportedFiles, config) {
1594
1602
 
1595
1603
  const {
1596
1604
  NODE_MODULES,
1597
- NPM: NPM$4,
1605
+ NPM: NPM$3,
1598
1606
  NPX,
1599
1607
  SOCKET_CLI_ISSUES_URL
1600
1608
  } = constants;
@@ -1608,7 +1616,7 @@ function exitWithBinPathError(binName) {
1608
1616
  let _npmBinPathDetails;
1609
1617
  function getNpmBinPathDetails() {
1610
1618
  if (_npmBinPathDetails === undefined) {
1611
- _npmBinPathDetails = findBinPathDetailsSync(NPM$4);
1619
+ _npmBinPathDetails = findBinPathDetailsSync(NPM$3);
1612
1620
  }
1613
1621
  return _npmBinPathDetails;
1614
1622
  }
@@ -1630,7 +1638,7 @@ function getNpmBinPath() {
1630
1638
  if (_npmBinPath === undefined) {
1631
1639
  _npmBinPath = getNpmBinPathDetails().path;
1632
1640
  if (!_npmBinPath) {
1633
- exitWithBinPathError(NPM$4);
1641
+ exitWithBinPathError(NPM$3);
1634
1642
  }
1635
1643
  }
1636
1644
  return _npmBinPath;
@@ -1659,7 +1667,7 @@ let _npmRequire;
1659
1667
  function getNpmRequire() {
1660
1668
  if (_npmRequire === undefined) {
1661
1669
  const npmPath = getNpmPath();
1662
- const npmNmPath = path.join(npmPath, NODE_MODULES, NPM$4);
1670
+ const npmNmPath = path.join(npmPath, NODE_MODULES, NPM$3);
1663
1671
  _npmRequire = Module.createRequire(path.join(fs.existsSync(npmNmPath) ? npmNmPath : npmPath, '<dummy-basename>'));
1664
1672
  }
1665
1673
  return _npmRequire;
@@ -1701,10 +1709,15 @@ function isHelpFlag(cmdArg) {
1701
1709
  return helpFlags.has(cmdArg);
1702
1710
  }
1703
1711
 
1712
+ function getPurlObject(purl) {
1713
+ return typeof purl === 'string' ? vendor.packageurlJsExports.PackageURL.fromString(purl) : purl;
1714
+ }
1715
+
1704
1716
  const {
1705
1717
  SOCKET_WEBSITE_URL
1706
1718
  } = constants;
1707
- function getPkgFullNameFromPurlObj(purlObj) {
1719
+ function getPkgFullNameFromPurl(purl) {
1720
+ const purlObj = getPurlObject(purl);
1708
1721
  const {
1709
1722
  name,
1710
1723
  namespace
@@ -1714,13 +1727,14 @@ function getPkgFullNameFromPurlObj(purlObj) {
1714
1727
  function getSocketDevAlertUrl(alertType) {
1715
1728
  return `${SOCKET_WEBSITE_URL}/alerts/${alertType}`;
1716
1729
  }
1717
- function getSocketDevPackageOverviewUrlFromPurl(purlObj) {
1718
- const fullName = getPkgFullNameFromPurlObj(purlObj);
1730
+ function getSocketDevPackageOverviewUrlFromPurl(purl) {
1731
+ const purlObj = getPurlObject(purl);
1732
+ const fullName = getPkgFullNameFromPurl(purlObj);
1719
1733
  return getSocketDevPackageOverviewUrl(purlObj.type, fullName, purlObj.version);
1720
1734
  }
1721
1735
  function getSocketDevPackageOverviewUrl(ecosystem, fullName, version) {
1722
1736
  const url = `${SOCKET_WEBSITE_URL}/${ecosystem}/package/${fullName}`;
1723
- return ecosystem === 'go' ? `${url}${version ? `?section=overview&version=${version}` : ''}` : `${url}${version ? `/overview/${version}` : ''}`;
1737
+ return ecosystem === 'golang' ? `${url}${version ? `?section=overview&version=${version}` : ''}` : `${url}${version ? `/overview/${version}` : ''}`;
1724
1738
  }
1725
1739
 
1726
1740
  /**
@@ -1849,10 +1863,6 @@ async function writeSocketJson(cwd, socketJson) {
1849
1863
  };
1850
1864
  }
1851
1865
 
1852
- function getPurlObject(purl) {
1853
- return typeof purl === 'string' ? vendor.packageurlJsExports.PackageURL.fromString(purl) : purl;
1854
- }
1855
-
1856
1866
  const {
1857
1867
  ALERT_TYPE_CRITICAL_CVE,
1858
1868
  ALERT_TYPE_CVE,
@@ -2056,72 +2066,6 @@ function getTranslations() {
2056
2066
  return _translations;
2057
2067
  }
2058
2068
 
2059
- function extractOverridesFromPnpmLockfileContent(lockfileContent) {
2060
- return typeof lockfileContent === 'string' ? /^overrides:(\r?\n {2}.+)+(?:\r?\n)*/m.exec(lockfileContent)?.[0] ?? '' : '';
2061
- }
2062
- async function extractPurlsFromPnpmLockfile(lockfile) {
2063
- const packages = lockfile?.packages ?? {};
2064
- const seen = new Set();
2065
- const visit = pkgPath => {
2066
- if (seen.has(pkgPath)) {
2067
- return;
2068
- }
2069
- const pkg = packages[pkgPath];
2070
- if (!pkg) {
2071
- return;
2072
- }
2073
- seen.add(pkgPath);
2074
- const deps = {
2075
- __proto__: null,
2076
- ...pkg.dependencies,
2077
- ...pkg.optionalDependencies,
2078
- ...pkg.devDependencies
2079
- };
2080
- for (const depName in deps) {
2081
- const ref = deps[depName];
2082
- const subKey = isPnpmDepPath(ref) ? ref : `/${depName}@${ref}`;
2083
- visit(subKey);
2084
- }
2085
- };
2086
- for (const pkgPath of Object.keys(packages)) {
2087
- visit(pkgPath);
2088
- }
2089
- return [...seen].map(p => idToPurl(stripPnpmPeerSuffix(stripLeadingPnpmDepPathSlash(p))));
2090
- }
2091
- function isPnpmDepPath(maybeDepPath) {
2092
- return maybeDepPath.length > 0 && maybeDepPath.charCodeAt(0) === 47; /*'/'*/
2093
- }
2094
- function parsePnpmLockfile(lockfileContent) {
2095
- let result;
2096
- if (typeof lockfileContent === 'string') {
2097
- try {
2098
- result = vendor.jsYaml.load(strings.stripBom(lockfileContent));
2099
- } catch {}
2100
- }
2101
- return objects.isObjectObject(result) ? result : null;
2102
- }
2103
- function parsePnpmLockfileVersion(version) {
2104
- try {
2105
- return vendor.semverExports.coerce(version);
2106
- } catch {}
2107
- return null;
2108
- }
2109
- async function readPnpmLockfile(lockfilePath) {
2110
- return fs.existsSync(lockfilePath) ? await readFileUtf8(lockfilePath) : null;
2111
- }
2112
- function stripLeadingPnpmDepPathSlash(depPath) {
2113
- return isPnpmDepPath(depPath) ? depPath.slice(1) : depPath;
2114
- }
2115
- function stripPnpmPeerSuffix(depPath) {
2116
- const parenIndex = depPath.indexOf('(');
2117
- const index = parenIndex === -1 ? depPath.indexOf('_') : parenIndex;
2118
- return index === -1 ? depPath : depPath.slice(0, index);
2119
- }
2120
-
2121
- function idToPurl(id) {
2122
- return `pkg:npm/${id}`;
2123
- }
2124
-
2125
2069
  const ALERT_SEVERITY_COLOR = createEnum({
2126
2070
  critical: 'magenta',
2127
2071
  high: 'red',
@@ -2135,9 +2079,6 @@ const ALERT_SEVERITY_ORDER = createEnum({
2135
2079
  low: 3,
2136
2080
  none: 4
2137
2081
  });
2138
- const {
2139
- NPM: NPM$3
2140
- } = constants;
2141
2082
  const MIN_ABOVE_THE_FOLD_COUNT = 3;
2142
2083
  const MIN_ABOVE_THE_FOLD_ALERT_COUNT = 1;
2143
2084
  const format = new ColorOrMarkdown(false);
@@ -2182,10 +2123,10 @@ function getHiddenRisksDescription(riskCounts) {
2182
2123
  }
2183
2124
  return `(${descriptions.join('; ')})`;
2184
2125
  }
2185
- async function addArtifactToAlertsMap(artifact, alertsByPkgId, options) {
2126
+ async function addArtifactToAlertsMap(artifact, alertsByPurl, options) {
2186
2127
  // Make TypeScript happy.
2187
2128
  if (!artifact.name || !artifact.version || !artifact.alerts?.length) {
2188
- return alertsByPkgId;
2129
+ return alertsByPurl;
2189
2130
  }
2190
2131
  const {
2191
2132
  consolidate = false,
@@ -2208,6 +2149,7 @@ async function addArtifactToAlertsMap(artifact, alertsByPkgId, options) {
2208
2149
  };
2209
2150
  const name = packages.resolvePackageName(artifact);
2210
2151
  const {
2152
+ type: ecosystem,
2211
2153
  version
2212
2154
  } = artifact;
2213
2155
  const enabledState = {
@@ -2237,6 +2179,7 @@ async function addArtifactToAlertsMap(artifact, alertsByPkgId, options) {
2237
2179
  type: alert.type,
2238
2180
  blocked,
2239
2181
  critical,
2182
+ ecosystem,
2240
2183
  fixable,
2241
2184
  raw: alert,
2242
2185
  upgradable
@@ -2244,9 +2187,9 @@ async function addArtifactToAlertsMap(artifact, alertsByPkgId, options) {
2244
2187
  }
2245
2188
  }
2246
2189
  if (!sockPkgAlerts.length) {
2247
- return alertsByPkgId;
2190
+ return alertsByPurl;
2248
2191
  }
2249
- const pkgId = `${name}@${version}`;
2192
+ const purl = `pkg:${ecosystem}/${name}@${version}`;
2250
2193
  const major = getMajor(version);
2251
2194
  if (consolidate) {
2252
2195
  const highestForCve = new Map();
@@ -2295,9 +2238,9 @@ async function addArtifactToAlertsMap(artifact, alertsByPkgId, options) {
2295
2238
  sockPkgAlerts.sort((a, b) => sorts.naturalCompare(a.type, b.type));
2296
2239
  }
2297
2240
  if (sockPkgAlerts.length) {
2298
- alertsByPkgId.set(pkgId, sockPkgAlerts);
2241
+ alertsByPurl.set(purl, sockPkgAlerts);
2299
2242
  }
2300
- return alertsByPkgId;
2243
+ return alertsByPurl;
2301
2244
  }
2302
2245
  function alertsHaveBlocked(alerts) {
2303
2246
  return alerts.find(a => a.blocked) !== undefined;
@@ -2331,22 +2274,26 @@ function getCveInfoFromAlertsMap(alertsMap, options_) {
2331
2274
  ...options.exclude
2332
2275
  };
2333
2276
  let count = 0;
2334
- let infoByPkgName = null;
2335
- alertsMapLoop: for (const [pkgId, sockPkgAlerts] of alertsMap) {
2336
- const purlObj = vendor.packageurlJsExports.PackageURL.fromString(idToPurl(pkgId));
2277
+ let infoByPartialPurl = null;
2278
+ alertsMapLoop: for (const {
2279
+ 0: purl,
2280
+ 1: sockPkgAlerts
2281
+ } of alertsMap) {
2282
+ const purlObj = getPurlObject(purl);
2283
+ const partialPurl = new vendor.packageurlJsExports$1.PackageURL(purlObj.type, purlObj.namespace, purlObj.name).toString();
2337
2284
  const name = packages.resolvePackageName(purlObj);
2338
2285
  sockPkgAlertsLoop: for (const sockPkgAlert of sockPkgAlerts) {
2339
2286
  const alert = sockPkgAlert.raw;
2340
- if (alert.fix?.type !== ALERT_FIX_TYPE.cve || options.exclude.upgradable && registry.getManifestData(NPM$3, name)) {
2287
+ if (alert.fix?.type !== ALERT_FIX_TYPE.cve || options.exclude.upgradable && registry.getManifestData(sockPkgAlert.ecosystem, name)) {
2341
2288
  continue sockPkgAlertsLoop;
2342
2289
  }
2343
- if (!infoByPkgName) {
2344
- infoByPkgName = new Map();
2290
+ if (!infoByPartialPurl) {
2291
+ infoByPartialPurl = new Map();
2345
2292
  }
2346
- let infos = infoByPkgName.get(name);
2293
+ let infos = infoByPartialPurl.get(partialPurl);
2347
2294
  if (!infos) {
2348
2295
  infos = new Map();
2349
- infoByPkgName.set(name, infos);
2296
+ infoByPartialPurl.set(partialPurl, infos);
2350
2297
  }
2351
2298
  const {
2352
2299
  key
@@ -2365,7 +2312,7 @@ function getCveInfoFromAlertsMap(alertsMap, options_) {
2365
2312
  vulnerableVersionRange: new vendor.semverExports.Range(
2366
2313
  // Replace ', ' in a range like '>= 1.0.0, < 1.8.2' with ' ' so that
2367
2314
  // semver.Range will parse it without erroring.
2368
- vulnerableVersionRange.replace(/, +/g, ' ')).format()
2315
+ vulnerableVersionRange.replace(/, +/g, ' ').replace(/; +/g, ' || ')).format()
2369
2316
  });
2370
2317
  if (++count >= options.limit) {
2371
2318
  break alertsMapLoop;
@@ -2378,12 +2325,12 @@ function getCveInfoFromAlertsMap(alertsMap, options_) {
2378
2325
  debug.debugFn('fail: invalid SocketPackageAlert\n', alert);
2379
2326
  if (error) {
2380
2327
  // Explicitly use debugLog here.
2381
- debug.debugLog(error);
2328
+ debug.debugLog(error.message ?? error);
2382
2329
  }
2383
2330
  }
2384
2331
  }
2385
2332
  }
2386
- return infoByPkgName;
2333
+ return infoByPartialPurl;
2387
2334
  }
2388
2335
  function getSeverityLabel(severity) {
2389
2336
  return severity === 'middle' ? 'moderate' : severity;
@@ -2398,14 +2345,14 @@ function logAlertsMap(alertsMap, options) {
2398
2345
  };
2399
2346
  const translations = getTranslations();
2400
2347
  const sortedEntries = [...alertsMap.entries()].sort((a, b) => getAlertsSeverityOrder(a[1]) - getAlertsSeverityOrder(b[1]));
2401
- const aboveTheFoldPkgIds = new Set();
2402
- const viewableAlertsByPkgId = new Map();
2403
- const hiddenAlertsByPkgId = new Map();
2348
+ const aboveTheFoldPurls = new Set();
2349
+ const viewableAlertsByPurl = new Map();
2350
+ const hiddenAlertsByPurl = new Map();
2404
2351
  for (let i = 0, {
2405
2352
  length
2406
2353
  } = sortedEntries; i < length; i += 1) {
2407
2354
  const {
2408
- 0: pkgId,
2355
+ 0: purl,
2409
2356
  1: alerts
2410
2357
  } = sortedEntries[i];
2411
2358
  const hiddenAlerts = [];
@@ -2417,37 +2364,37 @@ function logAlertsMap(alertsMap, options) {
2417
2364
  return keep;
2418
2365
  });
2419
2366
  if (hiddenAlerts.length) {
2420
- hiddenAlertsByPkgId.set(pkgId, hiddenAlerts.sort(alertSeverityComparator));
2367
+ hiddenAlertsByPurl.set(purl, hiddenAlerts.sort(alertSeverityComparator));
2421
2368
  }
2422
2369
  if (!viewableAlerts.length) {
2423
2370
  continue;
2424
2371
  }
2425
2372
  viewableAlerts.sort(alertSeverityComparator);
2426
- viewableAlertsByPkgId.set(pkgId, viewableAlerts);
2373
+ viewableAlertsByPurl.set(purl, viewableAlerts);
2427
2374
  if (viewableAlerts.find(a => a.blocked || getAlertSeverityOrder(a) < ALERT_SEVERITY_ORDER.middle)) {
2428
- aboveTheFoldPkgIds.add(pkgId);
2375
+ aboveTheFoldPurls.add(purl);
2429
2376
  }
2430
2377
  }
2431
2378
 
2432
2379
  // If MIN_ABOVE_THE_FOLD_COUNT is NOT met add more from viewable pkg ids.
2433
2380
  for (const {
2434
- 0: pkgId
2435
- } of viewableAlertsByPkgId.entries()) {
2436
- if (aboveTheFoldPkgIds.size >= MIN_ABOVE_THE_FOLD_COUNT) {
2381
+ 0: purl
2382
+ } of viewableAlertsByPurl.entries()) {
2383
+ if (aboveTheFoldPurls.size >= MIN_ABOVE_THE_FOLD_COUNT) {
2437
2384
  break;
2438
2385
  }
2439
- aboveTheFoldPkgIds.add(pkgId);
2386
+ aboveTheFoldPurls.add(purl);
2440
2387
  }
2441
2388
  // If MIN_ABOVE_THE_FOLD_COUNT is STILL NOT met add more from hidden pkg ids.
2442
2389
  for (const {
2443
- 0: pkgId,
2390
+ 0: purl,
2444
2391
  1: hiddenAlerts
2445
- } of hiddenAlertsByPkgId.entries()) {
2446
- if (aboveTheFoldPkgIds.size >= MIN_ABOVE_THE_FOLD_COUNT) {
2392
+ } of hiddenAlertsByPurl.entries()) {
2393
+ if (aboveTheFoldPurls.size >= MIN_ABOVE_THE_FOLD_COUNT) {
2447
2394
  break;
2448
2395
  }
2449
- aboveTheFoldPkgIds.add(pkgId);
2450
- const viewableAlerts = viewableAlertsByPkgId.get(pkgId) ?? [];
2396
+ aboveTheFoldPurls.add(purl);
2397
+ const viewableAlerts = viewableAlertsByPurl.get(purl) ?? [];
2451
2398
  if (viewableAlerts.length < MIN_ABOVE_THE_FOLD_ALERT_COUNT) {
2452
2399
  const neededCount = MIN_ABOVE_THE_FOLD_ALERT_COUNT - viewableAlerts.length;
2453
2400
  let removedHiddenAlerts;
@@ -2455,17 +2402,17 @@ function logAlertsMap(alertsMap, options) {
2455
2402
  removedHiddenAlerts = hiddenAlerts.splice(0, MIN_ABOVE_THE_FOLD_ALERT_COUNT);
2456
2403
  } else {
2457
2404
  removedHiddenAlerts = hiddenAlerts;
2458
- hiddenAlertsByPkgId.delete(pkgId);
2405
+ hiddenAlertsByPurl.delete(purl);
2459
2406
  }
2460
- viewableAlertsByPkgId.set(pkgId, [...viewableAlerts, ...removedHiddenAlerts]);
2407
+ viewableAlertsByPurl.set(purl, [...viewableAlerts, ...removedHiddenAlerts]);
2461
2408
  }
2462
2409
  }
2463
- const mentionedPkgIdsWithHiddenAlerts = new Set();
2464
- for (let i = 0, prevAboveTheFold = true, entries = [...viewableAlertsByPkgId.entries()], {
2410
+ const mentionedPurlsWithHiddenAlerts = new Set();
2411
+ for (let i = 0, prevAboveTheFold = true, entries = [...viewableAlertsByPurl.entries()], {
2465
2412
  length
2466
2413
  } = entries; i < length; i += 1) {
2467
2414
  const {
2468
- 0: pkgId,
2415
+ 0: purl,
2469
2416
  1: alerts
2470
2417
  } = entries[i];
2471
2418
  const lines = new Set();
@@ -2485,11 +2432,12 @@ function logAlertsMap(alertsMap, options) {
2485
2432
  // TODO: emoji seems to mis-align terminals sometimes
2486
2433
  lines.add(` ${content}`);
2487
2434
  }
2488
- const purlObj = vendor.packageurlJsExports.PackageURL.fromString(idToPurl(pkgId));
2489
- const hyperlink = format.hyperlink(pkgId, getSocketDevPackageOverviewUrl(NPM$3, packages.resolvePackageName(purlObj), purlObj.version));
2490
- const isAboveTheFold = aboveTheFoldPkgIds.has(pkgId);
2435
+ const purlObj = getPurlObject(purl);
2436
+ const pkgName = packages.resolvePackageName(purlObj);
2437
+ const hyperlink = format.hyperlink(pkgName, getSocketDevPackageOverviewUrl(purlObj.type, pkgName, purlObj.version));
2438
+ const isAboveTheFold = aboveTheFoldPurls.has(purl);
2491
2439
  if (isAboveTheFold) {
2492
- aboveTheFoldPkgIds.add(pkgId);
2440
+ aboveTheFoldPurls.add(purl);
2493
2441
  output.write(`${i ? '\n' : ''}${hyperlink}:\n`);
2494
2442
  } else {
2495
2443
  output.write(`${prevAboveTheFold ? '\n' : ''}${hyperlink}:\n`);
@@ -2497,12 +2445,12 @@ function logAlertsMap(alertsMap, options) {
2497
2445
  for (const line of lines) {
2498
2446
  output.write(`${line}\n`);
2499
2447
  }
2500
- const hiddenAlerts = hiddenAlertsByPkgId.get(pkgId) ?? [];
2448
+ const hiddenAlerts = hiddenAlertsByPurl.get(purl) ?? [];
2501
2449
  const {
2502
2450
  length: hiddenAlertsCount
2503
2451
  } = hiddenAlerts;
2504
2452
  if (hiddenAlertsCount) {
2505
- mentionedPkgIdsWithHiddenAlerts.add(pkgId);
2453
+ mentionedPurlsWithHiddenAlerts.add(purl);
2506
2454
  if (hiddenAlertsCount === 1) {
2507
2455
  output.write(` ${vendor.yoctocolorsCjsExports.dim(`+1 Hidden ${getSeverityLabel(hiddenAlerts[0].raw.severity ?? 'low')} risk alert`)}\n`);
2508
2456
  } else {
@@ -2511,7 +2459,7 @@ function logAlertsMap(alertsMap, options) {
2511
2459
  }
2512
2460
  prevAboveTheFold = isAboveTheFold;
2513
2461
  }
2514
- const additionalHiddenCount = hiddenAlertsByPkgId.size - mentionedPkgIdsWithHiddenAlerts.size;
2462
+ const additionalHiddenCount = hiddenAlertsByPurl.size - mentionedPurlsWithHiddenAlerts.size;
2515
2463
  if (additionalHiddenCount) {
2516
2464
  const totalRiskCounts = {
2517
2465
  critical: 0,
@@ -2520,10 +2468,10 @@ function logAlertsMap(alertsMap, options) {
2520
2468
  low: 0
2521
2469
  };
2522
2470
  for (const {
2523
- 0: pkgId,
2471
+ 0: purl,
2524
2472
  1: alerts
2525
- } of hiddenAlertsByPkgId.entries()) {
2526
- if (mentionedPkgIdsWithHiddenAlerts.has(pkgId)) {
2473
+ } of hiddenAlertsByPurl.entries()) {
2474
+ if (mentionedPurlsWithHiddenAlerts.has(purl)) {
2527
2475
  continue;
2528
2476
  }
2529
2477
  const riskCounts = getHiddenRiskCounts(alerts);
@@ -2532,11 +2480,80 @@ function logAlertsMap(alertsMap, options) {
2532
2480
  totalRiskCounts.middle += riskCounts.middle;
2533
2481
  totalRiskCounts.low += riskCounts.low;
2534
2482
  }
2535
- output.write(`${aboveTheFoldPkgIds.size ? '\n' : ''}${vendor.yoctocolorsCjsExports.dim(`${aboveTheFoldPkgIds.size ? '+' : ''}${additionalHiddenCount} Packages with hidden alerts ${vendor.yoctocolorsCjsExports.italic(getHiddenRisksDescription(totalRiskCounts))}`)}\n`);
2483
+ output.write(`${aboveTheFoldPurls.size ? '\n' : ''}${vendor.yoctocolorsCjsExports.dim(`${aboveTheFoldPurls.size ? '+' : ''}${additionalHiddenCount} Packages with hidden alerts ${vendor.yoctocolorsCjsExports.italic(getHiddenRisksDescription(totalRiskCounts))}`)}\n`);
2536
2484
  }
2537
2485
  output.write('\n');
2538
2486
  }
2539
2487
 
2488
+ function idToNpmPurl(id) {
2489
+ return `pkg:npm/${id}`;
2490
+ }
2491
+ function idToPurl(id, type) {
2492
+ return `pkg:${type}/${id}`;
2493
+ }
2494
+
2495
+ function extractOverridesFromPnpmLockfileContent(lockfileContent) {
2496
+ return typeof lockfileContent === 'string' ? /^overrides:(\r?\n {2}.+)+(?:\r?\n)*/m.exec(lockfileContent)?.[0] ?? '' : '';
2497
+ }
2498
+ async function extractPurlsFromPnpmLockfile(lockfile) {
2499
+ const packages = lockfile?.packages ?? {};
2500
+ const seen = new Set();
2501
+ const visit = pkgPath => {
2502
+ if (seen.has(pkgPath)) {
2503
+ return;
2504
+ }
2505
+ const pkg = packages[pkgPath];
2506
+ if (!pkg) {
2507
+ return;
2508
+ }
2509
+ seen.add(pkgPath);
2510
+ const deps = {
2511
+ __proto__: null,
2512
+ ...pkg.dependencies,
2513
+ ...pkg.optionalDependencies,
2514
+ ...pkg.devDependencies
2515
+ };
2516
+ for (const depName in deps) {
2517
+ const ref = deps[depName];
2518
+ const subKey = isPnpmDepPath(ref) ? ref : `/${depName}@${ref}`;
2519
+ visit(subKey);
2520
+ }
2521
+ };
2522
+ for (const pkgPath of Object.keys(packages)) {
2523
+ visit(pkgPath);
2524
+ }
2525
+ return [...seen].map(p => idToNpmPurl(stripPnpmPeerSuffix(stripLeadingPnpmDepPathSlash(p))));
2526
+ }
2527
+ function isPnpmDepPath(maybeDepPath) {
2528
+ return maybeDepPath.length > 0 && maybeDepPath.charCodeAt(0) === 47; /*'/'*/
2529
+ }
2530
+ function parsePnpmLockfile(lockfileContent) {
2531
+ let result;
2532
+ if (typeof lockfileContent === 'string') {
2533
+ try {
2534
+ result = vendor.jsYaml.load(strings.stripBom(lockfileContent));
2535
+ } catch {}
2536
+ }
2537
+ return objects.isObjectObject(result) ? result : null;
2538
+ }
2539
+ function parsePnpmLockfileVersion(version) {
2540
+ try {
2541
+ return vendor.semverExports.coerce(version);
2542
+ } catch {}
2543
+ return null;
2544
+ }
2545
+ async function readPnpmLockfile(lockfilePath) {
2546
+ return fs.existsSync(lockfilePath) ? await readFileUtf8(lockfilePath) : null;
2547
+ }
2548
+ function stripLeadingPnpmDepPathSlash(depPath) {
2549
+ return isPnpmDepPath(depPath) ? depPath.slice(1) : depPath;
2550
+ }
2551
+ function stripPnpmPeerSuffix(depPath) {
2552
+ const parenIndex = depPath.indexOf('(');
2553
+ const index = parenIndex === -1 ? depPath.indexOf('_') : parenIndex;
2554
+ return index === -1 ? depPath : depPath.slice(0, index);
2555
+ }
2556
+
2540
2557
  async function getAlertsMapFromPnpmLockfile(lockfile, options) {
2541
2558
  const purls = await extractPurlsFromPnpmLockfile(lockfile);
2542
2559
  return await getAlertsMapFromPurls(purls, {
@@ -2572,9 +2589,9 @@ async function getAlertsMapFromPurls(purls, options_) {
2572
2589
  let {
2573
2590
  length: remaining
2574
2591
  } = uniqPurls;
2575
- const alertsByPkgId = new Map();
2592
+ const alertsByPurl = new Map();
2576
2593
  if (!remaining) {
2577
- return alertsByPkgId;
2594
+ return alertsByPurl;
2578
2595
  }
2579
2596
  const getText = () => `Looking up data for ${remaining} packages`;
2580
2597
  spinner?.start(getText());
@@ -2604,7 +2621,7 @@ async function getAlertsMapFromPurls(purls, options_) {
2604
2621
  }))
2605
2622
  })) {
2606
2623
  if (batchResult.success) {
2607
- await addArtifactToAlertsMap(batchResult.data, alertsByPkgId, alertsMapOptions);
2624
+ await addArtifactToAlertsMap(batchResult.data, alertsByPurl, alertsMapOptions);
2608
2625
  } else if (!options.nothrow) {
2609
2626
  const statusCode = batchResult.status ?? 'unknown';
2610
2627
  const statusMessage = batchResult.error ?? 'No status message';
@@ -2617,7 +2634,7 @@ async function getAlertsMapFromPurls(purls, options_) {
2617
2634
  }
2618
2635
  }
2619
2636
  spinner?.stop();
2620
- return alertsByPkgId;
2637
+ return alertsByPurl;
2621
2638
  }
2622
2639
 
2623
2640
  function npa(...args) {
@@ -3175,7 +3192,7 @@ exports.getNpmRequire = getNpmRequire;
3175
3192
  exports.getNpxBinPath = getNpxBinPath;
3176
3193
  exports.getOutputKind = getOutputKind;
3177
3194
  exports.getPackageFilesForScan = getPackageFilesForScan;
3178
- exports.getPkgFullNameFromPurlObj = getPkgFullNameFromPurlObj;
3195
+ exports.getPkgFullNameFromPurl = getPkgFullNameFromPurl;
3179
3196
  exports.getPublicToken = getPublicToken;
3180
3197
  exports.getPurlObject = getPurlObject;
3181
3198
  exports.getSeverityCount = getSeverityCount;
@@ -3188,6 +3205,7 @@ exports.handleApiCall = handleApiCall;
3188
3205
  exports.handleApiCallNoSpinner = handleApiCallNoSpinner;
3189
3206
  exports.handleUnsuccessfulApiResponse = handleUnsuccessfulApiResponse;
3190
3207
  exports.hasDefaultToken = hasDefaultToken;
3208
+ exports.idToNpmPurl = idToNpmPurl;
3191
3209
  exports.idToPurl = idToPurl;
3192
3210
  exports.isHelpFlag = isHelpFlag;
3193
3211
  exports.isNpmBinPathShadowed = isNpmBinPathShadowed;
@@ -3222,5 +3240,5 @@ exports.updateConfigValue = updateConfigValue;
3222
3240
  exports.validationFlags = validationFlags;
3223
3241
  exports.walkNestedMap = walkNestedMap;
3224
3242
  exports.writeSocketJson = writeSocketJson;
3225
- //# debugId=bf60df12-bcc2-4bec-9805-5a2aace6e3a3
3243
+ //# debugId=c940586c-7f80-4e5e-ab46-bf967fcb3730
3226
3244
  //# sourceMappingURL=utils.js.map