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