@socketsecurity/cli-with-sentry 1.0.79 → 1.0.81
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/cli.js +141 -147
- package/dist/cli.js.map +1 -1
- package/dist/constants.js +3 -3
- package/dist/constants.js.map +1 -1
- package/dist/shadow-npm-bin.js +3 -3
- package/dist/shadow-npm-bin.js.map +1 -1
- package/dist/shadow-npm-inject.js +4 -4
- package/dist/shadow-npm-inject.js.map +1 -1
- package/dist/tsconfig.dts.tsbuildinfo +1 -1
- package/dist/types/commands/ci/fetch-default-org-slug.d.mts.map +1 -1
- package/dist/types/commands/fix/cmd-fix.d.mts.map +1 -1
- package/dist/types/commands/fix/coana-fix.d.mts.map +1 -1
- package/dist/types/commands/fix/pull-request.d.mts.map +1 -1
- package/dist/types/commands/json/output-cmd-json.d.mts.map +1 -1
- package/dist/types/commands/optimize/add-overrides.d.mts.map +1 -1
- package/dist/types/utils/fs.d.mts +0 -26
- package/dist/types/utils/fs.d.mts.map +1 -1
- package/dist/types/utils/glob.d.mts +1 -1
- package/dist/types/utils/glob.d.mts.map +1 -1
- package/dist/types/utils/package-environment.d.mts.map +1 -1
- package/dist/types/utils/path-resolve.d.mts.map +1 -1
- package/dist/utils.js +406 -436
- package/dist/utils.js.map +1 -1
- package/dist/vendor.js +11302 -11294
- package/external/@socketsecurity/registry/lib/fs.js +109 -78
- package/external/@socketsecurity/registry/lib/globs.js +46 -1
- package/external/@socketsecurity/registry/lib/path.js +63 -19
- package/external/@socketsecurity/registry/lib/promises.js +43 -17
- package/external/@socketsecurity/registry/lib/streams.js +29 -8
- package/package.json +10 -10
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
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
-
|
|
421
|
+
require$$6.debugFn('error', `caught: ${desc} error`);
|
|
695
422
|
} else {
|
|
696
423
|
spinner?.stop();
|
|
697
|
-
|
|
424
|
+
require$$6.debugFn('error', `caught: error`);
|
|
698
425
|
}
|
|
699
|
-
|
|
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
|
-
|
|
446
|
+
require$$6.debugFn('error', `fail: ${desc} bad response`);
|
|
720
447
|
} else {
|
|
721
|
-
|
|
448
|
+
require$$6.debugFn('error', 'fail: bad response');
|
|
722
449
|
}
|
|
723
|
-
|
|
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
|
-
|
|
752
|
-
|
|
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
|
-
|
|
767
|
-
|
|
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
|
-
|
|
855
|
-
|
|
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
|
-
|
|
882
|
-
|
|
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
|
-
|
|
732
|
+
require$$6.debugFn('inspect', 'typeof data=', typeof data);
|
|
1006
733
|
if (typeof data !== 'object' && data) {
|
|
1007
|
-
|
|
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
|
-
|
|
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
|
-
|
|
1402
|
+
require$$6.debugFn('notice', 'use: org from defaultOrg value of socket/settings local app data', 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
|
-
|
|
1412
|
+
require$$6.debugFn('notice', 'use: org from SOCKET_CLI_ORG_SLUG environment variable', envOrgSlug);
|
|
1686
1413
|
return {
|
|
1687
1414
|
ok: true,
|
|
1688
1415
|
data: envOrgSlug
|
|
@@ -1700,7 +1427,7 @@ async function getDefaultOrgSlug() {
|
|
|
1700
1427
|
return {
|
|
1701
1428
|
ok: false,
|
|
1702
1429
|
message: 'Failed to establish identity',
|
|
1703
|
-
data: `
|
|
1430
|
+
data: `No organization associated with the API token. Unable to continue.`
|
|
1704
1431
|
};
|
|
1705
1432
|
}
|
|
1706
1433
|
const slug = organizations[keys[0]]?.name ?? undefined;
|
|
@@ -1708,10 +1435,10 @@ async function getDefaultOrgSlug() {
|
|
|
1708
1435
|
return {
|
|
1709
1436
|
ok: false,
|
|
1710
1437
|
message: 'Failed to establish identity',
|
|
1711
|
-
data: `
|
|
1438
|
+
data: `Cannot determine the default organization for the API token. Unable to continue.`
|
|
1712
1439
|
};
|
|
1713
1440
|
}
|
|
1714
|
-
|
|
1441
|
+
require$$6.debugFn('notice', 'resolve: org from API', 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
|
-
|
|
1761
|
-
|
|
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
|
-
|
|
1767
|
-
|
|
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:
|
|
1523
|
+
stdio: require$$6.isDebug('stdio') ? 'inherit' : 'ignore'
|
|
1797
1524
|
};
|
|
1798
1525
|
const quotedCmd = '`git clean -fdx`';
|
|
1799
|
-
|
|
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
|
-
|
|
1805
|
-
|
|
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:
|
|
1541
|
+
stdio: require$$6.isDebug('stdio') ? 'inherit' : 'ignore'
|
|
1815
1542
|
};
|
|
1816
1543
|
const quotedCmd = `\`git checkout ${branch}\``;
|
|
1817
|
-
|
|
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
|
-
|
|
1823
|
-
|
|
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:
|
|
1562
|
+
stdio: require$$6.isDebug('stdio') ? 'inherit' : 'ignore'
|
|
1836
1563
|
};
|
|
1837
1564
|
const quotedCmd = `\`git branch ${branch}\``;
|
|
1838
|
-
|
|
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
|
-
|
|
1844
|
-
|
|
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:
|
|
1580
|
+
stdio: require$$6.isDebug('stdio') ? 'inherit' : 'ignore'
|
|
1854
1581
|
};
|
|
1855
1582
|
const quotedCmd = `\`git push --force --set-upstream origin ${branch}\``;
|
|
1856
|
-
|
|
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
|
-
|
|
1588
|
+
require$$6.debugFn('error', `caught: ${quotedCmd} failed`);
|
|
1862
1589
|
if (spawn.isSpawnError(e) && e.code === 128) {
|
|
1863
|
-
|
|
1590
|
+
require$$6.debugFn('error', "denied: token requires write permissions for 'contents' and 'pull-requests'");
|
|
1864
1591
|
}
|
|
1865
|
-
|
|
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
|
-
|
|
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:
|
|
1616
|
+
stdio: require$$6.isDebug('stdio') ? 'inherit' : 'ignore'
|
|
1890
1617
|
};
|
|
1891
1618
|
const quotedAddCmd = `\`git add ${filepaths.join(' ')}\``;
|
|
1892
|
-
|
|
1619
|
+
require$$6.debugFn('stdio', `spawn: ${quotedAddCmd}`);
|
|
1893
1620
|
try {
|
|
1894
1621
|
await spawn.spawn('git', ['add', ...filepaths], stdioIgnoreOptions);
|
|
1895
1622
|
} catch (e) {
|
|
1896
|
-
|
|
1897
|
-
|
|
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
|
-
|
|
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
|
-
|
|
1908
|
-
|
|
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:
|
|
1644
|
+
stdio: require$$6.isDebug('stdio') ? 'inherit' : 'ignore'
|
|
1918
1645
|
};
|
|
1919
1646
|
const quotedCmd = `\`git branch -D ${branch}\``;
|
|
1920
|
-
|
|
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 (
|
|
1927
|
-
|
|
1928
|
-
|
|
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
|
-
|
|
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 (
|
|
1953
|
-
|
|
1954
|
-
|
|
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:
|
|
1690
|
+
stdio: require$$6.isDebug('stdio') ? 'inherit' : 'ignore'
|
|
1964
1691
|
};
|
|
1965
1692
|
const quotedCmd = `\`git config ${prop} ${value}\``;
|
|
1966
|
-
|
|
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 (
|
|
1971
|
-
|
|
1972
|
-
|
|
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:
|
|
1710
|
+
stdio: require$$6.isDebug('stdio') ? 'inherit' : 'ignore'
|
|
1984
1711
|
};
|
|
1985
1712
|
const quotedCmd = `\`git show-ref --quiet refs/heads/${branch}\``;
|
|
1986
|
-
|
|
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 (
|
|
1993
|
-
|
|
1994
|
-
|
|
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:
|
|
1746
|
+
stdio: require$$6.isDebug('stdio') ? 'inherit' : 'ignore'
|
|
2020
1747
|
};
|
|
2021
1748
|
const quotedCmd = `\`git reset --hard ${branch}\``;
|
|
2022
|
-
|
|
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
|
-
|
|
2028
|
-
|
|
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
|
-
|
|
2048
|
-
|
|
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,214 @@ 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
|
+
|
|
2040
|
+
// Add support for negated "ignore" patterns which many globbing libraries,
|
|
2041
|
+
// including 'fast-glob', 'globby', and 'tinyglobby', lack support for.
|
|
2042
|
+
const filtered = [];
|
|
2043
|
+
const ig = vendor.ignoreExports().add([...ignores]);
|
|
2044
|
+
const stream = vendor.outExports.globStream(patterns, globOptions);
|
|
2045
|
+
for await (const p of stream) {
|
|
2046
|
+
// Note: the input files must be INSIDE the cwd. If you get strange looking
|
|
2047
|
+
// relative path errors here, most likely your path is outside the given cwd.
|
|
2048
|
+
const relPath = globOptions.absolute ? path.relative(cwd, p) : p;
|
|
2049
|
+
if (!ig.ignores(relPath)) {
|
|
2050
|
+
filtered.push(p);
|
|
2051
|
+
}
|
|
2052
|
+
}
|
|
2053
|
+
return filtered;
|
|
2054
|
+
}
|
|
2055
|
+
async function globStreamNodeModules(cwd = process.cwd()) {
|
|
2056
|
+
return vendor.outExports.globStream('**/node_modules', {
|
|
2057
|
+
absolute: true,
|
|
2058
|
+
cwd,
|
|
2059
|
+
onlyDirectories: true
|
|
2060
|
+
});
|
|
2061
|
+
}
|
|
2062
|
+
async function globWorkspace(agent, cwd = process.cwd()) {
|
|
2063
|
+
const workspaceGlobs = await getWorkspaceGlobs(agent, cwd);
|
|
2064
|
+
return workspaceGlobs.length ? await vendor.outExports.glob(workspaceGlobs, {
|
|
2065
|
+
absolute: true,
|
|
2066
|
+
cwd,
|
|
2067
|
+
ignore: globs.defaultIgnore
|
|
2068
|
+
}) : [];
|
|
2069
|
+
}
|
|
2070
|
+
function isReportSupportedFile(filepath, supportedFiles) {
|
|
2071
|
+
const patterns = getSupportedFilePatterns(supportedFiles);
|
|
2072
|
+
return vendor.micromatchExports.some(filepath, patterns);
|
|
2073
|
+
}
|
|
2074
|
+
function pathsToGlobPatterns(paths) {
|
|
2075
|
+
// TODO: Does not support `~/` paths.
|
|
2076
|
+
return paths.map(p => p === '.' || p === './' ? '**/*' : p);
|
|
2077
|
+
}
|
|
2078
|
+
|
|
2144
2079
|
function findBinPathDetailsSync(binName) {
|
|
2145
2080
|
const binPaths = vendor.libExports$1.sync(binName, {
|
|
2146
2081
|
all: true,
|
|
@@ -2186,11 +2121,11 @@ function findNpmDirPathSync(npmBinPath) {
|
|
|
2186
2121
|
// Use existsSync here because statsSync, even with { throwIfNoEntry: false },
|
|
2187
2122
|
// will throw an ENOTDIR error for paths like ./a-file-that-exists/a-directory-that-does-not.
|
|
2188
2123
|
// See https://github.com/nodejs/node/issues/56993.
|
|
2189
|
-
|
|
2124
|
+
fs.isDirSync(libNmNpmPath)) {
|
|
2190
2125
|
thePath = libNmNpmPath;
|
|
2191
2126
|
}
|
|
2192
|
-
const
|
|
2193
|
-
const
|
|
2127
|
+
const hasNmInCurrPath = fs.isDirSync(path.join(thePath, 'node_modules'));
|
|
2128
|
+
const hasNmInParentPath = !hasNmInCurrPath && fs.isDirSync(path.join(thePath, '../node_modules'));
|
|
2194
2129
|
if (
|
|
2195
2130
|
// npm bin paths may look like:
|
|
2196
2131
|
// /usr/local/share/npm/bin/npm
|
|
@@ -2202,14 +2137,14 @@ function findNpmDirPathSync(npmBinPath) {
|
|
|
2202
2137
|
// In practically all cases the npm path contains a node_modules folder:
|
|
2203
2138
|
// /usr/local/share/npm/bin/npm/node_modules
|
|
2204
2139
|
// C:\Program Files\nodejs\node_modules
|
|
2205
|
-
(
|
|
2206
|
-
// In some bespoke cases the node_modules folder is
|
|
2207
|
-
|
|
2140
|
+
(hasNmInCurrPath ||
|
|
2141
|
+
// In some bespoke cases the node_modules folder is in the parent directory.
|
|
2142
|
+
hasNmInParentPath) && (
|
|
2208
2143
|
// Optimistically look for the default location.
|
|
2209
2144
|
path.basename(thePath) === 'npm' ||
|
|
2210
2145
|
// Chocolatey installs npm bins in the same directory as node bins.
|
|
2211
|
-
WIN32 && fs.existsSync(path.join(thePath, 'npm.cmd')))) {
|
|
2212
|
-
return
|
|
2146
|
+
WIN32 && fs$1.existsSync(path.join(thePath, 'npm.cmd')))) {
|
|
2147
|
+
return hasNmInParentPath ? path.dirname(thePath) : thePath;
|
|
2213
2148
|
}
|
|
2214
2149
|
const parent = path.dirname(thePath);
|
|
2215
2150
|
if (parent === thePath) {
|
|
@@ -2252,8 +2187,8 @@ function getDefaultSocketJson() {
|
|
|
2252
2187
|
}
|
|
2253
2188
|
async function readSocketJson(cwd, defaultOnError = false) {
|
|
2254
2189
|
const sockJsonPath = path.join(cwd, 'socket.json');
|
|
2255
|
-
if (!fs.existsSync(sockJsonPath)) {
|
|
2256
|
-
|
|
2190
|
+
if (!fs$1.existsSync(sockJsonPath)) {
|
|
2191
|
+
require$$6.debugFn('notice', `miss: file not found ${sockJsonPath}`);
|
|
2257
2192
|
return {
|
|
2258
2193
|
ok: true,
|
|
2259
2194
|
data: getDefaultSocketJson()
|
|
@@ -2261,9 +2196,9 @@ async function readSocketJson(cwd, defaultOnError = false) {
|
|
|
2261
2196
|
}
|
|
2262
2197
|
let json = null;
|
|
2263
2198
|
try {
|
|
2264
|
-
json = await fs.promises.readFile(sockJsonPath, 'utf8');
|
|
2199
|
+
json = await fs$1.promises.readFile(sockJsonPath, 'utf8');
|
|
2265
2200
|
} catch (e) {
|
|
2266
|
-
|
|
2201
|
+
require$$6.debugDir('inspect', {
|
|
2267
2202
|
error: e
|
|
2268
2203
|
});
|
|
2269
2204
|
if (defaultOnError) {
|
|
@@ -2284,8 +2219,8 @@ async function readSocketJson(cwd, defaultOnError = false) {
|
|
|
2284
2219
|
try {
|
|
2285
2220
|
obj = JSON.parse(json);
|
|
2286
2221
|
} catch {
|
|
2287
|
-
|
|
2288
|
-
|
|
2222
|
+
require$$6.debugFn('error', 'fail: parse JSON');
|
|
2223
|
+
require$$6.debugDir('inspect', {
|
|
2289
2224
|
json
|
|
2290
2225
|
});
|
|
2291
2226
|
if (defaultOnError) {
|
|
@@ -2322,11 +2257,11 @@ async function writeSocketJson(cwd, sockJson) {
|
|
|
2322
2257
|
try {
|
|
2323
2258
|
json = JSON.stringify(sockJson, null, 2);
|
|
2324
2259
|
} catch (e) {
|
|
2325
|
-
|
|
2326
|
-
|
|
2260
|
+
require$$6.debugFn('error', 'fail: stringify JSON');
|
|
2261
|
+
require$$6.debugDir('inspect', {
|
|
2327
2262
|
error: e
|
|
2328
2263
|
});
|
|
2329
|
-
|
|
2264
|
+
require$$6.debugDir('inspect', {
|
|
2330
2265
|
sockJson
|
|
2331
2266
|
});
|
|
2332
2267
|
return {
|
|
@@ -2336,48 +2271,13 @@ async function writeSocketJson(cwd, sockJson) {
|
|
|
2336
2271
|
};
|
|
2337
2272
|
}
|
|
2338
2273
|
const filepath = path.join(cwd, 'socket.json');
|
|
2339
|
-
await fs.promises.writeFile(filepath, json + '\n', 'utf8');
|
|
2274
|
+
await fs$1.promises.writeFile(filepath, json + '\n', 'utf8');
|
|
2340
2275
|
return {
|
|
2341
2276
|
ok: true,
|
|
2342
2277
|
data: undefined
|
|
2343
2278
|
};
|
|
2344
2279
|
}
|
|
2345
2280
|
|
|
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
2281
|
async function spawnCoana(args, options, extra) {
|
|
2382
2282
|
const {
|
|
2383
2283
|
env: spawnEnv
|
|
@@ -2480,7 +2380,7 @@ function getNpmRequire() {
|
|
|
2480
2380
|
if (_npmRequire === undefined) {
|
|
2481
2381
|
const npmDirPath = getNpmDirPath();
|
|
2482
2382
|
const npmNmPath = path.join(npmDirPath, NODE_MODULES, NPM$3);
|
|
2483
|
-
_npmRequire = require$$5.createRequire(path.join(fs.existsSync(npmNmPath) ? npmNmPath : npmDirPath, '<dummy-basename>'));
|
|
2383
|
+
_npmRequire = require$$5.createRequire(path.join(fs$1.existsSync(npmNmPath) ? npmNmPath : npmDirPath, '<dummy-basename>'));
|
|
2484
2384
|
}
|
|
2485
2385
|
return _npmRequire;
|
|
2486
2386
|
}
|
|
@@ -2898,12 +2798,12 @@ function getCveInfoFromAlertsMap(alertsMap, options) {
|
|
|
2898
2798
|
error = e;
|
|
2899
2799
|
}
|
|
2900
2800
|
}
|
|
2901
|
-
|
|
2902
|
-
|
|
2801
|
+
require$$6.debugFn('error', 'fail: invalid SocketPackageAlert');
|
|
2802
|
+
require$$6.debugDir('inspect', {
|
|
2903
2803
|
alert
|
|
2904
2804
|
});
|
|
2905
2805
|
if (error) {
|
|
2906
|
-
|
|
2806
|
+
require$$6.debugDir('inspect', {
|
|
2907
2807
|
error: error.message ?? error
|
|
2908
2808
|
});
|
|
2909
2809
|
}
|
|
@@ -3164,7 +3064,7 @@ async function getAlertsMapFromPurls(purls, options) {
|
|
|
3164
3064
|
...opts.include
|
|
3165
3065
|
};
|
|
3166
3066
|
const uniqPurls = arrays.arrayUnique(purls);
|
|
3167
|
-
|
|
3067
|
+
require$$6.debugDir('silly', {
|
|
3168
3068
|
purls: uniqPurls
|
|
3169
3069
|
});
|
|
3170
3070
|
let {
|
|
@@ -3218,7 +3118,7 @@ async function getAlertsMapFromPurls(purls, options) {
|
|
|
3218
3118
|
} else {
|
|
3219
3119
|
spinner?.stop();
|
|
3220
3120
|
logger.logger.fail(`Received a ${batchResult.status} response from Socket API which we consider a permanent failure:`, batchResult.error, batchResult.cause ? `( ${batchResult.cause} )` : '');
|
|
3221
|
-
|
|
3121
|
+
require$$6.debugDir('inspect', {
|
|
3222
3122
|
batchResult
|
|
3223
3123
|
});
|
|
3224
3124
|
break;
|
|
@@ -3239,6 +3139,79 @@ function npa(...args) {
|
|
|
3239
3139
|
return null;
|
|
3240
3140
|
}
|
|
3241
3141
|
|
|
3142
|
+
async function removeNodeModules(cwd = process.cwd()) {
|
|
3143
|
+
const stream = await globStreamNodeModules(cwd);
|
|
3144
|
+
await streams.parallelEach(stream, p => fs.remove(p, {
|
|
3145
|
+
force: true,
|
|
3146
|
+
recursive: true
|
|
3147
|
+
}), {
|
|
3148
|
+
concurrency: 8
|
|
3149
|
+
});
|
|
3150
|
+
}
|
|
3151
|
+
async function findUp(name, {
|
|
3152
|
+
cwd = process.cwd(),
|
|
3153
|
+
// Lazily access constants.abortSignal.
|
|
3154
|
+
signal = constants.abortSignal
|
|
3155
|
+
}) {
|
|
3156
|
+
let dir = path.resolve(cwd);
|
|
3157
|
+
const {
|
|
3158
|
+
root
|
|
3159
|
+
} = path.parse(dir);
|
|
3160
|
+
const names = [name].flat();
|
|
3161
|
+
while (dir && dir !== root) {
|
|
3162
|
+
for (const name of names) {
|
|
3163
|
+
if (signal?.aborted) {
|
|
3164
|
+
return undefined;
|
|
3165
|
+
}
|
|
3166
|
+
const filePath = path.join(dir, name);
|
|
3167
|
+
try {
|
|
3168
|
+
// eslint-disable-next-line no-await-in-loop
|
|
3169
|
+
const stats = await fs$1.promises.stat(filePath);
|
|
3170
|
+
if (stats.isFile()) {
|
|
3171
|
+
return filePath;
|
|
3172
|
+
}
|
|
3173
|
+
} catch {}
|
|
3174
|
+
}
|
|
3175
|
+
dir = path.dirname(dir);
|
|
3176
|
+
}
|
|
3177
|
+
return undefined;
|
|
3178
|
+
}
|
|
3179
|
+
|
|
3180
|
+
const helpFlags = new Set(['--help', '-h']);
|
|
3181
|
+
function cmdFlagsToString(args) {
|
|
3182
|
+
const result = [];
|
|
3183
|
+
for (let i = 0, {
|
|
3184
|
+
length
|
|
3185
|
+
} = args; i < length; i += 1) {
|
|
3186
|
+
if (args[i].startsWith('--')) {
|
|
3187
|
+
// Check if the next item exists and is NOT another flag.
|
|
3188
|
+
if (i + 1 < length && !args[i + 1].startsWith('--')) {
|
|
3189
|
+
result.push(`${args[i]}=${args[i + 1]}`);
|
|
3190
|
+
i += 1;
|
|
3191
|
+
} else {
|
|
3192
|
+
result.push(args[i]);
|
|
3193
|
+
}
|
|
3194
|
+
}
|
|
3195
|
+
}
|
|
3196
|
+
return result.join(' ');
|
|
3197
|
+
}
|
|
3198
|
+
function cmdFlagValueToArray(flagValue) {
|
|
3199
|
+
if (typeof flagValue === 'string') {
|
|
3200
|
+
return flagValue.trim().split(/, */);
|
|
3201
|
+
}
|
|
3202
|
+
if (Array.isArray(flagValue)) {
|
|
3203
|
+
return flagValue.flatMap(v => v.split(/, */));
|
|
3204
|
+
}
|
|
3205
|
+
return [];
|
|
3206
|
+
}
|
|
3207
|
+
function cmdPrefixMessage(cmdName, text) {
|
|
3208
|
+
const cmdPrefix = cmdName ? `${cmdName}: ` : '';
|
|
3209
|
+
return `${cmdPrefix}${text}`;
|
|
3210
|
+
}
|
|
3211
|
+
function isHelpFlag(cmdArg) {
|
|
3212
|
+
return helpFlags.has(cmdArg);
|
|
3213
|
+
}
|
|
3214
|
+
|
|
3242
3215
|
const {
|
|
3243
3216
|
NPM: NPM$2,
|
|
3244
3217
|
SOCKET_CLI_SAFE_BIN,
|
|
@@ -3266,7 +3239,7 @@ function safeNpmInstall(options) {
|
|
|
3266
3239
|
} else if (useIpc && Array.isArray(stdio) && !stdio.includes('ipc')) {
|
|
3267
3240
|
stdio = stdio.concat('ipc');
|
|
3268
3241
|
}
|
|
3269
|
-
const useDebug =
|
|
3242
|
+
const useDebug = require$$6.isDebug('stdio');
|
|
3270
3243
|
const terminatorPos = args.indexOf('--');
|
|
3271
3244
|
const rawBinArgs = terminatorPos === -1 ? args : args.slice(0, terminatorPos);
|
|
3272
3245
|
const progressArg = rawBinArgs.findLast(npm.isNpmProgressFlag) !== '--no-progress';
|
|
@@ -3408,7 +3381,7 @@ async function getNpmConfig(options) {
|
|
|
3408
3381
|
}
|
|
3409
3382
|
|
|
3410
3383
|
async function readLockfile(lockfilePath) {
|
|
3411
|
-
return fs.existsSync(lockfilePath) ? await readFileUtf8(lockfilePath) : null;
|
|
3384
|
+
return fs$1.existsSync(lockfilePath) ? await fs.readFileUtf8(lockfilePath) : null;
|
|
3412
3385
|
}
|
|
3413
3386
|
|
|
3414
3387
|
const {
|
|
@@ -3436,8 +3409,8 @@ const readLockFileByAgent = (() => {
|
|
|
3436
3409
|
return undefined;
|
|
3437
3410
|
};
|
|
3438
3411
|
}
|
|
3439
|
-
const binaryReader = wrapReader(readFileBinary);
|
|
3440
|
-
const defaultReader = wrapReader(async lockPath => await readFileUtf8(lockPath));
|
|
3412
|
+
const binaryReader = wrapReader(fs.readFileBinary);
|
|
3413
|
+
const defaultReader = wrapReader(async lockPath => await fs.readFileUtf8(lockPath));
|
|
3441
3414
|
return new Map([[BUN, wrapReader(async (lockPath, agentExecPath, cwd = process.cwd()) => {
|
|
3442
3415
|
const ext = path.extname(lockPath);
|
|
3443
3416
|
if (ext === LOCK_EXT) {
|
|
@@ -3510,8 +3483,8 @@ async function getAgentVersion(agentExecPath, cwd) {
|
|
|
3510
3483
|
shell: constants.WIN32
|
|
3511
3484
|
})).stdout) ?? undefined;
|
|
3512
3485
|
} catch (e) {
|
|
3513
|
-
|
|
3514
|
-
|
|
3486
|
+
require$$6.debugFn('error', 'caught: unexpected error');
|
|
3487
|
+
require$$6.debugDir('inspect', {
|
|
3515
3488
|
error: e
|
|
3516
3489
|
});
|
|
3517
3490
|
}
|
|
@@ -3529,7 +3502,7 @@ async function detectPackageEnvironment({
|
|
|
3529
3502
|
const pkgJsonPath = lockPath ? path.resolve(lockPath, `${isHiddenLockFile ? '../' : ''}../${PACKAGE_JSON}`) : await findUp(PACKAGE_JSON, {
|
|
3530
3503
|
cwd
|
|
3531
3504
|
});
|
|
3532
|
-
const pkgPath = pkgJsonPath && fs.existsSync(pkgJsonPath) ? path.dirname(pkgJsonPath) : undefined;
|
|
3505
|
+
const pkgPath = pkgJsonPath && fs$1.existsSync(pkgJsonPath) ? path.dirname(pkgJsonPath) : undefined;
|
|
3533
3506
|
const editablePkgJson = pkgPath ? await packages.readPackageJson(pkgPath, {
|
|
3534
3507
|
editable: true
|
|
3535
3508
|
}) : undefined;
|
|
@@ -3755,7 +3728,7 @@ function getCompletionSourcingCommand() {
|
|
|
3755
3728
|
const completionScriptExportPath = path.join(
|
|
3756
3729
|
// Lazily access constants.distPath.
|
|
3757
3730
|
constants.distPath, 'socket-completion.bash');
|
|
3758
|
-
if (!fs.existsSync(completionScriptExportPath)) {
|
|
3731
|
+
if (!fs$1.existsSync(completionScriptExportPath)) {
|
|
3759
3732
|
return {
|
|
3760
3733
|
ok: false,
|
|
3761
3734
|
message: 'Tab Completion script not found',
|
|
@@ -3891,9 +3864,6 @@ exports.readOrDefaultSocketJson = readOrDefaultSocketJson;
|
|
|
3891
3864
|
exports.readSocketJson = readSocketJson;
|
|
3892
3865
|
exports.removeNodeModules = removeNodeModules;
|
|
3893
3866
|
exports.runAgentInstall = runAgentInstall;
|
|
3894
|
-
exports.safeReadFile = safeReadFile;
|
|
3895
|
-
exports.safeReadFileSync = safeReadFileSync;
|
|
3896
|
-
exports.safeStatsSync = safeStatsSync;
|
|
3897
3867
|
exports.serializeResultJson = serializeResultJson;
|
|
3898
3868
|
exports.setupSdk = setupSdk;
|
|
3899
3869
|
exports.spawnCoana = spawnCoana;
|
|
@@ -3902,5 +3872,5 @@ exports.tildify = tildify;
|
|
|
3902
3872
|
exports.updateConfigValue = updateConfigValue;
|
|
3903
3873
|
exports.walkNestedMap = walkNestedMap;
|
|
3904
3874
|
exports.writeSocketJson = writeSocketJson;
|
|
3905
|
-
//# debugId=
|
|
3875
|
+
//# debugId=e5cd4032-d503-47fb-97fe-83d96ce9043d
|
|
3906
3876
|
//# sourceMappingURL=utils.js.map
|