@socketsecurity/cli-with-sentry 0.14.77 → 0.14.78

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.
@@ -11,9 +11,6 @@ declare const AGENTS: readonly [
11
11
  'vlt'
12
12
  ]
13
13
  type Agent = (typeof AGENTS)[number]
14
- type StringKeyValueObject = {
15
- [key: string]: string
16
- }
17
14
  type DetectOptions = {
18
15
  cwd?: string | undefined
19
16
  onUnknown?: (pkgManager: string | undefined) => void
@@ -77,7 +74,6 @@ declare function detectAndValidatePackageEnvironment(
77
74
  export {
78
75
  AGENTS,
79
76
  Agent,
80
- StringKeyValueObject,
81
77
  DetectOptions,
82
78
  EnvDetails,
83
79
  PartialEnvDetails,
@@ -406,7 +406,7 @@ async function setupSdk(
406
406
  // The '@rollup/plugin-replace' will replace "process.env['INLINED_SOCKET_CLI_NAME']".
407
407
  name: '@socketsecurity/cli',
408
408
  // The '@rollup/plugin-replace' will replace "process.env['INLINED_SOCKET_CLI_VERSION']".
409
- version: '0.14.77',
409
+ version: '0.14.78',
410
410
  // The '@rollup/plugin-replace' will replace "process.env['INLINED_SOCKET_CLI_HOMEPAGE']".
411
411
  homepage: 'https://github.com/SocketDev/socket-cli'
412
412
  })
@@ -1843,7 +1843,31 @@ function findBestPatchVersion(
1843
1843
  }
1844
1844
  return semver.maxSatisfying(eligibleVersions, '*')
1845
1845
  }
1846
- function findPackageNodes(tree, packageName) {
1846
+ function findPackageNode(tree, name, version) {
1847
+ const queue = [
1848
+ {
1849
+ node: tree
1850
+ }
1851
+ ]
1852
+ let sentinel = 0
1853
+ while (queue.length) {
1854
+ if (sentinel++ === LOOP_SENTINEL) {
1855
+ throw new Error('Detected infinite loop in findPackageNodes')
1856
+ }
1857
+ const { node: currentNode } = queue.pop()
1858
+ const node = currentNode.children.get(name)
1859
+ if (node && (typeof version !== 'string' || node.version === version)) {
1860
+ return node
1861
+ }
1862
+ const children = [...currentNode.children.values()]
1863
+ for (let i = children.length - 1; i >= 0; i -= 1) {
1864
+ queue.push({
1865
+ node: children[i]
1866
+ })
1867
+ }
1868
+ }
1869
+ }
1870
+ function findPackageNodes(tree, name, version) {
1847
1871
  const queue = [
1848
1872
  {
1849
1873
  node: tree
@@ -1856,8 +1880,8 @@ function findPackageNodes(tree, packageName) {
1856
1880
  throw new Error('Detected infinite loop in findPackageNodes')
1857
1881
  }
1858
1882
  const { node: currentNode } = queue.pop()
1859
- const node = currentNode.children.get(packageName)
1860
- if (node) {
1883
+ const node = currentNode.children.get(name)
1884
+ if (node && 'undefined' !== 'string') {
1861
1885
  matches.push(node)
1862
1886
  }
1863
1887
  const children = [...currentNode.children.values()]
@@ -1878,6 +1902,7 @@ async function getAlertsMapFromArborist(arb, options_) {
1878
1902
  }
1879
1903
  const include = {
1880
1904
  __proto__: null,
1905
+ actions: undefined,
1881
1906
  blocked: true,
1882
1907
  critical: true,
1883
1908
  cve: true,
@@ -1924,7 +1949,16 @@ async function getAlertsMapFromArborist(arb, options_) {
1924
1949
  {
1925
1950
  alerts: 'true',
1926
1951
  compact: 'true',
1927
- fixable: include.unfixable ? 'false' : 'true'
1952
+ ...(include.actions
1953
+ ? {
1954
+ actions: include.actions.join(',')
1955
+ }
1956
+ : {}),
1957
+ ...(include.unfixable
1958
+ ? {}
1959
+ : {
1960
+ fixable: 'true'
1961
+ })
1928
1962
  },
1929
1963
  {
1930
1964
  components: pkgIds.map(id => ({
@@ -1954,6 +1988,9 @@ async function getAlertsMapFromArborist(arb, options_) {
1954
1988
  spinner?.stop()
1955
1989
  return alertsByPkgId
1956
1990
  }
1991
+ function isTopLevel(tree, node) {
1992
+ return tree.children.get(node.name) === node
1993
+ }
1957
1994
  function updateNode(
1958
1995
  node,
1959
1996
  packument,
@@ -1975,27 +2012,33 @@ function updateNode(
1975
2012
  // No suitable patch version found.
1976
2013
  return false
1977
2014
  }
1978
- // Use Object.defineProperty to override the version.
2015
+ // Object.defineProperty is needed to set the version property and replace
2016
+ // the old value with targetVersion.
1979
2017
  Object.defineProperty(node, 'version', {
1980
2018
  configurable: true,
1981
2019
  enumerable: true,
1982
2020
  get: () => targetVersion
1983
2021
  })
2022
+ // Update package.version associated with the node.
1984
2023
  node.package.version = targetVersion
1985
- // Update resolved and clear integrity for the new version.
2024
+ // Update node.resolved.
1986
2025
  const purlObj = packageurlJs.PackageURL.fromString(`pkg:npm/${node.name}`)
1987
2026
  node.resolved = `${NPM_REGISTRY_URL}/${node.name}/-/${purlObj.name}-${targetVersion}.tgz`
2027
+ // Update node.integrity with the targetPackument.dist.integrity value if available
2028
+ // else delete node.integrity so a new value is resolved for the target version.
1988
2029
  const { integrity } = targetPackument.dist
1989
2030
  if (integrity) {
1990
2031
  node.integrity = integrity
1991
2032
  } else {
1992
2033
  delete node.integrity
1993
2034
  }
1994
- if ('deprecated' in targetPackument) {
2035
+ // Update node.package.deprecated based on targetPackument.deprecated.
2036
+ if (objects.hasOwn(targetPackument, 'deprecated')) {
1995
2037
  node.package['deprecated'] = targetPackument.deprecated
1996
2038
  } else {
1997
2039
  delete node.package['deprecated']
1998
2040
  }
2041
+ // Update node.package.dependencies.
1999
2042
  const newDeps = {
2000
2043
  ...targetPackument.dependencies
2001
2044
  }
@@ -2004,12 +2047,16 @@ function updateNode(
2004
2047
  if (oldDeps) {
2005
2048
  for (const oldDepName of Object.keys(oldDeps)) {
2006
2049
  if (!objects.hasOwn(newDeps, oldDepName)) {
2050
+ // Detach old edges for dependencies that don't exist on the updated
2051
+ // node.package.dependencies.
2007
2052
  node.edgesOut.get(oldDepName)?.detach()
2008
2053
  }
2009
2054
  }
2010
2055
  }
2011
2056
  for (const newDepName of Object.keys(newDeps)) {
2012
2057
  if (!objects.hasOwn(oldDeps, newDepName)) {
2058
+ // Add new edges for dependencies that don't exist on the old
2059
+ // node.package.dependencies.
2013
2060
  node.addEdgeOut(
2014
2061
  new Edge({
2015
2062
  from: node,
@@ -2022,6 +2069,30 @@ function updateNode(
2022
2069
  }
2023
2070
  return true
2024
2071
  }
2072
+ function updatePackageJsonFromNode(editablePkgJson, tree, node) {
2073
+ if (isTopLevel(tree, node)) {
2074
+ const { name, version } = node
2075
+ for (const depField of [
2076
+ 'dependencies',
2077
+ 'optionalDependencies',
2078
+ 'peerDependencies'
2079
+ ]) {
2080
+ const oldValue = editablePkgJson.content[depField]
2081
+ if (oldValue) {
2082
+ const oldVersion = oldValue[name]
2083
+ if (oldVersion) {
2084
+ const rangeDecorator = /^[~^]/.exec(oldVersion)?.[0] ?? ''
2085
+ editablePkgJson.update({
2086
+ [depField]: {
2087
+ ...oldValue,
2088
+ [name]: `${rangeDecorator}${version}`
2089
+ }
2090
+ })
2091
+ }
2092
+ }
2093
+ }
2094
+ }
2095
+ }
2025
2096
 
2026
2097
  const {
2027
2098
  NPM,
@@ -2103,6 +2174,10 @@ class SafeArborist extends Arborist {
2103
2174
  // @ts-ignore: TS gets grumpy about rest parameters.
2104
2175
  ...args.slice(1)
2105
2176
  )
2177
+ // Lazily access constants.ENV[SOCKET_CLI_ACCEPT_RISKS].
2178
+ const acceptRisks = constants.ENV[SOCKET_CLI_ACCEPT_RISKS]
2179
+ // Lazily access constants.ENV[SOCKET_CLI_VIEW_ALL_RISKS].
2180
+ const viewAllRisks = constants.ENV[SOCKET_CLI_VIEW_ALL_RISKS]
2106
2181
  const progress = ipc[SOCKET_CLI_SAFE_PROGRESS]
2107
2182
  const spinner =
2108
2183
  options['silent'] || !progress
@@ -2114,14 +2189,13 @@ class SafeArborist extends Arborist {
2114
2189
  const alertsMap = await getAlertsMapFromArborist(this, {
2115
2190
  spinner,
2116
2191
  include:
2117
- options.dryRun ||
2118
- options['yes'] ||
2119
- // Lazily access constants.ENV[SOCKET_CLI_ACCEPT_RISKS].
2120
- constants.ENV[SOCKET_CLI_ACCEPT_RISKS]
2192
+ acceptRisks || options.dryRun || options['yes']
2121
2193
  ? {
2194
+ actions: ['error'],
2122
2195
  blocked: true,
2123
2196
  critical: false,
2124
2197
  cve: false,
2198
+ existing: true,
2125
2199
  unfixable: false
2126
2200
  }
2127
2201
  : {
@@ -2132,17 +2206,16 @@ class SafeArborist extends Arborist {
2132
2206
  if (alertsMap.size) {
2133
2207
  process$1.exitCode = 1
2134
2208
  logAlertsMap(alertsMap, {
2135
- // Lazily access constants.ENV[SOCKET_CLI_VIEW_ALL_RISKS].
2136
- hideAt: constants.ENV[SOCKET_CLI_VIEW_ALL_RISKS] ? 'none' : 'middle',
2209
+ hideAt: viewAllRisks ? 'none' : 'middle',
2137
2210
  output: process$1.stderr
2138
2211
  })
2139
2212
  throw new Error(commonTags.stripIndents`
2140
- Socket ${binName} exiting due to risks.
2141
- View all risks - Rerun with environment variable ${SOCKET_CLI_VIEW_ALL_RISKS}=1.
2142
- Accept risks - Rerun with environment variable ${SOCKET_CLI_ACCEPT_RISKS}=1.
2213
+ Socket ${binName} exiting due to risks.${viewAllRisks ? '' : `\nView all risks - Rerun with environment variable ${SOCKET_CLI_VIEW_ALL_RISKS}=1.`}${acceptRisks ? '' : `\nAccept risks - Rerun with environment variable ${SOCKET_CLI_ACCEPT_RISKS}=1.`}
2143
2214
  `)
2144
2215
  } else if (!options['silent']) {
2145
- logger.logger.success(`Socket ${binName} found no risks!`)
2216
+ logger.logger.success(
2217
+ `Socket ${binName} ${acceptRisks ? 'accepted' : 'found no'} risks`
2218
+ )
2146
2219
  if (binName === NPX) {
2147
2220
  logger.logger.log(`Running ${options.add[0]}`)
2148
2221
  }
@@ -2182,6 +2255,7 @@ exports.SafeArborist = SafeArborist
2182
2255
  exports.addArtifactToAlertsMap = addArtifactToAlertsMap
2183
2256
  exports.captureException = captureException
2184
2257
  exports.findBestPatchVersion = findBestPatchVersion
2258
+ exports.findPackageNode = findPackageNode
2185
2259
  exports.findPackageNodes = findPackageNodes
2186
2260
  exports.findUp = findUp
2187
2261
  exports.formatSeverityCount = formatSeverityCount
@@ -2204,5 +2278,6 @@ exports.setupSdk = setupSdk
2204
2278
  exports.supportedConfigKeys = supportedConfigKeys
2205
2279
  exports.updateConfigValue = updateConfigValue
2206
2280
  exports.updateNode = updateNode
2207
- //# debugId=c9cead2a-fe3b-4520-bcb7-22b65cf339e6
2281
+ exports.updatePackageJsonFromNode = updatePackageJsonFromNode
2282
+ //# debugId=614f78b2-1784-408d-8999-6c772d924dc8
2208
2283
  //# sourceMappingURL=shadow-npm-inject.js.map