@socketsecurity/cli-with-sentry 0.14.44

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +121 -0
  3. package/bin/cli.js +57 -0
  4. package/bin/npm-cli.js +6 -0
  5. package/bin/npx-cli.js +6 -0
  6. package/dist/constants.d.ts +162 -0
  7. package/dist/constants.js +8 -0
  8. package/dist/constants.js.map +1 -0
  9. package/dist/init.gradle +250 -0
  10. package/dist/instrument-with-sentry.d.ts +1 -0
  11. package/dist/instrument-with-sentry.js +58 -0
  12. package/dist/instrument-with-sentry.js.map +1 -0
  13. package/dist/module-sync/cli.d.ts +2 -0
  14. package/dist/module-sync/cli.js +6851 -0
  15. package/dist/module-sync/cli.js.map +1 -0
  16. package/dist/module-sync/constants.js +3 -0
  17. package/dist/module-sync/constants2.d.ts +0 -0
  18. package/dist/module-sync/constants2.js +231 -0
  19. package/dist/module-sync/constants2.js.map +1 -0
  20. package/dist/module-sync/debug.d.ts +3 -0
  21. package/dist/module-sync/edge.d.ts +66 -0
  22. package/dist/module-sync/errors.d.ts +14 -0
  23. package/dist/module-sync/index.d.ts +192 -0
  24. package/dist/module-sync/index.js +1879 -0
  25. package/dist/module-sync/index.js.map +1 -0
  26. package/dist/module-sync/logging.d.ts +16 -0
  27. package/dist/module-sync/node.d.ts +84 -0
  28. package/dist/module-sync/npm-injection.d.ts +1 -0
  29. package/dist/module-sync/npm-injection.js +26 -0
  30. package/dist/module-sync/npm-injection.js.map +1 -0
  31. package/dist/module-sync/npm-paths.d.ts +15 -0
  32. package/dist/module-sync/npm-paths.js +423 -0
  33. package/dist/module-sync/npm-paths.js.map +1 -0
  34. package/dist/module-sync/npm.d.ts +24 -0
  35. package/dist/module-sync/npm.js +99 -0
  36. package/dist/module-sync/npm.js.map +1 -0
  37. package/dist/module-sync/path-resolve.d.ts +12 -0
  38. package/dist/module-sync/proc-log.d.ts +3 -0
  39. package/dist/module-sync/reify.d.ts +1018 -0
  40. package/dist/module-sync/sdk.d.ts +5 -0
  41. package/dist/module-sync/settings.d.ts +15 -0
  42. package/dist/module-sync/shadow-bin.d.ts +2 -0
  43. package/dist/module-sync/shadow-bin.js +103 -0
  44. package/dist/module-sync/shadow-bin.js.map +1 -0
  45. package/dist/module-sync/types.d.ts +45 -0
  46. package/dist/require/cli.js +6848 -0
  47. package/dist/require/constants.js +3 -0
  48. package/dist/require/index.js +3 -0
  49. package/dist/require/npm-injection.js +3 -0
  50. package/dist/require/npm-paths.js +3 -0
  51. package/dist/require/npm.js +3 -0
  52. package/dist/require/shadow-bin.js +3 -0
  53. package/dist/require/vendor.js +11474 -0
  54. package/package.json +245 -0
  55. package/shadow-bin/npm +4 -0
  56. package/shadow-bin/npx +4 -0
  57. package/translations.json +592 -0
