@socketsecurity/cli-with-sentry 0.14.114 → 0.14.116

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.
@@ -0,0 +1,63 @@
1
+ /// <reference types="node" />
2
+ import { Remap } from '@socketsecurity/registry/lib/objects'
3
+ import { Abortable } from 'node:events'
4
+ import {
5
+ ObjectEncodingOptions,
6
+ OpenMode,
7
+ PathLike,
8
+ PathOrFileDescriptor
9
+ } from 'node:fs'
10
+ import { FileHandle } from 'node:fs/promises'
11
+ declare function removeNodeModules(cwd?: string): Promise<void>
12
+ type FindUpOptions = {
13
+ cwd?: string | undefined
14
+ signal?: AbortSignal | undefined
15
+ }
16
+ declare function findUp(
17
+ name: string | string[],
18
+ { cwd, signal }: FindUpOptions
19
+ ): Promise<string | undefined>
20
+ type ReadFileOptions = Remap<
21
+ ObjectEncodingOptions &
22
+ Abortable & {
23
+ flag?: OpenMode | undefined
24
+ }
25
+ >
26
+ declare function readFileBinary(
27
+ filepath: PathLike | FileHandle,
28
+ options?: ReadFileOptions | undefined
29
+ ): Promise<Buffer>
30
+ declare function readFileUtf8(
31
+ filepath: PathLike | FileHandle,
32
+ options?: ReadFileOptions | undefined
33
+ ): Promise<string>
34
+ declare function safeReadFile(
35
+ filepath: PathLike | FileHandle,
36
+ options?:
37
+ | 'utf8'
38
+ | 'utf-8'
39
+ | {
40
+ encoding: 'utf8' | 'utf-8'
41
+ }
42
+ | undefined
43
+ ): Promise<string | undefined>
44
+ declare function safeReadFileSync(
45
+ filepath: PathOrFileDescriptor,
46
+ options?:
47
+ | 'utf8'
48
+ | 'utf-8'
49
+ | {
50
+ encoding: 'utf8' | 'utf-8'
51
+ }
52
+ | undefined
53
+ ): string | undefined
54
+ export {
55
+ removeNodeModules,
56
+ FindUpOptions,
57
+ findUp,
58
+ ReadFileOptions,
59
+ readFileBinary,
60
+ readFileUtf8,
61
+ safeReadFile,
62
+ safeReadFileSync
63
+ }
@@ -18,12 +18,248 @@ const sdk = require('@socketsecurity/sdk')
18
18
  const fs = require('node:fs')
19
19
  const os = require('node:os')
20
20
  const path = require('node:path')
21
- const promises = require('node:timers/promises')
21
+ const fs$1 = require('@socketsecurity/registry/lib/fs')
22
22
  const packages = require('@socketsecurity/registry/lib/packages')
23
+ const promises = require('node:timers/promises')
23
24
  const sorts = require('@socketsecurity/registry/lib/sorts')
24
25
  const indentString = require('@socketregistry/indent-string/index.cjs')
25
26
 
