@socketsecurity/cli-with-sentry 0.14.113 → 0.14.115

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.113',
630
+ version: '0.14.115',
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
  })
@@ -1417,13 +1653,9 @@ function updatePackageJsonFromNode(
1417
1653
  ) {
1418
1654
  let result = false
1419
1655
  if (!isTopLevel(tree, node)) {
1420
- debug.debugLog('not top level', node)
1421
- debug.debugLog('tree.children', tree.children)
1422
1656
  return result
1423
1657
  }
1424
1658
  const { name } = node
1425
- debug.debugLog('name', name)
1426
- debug.debugLog('editablePkgJson.content', editablePkgJson.content)
1427
1659
  for (const depField of [
1428
1660
  'dependencies',
1429
1661
  'optionalDependencies',
@@ -2331,6 +2563,7 @@ exports.SAFE_ARBORIST_REIFY_OPTIONS_OVERRIDES =
2331
2563
  exports.SafeArborist = SafeArborist
2332
2564
  exports.applyRange = applyRange
2333
2565
  exports.captureException = captureException
2566
+ exports.filterGlobResultToSupportedFiles = filterGlobResultToSupportedFiles
2334
2567
  exports.findBestPatchVersion = findBestPatchVersion
2335
2568
  exports.findPackageNode = findPackageNode
2336
2569
  exports.findPackageNodes = findPackageNodes
@@ -2346,11 +2579,15 @@ exports.getPublicToken = getPublicToken
2346
2579
  exports.getSeverityCount = getSeverityCount
2347
2580
  exports.getSocketDevAlertUrl = getSocketDevAlertUrl
2348
2581
  exports.getSocketDevPackageOverviewUrl = getSocketDevPackageOverviewUrl
2582
+ exports.globWithGitIgnore = globWithGitIgnore
2583
+ exports.globWorkspace = globWorkspace
2349
2584
  exports.isReadOnlyConfig = isReadOnlyConfig
2350
2585
  exports.overrideCachedConfig = overrideCachedConfig
2351
2586
  exports.overrideConfigApiToken = overrideConfigApiToken
2587
+ exports.pathsToGlobPatterns = pathsToGlobPatterns
2352
2588
  exports.readFileBinary = readFileBinary
2353
2589
  exports.readFileUtf8 = readFileUtf8
2590
+ exports.removeNodeModules = removeNodeModules
2354
2591
  exports.safeReadFile = safeReadFile
2355
2592
  exports.sensitiveConfigKeys = sensitiveConfigKeys
2356
2593
  exports.setupSdk = setupSdk
@@ -2358,5 +2595,5 @@ exports.supportedConfigKeys = supportedConfigKeys
2358
2595
  exports.updateConfigValue = updateConfigValue
2359
2596
  exports.updateNode = updateNode
2360
2597
  exports.updatePackageJsonFromNode = updatePackageJsonFromNode
2361
- //# debugId=8aedd63e-0637-460e-91a4-99790be76418
2598
+ //# debugId=c60480dd-5d67-4120-8205-1ffbb6b16f91
2362
2599
  //# sourceMappingURL=shadow-npm-inject.js.map