@@ -0,0 +1,423 @@
1
+ 'use strict';
2
+
3
+ function _socketInterop(e) {
4
+ let c = 0
5
+ for (const k in e ?? {}) {
6
+ c = c === 0 && k === 'default' ? 1 : 0
7
+ if (!c && k !== '__esModule') break
8
+ }
9
+ return c ? e.default : e
10
+ }
11
+
12
+ var fs = require('node:fs');
13
+ var Module = require('node:module');
14
+ var path = require('node:path');
15
+ var process = require('node:process');
16
+ var path$1 = require('@socketsecurity/registry/lib/path');
17
+ var constants = require('./constants2.js');
18
+ var ignore = _socketInterop(require('ignore'));
19
+ var micromatch = _socketInterop(require('micromatch'));
20
+ var tinyglobby = _socketInterop(require('tinyglobby'));
21
+ var which = _socketInterop(require('which'));
22
+ var colors = _socketInterop(require('yoctocolors-cjs'));
23
+ var isUnicodeSupported = require('@socketregistry/is-unicode-supported/index.cjs');
24
+ var spinner = require('@socketsecurity/registry/lib/spinner');
25
+
26
+ let _logSymbols;
27
+ function getLogSymbols() {
28
+ if (_logSymbols === undefined) {
29
+ _logSymbols = isUnicodeSupported() ? {
30
+ __proto__: null,
31
+ info: colors.blue('ℹ'),
32
+ success: colors.green('✔'),
33
+ warning: colors.yellow('⚠'),
34
+ error: colors.red('✖️')
35
+ } : {
36
+ __proto__: null,
37
+ info: colors.blue('i'),
38
+ success: colors.green('√'),
39
+ warning: colors.yellow('‼'),
40
+ error: colors.red('×')
41
+ };
42
+ }
43
+ return _logSymbols;
44
+ }
45
+ class Logger {
46
+ #spinnerLogger;
47
+ constructor() {
48
+ this.#spinnerLogger = new spinner.Spinner();
49
+ }
50
+ error(text) {
51
+ this.#spinnerLogger.error(text);
52
+ }
53
+ info(text) {
54
+ this.#spinnerLogger.info(text);
55
+ }
56
+ warn(text) {
57
+ this.#spinnerLogger.warning(text);
58
+ }
59
+ }
60
+ const logger = new Logger();
61
+
62
+ function isDebug() {
63
+ // Lazily access constants.ENV.
64
+ return constants.constants.ENV.SOCKET_CLI_DEBUG;
65
+ }
66
+ function debugLog(...args) {
67
+ if (isDebug()) {
68
+ console.error(getLogSymbols().info, ...args);
69
+ }
70
+ }
71
+
72
+ const ignoredDirs = [
73
+ // Taken from ignore-by-default:
74
+ // https://github.com/novemberborn/ignore-by-default/blob/v2.1.0/index.js
75
+ '.git',
76
+ // Git repository files, see <https://git-scm.com/>
77
+ '.log',
78
+ // Log files emitted by tools such as `tsserver`, see <https://github.com/Microsoft/TypeScript/wiki/Standalone-Server-%28tsserver%29>
79
+ '.nyc_output',
80
+ // Temporary directory where nyc stores coverage data, see <https://github.com/bcoe/nyc>
81
+ '.sass-cache',
82
+ // Cache folder for node-sass, see <https://github.com/sass/node-sass>
83
+ '.yarn',
84
+ // Where node modules are installed when using Yarn, see <https://yarnpkg.com/>
85
+ 'bower_components',
86
+ // Where Bower packages are installed, see <http://bower.io/>
87
+ 'coverage',
88
+ // Standard output directory for code coverage reports, see <https://github.com/gotwarlost/istanbul>
89
+ 'node_modules',
90
+ // Where Node modules are installed, see <https://nodejs.org/>
91
+ // Taken from globby:
92
+ // https://github.com/sindresorhus/globby/blob/v14.0.2/ignore.js#L11-L16
93
+ 'flow-typed'];
94
+ const ignoredDirPatterns = ignoredDirs.map(i => `**/${i}`);
95
+ function directoryPatterns() {
96
+ return [...ignoredDirPatterns];
97
+ }
98
+
99
+ const {
100
+ NODE_MODULES: NODE_MODULES$1,
101
+ NPM: NPM$1,
102
+ shadowBinPath
103
+ } = constants.constants;
104
+ async function filterGlobResultToSupportedFiles(entries, supportedFiles) {
105
+ const patterns = ['golang', NPM$1, 'maven', 'pypi'].reduce((r, n) => {
106
+ const supported = supportedFiles[n];
107
+ r.push(...(supported ? Object.values(supported).map(p => `**/${p.pattern}`) : []));
108
+ return r;
109
+ }, []);
110
+ return entries.filter(p => micromatch.some(p, patterns));
111
+ }
112
+ async function globWithGitIgnore(patterns, options) {
113
+ const {
114
+ cwd = process.cwd(),
115
+ socketConfig,
116
+ ...additionalOptions
117
+ } = {
118
+ __proto__: null,
119
+ ...options
120
+ };
121
+ const projectIgnorePaths = socketConfig?.projectIgnorePaths;
122
+ const ignoreFiles = await tinyglobby.glob(['**/.gitignore'], {
123
+ absolute: true,
124
+ cwd,
125
+ expandDirectories: true
126
+ });
127
+ const ignores = [...directoryPatterns(), ...(Array.isArray(projectIgnorePaths) ? ignoreFileLinesToGlobPatterns(projectIgnorePaths, path.join(cwd, '.gitignore'), cwd) : []), ...(await Promise.all(ignoreFiles.map(async filepath => ignoreFileToGlobPatterns(await fs.promises.readFile(filepath, 'utf8'), filepath, cwd)))).flat()];
128
+ const hasNegatedPattern = ignores.some(p => p.charCodeAt(0) === 33 /*'!'*/);
129
+ const globOptions = {
130
+ absolute: true,
131
+ cwd,
132
+ expandDirectories: false,
133
+ ignore: hasNegatedPattern ? [] : ignores,
134
+ ...additionalOptions
135
+ };
136
+ const result = await tinyglobby.glob(patterns, globOptions);
137
+ if (!hasNegatedPattern) {
138
+ return result;
139
+ }
140
+ const {
141
+ absolute
142
+ } = globOptions;
143
+
144
+ // Note: the input files must be INSIDE the cwd. If you get strange looking
145
+ // relative path errors here, most likely your path is outside the given cwd.
146
+ const filtered = ignore().add(ignores).filter(absolute ? result.map(p => path.relative(cwd, p)) : result);
147
+ return absolute ? filtered.map(p => path.resolve(cwd, p)) : filtered;
148
+ }
149
+ function ignoreFileLinesToGlobPatterns(lines, filepath, cwd) {
150
+ const base = path.relative(cwd, path.dirname(filepath)).replace(/\\/g, '/');
151
+ const patterns = [];
152
+ for (let i = 0, {
153
+ length
154
+ } = lines; i < length; i += 1) {
155
+ const pattern = lines[i].trim();
156
+ if (pattern.length > 0 && pattern.charCodeAt(0) !== 35 /*'#'*/) {
157
+ patterns.push(ignorePatternToMinimatch(pattern.length && pattern.charCodeAt(0) === 33 /*'!'*/ ? `!${path.posix.join(base, pattern.slice(1))}` : path.posix.join(base, pattern)));
158
+ }
159
+ }
160
+ return patterns;
161
+ }
162
+ function ignoreFileToGlobPatterns(content, filepath, cwd) {
163
+ return ignoreFileLinesToGlobPatterns(content.split(/\r?\n/), filepath, cwd);
164
+ }
165
+
166
+ // Based on `@eslint/compat` convertIgnorePatternToMinimatch.
167
+ // Apache v2.0 licensed
168
+ // Copyright Nicholas C. Zakas
169
+ // https://github.com/eslint/rewrite/blob/compat-v1.2.1/packages/compat/src/ignore-file.js#L28
170
+ function ignorePatternToMinimatch(pattern) {
171
+ const isNegated = pattern.startsWith('!');
172
+ const negatedPrefix = isNegated ? '!' : '';
173
+ const patternToTest = (isNegated ? pattern.slice(1) : pattern).trimEnd();
174
+ // Special cases.
175
+ if (patternToTest === '' || patternToTest === '**' || patternToTest === '/**' || patternToTest === '**') {
176
+ return `${negatedPrefix}${patternToTest}`;
177
+ }
178
+ const firstIndexOfSlash = patternToTest.indexOf('/');
179
+ const matchEverywherePrefix = firstIndexOfSlash === -1 || firstIndexOfSlash === patternToTest.length - 1 ? '**/' : '';
180
+ const patternWithoutLeadingSlash = firstIndexOfSlash === 0 ? patternToTest.slice(1) : patternToTest;
181
+ // Escape `{` and `(` because in gitignore patterns they are just
182
+ // literal characters without any specific syntactic meaning,
183
+ // while in minimatch patterns they can form brace expansion or extglob syntax.
184
+ //
185
+ // For example, gitignore pattern `src/{a,b}.js` ignores file `src/{a,b}.js`.
186
+ // But, the same minimatch pattern `src/{a,b}.js` ignores files `src/a.js` and `src/b.js`.
187
+ // Minimatch pattern `src/\{a,b}.js` is equivalent to gitignore pattern `src/{a,b}.js`.
188
+ const escapedPatternWithoutLeadingSlash = patternWithoutLeadingSlash.replaceAll(/(?=((?:\\.|[^{(])*))\1([{(])/guy, '$1\\$2');
189
+ const matchInsideSuffix = patternToTest.endsWith('/**') ? '/*' : '';
190
+ return `${negatedPrefix}${matchEverywherePrefix}${escapedPatternWithoutLeadingSlash}${matchInsideSuffix}`;
191
+ }
192
+ function pathsToPatterns(paths) {
193
+ // TODO: Does not support `~/` paths.
194
+ return paths.map(p => p === '.' ? '**/*' : p);
195
+ }
196
+ function findBinPathDetailsSync(binName) {
197
+ let shadowIndex = -1;
198
+ const bins = which.sync(binName, {
199
+ all: true,
200
+ nothrow: true
201
+ }) ?? [];
202
+ let binPath;
203
+ for (let i = 0, {
204
+ length
205
+ } = bins; i < length; i += 1) {
206
+ const bin = fs.realpathSync.native(bins[i]);
207
+ // Skip our bin directory if it's in the front.
208
+ if (path.dirname(bin) === shadowBinPath) {
209
+ shadowIndex = i;
210
+ } else {
211
+ binPath = bin;
212
+ break;
213
+ }
214
+ }
215
+ return {
216
+ name: binName,
217
+ path: binPath,
218
+ shadowed: shadowIndex !== -1
219
+ };
220
+ }
221
+ function findNpmPathSync(npmBinPath) {
222
+ let thePath = npmBinPath;
223
+ while (true) {
224
+ const nmPath = path.join(thePath, NODE_MODULES$1);
225
+ if (
226
+ // npm bin paths may look like:
227
+ // /usr/local/share/npm/bin/npm
228
+ // /Users/SomeUsername/.nvm/versions/node/vX.X.X/bin/npm
229
+ // C:\Users\SomeUsername\AppData\Roaming\npm\bin\npm.cmd
230
+ // OR
231
+ // C:\Program Files\nodejs\npm.cmd
232
+ //
233
+ // In all cases the npm path contains a node_modules folder:
234
+ // /usr/local/share/npm/bin/npm/node_modules
235
+ // C:\Program Files\nodejs\node_modules
236
+ //
237
+ // Use existsSync here because statsSync, even with { throwIfNoEntry: false },
238
+ // will throw an ENOTDIR error for paths like ./a-file-that-exists/a-directory-that-does-not.
239
+ // See https://github.com/nodejs/node/issues/56993.
240
+ fs.existsSync(nmPath) && fs.statSync(nmPath, {
241
+ throwIfNoEntry: false
242
+ })?.isDirectory() && (
243
+ // Optimistically look for the default location.
244
+ path.basename(thePath) === NPM$1 ||
245
+ // Chocolatey installs npm bins in the same directory as node bins.
246
+ // Lazily access constants.WIN32.
247
+ constants.constants.WIN32 && fs.existsSync(path.join(thePath, `${NPM$1}.cmd`)))) {
248
+ return thePath;
249
+ }
250
+ const parent = path.dirname(thePath);
251
+ if (parent === thePath) {
252
+ return undefined;
253
+ }
254
+ thePath = parent;
255
+ }
256
+ }
257
+ async function getPackageFiles(cwd, inputPaths, config, supportedFiles) {
258
+ debugLog(`Globbed resolving ${inputPaths.length} paths:`, inputPaths);
259
+ const entries = await globWithGitIgnore(pathsToPatterns(inputPaths), {
260
+ cwd,
261
+ socketConfig: config
262
+ });
263
+ debugLog(`Globbed resolved ${inputPaths.length} paths to ${entries.length} paths:`, entries);
264
+ const packageFiles = await filterGlobResultToSupportedFiles(entries, supportedFiles);
265
+ debugLog(`Mapped ${entries.length} entries to ${packageFiles.length} files:`, packageFiles);
266
+ return packageFiles;
267
+ }
268
+ async function getPackageFilesFullScans(cwd, inputPaths, supportedFiles, debugLog = () => {}) {
269
+ debugLog(`Globbed resolving ${inputPaths.length} paths:`, inputPaths);
270
+ const entries = await globWithGitIgnore(pathsToPatterns(inputPaths), {
271
+ cwd
272
+ });
273
+ debugLog(`Globbed resolved ${inputPaths.length} paths to ${entries.length} paths:`, entries);
274
+ const packageFiles = await filterGlobResultToSupportedFiles(entries, supportedFiles);
275
+ debugLog(`Mapped ${entries.length} entries to ${packageFiles.length} files:`, packageFiles);
276
+ return packageFiles;
277
+ }
278
+
279
+ const {
280
+ NODE_MODULES,
281
+ NPM,
282
+ NPX,
283
+ SOCKET_CLI_ISSUES_URL
284
+ } = constants.constants;
285
+ function exitWithBinPathError(binName) {
286
+ console.error(`Socket unable to locate ${binName}; ensure it is available in the PATH environment variable.`);
287
+ // The exit code 127 indicates that the command or binary being executed
288
+ // could not be found.
289
+ process.exit(127);
290
+ }
291
+ let _npmBinPathDetails;
292
+ function getNpmBinPathDetails() {
293
+ if (_npmBinPathDetails === undefined) {
294
+ _npmBinPathDetails = findBinPathDetailsSync(NPM);
295
+ }
296
+ return _npmBinPathDetails;
297
+ }
298
+ let _npxBinPathDetails;
299
+ function getNpxBinPathDetails() {
300
+ if (_npxBinPathDetails === undefined) {
301
+ _npxBinPathDetails = findBinPathDetailsSync(NPX);
302
+ }
303
+ return _npxBinPathDetails;
304
+ }
305
+ let _npmBinPath;
306
+ function getNpmBinPath() {
307
+ if (_npmBinPath === undefined) {
308
+ _npmBinPath = getNpmBinPathDetails().path;
309
+ if (!_npmBinPath) {
310
+ exitWithBinPathError(NPM);
311
+ }
312
+ }
313
+ return _npmBinPath;
314
+ }
315
+ function isNpmBinPathShadowed() {
316
+ return getNpmBinPathDetails().shadowed;
317
+ }
318
+ let _npxBinPath;
319
+ function getNpxBinPath() {
320
+ if (_npxBinPath === undefined) {
321
+ _npxBinPath = getNpxBinPathDetails().path;
322
+ if (!_npxBinPath) {
323
+ exitWithBinPathError(NPX);
324
+ }
325
+ }
326
+ return _npxBinPath;
327
+ }
328
+ function isNpxBinPathShadowed() {
329
+ return getNpxBinPathDetails().shadowed;
330
+ }
331
+ let _npmPath;
332
+ function getNpmPath() {
333
+ if (_npmPath === undefined) {
334
+ const npmBinPath = getNpmBinPath();
335
+ _npmPath = npmBinPath ? findNpmPathSync(npmBinPath) : undefined;
336
+ if (!_npmPath) {
337
+ let message = 'Unable to find npm CLI install directory.';
338
+ if (npmBinPath) {
339
+ message += `\nSearched parent directories of ${path.dirname(npmBinPath)}.`;
340
+ }
341
+ message += `\n\nThis is may be a bug with socket-npm related to changes to the npm CLI.\nPlease report to ${SOCKET_CLI_ISSUES_URL}.`;
342
+ console.error(message);
343
+ // The exit code 127 indicates that the command or binary being executed
344
+ // could not be found.
345
+ process.exit(127);
346
+ }
347
+ }
348
+ return _npmPath;
349
+ }
350
+ let _npmRequire;
351
+ function getNpmRequire() {
352
+ if (_npmRequire === undefined) {
353
+ const npmPath = getNpmPath();
354
+ const npmNmPath = path.join(npmPath, NODE_MODULES, NPM);
355
+ _npmRequire = Module.createRequire(path.join(fs.existsSync(npmNmPath) ? npmNmPath : npmPath, '<dummy-basename>'));
356
+ }
357
+ return _npmRequire;
358
+ }
359
+ let _arboristPkgPath;
360
+ function getArboristPackagePath() {
361
+ if (_arboristPkgPath === undefined) {
362
+ const pkgName = '@npmcli/arborist';
363
+ const mainPathWithForwardSlashes = path$1.normalizePath(getNpmRequire().resolve(pkgName));
364
+ const arboristPkgPathWithForwardSlashes = mainPathWithForwardSlashes.slice(0, mainPathWithForwardSlashes.lastIndexOf(pkgName) + pkgName.length);
365
+ // Lazily access constants.WIN32.
366
+ _arboristPkgPath = constants.constants.WIN32 ? path.normalize(arboristPkgPathWithForwardSlashes) : arboristPkgPathWithForwardSlashes;
367
+ }
368
+ return _arboristPkgPath;
369
+ }
370
+ let _arboristClassPath;
371
+ function getArboristClassPath() {
372
+ if (_arboristClassPath === undefined) {
373
+ _arboristClassPath = path.join(getArboristPackagePath(), 'lib/arborist/index.js');
374
+ }
375
+ return _arboristClassPath;
376
+ }
377
+ let _arboristDepValidPath;
378
+ function getArboristDepValidPath() {
379
+ if (_arboristDepValidPath === undefined) {
380
+ _arboristDepValidPath = path.join(getArboristPackagePath(), 'lib/dep-valid.js');
381
+ }
382
+ return _arboristDepValidPath;
383
+ }
384
+ let _arboristEdgeClassPath;
385
+ function getArboristEdgeClassPath() {
386
+ if (_arboristEdgeClassPath === undefined) {
387
+ _arboristEdgeClassPath = path.join(getArboristPackagePath(), 'lib/edge.js');
388
+ }
389
+ return _arboristEdgeClassPath;
390
+ }
391
+ let _arboristNodeClassPath;
392
+ function getArboristNodeClassPath() {
393
+ if (_arboristNodeClassPath === undefined) {
394
+ _arboristNodeClassPath = path.join(getArboristPackagePath(), 'lib/node.js');
395
+ }
396
+ return _arboristNodeClassPath;
397
+ }
398
+ let _arboristOverrideSetClassPath;
399
+ function getArboristOverrideSetClassPath() {
400
+ if (_arboristOverrideSetClassPath === undefined) {
401
+ _arboristOverrideSetClassPath = path.join(getArboristPackagePath(), 'lib/override-set.js');
402
+ }
403
+ return _arboristOverrideSetClassPath;
404
+ }
405
+
406
+ exports.debugLog = debugLog;
407
+ exports.getArboristClassPath = getArboristClassPath;
408
+ exports.getArboristDepValidPath = getArboristDepValidPath;
409
+ exports.getArboristEdgeClassPath = getArboristEdgeClassPath;
410
+ exports.getArboristNodeClassPath = getArboristNodeClassPath;
411
+ exports.getArboristOverrideSetClassPath = getArboristOverrideSetClassPath;
412
+ exports.getLogSymbols = getLogSymbols;
413
+ exports.getNpmBinPath = getNpmBinPath;
414
+ exports.getNpmRequire = getNpmRequire;
415
+ exports.getNpxBinPath = getNpxBinPath;
416
+ exports.getPackageFiles = getPackageFiles;
417
+ exports.getPackageFilesFullScans = getPackageFilesFullScans;
418
+ exports.isDebug = isDebug;
419
+ exports.isNpmBinPathShadowed = isNpmBinPathShadowed;
420
+ exports.isNpxBinPathShadowed = isNpxBinPathShadowed;
421
+ exports.logger = logger;
422
+ //# debugId=ff4e9bce-e186-418c-a87c-6ea63ce4776e
423
+ //# sourceMappingURL=npm-paths.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"npm-paths.js","sources":["../../src/utils/logging.ts","../../src/utils/debug.ts","../../src/utils/ignore-by-default.ts","../../src/utils/path-resolve.ts","../../src/shadow/npm-paths.ts"],"sourcesContent":["import colors from 'yoctocolors-cjs'\n\nimport isUnicodeSupported from '@socketregistry/is-unicode-supported/index.cjs'\nimport { Spinner } from '@socketsecurity/registry/lib/spinner'\n\nexport type LogSymbols = {\n info: string\n success: string\n warning: string\n error: string\n}\n\nlet _logSymbols: LogSymbols | undefined\nexport function getLogSymbols() {\n if (_logSymbols === undefined) {\n _logSymbols = <LogSymbols>(isUnicodeSupported()\n ? {\n __proto__: null,\n info: colors.blue('ℹ'),\n success: colors.green('✔'),\n warning: colors.yellow('⚠'),\n error: colors.red('✖️')\n }\n : {\n __proto__: null,\n info: colors.blue('i'),\n success: colors.green('√'),\n warning: colors.yellow('‼'),\n error: colors.red('×')\n })\n }\n return _logSymbols\n}\n\nexport class Logger {\n #spinnerLogger: ReturnType<typeof Spinner>\n constructor() {\n this.#spinnerLogger = new Spinner()\n }\n\n error(text: string) {\n this.#spinnerLogger.error(text)\n }\n\n info(text: string) {\n this.#spinnerLogger.info(text)\n }\n\n warn(text: string) {\n this.#spinnerLogger.warning(text)\n }\n}\n\nexport const logger = new Logger()\n","import { getLogSymbols } from './logging'\nimport constants from '../constants'\n\nexport function isDebug() {\n // Lazily access constants.ENV.\n return constants.ENV.SOCKET_CLI_DEBUG\n}\n\nexport function debugLog(...args: any[]) {\n if (isDebug()) {\n console.error(getLogSymbols().info, ...args)\n }\n}\n","const ignoredDirs = [\n // Taken from ignore-by-default:\n // https://github.com/novemberborn/ignore-by-default/blob/v2.1.0/index.js\n '.git', // Git repository files, see <https://git-scm.com/>\n '.log', // Log files emitted by tools such as `tsserver`, see <https://github.com/Microsoft/TypeScript/wiki/Standalone-Server-%28tsserver%29>\n '.nyc_output', // Temporary directory where nyc stores coverage data, see <https://github.com/bcoe/nyc>\n '.sass-cache', // Cache folder for node-sass, see <https://github.com/sass/node-sass>\n '.yarn', // Where node modules are installed when using Yarn, see <https://yarnpkg.com/>\n 'bower_components', // Where Bower packages are installed, see <http://bower.io/>\n 'coverage', // Standard output directory for code coverage reports, see <https://github.com/gotwarlost/istanbul>\n 'node_modules', // Where Node modules are installed, see <https://nodejs.org/>\n // Taken from globby:\n // https://github.com/sindresorhus/globby/blob/v14.0.2/ignore.js#L11-L16\n 'flow-typed'\n] as const\n\nconst ignoredDirPatterns = ignoredDirs.map(i => `**/${i}`)\n\nexport function directoryPatterns() {\n return [...ignoredDirPatterns]\n}\n","import { existsSync, promises as fs, realpathSync, statSync } from 'node:fs'\nimport path from 'node:path'\nimport process from 'node:process'\n\nimport ignore from 'ignore'\nimport micromatch from 'micromatch'\nimport { glob as tinyGlob } from 'tinyglobby'\nimport which from 'which'\n\nimport { debugLog } from './debug'\nimport { directoryPatterns } from './ignore-by-default'\nimport constants from '../constants'\n\nimport type { SocketYml } from '@socketsecurity/config'\nimport type { SocketSdkReturnType } from '@socketsecurity/sdk'\nimport type { GlobOptions } from 'tinyglobby'\n\ntype GlobWithGitIgnoreOptions = GlobOptions & {\n socketConfig?: SocketYml | undefined\n}\n\nconst { NODE_MODULES, NPM, shadowBinPath } = constants\n\nasync function filterGlobResultToSupportedFiles(\n entries: string[],\n supportedFiles: SocketSdkReturnType<'getReportSupportedFiles'>['data']\n): Promise<string[]> {\n const patterns = ['golang', NPM, 'maven', 'pypi'].reduce(\n (r: string[], n: string) => {\n const supported = supportedFiles[n]\n r.push(\n ...(supported\n ? Object.values(supported).map(p => `**/${p.pattern}`)\n : [])\n )\n return r\n },\n []\n )\n return entries.filter(p => micromatch.some(p, patterns))\n}\n\nasync function globWithGitIgnore(\n patterns: string[],\n options: GlobWithGitIgnoreOptions\n) {\n const {\n cwd = process.cwd(),\n socketConfig,\n ...additionalOptions\n } = <GlobWithGitIgnoreOptions>{ __proto__: null, ...options }\n const projectIgnorePaths = socketConfig?.projectIgnorePaths\n const ignoreFiles = await tinyGlob(['**/.gitignore'], {\n absolute: true,\n cwd,\n expandDirectories: true\n })\n const ignores = [\n ...directoryPatterns(),\n ...(Array.isArray(projectIgnorePaths)\n ? ignoreFileLinesToGlobPatterns(\n projectIgnorePaths,\n path.join(cwd, '.gitignore'),\n cwd\n )\n : []),\n ...(\n await Promise.all(\n ignoreFiles.map(async filepath =>\n ignoreFileToGlobPatterns(\n await fs.readFile(filepath, 'utf8'),\n filepath,\n cwd\n )\n )\n )\n ).flat()\n ]\n const hasNegatedPattern = ignores.some(p => p.charCodeAt(0) === 33 /*'!'*/)\n const globOptions = {\n absolute: true,\n cwd,\n expandDirectories: false,\n ignore: hasNegatedPattern ? [] : ignores,\n ...additionalOptions\n }\n const result = await tinyGlob(patterns, globOptions)\n if (!hasNegatedPattern) {\n return result\n }\n const { absolute } = globOptions\n\n // Note: the input files must be INSIDE the cwd. If you get strange looking\n // relative path errors here, most likely your path is outside the given cwd.\n const filtered = ignore()\n .add(ignores)\n .filter(absolute ? result.map(p => path.relative(cwd, p)) : result)\n return absolute ? filtered.map(p => path.resolve(cwd, p)) : filtered\n}\n\nfunction ignoreFileLinesToGlobPatterns(\n lines: string[],\n filepath: string,\n cwd: string\n): string[] {\n const base = path.relative(cwd, path.dirname(filepath)).replace(/\\\\/g, '/')\n const patterns = []\n for (let i = 0, { length } = lines; i < length; i += 1) {\n const pattern = lines[i]!.trim()\n if (pattern.length > 0 && pattern.charCodeAt(0) !== 35 /*'#'*/) {\n patterns.push(\n ignorePatternToMinimatch(\n pattern.length && pattern.charCodeAt(0) === 33 /*'!'*/\n ? `!${path.posix.join(base, pattern.slice(1))}`\n : path.posix.join(base, pattern)\n )\n )\n }\n }\n return patterns\n}\n\nfunction ignoreFileToGlobPatterns(\n content: string,\n filepath: string,\n cwd: string\n): string[] {\n return ignoreFileLinesToGlobPatterns(content.split(/\\r?\\n/), filepath, cwd)\n}\n\n// Based on `@eslint/compat` convertIgnorePatternToMinimatch.\n// Apache v2.0 licensed\n// Copyright Nicholas C. Zakas\n// https://github.com/eslint/rewrite/blob/compat-v1.2.1/packages/compat/src/ignore-file.js#L28\nfunction ignorePatternToMinimatch(pattern: string): string {\n const isNegated = pattern.startsWith('!')\n const negatedPrefix = isNegated ? '!' : ''\n const patternToTest = (isNegated ? pattern.slice(1) : pattern).trimEnd()\n // Special cases.\n if (\n patternToTest === '' ||\n patternToTest === '**' ||\n patternToTest === '/**' ||\n patternToTest === '**'\n ) {\n return `${negatedPrefix}${patternToTest}`\n }\n const firstIndexOfSlash = patternToTest.indexOf('/')\n const matchEverywherePrefix =\n firstIndexOfSlash === -1 || firstIndexOfSlash === patternToTest.length - 1\n ? '**/'\n : ''\n const patternWithoutLeadingSlash =\n firstIndexOfSlash === 0 ? patternToTest.slice(1) : patternToTest\n // Escape `{` and `(` because in gitignore patterns they are just\n // literal characters without any specific syntactic meaning,\n // while in minimatch patterns they can form brace expansion or extglob syntax.\n //\n // For example, gitignore pattern `src/{a,b}.js` ignores file `src/{a,b}.js`.\n // But, the same minimatch pattern `src/{a,b}.js` ignores files `src/a.js` and `src/b.js`.\n // Minimatch pattern `src/\\{a,b}.js` is equivalent to gitignore pattern `src/{a,b}.js`.\n const escapedPatternWithoutLeadingSlash =\n patternWithoutLeadingSlash.replaceAll(\n /(?=((?:\\\\.|[^{(])*))\\1([{(])/guy,\n '$1\\\\$2'\n )\n const matchInsideSuffix = patternToTest.endsWith('/**') ? '/*' : ''\n return `${negatedPrefix}${matchEverywherePrefix}${escapedPatternWithoutLeadingSlash}${matchInsideSuffix}`\n}\n\nfunction pathsToPatterns(paths: string[]): string[] {\n // TODO: Does not support `~/` paths.\n return paths.map(p => (p === '.' ? '**/*' : p))\n}\n\nexport function findBinPathDetailsSync(binName: string): {\n name: string\n path: string | undefined\n shadowed: boolean\n} {\n let shadowIndex = -1\n const bins =\n which.sync(binName, {\n all: true,\n nothrow: true\n }) ?? []\n let binPath: string | undefined\n for (let i = 0, { length } = bins; i < length; i += 1) {\n const bin = realpathSync.native(bins[i]!)\n // Skip our bin directory if it's in the front.\n if (path.dirname(bin) === shadowBinPath) {\n shadowIndex = i\n } else {\n binPath = bin\n break\n }\n }\n return { name: binName, path: binPath, shadowed: shadowIndex !== -1 }\n}\n\nexport function findNpmPathSync(npmBinPath: string): string | undefined {\n let thePath = npmBinPath\n while (true) {\n const nmPath = path.join(thePath, NODE_MODULES)\n if (\n // npm bin paths may look like:\n // /usr/local/share/npm/bin/npm\n // /Users/SomeUsername/.nvm/versions/node/vX.X.X/bin/npm\n // C:\\Users\\SomeUsername\\AppData\\Roaming\\npm\\bin\\npm.cmd\n // OR\n // C:\\Program Files\\nodejs\\npm.cmd\n //\n // In all cases the npm path contains a node_modules folder:\n // /usr/local/share/npm/bin/npm/node_modules\n // C:\\Program Files\\nodejs\\node_modules\n //\n // Use existsSync here because statsSync, even with { throwIfNoEntry: false },\n // will throw an ENOTDIR error for paths like ./a-file-that-exists/a-directory-that-does-not.\n // See https://github.com/nodejs/node/issues/56993.\n existsSync(nmPath) &&\n statSync(nmPath, { throwIfNoEntry: false })?.isDirectory() &&\n // Optimistically look for the default location.\n (path.basename(thePath) === NPM ||\n // Chocolatey installs npm bins in the same directory as node bins.\n // Lazily access constants.WIN32.\n (constants.WIN32 && existsSync(path.join(thePath, `${NPM}.cmd`))))\n ) {\n return thePath\n }\n const parent = path.dirname(thePath)\n if (parent === thePath) {\n return undefined\n }\n thePath = parent\n }\n}\n\nexport async function getPackageFiles(\n cwd: string,\n inputPaths: string[],\n config: SocketYml | undefined,\n supportedFiles: SocketSdkReturnType<'getReportSupportedFiles'>['data']\n): Promise<string[]> {\n debugLog(`Globbed resolving ${inputPaths.length} paths:`, inputPaths)\n\n const entries = await globWithGitIgnore(pathsToPatterns(inputPaths), {\n cwd,\n socketConfig: config\n })\n\n debugLog(\n `Globbed resolved ${inputPaths.length} paths to ${entries.length} paths:`,\n entries\n )\n\n const packageFiles = await filterGlobResultToSupportedFiles(\n entries,\n supportedFiles\n )\n\n debugLog(\n `Mapped ${entries.length} entries to ${packageFiles.length} files:`,\n packageFiles\n )\n\n return packageFiles\n}\n\nexport async function getPackageFilesFullScans(\n cwd: string,\n inputPaths: string[],\n supportedFiles: SocketSdkReturnType<'getReportSupportedFiles'>['data'],\n debugLog: typeof console.error = () => {}\n): Promise<string[]> {\n debugLog(`Globbed resolving ${inputPaths.length} paths:`, inputPaths)\n\n const entries = await globWithGitIgnore(pathsToPatterns(inputPaths), {\n cwd\n })\n\n debugLog(\n `Globbed resolved ${inputPaths.length} paths to ${entries.length} paths:`,\n entries\n )\n\n const packageFiles = await filterGlobResultToSupportedFiles(\n entries,\n supportedFiles\n )\n\n debugLog(\n `Mapped ${entries.length} entries to ${packageFiles.length} files:`,\n packageFiles\n )\n\n return packageFiles\n}\n","import { existsSync } from 'node:fs'\nimport Module from 'node:module'\nimport path from 'node:path'\nimport process from 'node:process'\n\nimport { normalizePath } from '@socketsecurity/registry/lib/path'\n\nimport constants from '../constants'\nimport { findBinPathDetailsSync, findNpmPathSync } from '../utils/path-resolve'\n\nconst { NODE_MODULES, NPM, NPX, SOCKET_CLI_ISSUES_URL } = constants\n\nfunction exitWithBinPathError(binName: string): never {\n console.error(\n `Socket unable to locate ${binName}; ensure it is available in the PATH environment variable.`\n )\n // The exit code 127 indicates that the command or binary being executed\n // could not be found.\n process.exit(127)\n}\n\nlet _npmBinPathDetails: ReturnType<typeof findBinPathDetailsSync> | undefined\nfunction getNpmBinPathDetails(): ReturnType<typeof findBinPathDetailsSync> {\n if (_npmBinPathDetails === undefined) {\n _npmBinPathDetails = findBinPathDetailsSync(NPM)\n }\n return _npmBinPathDetails\n}\n\nlet _npxBinPathDetails: ReturnType<typeof findBinPathDetailsSync> | undefined\nfunction getNpxBinPathDetails(): ReturnType<typeof findBinPathDetailsSync> {\n if (_npxBinPathDetails === undefined) {\n _npxBinPathDetails = findBinPathDetailsSync(NPX)\n }\n return _npxBinPathDetails\n}\n\nlet _npmBinPath: string | undefined\nexport function getNpmBinPath(): string {\n if (_npmBinPath === undefined) {\n _npmBinPath = getNpmBinPathDetails().path\n if (!_npmBinPath) {\n exitWithBinPathError(NPM)\n }\n }\n return _npmBinPath\n}\n\nexport function isNpmBinPathShadowed() {\n return getNpmBinPathDetails().shadowed\n}\n\nlet _npxBinPath: string | undefined\nexport function getNpxBinPath(): string {\n if (_npxBinPath === undefined) {\n _npxBinPath = getNpxBinPathDetails().path\n if (!_npxBinPath) {\n exitWithBinPathError(NPX)\n }\n }\n return _npxBinPath\n}\n\nexport function isNpxBinPathShadowed() {\n return getNpxBinPathDetails().shadowed\n}\n\nlet _npmPath: string | undefined\nexport function getNpmPath() {\n if (_npmPath === undefined) {\n const npmBinPath = getNpmBinPath()\n _npmPath = npmBinPath ? findNpmPathSync(npmBinPath) : undefined\n if (!_npmPath) {\n let message = 'Unable to find npm CLI install directory.'\n if (npmBinPath) {\n message += `\\nSearched parent directories of ${path.dirname(npmBinPath)}.`\n }\n message += `\\n\\nThis is may be a bug with socket-npm related to changes to the npm CLI.\\nPlease report to ${SOCKET_CLI_ISSUES_URL}.`\n console.error(message)\n // The exit code 127 indicates that the command or binary being executed\n // could not be found.\n process.exit(127)\n }\n }\n return _npmPath\n}\n\nlet _npmRequire: NodeJS.Require | undefined\nexport function getNpmRequire(): NodeJS.Require {\n if (_npmRequire === undefined) {\n const npmPath = getNpmPath()\n const npmNmPath = path.join(npmPath, NODE_MODULES, NPM)\n _npmRequire = Module.createRequire(\n path.join(existsSync(npmNmPath) ? npmNmPath : npmPath, '<dummy-basename>')\n )\n }\n return _npmRequire\n}\n\nlet _arboristPkgPath: string | undefined\nexport function getArboristPackagePath() {\n if (_arboristPkgPath === undefined) {\n const pkgName = '@npmcli/arborist'\n const mainPathWithForwardSlashes = normalizePath(\n getNpmRequire().resolve(pkgName)\n )\n const arboristPkgPathWithForwardSlashes = mainPathWithForwardSlashes.slice(\n 0,\n mainPathWithForwardSlashes.lastIndexOf(pkgName) + pkgName.length\n )\n // Lazily access constants.WIN32.\n _arboristPkgPath = constants.WIN32\n ? path.normalize(arboristPkgPathWithForwardSlashes)\n : arboristPkgPathWithForwardSlashes\n }\n return _arboristPkgPath\n}\n\nlet _arboristClassPath: string | undefined\nexport function getArboristClassPath() {\n if (_arboristClassPath === undefined) {\n _arboristClassPath = path.join(\n getArboristPackagePath(),\n 'lib/arborist/index.js'\n )\n }\n return _arboristClassPath\n}\n\nlet _arboristDepValidPath: string | undefined\nexport function getArboristDepValidPath() {\n if (_arboristDepValidPath === undefined) {\n _arboristDepValidPath = path.join(\n getArboristPackagePath(),\n 'lib/dep-valid.js'\n )\n }\n return _arboristDepValidPath\n}\n\nlet _arboristEdgeClassPath: string | undefined\nexport function getArboristEdgeClassPath() {\n if (_arboristEdgeClassPath === undefined) {\n _arboristEdgeClassPath = path.join(getArboristPackagePath(), 'lib/edge.js')\n }\n return _arboristEdgeClassPath\n}\n\nlet _arboristNodeClassPath: string | undefined\nexport function getArboristNodeClassPath() {\n if (_arboristNodeClassPath === undefined) {\n _arboristNodeClassPath = path.join(getArboristPackagePath(), 'lib/node.js')\n }\n return _arboristNodeClassPath\n}\n\nlet _arboristOverrideSetClassPath: string | undefined\nexport function getArboristOverrideSetClassPath() {\n if (_arboristOverrideSetClassPath === undefined) {\n _arboristOverrideSetClassPath = path.join(\n getArboristPackagePath(),\n 'lib/override-set.js'\n )\n }\n return _arboristOverrideSetClassPath\n}\n"],"names":["_logSymbols","__proto__","info","success","warning","error","constructor","shadowBinPath","cwd","absolute","expandDirectories","ignore","length","all","nothrow","shadowIndex","binPath","name","path","existsSync","throwIfNoEntry","constants","thePath","socketConfig","debugLog","SOCKET_CLI_ISSUES_URL","console","process","_npmBinPathDetails","_npxBinPathDetails","_npmBinPath","_npxBinPath","_arboristPkgPath"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAYA;AACO;;AAEHA;AAEMC;AACAC;AACAC;AACAC;AACAC;AACF;AAEEJ;AACAC;AACAC;AACAC;AACAC;;AAER;AACA;AACF;AAEO;AACL;AACAC;AACE;AACF;;AAGE;AACF;;AAGE;AACF;;AAGE;AACF;AACF;;;AChDO;AACL;AACA;AACF;AAEO;;;AAGL;AACF;;ACZA;AACE;AACA;AACA;AAAQ;AACR;AAAQ;AACR;AAAe;AACf;AAAe;AACf;AAAS;AACT;AAAoB;AACpB;AAAY;AACZ;AAAgB;AAChB;AACA;AACA;AAGF;AAEO;;AAEP;;ACCA;;;AAA2BC;AAAc;AAEzC;AAIE;AAEI;;AAMA;;AAIJ;AACF;AAEA;;AAKIC;;;AAGF;AAAgCP;;;AAChC;;AAEEQ;;AAEAC;AACF;AACA;AAqBA;AACA;AACED;;AAEAC;AACAC;;;;;AAKA;AACF;;AACQF;AAAS;;AAEjB;AACA;AACA;AAGA;AACF;AAEA;;;AAOE;AAAkBG;;;AAEhB;;AAQA;AACF;AACA;AACF;AAEA;AAKE;AACF;;AAEA;AACA;AACA;AACA;AACA;AACE;AACA;AACA;AACA;AACA;AAME;AACF;AACA;AACA;AAIA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;;;AAQF;AAEA;AACE;AACA;AACF;AAEO;;AAML;AAEIC;AACAC;;AAEJ;AACA;AAAkBF;;;AAEhB;;AAEEG;AACF;AACEC;AACA;AACF;AACF;;AACSC;AAAeC;;;AAC1B;AAEO;;AAEL;;AAEE;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACAC;AACmBC;AAAsB;AACzC;AACCF;AACC;AACA;AACCG;AAEH;AACF;AACA;;AAEE;AACF;AACAC;AACF;AACF;AAEO;;;;AAUHC;AACF;AAEAC;;AAUAA;AAKA;AACF;AAEO;;;AASHhB;AACF;AAEAgB;;AAUAA;AAKA;AACF;;AC9RA;;;;AAAgCC;AAAsB;AAEtD;AACEC;AAGA;AACA;AACAC;AACF;AAEA;AACA;;AAEIC;AACF;AACA;AACF;AAEA;AACA;;AAEIC;AACF;AACA;AACF;AAEA;AACO;;AAEHC;;;AAGA;AACF;AACA;AACF;AAEO;AACL;AACF;AAEA;AACO;;AAEHC;;;AAGA;AACF;AACA;AACF;AAEO;AACL;AACF;AAEA;AACO;;AAEH;;;;AAIE;;AAEA;;AAEAL;AACA;AACA;AACAC;AACF;AACF;AACA;AACF;AAEA;AACO;;AAEH;;;AAKF;AACA;AACF;AAEA;AACO;;;AAGH;AAGA;AAIA;AACAK;AAGF;AACA;AACF;AAEA;AACO;;;AAML;AACA;AACF;AAEA;AACO;;;AAML;AACA;AACF;AAEA;AACO;;;AAGL;AACA;AACF;AAEA;AACO;;;AAGL;AACA;AACF;AAEA;AACO;;;AAML;AACA;AACF;;;;;;;;;;;;;;;;;","debugId":"ff4e9bce-e186-418c-a87c-6ea63ce4776e"}
@@ -0,0 +1,24 @@
1
+ /// <reference types="npmcli__promise-spawn" />
2
+ /// <reference types="node" />
3
+ import spawn from '@npmcli/promise-spawn';
4
+ declare function isAuditFlag(cmdArg: string): boolean;
5
+ declare function isFundFlag(cmdArg: string): boolean;
6
+ declare function isLoglevelFlag(cmdArg: string): boolean;
7
+ declare function isProgressFlag(cmdArg: string): boolean;
8
+ type SpawnOption = Exclude<Parameters<typeof spawn>[2], undefined>;
9
+ type SafeNpmInstallOptions = SpawnOption & {
10
+ args?: string[];
11
+ ipc?: object;
12
+ };
13
+ declare function safeNpmInstall(opts?: SafeNpmInstallOptions): Promise<{
14
+ cmd: string;
15
+ args: string[];
16
+ code: number;
17
+ signal: NodeJS.Signals | null;
18
+ stdout: string;
19
+ stderr: string;
20
+ } & Record<any, any>> & {
21
+ process: import("child_process").ChildProcess;
22
+ stdio: [import("stream").Writable | null, import("stream").Readable | null, import("stream").Readable | null, import("stream").Writable | import("stream").Readable | null | undefined, import("stream").Writable | import("stream").Readable | null | undefined];
23
+ };
24
+ export { isAuditFlag, isFundFlag, isLoglevelFlag, isProgressFlag, safeNpmInstall };
@@ -0,0 +1,99 @@
1
+ 'use strict';
2
+
3
+ function _socketInterop(e) {
4
+ let c = 0
5
+ for (const k in e ?? {}) {
6
+ c = c === 0 && k === 'default' ? 1 : 0
7
+ if (!c && k !== '__esModule') break
8
+ }
9
+ return c ? e.default : e
10
+ }
11
+
12
+ var process = require('node:process');
13
+ var spawn = _socketInterop(require('@npmcli/promise-spawn'));
14
+ var objects = require('@socketsecurity/registry/lib/objects');
15
+ var npmPaths = require('./npm-paths.js');
16
+ var constants = require('./constants2.js');
17
+
18
+ const {
19
+ SOCKET_IPC_HANDSHAKE,
20
+ abortSignal
21
+ } = constants.constants;
22
+ const auditFlags = new Set(['--audit', '--no-audit']);
23
+ const fundFlags = new Set(['--fund', '--no-fund']);
24
+
25
+ // https://docs.npmjs.com/cli/v11/using-npm/logging#aliases
26
+ const logFlags = new Set(['--loglevel', '-d', '--dd', '--ddd', '-q', '--quiet', '-s', '--silent']);
27
+ const progressFlags = new Set(['--progress', '--no-progress']);
28
+ function isAuditFlag(cmdArg) {
29
+ return auditFlags.has(cmdArg);
30
+ }
31
+ function isFundFlag(cmdArg) {
32
+ return fundFlags.has(cmdArg);
33
+ }
34
+ function isLoglevelFlag(cmdArg) {
35
+ // https://docs.npmjs.com/cli/v11/using-npm/logging#setting-log-levels
36
+ return cmdArg.startsWith('--loglevel=') || logFlags.has(cmdArg);
37
+ }
38
+ function isProgressFlag(cmdArg) {
39
+ return progressFlags.has(cmdArg);
40
+ }
41
+ function safeNpmInstall(opts) {
42
+ const {
43
+ args = [],
44
+ ipc,
45
+ ...spawnOptions
46
+ } = {
47
+ __proto__: null,
48
+ ...opts
49
+ };
50
+ const terminatorPos = args.indexOf('--');
51
+ const npmArgs = (terminatorPos === -1 ? args : args.slice(0, terminatorPos)).filter(a => !isAuditFlag(a) && !isFundFlag(a) && !isProgressFlag(a));
52
+ const otherArgs = terminatorPos === -1 ? [] : args.slice(terminatorPos);
53
+ const useIpc = objects.isObject(ipc);
54
+ const useDebug = npmPaths.isDebug();
55
+ const spawnPromise = spawn(
56
+ // Lazily access constants.execPath.
57
+ constants.constants.execPath, [
58
+ // Lazily access constants.nodeNoWarningsFlags.
59
+ ...constants.constants.nodeNoWarningsFlags, '--require',
60
+ // Lazily access constants.npmInjectionPath.
61
+ constants.constants.npmInjectionPath, npmPaths.getNpmBinPath(), 'install',
62
+ // Even though the '--silent' flag is passed npm will still run through
63
+ // code paths for 'audit' and 'fund' unless '--no-audit' and '--no-fund'
64
+ // flags are passed.
65
+ '--no-audit', '--no-fund',
66
+ // Add `--no-progress` and `--silent` flags to fix input being swallowed
67
+ // by the spinner when running the command with recent versions of npm.
68
+ '--no-progress',
69
+ // Add the '--silent' flag if a loglevel flag is not provided and the
70
+ // SOCKET_CLI_DEBUG environment variable is not truthy.
71
+ ...(useDebug || npmArgs.some(isLoglevelFlag) ? [] : ['--silent']), ...npmArgs, ...otherArgs], {
72
+ signal: abortSignal,
73
+ // Set stdio to include 'ipc'.
74
+ // See https://github.com/nodejs/node/blob/v23.6.0/lib/child_process.js#L161-L166
75
+ // and https://github.com/nodejs/node/blob/v23.6.0/lib/internal/child_process.js#L238.
76
+ stdio: useDebug ?
77
+ // 'inherit'
78
+ useIpc ? [0, 1, 2, 'ipc'] : 'inherit' :
79
+ // 'ignore'
80
+ useIpc ? ['ignore', 'ignore', 'ignore', 'ipc'] : 'ignore',
81
+ ...spawnOptions,
82
+ env: {
83
+ ...process.env,
84
+ ...spawnOptions.env
85
+ }
86
+ });
87
+ if (useIpc) {
88
+ spawnPromise.process.send({
89
+ [SOCKET_IPC_HANDSHAKE]: ipc
90
+ });
91
+ }
92
+ return spawnPromise;
93
+ }
94
+
95
+ exports.isLoglevelFlag = isLoglevelFlag;
96
+ exports.isProgressFlag = isProgressFlag;
97
+ exports.safeNpmInstall = safeNpmInstall;
98
+ //# debugId=fcfc8894-7d11-47dd-a73e-8b7ff358443
99
+ //# sourceMappingURL=npm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"npm.js","sources":["../../src/utils/npm.ts"],"sourcesContent":["import process from 'node:process'\n\nimport spawn from '@npmcli/promise-spawn'\n\nimport { isObject } from '@socketsecurity/registry/lib/objects'\n\nimport { isDebug } from './debug'\nimport constants from '../constants'\nimport { getNpmBinPath } from '../shadow/npm-paths'\n\nconst { SOCKET_IPC_HANDSHAKE, abortSignal } = constants\n\nconst auditFlags = new Set(['--audit', '--no-audit'])\n\nconst fundFlags = new Set(['--fund', '--no-fund'])\n\n// https://docs.npmjs.com/cli/v11/using-npm/logging#aliases\nconst logFlags = new Set([\n '--loglevel',\n '-d',\n '--dd',\n '--ddd',\n '-q',\n '--quiet',\n '-s',\n '--silent'\n])\n\nconst progressFlags = new Set(['--progress', '--no-progress'])\n\nexport function isAuditFlag(cmdArg: string) {\n return auditFlags.has(cmdArg)\n}\n\nexport function isFundFlag(cmdArg: string) {\n return fundFlags.has(cmdArg)\n}\n\nexport function isLoglevelFlag(cmdArg: string) {\n // https://docs.npmjs.com/cli/v11/using-npm/logging#setting-log-levels\n return cmdArg.startsWith('--loglevel=') || logFlags.has(cmdArg)\n}\n\nexport function isProgressFlag(cmdArg: string) {\n return progressFlags.has(cmdArg)\n}\n\ntype SpawnOption = Exclude<Parameters<typeof spawn>[2], undefined>\n\ntype SafeNpmInstallOptions = SpawnOption & {\n args?: string[]\n ipc?: object\n}\n\nexport function safeNpmInstall(opts?: SafeNpmInstallOptions) {\n const { args = [], ipc, ...spawnOptions } = { __proto__: null, ...opts }\n const terminatorPos = args.indexOf('--')\n const npmArgs = (\n terminatorPos === -1 ? args : args.slice(0, terminatorPos)\n ).filter(a => !isAuditFlag(a) && !isFundFlag(a) && !isProgressFlag(a))\n const otherArgs = terminatorPos === -1 ? [] : args.slice(terminatorPos)\n const useIpc = isObject(ipc)\n const useDebug = isDebug()\n const spawnPromise = spawn(\n // Lazily access constants.execPath.\n constants.execPath,\n [\n // Lazily access constants.nodeNoWarningsFlags.\n ...constants.nodeNoWarningsFlags,\n '--require',\n // Lazily access constants.npmInjectionPath.\n constants.npmInjectionPath,\n getNpmBinPath(),\n 'install',\n // Even though the '--silent' flag is passed npm will still run through\n // code paths for 'audit' and 'fund' unless '--no-audit' and '--no-fund'\n // flags are passed.\n '--no-audit',\n '--no-fund',\n // Add `--no-progress` and `--silent` flags to fix input being swallowed\n // by the spinner when running the command with recent versions of npm.\n '--no-progress',\n // Add the '--silent' flag if a loglevel flag is not provided and the\n // SOCKET_CLI_DEBUG environment variable is not truthy.\n ...(useDebug || npmArgs.some(isLoglevelFlag) ? [] : ['--silent']),\n ...npmArgs,\n ...otherArgs\n ],\n {\n signal: abortSignal,\n // Set stdio to include 'ipc'.\n // See https://github.com/nodejs/node/blob/v23.6.0/lib/child_process.js#L161-L166\n // and https://github.com/nodejs/node/blob/v23.6.0/lib/internal/child_process.js#L238.\n stdio: useDebug\n ? // 'inherit'\n useIpc\n ? [0, 1, 2, 'ipc']\n : 'inherit'\n : // 'ignore'\n useIpc\n ? ['ignore', 'ignore', 'ignore', 'ipc']\n : 'ignore',\n ...spawnOptions,\n env: {\n ...process.env,\n ...spawnOptions.env\n }\n }\n )\n if (useIpc) {\n spawnPromise.process.send({ [SOCKET_IPC_HANDSHAKE]: ipc })\n }\n return spawnPromise\n}\n"],"names":["abortSignal","args","__proto__","constants","signal","stdio","env","spawnPromise"],"mappings":";;;;;;;;;;;;;;;;;AAUA;;AAA8BA;AAAY;AAE1C;AAEA;;AAEA;AACA;AAWA;AAEO;AACL;AACF;AAEO;AACL;AACF;AAEO;AACL;AACA;AACF;AAEO;AACL;AACF;AASO;;AACGC;;;AAAgC;AAAMC;;;AAC9C;AACA;AAGA;AACA;AACA;;AAEE;;AAGE;AACA;AAEA;AACAC;AAGA;AACA;AACA;AACA;AAEA;AACA;;AAEA;AACA;;AAMAC;AACA;AACA;AACA;AACAC;AACI;;AAIA;;AAIJ;AACAC;;AAEE;AACF;AACF;AAEF;AACEC;AAA4B;AAA4B;AAC1D;AACA;AACF;;;;","debugId":"fcfc8894-7d11-47dd-a73e-8b7ff358443"}
@@ -0,0 +1,12 @@
1
+ /// <reference types="node" />
2
+ import { SocketYml } from '@socketsecurity/config';
3
+ import { SocketSdkReturnType } from '@socketsecurity/sdk';
4
+ declare function findBinPathDetailsSync(binName: string): {
5
+ name: string;
6
+ path: string | undefined;
7
+ shadowed: boolean;
8
+ };
9
+ declare function findNpmPathSync(npmBinPath: string): string | undefined;
10
+ declare function getPackageFiles(cwd: string, inputPaths: string[], config: SocketYml | undefined, supportedFiles: SocketSdkReturnType<'getReportSupportedFiles'>['data']): Promise<string[]>;
11
+ declare function getPackageFilesFullScans(cwd: string, inputPaths: string[], supportedFiles: SocketSdkReturnType<'getReportSupportedFiles'>['data'], debugLog?: typeof console.error): Promise<string[]>;
12
+ export { findBinPathDetailsSync, findNpmPathSync, getPackageFiles, getPackageFilesFullScans };
@@ -0,0 +1,3 @@
1
+ type Logger = typeof import("npmlog") | typeof import("proc-log") | undefined;
2
+ declare function getLogger(): Logger;
3
+ export { Logger, getLogger };