@socketsecurity/cli-with-sentry 1.0.79 → 1.0.80

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.
package/dist/utils.js CHANGED
@@ -3,7 +3,7 @@
3
3
  var vendor = require('./vendor.js');
4
4
  var logger = require('../external/@socketsecurity/registry/lib/logger');
5
5
  var strings = require('../external/@socketsecurity/registry/lib/strings');
6
- var debug = require('../external/@socketsecurity/registry/lib/debug');
6
+ var require$$6 = require('../external/@socketsecurity/registry/lib/debug');
7
7
  var arrays = require('../external/@socketsecurity/registry/lib/arrays');
8
8
  var require$$7 = require('../external/@socketsecurity/registry/lib/objects');
9
9
  var path$1 = require('../external/@socketsecurity/registry/lib/path');
@@ -14,290 +14,17 @@ var path = require('node:path');
14
14
  var regexps = require('../external/@socketsecurity/registry/lib/regexps');
15
15
  var prompts = require('../external/@socketsecurity/registry/lib/prompts');
16
16
  var spawn = require('../external/@socketsecurity/registry/lib/spawn');
17
- var fs = require('node:fs');
17
+ var fs$1 = require('node:fs');
18
18
  var promises = require('node:timers/promises');
19
- var fs$1 = require('../external/@socketsecurity/registry/lib/fs');
20
- var require$$8 = require('../external/@socketsecurity/registry/lib/promises');
21
- var packages = require('../external/@socketsecurity/registry/lib/packages');
22
- var streams = require('../external/@socketsecurity/registry/lib/streams');
19
+ var fs = require('../external/@socketsecurity/registry/lib/fs');
23
20
  var registry = require('../external/@socketsecurity/registry');
21
+ var packages = require('../external/@socketsecurity/registry/lib/packages');
24
22
  var require$$5 = require('node:module');
25
23
  var npm = require('../external/@socketsecurity/registry/lib/npm');
24
+ var streams = require('../external/@socketsecurity/registry/lib/streams');
25
+ var globs = require('../external/@socketsecurity/registry/lib/globs');
26
26
 
27
27
  var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