27
+ const { NPM: NPM$3, PNPM } = constants
28
+ const PNPM_WORKSPACE = `${PNPM}-workspace`
29
+ const ignoredDirs = [
30
+ // Taken from ignore-by-default:
31
+ // https://github.com/novemberborn/ignore-by-default/blob/v2.1.0/index.js
32
+ '.git',
33
+ // Git repository files, see <https://git-scm.com/>
34
+ '.log',
35
+ // Log files emitted by tools such as `tsserver`, see <https://github.com/Microsoft/TypeScript/wiki/Standalone-Server-%28tsserver%29>
36
+ '.nyc_output',
37
+ // Temporary directory where nyc stores coverage data, see <https://github.com/bcoe/nyc>
38
+ '.sass-cache',
39
+ // Cache folder for node-sass, see <https://github.com/sass/node-sass>
40
+ '.yarn',
41
+ // Where node modules are installed when using Yarn, see <https://yarnpkg.com/>
42
+ 'bower_components',
43
+ // Where Bower packages are installed, see <http://bower.io/>
44
+ 'coverage',
45
+ // Standard output directory for code coverage reports, see <https://github.com/gotwarlost/istanbul>
46
+ 'node_modules',
47
+ // Where Node modules are installed, see <https://nodejs.org/>
48
+ // Taken from globby:
49
+ // https://github.com/sindresorhus/globby/blob/v14.0.2/ignore.js#L11-L16
50
+ 'flow-typed'
51
+ ]
52
+ const ignoredDirPatterns = ignoredDirs.map(i => `**/${i}`)
53
+ async function getWorkspaceGlobs(agent, cwd = process$1.cwd()) {
54
+ let workspacePatterns
55
+ if (agent === PNPM) {
56
+ for (const workspacePath of [
57
+ path.join(cwd, `${PNPM_WORKSPACE}.yaml`),
58
+ path.join(cwd, `${PNPM_WORKSPACE}.yml`)
59
+ ]) {
60
+ // eslint-disable-next-line no-await-in-loop
61
+ const yml = await safeReadFile(workspacePath)
62
+ if (yml) {
63
+ try {
64
+ workspacePatterns = vendor.distExports$1.parse(yml)?.packages
65
+ } catch {}
66
+ if (workspacePatterns) {
67
+ break
68
+ }
69
+ }
70
+ }
71
+ } else {
72
+ workspacePatterns = (
73
+ await packages.readPackageJson(cwd, {
74
+ throws: false
75
+ })
76
+ )?.['workspaces']
77
+ }
78
+ return Array.isArray(workspacePatterns)
79
+ ? workspacePatterns
80
+ .filter(strings.isNonEmptyString)
81
+ .map(workspacePatternToGlobPattern)
82
+ : []
83
+ }
84
+ function ignoreFileLinesToGlobPatterns(lines, filepath, cwd) {
85
+ const base = path.relative(cwd, path.dirname(filepath)).replace(/\\/g, '/')
86
+ const patterns = []
87
+ for (let i = 0, { length } = lines; i < length; i += 1) {
88
+ const pattern = lines[i].trim()
89
+ if (pattern.length > 0 && pattern.charCodeAt(0) !== 35 /*'#'*/) {
90
+ patterns.push(
91
+ ignorePatternToMinimatch(
92
+ pattern.length && pattern.charCodeAt(0) === 33 /*'!'*/
93
+ ? `!${path.posix.join(base, pattern.slice(1))}`
94
+ : path.posix.join(base, pattern)
95
+ )
96
+ )
97
+ }
98
+ }
99
+ return patterns
100
+ }
101
+ function ignoreFileToGlobPatterns(content, filepath, cwd) {
102
+ return ignoreFileLinesToGlobPatterns(content.split(/\r?\n/), filepath, cwd)
103
+ }
104
+
105
+ // Based on `@eslint/compat` convertIgnorePatternToMinimatch.
106
+ // Apache v2.0 licensed
107
+ // Copyright Nicholas C. Zakas
108
+ // https://github.com/eslint/rewrite/blob/compat-v1.2.1/packages/compat/src/ignore-file.js#L28
109
+ function ignorePatternToMinimatch(pattern) {
110
+ const isNegated = pattern.startsWith('!')
111
+ const negatedPrefix = isNegated ? '!' : ''
112
+ const patternToTest = (isNegated ? pattern.slice(1) : pattern).trimEnd()
113
+ // Special cases.
114
+ if (
115
+ patternToTest === '' ||
116
+ patternToTest === '**' ||
117
+ patternToTest === '/**' ||
118
+ patternToTest === '**'
119
+ ) {
120
+ return `${negatedPrefix}${patternToTest}`
121
+ }
122
+ const firstIndexOfSlash = patternToTest.indexOf('/')
123
+ const matchEverywherePrefix =
124
+ firstIndexOfSlash === -1 || firstIndexOfSlash === patternToTest.length - 1
125
+ ? '**/'
126
+ : ''
127
+ const patternWithoutLeadingSlash =
128
+ firstIndexOfSlash === 0 ? patternToTest.slice(1) : patternToTest
129
+ // Escape `{` and `(` because in gitignore patterns they are just
130
+ // literal characters without any specific syntactic meaning,
131
+ // while in minimatch patterns they can form brace expansion or extglob syntax.
132
+ //
133
+ // For example, gitignore pattern `src/{a,b}.js` ignores file `src/{a,b}.js`.
134
+ // But, the same minimatch pattern `src/{a,b}.js` ignores files `src/a.js` and `src/b.js`.
135
+ // Minimatch pattern `src/\{a,b}.js` is equivalent to gitignore pattern `src/{a,b}.js`.
136
+ const escapedPatternWithoutLeadingSlash =
137
+ patternWithoutLeadingSlash.replaceAll(
138
+ /(?=((?:\\.|[^{(])*))\1([{(])/guy,
139
+ '$1\\$2'
140
+ )
141
+ const matchInsideSuffix = patternToTest.endsWith('/**') ? '/*' : ''
142
+ return `${negatedPrefix}${matchEverywherePrefix}${escapedPatternWithoutLeadingSlash}${matchInsideSuffix}`
143
+ }
144
+ function workspacePatternToGlobPattern(workspace) {
145
+ const { length } = workspace
146
+ if (!length) {
147
+ return ''
148
+ }
149
+ // If the workspace ends with "/"
150
+ if (workspace.charCodeAt(length - 1) === 47 /*'/'*/) {
151
+ return `${workspace}/*/package.json`
152
+ }
153
+ // If the workspace ends with "/**"
154
+ if (
155
+ workspace.charCodeAt(length - 1) === 42 /*'*'*/ &&
156
+ workspace.charCodeAt(length - 2) === 42 /*'*'*/ &&
157
+ workspace.charCodeAt(length - 3) === 47 /*'/'*/
158
+ ) {
159
+ return `${workspace}/*/**/package.json`
160
+ }
161
+ // Things like "packages/a" or "packages/*"
162
+ return `${workspace}/package.json`
163
+ }
164
+ async function filterGlobResultToSupportedFiles(entries, supportedFiles) {
165
+ const patterns = ['golang', NPM$3, 'maven', 'pypi', 'gem', 'nuget'].reduce(
166
+ (r, n) => {
167
+ const supported = supportedFiles[n]
168
+ r.push(
169
+ ...(supported
170
+ ? Object.values(supported).map(p => `**/${p.pattern}`)
171
+ : [])
172
+ )
173
+ return r
174
+ },
175
+ []
176
+ )
177
+ return entries.filter(p => vendor.micromatchExports.some(p, patterns))
178
+ }
179
+ async function globWithGitIgnore(patterns, options) {
180
+ const {
181
+ cwd = process$1.cwd(),
182
+ socketConfig,
183
+ ...additionalOptions
184
+ } = {
185
+ __proto__: null,
186
+ ...options
187
+ }
188
+ const projectIgnorePaths = socketConfig?.projectIgnorePaths
189
+ const ignoreFiles = await vendor.distExports.glob(['**/.gitignore'], {
190
+ absolute: true,
191
+ cwd,
192
+ expandDirectories: true
193
+ })
194
+ const ignores = [
195
+ ...ignoredDirPatterns,
196
+ ...(Array.isArray(projectIgnorePaths)
197
+ ? ignoreFileLinesToGlobPatterns(
198
+ projectIgnorePaths,
199
+ path.join(cwd, '.gitignore'),
200
+ cwd
201
+ )
202
+ : []),
203
+ ...(
204
+ await Promise.all(
205
+ ignoreFiles.map(async filepath =>
206
+ ignoreFileToGlobPatterns(
207
+ await fs.promises.readFile(filepath, 'utf8'),
208
+ filepath,
209
+ cwd
210
+ )
211
+ )
212
+ )
213
+ ).flat()
214
+ ]
215
+ const hasNegatedPattern = ignores.some(p => p.charCodeAt(0) === 33 /*'!'*/)
216
+ const globOptions = {
217
+ absolute: true,
218
+ cwd,
219
+ expandDirectories: false,
220
+ ignore: hasNegatedPattern ? [] : ignores,
221
+ ...additionalOptions
222
+ }
223
+ const result = await vendor.distExports.glob(patterns, globOptions)
224
+ if (!hasNegatedPattern) {
225
+ return result
226
+ }
227
+ const { absolute } = globOptions
228
+
229
+ // Note: the input files must be INSIDE the cwd. If you get strange looking
230
+ // relative path errors here, most likely your path is outside the given cwd.
231
+ const filtered = vendor
232
+ .ignoreExports()
233
+ .add(ignores)
234
+ .filter(absolute ? result.map(p => path.relative(cwd, p)) : result)
235
+ return absolute ? filtered.map(p => path.resolve(cwd, p)) : filtered
236
+ }
237
+ async function globNodeModules(cwd = process$1.cwd()) {
238
+ return await vendor.distExports.glob('**/node_modules/**', {
239
+ absolute: true,
240
+ cwd
241
+ })
242
+ }
243
+ async function globWorkspace(agent, cwd = process$1.cwd()) {
244
+ const workspaceGlobs = await getWorkspaceGlobs(agent, cwd)
245
+ return workspaceGlobs.length
246
+ ? await vendor.distExports.glob(workspaceGlobs, {
247
+ absolute: true,
248
+ cwd,
249
+ ignore: ['**/node_modules/**', '**/bower_components/**']
250
+ })
251
+ : []
252
+ }
253
+ function pathsToGlobPatterns(paths) {
254
+ // TODO: Does not support `~/` paths.
255
+ return paths.map(p => (p === '.' || p === './' ? '**/*' : p))
256
+ }
257
+
26
258
  const { abortSignal } = constants
259
+ async function removeNodeModules(cwd = process$1.cwd()) {
260
+ const nodeModulesPaths = await globNodeModules(cwd)
261
+ await Promise.all(nodeModulesPaths.map(p => fs$1.remove(p)))
262
+ }
27
263
  async function findUp(name, { cwd = process$1.cwd(), signal = abortSignal }) {
28
264
  let dir = path.resolve(cwd)
29
265
  const { root } = path.parse(dir)
@@ -391,7 +627,7 @@ async function setupSdk(
391
627
  // The '@rollup/plugin-replace' will replace "process.env['INLINED_SOCKET_CLI_NAME']".
392
628
  name: '@socketsecurity/cli',
393
629
  // The '@rollup/plugin-replace' will replace "process.env['INLINED_SOCKET_CLI_VERSION']".
394
- version: '0.14.114',
630
+ version: '0.14.116',
395
631
  // The '@rollup/plugin-replace' will replace "process.env['INLINED_SOCKET_CLI_HOMEPAGE']".
396
632
  homepage: 'https://github.com/SocketDev/socket-cli'
397
633
  })
@@ -1193,19 +1429,36 @@ function findBestPatchVersion(
1193
1429
  let eligibleVersions
1194
1430
  if (manifestData && manifestData.name === manifestData.package) {
1195
1431
  const major = vendor.semverExports.major(manifestData.version)
1196
- eligibleVersions = availableVersions.filter(
1197
- v => vendor.semverExports.major(v) === major
1198
- )
1432
+ eligibleVersions = availableVersions.filter(v => {
1433
+ const coerced = vendor.semverExports.coerce(v)
1434
+ if (coerced) {
1435
+ try {
1436
+ return vendor.semverExports.major(coerced) === major
1437
+ } catch (e) {
1438
+ debug.debugLog(`Error parsing '${v}'`, e)
1439
+ }
1440
+ }
1441
+ return false
1442
+ })
1199
1443
  } else {
1200
1444
  const major = vendor.semverExports.major(node.version)
1201
- eligibleVersions = availableVersions.filter(
1202
- v =>
1445
+ eligibleVersions = availableVersions.filter(v => {
1446
+ const coerced = vendor.semverExports.coerce(v)
1447
+ try {
1203
1448
  // Filter for versions that are within the current major version and
1204
1449
  // are NOT in the vulnerable range.
1205
- vendor.semverExports.major(v) === major &&
1206
- (!vulnerableVersionRange ||
1207
- !vendor.semverExports.satisfies(v, vulnerableVersionRange))
1208
- )
1450
+ if (coerced) {
1451
+ return (
1452
+ vendor.semverExports.major(coerced) === major &&
1453
+ (!vulnerableVersionRange ||
1454
+ !vendor.semverExports.satisfies(v, vulnerableVersionRange))
1455
+ )
1456
+ }
1457
+ } catch (e) {
1458
+ debug.debugLog(`Error parsing '${v}'`, e)
1459
+ }
1460
+ return false
1461
+ })
1209
1462
  }
1210
1463
  return vendor.semverExports.maxSatisfying(eligibleVersions, '*')
1211
1464
  }
@@ -1417,13 +1670,9 @@ function updatePackageJsonFromNode(
1417
1670
  ) {
1418
1671
  let result = false
1419
1672
  if (!isTopLevel(tree, node)) {
1420
- debug.debugLog('not top level', node)
1421
- debug.debugLog('tree.children', tree.children)
1422
1673
  return result
1423
1674
  }
1424
1675
  const { name } = node
1425
- debug.debugLog('name', name)
1426
- debug.debugLog('editablePkgJson.content', editablePkgJson.content)
1427
1676
  for (const depField of [
1428
1677
  'dependencies',
1429
1678
  'optionalDependencies',
@@ -2331,6 +2580,7 @@ exports.SAFE_ARBORIST_REIFY_OPTIONS_OVERRIDES =
2331
2580
  exports.SafeArborist = SafeArborist
2332
2581
  exports.applyRange = applyRange
2333
2582
  exports.captureException = captureException
2583
+ exports.filterGlobResultToSupportedFiles = filterGlobResultToSupportedFiles
2334
2584
  exports.findBestPatchVersion = findBestPatchVersion
2335
2585
  exports.findPackageNode = findPackageNode
2336
2586
  exports.findPackageNodes = findPackageNodes
@@ -2346,11 +2596,15 @@ exports.getPublicToken = getPublicToken
2346
2596
  exports.getSeverityCount = getSeverityCount
2347
2597
  exports.getSocketDevAlertUrl = getSocketDevAlertUrl
2348
2598
  exports.getSocketDevPackageOverviewUrl = getSocketDevPackageOverviewUrl
2599
+ exports.globWithGitIgnore = globWithGitIgnore
2600
+ exports.globWorkspace = globWorkspace
2349
2601
  exports.isReadOnlyConfig = isReadOnlyConfig
2350
2602
  exports.overrideCachedConfig = overrideCachedConfig
2351
2603
  exports.overrideConfigApiToken = overrideConfigApiToken
2604
+ exports.pathsToGlobPatterns = pathsToGlobPatterns
2352
2605
  exports.readFileBinary = readFileBinary
2353
2606
  exports.readFileUtf8 = readFileUtf8
2607
+ exports.removeNodeModules = removeNodeModules
2354
2608
  exports.safeReadFile = safeReadFile
2355
2609
  exports.sensitiveConfigKeys = sensitiveConfigKeys
2356
2610
  exports.setupSdk = setupSdk
@@ -2358,5 +2612,5 @@ exports.supportedConfigKeys = supportedConfigKeys
2358
2612
  exports.updateConfigValue = updateConfigValue
2359
2613
  exports.updateNode = updateNode
2360
2614
  exports.updatePackageJsonFromNode = updatePackageJsonFromNode
2361
- //# debugId=992f3ef2-20a6-4ad5-b2ae-9b967b041eba
2615
+ //# debugId=5a309826-f704-4471-96b5-cdefeafaf366
2362
2616
  //# sourceMappingURL=shadow-npm-inject.js.map