@socketsecurity/cli 0.14.39 → 0.14.41

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.
@@ -1,201 +1,3 @@
1
- 'use strict';
1
+ 'use strict'
2
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 path = require('node:path');
14
- var ignore = _socketInterop(require('ignore'));
15
- var micromatch = _socketInterop(require('micromatch'));
16
- var tinyglobby = _socketInterop(require('tinyglobby'));
17
- var which = _socketInterop(require('which'));
18
- var constants = require('./constants.js');
19
-
20
- const ignoredDirs = [
21
- // Taken from ignore-by-default:
22
- // https://github.com/novemberborn/ignore-by-default/blob/v2.1.0/index.js
23
- '.git',
24
- // Git repository files, see <https://git-scm.com/>
25
- '.log',
26
- // Log files emitted by tools such as `tsserver`, see <https://github.com/Microsoft/TypeScript/wiki/Standalone-Server-%28tsserver%29>
27
- '.nyc_output',
28
- // Temporary directory where nyc stores coverage data, see <https://github.com/bcoe/nyc>
29
- '.sass-cache',
30
- // Cache folder for node-sass, see <https://github.com/sass/node-sass>
31
- '.yarn',
32
- // Where node modules are installed when using Yarn, see <https://yarnpkg.com/>
33
- 'bower_components',
34
- // Where Bower packages are installed, see <http://bower.io/>
35
- 'coverage',
36
- // Standard output directory for code coverage reports, see <https://github.com/gotwarlost/istanbul>
37
- 'node_modules',
38
- // Where Node modules are installed, see <https://nodejs.org/>
39
- // Taken from globby:
40
- // https://github.com/sindresorhus/globby/blob/v14.0.2/ignore.js#L11-L16
41
- 'flow-typed'];
42
- const ignoredDirPatterns = ignoredDirs.map(i => `**/${i}`);
43
- function directoryPatterns() {
44
- return [...ignoredDirPatterns];
45
- }
46
-
47
- const {
48
- NPM,
49
- shadowBinPath
50
- } = constants;
51
- async function filterGlobResultToSupportedFiles(entries, supportedFiles) {
52
- const patterns = ['golang', NPM, 'pypi'].reduce((r, n) => {
53
- const supported = supportedFiles[n];
54
- r.push(...(supported ? Object.values(supported).map(p => `**/${p.pattern}`) : []));
55
- return r;
56
- }, []);
57
- return entries.filter(p => micromatch.some(p, patterns));
58
- }
59
- async function globWithGitIgnore(patterns, options) {
60
- const {
61
- cwd = process.cwd(),
62
- socketConfig,
63
- ...additionalOptions
64
- } = {
65
- __proto__: null,
66
- ...options
67
- };
68
- const projectIgnorePaths = socketConfig?.projectIgnorePaths;
69
- const ignoreFiles = await tinyglobby.glob(['**/.gitignore'], {
70
- absolute: true,
71
- cwd,
72
- expandDirectories: true
73
- });
74
- 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()];
75
- const hasNegatedPattern = ignores.some(p => p.charCodeAt(0) === 33 /*'!'*/);
76
- const globOptions = {
77
- absolute: true,
78
- cwd,
79
- expandDirectories: false,
80
- ignore: hasNegatedPattern ? [] : ignores,
81
- ...additionalOptions
82
- };
83
- const result = await tinyglobby.glob(patterns, globOptions);
84
- if (!hasNegatedPattern) {
85
- return result;
86
- }
87
- const {
88
- absolute
89
- } = globOptions;
90
- const filtered = ignore().add(ignores).filter(absolute ? result.map(p => path.relative(cwd, p)) : result);
91
- return absolute ? filtered.map(p => path.resolve(cwd, p)) : filtered;
92
- }
93
- function ignoreFileLinesToGlobPatterns(lines, filepath, cwd) {
94
- const base = path.relative(cwd, path.dirname(filepath)).replace(/\\/g, '/');
95
- const patterns = [];
96
- for (let i = 0, {
97
- length
98
- } = lines; i < length; i += 1) {
99
- const pattern = lines[i].trim();
100
- if (pattern.length > 0 && pattern.charCodeAt(0) !== 35 /*'#'*/) {
101
- patterns.push(ignorePatternToMinimatch(pattern.length && pattern.charCodeAt(0) === 33 /*'!'*/ ? `!${path.posix.join(base, pattern.slice(1))}` : path.posix.join(base, pattern)));
102
- }
103
- }
104
- return patterns;
105
- }
106
- function ignoreFileToGlobPatterns(content, filepath, cwd) {
107
- return ignoreFileLinesToGlobPatterns(content.split(/\r?\n/), filepath, cwd);
108
- }
109
-
110
- // Based on `@eslint/compat` convertIgnorePatternToMinimatch.
111
- // Apache v2.0 licensed
112
- // Copyright Nicholas C. Zakas
113
- // https://github.com/eslint/rewrite/blob/compat-v1.2.1/packages/compat/src/ignore-file.js#L28
114
- function ignorePatternToMinimatch(pattern) {
115
- const isNegated = pattern.startsWith('!');
116
- const negatedPrefix = isNegated ? '!' : '';
117
- const patternToTest = (isNegated ? pattern.slice(1) : pattern).trimEnd();
118
- // Special cases.
119
- if (patternToTest === '' || patternToTest === '**' || patternToTest === '/**' || patternToTest === '**') {
120
- return `${negatedPrefix}${patternToTest}`;
121
- }
122
- const firstIndexOfSlash = patternToTest.indexOf('/');
123
- const matchEverywherePrefix = firstIndexOfSlash === -1 || firstIndexOfSlash === patternToTest.length - 1 ? '**/' : '';
124
- const patternWithoutLeadingSlash = firstIndexOfSlash === 0 ? patternToTest.slice(1) : patternToTest;
125
- // Escape `{` and `(` because in gitignore patterns they are just
126
- // literal characters without any specific syntactic meaning,
127
- // while in minimatch patterns they can form brace expansion or extglob syntax.
128
- //
129
- // For example, gitignore pattern `src/{a,b}.js` ignores file `src/{a,b}.js`.
130
- // But, the same minimatch pattern `src/{a,b}.js` ignores files `src/a.js` and `src/b.js`.
131
- // Minimatch pattern `src/\{a,b}.js` is equivalent to gitignore pattern `src/{a,b}.js`.
132
- const escapedPatternWithoutLeadingSlash = patternWithoutLeadingSlash.replaceAll(/(?=((?:\\.|[^{(])*))\1([{(])/guy, '$1\\$2');
133
- const matchInsideSuffix = patternToTest.endsWith('/**') ? '/*' : '';
134
- return `${negatedPrefix}${matchEverywherePrefix}${escapedPatternWithoutLeadingSlash}${matchInsideSuffix}`;
135
- }
136
- function pathsToPatterns(paths) {
137
- return paths.map(p => p === '.' ? '**/*' : p);
138
- }
139
- function findRoot(filepath) {
140
- let curPath = filepath;
141
- while (true) {
142
- if (path.basename(curPath) === NPM) {
143
- return curPath;
144
- }
145
- const parent = path.dirname(curPath);
146
- if (parent === curPath) {
147
- return undefined;
148
- }
149
- curPath = parent;
150
- }
151
- }
152
- async function findBinPathDetails(binName) {
153
- let shadowIndex = -1;
154
- const bins = (await which(binName, {
155
- all: true,
156
- nothrow: true
157
- })) ?? [];
158
- const binPath = bins.find((binPath, i) => {
159
- // Skip our bin directory if it's in the front.
160
- if (fs.realpathSync(path.dirname(binPath)) === shadowBinPath) {
161
- shadowIndex = i;
162
- return false;
163
- }
164
- return true;
165
- });
166
- return {
167
- name: binName,
168
- path: binPath,
169
- shadowed: shadowIndex !== -1
170
- };
171
- }
172
- async function getPackageFiles(cwd, inputPaths, config, supportedFiles, debugLog = () => {}) {
173
- debugLog(`Globbed resolving ${inputPaths.length} paths:`, inputPaths);
174
-
175
- // TODO: Does not support `~/` paths
176
- const entries = await globWithGitIgnore(pathsToPatterns(inputPaths), {
177
- cwd,
178
- socketConfig: config
179
- });
180
- debugLog(`Globbed resolved ${inputPaths.length} paths to ${entries.length} paths:`, entries);
181
- const packageFiles = await filterGlobResultToSupportedFiles(entries, supportedFiles);
182
- debugLog(`Mapped ${entries.length} entries to ${packageFiles.length} files:`, packageFiles);
183
- return packageFiles;
184
- }
185
- async function getPackageFilesFullScans(cwd, inputPaths, supportedFiles, debugLog = () => {}) {
186
- debugLog(`Globbed resolving ${inputPaths.length} paths:`, inputPaths);
187
-
188
- // TODO: Does not support `~/` paths
189
- const entries = await globWithGitIgnore(pathsToPatterns(inputPaths), {
190
- cwd
191
- });
192
- debugLog(`Globbed resolved ${inputPaths.length} paths to ${entries.length} paths:`, entries);
193
- const packageFiles = await filterGlobResultToSupportedFiles(entries, supportedFiles);
194
- debugLog(`Mapped ${entries.length} entries to ${packageFiles.length} files:`, packageFiles);
195
- return packageFiles;
196
- }
197
-
198
- exports.findBinPathDetails = findBinPathDetails;
199
- exports.findRoot = findRoot;
200
- exports.getPackageFiles = getPackageFiles;
201
- exports.getPackageFilesFullScans = getPackageFilesFullScans;
3
+ module.exports = require('../module-sync/path-resolve.js')
@@ -1,103 +1,3 @@
1
- 'use strict';
1
+ 'use strict'
2
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 path = require('node:path');
14
- var spawn = _socketInterop(require('@npmcli/promise-spawn'));
15
- var constants = require('./constants.js');
16
- var cmdShim = _socketInterop(require('cmd-shim'));
17
- var pathResolve = require('./path-resolve.js');
18
-
19
- const {
20
- WIN32,
21
- rootDistPath
22
- } = constants;
23
- async function installLinks(realBinPath, binName) {
24
- // Find package manager being shadowed by this process.
25
- const {
26
- path: binPath,
27
- shadowed
28
- } = await pathResolve.findBinPathDetails(binName);
29
- if (!binPath) {
30
- // The exit code 127 indicates that the command or binary being executed
31
- // could not be found.
32
- console.error(`Socket unable to locate ${binName}; ensure it is available in the PATH environment variable.`);
33
- process.exit(127);
34
- }
35
- // TODO: Is this early exit needed?
36
- if (WIN32 && binPath) {
37
- return binPath;
38
- }
39
- // Move our bin directory to front of PATH so its found first.
40
- if (!shadowed) {
41
- if (WIN32) {
42
- await cmdShim(path.join(rootDistPath, `${binName}-cli.js`), path.join(realBinPath, binName));
43
- }
44
- process.env['PATH'] = `${realBinPath}${path.delimiter}${process.env['PATH']}`;
45
- }
46
- return binPath;
47
- }
48
-
49
- const {
50
- NPM,
51
- abortSignal,
52
- distPath,
53
- execPath,
54
- shadowBinPath
55
- } = constants;
56
- const injectionPath = path.join(distPath, 'npm-injection.js');
57
- async function shadow(binName, binArgs = process.argv.slice(2)) {
58
- const binPath = await installLinks(shadowBinPath, binName);
59
- if (abortSignal.aborted) {
60
- return;
61
- }
62
- // Adding the `--quiet` and `--no-progress` flags when the `proc-log` module
63
- // is found to fix a UX issue when running the command with recent versions of
64
- // npm (input swallowed by the standard npm spinner)
65
- if (binName === NPM && binArgs.includes('install') && !binArgs.includes('--no-progress') && !binArgs.includes('--quiet')) {
66
- const npmEntrypoint = fs.realpathSync(binPath);
67
- const npmRootPath = pathResolve.findRoot(path.dirname(npmEntrypoint));
68
- if (npmRootPath === undefined) {
69
- // The exit code 127 indicates that the command or binary being executed
70
- // could not be found.
71
- process.exit(127);
72
- }
73
- const npmDepPath = path.join(npmRootPath, 'node_modules');
74
- let procLog;
75
- try {
76
- procLog = require(path.join(npmDepPath, 'proc-log/lib/index.js')).log;
77
- } catch {}
78
- if (procLog) {
79
- binArgs.push('--no-progress', '--quiet');
80
- }
81
- }
82
- process.exitCode = 1;
83
- const spawnPromise = spawn(execPath, [
84
- // Lazily access constants.nodeNoWarningsFlags.
85
- ...constants.nodeNoWarningsFlags, '--require', injectionPath, binPath, ...binArgs], {
86
- signal: abortSignal,
87
- stdio: 'inherit'
88
- });
89
- // See https://nodejs.org/api/all.html#all_child_process_event-exit.
90
- spawnPromise.process.on('exit', (code, signalName) => {
91
- if (abortSignal.aborted) {
92
- return;
93
- }
94
- if (signalName) {
95
- process.kill(process.pid, signalName);
96
- } else if (code !== null) {
97
- process.exit(code);
98
- }
99
- });
100
- await spawnPromise;
101
- }
102
-
103
- module.exports = shadow;
3
+ module.exports = require('../module-sync/shadow-bin.js')
@@ -0,0 +1,3 @@
1
+ 'use strict'
2
+
3
+ module.exports = require('../module-sync/socket-url.js')