28
- const ignoredDirs = [
29
- // Taken from ignore-by-default:
30
- // https://github.com/novemberborn/ignore-by-default/blob/v2.1.0/index.js
31
- '.git',
32
- // Git repository files, see <https://git-scm.com/>
33
- '.log',
34
- // Log files emitted by tools such as `tsserver`, see <https://github.com/Microsoft/TypeScript/wiki/Standalone-Server-%28tsserver%29>
35
- '.nyc_output',
36
- // Temporary directory where nyc stores coverage data, see <https://github.com/bcoe/nyc>
37
- '.sass-cache',
38
- // Cache folder for node-sass, see <https://github.com/sass/node-sass>
39
- '.yarn',
40
- // Where node modules are installed when using Yarn, see <https://yarnpkg.com/>
41
- 'bower_components',
42
- // Where Bower packages are installed, see <http://bower.io/>
43
- 'coverage',
44
- // Standard output directory for code coverage reports, see <https://github.com/gotwarlost/istanbul>
45
- 'node_modules',
46
- // Where Node modules are installed, see <https://nodejs.org/>
47
- // Taken from globby:
48
- // https://github.com/sindresorhus/globby/blob/v14.0.2/ignore.js#L11-L16
49
- 'flow-typed'];
50
- const ignoredDirPatterns = ignoredDirs.map(i => `**/${i}`);
51
- async function getWorkspaceGlobs(agent, cwd = process.cwd()) {
52
- let workspacePatterns;
53
- if (agent === 'pnpm') {
54
- for (const workspacePath of [path.join(cwd, 'pnpm-workspace.yaml'), path.join(cwd, 'pnpm-workspace.yml')]) {
55
- // eslint-disable-next-line no-await-in-loop
56
- const yml = await safeReadFile(workspacePath);
57
- if (yml) {
58
- try {
59
- workspacePatterns = vendor.distExports.parse(yml)?.packages;
60
- } catch {}
61
- if (workspacePatterns) {
62
- break;
63
- }
64
- }
65
- }
66
- } else {
67
- workspacePatterns = (await packages.readPackageJson(cwd, {
68
- throws: false
69
- }))?.['workspaces'];
70
- }
71
- return Array.isArray(workspacePatterns) ? workspacePatterns.filter(strings.isNonEmptyString).map(workspacePatternToGlobPattern) : [];
72
- }
73
- function ignoreFileLinesToGlobPatterns(lines, filepath, cwd) {
74
- const base = path.relative(cwd, path.dirname(filepath)).replace(/\\/g, '/');
75
- const patterns = [];
76
- for (let i = 0, {
77
- length
78
- } = lines; i < length; i += 1) {
79
- const pattern = lines[i].trim();
80
- if (pattern.length > 0 && pattern.charCodeAt(0) !== 35 /*'#'*/) {
81
- patterns.push(ignorePatternToMinimatch(pattern.length && pattern.charCodeAt(0) === 33 /*'!'*/ ? `!${path.posix.join(base, pattern.slice(1))}` : path.posix.join(base, pattern)));
82
- }
83
- }
84
- return patterns;
85
- }
86
- function ignoreFileToGlobPatterns(content, filepath, cwd) {
87
- return ignoreFileLinesToGlobPatterns(content.split(/\r?\n/), filepath, cwd);
88
- }
89
-
90
- // Based on `@eslint/compat` convertIgnorePatternToMinimatch.
91
- // Apache v2.0 licensed
92
- // Copyright Nicholas C. Zakas
93
- // https://github.com/eslint/rewrite/blob/compat-v1.2.1/packages/compat/src/ignore-file.js#L28
94
- function ignorePatternToMinimatch(pattern) {
95
- const isNegated = pattern.startsWith('!');
96
- const negatedPrefix = isNegated ? '!' : '';
97
- const patternToTest = (isNegated ? pattern.slice(1) : pattern).trimEnd();
98
- // Special cases.
99
- if (patternToTest === '' || patternToTest === '**' || patternToTest === '/**' || patternToTest === '**') {
100
- return `${negatedPrefix}${patternToTest}`;
101
- }
102
- const firstIndexOfSlash = patternToTest.indexOf('/');
103
- const matchEverywherePrefix = firstIndexOfSlash === -1 || firstIndexOfSlash === patternToTest.length - 1 ? '**/' : '';
104
- const patternWithoutLeadingSlash = firstIndexOfSlash === 0 ? patternToTest.slice(1) : patternToTest;
105
- // Escape `{` and `(` because in gitignore patterns they are just
106
- // literal characters without any specific syntactic meaning,
107
- // while in minimatch patterns they can form brace expansion or extglob syntax.
108
- //
109
- // For example, gitignore pattern `src/{a,b}.js` ignores file `src/{a,b}.js`.
110
- // But, the same minimatch pattern `src/{a,b}.js` ignores files `src/a.js` and `src/b.js`.
111
- // Minimatch pattern `src/\{a,b}.js` is equivalent to gitignore pattern `src/{a,b}.js`.
112
- const escapedPatternWithoutLeadingSlash = patternWithoutLeadingSlash.replaceAll(/(?=((?:\\.|[^{(])*))\1([{(])/guy, '$1\\$2');
113
- const matchInsideSuffix = patternToTest.endsWith('/**') ? '/*' : '';
114
- return `${negatedPrefix}${matchEverywherePrefix}${escapedPatternWithoutLeadingSlash}${matchInsideSuffix}`;
115
- }
116
- function workspacePatternToGlobPattern(workspace) {
117
- const {
118
- length
119
- } = workspace;
120
- if (!length) {
121
- return '';
122
- }
123
- // If the workspace ends with "/"
124
- if (workspace.charCodeAt(length - 1) === 47 /*'/'*/) {
125
- return `${workspace}/*/package.json`;
126
- }
127
- // If the workspace ends with "/**"
128
- if (workspace.charCodeAt(length - 1) === 42 /*'*'*/ && workspace.charCodeAt(length - 2) === 42 /*'*'*/ && workspace.charCodeAt(length - 3) === 47 /*'/'*/) {
129
- return `${workspace}/*/**/package.json`;
130
- }
131
- // Things like "packages/a" or "packages/*"
132
- return `${workspace}/package.json`;
133
- }
134
- function filterBySupportedScanFiles(filepaths, supportedFiles) {
135
- const patterns = getSupportedFilePatterns(supportedFiles);
136
- return filepaths.filter(p => vendor.micromatchExports.some(p, patterns));
137
- }
138
- function getSupportedFilePatterns(supportedFiles) {
139
- const patterns = [];
140
- for (const key of Object.keys(supportedFiles)) {
141
- const supported = supportedFiles[key];
142
- if (supported) {
143
- patterns.push(...Object.values(supported).map(p => `**/${p.pattern}`));
144
- }
145
- }
146
- return patterns;
147
- }
148
- async function globWithGitIgnore(patterns, options) {
149
- const {
150
- cwd = process.cwd(),
151
- socketConfig,
152
- ...additionalOptions
153
- } = {
154
- __proto__: null,
155
- ...options
156
- };
157
- const projectIgnorePaths = socketConfig?.projectIgnorePaths;
158
- const ignores = [...ignoredDirPatterns, ...(Array.isArray(projectIgnorePaths) ? ignoreFileLinesToGlobPatterns(projectIgnorePaths, path.join(cwd, '.gitignore'), cwd) : [])];
159
- const ignoreFilesStream = vendor.outExports.globStream(['**/.gitignore'], {
160
- absolute: true,
161
- cwd
162
- });
163
- for await (const ignorePattern of streams.transform(8,
164
- // Concurrency level.
165
- async filepath => ignoreFileToGlobPatterns((await safeReadFile(filepath)) ?? '', filepath, cwd), ignoreFilesStream)) {
166
- ignores.push(...ignorePattern);
167
- }
168
- const hasNegatedPattern = ignores.some(p => p.charCodeAt(0) === 33 /*'!'*/);
169
- const globOptions = {
170
- __proto__: null,
171
- absolute: true,
172
- cwd,
173
- dot: true,
174
- ignore: hasNegatedPattern ? ['**/.git', '**/node_modules'] : ignores,
175
- ...additionalOptions
176
- };
177
- const result = await vendor.outExports.glob(patterns, globOptions);
178
- if (!hasNegatedPattern) {
179
- return result;
180
- }
181
-
182
- // Note: the input files must be INSIDE the cwd. If you get strange looking
183
- // relative path errors here, most likely your path is outside the given cwd.
184
- const filtered = vendor.ignoreExports().add(ignores).filter(globOptions.absolute ? result.map(p => path.relative(cwd, p)) : result);
185
- return globOptions.absolute ? filtered.map(p => path.resolve(cwd, p)) : filtered;
186
- }
187
- async function globNodeModules(cwd = process.cwd()) {
188
- return await vendor.outExports.glob('**/node_modules', {
189
- absolute: true,
190
- cwd,
191
- onlyDirectories: true
192
- });
193
- }
194
- async function globWorkspace(agent, cwd = process.cwd()) {
195
- const workspaceGlobs = await getWorkspaceGlobs(agent, cwd);
196
- return workspaceGlobs.length ? await vendor.outExports.glob(workspaceGlobs, {
197
- absolute: true,
198
- cwd,
199
- ignore: ['**/node_modules/**', '**/bower_components/**']
200
- }) : [];
201
- }
202
- function isReportSupportedFile(filepath, supportedFiles) {
203
- const patterns = getSupportedFilePatterns(supportedFiles);
204
- return vendor.micromatchExports.some(filepath, patterns);
205
- }
206
- function pathsToGlobPatterns(paths) {
207
- // TODO: Does not support `~/` paths.
208
- return paths.map(p => p === '.' || p === './' ? '**/*' : p);
209
- }
210
-
211
- async function removeNodeModules(cwd = process.cwd()) {
212
- const nodeModulesPaths = await globNodeModules(cwd);
213
- await require$$8.pEach(nodeModulesPaths, 3, p => fs$1.remove(p, {
214
- force: true,
215
- recursive: true
216
- }), {
217
- retries: 3
218
- });
219
- }
220
- async function findUp(name, {
221
- cwd = process.cwd(),
222
- // Lazily access constants.abortSignal.
223
- signal = constants.abortSignal
224
- }) {
225
- let dir = path.resolve(cwd);
226
- const {
227
- root
228
- } = path.parse(dir);
229
- const names = [name].flat();
230
- while (dir && dir !== root) {
231
- for (const name of names) {
232
- if (signal?.aborted) {
233
- return undefined;
234
- }
235
- const filePath = path.join(dir, name);
236
- try {
237
- // eslint-disable-next-line no-await-in-loop
238
- const stats = await fs.promises.stat(filePath);
239
- if (stats.isFile()) {
240
- return filePath;
241
- }
242
- } catch {}
243
- }
244
- dir = path.dirname(dir);
245
- }
246
- return undefined;
247
- }
248
- function isDirectorySync(filepath) {
249
- return fs.existsSync(filepath) && !!safeStatsSync(filepath)?.isDirectory();
250
- }
251
- async function readFileBinary(filepath, options) {
252
- return await fs.promises.readFile(filepath, {
253
- // Lazily access constants.abortSignal.
254
- signal: constants.abortSignal,
255
- ...options,
256
- encoding: 'binary'
257
- });
258
- }
259
- async function readFileUtf8(filepath, options) {
260
- return await fs.promises.readFile(filepath, {
261
- // Lazily access constants.abortSignal.
262
- signal: constants.abortSignal,
263
- ...options,
264
- encoding: 'utf8'
265
- });
266
- }
267
- async function safeReadFile(filepath, options) {
268
- try {
269
- return await fs.promises.readFile(filepath, {
270
- encoding: 'utf8',
271
- // Lazily access constants.abortSignal.
272
- signal: constants.abortSignal,
273
- ...(typeof options === 'string' ? {
274
- encoding: options
275
- } : options)
276
- });
277
- } catch {}
278
- return undefined;
279
- }
280
- function safeReadFileSync(filepath, options) {
281
- try {
282
- return fs.readFileSync(filepath, {
283
- encoding: 'utf8',
284
- ...(typeof options === 'string' ? {
285
- encoding: options
286
- } : options)
287
- });
288
- } catch {}
289
- return undefined;
290
- }
291
- function safeStatsSync(filepath, options) {
292
- try {
293
- return fs.statSync(filepath, {
294
- throwIfNoEntry: false,
295
- ...options
296
- });
297
- } catch {}
298
- return undefined;
299
- }
300
-
301
28
  const sensitiveConfigKeyLookup = new Set(['apiToken']);
302
29
  const supportedConfig = 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']]);
303
30
  const supportedConfigEntries = [...supportedConfig.entries()].sort((a, b) => sorts.naturalCompare(a[0], b[0]));
@@ -311,7 +38,7 @@ function getConfigValues() {
311
38
  socketAppDataPath
312
39
  } = constants;
313
40
  if (socketAppDataPath) {
314
- const raw = safeReadFileSync(socketAppDataPath);
41
+ const raw = fs.safeReadFileSync(socketAppDataPath);
315
42
  if (raw) {
316
43
  try {
317
44
  Object.assign(_cachedConfig, JSON.parse(Buffer.from(raw, 'base64').toString()));
@@ -326,7 +53,7 @@ function getConfigValues() {
326
53
  updateConfigValue('apiToken', token);
327
54
  }
328
55
  } else {
329
- fs.mkdirSync(path.dirname(socketAppDataPath), {
56
+ fs$1.mkdirSync(path.dirname(socketAppDataPath), {
330
57
  recursive: true
331
58
  });
332
59
  }
@@ -355,10 +82,10 @@ function findSocketYmlSync(dir = process.cwd()) {
355
82
  let prevDir = null;
356
83
  while (dir !== prevDir) {
357
84
  let ymlPath = path.join(dir, 'socket.yml');
358
- let yml = safeReadFileSync(ymlPath);
85
+ let yml = fs.safeReadFileSync(ymlPath);
359
86
  if (yml === undefined) {
360
87
  ymlPath = path.join(dir, 'socket.yaml');
361
- yml = safeReadFileSync(ymlPath);
88
+ yml = fs.safeReadFileSync(ymlPath);
362
89
  }
363
90
  if (typeof yml === 'string') {
364
91
  try {
@@ -420,7 +147,7 @@ let _cachedConfig;
420
147
  // When using --config or SOCKET_CLI_CONFIG, do not persist the config.
421
148
  let _readOnlyConfig = false;
422
149
  function overrideCachedConfig(jsonConfig) {
423
- debug.debugFn('notice', 'override: full config (not stored)');
150
+ require$$6.debugFn('notice', 'override: full config (not stored)');
424
151
  let config;
425
152
  try {
426
153
  config = JSON.parse(String(jsonConfig));
@@ -462,7 +189,7 @@ function overrideCachedConfig(jsonConfig) {
462
189
  };
463
190
  }
464
191
  function overrideConfigApiToken(apiToken) {
465
- debug.debugFn('notice', 'override: API token (not stored)');
192
+ require$$6.debugFn('notice', 'override: API token (not stored)');
466
193
  // Set token to the local cached config and mark it read-only so it doesn't persist.
467
194
  _cachedConfig = {
468
195
  ...vendor.configExports,
@@ -511,7 +238,7 @@ function updateConfigValue(configKey, value) {
511
238
  socketAppDataPath
512
239
  } = constants;
513
240
  if (socketAppDataPath) {
514
- fs.writeFileSync(socketAppDataPath, Buffer.from(JSON.stringify(localConfig)).toString('base64'));
241
+ fs$1.writeFileSync(socketAppDataPath, Buffer.from(JSON.stringify(localConfig)).toString('base64'));
515
242
  }
516
243
  });
517
244
  }
@@ -546,7 +273,7 @@ function captureExceptionSync(exception, hint) {
546
273
  if (!Sentry) {
547
274
  return '';
548
275
  }
549
- debug.debugFn('notice', 'send: exception to Sentry');
276
+ require$$6.debugFn('notice', 'send: exception to Sentry');
550
277
  return Sentry.captureException(exception, hint);
551
278
  }
552
279
 
@@ -648,12 +375,12 @@ async function setupSdk(options) {
648
375
  const ProxyAgent = apiProxy?.startsWith('http:') ? vendor.HttpProxyAgent : vendor.HttpsProxyAgent;
649
376
  return {
650
377
  ok: true,
651
- data: new vendor.distExports$1.SocketSdk(apiToken, {
378
+ data: new vendor.distExports.SocketSdk(apiToken, {
652
379
  agent: apiProxy ? new ProxyAgent({
653
380
  proxy: apiProxy
654
381
  }) : undefined,
655
382
  baseUrl: apiBaseUrl,
656
- userAgent: vendor.distExports$1.createUserAgentFromPkgJson({
383
+ userAgent: vendor.distExports.createUserAgentFromPkgJson({
657
384
  // Lazily access constants.ENV.INLINED_SOCKET_CLI_NAME.
658
385
  name: constants.ENV.INLINED_SOCKET_CLI_NAME,
659
386
  // Lazily access constants.ENV.INLINED_SOCKET_CLI_VERSION.
@@ -691,12 +418,12 @@ async function handleApiCall(value, options) {
691
418
  } catch (e) {
692
419
  if (desc) {
693
420
  spinner?.failAndStop(`An error was thrown while requesting ${desc}`);
694
- debug.debugFn('error', `caught: ${desc} error`);
421
+ require$$6.debugFn('error', `caught: ${desc} error`);
695
422
  } else {
696
423
  spinner?.stop();
697
- debug.debugFn('error', `caught: error`);
424
+ require$$6.debugFn('error', `caught: error`);
698
425
  }
699
- debug.debugDir('inspect', {
426
+ require$$6.debugDir('inspect', {
700
427
  error: e
701
428
  });
702
429
  return {
@@ -716,11 +443,11 @@ async function handleApiCall(value, options) {
716
443
  cause: reason
717
444
  } = errorResult;
718
445
  if (desc) {
719
- debug.debugFn('error', `fail: ${desc} bad response`);
446
+ require$$6.debugFn('error', `fail: ${desc} bad response`);
720
447
  } else {
721
- debug.debugFn('error', 'fail: bad response');
448
+ require$$6.debugFn('error', 'fail: bad response');
722
449
  }
723
- debug.debugDir('inspect', {
450
+ require$$6.debugDir('inspect', {
724
451
  sdkResult
725
452
  });
726
453
  return {
@@ -748,8 +475,8 @@ async function handleApiCallNoSpinner(value, description) {
748
475
  } catch (e) {
749
476
  const message = `${e || NO_ERROR_MESSAGE}`;
750
477
  const reason = `${e || NO_ERROR_MESSAGE}`;
751
- debug.debugFn('error', `caught: ${description} error`);
752
- debug.debugDir('inspect', {
478
+ require$$6.debugFn('error', `caught: ${description} error`);
479
+ require$$6.debugDir('inspect', {
753
480
  error: e
754
481
  });
755
482
  return {
@@ -763,8 +490,8 @@ async function handleApiCallNoSpinner(value, description) {
763
490
  if (result.success === false) {
764
491
  const error = result;
765
492
  const message = `${error.error || NO_ERROR_MESSAGE}`;
766
- debug.debugFn('error', `fail: ${description} bad response`);
767
- debug.debugDir('inspect', {
493
+ require$$6.debugFn('error', `fail: ${description} bad response`);
494
+ require$$6.debugDir('inspect', {
768
495
  error
769
496
  });
770
497
  return {
@@ -851,8 +578,8 @@ async function queryApiSafeText(path, fetchSpinnerDesc) {
851
578
  spinner.failAndStop(`An error was thrown while requesting ${fetchSpinnerDesc}.`);
852
579
  }
853
580
  const cause = e?.message;
854
- debug.debugFn('error', 'caught: queryApi() error');
855
- debug.debugDir('inspect', {
581
+ require$$6.debugFn('error', 'caught: queryApi() error');
582
+ require$$6.debugDir('inspect', {
856
583
  error: e
857
584
  });
858
585
  return {
@@ -878,8 +605,8 @@ async function queryApiSafeText(path, fetchSpinnerDesc) {
878
605
  data
879
606
  };
880
607
  } catch (e) {
881
- debug.debugFn('error', 'caught: await result.text() error');
882
- debug.debugDir('inspect', {
608
+ require$$6.debugFn('error', 'caught: await result.text() error');
609
+ require$$6.debugDir('inspect', {
883
610
  error: e
884
611
  });
885
612
  return {
@@ -1002,9 +729,9 @@ cols) {
1002
729
  function serializeResultJson(data) {
1003
730
  if (typeof data !== 'object' || !data) {
1004
731
  process.exitCode = 1;
1005
- debug.debugFn('inspect', 'typeof data=', typeof data);
732
+ require$$6.debugFn('inspect', 'typeof data=', typeof data);
1006
733
  if (typeof data !== 'object' && data) {
1007
- debug.debugFn('inspect', 'data:\n', data);
734
+ require$$6.debugFn('inspect', 'data:\n', data);
1008
735
  }
1009
736
 
1010
737
  // We should not allow the JSON value to be "null", or a boolean/number/string,
@@ -1024,7 +751,7 @@ function serializeResultJson(data) {
1024
751
  // This could be caused by circular references, which is an "us" problem
1025
752
  const message = 'There was a problem converting the data set to JSON. Please try again without --json';
1026
753
  logger.logger.fail(message);
1027
- debug.debugDir('inspect', {
754
+ require$$6.debugDir('inspect', {
1028
755
  error: e
1029
756
  });
1030
757
  return JSON.stringify({
@@ -1672,7 +1399,7 @@ async function determineOrgSlug(orgFlag, interactive, dryRun) {
1672
1399
  async function getDefaultOrgSlug() {
1673
1400
  const defaultOrgResult = getConfigValueOrUndef('defaultOrg');
1674
1401
  if (defaultOrgResult) {
1675
- debug.debugFn('notice', 'use: default org', defaultOrgResult);
1402
+ require$$6.debugFn('notice', 'use: default org', defaultOrgResult);
1676
1403
  return {
1677
1404
  ok: true,
1678
1405
  data: defaultOrgResult
@@ -1682,7 +1409,7 @@ async function getDefaultOrgSlug() {
1682
1409
  // Lazily access constants.ENV.SOCKET_CLI_ORG_SLUG.
1683
1410
  const envOrgSlug = constants.ENV.SOCKET_CLI_ORG_SLUG;
1684
1411
  if (envOrgSlug) {
1685
- debug.debugFn('notice', 'use: org from environment variable', envOrgSlug);
1412
+ require$$6.debugFn('notice', 'use: org from environment variable', envOrgSlug);
1686
1413
  return {
1687
1414
  ok: true,
1688
1415
  data: envOrgSlug
@@ -1711,7 +1438,7 @@ async function getDefaultOrgSlug() {
1711
1438
  data: `Was unable to determine the default organization for the current API token. Unable to continue.`
1712
1439
  };
1713
1440
  }
1714
- debug.debugFn('notice', 'resolve: org', slug);
1441
+ require$$6.debugFn('notice', 'resolve: org', slug);
1715
1442
  return {
1716
1443
  ok: true,
1717
1444
  message: 'Retrieved default org from server',
@@ -1757,14 +1484,14 @@ async function getRepoInfo(cwd = process.cwd()) {
1757
1484
  })).stdout;
1758
1485
  info = parseGitRemoteUrl(remoteUrl);
1759
1486
  if (!info) {
1760
- debug.debugFn('error', 'git: unmatched git remote URL format');
1761
- debug.debugDir('inspect', {
1487
+ require$$6.debugFn('error', 'git: unmatched git remote URL format');
1488
+ require$$6.debugDir('inspect', {
1762
1489
  remoteUrl
1763
1490
  });
1764
1491
  }
1765
1492
  } catch (e) {
1766
- debug.debugFn('error', 'caught: `git remote get-url origin` failed');
1767
- debug.debugDir('inspect', {
1493
+ require$$6.debugFn('error', 'caught: `git remote get-url origin` failed');
1494
+ require$$6.debugDir('inspect', {
1768
1495
  error: e
1769
1496
  });
1770
1497
  }
@@ -1793,16 +1520,16 @@ async function gitBranch(cwd = process.cwd()) {
1793
1520
  async function gitCleanFdx(cwd = process.cwd()) {
1794
1521
  const stdioIgnoreOptions = {
1795
1522
  cwd,
1796
- stdio: debug.isDebug('stdio') ? 'inherit' : 'ignore'
1523
+ stdio: require$$6.isDebug('stdio') ? 'inherit' : 'ignore'
1797
1524
  };
1798
1525
  const quotedCmd = '`git clean -fdx`';
1799
- debug.debugFn('stdio', `spawn: ${quotedCmd}`);
1526
+ require$$6.debugFn('stdio', `spawn: ${quotedCmd}`);
1800
1527
  try {
1801
1528
  await spawn.spawn('git', ['clean', '-fdx'], stdioIgnoreOptions);
1802
1529
  return true;
1803
1530
  } catch (e) {
1804
- debug.debugFn('error', `caught: ${quotedCmd} failed`);
1805
- debug.debugDir('inspect', {
1531
+ require$$6.debugFn('error', `caught: ${quotedCmd} failed`);
1532
+ require$$6.debugDir('inspect', {
1806
1533
  error: e
1807
1534
  });
1808
1535
  }
@@ -1811,16 +1538,16 @@ async function gitCleanFdx(cwd = process.cwd()) {
1811
1538
  async function gitCheckoutBranch(branch, cwd = process.cwd()) {
1812
1539
  const stdioIgnoreOptions = {
1813
1540
  cwd,
1814
- stdio: debug.isDebug('stdio') ? 'inherit' : 'ignore'
1541
+ stdio: require$$6.isDebug('stdio') ? 'inherit' : 'ignore'
1815
1542
  };
1816
1543
  const quotedCmd = `\`git checkout ${branch}\``;
1817
- debug.debugFn('stdio', `spawn: ${quotedCmd}`);
1544
+ require$$6.debugFn('stdio', `spawn: ${quotedCmd}`);
1818
1545
  try {
1819
1546
  await spawn.spawn('git', ['checkout', branch], stdioIgnoreOptions);
1820
1547
  return true;
1821
1548
  } catch (e) {
1822
- debug.debugFn('error', `caught: ${quotedCmd} failed`);
1823
- debug.debugDir('inspect', {
1549
+ require$$6.debugFn('error', `caught: ${quotedCmd} failed`);
1550
+ require$$6.debugDir('inspect', {
1824
1551
  error: e
1825
1552
  });
1826
1553
  }
@@ -1832,16 +1559,16 @@ async function gitCreateBranch(branch, cwd = process.cwd()) {
1832
1559
  }
1833
1560
  const stdioIgnoreOptions = {
1834
1561
  cwd,
1835
- stdio: debug.isDebug('stdio') ? 'inherit' : 'ignore'
1562
+ stdio: require$$6.isDebug('stdio') ? 'inherit' : 'ignore'
1836
1563
  };
1837
1564
  const quotedCmd = `\`git branch ${branch}\``;
1838
- debug.debugFn('stdio', `spawn: ${quotedCmd}`);
1565
+ require$$6.debugFn('stdio', `spawn: ${quotedCmd}`);
1839
1566
  try {
1840
1567
  await spawn.spawn('git', ['branch', branch], stdioIgnoreOptions);
1841
1568
  return true;
1842
1569
  } catch (e) {
1843
- debug.debugFn('error', `caught: ${quotedCmd} failed`);
1844
- debug.debugDir('inspect', {
1570
+ require$$6.debugFn('error', `caught: ${quotedCmd} failed`);
1571
+ require$$6.debugDir('inspect', {
1845
1572
  error: e
1846
1573
  });
1847
1574
  }
@@ -1850,19 +1577,19 @@ async function gitCreateBranch(branch, cwd = process.cwd()) {
1850
1577
  async function gitPushBranch(branch, cwd = process.cwd()) {
1851
1578
  const stdioIgnoreOptions = {
1852
1579
  cwd,
1853
- stdio: debug.isDebug('stdio') ? 'inherit' : 'ignore'
1580
+ stdio: require$$6.isDebug('stdio') ? 'inherit' : 'ignore'
1854
1581
  };
1855
1582
  const quotedCmd = `\`git push --force --set-upstream origin ${branch}\``;
1856
- debug.debugFn('stdio', `spawn: ${quotedCmd}`);
1583
+ require$$6.debugFn('stdio', `spawn: ${quotedCmd}`);
1857
1584
  try {
1858
1585
  await spawn.spawn('git', ['push', '--force', '--set-upstream', 'origin', branch], stdioIgnoreOptions);
1859
1586
  return true;
1860
1587
  } catch (e) {
1861
- debug.debugFn('error', `caught: ${quotedCmd} failed`);
1588
+ require$$6.debugFn('error', `caught: ${quotedCmd} failed`);
1862
1589
  if (spawn.isSpawnError(e) && e.code === 128) {
1863
- debug.debugFn('error', "denied: token requires write permissions for 'contents' and 'pull-requests'");
1590
+ require$$6.debugFn('error', "denied: token requires write permissions for 'contents' and 'pull-requests'");
1864
1591
  }
1865
- debug.debugDir('inspect', {
1592
+ require$$6.debugDir('inspect', {
1866
1593
  error: e
1867
1594
  });
1868
1595
  }
@@ -1870,7 +1597,7 @@ async function gitPushBranch(branch, cwd = process.cwd()) {
1870
1597
  }
1871
1598
  async function gitCommit(commitMsg, filepaths, options) {
1872
1599
  if (!filepaths.length) {
1873
- debug.debugFn('notice', `miss: no filepaths to add`);
1600
+ require$$6.debugFn('notice', `miss: no filepaths to add`);
1874
1601
  return false;
1875
1602
  }
1876
1603
  const {
@@ -1886,26 +1613,26 @@ async function gitCommit(commitMsg, filepaths, options) {
1886
1613
  await gitEnsureIdentity(user, email, cwd);
1887
1614
  const stdioIgnoreOptions = {
1888
1615
  cwd,
1889
- stdio: debug.isDebug('stdio') ? 'inherit' : 'ignore'
1616
+ stdio: require$$6.isDebug('stdio') ? 'inherit' : 'ignore'
1890
1617
  };
1891
1618
  const quotedAddCmd = `\`git add ${filepaths.join(' ')}\``;
1892
- debug.debugFn('stdio', `spawn: ${quotedAddCmd}`);
1619
+ require$$6.debugFn('stdio', `spawn: ${quotedAddCmd}`);
1893
1620
  try {
1894
1621
  await spawn.spawn('git', ['add', ...filepaths], stdioIgnoreOptions);
1895
1622
  } catch (e) {
1896
- debug.debugFn('error', `caught: ${quotedAddCmd} failed`);
1897
- debug.debugDir('inspect', {
1623
+ require$$6.debugFn('error', `caught: ${quotedAddCmd} failed`);
1624
+ require$$6.debugDir('inspect', {
1898
1625
  error: e
1899
1626
  });
1900
1627
  }
1901
1628
  const quotedCommitCmd = `\`git commit -m ${commitMsg}\``;
1902
- debug.debugFn('stdio', `spawn: ${quotedCommitCmd}`);
1629
+ require$$6.debugFn('stdio', `spawn: ${quotedCommitCmd}`);
1903
1630
  try {
1904
1631
  await spawn.spawn('git', ['commit', '-m', commitMsg], stdioIgnoreOptions);
1905
1632
  return true;
1906
1633
  } catch (e) {
1907
- debug.debugFn('error', `caught: ${quotedCommitCmd} failed`);
1908
- debug.debugDir('inspect', {
1634
+ require$$6.debugFn('error', `caught: ${quotedCommitCmd} failed`);
1635
+ require$$6.debugDir('inspect', {
1909
1636
  error: e
1910
1637
  });
1911
1638
  }
@@ -1914,18 +1641,18 @@ async function gitCommit(commitMsg, filepaths, options) {
1914
1641
  async function gitDeleteBranch(branch, cwd = process.cwd()) {
1915
1642
  const stdioIgnoreOptions = {
1916
1643
  cwd,
1917
- stdio: debug.isDebug('stdio') ? 'inherit' : 'ignore'
1644
+ stdio: require$$6.isDebug('stdio') ? 'inherit' : 'ignore'
1918
1645
  };
1919
1646
  const quotedCmd = `\`git branch -D ${branch}\``;
1920
- debug.debugFn('stdio', `spawn: ${quotedCmd}`);
1647
+ require$$6.debugFn('stdio', `spawn: ${quotedCmd}`);
1921
1648
  try {
1922
1649
  // Will throw with exit code 1 if branch does not exist.
1923
1650
  await spawn.spawn('git', ['branch', '-D', branch], stdioIgnoreOptions);
1924
1651
  return true;
1925
1652
  } catch (e) {
1926
- if (debug.isDebug('stdio')) {
1927
- debug.debugFn('error', `caught: ${quotedCmd} failed`);
1928
- debug.debugDir('inspect', {
1653
+ if (require$$6.isDebug('stdio')) {
1654
+ require$$6.debugFn('error', `caught: ${quotedCmd} failed`);
1655
+ require$$6.debugDir('inspect', {
1929
1656
  error: e
1930
1657
  });
1931
1658
  }
@@ -1944,14 +1671,14 @@ async function gitEnsureIdentity(name, email, cwd = process.cwd()) {
1944
1671
  let configValue;
1945
1672
  {
1946
1673
  const quotedCmd = `\`git config --get ${prop}\``;
1947
- debug.debugFn('stdio', `spawn: ${quotedCmd}`);
1674
+ require$$6.debugFn('stdio', `spawn: ${quotedCmd}`);
1948
1675
  try {
1949
1676
  // Will throw with exit code 1 if the config property is not set.
1950
1677
  configValue = (await spawn.spawn('git', ['config', '--get', prop], stdioPipeOptions)).stdout;
1951
1678
  } catch (e) {
1952
- if (debug.isDebug('stdio')) {
1953
- debug.debugFn('error', `caught: ${quotedCmd} failed`);
1954
- debug.debugDir('inspect', {
1679
+ if (require$$6.isDebug('stdio')) {
1680
+ require$$6.debugFn('error', `caught: ${quotedCmd} failed`);
1681
+ require$$6.debugDir('inspect', {
1955
1682
  error: e
1956
1683
  });
1957
1684
  }
@@ -1960,16 +1687,16 @@ async function gitEnsureIdentity(name, email, cwd = process.cwd()) {
1960
1687
  if (configValue !== value) {
1961
1688
  const stdioIgnoreOptions = {
1962
1689
  cwd,
1963
- stdio: debug.isDebug('stdio') ? 'inherit' : 'ignore'
1690
+ stdio: require$$6.isDebug('stdio') ? 'inherit' : 'ignore'
1964
1691
  };
1965
1692
  const quotedCmd = `\`git config ${prop} ${value}\``;
1966
- debug.debugFn('stdio', `spawn: ${quotedCmd}`);
1693
+ require$$6.debugFn('stdio', `spawn: ${quotedCmd}`);
1967
1694
  try {
1968
1695
  await spawn.spawn('git', ['config', prop, value], stdioIgnoreOptions);
1969
1696
  } catch (e) {
1970
- if (debug.isDebug('stdio')) {
1971
- debug.debugFn('error', `caught: ${quotedCmd} failed`);
1972
- debug.debugDir('inspect', {
1697
+ if (require$$6.isDebug('stdio')) {
1698
+ require$$6.debugFn('error', `caught: ${quotedCmd} failed`);
1699
+ require$$6.debugDir('inspect', {
1973
1700
  error: e
1974
1701
  });
1975
1702
  }
@@ -1980,18 +1707,18 @@ async function gitEnsureIdentity(name, email, cwd = process.cwd()) {
1980
1707
  async function gitLocalBranchExists(branch, cwd = process.cwd()) {
1981
1708
  const stdioIgnoreOptions = {
1982
1709
  cwd,
1983
- stdio: debug.isDebug('stdio') ? 'inherit' : 'ignore'
1710
+ stdio: require$$6.isDebug('stdio') ? 'inherit' : 'ignore'
1984
1711
  };
1985
1712
  const quotedCmd = `\`git show-ref --quiet refs/heads/${branch}\``;
1986
- debug.debugFn('stdio', `spawn: ${quotedCmd}`);
1713
+ require$$6.debugFn('stdio', `spawn: ${quotedCmd}`);
1987
1714
  try {
1988
1715
  // Will throw with exit code 1 if the branch does not exist.
1989
1716
  await spawn.spawn('git', ['show-ref', '--quiet', `refs/heads/${branch}`], stdioIgnoreOptions);
1990
1717
  return true;
1991
1718
  } catch (e) {
1992
- if (debug.isDebug('stdio')) {
1993
- debug.debugFn('error', `caught: ${quotedCmd} failed`);
1994
- debug.debugDir('inspect', {
1719
+ if (require$$6.isDebug('stdio')) {
1720
+ require$$6.debugFn('error', `caught: ${quotedCmd} failed`);
1721
+ require$$6.debugDir('inspect', {
1995
1722
  error: e
1996
1723
  });
1997
1724
  }
@@ -2016,16 +1743,16 @@ async function gitResetAndClean(branch = 'HEAD', cwd = process.cwd()) {
2016
1743
  async function gitResetHard(branch = 'HEAD', cwd = process.cwd()) {
2017
1744
  const stdioIgnoreOptions = {
2018
1745
  cwd,
2019
- stdio: debug.isDebug('stdio') ? 'inherit' : 'ignore'
1746
+ stdio: require$$6.isDebug('stdio') ? 'inherit' : 'ignore'
2020
1747
  };
2021
1748
  const quotedCmd = `\`git reset --hard ${branch}\``;
2022
- debug.debugFn('stdio', `spawn: ${quotedCmd}`);
1749
+ require$$6.debugFn('stdio', `spawn: ${quotedCmd}`);
2023
1750
  try {
2024
1751
  await spawn.spawn('git', ['reset', '--hard', branch], stdioIgnoreOptions);
2025
1752
  return true;
2026
1753
  } catch (e) {
2027
- debug.debugFn('error', `caught: ${quotedCmd} failed`);
2028
- debug.debugDir('inspect', {
1754
+ require$$6.debugFn('error', `caught: ${quotedCmd} failed`);
1755
+ require$$6.debugDir('inspect', {
2029
1756
  error: e
2030
1757
  });
2031
1758
  }
@@ -2044,8 +1771,8 @@ async function gitUnstagedModifiedFiles(cwd = process.cwd()) {
2044
1771
  data: relPaths.map(p => path$1.normalizePath(p))
2045
1772
  };
2046
1773
  } catch (e) {
2047
- debug.debugFn('error', `caught: ${quotedCmd} failed`);
2048
- debug.debugDir('inspect', {
1774
+ require$$6.debugFn('error', `caught: ${quotedCmd} failed`);
1775
+ require$$6.debugDir('inspect', {
2049
1776
  error: e
2050
1777
  });
2051
1778
  return {
@@ -2141,6 +1868,211 @@ function* walkNestedMap(map, keys = []) {
2141
1868
  }
2142
1869
  }
2143
1870
 
1871
+ const DEFAULT_IGNORE_FOR_GIT_IGNORE = globs.defaultIgnore.filter(p => !p.endsWith('.gitignore'));
1872
+ const IGNORED_DIRS = [
1873
+ // Taken from ignore-by-default:
1874
+ // https://github.com/novemberborn/ignore-by-default/blob/v2.1.0/index.js
1875
+ '.git',
1876
+ // Git repository files, see <https://git-scm.com/>
1877
+ '.log',
1878
+ // Log files emitted by tools such as `tsserver`, see <https://github.com/Microsoft/TypeScript/wiki/Standalone-Server-%28tsserver%29>
1879
+ '.nyc_output',
1880
+ // Temporary directory where nyc stores coverage data, see <https://github.com/bcoe/nyc>
1881
+ '.sass-cache',
1882
+ // Cache folder for node-sass, see <https://github.com/sass/node-sass>
1883
+ '.yarn',
1884
+ // Where node modules are installed when using Yarn, see <https://yarnpkg.com/>
1885
+ 'bower_components',
1886
+ // Where Bower packages are installed, see <http://bower.io/>
1887
+ 'coverage',
1888
+ // Standard output directory for code coverage reports, see <https://github.com/gotwarlost/istanbul>
1889
+ 'node_modules',
1890
+ // Where Node modules are installed, see <https://nodejs.org/>
1891
+ // Taken from globby:
1892
+ // https://github.com/sindresorhus/globby/blob/v14.0.2/ignore.js#L11-L16
1893
+ 'flow-typed'];
1894
+ const IGNORED_DIR_PATTERNS = IGNORED_DIRS.map(i => `**/${i}`);
1895
+ async function getWorkspaceGlobs(agent, cwd = process.cwd()) {
1896
+ let workspacePatterns;
1897
+ if (agent === 'pnpm') {
1898
+ for (const workspacePath of [path.join(cwd, 'pnpm-workspace.yaml'), path.join(cwd, 'pnpm-workspace.yml')]) {
1899
+ // eslint-disable-next-line no-await-in-loop
1900
+ const yml = await fs.safeReadFile(workspacePath);
1901
+ if (yml) {
1902
+ try {
1903
+ workspacePatterns = vendor.distExports$1.parse(yml)?.packages;
1904
+ } catch {}
1905
+ if (workspacePatterns) {
1906
+ break;
1907
+ }
1908
+ }
1909
+ }
1910
+ } else {
1911
+ workspacePatterns = (await packages.readPackageJson(cwd, {
1912
+ throws: false
1913
+ }))?.['workspaces'];
1914
+ }
1915
+ return Array.isArray(workspacePatterns) ? workspacePatterns.filter(strings.isNonEmptyString).map(workspacePatternToGlobPattern) : [];
1916
+ }
1917
+ function ignoreFileLinesToGlobPatterns(lines, filepath, cwd) {
1918
+ const base = path.relative(cwd, path.dirname(filepath)).replace(/\\/g, '/');
1919
+ const patterns = [];
1920
+ for (let i = 0, {
1921
+ length
1922
+ } = lines; i < length; i += 1) {
1923
+ const pattern = lines[i].trim();
1924
+ if (pattern.length > 0 && pattern.charCodeAt(0) !== 35 /*'#'*/) {
1925
+ patterns.push(ignorePatternToMinimatch(pattern.length && pattern.charCodeAt(0) === 33 /*'!'*/ ? `!${path.posix.join(base, pattern.slice(1))}` : path.posix.join(base, pattern)));
1926
+ }
1927
+ }
1928
+ return patterns;
1929
+ }
1930
+ function ignoreFileToGlobPatterns(content, filepath, cwd) {
1931
+ return ignoreFileLinesToGlobPatterns(content.split(/\r?\n/), filepath, cwd);
1932
+ }
1933
+
1934
+ // Based on `@eslint/compat` convertIgnorePatternToMinimatch.
1935
+ // Apache v2.0 licensed
1936
+ // Copyright Nicholas C. Zakas
1937
+ // https://github.com/eslint/rewrite/blob/compat-v1.2.1/packages/compat/src/ignore-file.js#L28
1938
+ function ignorePatternToMinimatch(pattern) {
1939
+ const isNegated = pattern.startsWith('!');
1940
+ const negatedPrefix = isNegated ? '!' : '';
1941
+ const patternToTest = (isNegated ? pattern.slice(1) : pattern).trimEnd();
1942
+ // Special cases.
1943
+ if (patternToTest === '' || patternToTest === '**' || patternToTest === '/**' || patternToTest === '**') {
1944
+ return `${negatedPrefix}${patternToTest}`;
1945
+ }
1946
+ const firstIndexOfSlash = patternToTest.indexOf('/');
1947
+ const matchEverywherePrefix = firstIndexOfSlash === -1 || firstIndexOfSlash === patternToTest.length - 1 ? '**/' : '';
1948
+ const patternWithoutLeadingSlash = firstIndexOfSlash === 0 ? patternToTest.slice(1) : patternToTest;
1949
+ // Escape `{` and `(` because in gitignore patterns they are just
1950
+ // literal characters without any specific syntactic meaning,
1951
+ // while in minimatch patterns they can form brace expansion or extglob syntax.
1952
+ //
1953
+ // For example, gitignore pattern `src/{a,b}.js` ignores file `src/{a,b}.js`.
1954
+ // But, the same minimatch pattern `src/{a,b}.js` ignores files `src/a.js` and `src/b.js`.
1955
+ // Minimatch pattern `src/\{a,b}.js` is equivalent to gitignore pattern `src/{a,b}.js`.
1956
+ const escapedPatternWithoutLeadingSlash = patternWithoutLeadingSlash.replaceAll(/(?=((?:\\.|[^{(])*))\1([{(])/guy, '$1\\$2');
1957
+ const matchInsideSuffix = patternToTest.endsWith('/**') ? '/*' : '';
1958
+ return `${negatedPrefix}${matchEverywherePrefix}${escapedPatternWithoutLeadingSlash}${matchInsideSuffix}`;
1959
+ }
1960
+ function workspacePatternToGlobPattern(workspace) {
1961
+ const {
1962
+ length
1963
+ } = workspace;
1964
+ if (!length) {
1965
+ return '';
1966
+ }
1967
+ // If the workspace ends with "/"
1968
+ if (workspace.charCodeAt(length - 1) === 47 /*'/'*/) {
1969
+ return `${workspace}/*/package.json`;
1970
+ }
1971
+ // If the workspace ends with "/**"
1972
+ if (workspace.charCodeAt(length - 1) === 42 /*'*'*/ && workspace.charCodeAt(length - 2) === 42 /*'*'*/ && workspace.charCodeAt(length - 3) === 47 /*'/'*/) {
1973
+ return `${workspace}/*/**/package.json`;
1974
+ }
1975
+ // Things like "packages/a" or "packages/*"
1976
+ return `${workspace}/package.json`;
1977
+ }
1978
+ function filterBySupportedScanFiles(filepaths, supportedFiles) {
1979
+ const patterns = getSupportedFilePatterns(supportedFiles);
1980
+ return filepaths.filter(p => vendor.micromatchExports.some(p, patterns));
1981
+ }
1982
+ function getSupportedFilePatterns(supportedFiles) {
1983
+ const patterns = [];
1984
+ for (const key of Object.keys(supportedFiles)) {
1985
+ const supported = supportedFiles[key];
1986
+ if (supported) {
1987
+ patterns.push(...Object.values(supported).map(p => `**/${p.pattern}`));
1988
+ }
1989
+ }
1990
+ return patterns;
1991
+ }
1992
+ async function globWithGitIgnore(patterns, options) {
1993
+ const {
1994
+ cwd = process.cwd(),
1995
+ socketConfig,
1996
+ ...additionalOptions
1997
+ } = {
1998
+ __proto__: null,
1999
+ ...options
2000
+ };
2001
+ const ignores = new Set(IGNORED_DIR_PATTERNS);
2002
+ const projectIgnorePaths = socketConfig?.projectIgnorePaths;
2003
+ if (Array.isArray(projectIgnorePaths)) {
2004
+ const ignorePatterns = ignoreFileLinesToGlobPatterns(projectIgnorePaths, path.join(cwd, '.gitignore'), cwd);
2005
+ for (const pattern of ignorePatterns) {
2006
+ ignores.add(pattern);
2007
+ }
2008
+ }
2009
+ const gitIgnoreStream = vendor.outExports.globStream(['**/.gitignore'], {
2010
+ absolute: true,
2011
+ cwd,
2012
+ ignore: DEFAULT_IGNORE_FOR_GIT_IGNORE
2013
+ });
2014
+ for await (const ignorePatterns of streams.transform(gitIgnoreStream, async filepath => ignoreFileToGlobPatterns((await fs.safeReadFile(filepath)) ?? '', filepath, cwd), {
2015
+ concurrency: 8
2016
+ })) {
2017
+ for (const p of ignorePatterns) {
2018
+ ignores.add(p);
2019
+ }
2020
+ }
2021
+ let hasNegatedPattern = false;
2022
+ for (const p of ignores) {
2023
+ if (p.charCodeAt(0) === 33) {
2024
+ hasNegatedPattern = true;
2025
+ break;
2026
+ }
2027
+ }
2028
+ const globOptions = {
2029
+ __proto__: null,
2030
+ absolute: true,
2031
+ cwd,
2032
+ dot: true,
2033
+ ignore: hasNegatedPattern ? globs.defaultIgnore : [...ignores],
2034
+ ...additionalOptions
2035
+ };
2036
+ if (!hasNegatedPattern) {
2037
+ return await vendor.outExports.glob(patterns, globOptions);
2038
+ }
2039
+ const ig = vendor.ignoreExports().add([...ignores]);
2040
+ const filtered = [];
2041
+ const stream = vendor.outExports.globStream(patterns, globOptions);
2042
+ for await (const p of stream) {
2043
+ // Note: the input files must be INSIDE the cwd. If you get strange looking
2044
+ // relative path errors here, most likely your path is outside the given cwd.
2045
+ const relPath = globOptions.absolute ? path.relative(cwd, p) : p;
2046
+ if (!ig.ignores(relPath)) {
2047
+ filtered.push(p);
2048
+ }
2049
+ }
2050
+ return filtered;
2051
+ }
2052
+ async function globStreamNodeModules(cwd = process.cwd()) {
2053
+ return vendor.outExports.globStream('**/node_modules', {
2054
+ absolute: true,
2055
+ cwd,
2056
+ onlyDirectories: true
2057
+ });
2058
+ }
2059
+ async function globWorkspace(agent, cwd = process.cwd()) {
2060
+ const workspaceGlobs = await getWorkspaceGlobs(agent, cwd);
2061
+ return workspaceGlobs.length ? await vendor.outExports.glob(workspaceGlobs, {
2062
+ absolute: true,
2063
+ cwd,
2064
+ ignore: globs.defaultIgnore
2065
+ }) : [];
2066
+ }
2067
+ function isReportSupportedFile(filepath, supportedFiles) {
2068
+ const patterns = getSupportedFilePatterns(supportedFiles);
2069
+ return vendor.micromatchExports.some(filepath, patterns);
2070
+ }
2071
+ function pathsToGlobPatterns(paths) {
2072
+ // TODO: Does not support `~/` paths.
2073
+ return paths.map(p => p === '.' || p === './' ? '**/*' : p);
2074
+ }
2075
+
2144
2076
  function findBinPathDetailsSync(binName) {
2145
2077
  const binPaths = vendor.libExports$1.sync(binName, {
2146
2078
  all: true,
@@ -2186,11 +2118,11 @@ function findNpmDirPathSync(npmBinPath) {
2186
2118
  // Use existsSync here because statsSync, even with { throwIfNoEntry: false },
2187
2119
  // will throw an ENOTDIR error for paths like ./a-file-that-exists/a-directory-that-does-not.
2188
2120
  // See https://github.com/nodejs/node/issues/56993.
2189
- isDirectorySync(libNmNpmPath)) {
2121
+ fs.isDirSync(libNmNpmPath)) {
2190
2122
  thePath = libNmNpmPath;
2191
2123
  }
2192
- const hasSameLevelNmPath = isDirectorySync(path.join(thePath, 'node_modules'));
2193
- const hasOneBackNmPath = !hasSameLevelNmPath && isDirectorySync(path.join(thePath, '../node_modules'));
2124
+ const hasNmInCurrPath = fs.isDirSync(path.join(thePath, 'node_modules'));
2125
+ const hasNmInParentPath = !hasNmInCurrPath && fs.isDirSync(path.join(thePath, '../node_modules'));
2194
2126
  if (
2195
2127
  // npm bin paths may look like:
2196
2128
  // /usr/local/share/npm/bin/npm
@@ -2202,14 +2134,14 @@ function findNpmDirPathSync(npmBinPath) {
2202
2134
  // In practically all cases the npm path contains a node_modules folder:
2203
2135
  // /usr/local/share/npm/bin/npm/node_modules
2204
2136
  // C:\Program Files\nodejs\node_modules
2205
- (hasSameLevelNmPath ||
2206
- // In some bespoke cases the node_modules folder is one level back.
2207
- hasOneBackNmPath) && (
2137
+ (hasNmInCurrPath ||
2138
+ // In some bespoke cases the node_modules folder is in the parent directory.
2139
+ hasNmInParentPath) && (
2208
2140
  // Optimistically look for the default location.
2209
2141
  path.basename(thePath) === 'npm' ||
2210
2142
  // Chocolatey installs npm bins in the same directory as node bins.
2211
- WIN32 && fs.existsSync(path.join(thePath, 'npm.cmd')))) {
2212
- return hasOneBackNmPath ? path.dirname(thePath) : thePath;
2143
+ WIN32 && fs$1.existsSync(path.join(thePath, 'npm.cmd')))) {
2144
+ return hasNmInParentPath ? path.dirname(thePath) : thePath;
2213
2145
  }
2214
2146
  const parent = path.dirname(thePath);
2215
2147
  if (parent === thePath) {
@@ -2252,8 +2184,8 @@ function getDefaultSocketJson() {
2252
2184
  }
2253
2185
  async function readSocketJson(cwd, defaultOnError = false) {
2254
2186
  const sockJsonPath = path.join(cwd, 'socket.json');
2255
- if (!fs.existsSync(sockJsonPath)) {
2256
- debug.debugFn('notice', `miss: file not found ${sockJsonPath}`);
2187
+ if (!fs$1.existsSync(sockJsonPath)) {
2188
+ require$$6.debugFn('notice', `miss: file not found ${sockJsonPath}`);
2257
2189
  return {
2258
2190
  ok: true,
2259
2191
  data: getDefaultSocketJson()
@@ -2261,9 +2193,9 @@ async function readSocketJson(cwd, defaultOnError = false) {
2261
2193
  }
2262
2194
  let json = null;
2263
2195
  try {
2264
- json = await fs.promises.readFile(sockJsonPath, 'utf8');
2196
+ json = await fs$1.promises.readFile(sockJsonPath, 'utf8');
2265
2197
  } catch (e) {
2266
- debug.debugDir('inspect', {
2198
+ require$$6.debugDir('inspect', {
2267
2199
  error: e
2268
2200
  });
2269
2201
  if (defaultOnError) {
@@ -2284,8 +2216,8 @@ async function readSocketJson(cwd, defaultOnError = false) {
2284
2216
  try {
2285
2217
  obj = JSON.parse(json);
2286
2218
  } catch {
2287
- debug.debugFn('error', 'fail: parse JSON');
2288
- debug.debugDir('inspect', {
2219
+ require$$6.debugFn('error', 'fail: parse JSON');
2220
+ require$$6.debugDir('inspect', {
2289
2221
  json
2290
2222
  });
2291
2223
  if (defaultOnError) {
@@ -2322,11 +2254,11 @@ async function writeSocketJson(cwd, sockJson) {
2322
2254
  try {
2323
2255
  json = JSON.stringify(sockJson, null, 2);
2324
2256
  } catch (e) {
2325
- debug.debugFn('error', 'fail: stringify JSON');
2326
- debug.debugDir('inspect', {
2257
+ require$$6.debugFn('error', 'fail: stringify JSON');
2258
+ require$$6.debugDir('inspect', {
2327
2259
  error: e
2328
2260
  });
2329
- debug.debugDir('inspect', {
2261
+ require$$6.debugDir('inspect', {
2330
2262
  sockJson
2331
2263
  });
2332
2264
  return {
@@ -2336,48 +2268,13 @@ async function writeSocketJson(cwd, sockJson) {
2336
2268
  };
2337
2269
  }
2338
2270
  const filepath = path.join(cwd, 'socket.json');
2339
- await fs.promises.writeFile(filepath, json + '\n', 'utf8');
2271
+ await fs$1.promises.writeFile(filepath, json + '\n', 'utf8');
2340
2272
  return {
2341
2273
  ok: true,
2342
2274
  data: undefined
2343
2275
  };
2344
2276
  }
2345
2277
 
2346
- const helpFlags = new Set(['--help', '-h']);
2347
- function cmdFlagsToString(args) {
2348
- const result = [];
2349
- for (let i = 0, {
2350
- length
2351
- } = args; i < length; i += 1) {
2352
- if (args[i].startsWith('--')) {
2353
- // Check if the next item exists and is NOT another flag.
2354
- if (i + 1 < length && !args[i + 1].startsWith('--')) {
2355
- result.push(`${args[i]}=${args[i + 1]}`);
2356
- i += 1;
2357
- } else {
2358
- result.push(args[i]);
2359
- }
2360
- }
2361
- }
2362
- return result.join(' ');
2363
- }
2364
- function cmdFlagValueToArray(flagValue) {
2365
- if (typeof flagValue === 'string') {
2366
- return flagValue.trim().split(/, */);
2367
- }
2368
- if (Array.isArray(flagValue)) {
2369
- return flagValue.flatMap(v => v.split(/, */));
2370
- }
2371
- return [];
2372
- }
2373
- function cmdPrefixMessage(cmdName, text) {
2374
- const cmdPrefix = cmdName ? `${cmdName}: ` : '';
2375
- return `${cmdPrefix}${text}`;
2376
- }
2377
- function isHelpFlag(cmdArg) {
2378
- return helpFlags.has(cmdArg);
2379
- }
2380
-
2381
2278
  async function spawnCoana(args, options, extra) {
2382
2279
  const {
2383
2280
  env: spawnEnv
@@ -2480,7 +2377,7 @@ function getNpmRequire() {
2480
2377
  if (_npmRequire === undefined) {
2481
2378
  const npmDirPath = getNpmDirPath();
2482
2379
  const npmNmPath = path.join(npmDirPath, NODE_MODULES, NPM$3);
2483
- _npmRequire = require$$5.createRequire(path.join(fs.existsSync(npmNmPath) ? npmNmPath : npmDirPath, '<dummy-basename>'));
2380
+ _npmRequire = require$$5.createRequire(path.join(fs$1.existsSync(npmNmPath) ? npmNmPath : npmDirPath, '<dummy-basename>'));
2484
2381
  }
2485
2382
  return _npmRequire;
2486
2383
  }
@@ -2898,12 +2795,12 @@ function getCveInfoFromAlertsMap(alertsMap, options) {
2898
2795
  error = e;
2899
2796
  }
2900
2797
  }
2901
- debug.debugFn('error', 'fail: invalid SocketPackageAlert');
2902
- debug.debugDir('inspect', {
2798
+ require$$6.debugFn('error', 'fail: invalid SocketPackageAlert');
2799
+ require$$6.debugDir('inspect', {
2903
2800
  alert
2904
2801
  });
2905
2802
  if (error) {
2906
- debug.debugDir('inspect', {
2803
+ require$$6.debugDir('inspect', {
2907
2804
  error: error.message ?? error
2908
2805
  });
2909
2806
  }
@@ -3164,7 +3061,7 @@ async function getAlertsMapFromPurls(purls, options) {
3164
3061
  ...opts.include
3165
3062
  };
3166
3063
  const uniqPurls = arrays.arrayUnique(purls);
3167
- debug.debugDir('silly', {
3064
+ require$$6.debugDir('silly', {
3168
3065
  purls: uniqPurls
3169
3066
  });
3170
3067
  let {
@@ -3218,7 +3115,7 @@ async function getAlertsMapFromPurls(purls, options) {
3218
3115
  } else {
3219
3116
  spinner?.stop();
3220
3117
  logger.logger.fail(`Received a ${batchResult.status} response from Socket API which we consider a permanent failure:`, batchResult.error, batchResult.cause ? `( ${batchResult.cause} )` : '');
3221
- debug.debugDir('inspect', {
3118
+ require$$6.debugDir('inspect', {
3222
3119
  batchResult
3223
3120
  });
3224
3121
  break;
@@ -3239,6 +3136,79 @@ function npa(...args) {
3239
3136
  return null;
3240
3137
  }
3241
3138
 
3139
+ async function removeNodeModules(cwd = process.cwd()) {
3140
+ const stream = await globStreamNodeModules(cwd);
3141
+ await streams.parallelEach(stream, p => fs.remove(p, {
3142
+ force: true,
3143
+ recursive: true
3144
+ }), {
3145
+ concurrency: 8
3146
+ });
3147
+ }
3148
+ async function findUp(name, {
3149
+ cwd = process.cwd(),
3150
+ // Lazily access constants.abortSignal.
3151
+ signal = constants.abortSignal
3152
+ }) {
3153
+ let dir = path.resolve(cwd);
3154
+ const {
3155
+ root
3156
+ } = path.parse(dir);
3157
+ const names = [name].flat();
3158
+ while (dir && dir !== root) {
3159
+ for (const name of names) {
3160
+ if (signal?.aborted) {
3161
+ return undefined;
3162
+ }
3163
+ const filePath = path.join(dir, name);
3164
+ try {
3165
+ // eslint-disable-next-line no-await-in-loop
3166
+ const stats = await fs$1.promises.stat(filePath);
3167
+ if (stats.isFile()) {
3168
+ return filePath;
3169
+ }
3170
+ } catch {}
3171
+ }
3172
+ dir = path.dirname(dir);
3173
+ }
3174
+ return undefined;
3175
+ }
3176
+
3177
+ const helpFlags = new Set(['--help', '-h']);
3178
+ function cmdFlagsToString(args) {
3179
+ const result = [];
3180
+ for (let i = 0, {
3181
+ length
3182
+ } = args; i < length; i += 1) {
3183
+ if (args[i].startsWith('--')) {
3184
+ // Check if the next item exists and is NOT another flag.
3185
+ if (i + 1 < length && !args[i + 1].startsWith('--')) {
3186
+ result.push(`${args[i]}=${args[i + 1]}`);
3187
+ i += 1;
3188
+ } else {
3189
+ result.push(args[i]);
3190
+ }
3191
+ }
3192
+ }
3193
+ return result.join(' ');
3194
+ }
3195
+ function cmdFlagValueToArray(flagValue) {
3196
+ if (typeof flagValue === 'string') {
3197
+ return flagValue.trim().split(/, */);
3198
+ }
3199
+ if (Array.isArray(flagValue)) {
3200
+ return flagValue.flatMap(v => v.split(/, */));
3201
+ }
3202
+ return [];
3203
+ }
3204
+ function cmdPrefixMessage(cmdName, text) {
3205
+ const cmdPrefix = cmdName ? `${cmdName}: ` : '';
3206
+ return `${cmdPrefix}${text}`;
3207
+ }
3208
+ function isHelpFlag(cmdArg) {
3209
+ return helpFlags.has(cmdArg);
3210
+ }
3211
+
3242
3212
  const {
3243
3213
  NPM: NPM$2,
3244
3214
  SOCKET_CLI_SAFE_BIN,
@@ -3266,7 +3236,7 @@ function safeNpmInstall(options) {
3266
3236
  } else if (useIpc && Array.isArray(stdio) && !stdio.includes('ipc')) {
3267
3237
  stdio = stdio.concat('ipc');
3268
3238
  }
3269
- const useDebug = debug.isDebug('stdio');
3239
+ const useDebug = require$$6.isDebug('stdio');
3270
3240
  const terminatorPos = args.indexOf('--');
3271
3241
  const rawBinArgs = terminatorPos === -1 ? args : args.slice(0, terminatorPos);
3272
3242
  const progressArg = rawBinArgs.findLast(npm.isNpmProgressFlag) !== '--no-progress';
@@ -3408,7 +3378,7 @@ async function getNpmConfig(options) {
3408
3378
  }
3409
3379
 
3410
3380
  async function readLockfile(lockfilePath) {
3411
- return fs.existsSync(lockfilePath) ? await readFileUtf8(lockfilePath) : null;
3381
+ return fs$1.existsSync(lockfilePath) ? await fs.readFileUtf8(lockfilePath) : null;
3412
3382
  }
3413
3383
 
3414
3384
  const {
@@ -3436,8 +3406,8 @@ const readLockFileByAgent = (() => {
3436
3406
  return undefined;
3437
3407
  };
3438
3408
  }
3439
- const binaryReader = wrapReader(readFileBinary);
3440
- const defaultReader = wrapReader(async lockPath => await readFileUtf8(lockPath));
3409
+ const binaryReader = wrapReader(fs.readFileBinary);
3410
+ const defaultReader = wrapReader(async lockPath => await fs.readFileUtf8(lockPath));
3441
3411
  return new Map([[BUN, wrapReader(async (lockPath, agentExecPath, cwd = process.cwd()) => {
3442
3412
  const ext = path.extname(lockPath);
3443
3413
  if (ext === LOCK_EXT) {
@@ -3510,8 +3480,8 @@ async function getAgentVersion(agentExecPath, cwd) {
3510
3480
  shell: constants.WIN32
3511
3481
  })).stdout) ?? undefined;
3512
3482
  } catch (e) {
3513
- debug.debugFn('error', 'caught: unexpected error');
3514
- debug.debugDir('inspect', {
3483
+ require$$6.debugFn('error', 'caught: unexpected error');
3484
+ require$$6.debugDir('inspect', {
3515
3485
  error: e
3516
3486
  });
3517
3487
  }
@@ -3529,7 +3499,7 @@ async function detectPackageEnvironment({
3529
3499
  const pkgJsonPath = lockPath ? path.resolve(lockPath, `${isHiddenLockFile ? '../' : ''}../${PACKAGE_JSON}`) : await findUp(PACKAGE_JSON, {
3530
3500
  cwd
3531
3501
  });
3532
- const pkgPath = pkgJsonPath && fs.existsSync(pkgJsonPath) ? path.dirname(pkgJsonPath) : undefined;
3502
+ const pkgPath = pkgJsonPath && fs$1.existsSync(pkgJsonPath) ? path.dirname(pkgJsonPath) : undefined;
3533
3503
  const editablePkgJson = pkgPath ? await packages.readPackageJson(pkgPath, {
3534
3504
  editable: true
3535
3505
  }) : undefined;
@@ -3755,7 +3725,7 @@ function getCompletionSourcingCommand() {
3755
3725
  const completionScriptExportPath = path.join(
3756
3726
  // Lazily access constants.distPath.
3757
3727
  constants.distPath, 'socket-completion.bash');
3758
- if (!fs.existsSync(completionScriptExportPath)) {
3728
+ if (!fs$1.existsSync(completionScriptExportPath)) {
3759
3729
  return {
3760
3730
  ok: false,
3761
3731
  message: 'Tab Completion script not found',
@@ -3891,9 +3861,6 @@ exports.readOrDefaultSocketJson = readOrDefaultSocketJson;
3891
3861
  exports.readSocketJson = readSocketJson;
3892
3862
  exports.removeNodeModules = removeNodeModules;
3893
3863
  exports.runAgentInstall = runAgentInstall;
3894
- exports.safeReadFile = safeReadFile;
3895
- exports.safeReadFileSync = safeReadFileSync;
3896
- exports.safeStatsSync = safeStatsSync;
3897
3864
  exports.serializeResultJson = serializeResultJson;
3898
3865
  exports.setupSdk = setupSdk;
3899
3866
  exports.spawnCoana = spawnCoana;
@@ -3902,5 +3869,5 @@ exports.tildify = tildify;
3902
3869
  exports.updateConfigValue = updateConfigValue;
3903
3870
  exports.walkNestedMap = walkNestedMap;
3904
3871
  exports.writeSocketJson = writeSocketJson;
3905
- //# debugId=19689308-c98a-486d-b9ee-6cfdd0348af0
3872
+ //# debugId=97cbba5e-7a53-4df3-9a47-3d2e8287b36b
3906
3873
  //# sourceMappingURL=utils.js.map