@socketsecurity/cli-with-sentry 0.14.62 → 0.14.63
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/cli.js +1 -0
- package/dist/constants.d.ts +14 -15
- package/dist/constants.js +4 -2
- package/dist/constants.js.map +1 -1
- package/dist/instrument-with-sentry.js +2 -2
- package/dist/instrument-with-sentry.js.map +1 -1
- package/dist/module-sync/cli.js +773 -1771
- package/dist/module-sync/cli.js.map +1 -1
- package/dist/module-sync/fs.d.ts +22 -0
- package/dist/module-sync/shadow-npm-inject.js +38 -27
- package/dist/module-sync/shadow-npm-inject.js.map +1 -1
- package/dist/require/cli.js +773 -1770
- package/dist/require/cli.js.map +1 -1
- package/dist/require/vendor.js +1 -2414
- package/dist/require/vendor.js.map +1 -1
- package/package.json +15 -25
package/dist/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:f94aacd0: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
|
});
|
|
@@ -3302,7 +2012,7 @@ const readLockFileByAgent = (() => {
|
|
|
3302
2012
|
const binaryReader = wrapReader(shadowNpmInject.readFileBinary);
|
|
3303
2013
|
const defaultReader = wrapReader(async lockPath => await shadowNpmInject.readFileUtf8(lockPath));
|
|
3304
2014
|
return new Map([[BUN$5, wrapReader(async (lockPath, agentExecPath) => {
|
|
3305
|
-
const ext = path.extname(lockPath);
|
|
2015
|
+
const ext = path$1.extname(lockPath);
|
|
3306
2016
|
if (ext === LOCK_EXT$1) {
|
|
3307
2017
|
return await defaultReader(lockPath);
|
|
3308
2018
|
}
|
|
@@ -3328,12 +2038,12 @@ async function detectPackageEnvironment({
|
|
|
3328
2038
|
let lockPath = await shadowNpmInject.findUp(Object.keys(LOCKS), {
|
|
3329
2039
|
cwd
|
|
3330
2040
|
});
|
|
3331
|
-
let lockName = lockPath ? path.basename(lockPath) : undefined;
|
|
2041
|
+
let lockName = lockPath ? path$1.basename(lockPath) : undefined;
|
|
3332
2042
|
const isHiddenLockFile = lockName === HIDDEN_PACKAGE_LOCK_JSON;
|
|
3333
|
-
const pkgJsonPath = lockPath ? path.resolve(lockPath, `${isHiddenLockFile ? '../' : ''}../${PACKAGE_JSON}`) : await shadowNpmInject.findUp(PACKAGE_JSON, {
|
|
2043
|
+
const pkgJsonPath = lockPath ? path$1.resolve(lockPath, `${isHiddenLockFile ? '../' : ''}../${PACKAGE_JSON}`) : await shadowNpmInject.findUp(PACKAGE_JSON, {
|
|
3334
2044
|
cwd
|
|
3335
2045
|
});
|
|
3336
|
-
const pkgPath = pkgJsonPath && fs.existsSync(pkgJsonPath) ? path.dirname(pkgJsonPath) : undefined;
|
|
2046
|
+
const pkgPath = pkgJsonPath && fs$1.existsSync(pkgJsonPath) ? path$1.dirname(pkgJsonPath) : undefined;
|
|
3337
2047
|
const editablePkgJson = pkgPath ? await packages.readPackageJson(pkgPath, {
|
|
3338
2048
|
editable: true
|
|
3339
2049
|
}) : undefined;
|
|
@@ -3518,7 +2228,7 @@ async function detectAndValidatePackageEnvironment(cwd, options) {
|
|
|
3518
2228
|
logger?.fail(cmdPrefixMessage(cmdName, `--prod not supported for ${agent}${agentVersion ? `@${agentVersion}` : ''}`));
|
|
3519
2229
|
return;
|
|
3520
2230
|
}
|
|
3521
|
-
if (details.lockPath && path.relative(cwd, details.lockPath).startsWith('.')) {
|
|
2231
|
+
if (details.lockPath && path$1.relative(cwd, details.lockPath).startsWith('.')) {
|
|
3522
2232
|
logger?.warn(cmdPrefixMessage(cmdName, `Package ${lockName} found at ${details.lockPath}`));
|
|
3523
2233
|
}
|
|
3524
2234
|
return details;
|
|
@@ -3560,9 +2270,9 @@ async function runFix() {
|
|
|
3560
2270
|
}
|
|
3561
2271
|
|
|
3562
2272
|
const {
|
|
3563
|
-
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$
|
|
2273
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$w
|
|
3564
2274
|
} = constants;
|
|
3565
|
-
const config$
|
|
2275
|
+
const config$x = {
|
|
3566
2276
|
commandName: 'fix',
|
|
3567
2277
|
description: 'Fix "fixable" Socket alerts',
|
|
3568
2278
|
hidden: true,
|
|
@@ -3578,27 +2288,27 @@ const config$w = {
|
|
|
3578
2288
|
`
|
|
3579
2289
|
};
|
|
3580
2290
|
const cmdFix = {
|
|
3581
|
-
description: config$
|
|
3582
|
-
hidden: config$
|
|
3583
|
-
run: run$
|
|
2291
|
+
description: config$x.description,
|
|
2292
|
+
hidden: config$x.hidden,
|
|
2293
|
+
run: run$x
|
|
3584
2294
|
};
|
|
3585
|
-
async function run$
|
|
2295
|
+
async function run$x(argv, importMeta, {
|
|
3586
2296
|
parentName
|
|
3587
2297
|
}) {
|
|
3588
2298
|
const cli = meowOrExit({
|
|
3589
2299
|
argv,
|
|
3590
|
-
config: config$
|
|
2300
|
+
config: config$x,
|
|
3591
2301
|
importMeta,
|
|
3592
2302
|
parentName
|
|
3593
2303
|
});
|
|
3594
2304
|
if (cli.flags['dryRun']) {
|
|
3595
|
-
logger.logger.log(DRY_RUN_BAIL_TEXT$
|
|
2305
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$w);
|
|
3596
2306
|
return;
|
|
3597
2307
|
}
|
|
3598
2308
|
await runFix();
|
|
3599
2309
|
}
|
|
3600
2310
|
|
|
3601
|
-
async function fetchPackageInfo(pkgName, pkgVersion, includeAllIssues) {
|
|
2311
|
+
async function fetchPackageInfo$1(pkgName, pkgVersion, includeAllIssues) {
|
|
3602
2312
|
const socketSdk = await shadowNpmInject.setupSdk(shadowNpmInject.getPublicToken());
|
|
3603
2313
|
const result = await handleApiCall(socketSdk.getIssuesByNPMPackage(pkgName, pkgVersion), 'looking up package');
|
|
3604
2314
|
const scoreResult = await handleApiCall(socketSdk.getScoreByNPMPackage(pkgName, pkgVersion), 'looking up package score');
|
|
@@ -3619,7 +2329,7 @@ async function fetchPackageInfo(pkgName, pkgVersion, includeAllIssues) {
|
|
|
3619
2329
|
const {
|
|
3620
2330
|
NPM: NPM$9
|
|
3621
2331
|
} = registryConstants;
|
|
3622
|
-
function formatScore(score) {
|
|
2332
|
+
function formatScore$1(score) {
|
|
3623
2333
|
if (score > 80) {
|
|
3624
2334
|
return colors.green(`${score}`);
|
|
3625
2335
|
} else if (score < 80 && score > 60) {
|
|
@@ -3658,7 +2368,7 @@ function logPackageIssuesDetails(packageData, outputMarkdown) {
|
|
|
3658
2368
|
}
|
|
3659
2369
|
}
|
|
3660
2370
|
}
|
|
3661
|
-
function logPackageInfo({
|
|
2371
|
+
function logPackageInfo$1({
|
|
3662
2372
|
data,
|
|
3663
2373
|
score,
|
|
3664
2374
|
severityCount
|
|
@@ -3689,7 +2399,7 @@ function logPackageInfo({
|
|
|
3689
2399
|
License: Math.floor(score.license.score * 100)
|
|
3690
2400
|
};
|
|
3691
2401
|
logger.logger.log('\n');
|
|
3692
|
-
Object.entries(scoreResult).map(score => logger.logger.log(`- ${score[0]}: ${formatScore(score[1])}`));
|
|
2402
|
+
Object.entries(scoreResult).map(score => logger.logger.log(`- ${score[0]}: ${formatScore$1(score[1])}`));
|
|
3693
2403
|
logger.logger.log('\n');
|
|
3694
2404
|
if (objects.hasKeys(severityCount)) {
|
|
3695
2405
|
if (outputKind === 'markdown') {
|
|
@@ -3732,10 +2442,10 @@ async function getPackageInfo({
|
|
|
3732
2442
|
spinner
|
|
3733
2443
|
} = constants;
|
|
3734
2444
|
spinner.start(pkgVersion === 'latest' ? `Looking up data for the latest version of ${pkgName}` : `Looking up data for version ${pkgVersion} of ${pkgName}`);
|
|
3735
|
-
const packageData = await fetchPackageInfo(pkgName, pkgVersion, includeAllIssues);
|
|
2445
|
+
const packageData = await fetchPackageInfo$1(pkgName, pkgVersion, includeAllIssues);
|
|
3736
2446
|
spinner.successAndStop('Data fetched');
|
|
3737
2447
|
if (packageData) {
|
|
3738
|
-
logPackageInfo(packageData, {
|
|
2448
|
+
logPackageInfo$1(packageData, {
|
|
3739
2449
|
name: commandName,
|
|
3740
2450
|
outputKind,
|
|
3741
2451
|
pkgName,
|
|
@@ -3749,9 +2459,9 @@ async function getPackageInfo({
|
|
|
3749
2459
|
}
|
|
3750
2460
|
|
|
3751
2461
|
const {
|
|
3752
|
-
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$
|
|
2462
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$v
|
|
3753
2463
|
} = constants;
|
|
3754
|
-
const config$
|
|
2464
|
+
const config$w = {
|
|
3755
2465
|
commandName: 'info',
|
|
3756
2466
|
description: 'Look up info regarding a package',
|
|
3757
2467
|
hidden: false,
|
|
@@ -3773,16 +2483,16 @@ const config$v = {
|
|
|
3773
2483
|
`
|
|
3774
2484
|
};
|
|
3775
2485
|
const cmdInfo = {
|
|
3776
|
-
description: config$
|
|
3777
|
-
hidden: config$
|
|
3778
|
-
run: run$
|
|
2486
|
+
description: config$w.description,
|
|
2487
|
+
hidden: config$w.hidden,
|
|
2488
|
+
run: run$w
|
|
3779
2489
|
};
|
|
3780
|
-
async function run$
|
|
2490
|
+
async function run$w(argv, importMeta, {
|
|
3781
2491
|
parentName
|
|
3782
2492
|
}) {
|
|
3783
2493
|
const cli = meowOrExit({
|
|
3784
2494
|
argv,
|
|
3785
|
-
config: config$
|
|
2495
|
+
config: config$w,
|
|
3786
2496
|
importMeta,
|
|
3787
2497
|
parentName
|
|
3788
2498
|
});
|
|
@@ -3807,11 +2517,11 @@ async function run$v(argv, importMeta, {
|
|
|
3807
2517
|
const pkgName = versionSeparator < 1 ? rawPkgName : rawPkgName.slice(0, versionSeparator);
|
|
3808
2518
|
const pkgVersion = versionSeparator < 1 ? 'latest' : rawPkgName.slice(versionSeparator + 1);
|
|
3809
2519
|
if (cli.flags['dryRun']) {
|
|
3810
|
-
logger.logger.log(DRY_RUN_BAIL_TEXT$
|
|
2520
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$v);
|
|
3811
2521
|
return;
|
|
3812
2522
|
}
|
|
3813
2523
|
await getPackageInfo({
|
|
3814
|
-
commandName: `${parentName} ${config$
|
|
2524
|
+
commandName: `${parentName} ${config$w.commandName}`,
|
|
3815
2525
|
includeAllIssues: Boolean(all),
|
|
3816
2526
|
outputKind: json ? 'json' : markdown ? 'markdown' : 'print',
|
|
3817
2527
|
pkgName,
|
|
@@ -3898,9 +2608,9 @@ async function attemptLogin(apiBaseUrl, apiProxy) {
|
|
|
3898
2608
|
}
|
|
3899
2609
|
|
|
3900
2610
|
const {
|
|
3901
|
-
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$
|
|
2611
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$u
|
|
3902
2612
|
} = constants;
|
|
3903
|
-
const config$
|
|
2613
|
+
const config$v = {
|
|
3904
2614
|
commandName: 'login',
|
|
3905
2615
|
description: 'Socket API login',
|
|
3906
2616
|
hidden: false,
|
|
@@ -3930,23 +2640,23 @@ const config$u = {
|
|
|
3930
2640
|
`
|
|
3931
2641
|
};
|
|
3932
2642
|
const cmdLogin = {
|
|
3933
|
-
description: config$
|
|
3934
|
-
hidden: config$
|
|
3935
|
-
run: run$
|
|
2643
|
+
description: config$v.description,
|
|
2644
|
+
hidden: config$v.hidden,
|
|
2645
|
+
run: run$v
|
|
3936
2646
|
};
|
|
3937
|
-
async function run$
|
|
2647
|
+
async function run$v(argv, importMeta, {
|
|
3938
2648
|
parentName
|
|
3939
2649
|
}) {
|
|
3940
2650
|
const cli = meowOrExit({
|
|
3941
2651
|
argv,
|
|
3942
|
-
config: config$
|
|
2652
|
+
config: config$v,
|
|
3943
2653
|
importMeta,
|
|
3944
2654
|
parentName
|
|
3945
2655
|
});
|
|
3946
2656
|
const apiBaseUrl = cli.flags['apiBaseUrl'];
|
|
3947
2657
|
const apiProxy = cli.flags['apiProxy'];
|
|
3948
2658
|
if (cli.flags['dryRun']) {
|
|
3949
|
-
logger.logger.log(DRY_RUN_BAIL_TEXT$
|
|
2659
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$u);
|
|
3950
2660
|
return;
|
|
3951
2661
|
}
|
|
3952
2662
|
if (!isInteractive()) {
|
|
@@ -3972,9 +2682,9 @@ function attemptLogout() {
|
|
|
3972
2682
|
}
|
|
3973
2683
|
|
|
3974
2684
|
const {
|
|
3975
|
-
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$
|
|
2685
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$t
|
|
3976
2686
|
} = constants;
|
|
3977
|
-
const config$
|
|
2687
|
+
const config$u = {
|
|
3978
2688
|
commandName: 'logout',
|
|
3979
2689
|
description: 'Socket API logout',
|
|
3980
2690
|
hidden: false,
|
|
@@ -3989,21 +2699,21 @@ const config$t = {
|
|
|
3989
2699
|
`
|
|
3990
2700
|
};
|
|
3991
2701
|
const cmdLogout = {
|
|
3992
|
-
description: config$
|
|
3993
|
-
hidden: config$
|
|
3994
|
-
run: run$
|
|
2702
|
+
description: config$u.description,
|
|
2703
|
+
hidden: config$u.hidden,
|
|
2704
|
+
run: run$u
|
|
3995
2705
|
};
|
|
3996
|
-
async function run$
|
|
2706
|
+
async function run$u(argv, importMeta, {
|
|
3997
2707
|
parentName
|
|
3998
2708
|
}) {
|
|
3999
2709
|
const cli = meowOrExit({
|
|
4000
2710
|
argv,
|
|
4001
|
-
config: config$
|
|
2711
|
+
config: config$u,
|
|
4002
2712
|
importMeta,
|
|
4003
2713
|
parentName
|
|
4004
2714
|
});
|
|
4005
2715
|
if (cli.flags['dryRun']) {
|
|
4006
|
-
logger.logger.log(DRY_RUN_BAIL_TEXT$
|
|
2716
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$t);
|
|
4007
2717
|
return;
|
|
4008
2718
|
}
|
|
4009
2719
|
attemptLogout();
|
|
@@ -4014,8 +2724,8 @@ async function convertGradleToMaven(target, bin, _out, verbose, gradleOpts) {
|
|
|
4014
2724
|
const {
|
|
4015
2725
|
spinner
|
|
4016
2726
|
} = constants;
|
|
4017
|
-
const rbin = path.resolve(bin);
|
|
4018
|
-
const rtarget = path.resolve(target);
|
|
2727
|
+
const rbin = path$1.resolve(bin);
|
|
2728
|
+
const rtarget = path$1.resolve(target);
|
|
4019
2729
|
if (verbose) {
|
|
4020
2730
|
logger.logger.group('gradle2maven:');
|
|
4021
2731
|
logger.logger.log(`[VERBOSE] - Absolute bin path: \`${rbin}\``);
|
|
@@ -4035,7 +2745,7 @@ async function convertGradleToMaven(target, bin, _out, verbose, gradleOpts) {
|
|
|
4035
2745
|
// I'd prefer something plain-text if it is to be committed.
|
|
4036
2746
|
|
|
4037
2747
|
// Note: init.gradle will be exported by .config/rollup.dist.config.mjs
|
|
4038
|
-
const initLocation = path.join(constants.rootDistPath, 'init.gradle');
|
|
2748
|
+
const initLocation = path$1.join(constants.rootDistPath, 'init.gradle');
|
|
4039
2749
|
const commandArgs = ['--init-script', initLocation, ...gradleOpts, 'pom'];
|
|
4040
2750
|
if (verbose) {
|
|
4041
2751
|
logger.logger.log('[VERBOSE] Executing:', bin, commandArgs);
|
|
@@ -4108,9 +2818,9 @@ async function convertGradleToMaven(target, bin, _out, verbose, gradleOpts) {
|
|
|
4108
2818
|
}
|
|
4109
2819
|
|
|
4110
2820
|
const {
|
|
4111
|
-
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$
|
|
2821
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$s
|
|
4112
2822
|
} = constants;
|
|
4113
|
-
const config$
|
|
2823
|
+
const config$t = {
|
|
4114
2824
|
commandName: 'gradle',
|
|
4115
2825
|
description: '[beta] Use Gradle to generate a manifest file (`pom.xml`) for a Gradle/Java/Kotlin/etc project',
|
|
4116
2826
|
hidden: false,
|
|
@@ -4182,22 +2892,22 @@ const config$s = {
|
|
|
4182
2892
|
`
|
|
4183
2893
|
};
|
|
4184
2894
|
const cmdManifestGradle = {
|
|
4185
|
-
description: config$
|
|
4186
|
-
hidden: config$
|
|
4187
|
-
run: run$
|
|
2895
|
+
description: config$t.description,
|
|
2896
|
+
hidden: config$t.hidden,
|
|
2897
|
+
run: run$t
|
|
4188
2898
|
};
|
|
4189
|
-
async function run$
|
|
2899
|
+
async function run$t(argv, importMeta, {
|
|
4190
2900
|
parentName
|
|
4191
2901
|
}) {
|
|
4192
2902
|
const cli = meowOrExit({
|
|
4193
2903
|
argv,
|
|
4194
|
-
config: config$
|
|
2904
|
+
config: config$t,
|
|
4195
2905
|
importMeta,
|
|
4196
2906
|
parentName
|
|
4197
2907
|
});
|
|
4198
2908
|
const verbose = Boolean(cli.flags['verbose']);
|
|
4199
2909
|
if (verbose) {
|
|
4200
|
-
logger.logger.group('- ', parentName, config$
|
|
2910
|
+
logger.logger.group('- ', parentName, config$t.commandName, ':');
|
|
4201
2911
|
logger.logger.group('- flags:', cli.flags);
|
|
4202
2912
|
logger.logger.groupEnd();
|
|
4203
2913
|
logger.logger.log('- input:', cli.input);
|
|
@@ -4224,7 +2934,7 @@ async function run$s(argv, importMeta, {
|
|
|
4224
2934
|
if (cli.flags['bin']) {
|
|
4225
2935
|
bin = cli.flags['bin'];
|
|
4226
2936
|
} else {
|
|
4227
|
-
bin = path.join(target, 'gradlew');
|
|
2937
|
+
bin = path$1.join(target, 'gradlew');
|
|
4228
2938
|
}
|
|
4229
2939
|
let out = './socket.pom.xml';
|
|
4230
2940
|
if (cli.flags['out']) {
|
|
@@ -4245,7 +2955,7 @@ async function run$s(argv, importMeta, {
|
|
|
4245
2955
|
gradleOpts = cli.flags['gradleOpts'].split(' ').map(s => s.trim()).filter(Boolean);
|
|
4246
2956
|
}
|
|
4247
2957
|
if (cli.flags['dryRun']) {
|
|
4248
|
-
logger.logger.log(DRY_RUN_BAIL_TEXT$
|
|
2958
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$s);
|
|
4249
2959
|
return;
|
|
4250
2960
|
}
|
|
4251
2961
|
await convertGradleToMaven(target, bin, out, verbose, gradleOpts);
|
|
@@ -4256,8 +2966,8 @@ async function convertSbtToMaven(target, bin, out, verbose, sbtOpts) {
|
|
|
4256
2966
|
const {
|
|
4257
2967
|
spinner
|
|
4258
2968
|
} = constants;
|
|
4259
|
-
const rbin = path.resolve(bin);
|
|
4260
|
-
const rtarget = path.resolve(target);
|
|
2969
|
+
const rbin = path$1.resolve(bin);
|
|
2970
|
+
const rtarget = path$1.resolve(target);
|
|
4261
2971
|
if (verbose) {
|
|
4262
2972
|
logger.logger.group('sbt2maven:');
|
|
4263
2973
|
logger.logger.log(`[VERBOSE] - Absolute bin path: \`${rbin}\``);
|
|
@@ -4350,9 +3060,9 @@ async function convertSbtToMaven(target, bin, out, verbose, sbtOpts) {
|
|
|
4350
3060
|
}
|
|
4351
3061
|
|
|
4352
3062
|
const {
|
|
4353
|
-
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$
|
|
3063
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$r
|
|
4354
3064
|
} = constants;
|
|
4355
|
-
const config$
|
|
3065
|
+
const config$s = {
|
|
4356
3066
|
commandName: 'scala',
|
|
4357
3067
|
description: "[beta] Generate a manifest file (`pom.xml`) from Scala's `build.sbt` file",
|
|
4358
3068
|
hidden: false,
|
|
@@ -4425,22 +3135,22 @@ const config$r = {
|
|
|
4425
3135
|
`
|
|
4426
3136
|
};
|
|
4427
3137
|
const cmdManifestScala = {
|
|
4428
|
-
description: config$
|
|
4429
|
-
hidden: config$
|
|
4430
|
-
run: run$
|
|
3138
|
+
description: config$s.description,
|
|
3139
|
+
hidden: config$s.hidden,
|
|
3140
|
+
run: run$s
|
|
4431
3141
|
};
|
|
4432
|
-
async function run$
|
|
3142
|
+
async function run$s(argv, importMeta, {
|
|
4433
3143
|
parentName
|
|
4434
3144
|
}) {
|
|
4435
3145
|
const cli = meowOrExit({
|
|
4436
3146
|
argv,
|
|
4437
|
-
config: config$
|
|
3147
|
+
config: config$s,
|
|
4438
3148
|
importMeta,
|
|
4439
3149
|
parentName
|
|
4440
3150
|
});
|
|
4441
3151
|
const verbose = Boolean(cli.flags['verbose']);
|
|
4442
3152
|
if (verbose) {
|
|
4443
|
-
logger.logger.group('- ', parentName, config$
|
|
3153
|
+
logger.logger.group('- ', parentName, config$s.commandName, ':');
|
|
4444
3154
|
logger.logger.group('- flags:', cli.flags);
|
|
4445
3155
|
logger.logger.groupEnd();
|
|
4446
3156
|
logger.logger.log('- input:', cli.input);
|
|
@@ -4486,16 +3196,16 @@ async function run$r(argv, importMeta, {
|
|
|
4486
3196
|
sbtOpts = cli.flags['sbtOpts'].split(' ').map(s => s.trim()).filter(Boolean);
|
|
4487
3197
|
}
|
|
4488
3198
|
if (cli.flags['dryRun']) {
|
|
4489
|
-
logger.logger.log(DRY_RUN_BAIL_TEXT$
|
|
3199
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$r);
|
|
4490
3200
|
return;
|
|
4491
3201
|
}
|
|
4492
3202
|
await convertSbtToMaven(target, bin, out, verbose, sbtOpts);
|
|
4493
3203
|
}
|
|
4494
3204
|
|
|
4495
3205
|
const {
|
|
4496
|
-
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$
|
|
3206
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$q
|
|
4497
3207
|
} = constants;
|
|
4498
|
-
const config$
|
|
3208
|
+
const config$r = {
|
|
4499
3209
|
commandName: 'auto',
|
|
4500
3210
|
description: 'Auto-detect build and attempt to generate manifest file',
|
|
4501
3211
|
hidden: false,
|
|
@@ -4525,23 +3235,23 @@ const config$q = {
|
|
|
4525
3235
|
`
|
|
4526
3236
|
};
|
|
4527
3237
|
const cmdManifestAuto = {
|
|
4528
|
-
description: config$
|
|
4529
|
-
hidden: config$
|
|
4530
|
-
run: run$
|
|
3238
|
+
description: config$r.description,
|
|
3239
|
+
hidden: config$r.hidden,
|
|
3240
|
+
run: run$r
|
|
4531
3241
|
};
|
|
4532
|
-
async function run$
|
|
3242
|
+
async function run$r(argv, importMeta, {
|
|
4533
3243
|
parentName
|
|
4534
3244
|
}) {
|
|
4535
3245
|
const cli = meowOrExit({
|
|
4536
3246
|
argv,
|
|
4537
|
-
config: config$
|
|
3247
|
+
config: config$r,
|
|
4538
3248
|
importMeta,
|
|
4539
3249
|
parentName
|
|
4540
3250
|
});
|
|
4541
3251
|
const verbose = !!cli.flags['verbose'];
|
|
4542
3252
|
const cwd = cli.flags['cwd'] ?? process.cwd();
|
|
4543
3253
|
if (verbose) {
|
|
4544
|
-
logger.logger.group('- ', parentName, config$
|
|
3254
|
+
logger.logger.group('- ', parentName, config$r.commandName, ':');
|
|
4545
3255
|
logger.logger.group('- flags:', cli.flags);
|
|
4546
3256
|
logger.logger.groupEnd();
|
|
4547
3257
|
logger.logger.log('- input:', cli.input);
|
|
@@ -4553,14 +3263,14 @@ async function run$q(argv, importMeta, {
|
|
|
4553
3263
|
subArgs.push('--verbose');
|
|
4554
3264
|
}
|
|
4555
3265
|
const dir = cwd;
|
|
4556
|
-
if (fs.existsSync(path.join(dir, 'build.sbt'))) {
|
|
3266
|
+
if (fs$1.existsSync(path$1.join(dir, 'build.sbt'))) {
|
|
4557
3267
|
logger.logger.log('Detected a Scala sbt build, running default Scala generator...');
|
|
4558
3268
|
if (cwd) {
|
|
4559
3269
|
subArgs.push('--cwd', cwd);
|
|
4560
3270
|
}
|
|
4561
3271
|
subArgs.push(dir);
|
|
4562
3272
|
if (cli.flags['dryRun']) {
|
|
4563
|
-
logger.logger.log(DRY_RUN_BAIL_TEXT$
|
|
3273
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$q);
|
|
4564
3274
|
return;
|
|
4565
3275
|
}
|
|
4566
3276
|
await cmdManifestScala.run(subArgs, importMeta, {
|
|
@@ -4568,14 +3278,14 @@ async function run$q(argv, importMeta, {
|
|
|
4568
3278
|
});
|
|
4569
3279
|
return;
|
|
4570
3280
|
}
|
|
4571
|
-
if (fs.existsSync(path.join(dir, 'gradlew'))) {
|
|
3281
|
+
if (fs$1.existsSync(path$1.join(dir, 'gradlew'))) {
|
|
4572
3282
|
logger.logger.log('Detected a gradle build, running default gradle generator...');
|
|
4573
3283
|
if (cwd) {
|
|
4574
3284
|
// This command takes the cwd as first arg.
|
|
4575
3285
|
subArgs.push(cwd);
|
|
4576
3286
|
}
|
|
4577
3287
|
if (cli.flags['dryRun']) {
|
|
4578
|
-
logger.logger.log(DRY_RUN_BAIL_TEXT$
|
|
3288
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$q);
|
|
4579
3289
|
return;
|
|
4580
3290
|
}
|
|
4581
3291
|
await cmdManifestGradle.run(subArgs, importMeta, {
|
|
@@ -4584,13 +3294,13 @@ async function run$q(argv, importMeta, {
|
|
|
4584
3294
|
return;
|
|
4585
3295
|
}
|
|
4586
3296
|
if (cli.flags['dryRun']) {
|
|
4587
|
-
logger.logger.log(DRY_RUN_BAIL_TEXT$
|
|
3297
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$q);
|
|
4588
3298
|
return;
|
|
4589
3299
|
}
|
|
4590
3300
|
|
|
4591
3301
|
// Show new help screen and exit.
|
|
4592
3302
|
meow(`
|
|
4593
|
-
$ ${parentName} ${config$
|
|
3303
|
+
$ ${parentName} ${config$r.commandName}
|
|
4594
3304
|
|
|
4595
3305
|
Unfortunately this script did not discover a supported language in the
|
|
4596
3306
|
current folder.
|
|
@@ -4603,13 +3313,13 @@ async function run$q(argv, importMeta, {
|
|
|
4603
3313
|
your target language.
|
|
4604
3314
|
`, {
|
|
4605
3315
|
argv: [],
|
|
4606
|
-
description: config$
|
|
3316
|
+
description: config$r.description,
|
|
4607
3317
|
importMeta
|
|
4608
3318
|
}).showHelp();
|
|
4609
3319
|
}
|
|
4610
3320
|
|
|
4611
3321
|
const {
|
|
4612
|
-
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$
|
|
3322
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$p
|
|
4613
3323
|
} = constants;
|
|
4614
3324
|
|
|
4615
3325
|
// TODO: we may want to dedupe some pieces for all gradle languages. I think it
|
|
@@ -4617,7 +3327,7 @@ const {
|
|
|
4617
3327
|
// sense for the help panels to note the requested language, rather than
|
|
4618
3328
|
// `socket manifest kotlin` to print help screens with `gradle` as the
|
|
4619
3329
|
// command. Room for improvement.
|
|
4620
|
-
const config$
|
|
3330
|
+
const config$q = {
|
|
4621
3331
|
commandName: 'kotlin',
|
|
4622
3332
|
description: '[beta] Use Gradle to generate a manifest file (`pom.xml`) for a Kotlin project',
|
|
4623
3333
|
hidden: false,
|
|
@@ -4689,22 +3399,22 @@ const config$p = {
|
|
|
4689
3399
|
`
|
|
4690
3400
|
};
|
|
4691
3401
|
const cmdManifestKotlin = {
|
|
4692
|
-
description: config$
|
|
4693
|
-
hidden: config$
|
|
4694
|
-
run: run$
|
|
3402
|
+
description: config$q.description,
|
|
3403
|
+
hidden: config$q.hidden,
|
|
3404
|
+
run: run$q
|
|
4695
3405
|
};
|
|
4696
|
-
async function run$
|
|
3406
|
+
async function run$q(argv, importMeta, {
|
|
4697
3407
|
parentName
|
|
4698
3408
|
}) {
|
|
4699
3409
|
const cli = meowOrExit({
|
|
4700
3410
|
argv,
|
|
4701
|
-
config: config$
|
|
3411
|
+
config: config$q,
|
|
4702
3412
|
importMeta,
|
|
4703
3413
|
parentName
|
|
4704
3414
|
});
|
|
4705
3415
|
const verbose = Boolean(cli.flags['verbose']);
|
|
4706
3416
|
if (verbose) {
|
|
4707
|
-
logger.logger.group('- ', parentName, config$
|
|
3417
|
+
logger.logger.group('- ', parentName, config$q.commandName, ':');
|
|
4708
3418
|
logger.logger.group('- flags:', cli.flags);
|
|
4709
3419
|
logger.logger.groupEnd();
|
|
4710
3420
|
logger.logger.log('- input:', cli.input);
|
|
@@ -4731,7 +3441,7 @@ async function run$p(argv, importMeta, {
|
|
|
4731
3441
|
if (cli.flags['bin']) {
|
|
4732
3442
|
bin = cli.flags['bin'];
|
|
4733
3443
|
} else {
|
|
4734
|
-
bin = path.join(target, 'gradlew');
|
|
3444
|
+
bin = path$1.join(target, 'gradlew');
|
|
4735
3445
|
}
|
|
4736
3446
|
let out = './socket.pom.xml';
|
|
4737
3447
|
if (cli.flags['out']) {
|
|
@@ -4752,13 +3462,13 @@ async function run$p(argv, importMeta, {
|
|
|
4752
3462
|
gradleOpts = cli.flags['gradleOpts'].split(' ').map(s => s.trim()).filter(Boolean);
|
|
4753
3463
|
}
|
|
4754
3464
|
if (cli.flags['dryRun']) {
|
|
4755
|
-
logger.logger.log(DRY_RUN_BAIL_TEXT$
|
|
3465
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$p);
|
|
4756
3466
|
return;
|
|
4757
3467
|
}
|
|
4758
3468
|
await convertGradleToMaven(target, bin, out, verbose, gradleOpts);
|
|
4759
3469
|
}
|
|
4760
3470
|
|
|
4761
|
-
const config$
|
|
3471
|
+
const config$p = {
|
|
4762
3472
|
commandName: 'manifest',
|
|
4763
3473
|
description: 'Generate a dependency manifest for given file or dir',
|
|
4764
3474
|
hidden: false,
|
|
@@ -4766,11 +3476,11 @@ const config$o = {
|
|
|
4766
3476
|
...commonFlags
|
|
4767
3477
|
}};
|
|
4768
3478
|
const cmdManifest = {
|
|
4769
|
-
description: config$
|
|
4770
|
-
hidden: config$
|
|
4771
|
-
run: run$
|
|
3479
|
+
description: config$p.description,
|
|
3480
|
+
hidden: config$p.hidden,
|
|
3481
|
+
run: run$p
|
|
4772
3482
|
};
|
|
4773
|
-
async function run$
|
|
3483
|
+
async function run$p(argv, importMeta, {
|
|
4774
3484
|
parentName
|
|
4775
3485
|
}) {
|
|
4776
3486
|
await meowWithSubcommands({
|
|
@@ -4782,15 +3492,15 @@ async function run$o(argv, importMeta, {
|
|
|
4782
3492
|
argv,
|
|
4783
3493
|
aliases: {
|
|
4784
3494
|
yolo: {
|
|
4785
|
-
description: config$
|
|
3495
|
+
description: config$p.description,
|
|
4786
3496
|
hidden: true,
|
|
4787
3497
|
argv: ['auto']
|
|
4788
3498
|
}
|
|
4789
3499
|
},
|
|
4790
|
-
description: config$
|
|
3500
|
+
description: config$p.description,
|
|
4791
3501
|
importMeta,
|
|
4792
|
-
flags: config$
|
|
4793
|
-
name: `${parentName} ${config$
|
|
3502
|
+
flags: config$p.flags,
|
|
3503
|
+
name: `${parentName} ${config$p.commandName}`
|
|
4794
3504
|
});
|
|
4795
3505
|
}
|
|
4796
3506
|
|
|
@@ -4804,10 +3514,10 @@ async function wrapNpm(argv) {
|
|
|
4804
3514
|
}
|
|
4805
3515
|
|
|
4806
3516
|
const {
|
|
4807
|
-
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$
|
|
3517
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$o,
|
|
4808
3518
|
NPM: NPM$7
|
|
4809
3519
|
} = constants;
|
|
4810
|
-
const config$
|
|
3520
|
+
const config$o = {
|
|
4811
3521
|
commandName: 'npm',
|
|
4812
3522
|
description: `${NPM$7} wrapper functionality`,
|
|
4813
3523
|
hidden: false,
|
|
@@ -4818,22 +3528,22 @@ const config$n = {
|
|
|
4818
3528
|
`
|
|
4819
3529
|
};
|
|
4820
3530
|
const cmdNpm = {
|
|
4821
|
-
description: config$
|
|
4822
|
-
hidden: config$
|
|
4823
|
-
run: run$
|
|
3531
|
+
description: config$o.description,
|
|
3532
|
+
hidden: config$o.hidden,
|
|
3533
|
+
run: run$o
|
|
4824
3534
|
};
|
|
4825
|
-
async function run$
|
|
3535
|
+
async function run$o(argv, importMeta, {
|
|
4826
3536
|
parentName
|
|
4827
3537
|
}) {
|
|
4828
3538
|
const cli = meowOrExit({
|
|
4829
3539
|
allowUnknownFlags: true,
|
|
4830
3540
|
argv,
|
|
4831
|
-
config: config$
|
|
3541
|
+
config: config$o,
|
|
4832
3542
|
importMeta,
|
|
4833
3543
|
parentName
|
|
4834
3544
|
});
|
|
4835
3545
|
if (cli.flags['dryRun']) {
|
|
4836
|
-
logger.logger.log(DRY_RUN_BAIL_TEXT$
|
|
3546
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$o);
|
|
4837
3547
|
return;
|
|
4838
3548
|
}
|
|
4839
3549
|
await wrapNpm(argv);
|
|
@@ -4849,10 +3559,10 @@ async function wrapNpx(argv) {
|
|
|
4849
3559
|
}
|
|
4850
3560
|
|
|
4851
3561
|
const {
|
|
4852
|
-
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$
|
|
3562
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$n,
|
|
4853
3563
|
NPX: NPX$1
|
|
4854
3564
|
} = constants;
|
|
4855
|
-
const config$
|
|
3565
|
+
const config$n = {
|
|
4856
3566
|
commandName: 'npx',
|
|
4857
3567
|
description: `${NPX$1} wrapper functionality`,
|
|
4858
3568
|
hidden: false,
|
|
@@ -4863,31 +3573,31 @@ const config$m = {
|
|
|
4863
3573
|
`
|
|
4864
3574
|
};
|
|
4865
3575
|
const cmdNpx = {
|
|
4866
|
-
description: config$
|
|
4867
|
-
hidden: config$
|
|
4868
|
-
run: run$
|
|
3576
|
+
description: config$n.description,
|
|
3577
|
+
hidden: config$n.hidden,
|
|
3578
|
+
run: run$n
|
|
4869
3579
|
};
|
|
4870
|
-
async function run$
|
|
3580
|
+
async function run$n(argv, importMeta, {
|
|
4871
3581
|
parentName
|
|
4872
3582
|
}) {
|
|
4873
3583
|
const cli = meowOrExit({
|
|
4874
3584
|
allowUnknownFlags: true,
|
|
4875
3585
|
argv,
|
|
4876
|
-
config: config$
|
|
3586
|
+
config: config$n,
|
|
4877
3587
|
importMeta,
|
|
4878
3588
|
parentName
|
|
4879
3589
|
});
|
|
4880
3590
|
if (cli.flags['dryRun']) {
|
|
4881
|
-
logger.logger.log(DRY_RUN_BAIL_TEXT$
|
|
3591
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$n);
|
|
4882
3592
|
return;
|
|
4883
3593
|
}
|
|
4884
3594
|
await wrapNpx(argv);
|
|
4885
3595
|
}
|
|
4886
3596
|
|
|
4887
3597
|
const {
|
|
4888
|
-
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$
|
|
3598
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$m
|
|
4889
3599
|
} = constants;
|
|
4890
|
-
const config$
|
|
3600
|
+
const config$m = {
|
|
4891
3601
|
commandName: 'oops',
|
|
4892
3602
|
description: 'Trigger an intentional error (for development)',
|
|
4893
3603
|
hidden: true,
|
|
@@ -4902,21 +3612,21 @@ const config$l = {
|
|
|
4902
3612
|
`
|
|
4903
3613
|
};
|
|
4904
3614
|
const cmdOops = {
|
|
4905
|
-
description: config$
|
|
4906
|
-
hidden: config$
|
|
4907
|
-
run: run$
|
|
3615
|
+
description: config$m.description,
|
|
3616
|
+
hidden: config$m.hidden,
|
|
3617
|
+
run: run$m
|
|
4908
3618
|
};
|
|
4909
|
-
async function run$
|
|
3619
|
+
async function run$m(argv, importMeta, {
|
|
4910
3620
|
parentName
|
|
4911
3621
|
}) {
|
|
4912
3622
|
const cli = meowOrExit({
|
|
4913
3623
|
argv,
|
|
4914
|
-
config: config$
|
|
3624
|
+
config: config$m,
|
|
4915
3625
|
importMeta,
|
|
4916
3626
|
parentName
|
|
4917
3627
|
});
|
|
4918
3628
|
if (cli.flags['dryRun']) {
|
|
4919
|
-
logger.logger.log(DRY_RUN_BAIL_TEXT$
|
|
3629
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$m);
|
|
4920
3630
|
return;
|
|
4921
3631
|
}
|
|
4922
3632
|
throw new Error('This error was intentionally left blank');
|
|
@@ -5035,7 +3745,7 @@ const PNPM_WORKSPACE = `${PNPM$4}-workspace`;
|
|
|
5035
3745
|
async function getWorkspaceGlobs(agent, pkgPath, pkgJson) {
|
|
5036
3746
|
let workspacePatterns;
|
|
5037
3747
|
if (agent === PNPM$4) {
|
|
5038
|
-
for (const workspacePath of [path.join(pkgPath, `${PNPM_WORKSPACE}.yaml`), path.join(pkgPath, `${PNPM_WORKSPACE}.yml`)]) {
|
|
3748
|
+
for (const workspacePath of [path$1.join(pkgPath, `${PNPM_WORKSPACE}.yaml`), path$1.join(pkgPath, `${PNPM_WORKSPACE}.yml`)]) {
|
|
5039
3749
|
// eslint-disable-next-line no-await-in-loop
|
|
5040
3750
|
const yml = await shadowNpmInject.safeReadFile(workspacePath);
|
|
5041
3751
|
if (yml) {
|
|
@@ -5403,7 +4113,7 @@ async function addOverrides(pkgPath, pkgEnvDetails, options) {
|
|
|
5403
4113
|
const {
|
|
5404
4114
|
content: pkgJson
|
|
5405
4115
|
} = editablePkgJson;
|
|
5406
|
-
const workspaceName = path.relative(rootPath, pkgPath);
|
|
4116
|
+
const workspaceName = path$1.relative(rootPath, pkgPath);
|
|
5407
4117
|
const workspaceGlobs = await getWorkspaceGlobs(agent, pkgPath, pkgJson);
|
|
5408
4118
|
const isRoot = pkgPath === rootPath;
|
|
5409
4119
|
const isLockScanned = isRoot && !prod;
|
|
@@ -5537,7 +4247,7 @@ async function addOverrides(pkgPath, pkgEnvDetails, options) {
|
|
|
5537
4247
|
});
|
|
5538
4248
|
// Chunk package names to process them in parallel 3 at a time.
|
|
5539
4249
|
await promises.pEach(workspacePkgJsonPaths, 3, async workspacePkgJsonPath => {
|
|
5540
|
-
const otherState = await addOverrides(path.dirname(workspacePkgJsonPath), pkgEnvDetails, {
|
|
4250
|
+
const otherState = await addOverrides(path$1.dirname(workspacePkgJsonPath), pkgEnvDetails, {
|
|
5541
4251
|
logger,
|
|
5542
4252
|
pin,
|
|
5543
4253
|
prod,
|
|
@@ -5575,7 +4285,7 @@ async function updateLockfile(pkgEnvDetails, options) {
|
|
|
5575
4285
|
__proto__: null,
|
|
5576
4286
|
...options
|
|
5577
4287
|
};
|
|
5578
|
-
const isSpinning = !!spinner?.isSpinning;
|
|
4288
|
+
const isSpinning = !!spinner?.['isSpinning'];
|
|
5579
4289
|
if (!isSpinning) {
|
|
5580
4290
|
spinner?.start();
|
|
5581
4291
|
}
|
|
@@ -5647,9 +4357,9 @@ async function applyOptimization(cwd, pin, prod) {
|
|
|
5647
4357
|
}
|
|
5648
4358
|
|
|
5649
4359
|
const {
|
|
5650
|
-
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$
|
|
4360
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$l
|
|
5651
4361
|
} = constants;
|
|
5652
|
-
const config$
|
|
4362
|
+
const config$l = {
|
|
5653
4363
|
commandName: 'optimize',
|
|
5654
4364
|
description: 'Optimize dependencies with @socketregistry overrides',
|
|
5655
4365
|
hidden: false,
|
|
@@ -5679,22 +4389,22 @@ const config$k = {
|
|
|
5679
4389
|
`
|
|
5680
4390
|
};
|
|
5681
4391
|
const cmdOptimize = {
|
|
5682
|
-
description: config$
|
|
5683
|
-
hidden: config$
|
|
5684
|
-
run: run$
|
|
4392
|
+
description: config$l.description,
|
|
4393
|
+
hidden: config$l.hidden,
|
|
4394
|
+
run: run$l
|
|
5685
4395
|
};
|
|
5686
|
-
async function run$
|
|
4396
|
+
async function run$l(argv, importMeta, {
|
|
5687
4397
|
parentName
|
|
5688
4398
|
}) {
|
|
5689
4399
|
const cli = meowOrExit({
|
|
5690
4400
|
argv,
|
|
5691
|
-
config: config$
|
|
4401
|
+
config: config$l,
|
|
5692
4402
|
importMeta,
|
|
5693
4403
|
parentName
|
|
5694
4404
|
});
|
|
5695
4405
|
const cwd = process$1.cwd();
|
|
5696
4406
|
if (cli.flags['dryRun']) {
|
|
5697
|
-
logger.logger.log(DRY_RUN_BAIL_TEXT$
|
|
4407
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$l);
|
|
5698
4408
|
return;
|
|
5699
4409
|
}
|
|
5700
4410
|
await applyOptimization(cwd, Boolean(cli.flags['pin']), Boolean(cli.flags['prod']));
|
|
@@ -5768,9 +4478,9 @@ async function printOrganizationsFromToken(apiToken, format = 'text') {
|
|
|
5768
4478
|
}
|
|
5769
4479
|
|
|
5770
4480
|
const {
|
|
5771
|
-
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$
|
|
4481
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$k
|
|
5772
4482
|
} = constants;
|
|
5773
|
-
const config$
|
|
4483
|
+
const config$k = {
|
|
5774
4484
|
commandName: 'list',
|
|
5775
4485
|
description: 'List organizations associated with the API key used',
|
|
5776
4486
|
hidden: false,
|
|
@@ -5783,20 +4493,20 @@ const config$j = {
|
|
|
5783
4493
|
$ ${command}
|
|
5784
4494
|
|
|
5785
4495
|
Options
|
|
5786
|
-
${getFlagListOutput(config$
|
|
4496
|
+
${getFlagListOutput(config$k.flags, 6)}
|
|
5787
4497
|
`
|
|
5788
4498
|
};
|
|
5789
4499
|
const cmdOrganizationList = {
|
|
5790
|
-
description: config$
|
|
5791
|
-
hidden: config$
|
|
5792
|
-
run: run$
|
|
4500
|
+
description: config$k.description,
|
|
4501
|
+
hidden: config$k.hidden,
|
|
4502
|
+
run: run$k
|
|
5793
4503
|
};
|
|
5794
|
-
async function run$
|
|
4504
|
+
async function run$k(argv, importMeta, {
|
|
5795
4505
|
parentName
|
|
5796
4506
|
}) {
|
|
5797
4507
|
const cli = meowOrExit({
|
|
5798
4508
|
argv,
|
|
5799
|
-
config: config$
|
|
4509
|
+
config: config$k,
|
|
5800
4510
|
importMeta,
|
|
5801
4511
|
parentName
|
|
5802
4512
|
});
|
|
@@ -5815,7 +4525,7 @@ ${colors.bgRed(colors.white('Input error'))}: Please provide the required fields
|
|
|
5815
4525
|
return;
|
|
5816
4526
|
}
|
|
5817
4527
|
if (cli.flags['dryRun']) {
|
|
5818
|
-
logger.logger.log(DRY_RUN_BAIL_TEXT$
|
|
4528
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$k);
|
|
5819
4529
|
return;
|
|
5820
4530
|
}
|
|
5821
4531
|
await getOrganization(json ? 'json' : markdown ? 'markdown' : 'text');
|
|
@@ -5863,11 +4573,11 @@ async function getSecurityPolicyWithToken(apiToken, orgSlug, format) {
|
|
|
5863
4573
|
}
|
|
5864
4574
|
|
|
5865
4575
|
const {
|
|
5866
|
-
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$
|
|
4576
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$j
|
|
5867
4577
|
} = constants;
|
|
5868
4578
|
|
|
5869
4579
|
// TODO: secret toplevel alias `socket security policy`?
|
|
5870
|
-
const config$
|
|
4580
|
+
const config$j = {
|
|
5871
4581
|
commandName: 'security',
|
|
5872
4582
|
description: 'Retrieve the security policy of an organization.',
|
|
5873
4583
|
hidden: true,
|
|
@@ -5880,7 +4590,7 @@ const config$i = {
|
|
|
5880
4590
|
$ ${command} <org slug>
|
|
5881
4591
|
|
|
5882
4592
|
Options
|
|
5883
|
-
${getFlagListOutput(config$
|
|
4593
|
+
${getFlagListOutput(config$j.flags, 6)}
|
|
5884
4594
|
|
|
5885
4595
|
Your API token will need the \`security-policy:read\` permission otherwise
|
|
5886
4596
|
the request will fail with an authentication error.
|
|
@@ -5891,16 +4601,16 @@ const config$i = {
|
|
|
5891
4601
|
`
|
|
5892
4602
|
};
|
|
5893
4603
|
const cmdOrganizationPolicyPolicy = {
|
|
5894
|
-
description: config$
|
|
5895
|
-
hidden: config$
|
|
5896
|
-
run: run$
|
|
4604
|
+
description: config$j.description,
|
|
4605
|
+
hidden: config$j.hidden,
|
|
4606
|
+
run: run$j
|
|
5897
4607
|
};
|
|
5898
|
-
async function run$
|
|
4608
|
+
async function run$j(argv, importMeta, {
|
|
5899
4609
|
parentName
|
|
5900
4610
|
}) {
|
|
5901
4611
|
const cli = meowOrExit({
|
|
5902
4612
|
argv,
|
|
5903
|
-
config: config$
|
|
4613
|
+
config: config$j,
|
|
5904
4614
|
importMeta,
|
|
5905
4615
|
parentName
|
|
5906
4616
|
});
|
|
@@ -5921,15 +4631,15 @@ ${colors.bgRed(colors.white('Input error'))}: Please provide the required fields
|
|
|
5921
4631
|
return;
|
|
5922
4632
|
}
|
|
5923
4633
|
if (cli.flags['dryRun']) {
|
|
5924
|
-
logger.logger.log(DRY_RUN_BAIL_TEXT$
|
|
4634
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$j);
|
|
5925
4635
|
return;
|
|
5926
4636
|
}
|
|
5927
4637
|
await getSecurityPolicy(orgSlug, json ? 'json' : markdown ? 'markdown' : 'text');
|
|
5928
4638
|
}
|
|
5929
4639
|
|
|
5930
|
-
const description$
|
|
4640
|
+
const description$5 = 'Organization policy details';
|
|
5931
4641
|
const cmdOrganizationPolicy = {
|
|
5932
|
-
description: description$
|
|
4642
|
+
description: description$5,
|
|
5933
4643
|
// Hidden because it was broken all this time (nobody could be using it)
|
|
5934
4644
|
// and we're not sure if it's useful to anyone in its current state.
|
|
5935
4645
|
// Until we do, we'll hide this to keep the help tidier.
|
|
@@ -5942,7 +4652,7 @@ const cmdOrganizationPolicy = {
|
|
|
5942
4652
|
security: cmdOrganizationPolicyPolicy
|
|
5943
4653
|
}, {
|
|
5944
4654
|
argv,
|
|
5945
|
-
description: description$
|
|
4655
|
+
description: description$5,
|
|
5946
4656
|
defaultSub: 'list',
|
|
5947
4657
|
// Backwards compat
|
|
5948
4658
|
importMeta,
|
|
@@ -5993,9 +4703,9 @@ async function getQuotaWithToken(apiToken, format = 'text') {
|
|
|
5993
4703
|
}
|
|
5994
4704
|
|
|
5995
4705
|
const {
|
|
5996
|
-
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$
|
|
4706
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$i
|
|
5997
4707
|
} = constants;
|
|
5998
|
-
const config$
|
|
4708
|
+
const config$i = {
|
|
5999
4709
|
commandName: 'quota',
|
|
6000
4710
|
description: 'List organizations associated with the API key used',
|
|
6001
4711
|
hidden: true,
|
|
@@ -6008,20 +4718,20 @@ const config$h = {
|
|
|
6008
4718
|
$ ${command}
|
|
6009
4719
|
|
|
6010
4720
|
Options
|
|
6011
|
-
${getFlagListOutput(config$
|
|
4721
|
+
${getFlagListOutput(config$i.flags, 6)}
|
|
6012
4722
|
`
|
|
6013
4723
|
};
|
|
6014
4724
|
const cmdOrganizationQuota = {
|
|
6015
|
-
description: config$
|
|
6016
|
-
hidden: config$
|
|
6017
|
-
run: run$
|
|
4725
|
+
description: config$i.description,
|
|
4726
|
+
hidden: config$i.hidden,
|
|
4727
|
+
run: run$i
|
|
6018
4728
|
};
|
|
6019
|
-
async function run$
|
|
4729
|
+
async function run$i(argv, importMeta, {
|
|
6020
4730
|
parentName
|
|
6021
4731
|
}) {
|
|
6022
4732
|
const cli = meowOrExit({
|
|
6023
4733
|
argv,
|
|
6024
|
-
config: config$
|
|
4734
|
+
config: config$i,
|
|
6025
4735
|
importMeta,
|
|
6026
4736
|
parentName
|
|
6027
4737
|
});
|
|
@@ -6040,15 +4750,15 @@ ${colors.bgRed(colors.white('Input error'))}: Please provide the required fields
|
|
|
6040
4750
|
return;
|
|
6041
4751
|
}
|
|
6042
4752
|
if (cli.flags['dryRun']) {
|
|
6043
|
-
logger.logger.log(DRY_RUN_BAIL_TEXT$
|
|
4753
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$i);
|
|
6044
4754
|
return;
|
|
6045
4755
|
}
|
|
6046
4756
|
await getQuota(json ? 'json' : markdown ? 'markdown' : 'text');
|
|
6047
4757
|
}
|
|
6048
4758
|
|
|
6049
|
-
const description$
|
|
4759
|
+
const description$4 = 'Account details';
|
|
6050
4760
|
const cmdOrganization = {
|
|
6051
|
-
description: description$
|
|
4761
|
+
description: description$4,
|
|
6052
4762
|
// Hidden because it was broken all this time (nobody could be using it)
|
|
6053
4763
|
// and we're not sure if it's useful to anyone in its current state.
|
|
6054
4764
|
// Until we do, we'll hide this to keep the help tidier.
|
|
@@ -6063,7 +4773,7 @@ const cmdOrganization = {
|
|
|
6063
4773
|
policy: cmdOrganizationPolicy
|
|
6064
4774
|
}, {
|
|
6065
4775
|
argv,
|
|
6066
|
-
description: description$
|
|
4776
|
+
description: description$4,
|
|
6067
4777
|
defaultSub: 'list',
|
|
6068
4778
|
// Backwards compat
|
|
6069
4779
|
importMeta,
|
|
@@ -6072,6 +4782,298 @@ const cmdOrganization = {
|
|
|
6072
4782
|
}
|
|
6073
4783
|
};
|
|
6074
4784
|
|
|
4785
|
+
// Either an ecosystem was given or all args must be (namespaced) purls
|
|
4786
|
+
// The `pkg:` part is optional here. We'll scan for `eco/name@version`.
|
|
4787
|
+
// Not hardcoding the namespace since we don't know what the server accepts.
|
|
4788
|
+
// The ecosystem is considered as the first package if it is not an a-z string.
|
|
4789
|
+
function parsePackageSpecifiers(ecosystem, pkgs) {
|
|
4790
|
+
let valid = true;
|
|
4791
|
+
const purls = [];
|
|
4792
|
+
if (!ecosystem) {
|
|
4793
|
+
valid = false;
|
|
4794
|
+
} else if (/^[a-zA-Z]+$/.test(ecosystem)) {
|
|
4795
|
+
for (let i = 0; i < pkgs.length; ++i) {
|
|
4796
|
+
const pkg = pkgs[i] ?? '';
|
|
4797
|
+
if (!pkg) {
|
|
4798
|
+
valid = false;
|
|
4799
|
+
break;
|
|
4800
|
+
} else if (pkg.startsWith('pkg:')) {
|
|
4801
|
+
// keep
|
|
4802
|
+
purls.push(pkg);
|
|
4803
|
+
} else if (pkg.includes('/')) {
|
|
4804
|
+
// Looks like this arg was already namespaced
|
|
4805
|
+
purls.push('pkg:' + pkg);
|
|
4806
|
+
} else {
|
|
4807
|
+
purls.push('pkg:' + ecosystem + '/' + pkg);
|
|
4808
|
+
}
|
|
4809
|
+
}
|
|
4810
|
+
if (!purls.length) {
|
|
4811
|
+
valid = false;
|
|
4812
|
+
}
|
|
4813
|
+
} else {
|
|
4814
|
+
// Assume ecosystem is a purl, too
|
|
4815
|
+
pkgs.unshift(ecosystem);
|
|
4816
|
+
for (let i = 0; i < pkgs.length; ++i) {
|
|
4817
|
+
const pkg = pkgs[i] ?? '';
|
|
4818
|
+
if (!/^(?:pkg:)?[a-zA-Z]+\/./.test(pkg)) {
|
|
4819
|
+
// At least one purl did not start with `pkg:eco/x` or `eco/x`
|
|
4820
|
+
valid = false;
|
|
4821
|
+
break;
|
|
4822
|
+
} else if (pkg.startsWith('pkg:')) {
|
|
4823
|
+
purls.push(pkg);
|
|
4824
|
+
} else {
|
|
4825
|
+
purls.push('pkg:' + pkg);
|
|
4826
|
+
}
|
|
4827
|
+
}
|
|
4828
|
+
if (!purls.length) {
|
|
4829
|
+
valid = false;
|
|
4830
|
+
}
|
|
4831
|
+
}
|
|
4832
|
+
return {
|
|
4833
|
+
purls,
|
|
4834
|
+
valid
|
|
4835
|
+
};
|
|
4836
|
+
}
|
|
4837
|
+
|
|
4838
|
+
async function fetchPackageInfo(purls) {
|
|
4839
|
+
const socketSdk = await shadowNpmInject.setupSdk(shadowNpmInject.getPublicToken());
|
|
4840
|
+
|
|
4841
|
+
// Lazily access constants.spinner.
|
|
4842
|
+
const {
|
|
4843
|
+
spinner
|
|
4844
|
+
} = constants;
|
|
4845
|
+
logger.logger.error(`Requesting shallow score data for ${purls.length} package urls (purl): ${purls.join(', ')}`);
|
|
4846
|
+
spinner.start(`Requesting data ...`);
|
|
4847
|
+
const result = await handleApiCall(socketSdk.batchPackageFetch({
|
|
4848
|
+
alerts: 'true'
|
|
4849
|
+
// compact: false,
|
|
4850
|
+
// fixable: false,
|
|
4851
|
+
// licenseattrib: false,
|
|
4852
|
+
// licensedetails: false
|
|
4853
|
+
}, {
|
|
4854
|
+
components: purls.map(purl => ({
|
|
4855
|
+
purl
|
|
4856
|
+
}))
|
|
4857
|
+
}), 'looking up package');
|
|
4858
|
+
spinner.successAndStop('Request completed');
|
|
4859
|
+
if (result.success) {
|
|
4860
|
+
return result;
|
|
4861
|
+
} else {
|
|
4862
|
+
handleUnsuccessfulApiResponse('batchPackageFetch', result);
|
|
4863
|
+
}
|
|
4864
|
+
}
|
|
4865
|
+
|
|
4866
|
+
function logPackageInfo(purls, packageData, outputKind) {
|
|
4867
|
+
if (outputKind === 'json') {
|
|
4868
|
+
// In JSON simply return what the server responds with. Don't bother trying
|
|
4869
|
+
// to match the response with the requested packages/purls.
|
|
4870
|
+
logger.logger.log(JSON.stringify(packageData, undefined, 2));
|
|
4871
|
+
return;
|
|
4872
|
+
}
|
|
4873
|
+
|
|
4874
|
+
// Make some effort to match the requested data with the response
|
|
4875
|
+
|
|
4876
|
+
const set = new Set();
|
|
4877
|
+
packageData.forEach(data => {
|
|
4878
|
+
set.add('pkg:' + data.type + '/' + data.name + '@' + data.version);
|
|
4879
|
+
set.add('pkg:' + data.type + '/' + data.name);
|
|
4880
|
+
});
|
|
4881
|
+
const missing = purls.filter(purl => {
|
|
4882
|
+
if (set.has(purl)) return false;
|
|
4883
|
+
if (purl.endsWith('@latest') && set.has(purl.slice(0, -'@latest'.length))) return false;
|
|
4884
|
+
return true; // not found
|
|
4885
|
+
});
|
|
4886
|
+
if (outputKind === 'markdown') {
|
|
4887
|
+
logger.logger.log(commonTags.stripIndents`
|
|
4888
|
+
# Shallow Package Report
|
|
4889
|
+
|
|
4890
|
+
This report contains the response for requesting data on some package url(s).
|
|
4891
|
+
|
|
4892
|
+
Please note: The listed scores are ONLY for the package itself. It does NOT
|
|
4893
|
+
reflect the scores of any dependencies, transitive or otherwise.
|
|
4894
|
+
|
|
4895
|
+
${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('')}` : ''}
|
|
4896
|
+
|
|
4897
|
+
${packageData.map(data => '## ' + formatReportCard(data, false)).join('\n\n\n')}
|
|
4898
|
+
`);
|
|
4899
|
+
return;
|
|
4900
|
+
}
|
|
4901
|
+
logger.logger.log('\n' + colors.bold('Shallow Package Score') + '\n');
|
|
4902
|
+
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.');
|
|
4903
|
+
if (missing.length) {
|
|
4904
|
+
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('')}`);
|
|
4905
|
+
}
|
|
4906
|
+
packageData.forEach(data => {
|
|
4907
|
+
logger.logger.log('\n');
|
|
4908
|
+
logger.logger.log(formatReportCard(data, true));
|
|
4909
|
+
});
|
|
4910
|
+
logger.logger.log('');
|
|
4911
|
+
}
|
|
4912
|
+
function formatReportCard(data, color) {
|
|
4913
|
+
const scoreResult = {
|
|
4914
|
+
'Supply Chain Risk': Math.floor((data.score?.supplyChain ?? 0) * 100),
|
|
4915
|
+
Maintenance: Math.floor((data.score?.maintenance ?? 0) * 100),
|
|
4916
|
+
Quality: Math.floor((data.score?.quality ?? 0) * 100),
|
|
4917
|
+
Vulnerabilities: Math.floor((data.score?.vulnerability ?? 0) * 100),
|
|
4918
|
+
License: Math.floor((data.score?.license ?? 0) * 100)
|
|
4919
|
+
};
|
|
4920
|
+
const alertString = getAlertString(data.alerts, !color);
|
|
4921
|
+
const purl = 'pkg:' + data.type + '/' + data.name + '@' + data.version;
|
|
4922
|
+
return ['Package: ' + (color ? colors.bold(purl) : purl), '', ...Object.entries(scoreResult).map(score => `- ${score[0]}:`.padEnd(20, ' ') + ` ${formatScore(score[1], !color, true)}`), alertString].join('\n');
|
|
4923
|
+
}
|
|
4924
|
+
function formatScore(score, noColor = false, pad = false) {
|
|
4925
|
+
const padded = String(score).padStart(pad ? 3 : 0, ' ');
|
|
4926
|
+
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);
|
|
4927
|
+
}
|
|
4928
|
+
function getAlertString(alerts, noColor = false) {
|
|
4929
|
+
if (!alerts?.length) {
|
|
4930
|
+
return noColor ? `- Alerts: none!` : `- Alerts: ${colors.green('none')}!`;
|
|
4931
|
+
} else {
|
|
4932
|
+
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);
|
|
4933
|
+
const mid = alerts.filter(alert => alert.severity === 'middle').sort((a, b) => a.type < b.type ? -1 : a.type > b.type ? 1 : 0);
|
|
4934
|
+
const low = alerts.filter(alert => alert.severity === 'low').sort((a, b) => a.type < b.type ? -1 : a.type > b.type ? 1 : 0);
|
|
4935
|
+
|
|
4936
|
+
// We need to create the no-color string regardless because the actual string
|
|
4937
|
+
// contains a bunch of invisible ANSI chars which would screw up length checks.
|
|
4938
|
+
const colorless = `- Alerts (${bad.length}/${mid.length.toString()}/${low.length}):`;
|
|
4939
|
+
if (noColor) {
|
|
4940
|
+
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(', ');
|
|
4941
|
+
}
|
|
4942
|
+
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(', ');
|
|
4943
|
+
}
|
|
4944
|
+
}
|
|
4945
|
+
|
|
4946
|
+
async function showPurlInfo({
|
|
4947
|
+
outputKind,
|
|
4948
|
+
purls
|
|
4949
|
+
}) {
|
|
4950
|
+
const packageData = await fetchPackageInfo(purls);
|
|
4951
|
+
if (packageData) {
|
|
4952
|
+
logPackageInfo(purls, packageData.data, outputKind);
|
|
4953
|
+
}
|
|
4954
|
+
}
|
|
4955
|
+
|
|
4956
|
+
const {
|
|
4957
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$h
|
|
4958
|
+
} = constants;
|
|
4959
|
+
const config$h = {
|
|
4960
|
+
commandName: 'shallow',
|
|
4961
|
+
description: 'Look up info regarding one or more packages but not their transitives',
|
|
4962
|
+
hidden: true,
|
|
4963
|
+
flags: {
|
|
4964
|
+
...commonFlags,
|
|
4965
|
+
...outputFlags
|
|
4966
|
+
},
|
|
4967
|
+
help: (command, config) => `
|
|
4968
|
+
Usage
|
|
4969
|
+
$ ${command} <<ecosystem> <name> [<name> ...] | <purl> [<purl> ...]>
|
|
4970
|
+
|
|
4971
|
+
Options
|
|
4972
|
+
${getFlagListOutput(config.flags, 6)}
|
|
4973
|
+
|
|
4974
|
+
Requirements
|
|
4975
|
+
- quota: 100
|
|
4976
|
+
- scope: \`packages:list\`
|
|
4977
|
+
|
|
4978
|
+
Show scoring details for one or more packages purely based on their own package.
|
|
4979
|
+
This means that any dependency scores are not reflected by the score. You can
|
|
4980
|
+
use the \`socket package score <pkg>\` command to get its full transitive score.
|
|
4981
|
+
|
|
4982
|
+
Only a few ecosystems are supported like npm, golang, and maven.
|
|
4983
|
+
|
|
4984
|
+
A "purl" is a standard package name formatting: \`pkg:eco/name@version\`
|
|
4985
|
+
This command will automatically prepend "pkg:" when not present.
|
|
4986
|
+
|
|
4987
|
+
If the first arg is an ecosystem, remaining args that are not a purl are
|
|
4988
|
+
assumed to be scoped to that ecosystem.
|
|
4989
|
+
|
|
4990
|
+
Examples
|
|
4991
|
+
$ ${command} npm webtorrent
|
|
4992
|
+
$ ${command} npm webtorrent@1.9.1
|
|
4993
|
+
$ ${command} npm/webtorrent@1.9.1
|
|
4994
|
+
$ ${command} pkg:npm/webtorrent@1.9.1
|
|
4995
|
+
$ ${command} maven webtorrent babel
|
|
4996
|
+
$ ${command} npm/webtorrent golang/babel
|
|
4997
|
+
$ ${command} npm npm/webtorrent@1.0.1 babel
|
|
4998
|
+
`
|
|
4999
|
+
};
|
|
5000
|
+
const cmdPackageShallow = {
|
|
5001
|
+
description: config$h.description,
|
|
5002
|
+
hidden: config$h.hidden,
|
|
5003
|
+
alias: {
|
|
5004
|
+
shallowScore: {
|
|
5005
|
+
description: config$h.description,
|
|
5006
|
+
hidden: true,
|
|
5007
|
+
argv: []
|
|
5008
|
+
}
|
|
5009
|
+
},
|
|
5010
|
+
run: run$h
|
|
5011
|
+
};
|
|
5012
|
+
async function run$h(argv, importMeta, {
|
|
5013
|
+
parentName
|
|
5014
|
+
}) {
|
|
5015
|
+
const cli = meowOrExit({
|
|
5016
|
+
argv,
|
|
5017
|
+
config: config$h,
|
|
5018
|
+
importMeta,
|
|
5019
|
+
parentName
|
|
5020
|
+
});
|
|
5021
|
+
const {
|
|
5022
|
+
json,
|
|
5023
|
+
markdown
|
|
5024
|
+
} = cli.flags;
|
|
5025
|
+
const [ecosystem = '', ...pkgs] = cli.input;
|
|
5026
|
+
const {
|
|
5027
|
+
purls,
|
|
5028
|
+
valid
|
|
5029
|
+
} = parsePackageSpecifiers(ecosystem, pkgs);
|
|
5030
|
+
if (!valid || !purls.length) {
|
|
5031
|
+
// Use exit status of 2 to indicate incorrect usage, generally invalid
|
|
5032
|
+
// options or missing arguments.
|
|
5033
|
+
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
5034
|
+
process.exitCode = 2;
|
|
5035
|
+
logger.logger.fail(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
5036
|
+
- First parameter should be an ecosystem or all args must be purls ${!valid ? colors.red('(bad!)') : colors.green('(ok)')}\n
|
|
5037
|
+
- Expecting at least one package ${!purls.length ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
5038
|
+
`);
|
|
5039
|
+
return;
|
|
5040
|
+
}
|
|
5041
|
+
if (cli.flags['dryRun']) {
|
|
5042
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$h);
|
|
5043
|
+
return;
|
|
5044
|
+
}
|
|
5045
|
+
await showPurlInfo({
|
|
5046
|
+
outputKind: json ? 'json' : markdown ? 'markdown' : 'text',
|
|
5047
|
+
purls
|
|
5048
|
+
});
|
|
5049
|
+
}
|
|
5050
|
+
|
|
5051
|
+
const description$3 = 'Commands relating to looking up published packages';
|
|
5052
|
+
const cmdPackage = {
|
|
5053
|
+
description: description$3,
|
|
5054
|
+
hidden: true,
|
|
5055
|
+
// [beta]
|
|
5056
|
+
async run(argv, importMeta, {
|
|
5057
|
+
parentName
|
|
5058
|
+
}) {
|
|
5059
|
+
await meowWithSubcommands({
|
|
5060
|
+
shallow: cmdPackageShallow
|
|
5061
|
+
}, {
|
|
5062
|
+
aliases: {
|
|
5063
|
+
pkg: {
|
|
5064
|
+
description: description$3,
|
|
5065
|
+
hidden: true,
|
|
5066
|
+
argv: []
|
|
5067
|
+
}
|
|
5068
|
+
},
|
|
5069
|
+
argv,
|
|
5070
|
+
description: description$3,
|
|
5071
|
+
importMeta,
|
|
5072
|
+
name: parentName + ' package'
|
|
5073
|
+
});
|
|
5074
|
+
}
|
|
5075
|
+
};
|
|
5076
|
+
|
|
6075
5077
|
async function runRawNpm(argv) {
|
|
6076
5078
|
const spawnPromise = spawn.spawn(shadowNpmPaths.getNpmBinPath(), argv, {
|
|
6077
5079
|
stdio: 'inherit'
|
|
@@ -6399,7 +5401,7 @@ async function run$e(argv, importMeta, {
|
|
|
6399
5401
|
|
|
6400
5402
|
// TODO: Allow setting a custom cwd and/or configFile path?
|
|
6401
5403
|
const cwd = process$1.cwd();
|
|
6402
|
-
const absoluteConfigPath = path.join(cwd, 'socket.yml');
|
|
5404
|
+
const absoluteConfigPath = path$1.join(cwd, 'socket.yml');
|
|
6403
5405
|
const dryRun = Boolean(cli.flags['dryRun']);
|
|
6404
5406
|
const json = Boolean(cli.flags['json']);
|
|
6405
5407
|
const markdown = Boolean(cli.flags['markdown']);
|
|
@@ -6780,8 +5782,8 @@ async function listReposWithToken({
|
|
|
6780
5782
|
const result = await handleApiCall(socketSdk.getOrgRepoList(orgSlug, {
|
|
6781
5783
|
sort,
|
|
6782
5784
|
direction,
|
|
6783
|
-
per_page,
|
|
6784
|
-
page
|
|
5785
|
+
per_page: String(per_page),
|
|
5786
|
+
page: String(page)
|
|
6785
5787
|
}), 'listing repositories');
|
|
6786
5788
|
if (!result.success) {
|
|
6787
5789
|
handleUnsuccessfulApiResponse('getOrgRepoList', result);
|
|
@@ -7242,13 +6244,13 @@ async function suggestRepoSlug(socketSdk, orgSlug) {
|
|
|
7242
6244
|
// There's no guarantee that the cwd is part of this page. If it's not
|
|
7243
6245
|
// then do an additional request and specific search for it instead.
|
|
7244
6246
|
// This way we can offer the tip of "do you want to create [cwd]?".
|
|
7245
|
-
perPage: 10,
|
|
7246
|
-
page: 0
|
|
6247
|
+
perPage: '10',
|
|
6248
|
+
page: '0'
|
|
7247
6249
|
}), 'looking up known repos');
|
|
7248
6250
|
// Ignore a failed request here. It was not the primary goal of
|
|
7249
6251
|
// running this command and reporting it only leads to end-user confusion.
|
|
7250
6252
|
if (result.success) {
|
|
7251
|
-
const currentDirName = dirNameToSlug(path.basename(process$1.cwd()));
|
|
6253
|
+
const currentDirName = dirNameToSlug(path$1.basename(process$1.cwd()));
|
|
7252
6254
|
let cwdIsKnown = !!currentDirName && result.data.results.some(obj => obj.slug === currentDirName);
|
|
7253
6255
|
if (!cwdIsKnown && currentDirName) {
|
|
7254
6256
|
// Do an explicit request so we can assert that the cwd exists or not
|
|
@@ -7468,9 +6470,9 @@ async function createFullScan({
|
|
|
7468
6470
|
repo: repoName,
|
|
7469
6471
|
branch: branchName,
|
|
7470
6472
|
commit_message: commitMessage,
|
|
7471
|
-
make_default_branch: defaultBranch,
|
|
7472
|
-
set_as_pending_head: pendingHead,
|
|
7473
|
-
tmp
|
|
6473
|
+
make_default_branch: String(defaultBranch),
|
|
6474
|
+
set_as_pending_head: String(pendingHead),
|
|
6475
|
+
tmp: String(tmp)
|
|
7474
6476
|
}, packagePaths, cwd), 'Creating scan');
|
|
7475
6477
|
if (!result.success) {
|
|
7476
6478
|
handleUnsuccessfulApiResponse('CreateOrgFullScan', result);
|
|
@@ -7787,8 +6789,8 @@ async function listFullScansWithToken({
|
|
|
7787
6789
|
const result = await handleApiCall(socketSdk.getOrgFullScanList(orgSlug, {
|
|
7788
6790
|
sort,
|
|
7789
6791
|
direction,
|
|
7790
|
-
per_page,
|
|
7791
|
-
page,
|
|
6792
|
+
per_page: String(per_page),
|
|
6793
|
+
page: String(page),
|
|
7792
6794
|
from: from_time
|
|
7793
6795
|
}), 'Listing scans');
|
|
7794
6796
|
if (!result.success) {
|
|
@@ -8396,7 +7398,7 @@ async function reportFullScan({
|
|
|
8396
7398
|
const json = short ? JSON.stringify(scanReport) : toJsonReport(scanReport);
|
|
8397
7399
|
if (filePath && filePath !== '-') {
|
|
8398
7400
|
logger.logger.log('Writing json report to', filePath);
|
|
8399
|
-
return await fs
|
|
7401
|
+
return await fs.writeFile(filePath, json);
|
|
8400
7402
|
}
|
|
8401
7403
|
logger.logger.log(json);
|
|
8402
7404
|
return;
|
|
@@ -8405,7 +7407,7 @@ async function reportFullScan({
|
|
|
8405
7407
|
const md = short ? `healthy = ${scanReport.healthy}` : toMarkdownReport(scanReport);
|
|
8406
7408
|
if (filePath && filePath !== '-') {
|
|
8407
7409
|
logger.logger.log('Writing markdown report to', filePath);
|
|
8408
|
-
return await fs
|
|
7410
|
+
return await fs.writeFile(filePath, md);
|
|
8409
7411
|
}
|
|
8410
7412
|
logger.logger.log(md);
|
|
8411
7413
|
return;
|
|
@@ -8646,7 +7648,7 @@ View this report at: https://socket.dev/dashboard/org/${orgSlug}/sbom/${fullScan
|
|
|
8646
7648
|
`.trim() + '\n';
|
|
8647
7649
|
if (filePath && filePath !== '-') {
|
|
8648
7650
|
try {
|
|
8649
|
-
await fs
|
|
7651
|
+
await fs.writeFile(filePath, report, 'utf8');
|
|
8650
7652
|
logger.logger.log(`Data successfully written to ${filePath}`);
|
|
8651
7653
|
} catch (e) {
|
|
8652
7654
|
process.exitCode = 1;
|
|
@@ -9009,7 +8011,7 @@ async function run$1(argv, importMeta, {
|
|
|
9009
8011
|
}
|
|
9010
8012
|
|
|
9011
8013
|
function addSocketWrapper(file) {
|
|
9012
|
-
return fs.appendFile(file, 'alias npm="socket npm"\nalias npx="socket npx"\n', err => {
|
|
8014
|
+
return fs$1.appendFile(file, 'alias npm="socket npm"\nalias npx="socket npx"\n', err => {
|
|
9013
8015
|
if (err) {
|
|
9014
8016
|
return new Error(`There was an error setting up the alias: ${err}`);
|
|
9015
8017
|
}
|
|
@@ -9023,7 +8025,7 @@ If you want to disable it at any time, run \`socket wrapper --disable\`
|
|
|
9023
8025
|
}
|
|
9024
8026
|
|
|
9025
8027
|
function checkSocketWrapperSetup(file) {
|
|
9026
|
-
const fileContent = fs.readFileSync(file, 'utf8');
|
|
8028
|
+
const fileContent = fs$1.readFileSync(file, 'utf8');
|
|
9027
8029
|
const linesWithSocketAlias = fileContent.split('\n').filter(l => l === 'alias npm="socket npm"' || l === 'alias npx="socket npx"');
|
|
9028
8030
|
if (linesWithSocketAlias.length) {
|
|
9029
8031
|
logger.logger.log(`The Socket npm/npx wrapper is set up in your bash profile (${file}).`);
|
|
@@ -9038,7 +8040,7 @@ function postinstallWrapper() {
|
|
|
9038
8040
|
bashRcPath,
|
|
9039
8041
|
zshRcPath
|
|
9040
8042
|
} = constants;
|
|
9041
|
-
const socketWrapperEnabled = fs.existsSync(bashRcPath) && checkSocketWrapperSetup(bashRcPath) || fs.existsSync(zshRcPath) && checkSocketWrapperSetup(zshRcPath);
|
|
8043
|
+
const socketWrapperEnabled = fs$1.existsSync(bashRcPath) && checkSocketWrapperSetup(bashRcPath) || fs$1.existsSync(zshRcPath) && checkSocketWrapperSetup(zshRcPath);
|
|
9042
8044
|
if (!socketWrapperEnabled) {
|
|
9043
8045
|
installSafeNpm(`The Socket CLI is now successfully installed! 🎉
|
|
9044
8046
|
|
|
@@ -9070,10 +8072,10 @@ function askQuestion(rl, query) {
|
|
|
9070
8072
|
zshRcPath
|
|
9071
8073
|
} = constants;
|
|
9072
8074
|
try {
|
|
9073
|
-
if (fs.existsSync(bashRcPath)) {
|
|
8075
|
+
if (fs$1.existsSync(bashRcPath)) {
|
|
9074
8076
|
addSocketWrapper(bashRcPath);
|
|
9075
8077
|
}
|
|
9076
|
-
if (fs.existsSync(zshRcPath)) {
|
|
8078
|
+
if (fs$1.existsSync(zshRcPath)) {
|
|
9077
8079
|
addSocketWrapper(zshRcPath);
|
|
9078
8080
|
}
|
|
9079
8081
|
} catch (e) {
|
|
@@ -9089,7 +8091,7 @@ function askQuestion(rl, query) {
|
|
|
9089
8091
|
}
|
|
9090
8092
|
|
|
9091
8093
|
function removeSocketWrapper(file) {
|
|
9092
|
-
return fs.readFile(file, 'utf8', function (err, data) {
|
|
8094
|
+
return fs$1.readFile(file, 'utf8', function (err, data) {
|
|
9093
8095
|
if (err) {
|
|
9094
8096
|
logger.logger.fail('There was an error removing the alias:');
|
|
9095
8097
|
logger.logger.error(err);
|
|
@@ -9097,7 +8099,7 @@ function removeSocketWrapper(file) {
|
|
|
9097
8099
|
}
|
|
9098
8100
|
const linesWithoutSocketAlias = data.split('\n').filter(l => l !== 'alias npm="socket npm"' && l !== 'alias npx="socket npx"');
|
|
9099
8101
|
const updatedFileContent = linesWithoutSocketAlias.join('\n');
|
|
9100
|
-
fs.writeFile(file, updatedFileContent, function (err) {
|
|
8102
|
+
fs$1.writeFile(file, updatedFileContent, function (err) {
|
|
9101
8103
|
if (err) {
|
|
9102
8104
|
logger.logger.error(err);
|
|
9103
8105
|
return;
|
|
@@ -9186,21 +8188,21 @@ async function run(argv, importMeta, {
|
|
|
9186
8188
|
zshRcPath
|
|
9187
8189
|
} = constants;
|
|
9188
8190
|
if (enable) {
|
|
9189
|
-
if (fs.existsSync(bashRcPath) && !checkSocketWrapperSetup(bashRcPath)) {
|
|
8191
|
+
if (fs$1.existsSync(bashRcPath) && !checkSocketWrapperSetup(bashRcPath)) {
|
|
9190
8192
|
addSocketWrapper(bashRcPath);
|
|
9191
8193
|
}
|
|
9192
|
-
if (fs.existsSync(zshRcPath) && !checkSocketWrapperSetup(zshRcPath)) {
|
|
8194
|
+
if (fs$1.existsSync(zshRcPath) && !checkSocketWrapperSetup(zshRcPath)) {
|
|
9193
8195
|
addSocketWrapper(zshRcPath);
|
|
9194
8196
|
}
|
|
9195
8197
|
} else {
|
|
9196
|
-
if (fs.existsSync(bashRcPath)) {
|
|
8198
|
+
if (fs$1.existsSync(bashRcPath)) {
|
|
9197
8199
|
removeSocketWrapper(bashRcPath);
|
|
9198
8200
|
}
|
|
9199
|
-
if (fs.existsSync(zshRcPath)) {
|
|
8201
|
+
if (fs$1.existsSync(zshRcPath)) {
|
|
9200
8202
|
removeSocketWrapper(zshRcPath);
|
|
9201
8203
|
}
|
|
9202
8204
|
}
|
|
9203
|
-
if (!fs.existsSync(bashRcPath) && !fs.existsSync(zshRcPath)) {
|
|
8205
|
+
if (!fs$1.existsSync(bashRcPath) && !fs$1.existsSync(zshRcPath)) {
|
|
9204
8206
|
logger.logger.fail('There was an issue setting up the alias in your bash profile');
|
|
9205
8207
|
}
|
|
9206
8208
|
}
|
|
@@ -9214,12 +8216,11 @@ void (async () => {
|
|
|
9214
8216
|
await updateNotifier({
|
|
9215
8217
|
name: SOCKET_CLI_BIN_NAME,
|
|
9216
8218
|
// The '@rollup/plugin-replace' will replace "process.env['INLINED_SOCKET_CLI_VERSION']".
|
|
9217
|
-
version: "0.14.
|
|
8219
|
+
version: "0.14.63",
|
|
9218
8220
|
ttl: 86_400_000 /* 24 hours in milliseconds */
|
|
9219
8221
|
});
|
|
9220
8222
|
try {
|
|
9221
8223
|
await meowWithSubcommands({
|
|
9222
|
-
action: cmdAction,
|
|
9223
8224
|
cdxgen: cmdCdxgen,
|
|
9224
8225
|
fix: cmdFix,
|
|
9225
8226
|
info: cmdInfo,
|
|
@@ -9230,6 +8231,7 @@ void (async () => {
|
|
|
9230
8231
|
oops: cmdOops,
|
|
9231
8232
|
optimize: cmdOptimize,
|
|
9232
8233
|
organization: cmdOrganization,
|
|
8234
|
+
package: cmdPackage,
|
|
9233
8235
|
'raw-npm': cmdRawNpm,
|
|
9234
8236
|
'raw-npx': cmdRawNpx,
|
|
9235
8237
|
report: cmdReport,
|
|
@@ -9281,5 +8283,5 @@ void (async () => {
|
|
|
9281
8283
|
await shadowNpmInject.captureException(e);
|
|
9282
8284
|
}
|
|
9283
8285
|
})();
|
|
9284
|
-
//# debugId=
|
|
8286
|
+
//# debugId=1342b1a0-23ef-45f8-ac9e-6652fb5e5b32
|
|
9285
8287
|
//# sourceMappingURL=cli.js.map
|