@socketsecurity/cli-with-sentry 0.14.62 → 0.14.63
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/bin/cli.js +1 -0
- package/dist/constants.d.ts +14 -15
- package/dist/constants.js +4 -2
- package/dist/constants.js.map +1 -1
- package/dist/instrument-with-sentry.js +2 -2
- package/dist/instrument-with-sentry.js.map +1 -1
- package/dist/module-sync/cli.js +773 -1771
- package/dist/module-sync/cli.js.map +1 -1
- package/dist/module-sync/fs.d.ts +22 -0
- package/dist/module-sync/shadow-npm-inject.js +38 -27
- package/dist/module-sync/shadow-npm-inject.js.map +1 -1
- package/dist/require/cli.js +773 -1770
- package/dist/require/cli.js.map +1 -1
- package/dist/require/vendor.js +1 -2414
- package/dist/require/vendor.js.map +1 -1
- package/package.json +15 -25
package/dist/require/cli.js
CHANGED
|
@@ -16,25 +16,20 @@ var ponyCause = _socketInterop(require('pony-cause'));
|
|
|
16
16
|
var vendor = require('./vendor.js');
|
|
17
17
|
var colors = _socketInterop(require('yoctocolors-cjs'));
|
|
18
18
|
var logger = require('@socketsecurity/registry/lib/logger');
|
|
19
|
-
var
|
|
20
|
-
var
|
|
21
|
-
var
|
|
22
|
-
var
|
|
23
|
-
var fs = require('node:fs');
|
|
24
|
-
var path = require('node:path');
|
|
25
|
-
var ndjson = _socketInterop(require('ndjson'));
|
|
19
|
+
var commonTags = _socketInterop(require('common-tags'));
|
|
20
|
+
var fs = require('node:fs/promises');
|
|
21
|
+
var ScreenWidget = _socketInterop(require('blessed/lib/widgets/screen'));
|
|
22
|
+
var contrib = _socketInterop(require('blessed-contrib'));
|
|
26
23
|
var shadowNpmInject = require('./shadow-npm-inject.js');
|
|
27
24
|
var constants = require('./constants.js');
|
|
25
|
+
var path$1 = require('node:path');
|
|
28
26
|
var objects = require('@socketsecurity/registry/lib/objects');
|
|
29
|
-
var path
|
|
27
|
+
var path = require('@socketsecurity/registry/lib/path');
|
|
30
28
|
var regexps = require('@socketsecurity/registry/lib/regexps');
|
|
31
|
-
var commonTags = _socketInterop(require('common-tags'));
|
|
32
|
-
var fs$1 = require('node:fs/promises');
|
|
33
|
-
var ScreenWidget = _socketInterop(require('blessed/lib/widgets/screen'));
|
|
34
|
-
var contrib = _socketInterop(require('blessed-contrib'));
|
|
35
29
|
var prompts = require('@socketsecurity/registry/lib/prompts');
|
|
36
30
|
var yargsParse = _socketInterop(require('yargs-parser'));
|
|
37
31
|
var words = require('@socketsecurity/registry/lib/words');
|
|
32
|
+
var fs$1 = require('node:fs');
|
|
38
33
|
var shadowBin = require('./shadow-bin.js');
|
|
39
34
|
var chalkTable = _socketInterop(require('chalk-table'));
|
|
40
35
|
var require$$0$1 = require('node:util');
|
|
@@ -67,1229 +62,6 @@ var BoxWidget = _socketInterop(require('blessed/lib/widgets/box'));
|
|
|
67
62
|
var TableWidget = _socketInterop(require('blessed-contrib/lib/widget/table'));
|
|
68
63
|
var readline$1 = require('node:readline');
|
|
69
64
|
|
|
70
|
-
// https://github.com/SocketDev/socket-python-cli/blob/6d4fc56faee68d3a4764f1f80f84710635bdaf05/socketsecurity/core/classes.py
|
|
71
|
-
|
|
72
|
-
class Comment {
|
|
73
|
-
id = 0;
|
|
74
|
-
body = '';
|
|
75
|
-
body_list = [];
|
|
76
|
-
constructor(arg) {
|
|
77
|
-
this.id = arg.id ?? this.id;
|
|
78
|
-
this.body = arg.body ?? this.body;
|
|
79
|
-
this.body_list = arg.body_list ?? this.body_list;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
class Diff {
|
|
83
|
-
newPackages = [];
|
|
84
|
-
newCapabilities = {};
|
|
85
|
-
removedPackages = [];
|
|
86
|
-
newAlerts = [];
|
|
87
|
-
id = '';
|
|
88
|
-
sbom = '';
|
|
89
|
-
packages = {};
|
|
90
|
-
reportUrl = '';
|
|
91
|
-
diffUrl = '';
|
|
92
|
-
}
|
|
93
|
-
class FullScan {
|
|
94
|
-
id = '';
|
|
95
|
-
created_at = '';
|
|
96
|
-
updated_at = '';
|
|
97
|
-
organizationId = '';
|
|
98
|
-
repositoryId = '';
|
|
99
|
-
branch = '';
|
|
100
|
-
commit_message = '';
|
|
101
|
-
commit_hash = '';
|
|
102
|
-
pull_request = 0;
|
|
103
|
-
sbom_artifacts = [];
|
|
104
|
-
packages = {};
|
|
105
|
-
constructor(obj = {}) {
|
|
106
|
-
this.id = obj.id ?? this.id;
|
|
107
|
-
this.created_at = obj.created_at ?? this.created_at;
|
|
108
|
-
this.updated_at = obj.updated_at ?? this.updated_at;
|
|
109
|
-
this.organizationId = obj.organizationId ?? this.organizationId;
|
|
110
|
-
this.repositoryId = obj.repositoryId ?? this.repositoryId;
|
|
111
|
-
this.branch = obj.branch ?? this.branch;
|
|
112
|
-
this.commit_message = obj.commit_message ?? this.commit_message;
|
|
113
|
-
this.commit_hash = obj.commit_hash ?? this.commit_hash;
|
|
114
|
-
this.pull_request = obj.pull_request ?? this.pull_request;
|
|
115
|
-
this.sbom_artifacts = obj.sbom_artifacts ?? this.sbom_artifacts;
|
|
116
|
-
this.packages = obj.packages ?? this.packages;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
class Issue {
|
|
120
|
-
pkg_type = '';
|
|
121
|
-
pkg_name = '';
|
|
122
|
-
pkg_version = '';
|
|
123
|
-
category = '';
|
|
124
|
-
type = '';
|
|
125
|
-
severity = '';
|
|
126
|
-
pkg_id = '';
|
|
127
|
-
props = {};
|
|
128
|
-
key = '';
|
|
129
|
-
error = false;
|
|
130
|
-
warn = false;
|
|
131
|
-
ignore = false;
|
|
132
|
-
monitor = false;
|
|
133
|
-
description = '';
|
|
134
|
-
title = '';
|
|
135
|
-
emoji = '';
|
|
136
|
-
next_step_title = '';
|
|
137
|
-
suggestion = '';
|
|
138
|
-
introduced_by = [];
|
|
139
|
-
manifests = '';
|
|
140
|
-
url = '';
|
|
141
|
-
purl = '';
|
|
142
|
-
constructor(arg) {
|
|
143
|
-
this.pkg_type = arg.pkg_type ?? this.pkg_type;
|
|
144
|
-
this.pkg_name = arg.pkg_name ?? this.pkg_name;
|
|
145
|
-
this.pkg_version = arg.pkg_version ?? this.pkg_version;
|
|
146
|
-
this.type = arg.type ?? this.type;
|
|
147
|
-
this.severity = arg.severity ?? this.severity;
|
|
148
|
-
this.pkg_id = arg.pkg_id ?? this.pkg_id;
|
|
149
|
-
this.props = arg.props ?? this.props;
|
|
150
|
-
this.key = arg.key ?? this.key;
|
|
151
|
-
this.error = arg.error ?? this.error;
|
|
152
|
-
this.warn = arg.warn ?? this.warn;
|
|
153
|
-
this.ignore = arg.ignore ?? this.ignore;
|
|
154
|
-
this.monitor = arg.monitor ?? this.monitor;
|
|
155
|
-
this.description = arg.description ?? this.description;
|
|
156
|
-
this.title = arg.title ?? this.title;
|
|
157
|
-
this.next_step_title = arg.next_step_title ?? this.next_step_title;
|
|
158
|
-
this.suggestion = arg.suggestion ?? this.suggestion;
|
|
159
|
-
if (arg.introduced_by) {
|
|
160
|
-
const arr = [];
|
|
161
|
-
for (const item of arg.introduced_by) {
|
|
162
|
-
const [, manifest] = item;
|
|
163
|
-
arr.push(manifest);
|
|
164
|
-
}
|
|
165
|
-
this.manifests = arr.join(';');
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
class Package {
|
|
170
|
-
type = '';
|
|
171
|
-
name = '';
|
|
172
|
-
version = '';
|
|
173
|
-
release = '';
|
|
174
|
-
id = '';
|
|
175
|
-
direct = false;
|
|
176
|
-
manifestFiles = [];
|
|
177
|
-
author = [];
|
|
178
|
-
size = 0;
|
|
179
|
-
scores = {};
|
|
180
|
-
alerts = [];
|
|
181
|
-
alert_counts = {};
|
|
182
|
-
topLevelAncestors = [];
|
|
183
|
-
url = '';
|
|
184
|
-
transitives = 0;
|
|
185
|
-
license = 'NoLicenseFound';
|
|
186
|
-
license_text = '';
|
|
187
|
-
purl = '';
|
|
188
|
-
constructor(arg) {
|
|
189
|
-
this.type = arg.type ?? this.type;
|
|
190
|
-
this.name = arg.name ?? this.name;
|
|
191
|
-
this.version = arg.version ?? this.version;
|
|
192
|
-
this.release = arg.release ?? this.release;
|
|
193
|
-
this.id = arg.id ?? this.id;
|
|
194
|
-
this.manifestFiles = arg.manifestFiles ?? this.manifestFiles;
|
|
195
|
-
this.author = arg.author ?? this.author;
|
|
196
|
-
this.size = arg.size ?? this.size;
|
|
197
|
-
this.alerts = arg.alerts ?? this.alerts;
|
|
198
|
-
this.topLevelAncestors = arg.topLevelAncestors ?? this.topLevelAncestors;
|
|
199
|
-
this.license = arg.license ?? this.license;
|
|
200
|
-
this.url = `https://socket.dev/${this.type}/package/${this.name}/overview/${this.version}`;
|
|
201
|
-
this.score = new Score(arg.score ?? {
|
|
202
|
-
supplyChain: 0,
|
|
203
|
-
quality: 0,
|
|
204
|
-
license: 0,
|
|
205
|
-
overall: 0,
|
|
206
|
-
vulnerability: 0
|
|
207
|
-
});
|
|
208
|
-
this.alert_counts = {
|
|
209
|
-
critical: 0,
|
|
210
|
-
high: 0,
|
|
211
|
-
middle: 0,
|
|
212
|
-
low: 0
|
|
213
|
-
};
|
|
214
|
-
this.purl = `${this.type}/${this.name}@${this.version}`;
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
class Purl {
|
|
218
|
-
id = '';
|
|
219
|
-
name = '';
|
|
220
|
-
version = '';
|
|
221
|
-
ecosystem = '';
|
|
222
|
-
direct = false;
|
|
223
|
-
author = [];
|
|
224
|
-
size = 0;
|
|
225
|
-
transitives = 0;
|
|
226
|
-
introduced_by = [];
|
|
227
|
-
capabilities = [];
|
|
228
|
-
// is_new = false
|
|
229
|
-
author_url = '';
|
|
230
|
-
url = '';
|
|
231
|
-
purl = '';
|
|
232
|
-
constructor(arg) {
|
|
233
|
-
this.id = arg.id ?? this.id;
|
|
234
|
-
this.name = arg.name ?? this.name;
|
|
235
|
-
this.version = arg.version ?? this.version;
|
|
236
|
-
this.ecosystem = arg.ecosystem ?? this.ecosystem;
|
|
237
|
-
this.direct = arg.direct ?? this.direct;
|
|
238
|
-
this.author = arg.author ?? this.author;
|
|
239
|
-
this.size = arg.size ?? this.size;
|
|
240
|
-
this.transitives = arg.transitives ?? this.transitives;
|
|
241
|
-
this.introduced_by = arg.introduced_by ?? this.introduced_by;
|
|
242
|
-
this.url = arg.url ?? this.url;
|
|
243
|
-
this.purl = arg.purl ?? this.purl;
|
|
244
|
-
this.author_url = this.generateAuthorData(this.author, this.ecosystem);
|
|
245
|
-
}
|
|
246
|
-
generateAuthorData(authors, ecosystem) {
|
|
247
|
-
const arr = [];
|
|
248
|
-
for (const author of authors) {
|
|
249
|
-
const url = `https://socket.dev/${ecosystem}/user/${author}`;
|
|
250
|
-
arr.push(`[${author}](${url})`);
|
|
251
|
-
}
|
|
252
|
-
return arr.join(',');
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
class Score {
|
|
256
|
-
supplyChain = 0;
|
|
257
|
-
quality = 0;
|
|
258
|
-
license = 0;
|
|
259
|
-
overall = 0;
|
|
260
|
-
vulnerability = 0;
|
|
261
|
-
constructor(arg) {
|
|
262
|
-
this.supplyChain = (arg.supplyChain ?? 0) * 100;
|
|
263
|
-
this.quality = (arg.quality ?? 0) * 100;
|
|
264
|
-
this.license = (arg.license ?? 0) * 100;
|
|
265
|
-
this.overall = (arg.overall ?? 0) * 100;
|
|
266
|
-
this.vulnerability = (arg.vulnerability ?? 0) * 100;
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
// https://github.com/SocketDev/socket-python-cli/blob/6d4fc56faee68d3a4764f1f80f84710635bdaf05/socketsecurity/core/__init__.py
|
|
271
|
-
class Core {
|
|
272
|
-
securityPolicy = {};
|
|
273
|
-
constructor({
|
|
274
|
-
owner,
|
|
275
|
-
repo,
|
|
276
|
-
socket
|
|
277
|
-
}) {
|
|
278
|
-
this.socket = socket;
|
|
279
|
-
this.owner = owner;
|
|
280
|
-
this.repo = repo;
|
|
281
|
-
this.files = [];
|
|
282
|
-
}
|
|
283
|
-
async getSbomData({
|
|
284
|
-
fullScanId
|
|
285
|
-
}) {
|
|
286
|
-
const orgFullScanResponse = await this.socket.getOrgFullScan(this.owner, fullScanId, undefined);
|
|
287
|
-
if (!orgFullScanResponse.success) {
|
|
288
|
-
return [];
|
|
289
|
-
}
|
|
290
|
-
const {
|
|
291
|
-
data: readStream
|
|
292
|
-
} = orgFullScanResponse;
|
|
293
|
-
const sbomArtifacts = [];
|
|
294
|
-
readStream.pipe(ndjson.parse()).on('data', sbomArtifact => sbomArtifacts.push(sbomArtifact));
|
|
295
|
-
await events.once(readStream, 'end');
|
|
296
|
-
return sbomArtifacts;
|
|
297
|
-
}
|
|
298
|
-
async createFullScan({
|
|
299
|
-
params
|
|
300
|
-
}) {
|
|
301
|
-
const orgFullScanResponse = await this.socket.createOrgFullScan(this.owner,
|
|
302
|
-
// Ignoring because pull_request is of type number but URLSearchParams will convert it to a string
|
|
303
|
-
// @ts-ignore
|
|
304
|
-
new URLSearchParams({
|
|
305
|
-
repo: this.repo,
|
|
306
|
-
...params
|
|
307
|
-
}), this.files);
|
|
308
|
-
if (!orgFullScanResponse.success) {
|
|
309
|
-
return new FullScan();
|
|
310
|
-
}
|
|
311
|
-
const {
|
|
312
|
-
id: fullScanId
|
|
313
|
-
} = orgFullScanResponse.data;
|
|
314
|
-
const fullScan = new FullScan(orgFullScanResponse.data);
|
|
315
|
-
if (fullScanId !== undefined) {
|
|
316
|
-
fullScan.sbom_artifacts = await this.getSbomData({
|
|
317
|
-
fullScanId
|
|
318
|
-
});
|
|
319
|
-
}
|
|
320
|
-
return fullScan;
|
|
321
|
-
}
|
|
322
|
-
getSourceData({
|
|
323
|
-
packages,
|
|
324
|
-
pkg
|
|
325
|
-
}) {
|
|
326
|
-
const introducedBy = [];
|
|
327
|
-
if (pkg.direct) {
|
|
328
|
-
const manifests = pkg.manifestFiles.map(({
|
|
329
|
-
file
|
|
330
|
-
}) => file).join(';');
|
|
331
|
-
introducedBy.push(['direct', manifests]);
|
|
332
|
-
} else {
|
|
333
|
-
for (const topId of pkg.topLevelAncestors) {
|
|
334
|
-
const topPackage = packages[topId];
|
|
335
|
-
if (!topPackage) {
|
|
336
|
-
continue;
|
|
337
|
-
}
|
|
338
|
-
const topPurl = `${topPackage.type}/${topPackage.name}@${topPackage.version}`;
|
|
339
|
-
const manifests = topPackage.manifestFiles.map(({
|
|
340
|
-
file
|
|
341
|
-
}) => file).join(';');
|
|
342
|
-
introducedBy.push([topPurl, manifests]);
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
return introducedBy;
|
|
346
|
-
}
|
|
347
|
-
createPurl({
|
|
348
|
-
packageId,
|
|
349
|
-
packages
|
|
350
|
-
}) {
|
|
351
|
-
const pkg = packages[packageId];
|
|
352
|
-
const introducedBy = this.getSourceData({
|
|
353
|
-
pkg,
|
|
354
|
-
packages
|
|
355
|
-
});
|
|
356
|
-
const purl = new Purl({
|
|
357
|
-
id: pkg.id,
|
|
358
|
-
name: pkg.name,
|
|
359
|
-
version: pkg.version,
|
|
360
|
-
ecosystem: pkg.type,
|
|
361
|
-
direct: pkg.direct,
|
|
362
|
-
introduced_by: introducedBy,
|
|
363
|
-
author: pkg.author,
|
|
364
|
-
size: pkg.size,
|
|
365
|
-
transitives: pkg.transitives,
|
|
366
|
-
url: pkg.url,
|
|
367
|
-
purl: pkg.purl
|
|
368
|
-
});
|
|
369
|
-
return {
|
|
370
|
-
purl,
|
|
371
|
-
pkg
|
|
372
|
-
};
|
|
373
|
-
}
|
|
374
|
-
async createIssueAlerts({
|
|
375
|
-
alerts,
|
|
376
|
-
packages,
|
|
377
|
-
pkg
|
|
378
|
-
}) {
|
|
379
|
-
const issues = JSON.parse(fs.readFileSync(path.join(undefined, 'issues.json'), 'utf8'));
|
|
380
|
-
for (const alert of pkg.alerts) {
|
|
381
|
-
const issue = issues[alert.type];
|
|
382
|
-
let description = '';
|
|
383
|
-
let title = '';
|
|
384
|
-
let suggestion = '';
|
|
385
|
-
let nextStepTitle = '';
|
|
386
|
-
if (issue !== undefined) {
|
|
387
|
-
description = issue['description'] ?? '';
|
|
388
|
-
title = issue['title'] ?? '';
|
|
389
|
-
suggestion = issue['suggestion'] ?? '';
|
|
390
|
-
nextStepTitle = issue['nextStepTitle'] ?? '';
|
|
391
|
-
}
|
|
392
|
-
const introducedBy = this.getSourceData({
|
|
393
|
-
pkg,
|
|
394
|
-
packages
|
|
395
|
-
});
|
|
396
|
-
const issueAlert = new Issue({
|
|
397
|
-
pkg_type: pkg.type,
|
|
398
|
-
pkg_name: pkg.name,
|
|
399
|
-
pkg_version: pkg.version,
|
|
400
|
-
pkg_id: pkg.id,
|
|
401
|
-
type: alert.type,
|
|
402
|
-
severity: alert.severity,
|
|
403
|
-
key: alert.key,
|
|
404
|
-
props: alert.props,
|
|
405
|
-
description,
|
|
406
|
-
title,
|
|
407
|
-
suggestion,
|
|
408
|
-
next_step_title: nextStepTitle,
|
|
409
|
-
introduced_by: introducedBy,
|
|
410
|
-
purl: pkg.purl,
|
|
411
|
-
url: pkg.url,
|
|
412
|
-
error: false,
|
|
413
|
-
ignore: false,
|
|
414
|
-
warn: false,
|
|
415
|
-
monitor: false
|
|
416
|
-
});
|
|
417
|
-
if (alert.type in this.securityPolicy) {
|
|
418
|
-
const action = this.securityPolicy[alert.type]?.action;
|
|
419
|
-
if (action !== undefined) {
|
|
420
|
-
issueAlert[action] = true;
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
if (issueAlert.type !== 'licenseSpdxDisj') {
|
|
424
|
-
if (!(issueAlert.key in alerts)) {
|
|
425
|
-
alerts[issueAlert.key] = [issueAlert];
|
|
426
|
-
} else {
|
|
427
|
-
alerts[issueAlert.key].push(issueAlert);
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
return alerts;
|
|
432
|
-
}
|
|
433
|
-
compareIssueAlerts({
|
|
434
|
-
alerts,
|
|
435
|
-
headScanAlerts,
|
|
436
|
-
newScanAlerts
|
|
437
|
-
}) {
|
|
438
|
-
const consolidatedAlerts = new Set();
|
|
439
|
-
for (const alertKey in newScanAlerts) {
|
|
440
|
-
if (!(alertKey in headScanAlerts)) {
|
|
441
|
-
const newAlerts = newScanAlerts[alertKey];
|
|
442
|
-
for (const alert of newAlerts) {
|
|
443
|
-
const alertStr = `${alert.purl},${alert.manifests},${alert.type}`;
|
|
444
|
-
if (alert.error || alert.warn) {
|
|
445
|
-
if (!consolidatedAlerts.has(alertStr)) {
|
|
446
|
-
alerts.push(alert);
|
|
447
|
-
consolidatedAlerts.add(alertStr);
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
} else {
|
|
452
|
-
const newAlerts = newScanAlerts[alertKey];
|
|
453
|
-
const headAlerts = headScanAlerts[alertKey];
|
|
454
|
-
for (const alert of newAlerts) {
|
|
455
|
-
const alertStr = `${alert.purl},${alert.manifests},${alert.type}`;
|
|
456
|
-
if (!headAlerts.includes(alert) && !consolidatedAlerts.has(alertStr)) {
|
|
457
|
-
if (alert.error || alert.warn) {
|
|
458
|
-
alerts.push(alert);
|
|
459
|
-
consolidatedAlerts.add(alertStr);
|
|
460
|
-
}
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
return alerts;
|
|
466
|
-
}
|
|
467
|
-
checkAlertCapabilities({
|
|
468
|
-
capabilities,
|
|
469
|
-
headPackage,
|
|
470
|
-
packageId,
|
|
471
|
-
pkg
|
|
472
|
-
}) {
|
|
473
|
-
const alertTypes = {
|
|
474
|
-
envVars: 'Environment',
|
|
475
|
-
networkAccess: 'Network',
|
|
476
|
-
filesystemAccess: 'File System',
|
|
477
|
-
shellAccess: 'Shell'
|
|
478
|
-
};
|
|
479
|
-
for (const alert of pkg.alerts) {
|
|
480
|
-
let newAlert = true;
|
|
481
|
-
if (headPackage !== undefined && headPackage.alerts.includes(alert)) {
|
|
482
|
-
newAlert = false;
|
|
483
|
-
}
|
|
484
|
-
if (alert.type in alertTypes && newAlert) {
|
|
485
|
-
const value = alertTypes[alert.type];
|
|
486
|
-
if (!(packageId in capabilities)) {
|
|
487
|
-
capabilities[packageId] = [value];
|
|
488
|
-
} else {
|
|
489
|
-
if (!capabilities[packageId].includes(value)) {
|
|
490
|
-
capabilities[packageId].push(value);
|
|
491
|
-
}
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
|
-
}
|
|
495
|
-
return capabilities;
|
|
496
|
-
}
|
|
497
|
-
compareCapabilities({
|
|
498
|
-
headPackages,
|
|
499
|
-
newPackages
|
|
500
|
-
}) {
|
|
501
|
-
let capabilities = {};
|
|
502
|
-
for (const packageId in newPackages) {
|
|
503
|
-
const pkg = newPackages[packageId];
|
|
504
|
-
if (packageId in headPackages) {
|
|
505
|
-
const headPackage = headPackages[packageId];
|
|
506
|
-
for (const alert of pkg.alerts) {
|
|
507
|
-
if (!headPackage.alerts.includes(alert)) {
|
|
508
|
-
capabilities = this.checkAlertCapabilities({
|
|
509
|
-
pkg,
|
|
510
|
-
capabilities,
|
|
511
|
-
packageId,
|
|
512
|
-
headPackage
|
|
513
|
-
});
|
|
514
|
-
}
|
|
515
|
-
}
|
|
516
|
-
} else {
|
|
517
|
-
capabilities = this.checkAlertCapabilities({
|
|
518
|
-
pkg,
|
|
519
|
-
capabilities,
|
|
520
|
-
packageId
|
|
521
|
-
});
|
|
522
|
-
}
|
|
523
|
-
}
|
|
524
|
-
return capabilities;
|
|
525
|
-
}
|
|
526
|
-
addCapabilitiesToPurl(diff) {
|
|
527
|
-
const newPackages = [];
|
|
528
|
-
for (const purl of diff.newPackages) {
|
|
529
|
-
if (purl.id in diff.newCapabilities) {
|
|
530
|
-
const capabilities = diff.newCapabilities[purl.id];
|
|
531
|
-
if (capabilities.length > 0) {
|
|
532
|
-
purl.capabilities = capabilities;
|
|
533
|
-
newPackages.push(purl);
|
|
534
|
-
}
|
|
535
|
-
} else {
|
|
536
|
-
newPackages.push(purl);
|
|
537
|
-
}
|
|
538
|
-
}
|
|
539
|
-
diff.newPackages = newPackages;
|
|
540
|
-
return diff;
|
|
541
|
-
}
|
|
542
|
-
async compareSBOMs({
|
|
543
|
-
headScan,
|
|
544
|
-
newScan
|
|
545
|
-
}) {
|
|
546
|
-
let diff = new Diff();
|
|
547
|
-
const newPackages = this.createSbomDict(newScan);
|
|
548
|
-
const headPackages = this.createSbomDict(headScan);
|
|
549
|
-
let newScanAlerts = {};
|
|
550
|
-
let headScanAlerts = {};
|
|
551
|
-
const consolidated = new Set();
|
|
552
|
-
for (const packageId in newPackages) {
|
|
553
|
-
const {
|
|
554
|
-
pkg,
|
|
555
|
-
purl
|
|
556
|
-
} = this.createPurl({
|
|
557
|
-
packageId,
|
|
558
|
-
packages: newPackages
|
|
559
|
-
});
|
|
560
|
-
const basePurl = `${purl.ecosystem}/${purl.name}@${purl.version}`;
|
|
561
|
-
if (!(packageId in headPackages) && pkg.direct && !consolidated.has(basePurl)) {
|
|
562
|
-
diff.newPackages.push(purl);
|
|
563
|
-
consolidated.add(basePurl);
|
|
564
|
-
}
|
|
565
|
-
// eslint-disable-next-line no-await-in-loop
|
|
566
|
-
newScanAlerts = await this.createIssueAlerts({
|
|
567
|
-
pkg,
|
|
568
|
-
alerts: newScanAlerts,
|
|
569
|
-
packages: newPackages
|
|
570
|
-
});
|
|
571
|
-
}
|
|
572
|
-
for (const packageId in headPackages) {
|
|
573
|
-
const {
|
|
574
|
-
pkg,
|
|
575
|
-
purl
|
|
576
|
-
} = this.createPurl({
|
|
577
|
-
packageId,
|
|
578
|
-
packages: headPackages
|
|
579
|
-
});
|
|
580
|
-
if (!(packageId in newPackages) && pkg.direct) {
|
|
581
|
-
diff.removedPackages.push(purl);
|
|
582
|
-
}
|
|
583
|
-
// eslint-disable-next-line no-await-in-loop
|
|
584
|
-
headScanAlerts = await this.createIssueAlerts({
|
|
585
|
-
pkg,
|
|
586
|
-
alerts: headScanAlerts,
|
|
587
|
-
packages: headPackages
|
|
588
|
-
});
|
|
589
|
-
}
|
|
590
|
-
diff.newAlerts = this.compareIssueAlerts({
|
|
591
|
-
newScanAlerts,
|
|
592
|
-
headScanAlerts,
|
|
593
|
-
alerts: diff.newAlerts
|
|
594
|
-
});
|
|
595
|
-
diff.newCapabilities = this.compareCapabilities({
|
|
596
|
-
newPackages,
|
|
597
|
-
headPackages
|
|
598
|
-
});
|
|
599
|
-
diff = this.addCapabilitiesToPurl(diff);
|
|
600
|
-
return diff;
|
|
601
|
-
}
|
|
602
|
-
createPackageFromSbomArtifact(sbomArtifact) {
|
|
603
|
-
return sbomArtifact.map(sbomArtifact => new Package({
|
|
604
|
-
type: sbomArtifact.type,
|
|
605
|
-
name: sbomArtifact.name,
|
|
606
|
-
version: sbomArtifact.version,
|
|
607
|
-
release: sbomArtifact.release,
|
|
608
|
-
id: sbomArtifact.id,
|
|
609
|
-
direct: sbomArtifact.direct,
|
|
610
|
-
manifestFiles: sbomArtifact.manifestFiles,
|
|
611
|
-
author: sbomArtifact.author,
|
|
612
|
-
size: sbomArtifact.size,
|
|
613
|
-
score: sbomArtifact.score,
|
|
614
|
-
alerts: sbomArtifact.alerts,
|
|
615
|
-
topLevelAncestors: sbomArtifact.topLevelAncestors,
|
|
616
|
-
license: sbomArtifact.license
|
|
617
|
-
}));
|
|
618
|
-
}
|
|
619
|
-
getLicenseDetails({
|
|
620
|
-
package: pkg
|
|
621
|
-
}) {
|
|
622
|
-
const licenseText = JSON.parse(fs.readFileSync(path.join(undefined, 'license_texts.json'), 'utf8'));
|
|
623
|
-
const licenseStr = licenseText[pkg.license];
|
|
624
|
-
if (licenseStr !== undefined) {
|
|
625
|
-
pkg.license_text = licenseStr;
|
|
626
|
-
}
|
|
627
|
-
return pkg;
|
|
628
|
-
}
|
|
629
|
-
createSbomDict(sbomArtifacts) {
|
|
630
|
-
const packages = {};
|
|
631
|
-
const topLevelCount = {};
|
|
632
|
-
for (const sbomArtifact of sbomArtifacts) {
|
|
633
|
-
let pkg = new Package({
|
|
634
|
-
type: sbomArtifact.type,
|
|
635
|
-
name: sbomArtifact.name,
|
|
636
|
-
version: sbomArtifact.version,
|
|
637
|
-
release: sbomArtifact.release,
|
|
638
|
-
id: sbomArtifact.id,
|
|
639
|
-
direct: sbomArtifact.direct,
|
|
640
|
-
manifestFiles: sbomArtifact.manifestFiles,
|
|
641
|
-
author: sbomArtifact.author,
|
|
642
|
-
size: sbomArtifact.size,
|
|
643
|
-
score: sbomArtifact.score,
|
|
644
|
-
alerts: sbomArtifact.alerts,
|
|
645
|
-
topLevelAncestors: sbomArtifact.topLevelAncestors,
|
|
646
|
-
license: sbomArtifact.license
|
|
647
|
-
});
|
|
648
|
-
if (pkg.id in packages) {
|
|
649
|
-
logger.logger.log('Duplicate package?');
|
|
650
|
-
} else {
|
|
651
|
-
pkg = this.getLicenseDetails({
|
|
652
|
-
package: pkg
|
|
653
|
-
});
|
|
654
|
-
packages[pkg.id] = pkg;
|
|
655
|
-
for (const topId in sbomArtifact.topLevelAncestors ?? []) {
|
|
656
|
-
if (!(topId in topLevelCount)) {
|
|
657
|
-
topLevelCount[topId] = 1;
|
|
658
|
-
} else {
|
|
659
|
-
topLevelCount[topId] += 1;
|
|
660
|
-
}
|
|
661
|
-
}
|
|
662
|
-
}
|
|
663
|
-
}
|
|
664
|
-
if (Object.keys(topLevelCount).length > 0) {
|
|
665
|
-
for (const packageId in topLevelCount) {
|
|
666
|
-
const pkg = packages[packageId];
|
|
667
|
-
if (pkg) {
|
|
668
|
-
pkg.transitives = topLevelCount[packageId] ?? 0;
|
|
669
|
-
}
|
|
670
|
-
}
|
|
671
|
-
}
|
|
672
|
-
return packages;
|
|
673
|
-
}
|
|
674
|
-
async createNewDiff({
|
|
675
|
-
params = {}
|
|
676
|
-
}) {
|
|
677
|
-
let headFullScanId = '';
|
|
678
|
-
let headFullScan = [];
|
|
679
|
-
try {
|
|
680
|
-
const orgRepoResponse = await this.socket.getOrgRepo(this.owner, this.repo);
|
|
681
|
-
if (orgRepoResponse.success) {
|
|
682
|
-
headFullScanId = orgRepoResponse.data.head_full_scan_id ?? '';
|
|
683
|
-
if (headFullScanId !== '') {
|
|
684
|
-
headFullScan = await this.getSbomData({
|
|
685
|
-
fullScanId: headFullScanId
|
|
686
|
-
});
|
|
687
|
-
}
|
|
688
|
-
}
|
|
689
|
-
} catch (e) {
|
|
690
|
-
logger.logger.error(e);
|
|
691
|
-
}
|
|
692
|
-
const newFullScan = await this.createFullScan({
|
|
693
|
-
params
|
|
694
|
-
});
|
|
695
|
-
newFullScan.packages = this.createSbomDict(newFullScan.sbom_artifacts);
|
|
696
|
-
const diffReport = await this.compareSBOMs({
|
|
697
|
-
newScan: newFullScan.sbom_artifacts,
|
|
698
|
-
headScan: headFullScan
|
|
699
|
-
});
|
|
700
|
-
diffReport.packages = newFullScan.packages;
|
|
701
|
-
const baseSocket = 'https://socket.dev/dashboard/org';
|
|
702
|
-
diffReport.id = newFullScan.id;
|
|
703
|
-
diffReport.reportUrl = `${baseSocket}/${this.owner}/sbom/${diffReport.id}`;
|
|
704
|
-
if (headFullScanId !== '') {
|
|
705
|
-
diffReport.diffUrl = `${baseSocket}/${this.owner}/diff/${diffReport.id}/${headFullScanId}`;
|
|
706
|
-
} else {
|
|
707
|
-
diffReport.diffUrl = diffReport.reportUrl;
|
|
708
|
-
}
|
|
709
|
-
return diffReport;
|
|
710
|
-
}
|
|
711
|
-
}
|
|
712
|
-
|
|
713
|
-
// https://github.com/SocketDev/socket-python-cli/blob/6d4fc56faee68d3a4764f1f80f84710635bdaf05/socketsecurity/core/scm_comments.py
|
|
714
|
-
function checkForSocketComments({
|
|
715
|
-
comments
|
|
716
|
-
}) {
|
|
717
|
-
const socketComments = {
|
|
718
|
-
security: undefined,
|
|
719
|
-
overview: undefined,
|
|
720
|
-
ignore: []
|
|
721
|
-
};
|
|
722
|
-
for (const commentId in comments) {
|
|
723
|
-
const comment = comments[commentId];
|
|
724
|
-
if (comment.body.includes('socket-security-comment-actions')) {
|
|
725
|
-
socketComments.security = comment;
|
|
726
|
-
} else if (comment.body.includes('socket-overview-comment-actions')) {
|
|
727
|
-
socketComments.overview = comment;
|
|
728
|
-
} else if (
|
|
729
|
-
// Based on:
|
|
730
|
-
// To ignore an alert, reply with a comment starting with @SocketSecurity ignore
|
|
731
|
-
// followed by a space separated list of ecosystem/package-name@version specifiers.
|
|
732
|
-
// e.g. @SocketSecurity ignore npm/foo@1.0.0 or ignore all packages with @SocketSecurity ignore-all
|
|
733
|
-
comment.body.split('\n').at(0)?.includes('SocketSecurity ignore')) {
|
|
734
|
-
socketComments.ignore.push(comment);
|
|
735
|
-
}
|
|
736
|
-
}
|
|
737
|
-
return socketComments;
|
|
738
|
-
}
|
|
739
|
-
|
|
740
|
-
// Parses the ignore command
|
|
741
|
-
// @SocketSecurity ignore pkg1 pkg2 ...
|
|
742
|
-
// @SocketSecurity ignore ignore-all
|
|
743
|
-
function parseIgnoreCommand(line) {
|
|
744
|
-
const result = {
|
|
745
|
-
packages: [],
|
|
746
|
-
ignoreAll: false
|
|
747
|
-
};
|
|
748
|
-
const words = line.trim().replace(/\s+/g, ' ').split(' ');
|
|
749
|
-
if (words.at(1) === 'ignore-all') {
|
|
750
|
-
result.ignoreAll = true;
|
|
751
|
-
return result;
|
|
752
|
-
}
|
|
753
|
-
if (words.at(1) === 'ignore') {
|
|
754
|
-
for (let i = 2; i < words.length; i++) {
|
|
755
|
-
const pkg = words[i];
|
|
756
|
-
result.packages.push(pkg);
|
|
757
|
-
}
|
|
758
|
-
return result;
|
|
759
|
-
}
|
|
760
|
-
return result;
|
|
761
|
-
}
|
|
762
|
-
|
|
763
|
-
// Ref: https://github.com/socketdev-demo/javascript-threats/pull/89#issuecomment-2456015512
|
|
764
|
-
function processSecurityComment({
|
|
765
|
-
ignore: ignoreComments,
|
|
766
|
-
security: securityComment
|
|
767
|
-
}) {
|
|
768
|
-
const result = [];
|
|
769
|
-
let start = false;
|
|
770
|
-
let ignoreAll = false;
|
|
771
|
-
const ignoredPackages = [];
|
|
772
|
-
for (const ignoreComment of ignoreComments) {
|
|
773
|
-
const parsed = parseIgnoreCommand(ignoreComment.body?.split('\n').at(0) ?? '');
|
|
774
|
-
if (parsed.ignoreAll) {
|
|
775
|
-
ignoreAll = true;
|
|
776
|
-
break;
|
|
777
|
-
}
|
|
778
|
-
ignoredPackages.push(parsed.packages);
|
|
779
|
-
}
|
|
780
|
-
|
|
781
|
-
// Split the comment body into lines and update them
|
|
782
|
-
// to generate a new comment body
|
|
783
|
-
for (let line of securityComment?.body?.split('\n') ?? []) {
|
|
784
|
-
line = line.trim();
|
|
785
|
-
if (line.includes('start-socket-alerts-table')) {
|
|
786
|
-
start = true;
|
|
787
|
-
result.push(line);
|
|
788
|
-
} else if (start && !line.includes('end-socket-alerts-table') &&
|
|
789
|
-
// is not heading line?
|
|
790
|
-
!(line === '|Alert|Package|Introduced by|Manifest File|CI|' || line.includes(':---')) && line !== '') {
|
|
791
|
-
// Parsing Markdown data colunms
|
|
792
|
-
const [_, _title, packageLink, _introducedBy, _manifest, _ci] = line.split('|');
|
|
793
|
-
|
|
794
|
-
// Parsing package link [npm/pkg](url)
|
|
795
|
-
const [_ecosystem, pkg] = packageLink.slice(1, packageLink.indexOf(']')).split('/', 2);
|
|
796
|
-
const [pkgName, pkgVersion] = pkg.split('@');
|
|
797
|
-
|
|
798
|
-
// Checking if this package should be ignored
|
|
799
|
-
let ignore = false;
|
|
800
|
-
if (ignoreAll) {
|
|
801
|
-
ignore = true;
|
|
802
|
-
} else {
|
|
803
|
-
for (const [ignoredPkgName, ignorePkgVersion] of ignoredPackages) {
|
|
804
|
-
if (pkgName === ignoredPkgName && (ignorePkgVersion === '*' || pkgVersion === ignorePkgVersion)) {
|
|
805
|
-
ignore = true;
|
|
806
|
-
break;
|
|
807
|
-
}
|
|
808
|
-
}
|
|
809
|
-
}
|
|
810
|
-
if (ignore) {
|
|
811
|
-
break;
|
|
812
|
-
}
|
|
813
|
-
result.push(line);
|
|
814
|
-
} else if (line.includes('end-socket-alerts-table')) {
|
|
815
|
-
start = false;
|
|
816
|
-
result.push(line);
|
|
817
|
-
} else {
|
|
818
|
-
result.push(line);
|
|
819
|
-
}
|
|
820
|
-
}
|
|
821
|
-
return result.join('\n');
|
|
822
|
-
}
|
|
823
|
-
function getIgnoreOptions({
|
|
824
|
-
comments
|
|
825
|
-
}) {
|
|
826
|
-
const ignoreCommands = [];
|
|
827
|
-
let ignoreAll = false;
|
|
828
|
-
for (const comment of comments.ignore) {
|
|
829
|
-
let firstLine = comment.body_list[0];
|
|
830
|
-
if (!ignoreAll && firstLine.includes('SocketSecurity ignore')) {
|
|
831
|
-
try {
|
|
832
|
-
firstLine = firstLine.replace(/@/, '');
|
|
833
|
-
let [, command] = firstLine.split('SocketSecurity ');
|
|
834
|
-
command = command.trim();
|
|
835
|
-
if (command === 'ignore-all') {
|
|
836
|
-
ignoreAll = true;
|
|
837
|
-
} else {
|
|
838
|
-
command = command.replace(/ignore/, '').trim();
|
|
839
|
-
const [name, version] = command.split('@');
|
|
840
|
-
const data = `${name}/${version}`;
|
|
841
|
-
ignoreCommands.push(data);
|
|
842
|
-
}
|
|
843
|
-
} catch (e) {
|
|
844
|
-
logger.logger.fail(`Unable to process ignore command for ${comment}`);
|
|
845
|
-
logger.logger.error(e);
|
|
846
|
-
}
|
|
847
|
-
}
|
|
848
|
-
}
|
|
849
|
-
return {
|
|
850
|
-
ignoreAll,
|
|
851
|
-
ignoreCommands
|
|
852
|
-
};
|
|
853
|
-
}
|
|
854
|
-
function removeAlerts({
|
|
855
|
-
comments,
|
|
856
|
-
newAlerts
|
|
857
|
-
}) {
|
|
858
|
-
const alerts = [];
|
|
859
|
-
if (comments.ignore.length === 0) {
|
|
860
|
-
return newAlerts;
|
|
861
|
-
}
|
|
862
|
-
const {
|
|
863
|
-
ignoreAll,
|
|
864
|
-
ignoreCommands
|
|
865
|
-
} = getIgnoreOptions({
|
|
866
|
-
comments
|
|
867
|
-
});
|
|
868
|
-
for (const alert of newAlerts) {
|
|
869
|
-
if (ignoreAll) {
|
|
870
|
-
break;
|
|
871
|
-
} else {
|
|
872
|
-
const fullName = `${alert.pkg_type}/${alert.pkg_name}`;
|
|
873
|
-
const purl = `${fullName}/${alert.pkg_version}`;
|
|
874
|
-
const purlStar = `${fullName}/*`;
|
|
875
|
-
if (ignoreCommands.includes(purl) || ignoreCommands.includes(purlStar)) {
|
|
876
|
-
logger.logger.log(`Alerts for ${alert.pkg_name}@${alert.pkg_version} ignored`);
|
|
877
|
-
} else {
|
|
878
|
-
logger.logger.log(`Adding alert ${alert.type} for ${alert.pkg_name}@${alert.pkg_version}`);
|
|
879
|
-
alerts.push(alert);
|
|
880
|
-
}
|
|
881
|
-
}
|
|
882
|
-
}
|
|
883
|
-
return alerts;
|
|
884
|
-
}
|
|
885
|
-
|
|
886
|
-
// https://github.com/SocketDev/socket-python-cli/blob/6d4fc56faee68d3a4764f1f80f84710635bdaf05/socketsecurity/core/github.py
|
|
887
|
-
/* eslint-disable no-await-in-loop */
|
|
888
|
-
class GitHub {
|
|
889
|
-
octokit = new vendor.Octokit();
|
|
890
|
-
constructor() {
|
|
891
|
-
const [owner = '', repo = ''] = (process.env['GITHUB_REPOSITORY'] ?? '').split('/');
|
|
892
|
-
// https://github.com/actions/checkout/issues/58#issuecomment-2264361099
|
|
893
|
-
const prNumber = parseInt(process.env['GITHUB_REF']?.match(/refs\/pull\/(\d+)\/merge/)?.at(1) ?? '');
|
|
894
|
-
this.owner = owner;
|
|
895
|
-
this.repo = repo;
|
|
896
|
-
this.prNumber = prNumber;
|
|
897
|
-
}
|
|
898
|
-
checkEventType() {
|
|
899
|
-
switch (process.env['GITHUB_EVENT_NAME']) {
|
|
900
|
-
case 'push':
|
|
901
|
-
return this.prNumber ? 'diff' : 'main';
|
|
902
|
-
case 'pull_request':
|
|
903
|
-
{
|
|
904
|
-
// This env variable needs to be set in the GitHub action.
|
|
905
|
-
// Add this code below to GitHub action:
|
|
906
|
-
// - steps:
|
|
907
|
-
// - name: Get PR State
|
|
908
|
-
// if: github.event_name == 'pull_request'
|
|
909
|
-
// run: echo "EVENT_ACTION=${{ github.event.action }}" >> $GITHUB_ENV
|
|
910
|
-
const eventAction = process.env['EVENT_ACTION'];
|
|
911
|
-
if (eventAction === 'opened' || eventAction === 'synchronize') {
|
|
912
|
-
return 'diff';
|
|
913
|
-
}
|
|
914
|
-
if (!eventAction) {
|
|
915
|
-
throw new Error('Missing event action');
|
|
916
|
-
}
|
|
917
|
-
logger.logger.log(`Pull request action: ${eventAction} is not supported`);
|
|
918
|
-
process.exit();
|
|
919
|
-
}
|
|
920
|
-
case 'issue_comment':
|
|
921
|
-
return 'comment';
|
|
922
|
-
default:
|
|
923
|
-
throw new Error(`Unknown event type: ${process.env['GITHUB_EVENT_NAME']}`);
|
|
924
|
-
}
|
|
925
|
-
}
|
|
926
|
-
async getCommentsForPR() {
|
|
927
|
-
const {
|
|
928
|
-
data: githubComments
|
|
929
|
-
} = await this.octokit.rest.issues.listComments({
|
|
930
|
-
owner: this.owner,
|
|
931
|
-
repo: this.repo,
|
|
932
|
-
issue_number: this.prNumber
|
|
933
|
-
});
|
|
934
|
-
const comments = {};
|
|
935
|
-
for (const githubComment of githubComments) {
|
|
936
|
-
comments[githubComment.id] = new Comment({
|
|
937
|
-
id: githubComment.id,
|
|
938
|
-
body: githubComment.body ?? '',
|
|
939
|
-
body_list: (githubComment.body ?? '').split('\n')
|
|
940
|
-
});
|
|
941
|
-
}
|
|
942
|
-
return checkForSocketComments({
|
|
943
|
-
comments
|
|
944
|
-
});
|
|
945
|
-
}
|
|
946
|
-
async commentReactionExists({
|
|
947
|
-
commentId
|
|
948
|
-
}) {
|
|
949
|
-
const {
|
|
950
|
-
data
|
|
951
|
-
} = await this.octokit.reactions.listForIssueComment({
|
|
952
|
-
owner: this.owner,
|
|
953
|
-
repo: this.repo,
|
|
954
|
-
comment_id: commentId
|
|
955
|
-
});
|
|
956
|
-
return data.some(reaction => reaction.content === '+1');
|
|
957
|
-
}
|
|
958
|
-
async postReaction({
|
|
959
|
-
commentId
|
|
960
|
-
}) {
|
|
961
|
-
await this.octokit.reactions.createForIssueComment({
|
|
962
|
-
owner: this.owner,
|
|
963
|
-
repo: this.repo,
|
|
964
|
-
comment_id: commentId,
|
|
965
|
-
content: '+1'
|
|
966
|
-
});
|
|
967
|
-
}
|
|
968
|
-
async handleIgnoreReactons({
|
|
969
|
-
comments
|
|
970
|
-
}) {
|
|
971
|
-
for (const ignoreComment of comments.ignore) {
|
|
972
|
-
if (ignoreComment.body?.includes('SocketSecurity ignore') && !(await this.commentReactionExists({
|
|
973
|
-
commentId: ignoreComment.id
|
|
974
|
-
}))) {
|
|
975
|
-
await this.postReaction({
|
|
976
|
-
commentId: ignoreComment.id
|
|
977
|
-
});
|
|
978
|
-
}
|
|
979
|
-
}
|
|
980
|
-
}
|
|
981
|
-
async updateComment({
|
|
982
|
-
body,
|
|
983
|
-
id
|
|
984
|
-
}) {
|
|
985
|
-
await this.octokit.issues.updateComment({
|
|
986
|
-
owner: this.owner,
|
|
987
|
-
repo: this.repo,
|
|
988
|
-
comment_id: id,
|
|
989
|
-
body
|
|
990
|
-
});
|
|
991
|
-
}
|
|
992
|
-
async removeCommentAlerts({
|
|
993
|
-
comments
|
|
994
|
-
}) {
|
|
995
|
-
const securityAlert = comments.security;
|
|
996
|
-
if (securityAlert !== undefined) {
|
|
997
|
-
const newBody = processSecurityComment({
|
|
998
|
-
security: comments.security,
|
|
999
|
-
ignore: comments.ignore
|
|
1000
|
-
});
|
|
1001
|
-
await this.handleIgnoreReactons({
|
|
1002
|
-
comments
|
|
1003
|
-
});
|
|
1004
|
-
await this.updateComment({
|
|
1005
|
-
id: securityAlert.id,
|
|
1006
|
-
body: newBody
|
|
1007
|
-
});
|
|
1008
|
-
}
|
|
1009
|
-
}
|
|
1010
|
-
async postComment({
|
|
1011
|
-
body
|
|
1012
|
-
}) {
|
|
1013
|
-
await this.octokit.issues.createComment({
|
|
1014
|
-
owner: this.owner,
|
|
1015
|
-
repo: this.repo,
|
|
1016
|
-
issue_number: this.prNumber,
|
|
1017
|
-
body
|
|
1018
|
-
});
|
|
1019
|
-
}
|
|
1020
|
-
async addSocketComments({
|
|
1021
|
-
comments,
|
|
1022
|
-
newOverviewComment,
|
|
1023
|
-
newSecurityComment,
|
|
1024
|
-
overviewComment,
|
|
1025
|
-
securityComment
|
|
1026
|
-
}) {
|
|
1027
|
-
const {
|
|
1028
|
-
overview: existingOverviewComment,
|
|
1029
|
-
security: existingSecurityComment
|
|
1030
|
-
} = comments;
|
|
1031
|
-
if (newOverviewComment) {
|
|
1032
|
-
logger.logger.log('New Dependency Overview comment');
|
|
1033
|
-
if (existingOverviewComment !== undefined) {
|
|
1034
|
-
logger.logger.log('Previous version of Dependency Overview, updating');
|
|
1035
|
-
await this.updateComment({
|
|
1036
|
-
body: overviewComment,
|
|
1037
|
-
id: existingOverviewComment.id
|
|
1038
|
-
});
|
|
1039
|
-
} else {
|
|
1040
|
-
logger.logger.log('No previous version of Dependency Overview, posting');
|
|
1041
|
-
await this.postComment({
|
|
1042
|
-
body: overviewComment
|
|
1043
|
-
});
|
|
1044
|
-
}
|
|
1045
|
-
}
|
|
1046
|
-
if (newSecurityComment) {
|
|
1047
|
-
logger.logger.log('New Security Issue Comment');
|
|
1048
|
-
if (existingSecurityComment !== undefined) {
|
|
1049
|
-
logger.logger.log('Previous version of Security Issue comment, updating');
|
|
1050
|
-
await this.updateComment({
|
|
1051
|
-
body: securityComment,
|
|
1052
|
-
id: existingSecurityComment.id
|
|
1053
|
-
});
|
|
1054
|
-
} else {
|
|
1055
|
-
logger.logger.log('No Previous version of Security Issue comment, posting');
|
|
1056
|
-
await this.postComment({
|
|
1057
|
-
body: securityComment
|
|
1058
|
-
});
|
|
1059
|
-
}
|
|
1060
|
-
}
|
|
1061
|
-
}
|
|
1062
|
-
}
|
|
1063
|
-
|
|
1064
|
-
// https://github.com/SocketDev/socket-python-cli/blob/6d4fc56faee68d3a4764f1f80f84710635bdaf05/socketsecurity/core/messages.py
|
|
1065
|
-
|
|
1066
|
-
function createPurlLink(purl) {
|
|
1067
|
-
const packageUrl = `[${purl.purl}](${purl.url})`;
|
|
1068
|
-
return packageUrl;
|
|
1069
|
-
}
|
|
1070
|
-
function createAddedTable(diff) {
|
|
1071
|
-
const overviewTable = ['Package', 'Direct', 'Capabilities', 'Transitives', 'Size', 'Author'];
|
|
1072
|
-
const rows = [];
|
|
1073
|
-
for (const added of diff.newPackages) {
|
|
1074
|
-
const packageUrl = createPurlLink(added);
|
|
1075
|
-
const capabilities = added.capabilities.join(', ');
|
|
1076
|
-
const row = [packageUrl, added.direct, capabilities, added.transitives, `${added.size} KB`, added.author_url];
|
|
1077
|
-
rows.push(row);
|
|
1078
|
-
}
|
|
1079
|
-
let md = '';
|
|
1080
|
-
md += `|${overviewTable.join('|')}|\n`;
|
|
1081
|
-
md += '|---|---|---|---|---|---|\n';
|
|
1082
|
-
for (const row of rows) {
|
|
1083
|
-
md += `|${row.join('|')}|\n`;
|
|
1084
|
-
}
|
|
1085
|
-
return md;
|
|
1086
|
-
}
|
|
1087
|
-
function createRemoveLine(diff) {
|
|
1088
|
-
const removedLine = ['Removed packages:'];
|
|
1089
|
-
for (const removed of diff.removedPackages) {
|
|
1090
|
-
const packageUrl = createPurlLink(removed);
|
|
1091
|
-
removedLine.push(packageUrl);
|
|
1092
|
-
}
|
|
1093
|
-
return removedLine.join(', ');
|
|
1094
|
-
}
|
|
1095
|
-
function dependencyOverviewTemplate(diff) {
|
|
1096
|
-
let md = '';
|
|
1097
|
-
md += '<!-- socket-overview-comment-actions -->\n';
|
|
1098
|
-
md += '# Socket Security: Dependency Overview\n';
|
|
1099
|
-
md += 'New and removed dependencies detected. Learn more about [socket.dev](https://socket.dev)\n\n';
|
|
1100
|
-
md += createAddedTable(diff);
|
|
1101
|
-
if (diff.removedPackages.length > 0) {
|
|
1102
|
-
md += createRemoveLine(diff);
|
|
1103
|
-
}
|
|
1104
|
-
return md;
|
|
1105
|
-
}
|
|
1106
|
-
function createSources(alert) {
|
|
1107
|
-
const sources = [];
|
|
1108
|
-
const manifests = [];
|
|
1109
|
-
for (const [source, manifest] of alert.introduced_by) {
|
|
1110
|
-
const addStr = `<li>${manifest}</li>`;
|
|
1111
|
-
const sourceStr = `<li>${source}</li>`;
|
|
1112
|
-
if (!sources.includes(sourceStr)) {
|
|
1113
|
-
sources.push(sourceStr);
|
|
1114
|
-
}
|
|
1115
|
-
if (!manifests.includes(addStr)) {
|
|
1116
|
-
manifests.push(addStr);
|
|
1117
|
-
}
|
|
1118
|
-
}
|
|
1119
|
-
const manifestList = manifests.join('');
|
|
1120
|
-
const sourceList = sources.join('');
|
|
1121
|
-
const manifestStr = `<ul>${manifestList}</ul>`;
|
|
1122
|
-
const sourcesStr = `<ul>${sourceList}</ul>`;
|
|
1123
|
-
return [manifestStr, sourcesStr];
|
|
1124
|
-
}
|
|
1125
|
-
function createSecurityAlertTable(diff) {
|
|
1126
|
-
const alertTable = ['Alert', 'Package', 'Introduced by', 'Manifest File', 'CI'];
|
|
1127
|
-
const nextSteps = {};
|
|
1128
|
-
const ignoreCommands = [];
|
|
1129
|
-
const rows = [];
|
|
1130
|
-
for (const alert of diff.newAlerts) {
|
|
1131
|
-
if (!(alert.next_step_title in nextSteps)) {
|
|
1132
|
-
nextSteps[alert.next_step_title] = [alert.description, alert.suggestion];
|
|
1133
|
-
}
|
|
1134
|
-
const ignore = `\`SocketSecurity ignore ${alert.purl}\``;
|
|
1135
|
-
if (!ignoreCommands.includes(ignore)) {
|
|
1136
|
-
ignoreCommands.push(ignore);
|
|
1137
|
-
}
|
|
1138
|
-
const [manifestStr, sourceStr] = createSources(alert);
|
|
1139
|
-
const purlUrl = `[${alert.purl}](${alert.url})`;
|
|
1140
|
-
if (alert.error) {
|
|
1141
|
-
alert.emoji = ':no_entry_sign:';
|
|
1142
|
-
} else {
|
|
1143
|
-
alert.emoji = ':warning:';
|
|
1144
|
-
}
|
|
1145
|
-
const row = [alert.title, purlUrl, sourceStr, manifestStr, alert.emoji];
|
|
1146
|
-
if (!rows.some(r => r.join() === row.join())) {
|
|
1147
|
-
rows.push(row);
|
|
1148
|
-
}
|
|
1149
|
-
}
|
|
1150
|
-
let md = '';
|
|
1151
|
-
md += `|${alertTable.join('|')}|\n`;
|
|
1152
|
-
md += '|---|---|---|---|---|\n';
|
|
1153
|
-
for (const row of rows) {
|
|
1154
|
-
md += `|${row.join('|')}|\n`;
|
|
1155
|
-
}
|
|
1156
|
-
return {
|
|
1157
|
-
ignoreCommands,
|
|
1158
|
-
nextSteps,
|
|
1159
|
-
mdTable: md
|
|
1160
|
-
};
|
|
1161
|
-
}
|
|
1162
|
-
function createNextSteps(nextSteps) {
|
|
1163
|
-
let md = '';
|
|
1164
|
-
for (const step in nextSteps) {
|
|
1165
|
-
const detail = nextSteps[step];
|
|
1166
|
-
md += '<details>\n';
|
|
1167
|
-
md += `<summary>${step}</summary>\n`;
|
|
1168
|
-
for (const line of detail) {
|
|
1169
|
-
md += `${line}\n`;
|
|
1170
|
-
}
|
|
1171
|
-
md += '</details>\n';
|
|
1172
|
-
}
|
|
1173
|
-
return md;
|
|
1174
|
-
}
|
|
1175
|
-
function createDeeperLook() {
|
|
1176
|
-
let md = '';
|
|
1177
|
-
md += '<details>\n';
|
|
1178
|
-
md += '<summary>Take a deeper look at the dependency</summary>\n';
|
|
1179
|
-
md += "Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support [AT] socket [DOT] dev.\n";
|
|
1180
|
-
md += '</details>\n';
|
|
1181
|
-
return md;
|
|
1182
|
-
}
|
|
1183
|
-
function createRemovePackage() {
|
|
1184
|
-
let md = '';
|
|
1185
|
-
md += '<details>\n';
|
|
1186
|
-
md += '<summary>Remove the package</summary>\n';
|
|
1187
|
-
md += 'If you happen to install a dependency that Socket reports as [https://socket.dev/npm/issue/malware](Known Malware) you should immediately remove it and select a different dependency. For other alert types, you may may wish to investigate alternative packages or consider if there are other ways to mitigate the specific risk posed by the dependency.\n';
|
|
1188
|
-
md += '</details>\n';
|
|
1189
|
-
return md;
|
|
1190
|
-
}
|
|
1191
|
-
function createAcceptableRisk(ignoreCommands) {
|
|
1192
|
-
let md = '';
|
|
1193
|
-
md += '<details>\n';
|
|
1194
|
-
md += '<summary>Mark a package as acceptable risk</summary>\n';
|
|
1195
|
-
md += 'To ignore an alert, reply with a comment starting with `SocketSecurity ignore` followed by a space separated list of `ecosystem/package-name@version` specifiers. e.g. `SocketSecurity ignore npm/foo@1.0.0` or ignore all packages with `SocketSecurity ignore-all`\n';
|
|
1196
|
-
md += '<ul>\n';
|
|
1197
|
-
for (const ignore of ignoreCommands) {
|
|
1198
|
-
md += `<li>${ignore}</li>\n`;
|
|
1199
|
-
}
|
|
1200
|
-
md += '</ul>\n';
|
|
1201
|
-
md += '</details>\n';
|
|
1202
|
-
return md;
|
|
1203
|
-
}
|
|
1204
|
-
function securityCommentTemplate(diff) {
|
|
1205
|
-
let md = '';
|
|
1206
|
-
md += '<!-- socket-security-comment-actions -->\n';
|
|
1207
|
-
md += '# Socket Security: Issues Report\n';
|
|
1208
|
-
md += 'Potential security issues detected. Learn more about [socket.dev](https://socket.dev)\n';
|
|
1209
|
-
md += 'To accept the risk, merge this PR and you will not be notified again.\n\n';
|
|
1210
|
-
md += '<!-- start-socket-alerts-table -->\n';
|
|
1211
|
-
const {
|
|
1212
|
-
ignoreCommands,
|
|
1213
|
-
mdTable,
|
|
1214
|
-
nextSteps
|
|
1215
|
-
} = createSecurityAlertTable(diff);
|
|
1216
|
-
md += mdTable;
|
|
1217
|
-
md += '<!-- end-socket-alerts-table -->\n\n';
|
|
1218
|
-
md += createNextSteps(nextSteps);
|
|
1219
|
-
md += createDeeperLook();
|
|
1220
|
-
md += createRemovePackage();
|
|
1221
|
-
md += createAcceptableRisk(ignoreCommands);
|
|
1222
|
-
return md.trim();
|
|
1223
|
-
}
|
|
1224
|
-
|
|
1225
|
-
// https://github.com/SocketDev/socket-python-cli/blob/6d4fc56faee68d3a4764f1f80f84710635bdaf05/socketsecurity/socketcli.py
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
// TODO: is this a github action handler?
|
|
1229
|
-
async function runAction(githubEventBefore, githubEventAfter) {
|
|
1230
|
-
//TODO
|
|
1231
|
-
const socket = new sdk.SocketSdk(shadowNpmInject.getDefaultToken());
|
|
1232
|
-
const git = simpleGit.simpleGit();
|
|
1233
|
-
const changedFiles = (await git.diff(process.env['GITHUB_EVENT_NAME'] === 'pull_request' ? ['--name-only', 'HEAD^1', 'HEAD'] : ['--name-only', githubEventBefore, githubEventAfter])).split('\n');
|
|
1234
|
-
logger.logger.log({
|
|
1235
|
-
changedFiles
|
|
1236
|
-
});
|
|
1237
|
-
// supportedFiles have 3-level deep globs
|
|
1238
|
-
const patterns = Object.values(await socket.getReportSupportedFiles()).flatMap(i => Object.values(i)).flatMap(i => Object.values(i)).flatMap(i => Object.values(i));
|
|
1239
|
-
const files = micromatch(changedFiles, patterns);
|
|
1240
|
-
const scm = new GitHub();
|
|
1241
|
-
if (scm.checkEventType() === 'comment') {
|
|
1242
|
-
logger.logger.log('Comment initiated flow');
|
|
1243
|
-
const comments = await scm.getCommentsForPR();
|
|
1244
|
-
await scm.removeCommentAlerts({
|
|
1245
|
-
comments
|
|
1246
|
-
});
|
|
1247
|
-
} else if (scm.checkEventType() === 'diff') {
|
|
1248
|
-
logger.logger.log('Push initiated flow');
|
|
1249
|
-
const core = new Core({
|
|
1250
|
-
owner: scm.owner,
|
|
1251
|
-
repo: scm.repo,
|
|
1252
|
-
files,
|
|
1253
|
-
socket
|
|
1254
|
-
});
|
|
1255
|
-
const diff = await core.createNewDiff({});
|
|
1256
|
-
const comments = await scm.getCommentsForPR();
|
|
1257
|
-
diff.newAlerts = removeAlerts({
|
|
1258
|
-
comments,
|
|
1259
|
-
newAlerts: diff.newAlerts
|
|
1260
|
-
});
|
|
1261
|
-
const overviewComment = dependencyOverviewTemplate(diff);
|
|
1262
|
-
const securityComment = securityCommentTemplate(diff);
|
|
1263
|
-
let newSecurityComment = true;
|
|
1264
|
-
let newOverviewComment = true;
|
|
1265
|
-
const updateOldSecurityComment = comments.security !== undefined;
|
|
1266
|
-
const updateOldOverviewComment = comments.overview !== undefined;
|
|
1267
|
-
if (diff.newAlerts.length === 0) {
|
|
1268
|
-
if (!updateOldSecurityComment) {
|
|
1269
|
-
newSecurityComment = false;
|
|
1270
|
-
logger.logger.log('No new alerts or security issue comment disabled');
|
|
1271
|
-
} else {
|
|
1272
|
-
logger.logger.log('Updated security comment with no new alerts');
|
|
1273
|
-
}
|
|
1274
|
-
}
|
|
1275
|
-
if (diff.newPackages.length === 0 && diff.removedPackages.length === 0) {
|
|
1276
|
-
if (!updateOldOverviewComment) {
|
|
1277
|
-
newOverviewComment = false;
|
|
1278
|
-
logger.logger.log('No new/removed packages or Dependency Overview comment disabled');
|
|
1279
|
-
} else {
|
|
1280
|
-
logger.logger.log('Updated overview comment with no dependencies');
|
|
1281
|
-
}
|
|
1282
|
-
}
|
|
1283
|
-
await scm.addSocketComments({
|
|
1284
|
-
securityComment,
|
|
1285
|
-
overviewComment,
|
|
1286
|
-
comments,
|
|
1287
|
-
newSecurityComment,
|
|
1288
|
-
newOverviewComment
|
|
1289
|
-
});
|
|
1290
|
-
}
|
|
1291
|
-
}
|
|
1292
|
-
|
|
1293
65
|
const {
|
|
1294
66
|
API_V0_URL
|
|
1295
67
|
} = constants;
|
|
@@ -1323,288 +95,20 @@ async function handleAPIError(code) {
|
|
|
1323
95
|
if (code === 400) {
|
|
1324
96
|
return 'One of the options passed might be incorrect.';
|
|
1325
97
|
} else if (code === 403) {
|
|
1326
|
-
return 'You might be trying to access an organization that is not linked to the API key you are logged in with.';
|
|
1327
|
-
}
|
|
1328
|
-
}
|
|
1329
|
-
function getLastFiveOfApiToken(token) {
|
|
1330
|
-
// Get the last 5 characters of the API token before the trailing "_api".
|
|
1331
|
-
return token.slice(-9, -4);
|
|
1332
|
-
}
|
|
1333
|
-
async function queryAPI(path, apiToken) {
|
|
1334
|
-
return await fetch(`${API_V0_URL}/${path}`, {
|
|
1335
|
-
method: 'GET',
|
|
1336
|
-
headers: {
|
|
1337
|
-
Authorization: `Basic ${btoa(`${apiToken}:${apiToken}`)}`
|
|
1338
|
-
}
|
|
1339
|
-
});
|
|
1340
|
-
}
|
|
1341
|
-
|
|
1342
|
-
function getFlagListOutput(list, indent, {
|
|
1343
|
-
keyPrefix = '--',
|
|
1344
|
-
padName
|
|
1345
|
-
} = {}) {
|
|
1346
|
-
return getHelpListOutput({
|
|
1347
|
-
...list
|
|
1348
|
-
}, indent, {
|
|
1349
|
-
keyPrefix,
|
|
1350
|
-
padName
|
|
1351
|
-
});
|
|
1352
|
-
}
|
|
1353
|
-
function getHelpListOutput(list, indent, {
|
|
1354
|
-
keyPrefix = '',
|
|
1355
|
-
padName = 18
|
|
1356
|
-
} = {}) {
|
|
1357
|
-
let result = '';
|
|
1358
|
-
const names = Object.keys(list).sort();
|
|
1359
|
-
for (const name of names) {
|
|
1360
|
-
const rawDescription = list[name];
|
|
1361
|
-
const description = (typeof rawDescription === 'object' ? rawDescription.description : rawDescription) || '';
|
|
1362
|
-
result += ''.padEnd(indent) + (keyPrefix + name).padEnd(padName) + description + '\n';
|
|
1363
|
-
}
|
|
1364
|
-
return result.trim();
|
|
1365
|
-
}
|
|
1366
|
-
|
|
1367
|
-
// TODO: not sure if I'm missing something but meow doesn't seem to expose this?
|
|
1368
|
-
|
|
1369
|
-
// Note: we use this description in getFlagListOutput, meow doesn't care
|
|
1370
|
-
|
|
1371
|
-
const commonFlags = {
|
|
1372
|
-
help: {
|
|
1373
|
-
type: 'boolean',
|
|
1374
|
-
default: false,
|
|
1375
|
-
shortFlag: 'h',
|
|
1376
|
-
description: 'Print this help.'
|
|
1377
|
-
},
|
|
1378
|
-
dryRun: {
|
|
1379
|
-
type: 'boolean',
|
|
1380
|
-
default: false,
|
|
1381
|
-
description: 'Do input validation for a command and exit 0 when input is ok'
|
|
1382
|
-
}
|
|
1383
|
-
};
|
|
1384
|
-
const outputFlags = {
|
|
1385
|
-
json: {
|
|
1386
|
-
type: 'boolean',
|
|
1387
|
-
shortFlag: 'j',
|
|
1388
|
-
default: false,
|
|
1389
|
-
description: 'Output result as json'
|
|
1390
|
-
},
|
|
1391
|
-
markdown: {
|
|
1392
|
-
type: 'boolean',
|
|
1393
|
-
shortFlag: 'm',
|
|
1394
|
-
default: false,
|
|
1395
|
-
description: 'Output result as markdown'
|
|
1396
|
-
}
|
|
1397
|
-
};
|
|
1398
|
-
const validationFlags = {
|
|
1399
|
-
all: {
|
|
1400
|
-
type: 'boolean',
|
|
1401
|
-
default: false,
|
|
1402
|
-
description: 'Include all issues'
|
|
1403
|
-
},
|
|
1404
|
-
strict: {
|
|
1405
|
-
type: 'boolean',
|
|
1406
|
-
default: false,
|
|
1407
|
-
description: 'Exits with an error code if any matching issues are found'
|
|
1408
|
-
}
|
|
1409
|
-
};
|
|
1410
|
-
|
|
1411
|
-
const {
|
|
1412
|
-
DRY_RUN_LABEL: DRY_RUN_LABEL$1,
|
|
1413
|
-
REDACTED
|
|
1414
|
-
} = constants;
|
|
1415
|
-
async function meowWithSubcommands(subcommands, options) {
|
|
1416
|
-
const {
|
|
1417
|
-
aliases = {},
|
|
1418
|
-
argv,
|
|
1419
|
-
defaultSub,
|
|
1420
|
-
importMeta,
|
|
1421
|
-
name,
|
|
1422
|
-
...additionalOptions
|
|
1423
|
-
} = {
|
|
1424
|
-
__proto__: null,
|
|
1425
|
-
...options
|
|
1426
|
-
};
|
|
1427
|
-
const [commandOrAliasNamex, ...rawCommandArgv] = argv;
|
|
1428
|
-
let commandOrAliasName = commandOrAliasNamex;
|
|
1429
|
-
if (!commandOrAliasName && defaultSub) {
|
|
1430
|
-
commandOrAliasName = defaultSub;
|
|
1431
|
-
}
|
|
1432
|
-
// If we got at least some args, then lets find out if we can find a command.
|
|
1433
|
-
if (commandOrAliasName) {
|
|
1434
|
-
const alias = aliases[commandOrAliasName];
|
|
1435
|
-
// First: Resolve argv data from alias if its an alias that's been given.
|
|
1436
|
-
const [commandName, ...commandArgv] = alias ? [...alias.argv, ...rawCommandArgv] : [commandOrAliasName, ...rawCommandArgv];
|
|
1437
|
-
// Second: Find a command definition using that data.
|
|
1438
|
-
const commandDefinition = commandName ? subcommands[commandName] : undefined;
|
|
1439
|
-
// Third: If a valid command has been found, then we run it...
|
|
1440
|
-
if (commandDefinition) {
|
|
1441
|
-
return await commandDefinition.run(commandArgv, importMeta, {
|
|
1442
|
-
parentName: name
|
|
1443
|
-
});
|
|
1444
|
-
}
|
|
1445
|
-
}
|
|
1446
|
-
const flags = {
|
|
1447
|
-
...commonFlags,
|
|
1448
|
-
...additionalOptions.flags
|
|
1449
|
-
};
|
|
1450
|
-
// ...else we provide basic instructions and help.
|
|
1451
|
-
|
|
1452
|
-
emitBanner(name);
|
|
1453
|
-
const cli = vendor.meow(`
|
|
1454
|
-
Usage
|
|
1455
|
-
$ ${name} <command>
|
|
1456
|
-
|
|
1457
|
-
Commands
|
|
1458
|
-
${getHelpListOutput({
|
|
1459
|
-
...objects.toSortedObject(Object.fromEntries(Object.entries(subcommands).filter(({
|
|
1460
|
-
1: subcommand
|
|
1461
|
-
}) => !subcommand.hidden))),
|
|
1462
|
-
...objects.toSortedObject(Object.fromEntries(Object.entries(aliases).filter(({
|
|
1463
|
-
1: alias
|
|
1464
|
-
}) => {
|
|
1465
|
-
const {
|
|
1466
|
-
hidden
|
|
1467
|
-
} = alias;
|
|
1468
|
-
const cmdName = hidden ? '' : alias.argv[0];
|
|
1469
|
-
const subcommand = cmdName ? subcommands[cmdName] : undefined;
|
|
1470
|
-
return subcommand && !subcommand.hidden;
|
|
1471
|
-
})))
|
|
1472
|
-
}, 6)}
|
|
1473
|
-
|
|
1474
|
-
Options
|
|
1475
|
-
${getFlagListOutput(flags, 6)}
|
|
1476
|
-
|
|
1477
|
-
Examples
|
|
1478
|
-
$ ${name} --help
|
|
1479
|
-
`, {
|
|
1480
|
-
argv,
|
|
1481
|
-
importMeta,
|
|
1482
|
-
...additionalOptions,
|
|
1483
|
-
flags,
|
|
1484
|
-
autoHelp: false // otherwise we can't exit(0)
|
|
1485
|
-
});
|
|
1486
|
-
if (!cli.flags['help'] && cli.flags['dryRun']) {
|
|
1487
|
-
process.exitCode = 0;
|
|
1488
|
-
logger.logger.log(`${DRY_RUN_LABEL$1}: No-op, call a sub-command; ok`);
|
|
1489
|
-
} else {
|
|
1490
|
-
cli.showHelp();
|
|
1491
|
-
}
|
|
1492
|
-
}
|
|
1493
|
-
|
|
1494
|
-
/**
|
|
1495
|
-
* Note: meow will exit immediately if it calls its .showHelp()
|
|
1496
|
-
*/
|
|
1497
|
-
function meowOrExit({
|
|
1498
|
-
allowUnknownFlags,
|
|
1499
|
-
// commands that pass-through args need to allow this
|
|
1500
|
-
argv,
|
|
1501
|
-
config,
|
|
1502
|
-
importMeta,
|
|
1503
|
-
parentName
|
|
1504
|
-
}) {
|
|
1505
|
-
const command = `${parentName} ${config.commandName}`;
|
|
1506
|
-
emitBanner(command);
|
|
1507
|
-
|
|
1508
|
-
// This exits if .printHelp() is called either by meow itself or by us.
|
|
1509
|
-
const cli = vendor.meow({
|
|
1510
|
-
argv,
|
|
1511
|
-
description: config.description,
|
|
1512
|
-
help: config.help(command, config),
|
|
1513
|
-
importMeta,
|
|
1514
|
-
flags: config.flags,
|
|
1515
|
-
allowUnknownFlags: Boolean(allowUnknownFlags),
|
|
1516
|
-
autoHelp: false // otherwise we can't exit(0)
|
|
1517
|
-
});
|
|
1518
|
-
if (cli.flags['help']) {
|
|
1519
|
-
cli.showHelp();
|
|
98
|
+
return 'You might be trying to access an organization that is not linked to the API key you are logged in with.';
|
|
1520
99
|
}
|
|
1521
|
-
return cli;
|
|
1522
|
-
}
|
|
1523
|
-
function emitBanner(name) {
|
|
1524
|
-
// Print a banner at the top of each command.
|
|
1525
|
-
// This helps with brand recognition and marketing.
|
|
1526
|
-
// It also helps with debugging since it contains version and command details.
|
|
1527
|
-
// Note: print over stderr to preserve stdout for flags like --json and
|
|
1528
|
-
// --markdown. If we don't do this, you can't use --json in particular
|
|
1529
|
-
// and pipe the result to other tools. By emitting the banner over stderr
|
|
1530
|
-
// you can do something like `socket scan view xyz | jq | process`.
|
|
1531
|
-
// The spinner also emits over stderr for example.
|
|
1532
|
-
logger.logger.error(getAsciiHeader(name));
|
|
1533
100
|
}
|
|
1534
|
-
function
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
const nodeVersion = process.version;
|
|
1538
|
-
const apiToken = shadowNpmInject.getSetting('apiToken');
|
|
1539
|
-
const shownToken = apiToken ? getLastFiveOfApiToken(apiToken) : 'no';
|
|
1540
|
-
const relCwd = path$1.normalizePath(process.cwd().replace(new RegExp(`^${regexps.escapeRegExp(constants.homePath)}(?:${path.sep}|$)`, 'i'), '~/'));
|
|
1541
|
-
const body = `
|
|
1542
|
-
_____ _ _ /---------------
|
|
1543
|
-
| __|___ ___| |_ ___| |_ | Socket.dev CLI ver ${cliVersion}
|
|
1544
|
-
|__ | . | _| '_| -_| _| | Node: ${nodeVersion}, API token set: ${shownToken}
|
|
1545
|
-
|_____|___|___|_,_|___|_|.dev | Command: \`${command}\`, cwd: ${relCwd}`.trimStart();
|
|
1546
|
-
return ` ${body}\n`;
|
|
101
|
+
function getLastFiveOfApiToken(token) {
|
|
102
|
+
// Get the last 5 characters of the API token before the trailing "_api".
|
|
103
|
+
return token.slice(-9, -4);
|
|
1547
104
|
}
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
} = constants;
|
|
1554
|
-
const config$C = {
|
|
1555
|
-
commandName: 'action',
|
|
1556
|
-
description: 'Socket action command',
|
|
1557
|
-
// GitHub Action ?
|
|
1558
|
-
hidden: true,
|
|
1559
|
-
flags: {
|
|
1560
|
-
// This flag is unused
|
|
1561
|
-
// socketSecurityApiKey: { // deprecate this asap.
|
|
1562
|
-
// type: 'string',
|
|
1563
|
-
// default: 'env var SOCKET_SECURITY_API_KEY',
|
|
1564
|
-
// description: 'Socket API token'
|
|
1565
|
-
// },
|
|
1566
|
-
githubEventBefore: {
|
|
1567
|
-
type: 'string',
|
|
1568
|
-
default: '',
|
|
1569
|
-
description: 'Before marker'
|
|
1570
|
-
},
|
|
1571
|
-
githubEventAfter: {
|
|
1572
|
-
type: 'string',
|
|
1573
|
-
default: '',
|
|
1574
|
-
description: 'After marker'
|
|
105
|
+
async function queryAPI(path, apiToken) {
|
|
106
|
+
return await fetch(`${API_V0_URL}/${path}`, {
|
|
107
|
+
method: 'GET',
|
|
108
|
+
headers: {
|
|
109
|
+
Authorization: `Basic ${btoa(`${apiToken}:${apiToken}`)}`
|
|
1575
110
|
}
|
|
1576
|
-
},
|
|
1577
|
-
help: (command, {
|
|
1578
|
-
flags
|
|
1579
|
-
}) => `
|
|
1580
|
-
Usage
|
|
1581
|
-
$ ${command} [options]
|
|
1582
|
-
|
|
1583
|
-
Options
|
|
1584
|
-
${getFlagListOutput(flags, 6)}
|
|
1585
|
-
`
|
|
1586
|
-
};
|
|
1587
|
-
const cmdAction = {
|
|
1588
|
-
description: config$C.description,
|
|
1589
|
-
hidden: config$C.hidden,
|
|
1590
|
-
run: run$C
|
|
1591
|
-
};
|
|
1592
|
-
async function run$C(argv, importMeta, {
|
|
1593
|
-
parentName
|
|
1594
|
-
}) {
|
|
1595
|
-
const cli = meowOrExit({
|
|
1596
|
-
argv,
|
|
1597
|
-
config: config$C,
|
|
1598
|
-
importMeta,
|
|
1599
|
-
parentName
|
|
1600
111
|
});
|
|
1601
|
-
const githubEventBefore = String(cli.flags['githubEventBefore'] || '');
|
|
1602
|
-
const githubEventAfter = String(cli.flags['githubEventAfter'] || '');
|
|
1603
|
-
if (cli.flags['dryRun']) {
|
|
1604
|
-
logger.logger.log(DRY_RUN_BAIL_TEXT$B);
|
|
1605
|
-
return;
|
|
1606
|
-
}
|
|
1607
|
-
await runAction(githubEventBefore, githubEventAfter);
|
|
1608
112
|
}
|
|
1609
113
|
|
|
1610
114
|
async function fetchOrgAnalyticsData(time, spinner, apiToken) {
|
|
@@ -1765,7 +269,7 @@ async function outputAnalyticsWithToken({
|
|
|
1765
269
|
if (!serialized) return;
|
|
1766
270
|
if (filePath && filePath !== '-') {
|
|
1767
271
|
try {
|
|
1768
|
-
await fs
|
|
272
|
+
await fs.writeFile(filePath, serialized, 'utf8');
|
|
1769
273
|
logger.logger.log(`Data successfully written to ${filePath}`);
|
|
1770
274
|
} catch (e) {
|
|
1771
275
|
process.exitCode = 1;
|
|
@@ -1781,7 +285,7 @@ async function outputAnalyticsWithToken({
|
|
|
1781
285
|
const serialized = renderMarkdown(fdata, time, repo);
|
|
1782
286
|
if (filePath && filePath !== '-') {
|
|
1783
287
|
try {
|
|
1784
|
-
await fs
|
|
288
|
+
await fs.writeFile(filePath, serialized, 'utf8');
|
|
1785
289
|
logger.logger.log(`Data successfully written to ${filePath}`);
|
|
1786
290
|
} catch (e) {
|
|
1787
291
|
logger.logger.error(e);
|
|
@@ -1950,10 +454,217 @@ function renderLineCharts(grid, screen, title, coords, data) {
|
|
|
1950
454
|
line.setData([lineData]);
|
|
1951
455
|
}
|
|
1952
456
|
|
|
457
|
+
// TODO: not sure if I'm missing something but meow doesn't seem to expose this?
|
|
458
|
+
|
|
459
|
+
// Note: we use this description in getFlagListOutput, meow doesn't care
|
|
460
|
+
|
|
461
|
+
const commonFlags = {
|
|
462
|
+
help: {
|
|
463
|
+
type: 'boolean',
|
|
464
|
+
default: false,
|
|
465
|
+
shortFlag: 'h',
|
|
466
|
+
description: 'Print this help.'
|
|
467
|
+
},
|
|
468
|
+
dryRun: {
|
|
469
|
+
type: 'boolean',
|
|
470
|
+
default: false,
|
|
471
|
+
description: 'Do input validation for a command and exit 0 when input is ok'
|
|
472
|
+
}
|
|
473
|
+
};
|
|
474
|
+
const outputFlags = {
|
|
475
|
+
json: {
|
|
476
|
+
type: 'boolean',
|
|
477
|
+
shortFlag: 'j',
|
|
478
|
+
default: false,
|
|
479
|
+
description: 'Output result as json'
|
|
480
|
+
},
|
|
481
|
+
markdown: {
|
|
482
|
+
type: 'boolean',
|
|
483
|
+
shortFlag: 'm',
|
|
484
|
+
default: false,
|
|
485
|
+
description: 'Output result as markdown'
|
|
486
|
+
}
|
|
487
|
+
};
|
|
488
|
+
const validationFlags = {
|
|
489
|
+
all: {
|
|
490
|
+
type: 'boolean',
|
|
491
|
+
default: false,
|
|
492
|
+
description: 'Include all issues'
|
|
493
|
+
},
|
|
494
|
+
strict: {
|
|
495
|
+
type: 'boolean',
|
|
496
|
+
default: false,
|
|
497
|
+
description: 'Exits with an error code if any matching issues are found'
|
|
498
|
+
}
|
|
499
|
+
};
|
|
500
|
+
|
|
501
|
+
function getFlagListOutput(list, indent, {
|
|
502
|
+
keyPrefix = '--',
|
|
503
|
+
padName
|
|
504
|
+
} = {}) {
|
|
505
|
+
return getHelpListOutput({
|
|
506
|
+
...list
|
|
507
|
+
}, indent, {
|
|
508
|
+
keyPrefix,
|
|
509
|
+
padName
|
|
510
|
+
});
|
|
511
|
+
}
|
|
512
|
+
function getHelpListOutput(list, indent, {
|
|
513
|
+
keyPrefix = '',
|
|
514
|
+
padName = 18
|
|
515
|
+
} = {}) {
|
|
516
|
+
let result = '';
|
|
517
|
+
const names = Object.keys(list).sort();
|
|
518
|
+
for (const name of names) {
|
|
519
|
+
const rawDescription = list[name];
|
|
520
|
+
const description = (typeof rawDescription === 'object' ? rawDescription.description : rawDescription) || '';
|
|
521
|
+
result += ''.padEnd(indent) + (keyPrefix + name).padEnd(padName) + description + '\n';
|
|
522
|
+
}
|
|
523
|
+
return result.trim();
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
const {
|
|
527
|
+
DRY_RUN_LABEL: DRY_RUN_LABEL$1,
|
|
528
|
+
REDACTED
|
|
529
|
+
} = constants;
|
|
530
|
+
async function meowWithSubcommands(subcommands, options) {
|
|
531
|
+
const {
|
|
532
|
+
aliases = {},
|
|
533
|
+
argv,
|
|
534
|
+
defaultSub,
|
|
535
|
+
importMeta,
|
|
536
|
+
name,
|
|
537
|
+
...additionalOptions
|
|
538
|
+
} = {
|
|
539
|
+
__proto__: null,
|
|
540
|
+
...options
|
|
541
|
+
};
|
|
542
|
+
const [commandOrAliasNamex, ...rawCommandArgv] = argv;
|
|
543
|
+
let commandOrAliasName = commandOrAliasNamex;
|
|
544
|
+
if (!commandOrAliasName && defaultSub) {
|
|
545
|
+
commandOrAliasName = defaultSub;
|
|
546
|
+
}
|
|
547
|
+
// If we got at least some args, then lets find out if we can find a command.
|
|
548
|
+
if (commandOrAliasName) {
|
|
549
|
+
const alias = aliases[commandOrAliasName];
|
|
550
|
+
// First: Resolve argv data from alias if its an alias that's been given.
|
|
551
|
+
const [commandName, ...commandArgv] = alias ? [...alias.argv, ...rawCommandArgv] : [commandOrAliasName, ...rawCommandArgv];
|
|
552
|
+
// Second: Find a command definition using that data.
|
|
553
|
+
const commandDefinition = commandName ? subcommands[commandName] : undefined;
|
|
554
|
+
// Third: If a valid command has been found, then we run it...
|
|
555
|
+
if (commandDefinition) {
|
|
556
|
+
return await commandDefinition.run(commandArgv, importMeta, {
|
|
557
|
+
parentName: name
|
|
558
|
+
});
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
const flags = {
|
|
562
|
+
...commonFlags,
|
|
563
|
+
...additionalOptions.flags
|
|
564
|
+
};
|
|
565
|
+
// ...else we provide basic instructions and help.
|
|
566
|
+
|
|
567
|
+
emitBanner(name);
|
|
568
|
+
const cli = vendor.meow(`
|
|
569
|
+
Usage
|
|
570
|
+
$ ${name} <command>
|
|
571
|
+
|
|
572
|
+
Commands
|
|
573
|
+
${getHelpListOutput({
|
|
574
|
+
...objects.toSortedObject(Object.fromEntries(Object.entries(subcommands).filter(({
|
|
575
|
+
1: subcommand
|
|
576
|
+
}) => !subcommand.hidden))),
|
|
577
|
+
...objects.toSortedObject(Object.fromEntries(Object.entries(aliases).filter(({
|
|
578
|
+
1: alias
|
|
579
|
+
}) => {
|
|
580
|
+
const {
|
|
581
|
+
hidden
|
|
582
|
+
} = alias;
|
|
583
|
+
const cmdName = hidden ? '' : alias.argv[0];
|
|
584
|
+
const subcommand = cmdName ? subcommands[cmdName] : undefined;
|
|
585
|
+
return subcommand && !subcommand.hidden;
|
|
586
|
+
})))
|
|
587
|
+
}, 6)}
|
|
588
|
+
|
|
589
|
+
Options
|
|
590
|
+
${getFlagListOutput(flags, 6)}
|
|
591
|
+
|
|
592
|
+
Examples
|
|
593
|
+
$ ${name} --help
|
|
594
|
+
`, {
|
|
595
|
+
argv,
|
|
596
|
+
importMeta,
|
|
597
|
+
...additionalOptions,
|
|
598
|
+
flags,
|
|
599
|
+
autoHelp: false // otherwise we can't exit(0)
|
|
600
|
+
});
|
|
601
|
+
if (!cli.flags['help'] && cli.flags['dryRun']) {
|
|
602
|
+
process.exitCode = 0;
|
|
603
|
+
logger.logger.log(`${DRY_RUN_LABEL$1}: No-op, call a sub-command; ok`);
|
|
604
|
+
} else {
|
|
605
|
+
cli.showHelp();
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
/**
|
|
610
|
+
* Note: meow will exit immediately if it calls its .showHelp()
|
|
611
|
+
*/
|
|
612
|
+
function meowOrExit({
|
|
613
|
+
allowUnknownFlags,
|
|
614
|
+
// commands that pass-through args need to allow this
|
|
615
|
+
argv,
|
|
616
|
+
config,
|
|
617
|
+
importMeta,
|
|
618
|
+
parentName
|
|
619
|
+
}) {
|
|
620
|
+
const command = `${parentName} ${config.commandName}`;
|
|
621
|
+
emitBanner(command);
|
|
622
|
+
|
|
623
|
+
// This exits if .printHelp() is called either by meow itself or by us.
|
|
624
|
+
const cli = vendor.meow({
|
|
625
|
+
argv,
|
|
626
|
+
description: config.description,
|
|
627
|
+
help: config.help(command, config),
|
|
628
|
+
importMeta,
|
|
629
|
+
flags: config.flags,
|
|
630
|
+
allowUnknownFlags: Boolean(allowUnknownFlags),
|
|
631
|
+
autoHelp: false // otherwise we can't exit(0)
|
|
632
|
+
});
|
|
633
|
+
if (cli.flags['help']) {
|
|
634
|
+
cli.showHelp();
|
|
635
|
+
}
|
|
636
|
+
return cli;
|
|
637
|
+
}
|
|
638
|
+
function emitBanner(name) {
|
|
639
|
+
// Print a banner at the top of each command.
|
|
640
|
+
// This helps with brand recognition and marketing.
|
|
641
|
+
// It also helps with debugging since it contains version and command details.
|
|
642
|
+
// Note: print over stderr to preserve stdout for flags like --json and
|
|
643
|
+
// --markdown. If we don't do this, you can't use --json in particular
|
|
644
|
+
// and pipe the result to other tools. By emitting the banner over stderr
|
|
645
|
+
// you can do something like `socket scan view xyz | jq | process`.
|
|
646
|
+
// The spinner also emits over stderr for example.
|
|
647
|
+
logger.logger.error(getAsciiHeader(name));
|
|
648
|
+
}
|
|
649
|
+
function getAsciiHeader(command) {
|
|
650
|
+
const cliVersion = // The '@rollup/plugin-replace' will replace "process.env['INLINED_SOCKET_CLI_VERSION_HASH']".
|
|
651
|
+
"0.14.63:988a495:f94aacd0:pub";
|
|
652
|
+
const nodeVersion = process.version;
|
|
653
|
+
const apiToken = shadowNpmInject.getSetting('apiToken');
|
|
654
|
+
const shownToken = apiToken ? getLastFiveOfApiToken(apiToken) : 'no';
|
|
655
|
+
const relCwd = path.normalizePath(process.cwd().replace(new RegExp(`^${regexps.escapeRegExp(constants.homePath)}(?:${path$1.sep}|$)`, 'i'), '~/'));
|
|
656
|
+
const body = `
|
|
657
|
+
_____ _ _ /---------------
|
|
658
|
+
| __|___ ___| |_ ___| |_ | Socket.dev CLI ver ${cliVersion}
|
|
659
|
+
|__ | . | _| '_| -_| _| | Node: ${nodeVersion}, API token set: ${shownToken}
|
|
660
|
+
|_____|___|___|_,_|___|_|.dev | Command: \`${command}\`, cwd: ${relCwd}`.trimStart();
|
|
661
|
+
return ` ${body}\n`;
|
|
662
|
+
}
|
|
663
|
+
|
|
1953
664
|
const {
|
|
1954
|
-
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$
|
|
665
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$B
|
|
1955
666
|
} = constants;
|
|
1956
|
-
const config$
|
|
667
|
+
const config$C = {
|
|
1957
668
|
commandName: 'analytics',
|
|
1958
669
|
description: `Look up analytics data`,
|
|
1959
670
|
hidden: false,
|
|
@@ -2004,16 +715,16 @@ const config$B = {
|
|
|
2004
715
|
`
|
|
2005
716
|
};
|
|
2006
717
|
const cmdAnalytics = {
|
|
2007
|
-
description: config$
|
|
2008
|
-
hidden: config$
|
|
2009
|
-
run: run$
|
|
718
|
+
description: config$C.description,
|
|
719
|
+
hidden: config$C.hidden,
|
|
720
|
+
run: run$C
|
|
2010
721
|
};
|
|
2011
|
-
async function run$
|
|
722
|
+
async function run$C(argv, importMeta, {
|
|
2012
723
|
parentName
|
|
2013
724
|
}) {
|
|
2014
725
|
const cli = meowOrExit({
|
|
2015
726
|
argv,
|
|
2016
|
-
config: config$
|
|
727
|
+
config: config$C,
|
|
2017
728
|
importMeta,
|
|
2018
729
|
parentName
|
|
2019
730
|
});
|
|
@@ -2050,7 +761,7 @@ async function run$B(argv, importMeta, {
|
|
|
2050
761
|
return;
|
|
2051
762
|
}
|
|
2052
763
|
if (cli.flags['dryRun']) {
|
|
2053
|
-
logger.logger.log(DRY_RUN_BAIL_TEXT$
|
|
764
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$B);
|
|
2054
765
|
return;
|
|
2055
766
|
}
|
|
2056
767
|
return await displayAnalytics({
|
|
@@ -2183,14 +894,14 @@ async function getAuditLogWithToken({
|
|
|
2183
894
|
spinner.start(`Looking up audit log for ${orgSlug}`);
|
|
2184
895
|
const socketSdk = await shadowNpmInject.setupSdk(apiToken);
|
|
2185
896
|
const result = await handleApiCall(socketSdk.getAuditLogEvents(orgSlug, {
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
897
|
+
// I'm not sure this is used at all.
|
|
898
|
+
outputJson: String(outputKind === 'json'),
|
|
899
|
+
// I'm not sure this is used at all.
|
|
900
|
+
outputMarkdown: String(outputKind === 'markdown'),
|
|
2190
901
|
orgSlug,
|
|
2191
902
|
type: logType,
|
|
2192
|
-
page,
|
|
2193
|
-
per_page: perPage
|
|
903
|
+
page: String(page),
|
|
904
|
+
per_page: String(perPage)
|
|
2194
905
|
}), `Looking up audit log for ${orgSlug}\n`);
|
|
2195
906
|
if (!result.success) {
|
|
2196
907
|
handleUnsuccessfulApiResponse('getAuditLogEvents', result);
|
|
@@ -2201,9 +912,9 @@ async function getAuditLogWithToken({
|
|
|
2201
912
|
}
|
|
2202
913
|
|
|
2203
914
|
const {
|
|
2204
|
-
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$
|
|
915
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$A
|
|
2205
916
|
} = constants;
|
|
2206
|
-
const config$
|
|
917
|
+
const config$B = {
|
|
2207
918
|
commandName: 'audit-log',
|
|
2208
919
|
description: 'Look up the audit log for an organization',
|
|
2209
920
|
hidden: false,
|
|
@@ -2244,16 +955,16 @@ const config$A = {
|
|
|
2244
955
|
`
|
|
2245
956
|
};
|
|
2246
957
|
const cmdAuditLog = {
|
|
2247
|
-
description: config$
|
|
2248
|
-
hidden: config$
|
|
2249
|
-
run: run$
|
|
958
|
+
description: config$B.description,
|
|
959
|
+
hidden: config$B.hidden,
|
|
960
|
+
run: run$B
|
|
2250
961
|
};
|
|
2251
|
-
async function run$
|
|
962
|
+
async function run$B(argv, importMeta, {
|
|
2252
963
|
parentName
|
|
2253
964
|
}) {
|
|
2254
965
|
const cli = meowOrExit({
|
|
2255
966
|
argv,
|
|
2256
|
-
config: config$
|
|
967
|
+
config: config$B,
|
|
2257
968
|
importMeta,
|
|
2258
969
|
parentName
|
|
2259
970
|
});
|
|
@@ -2278,7 +989,7 @@ async function run$A(argv, importMeta, {
|
|
|
2278
989
|
return;
|
|
2279
990
|
}
|
|
2280
991
|
if (cli.flags['dryRun']) {
|
|
2281
|
-
logger.logger.log(DRY_RUN_BAIL_TEXT$
|
|
992
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$A);
|
|
2282
993
|
return;
|
|
2283
994
|
}
|
|
2284
995
|
await getAuditLog({
|
|
@@ -2309,8 +1020,8 @@ async function runCycloneDX(yargvWithYes) {
|
|
|
2309
1020
|
...yargvWithYes
|
|
2310
1021
|
};
|
|
2311
1022
|
const yesArgs = yes ? ['--yes'] : [];
|
|
2312
|
-
if (yargv.type !== YARN$1 && nodejsPlatformTypes.has(yargv.type) && fs.existsSync(`./${YARN_LOCK}`)) {
|
|
2313
|
-
if (fs.existsSync(`./${PACKAGE_LOCK_JSON}`)) {
|
|
1023
|
+
if (yargv.type !== YARN$1 && nodejsPlatformTypes.has(yargv.type) && fs$1.existsSync(`./${YARN_LOCK}`)) {
|
|
1024
|
+
if (fs$1.existsSync(`./${PACKAGE_LOCK_JSON}`)) {
|
|
2314
1025
|
yargv.type = NPM$f;
|
|
2315
1026
|
} else {
|
|
2316
1027
|
// Use synp to create a package-lock.json from the yarn.lock,
|
|
@@ -2326,14 +1037,14 @@ async function runCycloneDX(yargvWithYes) {
|
|
|
2326
1037
|
}
|
|
2327
1038
|
await shadowBin(NPX$3, [...yesArgs,
|
|
2328
1039
|
// The '@rollup/plugin-replace' will replace "process.env['INLINED_CYCLONEDX_CDXGEN_VERSION']".
|
|
2329
|
-
`@cyclonedx/cdxgen@${"^11.2.
|
|
1040
|
+
`@cyclonedx/cdxgen@${"^11.2.2"}`, ...argvToArray(yargv)]);
|
|
2330
1041
|
if (cleanupPackageLock) {
|
|
2331
1042
|
try {
|
|
2332
|
-
await fs.promises.rm(`./${PACKAGE_LOCK_JSON}`);
|
|
1043
|
+
await fs$1.promises.rm(`./${PACKAGE_LOCK_JSON}`);
|
|
2333
1044
|
} catch {}
|
|
2334
1045
|
}
|
|
2335
|
-
const fullOutputPath = path.join(process$1.cwd(), yargv.output);
|
|
2336
|
-
if (fs.existsSync(fullOutputPath)) {
|
|
1046
|
+
const fullOutputPath = path$1.join(process$1.cwd(), yargv.output);
|
|
1047
|
+
if (fs$1.existsSync(fullOutputPath)) {
|
|
2337
1048
|
logger.logger.log(colors.cyanBright(`${yargv.output} created!`));
|
|
2338
1049
|
}
|
|
2339
1050
|
}
|
|
@@ -2395,7 +1106,7 @@ function isHelpFlag(cmdArg) {
|
|
|
2395
1106
|
|
|
2396
1107
|
// import { meowOrExit } from '../../utils/meow-with-subcommands'
|
|
2397
1108
|
const {
|
|
2398
|
-
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$
|
|
1109
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$z
|
|
2399
1110
|
} = constants;
|
|
2400
1111
|
|
|
2401
1112
|
// TODO: convert yargs to meow. Or convert all the other things to yargs.
|
|
@@ -2472,7 +1183,7 @@ const yargsConfig = {
|
|
|
2472
1183
|
'yes'],
|
|
2473
1184
|
string: ['api-key', 'lifecycle', 'output', 'parent-project-id', 'profile', 'project-group', 'project-name', 'project-version', 'project-id', 'server-host', 'server-port', 'server-url', 'spec-version']
|
|
2474
1185
|
};
|
|
2475
|
-
const config$
|
|
1186
|
+
const config$A = {
|
|
2476
1187
|
commandName: 'cdxgen',
|
|
2477
1188
|
description: 'Create an SBOM with CycloneDX generator (cdxgen)',
|
|
2478
1189
|
hidden: false,
|
|
@@ -2488,18 +1199,18 @@ const config$z = {
|
|
|
2488
1199
|
`
|
|
2489
1200
|
};
|
|
2490
1201
|
const cmdCdxgen = {
|
|
2491
|
-
description: config$
|
|
2492
|
-
hidden: config$
|
|
2493
|
-
run: run$
|
|
1202
|
+
description: config$A.description,
|
|
1203
|
+
hidden: config$A.hidden,
|
|
1204
|
+
run: run$A
|
|
2494
1205
|
};
|
|
2495
|
-
async function run$
|
|
1206
|
+
async function run$A(argv, importMeta, {
|
|
2496
1207
|
parentName
|
|
2497
1208
|
}) {
|
|
2498
1209
|
const cli = meowOrExit({
|
|
2499
1210
|
allowUnknownFlags: true,
|
|
2500
1211
|
// Don't let meow take over --help.
|
|
2501
1212
|
argv: argv.filter(a => !isHelpFlag(a)),
|
|
2502
|
-
config: config$
|
|
1213
|
+
config: config$A,
|
|
2503
1214
|
importMeta,
|
|
2504
1215
|
parentName
|
|
2505
1216
|
});
|
|
@@ -2531,7 +1242,7 @@ async function run$z(argv, importMeta, {
|
|
|
2531
1242
|
return;
|
|
2532
1243
|
}
|
|
2533
1244
|
if (cli.flags['dryRun']) {
|
|
2534
|
-
logger.logger.log(DRY_RUN_BAIL_TEXT$
|
|
1245
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$z);
|
|
2535
1246
|
return;
|
|
2536
1247
|
}
|
|
2537
1248
|
if (yargv.output === undefined) {
|
|
@@ -2598,9 +1309,9 @@ async function findDependencies({
|
|
|
2598
1309
|
}
|
|
2599
1310
|
|
|
2600
1311
|
const {
|
|
2601
|
-
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$
|
|
1312
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$y
|
|
2602
1313
|
} = constants;
|
|
2603
|
-
const config$
|
|
1314
|
+
const config$z = {
|
|
2604
1315
|
commandName: 'dependencies',
|
|
2605
1316
|
description: 'Search for any dependency that is being used in your organization',
|
|
2606
1317
|
hidden: false,
|
|
@@ -2632,21 +1343,21 @@ const config$y = {
|
|
|
2632
1343
|
`
|
|
2633
1344
|
};
|
|
2634
1345
|
const cmdScanCreate$1 = {
|
|
2635
|
-
description: config$
|
|
2636
|
-
hidden: config$
|
|
2637
|
-
run: run$
|
|
1346
|
+
description: config$z.description,
|
|
1347
|
+
hidden: config$z.hidden,
|
|
1348
|
+
run: run$z
|
|
2638
1349
|
};
|
|
2639
|
-
async function run$
|
|
1350
|
+
async function run$z(argv, importMeta, {
|
|
2640
1351
|
parentName
|
|
2641
1352
|
}) {
|
|
2642
1353
|
const cli = meowOrExit({
|
|
2643
1354
|
argv,
|
|
2644
|
-
config: config$
|
|
1355
|
+
config: config$z,
|
|
2645
1356
|
importMeta,
|
|
2646
1357
|
parentName
|
|
2647
1358
|
});
|
|
2648
1359
|
if (cli.flags['dryRun']) {
|
|
2649
|
-
logger.logger.log(DRY_RUN_BAIL_TEXT$
|
|
1360
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$y);
|
|
2650
1361
|
return;
|
|
2651
1362
|
}
|
|
2652
1363
|
|
|
@@ -2721,7 +1432,7 @@ async function getDiffScanWithToken({
|
|
|
2721
1432
|
}
|
|
2722
1433
|
if (file && file !== '-') {
|
|
2723
1434
|
logger.logger.log(`Writing json to \`${file}\``);
|
|
2724
|
-
fs.writeFile(file, JSON.stringify(result, null, 2), err => {
|
|
1435
|
+
fs$1.writeFile(file, JSON.stringify(result, null, 2), err => {
|
|
2725
1436
|
if (err) {
|
|
2726
1437
|
logger.logger.fail(`Writing to \`${file}\` failed...`);
|
|
2727
1438
|
logger.logger.error(err);
|
|
@@ -2754,9 +1465,9 @@ async function getDiffScanWithToken({
|
|
|
2754
1465
|
}
|
|
2755
1466
|
|
|
2756
1467
|
const {
|
|
2757
|
-
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$
|
|
1468
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$x
|
|
2758
1469
|
} = constants;
|
|
2759
|
-
const config$
|
|
1470
|
+
const config$y = {
|
|
2760
1471
|
commandName: 'get',
|
|
2761
1472
|
description: 'Get a diff scan for an organization',
|
|
2762
1473
|
hidden: false,
|
|
@@ -2808,16 +1519,16 @@ const config$x = {
|
|
|
2808
1519
|
`
|
|
2809
1520
|
};
|
|
2810
1521
|
const cmdDiffScanGet = {
|
|
2811
|
-
description: config$
|
|
2812
|
-
hidden: config$
|
|
2813
|
-
run: run$
|
|
1522
|
+
description: config$y.description,
|
|
1523
|
+
hidden: config$y.hidden,
|
|
1524
|
+
run: run$y
|
|
2814
1525
|
};
|
|
2815
|
-
async function run$
|
|
1526
|
+
async function run$y(argv, importMeta, {
|
|
2816
1527
|
parentName
|
|
2817
1528
|
}) {
|
|
2818
1529
|
const cli = meowOrExit({
|
|
2819
1530
|
argv,
|
|
2820
|
-
config: config$
|
|
1531
|
+
config: config$y,
|
|
2821
1532
|
importMeta,
|
|
2822
1533
|
parentName
|
|
2823
1534
|
});
|
|
@@ -2837,7 +1548,7 @@ async function run$x(argv, importMeta, {
|
|
|
2837
1548
|
return;
|
|
2838
1549
|
}
|
|
2839
1550
|
if (cli.flags['dryRun']) {
|
|
2840
|
-
logger.logger.log(DRY_RUN_BAIL_TEXT$
|
|
1551
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$x);
|
|
2841
1552
|
return;
|
|
2842
1553
|
}
|
|
2843
1554
|
await getDiffScan({
|
|
@@ -2850,9 +1561,9 @@ async function run$x(argv, importMeta, {
|
|
|
2850
1561
|
});
|
|
2851
1562
|
}
|
|
2852
1563
|
|
|
2853
|
-
const description$
|
|
1564
|
+
const description$6 = 'Diff scans related commands';
|
|
2854
1565
|
const cmdDiffScan = {
|
|
2855
|
-
description: description$
|
|
1566
|
+
description: description$6,
|
|
2856
1567
|
// Hidden because it was broken all this time (nobody could be using it)
|
|
2857
1568
|
// and we're not sure if it's useful to anyone in its current state.
|
|
2858
1569
|
// Until we do, we'll hide this to keep the help tidier.
|
|
@@ -2865,7 +1576,7 @@ const cmdDiffScan = {
|
|
|
2865
1576
|
get: cmdDiffScanGet
|
|
2866
1577
|
}, {
|
|
2867
1578
|
argv,
|
|
2868
|
-
description: description$
|
|
1579
|
+
description: description$6,
|
|
2869
1580
|
importMeta,
|
|
2870
1581
|
name: parentName + ' diff-scan'
|
|
2871
1582
|
});
|
|
@@ -3299,7 +2010,7 @@ const readLockFileByAgent = (() => {
|
|
|
3299
2010
|
const binaryReader = wrapReader(shadowNpmInject.readFileBinary);
|
|
3300
2011
|
const defaultReader = wrapReader(async lockPath => await shadowNpmInject.readFileUtf8(lockPath));
|
|
3301
2012
|
return new Map([[BUN$5, wrapReader(async (lockPath, agentExecPath) => {
|
|
3302
|
-
const ext = path.extname(lockPath);
|
|
2013
|
+
const ext = path$1.extname(lockPath);
|
|
3303
2014
|
if (ext === LOCK_EXT$1) {
|
|
3304
2015
|
return await defaultReader(lockPath);
|
|
3305
2016
|
}
|
|
@@ -3325,12 +2036,12 @@ async function detectPackageEnvironment({
|
|
|
3325
2036
|
let lockPath = await shadowNpmInject.findUp(Object.keys(LOCKS), {
|
|
3326
2037
|
cwd
|
|
3327
2038
|
});
|
|
3328
|
-
let lockName = lockPath ? path.basename(lockPath) : undefined;
|
|
2039
|
+
let lockName = lockPath ? path$1.basename(lockPath) : undefined;
|
|
3329
2040
|
const isHiddenLockFile = lockName === HIDDEN_PACKAGE_LOCK_JSON;
|
|
3330
|
-
const pkgJsonPath = lockPath ? path.resolve(lockPath, `${isHiddenLockFile ? '../' : ''}../${PACKAGE_JSON}`) : await shadowNpmInject.findUp(PACKAGE_JSON, {
|
|
2041
|
+
const pkgJsonPath = lockPath ? path$1.resolve(lockPath, `${isHiddenLockFile ? '../' : ''}../${PACKAGE_JSON}`) : await shadowNpmInject.findUp(PACKAGE_JSON, {
|
|
3331
2042
|
cwd
|
|
3332
2043
|
});
|
|
3333
|
-
const pkgPath = pkgJsonPath && fs.existsSync(pkgJsonPath) ? path.dirname(pkgJsonPath) : undefined;
|
|
2044
|
+
const pkgPath = pkgJsonPath && fs$1.existsSync(pkgJsonPath) ? path$1.dirname(pkgJsonPath) : undefined;
|
|
3334
2045
|
const editablePkgJson = pkgPath ? await packages.readPackageJson(pkgPath, {
|
|
3335
2046
|
editable: true
|
|
3336
2047
|
}) : undefined;
|
|
@@ -3515,7 +2226,7 @@ async function detectAndValidatePackageEnvironment(cwd, options) {
|
|
|
3515
2226
|
logger?.fail(cmdPrefixMessage(cmdName, `--prod not supported for ${agent}${agentVersion ? `@${agentVersion}` : ''}`));
|
|
3516
2227
|
return;
|
|
3517
2228
|
}
|
|
3518
|
-
if (details.lockPath && path.relative(cwd, details.lockPath).startsWith('.')) {
|
|
2229
|
+
if (details.lockPath && path$1.relative(cwd, details.lockPath).startsWith('.')) {
|
|
3519
2230
|
logger?.warn(cmdPrefixMessage(cmdName, `Package ${lockName} found at ${details.lockPath}`));
|
|
3520
2231
|
}
|
|
3521
2232
|
return details;
|
|
@@ -3557,9 +2268,9 @@ async function runFix() {
|
|
|
3557
2268
|
}
|
|
3558
2269
|
|
|
3559
2270
|
const {
|
|
3560
|
-
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$
|
|
2271
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$w
|
|
3561
2272
|
} = constants;
|
|
3562
|
-
const config$
|
|
2273
|
+
const config$x = {
|
|
3563
2274
|
commandName: 'fix',
|
|
3564
2275
|
description: 'Fix "fixable" Socket alerts',
|
|
3565
2276
|
hidden: true,
|
|
@@ -3575,27 +2286,27 @@ const config$w = {
|
|
|
3575
2286
|
`
|
|
3576
2287
|
};
|
|
3577
2288
|
const cmdFix = {
|
|
3578
|
-
description: config$
|
|
3579
|
-
hidden: config$
|
|
3580
|
-
run: run$
|
|
2289
|
+
description: config$x.description,
|
|
2290
|
+
hidden: config$x.hidden,
|
|
2291
|
+
run: run$x
|
|
3581
2292
|
};
|
|
3582
|
-
async function run$
|
|
2293
|
+
async function run$x(argv, importMeta, {
|
|
3583
2294
|
parentName
|
|
3584
2295
|
}) {
|
|
3585
2296
|
const cli = meowOrExit({
|
|
3586
2297
|
argv,
|
|
3587
|
-
config: config$
|
|
2298
|
+
config: config$x,
|
|
3588
2299
|
importMeta,
|
|
3589
2300
|
parentName
|
|
3590
2301
|
});
|
|
3591
2302
|
if (cli.flags['dryRun']) {
|
|
3592
|
-
logger.logger.log(DRY_RUN_BAIL_TEXT$
|
|
2303
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$w);
|
|
3593
2304
|
return;
|
|
3594
2305
|
}
|
|
3595
2306
|
await runFix();
|
|
3596
2307
|
}
|
|
3597
2308
|
|
|
3598
|
-
async function fetchPackageInfo(pkgName, pkgVersion, includeAllIssues) {
|
|
2309
|
+
async function fetchPackageInfo$1(pkgName, pkgVersion, includeAllIssues) {
|
|
3599
2310
|
const socketSdk = await shadowNpmInject.setupSdk(shadowNpmInject.getPublicToken());
|
|
3600
2311
|
const result = await handleApiCall(socketSdk.getIssuesByNPMPackage(pkgName, pkgVersion), 'looking up package');
|
|
3601
2312
|
const scoreResult = await handleApiCall(socketSdk.getScoreByNPMPackage(pkgName, pkgVersion), 'looking up package score');
|
|
@@ -3616,7 +2327,7 @@ async function fetchPackageInfo(pkgName, pkgVersion, includeAllIssues) {
|
|
|
3616
2327
|
const {
|
|
3617
2328
|
NPM: NPM$9
|
|
3618
2329
|
} = registryConstants;
|
|
3619
|
-
function formatScore(score) {
|
|
2330
|
+
function formatScore$1(score) {
|
|
3620
2331
|
if (score > 80) {
|
|
3621
2332
|
return colors.green(`${score}`);
|
|
3622
2333
|
} else if (score < 80 && score > 60) {
|
|
@@ -3655,7 +2366,7 @@ function logPackageIssuesDetails(packageData, outputMarkdown) {
|
|
|
3655
2366
|
}
|
|
3656
2367
|
}
|
|
3657
2368
|
}
|
|
3658
|
-
function logPackageInfo({
|
|
2369
|
+
function logPackageInfo$1({
|
|
3659
2370
|
data,
|
|
3660
2371
|
score,
|
|
3661
2372
|
severityCount
|
|
@@ -3686,7 +2397,7 @@ function logPackageInfo({
|
|
|
3686
2397
|
License: Math.floor(score.license.score * 100)
|
|
3687
2398
|
};
|
|
3688
2399
|
logger.logger.log('\n');
|
|
3689
|
-
Object.entries(scoreResult).map(score => logger.logger.log(`- ${score[0]}: ${formatScore(score[1])}`));
|
|
2400
|
+
Object.entries(scoreResult).map(score => logger.logger.log(`- ${score[0]}: ${formatScore$1(score[1])}`));
|
|
3690
2401
|
logger.logger.log('\n');
|
|
3691
2402
|
if (objects.hasKeys(severityCount)) {
|
|
3692
2403
|
if (outputKind === 'markdown') {
|
|
@@ -3729,10 +2440,10 @@ async function getPackageInfo({
|
|
|
3729
2440
|
spinner
|
|
3730
2441
|
} = constants;
|
|
3731
2442
|
spinner.start(pkgVersion === 'latest' ? `Looking up data for the latest version of ${pkgName}` : `Looking up data for version ${pkgVersion} of ${pkgName}`);
|
|
3732
|
-
const packageData = await fetchPackageInfo(pkgName, pkgVersion, includeAllIssues);
|
|
2443
|
+
const packageData = await fetchPackageInfo$1(pkgName, pkgVersion, includeAllIssues);
|
|
3733
2444
|
spinner.successAndStop('Data fetched');
|
|
3734
2445
|
if (packageData) {
|
|
3735
|
-
logPackageInfo(packageData, {
|
|
2446
|
+
logPackageInfo$1(packageData, {
|
|
3736
2447
|
name: commandName,
|
|
3737
2448
|
outputKind,
|
|
3738
2449
|
pkgName,
|
|
@@ -3746,9 +2457,9 @@ async function getPackageInfo({
|
|
|
3746
2457
|
}
|
|
3747
2458
|
|
|
3748
2459
|
const {
|
|
3749
|
-
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$
|
|
2460
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$v
|
|
3750
2461
|
} = constants;
|
|
3751
|
-
const config$
|
|
2462
|
+
const config$w = {
|
|
3752
2463
|
commandName: 'info',
|
|
3753
2464
|
description: 'Look up info regarding a package',
|
|
3754
2465
|
hidden: false,
|
|
@@ -3770,16 +2481,16 @@ const config$v = {
|
|
|
3770
2481
|
`
|
|
3771
2482
|
};
|
|
3772
2483
|
const cmdInfo = {
|
|
3773
|
-
description: config$
|
|
3774
|
-
hidden: config$
|
|
3775
|
-
run: run$
|
|
2484
|
+
description: config$w.description,
|
|
2485
|
+
hidden: config$w.hidden,
|
|
2486
|
+
run: run$w
|
|
3776
2487
|
};
|
|
3777
|
-
async function run$
|
|
2488
|
+
async function run$w(argv, importMeta, {
|
|
3778
2489
|
parentName
|
|
3779
2490
|
}) {
|
|
3780
2491
|
const cli = meowOrExit({
|
|
3781
2492
|
argv,
|
|
3782
|
-
config: config$
|
|
2493
|
+
config: config$w,
|
|
3783
2494
|
importMeta,
|
|
3784
2495
|
parentName
|
|
3785
2496
|
});
|
|
@@ -3804,11 +2515,11 @@ async function run$v(argv, importMeta, {
|
|
|
3804
2515
|
const pkgName = versionSeparator < 1 ? rawPkgName : rawPkgName.slice(0, versionSeparator);
|
|
3805
2516
|
const pkgVersion = versionSeparator < 1 ? 'latest' : rawPkgName.slice(versionSeparator + 1);
|
|
3806
2517
|
if (cli.flags['dryRun']) {
|
|
3807
|
-
logger.logger.log(DRY_RUN_BAIL_TEXT$
|
|
2518
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$v);
|
|
3808
2519
|
return;
|
|
3809
2520
|
}
|
|
3810
2521
|
await getPackageInfo({
|
|
3811
|
-
commandName: `${parentName} ${config$
|
|
2522
|
+
commandName: `${parentName} ${config$w.commandName}`,
|
|
3812
2523
|
includeAllIssues: Boolean(all),
|
|
3813
2524
|
outputKind: json ? 'json' : markdown ? 'markdown' : 'print',
|
|
3814
2525
|
pkgName,
|
|
@@ -3895,9 +2606,9 @@ async function attemptLogin(apiBaseUrl, apiProxy) {
|
|
|
3895
2606
|
}
|
|
3896
2607
|
|
|
3897
2608
|
const {
|
|
3898
|
-
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$
|
|
2609
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$u
|
|
3899
2610
|
} = constants;
|
|
3900
|
-
const config$
|
|
2611
|
+
const config$v = {
|
|
3901
2612
|
commandName: 'login',
|
|
3902
2613
|
description: 'Socket API login',
|
|
3903
2614
|
hidden: false,
|
|
@@ -3927,23 +2638,23 @@ const config$u = {
|
|
|
3927
2638
|
`
|
|
3928
2639
|
};
|
|
3929
2640
|
const cmdLogin = {
|
|
3930
|
-
description: config$
|
|
3931
|
-
hidden: config$
|
|
3932
|
-
run: run$
|
|
2641
|
+
description: config$v.description,
|
|
2642
|
+
hidden: config$v.hidden,
|
|
2643
|
+
run: run$v
|
|
3933
2644
|
};
|
|
3934
|
-
async function run$
|
|
2645
|
+
async function run$v(argv, importMeta, {
|
|
3935
2646
|
parentName
|
|
3936
2647
|
}) {
|
|
3937
2648
|
const cli = meowOrExit({
|
|
3938
2649
|
argv,
|
|
3939
|
-
config: config$
|
|
2650
|
+
config: config$v,
|
|
3940
2651
|
importMeta,
|
|
3941
2652
|
parentName
|
|
3942
2653
|
});
|
|
3943
2654
|
const apiBaseUrl = cli.flags['apiBaseUrl'];
|
|
3944
2655
|
const apiProxy = cli.flags['apiProxy'];
|
|
3945
2656
|
if (cli.flags['dryRun']) {
|
|
3946
|
-
logger.logger.log(DRY_RUN_BAIL_TEXT$
|
|
2657
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$u);
|
|
3947
2658
|
return;
|
|
3948
2659
|
}
|
|
3949
2660
|
if (!isInteractive()) {
|
|
@@ -3969,9 +2680,9 @@ function attemptLogout() {
|
|
|
3969
2680
|
}
|
|
3970
2681
|
|
|
3971
2682
|
const {
|
|
3972
|
-
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$
|
|
2683
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$t
|
|
3973
2684
|
} = constants;
|
|
3974
|
-
const config$
|
|
2685
|
+
const config$u = {
|
|
3975
2686
|
commandName: 'logout',
|
|
3976
2687
|
description: 'Socket API logout',
|
|
3977
2688
|
hidden: false,
|
|
@@ -3986,21 +2697,21 @@ const config$t = {
|
|
|
3986
2697
|
`
|
|
3987
2698
|
};
|
|
3988
2699
|
const cmdLogout = {
|
|
3989
|
-
description: config$
|
|
3990
|
-
hidden: config$
|
|
3991
|
-
run: run$
|
|
2700
|
+
description: config$u.description,
|
|
2701
|
+
hidden: config$u.hidden,
|
|
2702
|
+
run: run$u
|
|
3992
2703
|
};
|
|
3993
|
-
async function run$
|
|
2704
|
+
async function run$u(argv, importMeta, {
|
|
3994
2705
|
parentName
|
|
3995
2706
|
}) {
|
|
3996
2707
|
const cli = meowOrExit({
|
|
3997
2708
|
argv,
|
|
3998
|
-
config: config$
|
|
2709
|
+
config: config$u,
|
|
3999
2710
|
importMeta,
|
|
4000
2711
|
parentName
|
|
4001
2712
|
});
|
|
4002
2713
|
if (cli.flags['dryRun']) {
|
|
4003
|
-
logger.logger.log(DRY_RUN_BAIL_TEXT$
|
|
2714
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$t);
|
|
4004
2715
|
return;
|
|
4005
2716
|
}
|
|
4006
2717
|
attemptLogout();
|
|
@@ -4011,8 +2722,8 @@ async function convertGradleToMaven(target, bin, _out, verbose, gradleOpts) {
|
|
|
4011
2722
|
const {
|
|
4012
2723
|
spinner
|
|
4013
2724
|
} = constants;
|
|
4014
|
-
const rbin = path.resolve(bin);
|
|
4015
|
-
const rtarget = path.resolve(target);
|
|
2725
|
+
const rbin = path$1.resolve(bin);
|
|
2726
|
+
const rtarget = path$1.resolve(target);
|
|
4016
2727
|
if (verbose) {
|
|
4017
2728
|
logger.logger.group('gradle2maven:');
|
|
4018
2729
|
logger.logger.log(`[VERBOSE] - Absolute bin path: \`${rbin}\``);
|
|
@@ -4032,7 +2743,7 @@ async function convertGradleToMaven(target, bin, _out, verbose, gradleOpts) {
|
|
|
4032
2743
|
// I'd prefer something plain-text if it is to be committed.
|
|
4033
2744
|
|
|
4034
2745
|
// Note: init.gradle will be exported by .config/rollup.dist.config.mjs
|
|
4035
|
-
const initLocation = path.join(constants.rootDistPath, 'init.gradle');
|
|
2746
|
+
const initLocation = path$1.join(constants.rootDistPath, 'init.gradle');
|
|
4036
2747
|
const commandArgs = ['--init-script', initLocation, ...gradleOpts, 'pom'];
|
|
4037
2748
|
if (verbose) {
|
|
4038
2749
|
logger.logger.log('[VERBOSE] Executing:', bin, commandArgs);
|
|
@@ -4105,9 +2816,9 @@ async function convertGradleToMaven(target, bin, _out, verbose, gradleOpts) {
|
|
|
4105
2816
|
}
|
|
4106
2817
|
|
|
4107
2818
|
const {
|
|
4108
|
-
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$
|
|
2819
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$s
|
|
4109
2820
|
} = constants;
|
|
4110
|
-
const config$
|
|
2821
|
+
const config$t = {
|
|
4111
2822
|
commandName: 'gradle',
|
|
4112
2823
|
description: '[beta] Use Gradle to generate a manifest file (`pom.xml`) for a Gradle/Java/Kotlin/etc project',
|
|
4113
2824
|
hidden: false,
|
|
@@ -4179,22 +2890,22 @@ const config$s = {
|
|
|
4179
2890
|
`
|
|
4180
2891
|
};
|
|
4181
2892
|
const cmdManifestGradle = {
|
|
4182
|
-
description: config$
|
|
4183
|
-
hidden: config$
|
|
4184
|
-
run: run$
|
|
2893
|
+
description: config$t.description,
|
|
2894
|
+
hidden: config$t.hidden,
|
|
2895
|
+
run: run$t
|
|
4185
2896
|
};
|
|
4186
|
-
async function run$
|
|
2897
|
+
async function run$t(argv, importMeta, {
|
|
4187
2898
|
parentName
|
|
4188
2899
|
}) {
|
|
4189
2900
|
const cli = meowOrExit({
|
|
4190
2901
|
argv,
|
|
4191
|
-
config: config$
|
|
2902
|
+
config: config$t,
|
|
4192
2903
|
importMeta,
|
|
4193
2904
|
parentName
|
|
4194
2905
|
});
|
|
4195
2906
|
const verbose = Boolean(cli.flags['verbose']);
|
|
4196
2907
|
if (verbose) {
|
|
4197
|
-
logger.logger.group('- ', parentName, config$
|
|
2908
|
+
logger.logger.group('- ', parentName, config$t.commandName, ':');
|
|
4198
2909
|
logger.logger.group('- flags:', cli.flags);
|
|
4199
2910
|
logger.logger.groupEnd();
|
|
4200
2911
|
logger.logger.log('- input:', cli.input);
|
|
@@ -4221,7 +2932,7 @@ async function run$s(argv, importMeta, {
|
|
|
4221
2932
|
if (cli.flags['bin']) {
|
|
4222
2933
|
bin = cli.flags['bin'];
|
|
4223
2934
|
} else {
|
|
4224
|
-
bin = path.join(target, 'gradlew');
|
|
2935
|
+
bin = path$1.join(target, 'gradlew');
|
|
4225
2936
|
}
|
|
4226
2937
|
let out = './socket.pom.xml';
|
|
4227
2938
|
if (cli.flags['out']) {
|
|
@@ -4242,7 +2953,7 @@ async function run$s(argv, importMeta, {
|
|
|
4242
2953
|
gradleOpts = cli.flags['gradleOpts'].split(' ').map(s => s.trim()).filter(Boolean);
|
|
4243
2954
|
}
|
|
4244
2955
|
if (cli.flags['dryRun']) {
|
|
4245
|
-
logger.logger.log(DRY_RUN_BAIL_TEXT$
|
|
2956
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$s);
|
|
4246
2957
|
return;
|
|
4247
2958
|
}
|
|
4248
2959
|
await convertGradleToMaven(target, bin, out, verbose, gradleOpts);
|
|
@@ -4253,8 +2964,8 @@ async function convertSbtToMaven(target, bin, out, verbose, sbtOpts) {
|
|
|
4253
2964
|
const {
|
|
4254
2965
|
spinner
|
|
4255
2966
|
} = constants;
|
|
4256
|
-
const rbin = path.resolve(bin);
|
|
4257
|
-
const rtarget = path.resolve(target);
|
|
2967
|
+
const rbin = path$1.resolve(bin);
|
|
2968
|
+
const rtarget = path$1.resolve(target);
|
|
4258
2969
|
if (verbose) {
|
|
4259
2970
|
logger.logger.group('sbt2maven:');
|
|
4260
2971
|
logger.logger.log(`[VERBOSE] - Absolute bin path: \`${rbin}\``);
|
|
@@ -4347,9 +3058,9 @@ async function convertSbtToMaven(target, bin, out, verbose, sbtOpts) {
|
|
|
4347
3058
|
}
|
|
4348
3059
|
|
|
4349
3060
|
const {
|
|
4350
|
-
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$
|
|
3061
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$r
|
|
4351
3062
|
} = constants;
|
|
4352
|
-
const config$
|
|
3063
|
+
const config$s = {
|
|
4353
3064
|
commandName: 'scala',
|
|
4354
3065
|
description: "[beta] Generate a manifest file (`pom.xml`) from Scala's `build.sbt` file",
|
|
4355
3066
|
hidden: false,
|
|
@@ -4422,22 +3133,22 @@ const config$r = {
|
|
|
4422
3133
|
`
|
|
4423
3134
|
};
|
|
4424
3135
|
const cmdManifestScala = {
|
|
4425
|
-
description: config$
|
|
4426
|
-
hidden: config$
|
|
4427
|
-
run: run$
|
|
3136
|
+
description: config$s.description,
|
|
3137
|
+
hidden: config$s.hidden,
|
|
3138
|
+
run: run$s
|
|
4428
3139
|
};
|
|
4429
|
-
async function run$
|
|
3140
|
+
async function run$s(argv, importMeta, {
|
|
4430
3141
|
parentName
|
|
4431
3142
|
}) {
|
|
4432
3143
|
const cli = meowOrExit({
|
|
4433
3144
|
argv,
|
|
4434
|
-
config: config$
|
|
3145
|
+
config: config$s,
|
|
4435
3146
|
importMeta,
|
|
4436
3147
|
parentName
|
|
4437
3148
|
});
|
|
4438
3149
|
const verbose = Boolean(cli.flags['verbose']);
|
|
4439
3150
|
if (verbose) {
|
|
4440
|
-
logger.logger.group('- ', parentName, config$
|
|
3151
|
+
logger.logger.group('- ', parentName, config$s.commandName, ':');
|
|
4441
3152
|
logger.logger.group('- flags:', cli.flags);
|
|
4442
3153
|
logger.logger.groupEnd();
|
|
4443
3154
|
logger.logger.log('- input:', cli.input);
|
|
@@ -4483,16 +3194,16 @@ async function run$r(argv, importMeta, {
|
|
|
4483
3194
|
sbtOpts = cli.flags['sbtOpts'].split(' ').map(s => s.trim()).filter(Boolean);
|
|
4484
3195
|
}
|
|
4485
3196
|
if (cli.flags['dryRun']) {
|
|
4486
|
-
logger.logger.log(DRY_RUN_BAIL_TEXT$
|
|
3197
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$r);
|
|
4487
3198
|
return;
|
|
4488
3199
|
}
|
|
4489
3200
|
await convertSbtToMaven(target, bin, out, verbose, sbtOpts);
|
|
4490
3201
|
}
|
|
4491
3202
|
|
|
4492
3203
|
const {
|
|
4493
|
-
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$
|
|
3204
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$q
|
|
4494
3205
|
} = constants;
|
|
4495
|
-
const config$
|
|
3206
|
+
const config$r = {
|
|
4496
3207
|
commandName: 'auto',
|
|
4497
3208
|
description: 'Auto-detect build and attempt to generate manifest file',
|
|
4498
3209
|
hidden: false,
|
|
@@ -4522,23 +3233,23 @@ const config$q = {
|
|
|
4522
3233
|
`
|
|
4523
3234
|
};
|
|
4524
3235
|
const cmdManifestAuto = {
|
|
4525
|
-
description: config$
|
|
4526
|
-
hidden: config$
|
|
4527
|
-
run: run$
|
|
3236
|
+
description: config$r.description,
|
|
3237
|
+
hidden: config$r.hidden,
|
|
3238
|
+
run: run$r
|
|
4528
3239
|
};
|
|
4529
|
-
async function run$
|
|
3240
|
+
async function run$r(argv, importMeta, {
|
|
4530
3241
|
parentName
|
|
4531
3242
|
}) {
|
|
4532
3243
|
const cli = meowOrExit({
|
|
4533
3244
|
argv,
|
|
4534
|
-
config: config$
|
|
3245
|
+
config: config$r,
|
|
4535
3246
|
importMeta,
|
|
4536
3247
|
parentName
|
|
4537
3248
|
});
|
|
4538
3249
|
const verbose = !!cli.flags['verbose'];
|
|
4539
3250
|
const cwd = cli.flags['cwd'] ?? process.cwd();
|
|
4540
3251
|
if (verbose) {
|
|
4541
|
-
logger.logger.group('- ', parentName, config$
|
|
3252
|
+
logger.logger.group('- ', parentName, config$r.commandName, ':');
|
|
4542
3253
|
logger.logger.group('- flags:', cli.flags);
|
|
4543
3254
|
logger.logger.groupEnd();
|
|
4544
3255
|
logger.logger.log('- input:', cli.input);
|
|
@@ -4550,14 +3261,14 @@ async function run$q(argv, importMeta, {
|
|
|
4550
3261
|
subArgs.push('--verbose');
|
|
4551
3262
|
}
|
|
4552
3263
|
const dir = cwd;
|
|
4553
|
-
if (fs.existsSync(path.join(dir, 'build.sbt'))) {
|
|
3264
|
+
if (fs$1.existsSync(path$1.join(dir, 'build.sbt'))) {
|
|
4554
3265
|
logger.logger.log('Detected a Scala sbt build, running default Scala generator...');
|
|
4555
3266
|
if (cwd) {
|
|
4556
3267
|
subArgs.push('--cwd', cwd);
|
|
4557
3268
|
}
|
|
4558
3269
|
subArgs.push(dir);
|
|
4559
3270
|
if (cli.flags['dryRun']) {
|
|
4560
|
-
logger.logger.log(DRY_RUN_BAIL_TEXT$
|
|
3271
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$q);
|
|
4561
3272
|
return;
|
|
4562
3273
|
}
|
|
4563
3274
|
await cmdManifestScala.run(subArgs, importMeta, {
|
|
@@ -4565,14 +3276,14 @@ async function run$q(argv, importMeta, {
|
|
|
4565
3276
|
});
|
|
4566
3277
|
return;
|
|
4567
3278
|
}
|
|
4568
|
-
if (fs.existsSync(path.join(dir, 'gradlew'))) {
|
|
3279
|
+
if (fs$1.existsSync(path$1.join(dir, 'gradlew'))) {
|
|
4569
3280
|
logger.logger.log('Detected a gradle build, running default gradle generator...');
|
|
4570
3281
|
if (cwd) {
|
|
4571
3282
|
// This command takes the cwd as first arg.
|
|
4572
3283
|
subArgs.push(cwd);
|
|
4573
3284
|
}
|
|
4574
3285
|
if (cli.flags['dryRun']) {
|
|
4575
|
-
logger.logger.log(DRY_RUN_BAIL_TEXT$
|
|
3286
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$q);
|
|
4576
3287
|
return;
|
|
4577
3288
|
}
|
|
4578
3289
|
await cmdManifestGradle.run(subArgs, importMeta, {
|
|
@@ -4581,13 +3292,13 @@ async function run$q(argv, importMeta, {
|
|
|
4581
3292
|
return;
|
|
4582
3293
|
}
|
|
4583
3294
|
if (cli.flags['dryRun']) {
|
|
4584
|
-
logger.logger.log(DRY_RUN_BAIL_TEXT$
|
|
3295
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$q);
|
|
4585
3296
|
return;
|
|
4586
3297
|
}
|
|
4587
3298
|
|
|
4588
3299
|
// Show new help screen and exit.
|
|
4589
3300
|
vendor.meow(`
|
|
4590
|
-
$ ${parentName} ${config$
|
|
3301
|
+
$ ${parentName} ${config$r.commandName}
|
|
4591
3302
|
|
|
4592
3303
|
Unfortunately this script did not discover a supported language in the
|
|
4593
3304
|
current folder.
|
|
@@ -4600,13 +3311,13 @@ async function run$q(argv, importMeta, {
|
|
|
4600
3311
|
your target language.
|
|
4601
3312
|
`, {
|
|
4602
3313
|
argv: [],
|
|
4603
|
-
description: config$
|
|
3314
|
+
description: config$r.description,
|
|
4604
3315
|
importMeta
|
|
4605
3316
|
}).showHelp();
|
|
4606
3317
|
}
|
|
4607
3318
|
|
|
4608
3319
|
const {
|
|
4609
|
-
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$
|
|
3320
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$p
|
|
4610
3321
|
} = constants;
|
|
4611
3322
|
|
|
4612
3323
|
// TODO: we may want to dedupe some pieces for all gradle languages. I think it
|
|
@@ -4614,7 +3325,7 @@ const {
|
|
|
4614
3325
|
// sense for the help panels to note the requested language, rather than
|
|
4615
3326
|
// `socket manifest kotlin` to print help screens with `gradle` as the
|
|
4616
3327
|
// command. Room for improvement.
|
|
4617
|
-
const config$
|
|
3328
|
+
const config$q = {
|
|
4618
3329
|
commandName: 'kotlin',
|
|
4619
3330
|
description: '[beta] Use Gradle to generate a manifest file (`pom.xml`) for a Kotlin project',
|
|
4620
3331
|
hidden: false,
|
|
@@ -4686,22 +3397,22 @@ const config$p = {
|
|
|
4686
3397
|
`
|
|
4687
3398
|
};
|
|
4688
3399
|
const cmdManifestKotlin = {
|
|
4689
|
-
description: config$
|
|
4690
|
-
hidden: config$
|
|
4691
|
-
run: run$
|
|
3400
|
+
description: config$q.description,
|
|
3401
|
+
hidden: config$q.hidden,
|
|
3402
|
+
run: run$q
|
|
4692
3403
|
};
|
|
4693
|
-
async function run$
|
|
3404
|
+
async function run$q(argv, importMeta, {
|
|
4694
3405
|
parentName
|
|
4695
3406
|
}) {
|
|
4696
3407
|
const cli = meowOrExit({
|
|
4697
3408
|
argv,
|
|
4698
|
-
config: config$
|
|
3409
|
+
config: config$q,
|
|
4699
3410
|
importMeta,
|
|
4700
3411
|
parentName
|
|
4701
3412
|
});
|
|
4702
3413
|
const verbose = Boolean(cli.flags['verbose']);
|
|
4703
3414
|
if (verbose) {
|
|
4704
|
-
logger.logger.group('- ', parentName, config$
|
|
3415
|
+
logger.logger.group('- ', parentName, config$q.commandName, ':');
|
|
4705
3416
|
logger.logger.group('- flags:', cli.flags);
|
|
4706
3417
|
logger.logger.groupEnd();
|
|
4707
3418
|
logger.logger.log('- input:', cli.input);
|
|
@@ -4728,7 +3439,7 @@ async function run$p(argv, importMeta, {
|
|
|
4728
3439
|
if (cli.flags['bin']) {
|
|
4729
3440
|
bin = cli.flags['bin'];
|
|
4730
3441
|
} else {
|
|
4731
|
-
bin = path.join(target, 'gradlew');
|
|
3442
|
+
bin = path$1.join(target, 'gradlew');
|
|
4732
3443
|
}
|
|
4733
3444
|
let out = './socket.pom.xml';
|
|
4734
3445
|
if (cli.flags['out']) {
|
|
@@ -4749,13 +3460,13 @@ async function run$p(argv, importMeta, {
|
|
|
4749
3460
|
gradleOpts = cli.flags['gradleOpts'].split(' ').map(s => s.trim()).filter(Boolean);
|
|
4750
3461
|
}
|
|
4751
3462
|
if (cli.flags['dryRun']) {
|
|
4752
|
-
logger.logger.log(DRY_RUN_BAIL_TEXT$
|
|
3463
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$p);
|
|
4753
3464
|
return;
|
|
4754
3465
|
}
|
|
4755
3466
|
await convertGradleToMaven(target, bin, out, verbose, gradleOpts);
|
|
4756
3467
|
}
|
|
4757
3468
|
|
|
4758
|
-
const config$
|
|
3469
|
+
const config$p = {
|
|
4759
3470
|
commandName: 'manifest',
|
|
4760
3471
|
description: 'Generate a dependency manifest for given file or dir',
|
|
4761
3472
|
hidden: false,
|
|
@@ -4763,11 +3474,11 @@ const config$o = {
|
|
|
4763
3474
|
...commonFlags
|
|
4764
3475
|
}};
|
|
4765
3476
|
const cmdManifest = {
|
|
4766
|
-
description: config$
|
|
4767
|
-
hidden: config$
|
|
4768
|
-
run: run$
|
|
3477
|
+
description: config$p.description,
|
|
3478
|
+
hidden: config$p.hidden,
|
|
3479
|
+
run: run$p
|
|
4769
3480
|
};
|
|
4770
|
-
async function run$
|
|
3481
|
+
async function run$p(argv, importMeta, {
|
|
4771
3482
|
parentName
|
|
4772
3483
|
}) {
|
|
4773
3484
|
await meowWithSubcommands({
|
|
@@ -4779,15 +3490,15 @@ async function run$o(argv, importMeta, {
|
|
|
4779
3490
|
argv,
|
|
4780
3491
|
aliases: {
|
|
4781
3492
|
yolo: {
|
|
4782
|
-
description: config$
|
|
3493
|
+
description: config$p.description,
|
|
4783
3494
|
hidden: true,
|
|
4784
3495
|
argv: ['auto']
|
|
4785
3496
|
}
|
|
4786
3497
|
},
|
|
4787
|
-
description: config$
|
|
3498
|
+
description: config$p.description,
|
|
4788
3499
|
importMeta,
|
|
4789
|
-
flags: config$
|
|
4790
|
-
name: `${parentName} ${config$
|
|
3500
|
+
flags: config$p.flags,
|
|
3501
|
+
name: `${parentName} ${config$p.commandName}`
|
|
4791
3502
|
});
|
|
4792
3503
|
}
|
|
4793
3504
|
|
|
@@ -4801,10 +3512,10 @@ async function wrapNpm(argv) {
|
|
|
4801
3512
|
}
|
|
4802
3513
|
|
|
4803
3514
|
const {
|
|
4804
|
-
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$
|
|
3515
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$o,
|
|
4805
3516
|
NPM: NPM$7
|
|
4806
3517
|
} = constants;
|
|
4807
|
-
const config$
|
|
3518
|
+
const config$o = {
|
|
4808
3519
|
commandName: 'npm',
|
|
4809
3520
|
description: `${NPM$7} wrapper functionality`,
|
|
4810
3521
|
hidden: false,
|
|
@@ -4815,22 +3526,22 @@ const config$n = {
|
|
|
4815
3526
|
`
|
|
4816
3527
|
};
|
|
4817
3528
|
const cmdNpm = {
|
|
4818
|
-
description: config$
|
|
4819
|
-
hidden: config$
|
|
4820
|
-
run: run$
|
|
3529
|
+
description: config$o.description,
|
|
3530
|
+
hidden: config$o.hidden,
|
|
3531
|
+
run: run$o
|
|
4821
3532
|
};
|
|
4822
|
-
async function run$
|
|
3533
|
+
async function run$o(argv, importMeta, {
|
|
4823
3534
|
parentName
|
|
4824
3535
|
}) {
|
|
4825
3536
|
const cli = meowOrExit({
|
|
4826
3537
|
allowUnknownFlags: true,
|
|
4827
3538
|
argv,
|
|
4828
|
-
config: config$
|
|
3539
|
+
config: config$o,
|
|
4829
3540
|
importMeta,
|
|
4830
3541
|
parentName
|
|
4831
3542
|
});
|
|
4832
3543
|
if (cli.flags['dryRun']) {
|
|
4833
|
-
logger.logger.log(DRY_RUN_BAIL_TEXT$
|
|
3544
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$o);
|
|
4834
3545
|
return;
|
|
4835
3546
|
}
|
|
4836
3547
|
await wrapNpm(argv);
|
|
@@ -4846,10 +3557,10 @@ async function wrapNpx(argv) {
|
|
|
4846
3557
|
}
|
|
4847
3558
|
|
|
4848
3559
|
const {
|
|
4849
|
-
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$
|
|
3560
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$n,
|
|
4850
3561
|
NPX: NPX$1
|
|
4851
3562
|
} = constants;
|
|
4852
|
-
const config$
|
|
3563
|
+
const config$n = {
|
|
4853
3564
|
commandName: 'npx',
|
|
4854
3565
|
description: `${NPX$1} wrapper functionality`,
|
|
4855
3566
|
hidden: false,
|
|
@@ -4860,31 +3571,31 @@ const config$m = {
|
|
|
4860
3571
|
`
|
|
4861
3572
|
};
|
|
4862
3573
|
const cmdNpx = {
|
|
4863
|
-
description: config$
|
|
4864
|
-
hidden: config$
|
|
4865
|
-
run: run$
|
|
3574
|
+
description: config$n.description,
|
|
3575
|
+
hidden: config$n.hidden,
|
|
3576
|
+
run: run$n
|
|
4866
3577
|
};
|
|
4867
|
-
async function run$
|
|
3578
|
+
async function run$n(argv, importMeta, {
|
|
4868
3579
|
parentName
|
|
4869
3580
|
}) {
|
|
4870
3581
|
const cli = meowOrExit({
|
|
4871
3582
|
allowUnknownFlags: true,
|
|
4872
3583
|
argv,
|
|
4873
|
-
config: config$
|
|
3584
|
+
config: config$n,
|
|
4874
3585
|
importMeta,
|
|
4875
3586
|
parentName
|
|
4876
3587
|
});
|
|
4877
3588
|
if (cli.flags['dryRun']) {
|
|
4878
|
-
logger.logger.log(DRY_RUN_BAIL_TEXT$
|
|
3589
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$n);
|
|
4879
3590
|
return;
|
|
4880
3591
|
}
|
|
4881
3592
|
await wrapNpx(argv);
|
|
4882
3593
|
}
|
|
4883
3594
|
|
|
4884
3595
|
const {
|
|
4885
|
-
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$
|
|
3596
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$m
|
|
4886
3597
|
} = constants;
|
|
4887
|
-
const config$
|
|
3598
|
+
const config$m = {
|
|
4888
3599
|
commandName: 'oops',
|
|
4889
3600
|
description: 'Trigger an intentional error (for development)',
|
|
4890
3601
|
hidden: true,
|
|
@@ -4899,21 +3610,21 @@ const config$l = {
|
|
|
4899
3610
|
`
|
|
4900
3611
|
};
|
|
4901
3612
|
const cmdOops = {
|
|
4902
|
-
description: config$
|
|
4903
|
-
hidden: config$
|
|
4904
|
-
run: run$
|
|
3613
|
+
description: config$m.description,
|
|
3614
|
+
hidden: config$m.hidden,
|
|
3615
|
+
run: run$m
|
|
4905
3616
|
};
|
|
4906
|
-
async function run$
|
|
3617
|
+
async function run$m(argv, importMeta, {
|
|
4907
3618
|
parentName
|
|
4908
3619
|
}) {
|
|
4909
3620
|
const cli = meowOrExit({
|
|
4910
3621
|
argv,
|
|
4911
|
-
config: config$
|
|
3622
|
+
config: config$m,
|
|
4912
3623
|
importMeta,
|
|
4913
3624
|
parentName
|
|
4914
3625
|
});
|
|
4915
3626
|
if (cli.flags['dryRun']) {
|
|
4916
|
-
logger.logger.log(DRY_RUN_BAIL_TEXT$
|
|
3627
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$m);
|
|
4917
3628
|
return;
|
|
4918
3629
|
}
|
|
4919
3630
|
throw new Error('This error was intentionally left blank');
|
|
@@ -5032,7 +3743,7 @@ const PNPM_WORKSPACE = `${PNPM$4}-workspace`;
|
|
|
5032
3743
|
async function getWorkspaceGlobs(agent, pkgPath, pkgJson) {
|
|
5033
3744
|
let workspacePatterns;
|
|
5034
3745
|
if (agent === PNPM$4) {
|
|
5035
|
-
for (const workspacePath of [path.join(pkgPath, `${PNPM_WORKSPACE}.yaml`), path.join(pkgPath, `${PNPM_WORKSPACE}.yml`)]) {
|
|
3746
|
+
for (const workspacePath of [path$1.join(pkgPath, `${PNPM_WORKSPACE}.yaml`), path$1.join(pkgPath, `${PNPM_WORKSPACE}.yml`)]) {
|
|
5036
3747
|
// eslint-disable-next-line no-await-in-loop
|
|
5037
3748
|
const yml = await shadowNpmInject.safeReadFile(workspacePath);
|
|
5038
3749
|
if (yml) {
|
|
@@ -5400,7 +4111,7 @@ async function addOverrides(pkgPath, pkgEnvDetails, options) {
|
|
|
5400
4111
|
const {
|
|
5401
4112
|
content: pkgJson
|
|
5402
4113
|
} = editablePkgJson;
|
|
5403
|
-
const workspaceName = path.relative(rootPath, pkgPath);
|
|
4114
|
+
const workspaceName = path$1.relative(rootPath, pkgPath);
|
|
5404
4115
|
const workspaceGlobs = await getWorkspaceGlobs(agent, pkgPath, pkgJson);
|
|
5405
4116
|
const isRoot = pkgPath === rootPath;
|
|
5406
4117
|
const isLockScanned = isRoot && !prod;
|
|
@@ -5534,7 +4245,7 @@ async function addOverrides(pkgPath, pkgEnvDetails, options) {
|
|
|
5534
4245
|
});
|
|
5535
4246
|
// Chunk package names to process them in parallel 3 at a time.
|
|
5536
4247
|
await promises.pEach(workspacePkgJsonPaths, 3, async workspacePkgJsonPath => {
|
|
5537
|
-
const otherState = await addOverrides(path.dirname(workspacePkgJsonPath), pkgEnvDetails, {
|
|
4248
|
+
const otherState = await addOverrides(path$1.dirname(workspacePkgJsonPath), pkgEnvDetails, {
|
|
5538
4249
|
logger,
|
|
5539
4250
|
pin,
|
|
5540
4251
|
prod,
|
|
@@ -5572,7 +4283,7 @@ async function updateLockfile(pkgEnvDetails, options) {
|
|
|
5572
4283
|
__proto__: null,
|
|
5573
4284
|
...options
|
|
5574
4285
|
};
|
|
5575
|
-
const isSpinning = !!spinner?.isSpinning;
|
|
4286
|
+
const isSpinning = !!spinner?.['isSpinning'];
|
|
5576
4287
|
if (!isSpinning) {
|
|
5577
4288
|
spinner?.start();
|
|
5578
4289
|
}
|
|
@@ -5644,9 +4355,9 @@ async function applyOptimization(cwd, pin, prod) {
|
|
|
5644
4355
|
}
|
|
5645
4356
|
|
|
5646
4357
|
const {
|
|
5647
|
-
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$
|
|
4358
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$l
|
|
5648
4359
|
} = constants;
|
|
5649
|
-
const config$
|
|
4360
|
+
const config$l = {
|
|
5650
4361
|
commandName: 'optimize',
|
|
5651
4362
|
description: 'Optimize dependencies with @socketregistry overrides',
|
|
5652
4363
|
hidden: false,
|
|
@@ -5676,22 +4387,22 @@ const config$k = {
|
|
|
5676
4387
|
`
|
|
5677
4388
|
};
|
|
5678
4389
|
const cmdOptimize = {
|
|
5679
|
-
description: config$
|
|
5680
|
-
hidden: config$
|
|
5681
|
-
run: run$
|
|
4390
|
+
description: config$l.description,
|
|
4391
|
+
hidden: config$l.hidden,
|
|
4392
|
+
run: run$l
|
|
5682
4393
|
};
|
|
5683
|
-
async function run$
|
|
4394
|
+
async function run$l(argv, importMeta, {
|
|
5684
4395
|
parentName
|
|
5685
4396
|
}) {
|
|
5686
4397
|
const cli = meowOrExit({
|
|
5687
4398
|
argv,
|
|
5688
|
-
config: config$
|
|
4399
|
+
config: config$l,
|
|
5689
4400
|
importMeta,
|
|
5690
4401
|
parentName
|
|
5691
4402
|
});
|
|
5692
4403
|
const cwd = process$1.cwd();
|
|
5693
4404
|
if (cli.flags['dryRun']) {
|
|
5694
|
-
logger.logger.log(DRY_RUN_BAIL_TEXT$
|
|
4405
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$l);
|
|
5695
4406
|
return;
|
|
5696
4407
|
}
|
|
5697
4408
|
await applyOptimization(cwd, Boolean(cli.flags['pin']), Boolean(cli.flags['prod']));
|
|
@@ -5765,9 +4476,9 @@ async function printOrganizationsFromToken(apiToken, format = 'text') {
|
|
|
5765
4476
|
}
|
|
5766
4477
|
|
|
5767
4478
|
const {
|
|
5768
|
-
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$
|
|
4479
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$k
|
|
5769
4480
|
} = constants;
|
|
5770
|
-
const config$
|
|
4481
|
+
const config$k = {
|
|
5771
4482
|
commandName: 'list',
|
|
5772
4483
|
description: 'List organizations associated with the API key used',
|
|
5773
4484
|
hidden: false,
|
|
@@ -5780,20 +4491,20 @@ const config$j = {
|
|
|
5780
4491
|
$ ${command}
|
|
5781
4492
|
|
|
5782
4493
|
Options
|
|
5783
|
-
${getFlagListOutput(config$
|
|
4494
|
+
${getFlagListOutput(config$k.flags, 6)}
|
|
5784
4495
|
`
|
|
5785
4496
|
};
|
|
5786
4497
|
const cmdOrganizationList = {
|
|
5787
|
-
description: config$
|
|
5788
|
-
hidden: config$
|
|
5789
|
-
run: run$
|
|
4498
|
+
description: config$k.description,
|
|
4499
|
+
hidden: config$k.hidden,
|
|
4500
|
+
run: run$k
|
|
5790
4501
|
};
|
|
5791
|
-
async function run$
|
|
4502
|
+
async function run$k(argv, importMeta, {
|
|
5792
4503
|
parentName
|
|
5793
4504
|
}) {
|
|
5794
4505
|
const cli = meowOrExit({
|
|
5795
4506
|
argv,
|
|
5796
|
-
config: config$
|
|
4507
|
+
config: config$k,
|
|
5797
4508
|
importMeta,
|
|
5798
4509
|
parentName
|
|
5799
4510
|
});
|
|
@@ -5812,7 +4523,7 @@ ${colors.bgRed(colors.white('Input error'))}: Please provide the required fields
|
|
|
5812
4523
|
return;
|
|
5813
4524
|
}
|
|
5814
4525
|
if (cli.flags['dryRun']) {
|
|
5815
|
-
logger.logger.log(DRY_RUN_BAIL_TEXT$
|
|
4526
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$k);
|
|
5816
4527
|
return;
|
|
5817
4528
|
}
|
|
5818
4529
|
await getOrganization(json ? 'json' : markdown ? 'markdown' : 'text');
|
|
@@ -5860,11 +4571,11 @@ async function getSecurityPolicyWithToken(apiToken, orgSlug, format) {
|
|
|
5860
4571
|
}
|
|
5861
4572
|
|
|
5862
4573
|
const {
|
|
5863
|
-
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$
|
|
4574
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$j
|
|
5864
4575
|
} = constants;
|
|
5865
4576
|
|
|
5866
4577
|
// TODO: secret toplevel alias `socket security policy`?
|
|
5867
|
-
const config$
|
|
4578
|
+
const config$j = {
|
|
5868
4579
|
commandName: 'security',
|
|
5869
4580
|
description: 'Retrieve the security policy of an organization.',
|
|
5870
4581
|
hidden: true,
|
|
@@ -5877,7 +4588,7 @@ const config$i = {
|
|
|
5877
4588
|
$ ${command} <org slug>
|
|
5878
4589
|
|
|
5879
4590
|
Options
|
|
5880
|
-
${getFlagListOutput(config$
|
|
4591
|
+
${getFlagListOutput(config$j.flags, 6)}
|
|
5881
4592
|
|
|
5882
4593
|
Your API token will need the \`security-policy:read\` permission otherwise
|
|
5883
4594
|
the request will fail with an authentication error.
|
|
@@ -5888,16 +4599,16 @@ const config$i = {
|
|
|
5888
4599
|
`
|
|
5889
4600
|
};
|
|
5890
4601
|
const cmdOrganizationPolicyPolicy = {
|
|
5891
|
-
description: config$
|
|
5892
|
-
hidden: config$
|
|
5893
|
-
run: run$
|
|
4602
|
+
description: config$j.description,
|
|
4603
|
+
hidden: config$j.hidden,
|
|
4604
|
+
run: run$j
|
|
5894
4605
|
};
|
|
5895
|
-
async function run$
|
|
4606
|
+
async function run$j(argv, importMeta, {
|
|
5896
4607
|
parentName
|
|
5897
4608
|
}) {
|
|
5898
4609
|
const cli = meowOrExit({
|
|
5899
4610
|
argv,
|
|
5900
|
-
config: config$
|
|
4611
|
+
config: config$j,
|
|
5901
4612
|
importMeta,
|
|
5902
4613
|
parentName
|
|
5903
4614
|
});
|
|
@@ -5918,15 +4629,15 @@ ${colors.bgRed(colors.white('Input error'))}: Please provide the required fields
|
|
|
5918
4629
|
return;
|
|
5919
4630
|
}
|
|
5920
4631
|
if (cli.flags['dryRun']) {
|
|
5921
|
-
logger.logger.log(DRY_RUN_BAIL_TEXT$
|
|
4632
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$j);
|
|
5922
4633
|
return;
|
|
5923
4634
|
}
|
|
5924
4635
|
await getSecurityPolicy(orgSlug, json ? 'json' : markdown ? 'markdown' : 'text');
|
|
5925
4636
|
}
|
|
5926
4637
|
|
|
5927
|
-
const description$
|
|
4638
|
+
const description$5 = 'Organization policy details';
|
|
5928
4639
|
const cmdOrganizationPolicy = {
|
|
5929
|
-
description: description$
|
|
4640
|
+
description: description$5,
|
|
5930
4641
|
// Hidden because it was broken all this time (nobody could be using it)
|
|
5931
4642
|
// and we're not sure if it's useful to anyone in its current state.
|
|
5932
4643
|
// Until we do, we'll hide this to keep the help tidier.
|
|
@@ -5939,7 +4650,7 @@ const cmdOrganizationPolicy = {
|
|
|
5939
4650
|
security: cmdOrganizationPolicyPolicy
|
|
5940
4651
|
}, {
|
|
5941
4652
|
argv,
|
|
5942
|
-
description: description$
|
|
4653
|
+
description: description$5,
|
|
5943
4654
|
defaultSub: 'list',
|
|
5944
4655
|
// Backwards compat
|
|
5945
4656
|
importMeta,
|
|
@@ -5990,9 +4701,9 @@ async function getQuotaWithToken(apiToken, format = 'text') {
|
|
|
5990
4701
|
}
|
|
5991
4702
|
|
|
5992
4703
|
const {
|
|
5993
|
-
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$
|
|
4704
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$i
|
|
5994
4705
|
} = constants;
|
|
5995
|
-
const config$
|
|
4706
|
+
const config$i = {
|
|
5996
4707
|
commandName: 'quota',
|
|
5997
4708
|
description: 'List organizations associated with the API key used',
|
|
5998
4709
|
hidden: true,
|
|
@@ -6005,20 +4716,20 @@ const config$h = {
|
|
|
6005
4716
|
$ ${command}
|
|
6006
4717
|
|
|
6007
4718
|
Options
|
|
6008
|
-
${getFlagListOutput(config$
|
|
4719
|
+
${getFlagListOutput(config$i.flags, 6)}
|
|
6009
4720
|
`
|
|
6010
4721
|
};
|
|
6011
4722
|
const cmdOrganizationQuota = {
|
|
6012
|
-
description: config$
|
|
6013
|
-
hidden: config$
|
|
6014
|
-
run: run$
|
|
4723
|
+
description: config$i.description,
|
|
4724
|
+
hidden: config$i.hidden,
|
|
4725
|
+
run: run$i
|
|
6015
4726
|
};
|
|
6016
|
-
async function run$
|
|
4727
|
+
async function run$i(argv, importMeta, {
|
|
6017
4728
|
parentName
|
|
6018
4729
|
}) {
|
|
6019
4730
|
const cli = meowOrExit({
|
|
6020
4731
|
argv,
|
|
6021
|
-
config: config$
|
|
4732
|
+
config: config$i,
|
|
6022
4733
|
importMeta,
|
|
6023
4734
|
parentName
|
|
6024
4735
|
});
|
|
@@ -6037,15 +4748,15 @@ ${colors.bgRed(colors.white('Input error'))}: Please provide the required fields
|
|
|
6037
4748
|
return;
|
|
6038
4749
|
}
|
|
6039
4750
|
if (cli.flags['dryRun']) {
|
|
6040
|
-
logger.logger.log(DRY_RUN_BAIL_TEXT$
|
|
4751
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$i);
|
|
6041
4752
|
return;
|
|
6042
4753
|
}
|
|
6043
4754
|
await getQuota(json ? 'json' : markdown ? 'markdown' : 'text');
|
|
6044
4755
|
}
|
|
6045
4756
|
|
|
6046
|
-
const description$
|
|
4757
|
+
const description$4 = 'Account details';
|
|
6047
4758
|
const cmdOrganization = {
|
|
6048
|
-
description: description$
|
|
4759
|
+
description: description$4,
|
|
6049
4760
|
// Hidden because it was broken all this time (nobody could be using it)
|
|
6050
4761
|
// and we're not sure if it's useful to anyone in its current state.
|
|
6051
4762
|
// Until we do, we'll hide this to keep the help tidier.
|
|
@@ -6060,7 +4771,7 @@ const cmdOrganization = {
|
|
|
6060
4771
|
policy: cmdOrganizationPolicy
|
|
6061
4772
|
}, {
|
|
6062
4773
|
argv,
|
|
6063
|
-
description: description$
|
|
4774
|
+
description: description$4,
|
|
6064
4775
|
defaultSub: 'list',
|
|
6065
4776
|
// Backwards compat
|
|
6066
4777
|
importMeta,
|
|
@@ -6069,6 +4780,298 @@ const cmdOrganization = {
|
|
|
6069
4780
|
}
|
|
6070
4781
|
};
|
|
6071
4782
|
|
|
4783
|
+
// Either an ecosystem was given or all args must be (namespaced) purls
|
|
4784
|
+
// The `pkg:` part is optional here. We'll scan for `eco/name@version`.
|
|
4785
|
+
// Not hardcoding the namespace since we don't know what the server accepts.
|
|
4786
|
+
// The ecosystem is considered as the first package if it is not an a-z string.
|
|
4787
|
+
function parsePackageSpecifiers(ecosystem, pkgs) {
|
|
4788
|
+
let valid = true;
|
|
4789
|
+
const purls = [];
|
|
4790
|
+
if (!ecosystem) {
|
|
4791
|
+
valid = false;
|
|
4792
|
+
} else if (/^[a-zA-Z]+$/.test(ecosystem)) {
|
|
4793
|
+
for (let i = 0; i < pkgs.length; ++i) {
|
|
4794
|
+
const pkg = pkgs[i] ?? '';
|
|
4795
|
+
if (!pkg) {
|
|
4796
|
+
valid = false;
|
|
4797
|
+
break;
|
|
4798
|
+
} else if (pkg.startsWith('pkg:')) {
|
|
4799
|
+
// keep
|
|
4800
|
+
purls.push(pkg);
|
|
4801
|
+
} else if (pkg.includes('/')) {
|
|
4802
|
+
// Looks like this arg was already namespaced
|
|
4803
|
+
purls.push('pkg:' + pkg);
|
|
4804
|
+
} else {
|
|
4805
|
+
purls.push('pkg:' + ecosystem + '/' + pkg);
|
|
4806
|
+
}
|
|
4807
|
+
}
|
|
4808
|
+
if (!purls.length) {
|
|
4809
|
+
valid = false;
|
|
4810
|
+
}
|
|
4811
|
+
} else {
|
|
4812
|
+
// Assume ecosystem is a purl, too
|
|
4813
|
+
pkgs.unshift(ecosystem);
|
|
4814
|
+
for (let i = 0; i < pkgs.length; ++i) {
|
|
4815
|
+
const pkg = pkgs[i] ?? '';
|
|
4816
|
+
if (!/^(?:pkg:)?[a-zA-Z]+\/./.test(pkg)) {
|
|
4817
|
+
// At least one purl did not start with `pkg:eco/x` or `eco/x`
|
|
4818
|
+
valid = false;
|
|
4819
|
+
break;
|
|
4820
|
+
} else if (pkg.startsWith('pkg:')) {
|
|
4821
|
+
purls.push(pkg);
|
|
4822
|
+
} else {
|
|
4823
|
+
purls.push('pkg:' + pkg);
|
|
4824
|
+
}
|
|
4825
|
+
}
|
|
4826
|
+
if (!purls.length) {
|
|
4827
|
+
valid = false;
|
|
4828
|
+
}
|
|
4829
|
+
}
|
|
4830
|
+
return {
|
|
4831
|
+
purls,
|
|
4832
|
+
valid
|
|
4833
|
+
};
|
|
4834
|
+
}
|
|
4835
|
+
|
|
4836
|
+
async function fetchPackageInfo(purls) {
|
|
4837
|
+
const socketSdk = await shadowNpmInject.setupSdk(shadowNpmInject.getPublicToken());
|
|
4838
|
+
|
|
4839
|
+
// Lazily access constants.spinner.
|
|
4840
|
+
const {
|
|
4841
|
+
spinner
|
|
4842
|
+
} = constants;
|
|
4843
|
+
logger.logger.error(`Requesting shallow score data for ${purls.length} package urls (purl): ${purls.join(', ')}`);
|
|
4844
|
+
spinner.start(`Requesting data ...`);
|
|
4845
|
+
const result = await handleApiCall(socketSdk.batchPackageFetch({
|
|
4846
|
+
alerts: 'true'
|
|
4847
|
+
// compact: false,
|
|
4848
|
+
// fixable: false,
|
|
4849
|
+
// licenseattrib: false,
|
|
4850
|
+
// licensedetails: false
|
|
4851
|
+
}, {
|
|
4852
|
+
components: purls.map(purl => ({
|
|
4853
|
+
purl
|
|
4854
|
+
}))
|
|
4855
|
+
}), 'looking up package');
|
|
4856
|
+
spinner.successAndStop('Request completed');
|
|
4857
|
+
if (result.success) {
|
|
4858
|
+
return result;
|
|
4859
|
+
} else {
|
|
4860
|
+
handleUnsuccessfulApiResponse('batchPackageFetch', result);
|
|
4861
|
+
}
|
|
4862
|
+
}
|
|
4863
|
+
|
|
4864
|
+
function logPackageInfo(purls, packageData, outputKind) {
|
|
4865
|
+
if (outputKind === 'json') {
|
|
4866
|
+
// In JSON simply return what the server responds with. Don't bother trying
|
|
4867
|
+
// to match the response with the requested packages/purls.
|
|
4868
|
+
logger.logger.log(JSON.stringify(packageData, undefined, 2));
|
|
4869
|
+
return;
|
|
4870
|
+
}
|
|
4871
|
+
|
|
4872
|
+
// Make some effort to match the requested data with the response
|
|
4873
|
+
|
|
4874
|
+
const set = new Set();
|
|
4875
|
+
packageData.forEach(data => {
|
|
4876
|
+
set.add('pkg:' + data.type + '/' + data.name + '@' + data.version);
|
|
4877
|
+
set.add('pkg:' + data.type + '/' + data.name);
|
|
4878
|
+
});
|
|
4879
|
+
const missing = purls.filter(purl => {
|
|
4880
|
+
if (set.has(purl)) return false;
|
|
4881
|
+
if (purl.endsWith('@latest') && set.has(purl.slice(0, -'@latest'.length))) return false;
|
|
4882
|
+
return true; // not found
|
|
4883
|
+
});
|
|
4884
|
+
if (outputKind === 'markdown') {
|
|
4885
|
+
logger.logger.log(commonTags.stripIndents`
|
|
4886
|
+
# Shallow Package Report
|
|
4887
|
+
|
|
4888
|
+
This report contains the response for requesting data on some package url(s).
|
|
4889
|
+
|
|
4890
|
+
Please note: The listed scores are ONLY for the package itself. It does NOT
|
|
4891
|
+
reflect the scores of any dependencies, transitive or otherwise.
|
|
4892
|
+
|
|
4893
|
+
${missing.length ? `\n## Missing response\n\nAt least one package had no response or the purl was not canonical:\n\n${missing.map(purl => '- ' + purl + '\n').join('')}` : ''}
|
|
4894
|
+
|
|
4895
|
+
${packageData.map(data => '## ' + formatReportCard(data, false)).join('\n\n\n')}
|
|
4896
|
+
`);
|
|
4897
|
+
return;
|
|
4898
|
+
}
|
|
4899
|
+
logger.logger.log('\n' + colors.bold('Shallow Package Score') + '\n');
|
|
4900
|
+
logger.logger.log('Please note: The listed scores are ONLY for the package itself. It does NOT\n' + ' reflect the scores of any dependencies, transitive or otherwise.');
|
|
4901
|
+
if (missing.length) {
|
|
4902
|
+
logger.logger.log(`\nAt least one package had no response or the purl was not canonical:\n${missing.map(purl => '\n- ' + colors.bold(purl)).join('')}`);
|
|
4903
|
+
}
|
|
4904
|
+
packageData.forEach(data => {
|
|
4905
|
+
logger.logger.log('\n');
|
|
4906
|
+
logger.logger.log(formatReportCard(data, true));
|
|
4907
|
+
});
|
|
4908
|
+
logger.logger.log('');
|
|
4909
|
+
}
|
|
4910
|
+
function formatReportCard(data, color) {
|
|
4911
|
+
const scoreResult = {
|
|
4912
|
+
'Supply Chain Risk': Math.floor((data.score?.supplyChain ?? 0) * 100),
|
|
4913
|
+
Maintenance: Math.floor((data.score?.maintenance ?? 0) * 100),
|
|
4914
|
+
Quality: Math.floor((data.score?.quality ?? 0) * 100),
|
|
4915
|
+
Vulnerabilities: Math.floor((data.score?.vulnerability ?? 0) * 100),
|
|
4916
|
+
License: Math.floor((data.score?.license ?? 0) * 100)
|
|
4917
|
+
};
|
|
4918
|
+
const alertString = getAlertString(data.alerts, !color);
|
|
4919
|
+
const purl = 'pkg:' + data.type + '/' + data.name + '@' + data.version;
|
|
4920
|
+
return ['Package: ' + (color ? colors.bold(purl) : purl), '', ...Object.entries(scoreResult).map(score => `- ${score[0]}:`.padEnd(20, ' ') + ` ${formatScore(score[1], !color, true)}`), alertString].join('\n');
|
|
4921
|
+
}
|
|
4922
|
+
function formatScore(score, noColor = false, pad = false) {
|
|
4923
|
+
const padded = String(score).padStart(pad ? 3 : 0, ' ');
|
|
4924
|
+
if (noColor) return padded;else if (score >= 80) return colors.green(padded);else if (score >= 60) return colors.yellow(padded);else return colors.red(padded);
|
|
4925
|
+
}
|
|
4926
|
+
function getAlertString(alerts, noColor = false) {
|
|
4927
|
+
if (!alerts?.length) {
|
|
4928
|
+
return noColor ? `- Alerts: none!` : `- Alerts: ${colors.green('none')}!`;
|
|
4929
|
+
} else {
|
|
4930
|
+
const bad = alerts.filter(alert => alert.severity !== 'low' && alert.severity !== 'middle').sort((a, b) => a.type < b.type ? -1 : a.type > b.type ? 1 : 0);
|
|
4931
|
+
const mid = alerts.filter(alert => alert.severity === 'middle').sort((a, b) => a.type < b.type ? -1 : a.type > b.type ? 1 : 0);
|
|
4932
|
+
const low = alerts.filter(alert => alert.severity === 'low').sort((a, b) => a.type < b.type ? -1 : a.type > b.type ? 1 : 0);
|
|
4933
|
+
|
|
4934
|
+
// We need to create the no-color string regardless because the actual string
|
|
4935
|
+
// contains a bunch of invisible ANSI chars which would screw up length checks.
|
|
4936
|
+
const colorless = `- Alerts (${bad.length}/${mid.length.toString()}/${low.length}):`;
|
|
4937
|
+
if (noColor) {
|
|
4938
|
+
return colorless + ' '.repeat(Math.max(0, 20 - colorless.length)) + ' ' + [bad.map(alert => `[${alert.severity}] ` + alert.type).join(', '), mid.map(alert => `[${alert.severity}] ` + alert.type).join(', '), low.map(alert => `[${alert.severity}] ` + alert.type).join(', ')].filter(Boolean).join(', ');
|
|
4939
|
+
}
|
|
4940
|
+
return `- Alerts (${colors.red(bad.length.toString())}/${colors.yellow(mid.length.toString())}/${low.length}):` + ' '.repeat(Math.max(0, 20 - colorless.length)) + ' ' + [bad.map(alert => colors.red(colors.dim(`[${alert.severity}] `) + alert.type)).join(', '), mid.map(alert => colors.yellow(colors.dim(`[${alert.severity}] `) + alert.type)).join(', '), low.map(alert => colors.dim(`[${alert.severity}] `) + alert.type).join(', ')].filter(Boolean).join(', ');
|
|
4941
|
+
}
|
|
4942
|
+
}
|
|
4943
|
+
|
|
4944
|
+
async function showPurlInfo({
|
|
4945
|
+
outputKind,
|
|
4946
|
+
purls
|
|
4947
|
+
}) {
|
|
4948
|
+
const packageData = await fetchPackageInfo(purls);
|
|
4949
|
+
if (packageData) {
|
|
4950
|
+
logPackageInfo(purls, packageData.data, outputKind);
|
|
4951
|
+
}
|
|
4952
|
+
}
|
|
4953
|
+
|
|
4954
|
+
const {
|
|
4955
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$h
|
|
4956
|
+
} = constants;
|
|
4957
|
+
const config$h = {
|
|
4958
|
+
commandName: 'shallow',
|
|
4959
|
+
description: 'Look up info regarding one or more packages but not their transitives',
|
|
4960
|
+
hidden: true,
|
|
4961
|
+
flags: {
|
|
4962
|
+
...commonFlags,
|
|
4963
|
+
...outputFlags
|
|
4964
|
+
},
|
|
4965
|
+
help: (command, config) => `
|
|
4966
|
+
Usage
|
|
4967
|
+
$ ${command} <<ecosystem> <name> [<name> ...] | <purl> [<purl> ...]>
|
|
4968
|
+
|
|
4969
|
+
Options
|
|
4970
|
+
${getFlagListOutput(config.flags, 6)}
|
|
4971
|
+
|
|
4972
|
+
Requirements
|
|
4973
|
+
- quota: 100
|
|
4974
|
+
- scope: \`packages:list\`
|
|
4975
|
+
|
|
4976
|
+
Show scoring details for one or more packages purely based on their own package.
|
|
4977
|
+
This means that any dependency scores are not reflected by the score. You can
|
|
4978
|
+
use the \`socket package score <pkg>\` command to get its full transitive score.
|
|
4979
|
+
|
|
4980
|
+
Only a few ecosystems are supported like npm, golang, and maven.
|
|
4981
|
+
|
|
4982
|
+
A "purl" is a standard package name formatting: \`pkg:eco/name@version\`
|
|
4983
|
+
This command will automatically prepend "pkg:" when not present.
|
|
4984
|
+
|
|
4985
|
+
If the first arg is an ecosystem, remaining args that are not a purl are
|
|
4986
|
+
assumed to be scoped to that ecosystem.
|
|
4987
|
+
|
|
4988
|
+
Examples
|
|
4989
|
+
$ ${command} npm webtorrent
|
|
4990
|
+
$ ${command} npm webtorrent@1.9.1
|
|
4991
|
+
$ ${command} npm/webtorrent@1.9.1
|
|
4992
|
+
$ ${command} pkg:npm/webtorrent@1.9.1
|
|
4993
|
+
$ ${command} maven webtorrent babel
|
|
4994
|
+
$ ${command} npm/webtorrent golang/babel
|
|
4995
|
+
$ ${command} npm npm/webtorrent@1.0.1 babel
|
|
4996
|
+
`
|
|
4997
|
+
};
|
|
4998
|
+
const cmdPackageShallow = {
|
|
4999
|
+
description: config$h.description,
|
|
5000
|
+
hidden: config$h.hidden,
|
|
5001
|
+
alias: {
|
|
5002
|
+
shallowScore: {
|
|
5003
|
+
description: config$h.description,
|
|
5004
|
+
hidden: true,
|
|
5005
|
+
argv: []
|
|
5006
|
+
}
|
|
5007
|
+
},
|
|
5008
|
+
run: run$h
|
|
5009
|
+
};
|
|
5010
|
+
async function run$h(argv, importMeta, {
|
|
5011
|
+
parentName
|
|
5012
|
+
}) {
|
|
5013
|
+
const cli = meowOrExit({
|
|
5014
|
+
argv,
|
|
5015
|
+
config: config$h,
|
|
5016
|
+
importMeta,
|
|
5017
|
+
parentName
|
|
5018
|
+
});
|
|
5019
|
+
const {
|
|
5020
|
+
json,
|
|
5021
|
+
markdown
|
|
5022
|
+
} = cli.flags;
|
|
5023
|
+
const [ecosystem = '', ...pkgs] = cli.input;
|
|
5024
|
+
const {
|
|
5025
|
+
purls,
|
|
5026
|
+
valid
|
|
5027
|
+
} = parsePackageSpecifiers(ecosystem, pkgs);
|
|
5028
|
+
if (!valid || !purls.length) {
|
|
5029
|
+
// Use exit status of 2 to indicate incorrect usage, generally invalid
|
|
5030
|
+
// options or missing arguments.
|
|
5031
|
+
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
5032
|
+
process.exitCode = 2;
|
|
5033
|
+
logger.logger.fail(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
5034
|
+
- First parameter should be an ecosystem or all args must be purls ${!valid ? colors.red('(bad!)') : colors.green('(ok)')}\n
|
|
5035
|
+
- Expecting at least one package ${!purls.length ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
5036
|
+
`);
|
|
5037
|
+
return;
|
|
5038
|
+
}
|
|
5039
|
+
if (cli.flags['dryRun']) {
|
|
5040
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$h);
|
|
5041
|
+
return;
|
|
5042
|
+
}
|
|
5043
|
+
await showPurlInfo({
|
|
5044
|
+
outputKind: json ? 'json' : markdown ? 'markdown' : 'text',
|
|
5045
|
+
purls
|
|
5046
|
+
});
|
|
5047
|
+
}
|
|
5048
|
+
|
|
5049
|
+
const description$3 = 'Commands relating to looking up published packages';
|
|
5050
|
+
const cmdPackage = {
|
|
5051
|
+
description: description$3,
|
|
5052
|
+
hidden: true,
|
|
5053
|
+
// [beta]
|
|
5054
|
+
async run(argv, importMeta, {
|
|
5055
|
+
parentName
|
|
5056
|
+
}) {
|
|
5057
|
+
await meowWithSubcommands({
|
|
5058
|
+
shallow: cmdPackageShallow
|
|
5059
|
+
}, {
|
|
5060
|
+
aliases: {
|
|
5061
|
+
pkg: {
|
|
5062
|
+
description: description$3,
|
|
5063
|
+
hidden: true,
|
|
5064
|
+
argv: []
|
|
5065
|
+
}
|
|
5066
|
+
},
|
|
5067
|
+
argv,
|
|
5068
|
+
description: description$3,
|
|
5069
|
+
importMeta,
|
|
5070
|
+
name: parentName + ' package'
|
|
5071
|
+
});
|
|
5072
|
+
}
|
|
5073
|
+
};
|
|
5074
|
+
|
|
6072
5075
|
async function runRawNpm(argv) {
|
|
6073
5076
|
const spawnPromise = spawn.spawn(shadowNpmPaths.getNpmBinPath(), argv, {
|
|
6074
5077
|
stdio: 'inherit'
|
|
@@ -6396,7 +5399,7 @@ async function run$e(argv, importMeta, {
|
|
|
6396
5399
|
|
|
6397
5400
|
// TODO: Allow setting a custom cwd and/or configFile path?
|
|
6398
5401
|
const cwd = process$1.cwd();
|
|
6399
|
-
const absoluteConfigPath = path.join(cwd, 'socket.yml');
|
|
5402
|
+
const absoluteConfigPath = path$1.join(cwd, 'socket.yml');
|
|
6400
5403
|
const dryRun = Boolean(cli.flags['dryRun']);
|
|
6401
5404
|
const json = Boolean(cli.flags['json']);
|
|
6402
5405
|
const markdown = Boolean(cli.flags['markdown']);
|
|
@@ -6777,8 +5780,8 @@ async function listReposWithToken({
|
|
|
6777
5780
|
const result = await handleApiCall(socketSdk.getOrgRepoList(orgSlug, {
|
|
6778
5781
|
sort,
|
|
6779
5782
|
direction,
|
|
6780
|
-
per_page,
|
|
6781
|
-
page
|
|
5783
|
+
per_page: String(per_page),
|
|
5784
|
+
page: String(page)
|
|
6782
5785
|
}), 'listing repositories');
|
|
6783
5786
|
if (!result.success) {
|
|
6784
5787
|
handleUnsuccessfulApiResponse('getOrgRepoList', result);
|
|
@@ -7239,13 +6242,13 @@ async function suggestRepoSlug(socketSdk, orgSlug) {
|
|
|
7239
6242
|
// There's no guarantee that the cwd is part of this page. If it's not
|
|
7240
6243
|
// then do an additional request and specific search for it instead.
|
|
7241
6244
|
// This way we can offer the tip of "do you want to create [cwd]?".
|
|
7242
|
-
perPage: 10,
|
|
7243
|
-
page: 0
|
|
6245
|
+
perPage: '10',
|
|
6246
|
+
page: '0'
|
|
7244
6247
|
}), 'looking up known repos');
|
|
7245
6248
|
// Ignore a failed request here. It was not the primary goal of
|
|
7246
6249
|
// running this command and reporting it only leads to end-user confusion.
|
|
7247
6250
|
if (result.success) {
|
|
7248
|
-
const currentDirName = dirNameToSlug(path.basename(process$1.cwd()));
|
|
6251
|
+
const currentDirName = dirNameToSlug(path$1.basename(process$1.cwd()));
|
|
7249
6252
|
let cwdIsKnown = !!currentDirName && result.data.results.some(obj => obj.slug === currentDirName);
|
|
7250
6253
|
if (!cwdIsKnown && currentDirName) {
|
|
7251
6254
|
// Do an explicit request so we can assert that the cwd exists or not
|
|
@@ -7465,9 +6468,9 @@ async function createFullScan({
|
|
|
7465
6468
|
repo: repoName,
|
|
7466
6469
|
branch: branchName,
|
|
7467
6470
|
commit_message: commitMessage,
|
|
7468
|
-
make_default_branch: defaultBranch,
|
|
7469
|
-
set_as_pending_head: pendingHead,
|
|
7470
|
-
tmp
|
|
6471
|
+
make_default_branch: String(defaultBranch),
|
|
6472
|
+
set_as_pending_head: String(pendingHead),
|
|
6473
|
+
tmp: String(tmp)
|
|
7471
6474
|
}, packagePaths, cwd), 'Creating scan');
|
|
7472
6475
|
if (!result.success) {
|
|
7473
6476
|
handleUnsuccessfulApiResponse('CreateOrgFullScan', result);
|
|
@@ -7784,8 +6787,8 @@ async function listFullScansWithToken({
|
|
|
7784
6787
|
const result = await handleApiCall(socketSdk.getOrgFullScanList(orgSlug, {
|
|
7785
6788
|
sort,
|
|
7786
6789
|
direction,
|
|
7787
|
-
per_page,
|
|
7788
|
-
page,
|
|
6790
|
+
per_page: String(per_page),
|
|
6791
|
+
page: String(page),
|
|
7789
6792
|
from: from_time
|
|
7790
6793
|
}), 'Listing scans');
|
|
7791
6794
|
if (!result.success) {
|
|
@@ -8393,7 +7396,7 @@ async function reportFullScan({
|
|
|
8393
7396
|
const json = short ? JSON.stringify(scanReport) : toJsonReport(scanReport);
|
|
8394
7397
|
if (filePath && filePath !== '-') {
|
|
8395
7398
|
logger.logger.log('Writing json report to', filePath);
|
|
8396
|
-
return await fs
|
|
7399
|
+
return await fs.writeFile(filePath, json);
|
|
8397
7400
|
}
|
|
8398
7401
|
logger.logger.log(json);
|
|
8399
7402
|
return;
|
|
@@ -8402,7 +7405,7 @@ async function reportFullScan({
|
|
|
8402
7405
|
const md = short ? `healthy = ${scanReport.healthy}` : toMarkdownReport(scanReport);
|
|
8403
7406
|
if (filePath && filePath !== '-') {
|
|
8404
7407
|
logger.logger.log('Writing markdown report to', filePath);
|
|
8405
|
-
return await fs
|
|
7408
|
+
return await fs.writeFile(filePath, md);
|
|
8406
7409
|
}
|
|
8407
7410
|
logger.logger.log(md);
|
|
8408
7411
|
return;
|
|
@@ -8643,7 +7646,7 @@ View this report at: https://socket.dev/dashboard/org/${orgSlug}/sbom/${fullScan
|
|
|
8643
7646
|
`.trim() + '\n';
|
|
8644
7647
|
if (filePath && filePath !== '-') {
|
|
8645
7648
|
try {
|
|
8646
|
-
await fs
|
|
7649
|
+
await fs.writeFile(filePath, report, 'utf8');
|
|
8647
7650
|
logger.logger.log(`Data successfully written to ${filePath}`);
|
|
8648
7651
|
} catch (e) {
|
|
8649
7652
|
process.exitCode = 1;
|
|
@@ -9006,7 +8009,7 @@ async function run$1(argv, importMeta, {
|
|
|
9006
8009
|
}
|
|
9007
8010
|
|
|
9008
8011
|
function addSocketWrapper(file) {
|
|
9009
|
-
return fs.appendFile(file, 'alias npm="socket npm"\nalias npx="socket npx"\n', err => {
|
|
8012
|
+
return fs$1.appendFile(file, 'alias npm="socket npm"\nalias npx="socket npx"\n', err => {
|
|
9010
8013
|
if (err) {
|
|
9011
8014
|
return new Error(`There was an error setting up the alias: ${err}`);
|
|
9012
8015
|
}
|
|
@@ -9020,7 +8023,7 @@ If you want to disable it at any time, run \`socket wrapper --disable\`
|
|
|
9020
8023
|
}
|
|
9021
8024
|
|
|
9022
8025
|
function checkSocketWrapperSetup(file) {
|
|
9023
|
-
const fileContent = fs.readFileSync(file, 'utf8');
|
|
8026
|
+
const fileContent = fs$1.readFileSync(file, 'utf8');
|
|
9024
8027
|
const linesWithSocketAlias = fileContent.split('\n').filter(l => l === 'alias npm="socket npm"' || l === 'alias npx="socket npx"');
|
|
9025
8028
|
if (linesWithSocketAlias.length) {
|
|
9026
8029
|
logger.logger.log(`The Socket npm/npx wrapper is set up in your bash profile (${file}).`);
|
|
@@ -9035,7 +8038,7 @@ function postinstallWrapper() {
|
|
|
9035
8038
|
bashRcPath,
|
|
9036
8039
|
zshRcPath
|
|
9037
8040
|
} = constants;
|
|
9038
|
-
const socketWrapperEnabled = fs.existsSync(bashRcPath) && checkSocketWrapperSetup(bashRcPath) || fs.existsSync(zshRcPath) && checkSocketWrapperSetup(zshRcPath);
|
|
8041
|
+
const socketWrapperEnabled = fs$1.existsSync(bashRcPath) && checkSocketWrapperSetup(bashRcPath) || fs$1.existsSync(zshRcPath) && checkSocketWrapperSetup(zshRcPath);
|
|
9039
8042
|
if (!socketWrapperEnabled) {
|
|
9040
8043
|
installSafeNpm(`The Socket CLI is now successfully installed! 🎉
|
|
9041
8044
|
|
|
@@ -9067,10 +8070,10 @@ function askQuestion(rl, query) {
|
|
|
9067
8070
|
zshRcPath
|
|
9068
8071
|
} = constants;
|
|
9069
8072
|
try {
|
|
9070
|
-
if (fs.existsSync(bashRcPath)) {
|
|
8073
|
+
if (fs$1.existsSync(bashRcPath)) {
|
|
9071
8074
|
addSocketWrapper(bashRcPath);
|
|
9072
8075
|
}
|
|
9073
|
-
if (fs.existsSync(zshRcPath)) {
|
|
8076
|
+
if (fs$1.existsSync(zshRcPath)) {
|
|
9074
8077
|
addSocketWrapper(zshRcPath);
|
|
9075
8078
|
}
|
|
9076
8079
|
} catch (e) {
|
|
@@ -9086,7 +8089,7 @@ function askQuestion(rl, query) {
|
|
|
9086
8089
|
}
|
|
9087
8090
|
|
|
9088
8091
|
function removeSocketWrapper(file) {
|
|
9089
|
-
return fs.readFile(file, 'utf8', function (err, data) {
|
|
8092
|
+
return fs$1.readFile(file, 'utf8', function (err, data) {
|
|
9090
8093
|
if (err) {
|
|
9091
8094
|
logger.logger.fail('There was an error removing the alias:');
|
|
9092
8095
|
logger.logger.error(err);
|
|
@@ -9094,7 +8097,7 @@ function removeSocketWrapper(file) {
|
|
|
9094
8097
|
}
|
|
9095
8098
|
const linesWithoutSocketAlias = data.split('\n').filter(l => l !== 'alias npm="socket npm"' && l !== 'alias npx="socket npx"');
|
|
9096
8099
|
const updatedFileContent = linesWithoutSocketAlias.join('\n');
|
|
9097
|
-
fs.writeFile(file, updatedFileContent, function (err) {
|
|
8100
|
+
fs$1.writeFile(file, updatedFileContent, function (err) {
|
|
9098
8101
|
if (err) {
|
|
9099
8102
|
logger.logger.error(err);
|
|
9100
8103
|
return;
|
|
@@ -9183,21 +8186,21 @@ async function run(argv, importMeta, {
|
|
|
9183
8186
|
zshRcPath
|
|
9184
8187
|
} = constants;
|
|
9185
8188
|
if (enable) {
|
|
9186
|
-
if (fs.existsSync(bashRcPath) && !checkSocketWrapperSetup(bashRcPath)) {
|
|
8189
|
+
if (fs$1.existsSync(bashRcPath) && !checkSocketWrapperSetup(bashRcPath)) {
|
|
9187
8190
|
addSocketWrapper(bashRcPath);
|
|
9188
8191
|
}
|
|
9189
|
-
if (fs.existsSync(zshRcPath) && !checkSocketWrapperSetup(zshRcPath)) {
|
|
8192
|
+
if (fs$1.existsSync(zshRcPath) && !checkSocketWrapperSetup(zshRcPath)) {
|
|
9190
8193
|
addSocketWrapper(zshRcPath);
|
|
9191
8194
|
}
|
|
9192
8195
|
} else {
|
|
9193
|
-
if (fs.existsSync(bashRcPath)) {
|
|
8196
|
+
if (fs$1.existsSync(bashRcPath)) {
|
|
9194
8197
|
removeSocketWrapper(bashRcPath);
|
|
9195
8198
|
}
|
|
9196
|
-
if (fs.existsSync(zshRcPath)) {
|
|
8199
|
+
if (fs$1.existsSync(zshRcPath)) {
|
|
9197
8200
|
removeSocketWrapper(zshRcPath);
|
|
9198
8201
|
}
|
|
9199
8202
|
}
|
|
9200
|
-
if (!fs.existsSync(bashRcPath) && !fs.existsSync(zshRcPath)) {
|
|
8203
|
+
if (!fs$1.existsSync(bashRcPath) && !fs$1.existsSync(zshRcPath)) {
|
|
9201
8204
|
logger.logger.fail('There was an issue setting up the alias in your bash profile');
|
|
9202
8205
|
}
|
|
9203
8206
|
}
|
|
@@ -9211,12 +8214,11 @@ void (async () => {
|
|
|
9211
8214
|
await vendor.updater({
|
|
9212
8215
|
name: SOCKET_CLI_BIN_NAME,
|
|
9213
8216
|
// The '@rollup/plugin-replace' will replace "process.env['INLINED_SOCKET_CLI_VERSION']".
|
|
9214
|
-
version: "0.14.
|
|
8217
|
+
version: "0.14.63",
|
|
9215
8218
|
ttl: 86_400_000 /* 24 hours in milliseconds */
|
|
9216
8219
|
});
|
|
9217
8220
|
try {
|
|
9218
8221
|
await meowWithSubcommands({
|
|
9219
|
-
action: cmdAction,
|
|
9220
8222
|
cdxgen: cmdCdxgen,
|
|
9221
8223
|
fix: cmdFix,
|
|
9222
8224
|
info: cmdInfo,
|
|
@@ -9227,6 +8229,7 @@ void (async () => {
|
|
|
9227
8229
|
oops: cmdOops,
|
|
9228
8230
|
optimize: cmdOptimize,
|
|
9229
8231
|
organization: cmdOrganization,
|
|
8232
|
+
package: cmdPackage,
|
|
9230
8233
|
'raw-npm': cmdRawNpm,
|
|
9231
8234
|
'raw-npx': cmdRawNpx,
|
|
9232
8235
|
report: cmdReport,
|
|
@@ -9278,5 +8281,5 @@ void (async () => {
|
|
|
9278
8281
|
await shadowNpmInject.captureException(e);
|
|
9279
8282
|
}
|
|
9280
8283
|
})();
|
|
9281
|
-
//# debugId=
|
|
8284
|
+
//# debugId=4b4583e5-72f1-4646-aeb0-bc55c45384cb
|
|
9282
8285
|
//# sourceMappingURL=cli.js.map
|