@socketsecurity/cli-with-sentry 0.14.51 → 0.14.53
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 +10 -15
- package/dist/constants.d.ts +29 -4
- package/dist/constants.js +8 -2
- package/dist/constants.js.map +1 -1
- package/dist/instrument-with-sentry.js +7 -10
- package/dist/instrument-with-sentry.js.map +1 -1
- package/dist/module-sync/cli.js +670 -446
- package/dist/module-sync/cli.js.map +1 -1
- package/dist/module-sync/edge.d.ts +1 -1
- package/dist/module-sync/index.d.ts +22 -22
- package/dist/module-sync/index.js +5 -4
- package/dist/module-sync/index.js.map +1 -1
- package/dist/module-sync/npm-paths.js +12 -23
- package/dist/module-sync/npm-paths.js.map +1 -1
- package/dist/module-sync/path-resolve.d.ts +1 -2
- package/dist/module-sync/reify.d.ts +8 -8
- package/dist/module-sync/settings.d.ts +1 -1
- package/dist/module-sync/shadow-bin.js +5 -10
- package/dist/module-sync/shadow-bin.js.map +1 -1
- package/dist/require/cli.js +670 -446
- package/dist/require/cli.js.map +1 -1
- package/package.json +5 -5
- package/dist/module-sync/debug.d.ts +0 -3
- package/dist/module-sync/npm.d.ts +0 -26
- package/dist/module-sync/npm.js +0 -113
- package/dist/module-sync/npm.js.map +0 -1
- package/dist/require/npm.js +0 -3
package/dist/require/cli.js
CHANGED
|
@@ -24,13 +24,12 @@ var fs = require('node:fs');
|
|
|
24
24
|
var path = require('node:path');
|
|
25
25
|
var ndjson = _socketInterop(require('ndjson'));
|
|
26
26
|
var index = require('./index.js');
|
|
27
|
+
var constants = require('./constants.js');
|
|
27
28
|
var objects = require('@socketsecurity/registry/lib/objects');
|
|
28
29
|
var regexps = require('@socketsecurity/registry/lib/regexps');
|
|
29
|
-
var constants = require('./constants.js');
|
|
30
30
|
var fs$1 = require('node:fs/promises');
|
|
31
31
|
var ScreenWidget = _socketInterop(require('blessed/lib/widgets/screen'));
|
|
32
32
|
var contrib = _socketInterop(require('blessed-contrib'));
|
|
33
|
-
var spinner = require('@socketsecurity/registry/lib/spinner');
|
|
34
33
|
var prompts = require('@socketsecurity/registry/lib/prompts');
|
|
35
34
|
var yargsParse = _socketInterop(require('yargs-parser'));
|
|
36
35
|
var words = require('@socketsecurity/registry/lib/words');
|
|
@@ -42,7 +41,7 @@ var packages = require('@socketsecurity/registry/lib/packages');
|
|
|
42
41
|
var registryConstants = require('@socketsecurity/registry/lib/constants');
|
|
43
42
|
var isInteractive = require('@socketregistry/is-interactive/index.cjs');
|
|
44
43
|
var terminalLink = _socketInterop(require('terminal-link'));
|
|
45
|
-
var spawn =
|
|
44
|
+
var spawn = require('@socketsecurity/registry/lib/spawn');
|
|
46
45
|
var npa = _socketInterop(require('npm-package-arg'));
|
|
47
46
|
var semver = _socketInterop(require('semver'));
|
|
48
47
|
var tinyglobby = _socketInterop(require('tinyglobby'));
|
|
@@ -53,13 +52,12 @@ var index_cjs = require('@socketregistry/hyrious__bun.lockb/index.cjs');
|
|
|
53
52
|
var sorts = require('@socketsecurity/registry/lib/sorts');
|
|
54
53
|
var strings = require('@socketsecurity/registry/lib/strings');
|
|
55
54
|
var yaml = _socketInterop(require('yaml'));
|
|
55
|
+
var debug = require('@socketsecurity/registry/lib/debug');
|
|
56
56
|
var npmPaths = require('./npm-paths.js');
|
|
57
|
-
var npm$1 = require('./npm.js');
|
|
58
57
|
var betterAjvErrors = _socketInterop(require('@apideck/better-ajv-errors'));
|
|
59
58
|
var config$A = require('@socketsecurity/config');
|
|
60
59
|
var assert = require('node:assert');
|
|
61
60
|
var readline = require('node:readline/promises');
|
|
62
|
-
var childProcess = require('node:child_process');
|
|
63
61
|
var TableWidget = _socketInterop(require('blessed-contrib/lib/widget/table'));
|
|
64
62
|
var readline$1 = require('node:readline');
|
|
65
63
|
|
|
@@ -264,7 +262,6 @@ class Score {
|
|
|
264
262
|
}
|
|
265
263
|
|
|
266
264
|
// https://github.com/SocketDev/socket-python-cli/blob/6d4fc56faee68d3a4764f1f80f84710635bdaf05/socketsecurity/core/__init__.py
|
|
267
|
-
/* eslint-disable no-await-in-loop */
|
|
268
265
|
class Core {
|
|
269
266
|
securityPolicy = {};
|
|
270
267
|
constructor({
|
|
@@ -559,6 +556,7 @@ class Core {
|
|
|
559
556
|
diff.newPackages.push(purl);
|
|
560
557
|
consolidated.add(basePurl);
|
|
561
558
|
}
|
|
559
|
+
// eslint-disable-next-line no-await-in-loop
|
|
562
560
|
newScanAlerts = await this.createIssueAlerts({
|
|
563
561
|
pkg,
|
|
564
562
|
alerts: newScanAlerts,
|
|
@@ -576,6 +574,7 @@ class Core {
|
|
|
576
574
|
if (!(packageId in newPackages) && pkg.direct) {
|
|
577
575
|
diff.removedPackages.push(purl);
|
|
578
576
|
}
|
|
577
|
+
// eslint-disable-next-line no-await-in-loop
|
|
579
578
|
headScanAlerts = await this.createIssueAlerts({
|
|
580
579
|
pkg,
|
|
581
580
|
alerts: headScanAlerts,
|
|
@@ -641,7 +640,7 @@ class Core {
|
|
|
641
640
|
license: sbomArtifact.license
|
|
642
641
|
});
|
|
643
642
|
if (pkg.id in packages) {
|
|
644
|
-
|
|
643
|
+
logger.logger.log('Duplicate package?');
|
|
645
644
|
} else {
|
|
646
645
|
pkg = this.getLicenseDetails({
|
|
647
646
|
package: pkg
|
|
@@ -681,8 +680,8 @@ class Core {
|
|
|
681
680
|
});
|
|
682
681
|
}
|
|
683
682
|
}
|
|
684
|
-
} catch (
|
|
685
|
-
|
|
683
|
+
} catch (e) {
|
|
684
|
+
logger.logger.error(e);
|
|
686
685
|
}
|
|
687
686
|
const newFullScan = await this.createFullScan({
|
|
688
687
|
params
|
|
@@ -706,7 +705,6 @@ class Core {
|
|
|
706
705
|
}
|
|
707
706
|
|
|
708
707
|
// https://github.com/SocketDev/socket-python-cli/blob/6d4fc56faee68d3a4764f1f80f84710635bdaf05/socketsecurity/core/scm_comments.py
|
|
709
|
-
|
|
710
708
|
function checkForSocketComments({
|
|
711
709
|
comments
|
|
712
710
|
}) {
|
|
@@ -836,9 +834,9 @@ function getIgnoreOptions({
|
|
|
836
834
|
const data = `${name}/${version}`;
|
|
837
835
|
ignoreCommands.push(data);
|
|
838
836
|
}
|
|
839
|
-
} catch (
|
|
840
|
-
|
|
841
|
-
|
|
837
|
+
} catch (e) {
|
|
838
|
+
logger.logger.error(`Unable to process ignore command for ${comment}`);
|
|
839
|
+
logger.logger.error(e);
|
|
842
840
|
}
|
|
843
841
|
}
|
|
844
842
|
}
|
|
@@ -869,9 +867,9 @@ function removeAlerts({
|
|
|
869
867
|
const purl = `${fullName}/${alert.pkg_version}`;
|
|
870
868
|
const purlStar = `${fullName}/*`;
|
|
871
869
|
if (ignoreCommands.includes(purl) || ignoreCommands.includes(purlStar)) {
|
|
872
|
-
|
|
870
|
+
logger.logger.log(`Alerts for ${alert.pkg_name}@${alert.pkg_version} ignored`);
|
|
873
871
|
} else {
|
|
874
|
-
|
|
872
|
+
logger.logger.log(`Adding alert ${alert.type} for ${alert.pkg_name}@${alert.pkg_version}`);
|
|
875
873
|
alerts.push(alert);
|
|
876
874
|
}
|
|
877
875
|
}
|
|
@@ -909,7 +907,7 @@ class GitHub {
|
|
|
909
907
|
if (['opened', 'synchronize'].includes(eventAction)) {
|
|
910
908
|
return 'diff';
|
|
911
909
|
} else {
|
|
912
|
-
|
|
910
|
+
logger.logger.log(`Pull request action: ${eventAction} is not supported`);
|
|
913
911
|
process.exit();
|
|
914
912
|
}
|
|
915
913
|
case 'issue_comment':
|
|
@@ -1024,30 +1022,30 @@ class GitHub {
|
|
|
1024
1022
|
security: existingSecurityComment
|
|
1025
1023
|
} = comments;
|
|
1026
1024
|
if (newOverviewComment) {
|
|
1027
|
-
|
|
1025
|
+
logger.logger.log('New Dependency Overview comment');
|
|
1028
1026
|
if (existingOverviewComment !== undefined) {
|
|
1029
|
-
|
|
1027
|
+
logger.logger.log('Previous version of Dependency Overview, updating');
|
|
1030
1028
|
await this.updateComment({
|
|
1031
1029
|
body: overviewComment,
|
|
1032
1030
|
id: existingOverviewComment.id
|
|
1033
1031
|
});
|
|
1034
1032
|
} else {
|
|
1035
|
-
|
|
1033
|
+
logger.logger.log('No previous version of Dependency Overview, posting');
|
|
1036
1034
|
await this.postComment({
|
|
1037
1035
|
body: overviewComment
|
|
1038
1036
|
});
|
|
1039
1037
|
}
|
|
1040
1038
|
}
|
|
1041
1039
|
if (newSecurityComment) {
|
|
1042
|
-
|
|
1040
|
+
logger.logger.log('New Security Issue Comment');
|
|
1043
1041
|
if (existingSecurityComment !== undefined) {
|
|
1044
|
-
|
|
1042
|
+
logger.logger.log('Previous version of Security Issue comment, updating');
|
|
1045
1043
|
await this.updateComment({
|
|
1046
1044
|
body: securityComment,
|
|
1047
1045
|
id: existingSecurityComment.id
|
|
1048
1046
|
});
|
|
1049
1047
|
} else {
|
|
1050
|
-
|
|
1048
|
+
logger.logger.log('No Previous version of Security Issue comment, posting');
|
|
1051
1049
|
await this.postComment({
|
|
1052
1050
|
body: securityComment
|
|
1053
1051
|
});
|
|
@@ -1226,7 +1224,7 @@ async function runAction(githubEventBefore, githubEventAfter) {
|
|
|
1226
1224
|
const socket = new sdk.SocketSdk(index.getDefaultToken());
|
|
1227
1225
|
const git = simpleGit.simpleGit();
|
|
1228
1226
|
const changedFiles = (await git.diff(process.env['GITHUB_EVENT_NAME'] === 'pull_request' ? ['--name-only', 'HEAD^1', 'HEAD'] : ['--name-only', githubEventBefore, githubEventAfter])).split('\n');
|
|
1229
|
-
|
|
1227
|
+
logger.logger.log({
|
|
1230
1228
|
changedFiles
|
|
1231
1229
|
});
|
|
1232
1230
|
// supportedFiles have 3-level deep globs
|
|
@@ -1234,13 +1232,13 @@ async function runAction(githubEventBefore, githubEventAfter) {
|
|
|
1234
1232
|
const files = micromatch(changedFiles, patterns);
|
|
1235
1233
|
const scm = new GitHub();
|
|
1236
1234
|
if (scm.checkEventType() === 'comment') {
|
|
1237
|
-
|
|
1235
|
+
logger.logger.log('Comment initiated flow');
|
|
1238
1236
|
const comments = await scm.getCommentsForPR();
|
|
1239
1237
|
await scm.removeCommentAlerts({
|
|
1240
1238
|
comments
|
|
1241
1239
|
});
|
|
1242
1240
|
} else if (scm.checkEventType() === 'diff') {
|
|
1243
|
-
|
|
1241
|
+
logger.logger.log('Push initiated flow');
|
|
1244
1242
|
const core = new Core({
|
|
1245
1243
|
owner: scm.owner,
|
|
1246
1244
|
repo: scm.repo,
|
|
@@ -1262,17 +1260,17 @@ async function runAction(githubEventBefore, githubEventAfter) {
|
|
|
1262
1260
|
if (diff.newAlerts.length === 0) {
|
|
1263
1261
|
if (!updateOldSecurityComment) {
|
|
1264
1262
|
newSecurityComment = false;
|
|
1265
|
-
|
|
1263
|
+
logger.logger.log('No new alerts or security issue comment disabled');
|
|
1266
1264
|
} else {
|
|
1267
|
-
|
|
1265
|
+
logger.logger.log('Updated security comment with no new alerts');
|
|
1268
1266
|
}
|
|
1269
1267
|
}
|
|
1270
1268
|
if (diff.newPackages.length === 0 && diff.removedPackages.length === 0) {
|
|
1271
1269
|
if (!updateOldOverviewComment) {
|
|
1272
1270
|
newOverviewComment = false;
|
|
1273
|
-
|
|
1271
|
+
logger.logger.log('No new/removed packages or Dependency Overview comment disabled');
|
|
1274
1272
|
} else {
|
|
1275
|
-
|
|
1273
|
+
logger.logger.log('Updated overview comment with no dependencies');
|
|
1276
1274
|
}
|
|
1277
1275
|
}
|
|
1278
1276
|
await scm.addSocketComments({
|
|
@@ -1400,6 +1398,8 @@ const validationFlags = {
|
|
|
1400
1398
|
};
|
|
1401
1399
|
|
|
1402
1400
|
const {
|
|
1401
|
+
DRY_RUN_LABEL: DRY_RUN_LABEL$1,
|
|
1402
|
+
REDACTED,
|
|
1403
1403
|
SOCKET_CLI_SHOW_BANNER
|
|
1404
1404
|
} = constants;
|
|
1405
1405
|
async function meowWithSubcommands(subcommands, options) {
|
|
@@ -1437,7 +1437,7 @@ async function meowWithSubcommands(subcommands, options) {
|
|
|
1437
1437
|
// Temp disable until we clear the --json and --markdown usage
|
|
1438
1438
|
// Lazily access constants.ENV[SOCKET_CLI_SHOW_BANNER].
|
|
1439
1439
|
if (constants.ENV[SOCKET_CLI_SHOW_BANNER]) {
|
|
1440
|
-
|
|
1440
|
+
logger.logger.log(getAsciiHeader(name));
|
|
1441
1441
|
}
|
|
1442
1442
|
const cli = vendor.meow(`
|
|
1443
1443
|
Usage
|
|
@@ -1473,7 +1473,7 @@ async function meowWithSubcommands(subcommands, options) {
|
|
|
1473
1473
|
autoHelp: false // otherwise we can't exit(0)
|
|
1474
1474
|
});
|
|
1475
1475
|
if (!cli.flags['help'] && cli.flags['dryRun']) {
|
|
1476
|
-
|
|
1476
|
+
logger.logger.log(`${DRY_RUN_LABEL$1}: No-op, call a sub-command; ok`);
|
|
1477
1477
|
process.exitCode = 0;
|
|
1478
1478
|
} else {
|
|
1479
1479
|
cli.showHelp();
|
|
@@ -1495,7 +1495,7 @@ function meowOrExit({
|
|
|
1495
1495
|
// Temp disable until we clear the --json and --markdown usage.
|
|
1496
1496
|
// Lazily access constants.ENV[SOCKET_CLI_SHOW_BANNER].
|
|
1497
1497
|
if (constants.ENV[SOCKET_CLI_SHOW_BANNER]) {
|
|
1498
|
-
|
|
1498
|
+
logger.logger.log(getAsciiHeader(command));
|
|
1499
1499
|
}
|
|
1500
1500
|
|
|
1501
1501
|
// This exits if .printHelp() is called either by meow itself or by us.
|
|
@@ -1515,7 +1515,7 @@ function meowOrExit({
|
|
|
1515
1515
|
}
|
|
1516
1516
|
function getAsciiHeader(command) {
|
|
1517
1517
|
const cliVersion = // The '@rollup/plugin-replace' will replace "process.env['SOCKET_CLI_VERSION_HASH']".
|
|
1518
|
-
"0.14.
|
|
1518
|
+
"0.14.53:e7fcb39:b41fef49:pub";
|
|
1519
1519
|
const nodeVersion = process.version;
|
|
1520
1520
|
const apiToken = index.getSetting('apiToken');
|
|
1521
1521
|
const shownToken = apiToken ? getLastFiveOfApiToken(apiToken) : 'no';
|
|
@@ -1530,6 +1530,9 @@ function getAsciiHeader(command) {
|
|
|
1530
1530
|
|
|
1531
1531
|
// https://github.com/SocketDev/socket-python-cli/blob/6d4fc56faee68d3a4764f1f80f84710635bdaf05/socketsecurity/socketcli.py
|
|
1532
1532
|
|
|
1533
|
+
const {
|
|
1534
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$y
|
|
1535
|
+
} = constants;
|
|
1533
1536
|
const config$z = {
|
|
1534
1537
|
commandName: 'action',
|
|
1535
1538
|
description: 'Socket action command',
|
|
@@ -1580,7 +1583,8 @@ async function run$z(argv, importMeta, {
|
|
|
1580
1583
|
const githubEventBefore = String(cli.flags['githubEventBefore'] || '');
|
|
1581
1584
|
const githubEventAfter = String(cli.flags['githubEventAfter'] || '');
|
|
1582
1585
|
if (cli.flags['dryRun']) {
|
|
1583
|
-
|
|
1586
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$y);
|
|
1587
|
+
return;
|
|
1584
1588
|
}
|
|
1585
1589
|
await runAction(githubEventBefore, githubEventAfter);
|
|
1586
1590
|
}
|
|
@@ -1598,24 +1602,26 @@ async function displayAnalytics({
|
|
|
1598
1602
|
scope,
|
|
1599
1603
|
time
|
|
1600
1604
|
}) {
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1605
|
+
// Lazily access constants.spinner.
|
|
1606
|
+
const {
|
|
1607
|
+
spinner
|
|
1608
|
+
} = constants;
|
|
1609
|
+
spinner.start('Fetching analytics data');
|
|
1604
1610
|
let data;
|
|
1605
1611
|
if (scope === 'org') {
|
|
1606
|
-
data = await fetchOrgAnalyticsData(time, spinner
|
|
1612
|
+
data = await fetchOrgAnalyticsData(time, spinner, apiToken);
|
|
1607
1613
|
} else if (repo) {
|
|
1608
|
-
data = await fetchRepoAnalyticsData(repo, time, spinner
|
|
1614
|
+
data = await fetchRepoAnalyticsData(repo, time, spinner, apiToken);
|
|
1609
1615
|
}
|
|
1610
1616
|
if (data) {
|
|
1611
1617
|
if (outputJson && !filePath) {
|
|
1612
|
-
|
|
1618
|
+
logger.logger.log(data);
|
|
1613
1619
|
} else if (filePath) {
|
|
1614
1620
|
try {
|
|
1615
1621
|
await fs$1.writeFile(filePath, JSON.stringify(data), 'utf8');
|
|
1616
|
-
|
|
1622
|
+
logger.logger.log(`Data successfully written to ${filePath}`);
|
|
1617
1623
|
} catch (e) {
|
|
1618
|
-
|
|
1624
|
+
logger.logger.error(e);
|
|
1619
1625
|
}
|
|
1620
1626
|
} else {
|
|
1621
1627
|
const fdata = scope === 'org' ? formatData(data, 'org') : formatData(data, 'repo');
|
|
@@ -1664,7 +1670,7 @@ async function fetchOrgAnalyticsData(time, spinner, apiToken) {
|
|
|
1664
1670
|
}
|
|
1665
1671
|
spinner.stop();
|
|
1666
1672
|
if (!result.data.length) {
|
|
1667
|
-
|
|
1673
|
+
logger.logger.log('No analytics data is available for this organization yet.');
|
|
1668
1674
|
return undefined;
|
|
1669
1675
|
}
|
|
1670
1676
|
return result.data;
|
|
@@ -1678,7 +1684,7 @@ async function fetchRepoAnalyticsData(repo, time, spinner, apiToken) {
|
|
|
1678
1684
|
}
|
|
1679
1685
|
spinner.stop();
|
|
1680
1686
|
if (!result.data.length) {
|
|
1681
|
-
|
|
1687
|
+
logger.logger.log('No analytics data is available for this organization yet.');
|
|
1682
1688
|
return undefined;
|
|
1683
1689
|
}
|
|
1684
1690
|
return result.data;
|
|
@@ -1774,6 +1780,9 @@ function renderLineCharts(grid, screen, title, coords, data) {
|
|
|
1774
1780
|
line.setData([lineData]);
|
|
1775
1781
|
}
|
|
1776
1782
|
|
|
1783
|
+
const {
|
|
1784
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$x
|
|
1785
|
+
} = constants;
|
|
1777
1786
|
const config$y = {
|
|
1778
1787
|
commandName: 'analytics',
|
|
1779
1788
|
description: `Look up analytics data`,
|
|
@@ -1851,14 +1860,15 @@ async function run$y(argv, importMeta, {
|
|
|
1851
1860
|
// options or missing arguments.
|
|
1852
1861
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
1853
1862
|
process.exitCode = 2;
|
|
1854
|
-
|
|
1863
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
1855
1864
|
- Scope must be "repo" or "org" ${badScope ? colors.red('(bad!)') : colors.green('(ok)')}\n
|
|
1856
1865
|
- The time filter must either be 7, 30 or 90 ${badTime ? colors.red('(bad!)') : colors.green('(ok)')}\n
|
|
1857
1866
|
- Repository name using --repo when scope is "repo" ${badRepo ? colors.red('(bad!)') : colors.green('(ok)')}\n`);
|
|
1858
1867
|
return;
|
|
1859
1868
|
}
|
|
1860
1869
|
if (cli.flags['dryRun']) {
|
|
1861
|
-
|
|
1870
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$x);
|
|
1871
|
+
return;
|
|
1862
1872
|
}
|
|
1863
1873
|
const apiToken = index.getDefaultToken();
|
|
1864
1874
|
if (!apiToken) {
|
|
@@ -1883,9 +1893,11 @@ async function getAuditLog({
|
|
|
1883
1893
|
perPage,
|
|
1884
1894
|
type
|
|
1885
1895
|
}) {
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1896
|
+
// Lazily access constants.spinner.
|
|
1897
|
+
const {
|
|
1898
|
+
spinner
|
|
1899
|
+
} = constants;
|
|
1900
|
+
spinner.start(`Looking up audit log for ${orgSlug}`);
|
|
1889
1901
|
const socketSdk = await index.setupSdk(apiToken);
|
|
1890
1902
|
const result = await handleApiCall(socketSdk.getAuditLogEvents(orgSlug, {
|
|
1891
1903
|
outputJson,
|
|
@@ -1896,10 +1908,10 @@ async function getAuditLog({
|
|
|
1896
1908
|
per_page: perPage
|
|
1897
1909
|
}), `Looking up audit log for ${orgSlug}\n`);
|
|
1898
1910
|
if (!result.success) {
|
|
1899
|
-
handleUnsuccessfulApiResponse('getAuditLogEvents', result, spinner
|
|
1911
|
+
handleUnsuccessfulApiResponse('getAuditLogEvents', result, spinner);
|
|
1900
1912
|
return;
|
|
1901
1913
|
}
|
|
1902
|
-
spinner
|
|
1914
|
+
spinner.stop();
|
|
1903
1915
|
const data = [];
|
|
1904
1916
|
const logDetails = {};
|
|
1905
1917
|
for (const d of result.data.results) {
|
|
@@ -1918,13 +1930,16 @@ async function getAuditLog({
|
|
|
1918
1930
|
logDetails[name] = JSON.stringify(d.payload);
|
|
1919
1931
|
}
|
|
1920
1932
|
}
|
|
1921
|
-
|
|
1933
|
+
logger.logger.log(logDetails[await prompts.select({
|
|
1922
1934
|
message: type ? `\n Audit log for: ${orgSlug} with type: ${type}\n` : `\n Audit log for: ${orgSlug}\n`,
|
|
1923
1935
|
choices: data,
|
|
1924
1936
|
pageSize: 30
|
|
1925
1937
|
})]);
|
|
1926
1938
|
}
|
|
1927
1939
|
|
|
1940
|
+
const {
|
|
1941
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$w
|
|
1942
|
+
} = constants;
|
|
1928
1943
|
const config$x = {
|
|
1929
1944
|
commandName: 'audit-log',
|
|
1930
1945
|
description: 'Look up the audit log for an organization',
|
|
@@ -1983,12 +1998,13 @@ async function run$x(argv, importMeta, {
|
|
|
1983
1998
|
// options or missing arguments.
|
|
1984
1999
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
1985
2000
|
process.exitCode = 2;
|
|
1986
|
-
|
|
2001
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
1987
2002
|
- Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n`);
|
|
1988
2003
|
return;
|
|
1989
2004
|
}
|
|
1990
2005
|
if (cli.flags['dryRun']) {
|
|
1991
|
-
|
|
2006
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$w);
|
|
2007
|
+
return;
|
|
1992
2008
|
}
|
|
1993
2009
|
const apiToken = index.getDefaultToken();
|
|
1994
2010
|
if (!apiToken) {
|
|
@@ -2050,7 +2066,7 @@ async function runCycloneDX(yargv) {
|
|
|
2050
2066
|
}
|
|
2051
2067
|
const fullOutputPath = path.join(process$1.cwd(), yargv.output);
|
|
2052
2068
|
if (fs.existsSync(fullOutputPath)) {
|
|
2053
|
-
|
|
2069
|
+
logger.logger.log(colors.cyanBright(`${yargv.output} created!`));
|
|
2054
2070
|
}
|
|
2055
2071
|
}
|
|
2056
2072
|
function argvToArray(argv) {
|
|
@@ -2080,6 +2096,10 @@ function argvToArray(argv) {
|
|
|
2080
2096
|
}
|
|
2081
2097
|
|
|
2082
2098
|
// import { meowOrExit } from '../../utils/meow-with-subcommands'
|
|
2099
|
+
const {
|
|
2100
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$v
|
|
2101
|
+
} = constants;
|
|
2102
|
+
|
|
2083
2103
|
// TODO: convert yargs to meow. Or convert all the other things to yargs.
|
|
2084
2104
|
const toLower = arg => arg.toLowerCase();
|
|
2085
2105
|
const arrayToLower = arg => arg.map(toLower);
|
|
@@ -2184,7 +2204,7 @@ async function run$w(argv, importMeta, {
|
|
|
2184
2204
|
//
|
|
2185
2205
|
//
|
|
2186
2206
|
// if (cli.input.length)
|
|
2187
|
-
//
|
|
2207
|
+
// logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
2188
2208
|
// - Unexpected arguments\n
|
|
2189
2209
|
// `)
|
|
2190
2210
|
// config.help(parentName, config)
|
|
@@ -2205,14 +2225,15 @@ async function run$w(argv, importMeta, {
|
|
|
2205
2225
|
// options or missing arguments.
|
|
2206
2226
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
2207
2227
|
process$1.exitCode = 2;
|
|
2208
|
-
|
|
2228
|
+
logger.logger.error(`Unknown ${words.pluralize('argument', unknownLength)}: ${yargv._.join(', ')}`);
|
|
2209
2229
|
return;
|
|
2210
2230
|
}
|
|
2211
2231
|
if (yargv.output === undefined) {
|
|
2212
2232
|
yargv.output = 'socket-cdx.json';
|
|
2213
2233
|
}
|
|
2214
2234
|
if (cli.flags['dryRun']) {
|
|
2215
|
-
|
|
2235
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$v);
|
|
2236
|
+
return;
|
|
2216
2237
|
}
|
|
2217
2238
|
await runCycloneDX(yargv);
|
|
2218
2239
|
}
|
|
@@ -2227,21 +2248,23 @@ async function findDependencies({
|
|
|
2227
2248
|
if (!apiToken) {
|
|
2228
2249
|
throw new index.AuthError('User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.');
|
|
2229
2250
|
}
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2251
|
+
// Lazily access constants.spinner.
|
|
2252
|
+
const {
|
|
2253
|
+
spinner
|
|
2254
|
+
} = constants;
|
|
2255
|
+
spinner.start('Searching dependencies...');
|
|
2233
2256
|
const socketSdk = await index.setupSdk(apiToken);
|
|
2234
2257
|
const result = await handleApiCall(socketSdk.searchDependencies({
|
|
2235
2258
|
limit,
|
|
2236
2259
|
offset
|
|
2237
2260
|
}), 'Searching dependencies');
|
|
2238
2261
|
if (!result.success) {
|
|
2239
|
-
handleUnsuccessfulApiResponse('searchDependencies', result, spinner
|
|
2262
|
+
handleUnsuccessfulApiResponse('searchDependencies', result, spinner);
|
|
2240
2263
|
return;
|
|
2241
2264
|
}
|
|
2242
|
-
spinner
|
|
2265
|
+
spinner.stop('Organization dependencies:');
|
|
2243
2266
|
if (outputJson) {
|
|
2244
|
-
|
|
2267
|
+
logger.logger.log(result.data);
|
|
2245
2268
|
return;
|
|
2246
2269
|
}
|
|
2247
2270
|
const options = {
|
|
@@ -2268,9 +2291,12 @@ async function findDependencies({
|
|
|
2268
2291
|
name: colors.cyan('Direct')
|
|
2269
2292
|
}]
|
|
2270
2293
|
};
|
|
2271
|
-
|
|
2294
|
+
logger.logger.log(chalkTable(options, result.data.rows));
|
|
2272
2295
|
}
|
|
2273
2296
|
|
|
2297
|
+
const {
|
|
2298
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$u
|
|
2299
|
+
} = constants;
|
|
2274
2300
|
const config$v = {
|
|
2275
2301
|
commandName: 'dependencies',
|
|
2276
2302
|
description: 'Search for any dependency that is being used in your organization',
|
|
@@ -2317,7 +2343,8 @@ async function run$v(argv, importMeta, {
|
|
|
2317
2343
|
parentName
|
|
2318
2344
|
});
|
|
2319
2345
|
if (cli.flags['dryRun']) {
|
|
2320
|
-
|
|
2346
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$u);
|
|
2347
|
+
return;
|
|
2321
2348
|
}
|
|
2322
2349
|
|
|
2323
2350
|
// TODO: markdown flag is ignored
|
|
@@ -2335,38 +2362,44 @@ async function getDiffScan({
|
|
|
2335
2362
|
orgSlug,
|
|
2336
2363
|
outputJson
|
|
2337
2364
|
}, apiToken) {
|
|
2338
|
-
|
|
2339
|
-
|
|
2365
|
+
// Lazily access constants.spinner.
|
|
2366
|
+
const {
|
|
2367
|
+
spinner
|
|
2368
|
+
} = constants;
|
|
2369
|
+
spinner.start('Getting diff scan...');
|
|
2340
2370
|
const response = await queryAPI(`${orgSlug}/full-scans/diff?before=${before}&after=${after}&preview`, apiToken);
|
|
2341
2371
|
const data = await response.json();
|
|
2342
2372
|
if (!response.ok) {
|
|
2343
2373
|
const err = await handleAPIError(response.status);
|
|
2344
|
-
spinner
|
|
2374
|
+
spinner.errorAndStop(`${colors.bgRed(colors.white(response.statusText))}: ${err}`);
|
|
2345
2375
|
return;
|
|
2346
2376
|
}
|
|
2347
|
-
spinner
|
|
2377
|
+
spinner.stop();
|
|
2348
2378
|
if (file && !outputJson) {
|
|
2349
2379
|
fs.writeFile(file, JSON.stringify(data), err => {
|
|
2350
|
-
err ?
|
|
2380
|
+
err ? logger.logger.error(err) : logger.logger.log(`Data successfully written to ${file}`);
|
|
2351
2381
|
});
|
|
2352
2382
|
return;
|
|
2353
2383
|
}
|
|
2354
2384
|
if (outputJson) {
|
|
2355
|
-
|
|
2356
|
-
|
|
2385
|
+
logger.logger.log(`\n Diff scan result: \n`);
|
|
2386
|
+
logger.logger.log(require$$0$1.inspect(data, {
|
|
2357
2387
|
showHidden: false,
|
|
2358
2388
|
depth: null,
|
|
2359
2389
|
colors: true
|
|
2360
2390
|
}));
|
|
2361
|
-
|
|
2391
|
+
logger.logger.log(`\n View this diff scan in the Socket dashboard: ${colors.cyan(data?.['diff_report_url'])}`);
|
|
2362
2392
|
return;
|
|
2363
2393
|
}
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2394
|
+
logger.logger.log('Diff scan result:');
|
|
2395
|
+
logger.logger.log(data);
|
|
2396
|
+
logger.logger.log(`\n 📝 To display the detailed report in the terminal, use the --json flag \n`);
|
|
2397
|
+
logger.logger.log(`\n View this diff scan in the Socket dashboard: ${colors.cyan(data?.['diff_report_url'])}`);
|
|
2368
2398
|
}
|
|
2369
2399
|
|
|
2400
|
+
const {
|
|
2401
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$t
|
|
2402
|
+
} = constants;
|
|
2370
2403
|
const config$u = {
|
|
2371
2404
|
commandName: 'get',
|
|
2372
2405
|
description: 'Get a diff scan for an organization',
|
|
@@ -2432,14 +2465,15 @@ async function run$u(argv, importMeta, {
|
|
|
2432
2465
|
// options or missing arguments.
|
|
2433
2466
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
2434
2467
|
process.exitCode = 2;
|
|
2435
|
-
|
|
2468
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
2436
2469
|
- Specify a before and after full scan ID ${!before && !after ? colors.red('(missing before and after!)') : !before ? colors.red('(missing before!)') : !after ? colors.red('(missing after!)') : colors.green('(ok)')}\n
|
|
2437
2470
|
- To get full scans IDs, you can run the command "socket scan list <your org slug>".
|
|
2438
2471
|
- Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n`);
|
|
2439
2472
|
return;
|
|
2440
2473
|
}
|
|
2441
2474
|
if (cli.flags['dryRun']) {
|
|
2442
|
-
|
|
2475
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$t);
|
|
2476
|
+
return;
|
|
2443
2477
|
}
|
|
2444
2478
|
const apiToken = index.getDefaultToken();
|
|
2445
2479
|
if (!apiToken) {
|
|
@@ -2482,7 +2516,11 @@ function isTopLevel(tree, node) {
|
|
|
2482
2516
|
return tree.children.get(node.name) === node;
|
|
2483
2517
|
}
|
|
2484
2518
|
async function runFix() {
|
|
2485
|
-
|
|
2519
|
+
// Lazily access constants.spinner.
|
|
2520
|
+
const {
|
|
2521
|
+
spinner
|
|
2522
|
+
} = constants;
|
|
2523
|
+
spinner.start();
|
|
2486
2524
|
const cwd = process.cwd();
|
|
2487
2525
|
const editablePkgJson = await packages.readPackageJson(cwd, {
|
|
2488
2526
|
editable: true
|
|
@@ -2513,7 +2551,7 @@ async function runFix() {
|
|
|
2513
2551
|
const tree = arb.idealTree;
|
|
2514
2552
|
const hasUpgrade = !!registry.getManifestData(NPM$d, name);
|
|
2515
2553
|
if (hasUpgrade) {
|
|
2516
|
-
spinner
|
|
2554
|
+
spinner.info(`Skipping ${name}. Socket Optimize package exists.`);
|
|
2517
2555
|
continue;
|
|
2518
2556
|
}
|
|
2519
2557
|
const nodes = index.findPackageNodes(tree, name);
|
|
@@ -2539,10 +2577,10 @@ async function runFix() {
|
|
|
2539
2577
|
try {
|
|
2540
2578
|
// eslint-disable-next-line no-await-in-loop
|
|
2541
2579
|
await npm.runScript('test', [], {
|
|
2542
|
-
spinner
|
|
2580
|
+
spinner,
|
|
2543
2581
|
stdio: 'ignore'
|
|
2544
2582
|
});
|
|
2545
|
-
spinner
|
|
2583
|
+
spinner.info(`Patched ${name} ${oldVersion} -> ${node.version}`);
|
|
2546
2584
|
if (isTopLevel(tree, node)) {
|
|
2547
2585
|
for (const depField of ['dependencies', 'optionalDependencies', 'peerDependencies']) {
|
|
2548
2586
|
const oldVersion = editablePkgJson.content[depField]?.[name];
|
|
@@ -2555,11 +2593,11 @@ async function runFix() {
|
|
|
2555
2593
|
// eslint-disable-next-line no-await-in-loop
|
|
2556
2594
|
await editablePkgJson.save();
|
|
2557
2595
|
} catch {
|
|
2558
|
-
spinner
|
|
2596
|
+
spinner.error(`Reverting ${name} to ${oldVersion}`);
|
|
2559
2597
|
arb.idealTree = revertToIdealTree;
|
|
2560
2598
|
}
|
|
2561
2599
|
} else {
|
|
2562
|
-
spinner
|
|
2600
|
+
spinner.error(`Could not patch ${name} ${oldVersion}`);
|
|
2563
2601
|
}
|
|
2564
2602
|
}
|
|
2565
2603
|
}
|
|
@@ -2571,9 +2609,12 @@ async function runFix() {
|
|
|
2571
2609
|
});
|
|
2572
2610
|
arb2.idealTree = arb.idealTree;
|
|
2573
2611
|
await arb2.reify();
|
|
2574
|
-
spinner
|
|
2612
|
+
spinner.stop();
|
|
2575
2613
|
}
|
|
2576
2614
|
|
|
2615
|
+
const {
|
|
2616
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$s
|
|
2617
|
+
} = constants;
|
|
2577
2618
|
const config$t = {
|
|
2578
2619
|
commandName: 'fix',
|
|
2579
2620
|
description: 'Fix "fixable" Socket alerts',
|
|
@@ -2604,7 +2645,8 @@ async function run$t(argv, importMeta, {
|
|
|
2604
2645
|
parentName
|
|
2605
2646
|
});
|
|
2606
2647
|
if (cli.flags['dryRun']) {
|
|
2607
|
-
|
|
2648
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$s);
|
|
2649
|
+
return;
|
|
2608
2650
|
}
|
|
2609
2651
|
await runFix();
|
|
2610
2652
|
}
|
|
@@ -2716,9 +2758,9 @@ function formatPackageInfo({
|
|
|
2716
2758
|
strict
|
|
2717
2759
|
}, spinner) {
|
|
2718
2760
|
if (outputJson) {
|
|
2719
|
-
|
|
2761
|
+
logger.logger.log(JSON.stringify(data, undefined, 2));
|
|
2720
2762
|
} else {
|
|
2721
|
-
|
|
2763
|
+
logger.logger.log('\nPackage report card:');
|
|
2722
2764
|
const scoreResult = {
|
|
2723
2765
|
'Supply Chain Risk': Math.floor(score.supplyChainRisk.score * 100),
|
|
2724
2766
|
Maintenance: Math.floor(score.maintenance.score * 100),
|
|
@@ -2726,8 +2768,8 @@ function formatPackageInfo({
|
|
|
2726
2768
|
Vulnerabilities: Math.floor(score.vulnerability.score * 100),
|
|
2727
2769
|
License: Math.floor(score.license.score * 100)
|
|
2728
2770
|
};
|
|
2729
|
-
Object.entries(scoreResult).map(score =>
|
|
2730
|
-
|
|
2771
|
+
Object.entries(scoreResult).map(score => logger.logger.log(`- ${score[0]}: ${formatScore(score[1])}`));
|
|
2772
|
+
logger.logger.log('\n');
|
|
2731
2773
|
if (objectSome(severityCount)) {
|
|
2732
2774
|
spinner[strict ? 'error' : 'success'](`Package has these issues: ${formatSeverityCount(severityCount)}`);
|
|
2733
2775
|
formatPackageIssuesDetails(data, outputMarkdown);
|
|
@@ -2736,18 +2778,18 @@ function formatPackageInfo({
|
|
|
2736
2778
|
}
|
|
2737
2779
|
const format = new index.ColorOrMarkdown(!!outputMarkdown);
|
|
2738
2780
|
const url = index.getSocketDevPackageOverviewUrl(NPM$c, pkgName, pkgVersion);
|
|
2739
|
-
|
|
2781
|
+
logger.logger.log('\n');
|
|
2740
2782
|
if (pkgVersion === 'latest') {
|
|
2741
|
-
|
|
2783
|
+
logger.logger.log(`Detailed info on socket.dev: ${format.hyperlink(`${pkgName}`, url, {
|
|
2742
2784
|
fallbackToUrl: true
|
|
2743
2785
|
})}`);
|
|
2744
2786
|
} else {
|
|
2745
|
-
|
|
2787
|
+
logger.logger.log(`Detailed info on socket.dev: ${format.hyperlink(`${pkgName} v${pkgVersion}`, url, {
|
|
2746
2788
|
fallbackToUrl: true
|
|
2747
2789
|
})}`);
|
|
2748
2790
|
}
|
|
2749
2791
|
if (!outputMarkdown) {
|
|
2750
|
-
|
|
2792
|
+
logger.logger.log(colors.dim(`\nOr rerun ${colors.italic(name)} using the ${colors.italic('--json')} flag to get full JSON output`));
|
|
2751
2793
|
}
|
|
2752
2794
|
}
|
|
2753
2795
|
if (strict && objectSome(severityCount)) {
|
|
@@ -2778,9 +2820,9 @@ function formatPackageIssuesDetails(packageData, outputMarkdown) {
|
|
|
2778
2820
|
fallbackToUrl: true
|
|
2779
2821
|
});
|
|
2780
2822
|
if (uniqueIssues[issue]?.count === 1) {
|
|
2781
|
-
|
|
2823
|
+
logger.logger.log(`- ${issueWithLink}`);
|
|
2782
2824
|
} else {
|
|
2783
|
-
|
|
2825
|
+
logger.logger.log(`- ${issueWithLink}: ${uniqueIssues[issue]?.count}`);
|
|
2784
2826
|
}
|
|
2785
2827
|
}
|
|
2786
2828
|
}
|
|
@@ -2802,11 +2844,12 @@ async function getPackageInfo({
|
|
|
2802
2844
|
pkgVersion,
|
|
2803
2845
|
strict
|
|
2804
2846
|
}) {
|
|
2805
|
-
|
|
2806
|
-
const
|
|
2807
|
-
|
|
2808
|
-
}
|
|
2809
|
-
|
|
2847
|
+
// Lazily access constants.spinner.
|
|
2848
|
+
const {
|
|
2849
|
+
spinner
|
|
2850
|
+
} = constants;
|
|
2851
|
+
spinner.start(pkgVersion === 'latest' ? `Looking up data for the latest version of ${pkgName}` : `Looking up data for version ${pkgVersion} of ${pkgName}`);
|
|
2852
|
+
const packageData = await fetchPackageInfo(pkgName, pkgVersion, includeAllIssues, spinner);
|
|
2810
2853
|
if (packageData) {
|
|
2811
2854
|
formatPackageInfo(packageData, {
|
|
2812
2855
|
name: commandName,
|
|
@@ -2815,10 +2858,13 @@ async function getPackageInfo({
|
|
|
2815
2858
|
pkgName,
|
|
2816
2859
|
pkgVersion,
|
|
2817
2860
|
strict
|
|
2818
|
-
}, spinner
|
|
2861
|
+
}, spinner);
|
|
2819
2862
|
}
|
|
2820
2863
|
}
|
|
2821
2864
|
|
|
2865
|
+
const {
|
|
2866
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$r
|
|
2867
|
+
} = constants;
|
|
2822
2868
|
const config$s = {
|
|
2823
2869
|
commandName: 'info',
|
|
2824
2870
|
description: 'Look up info regarding a package',
|
|
@@ -2860,7 +2906,7 @@ async function run$s(argv, importMeta, {
|
|
|
2860
2906
|
// options or missing arguments.
|
|
2861
2907
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
2862
2908
|
process.exitCode = 2;
|
|
2863
|
-
|
|
2909
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
2864
2910
|
- Expecting a package name ${!rawPkgName ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
2865
2911
|
- Can only accept one package at a time ${cli.input.length > 1 ? colors.red('(got ' + cli.input.length + '!)') : colors.green('(ok)')}\n`);
|
|
2866
2912
|
return;
|
|
@@ -2869,7 +2915,8 @@ async function run$s(argv, importMeta, {
|
|
|
2869
2915
|
const pkgName = versionSeparator < 1 ? rawPkgName : rawPkgName.slice(0, versionSeparator);
|
|
2870
2916
|
const pkgVersion = versionSeparator < 1 ? 'latest' : rawPkgName.slice(versionSeparator + 1);
|
|
2871
2917
|
if (cli.flags['dryRun']) {
|
|
2872
|
-
|
|
2918
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$r);
|
|
2919
|
+
return;
|
|
2873
2920
|
}
|
|
2874
2921
|
await getPackageInfo({
|
|
2875
2922
|
commandName: `${parentName} ${config$s.commandName}`,
|
|
@@ -2889,19 +2936,20 @@ function applyLogin(apiToken, enforcedOrgs, apiBaseUrl, apiProxy) {
|
|
|
2889
2936
|
index.updateSetting('apiProxy', apiProxy);
|
|
2890
2937
|
}
|
|
2891
2938
|
|
|
2892
|
-
// TODO: this type should come from a general Socket REST API type doc
|
|
2893
|
-
|
|
2894
2939
|
const {
|
|
2895
2940
|
SOCKET_PUBLIC_API_TOKEN
|
|
2896
2941
|
} = constants;
|
|
2897
2942
|
async function attemptLogin(apiBaseUrl, apiProxy) {
|
|
2943
|
+
apiBaseUrl ??= index.getSetting('apiBaseUrl') ?? undefined;
|
|
2944
|
+
apiProxy ??= index.getSetting('apiProxy') ?? undefined;
|
|
2898
2945
|
const apiToken = (await prompts.password({
|
|
2899
2946
|
message: `Enter your ${terminalLink('Socket.dev API key', 'https://docs.socket.dev/docs/api-keys')} (leave blank for a public key)`
|
|
2900
2947
|
})) || SOCKET_PUBLIC_API_TOKEN;
|
|
2901
|
-
|
|
2902
|
-
|
|
2903
|
-
|
|
2904
|
-
|
|
2948
|
+
// Lazily access constants.spinner.
|
|
2949
|
+
const {
|
|
2950
|
+
spinner
|
|
2951
|
+
} = constants;
|
|
2952
|
+
spinner.start('Verifying API key...');
|
|
2905
2953
|
let orgs;
|
|
2906
2954
|
try {
|
|
2907
2955
|
const sdk = await index.setupSdk(apiToken, apiBaseUrl, apiProxy);
|
|
@@ -2910,9 +2958,9 @@ async function attemptLogin(apiBaseUrl, apiProxy) {
|
|
|
2910
2958
|
throw new index.AuthError();
|
|
2911
2959
|
}
|
|
2912
2960
|
orgs = result.data;
|
|
2913
|
-
spinner
|
|
2961
|
+
spinner.success('API key verified');
|
|
2914
2962
|
} catch {
|
|
2915
|
-
spinner
|
|
2963
|
+
spinner.errorAndStop('Invalid API key');
|
|
2916
2964
|
return;
|
|
2917
2965
|
}
|
|
2918
2966
|
const enforcedChoices = Object.values(orgs.organizations).filter(org => org?.plan === 'enterprise').map(org => ({
|
|
@@ -2929,7 +2977,7 @@ async function attemptLogin(apiBaseUrl, apiProxy) {
|
|
|
2929
2977
|
description: 'Pick "None" if this is a personal device'
|
|
2930
2978
|
})
|
|
2931
2979
|
}, {
|
|
2932
|
-
spinner
|
|
2980
|
+
spinner
|
|
2933
2981
|
});
|
|
2934
2982
|
if (id) {
|
|
2935
2983
|
enforcedOrgs = [id];
|
|
@@ -2939,7 +2987,7 @@ async function attemptLogin(apiBaseUrl, apiProxy) {
|
|
|
2939
2987
|
message: `Should Socket enforce ${enforcedChoices[0]?.name}'s security policies system-wide?`,
|
|
2940
2988
|
default: true
|
|
2941
2989
|
}, {
|
|
2942
|
-
spinner
|
|
2990
|
+
spinner
|
|
2943
2991
|
});
|
|
2944
2992
|
if (confirmOrg) {
|
|
2945
2993
|
const existing = enforcedChoices[0];
|
|
@@ -2951,12 +2999,15 @@ async function attemptLogin(apiBaseUrl, apiProxy) {
|
|
|
2951
2999
|
const oldToken = index.getSetting('apiToken');
|
|
2952
3000
|
try {
|
|
2953
3001
|
applyLogin(apiToken, enforcedOrgs, apiBaseUrl, apiProxy);
|
|
2954
|
-
spinner
|
|
3002
|
+
spinner.successAndStop(`API credentials ${oldToken ? 'updated' : 'set'}`);
|
|
2955
3003
|
} catch {
|
|
2956
|
-
spinner
|
|
3004
|
+
spinner.errorAndStop(`API login failed`);
|
|
2957
3005
|
}
|
|
2958
3006
|
}
|
|
2959
3007
|
|
|
3008
|
+
const {
|
|
3009
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$q
|
|
3010
|
+
} = constants;
|
|
2960
3011
|
const config$r = {
|
|
2961
3012
|
commandName: 'login',
|
|
2962
3013
|
description: 'Socket API login',
|
|
@@ -3003,7 +3054,8 @@ async function run$r(argv, importMeta, {
|
|
|
3003
3054
|
let apiBaseUrl = cli.flags['apiBaseUrl'];
|
|
3004
3055
|
let apiProxy = cli.flags['apiProxy'];
|
|
3005
3056
|
if (cli.flags['dryRun']) {
|
|
3006
|
-
|
|
3057
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$q);
|
|
3058
|
+
return;
|
|
3007
3059
|
}
|
|
3008
3060
|
if (!isInteractive()) {
|
|
3009
3061
|
throw new index.InputError('Cannot prompt for credentials in a non-interactive shell');
|
|
@@ -3027,6 +3079,9 @@ function attemptLogout() {
|
|
|
3027
3079
|
}
|
|
3028
3080
|
}
|
|
3029
3081
|
|
|
3082
|
+
const {
|
|
3083
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$p
|
|
3084
|
+
} = constants;
|
|
3030
3085
|
const config$q = {
|
|
3031
3086
|
commandName: 'logout',
|
|
3032
3087
|
description: 'Socket API logout',
|
|
@@ -3056,31 +3111,31 @@ async function run$q(argv, importMeta, {
|
|
|
3056
3111
|
parentName
|
|
3057
3112
|
});
|
|
3058
3113
|
if (cli.flags['dryRun']) {
|
|
3059
|
-
|
|
3114
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$p);
|
|
3115
|
+
return;
|
|
3060
3116
|
}
|
|
3061
3117
|
attemptLogout();
|
|
3062
3118
|
}
|
|
3063
3119
|
|
|
3064
3120
|
async function convertGradleToMaven(target, bin, _out, verbose, gradleOpts) {
|
|
3121
|
+
// Lazily access constants.spinner.
|
|
3122
|
+
const {
|
|
3123
|
+
spinner
|
|
3124
|
+
} = constants;
|
|
3065
3125
|
const rbin = path.resolve(bin);
|
|
3066
3126
|
const rtarget = path.resolve(target);
|
|
3067
|
-
// const rout = out === '-' ? '-' : path.resolve(out)
|
|
3068
|
-
|
|
3069
3127
|
if (verbose) {
|
|
3070
|
-
|
|
3071
|
-
|
|
3072
|
-
|
|
3073
|
-
|
|
3074
|
-
console.groupEnd();
|
|
3128
|
+
logger.logger.group('gradle2maven:');
|
|
3129
|
+
logger.logger.log(`[VERBOSE] - Absolute bin path: \`${rbin}\``);
|
|
3130
|
+
logger.logger.log(`[VERBOSE] - Absolute target path: \`${rtarget}\``);
|
|
3131
|
+
logger.logger.groupEnd();
|
|
3075
3132
|
} else {
|
|
3076
|
-
|
|
3077
|
-
|
|
3078
|
-
|
|
3079
|
-
|
|
3080
|
-
|
|
3081
|
-
}
|
|
3082
|
-
const spinner$1 = new spinner.Spinner();
|
|
3083
|
-
spinner$1.start(`Converting gradle to maven from \`${bin}\` on \`${target}\`...`);
|
|
3133
|
+
logger.logger.group('gradle2maven:');
|
|
3134
|
+
logger.logger.log(`- executing: \`${bin}\``);
|
|
3135
|
+
logger.logger.log(`- src dir: \`${target}\``);
|
|
3136
|
+
logger.logger.groupEnd();
|
|
3137
|
+
}
|
|
3138
|
+
spinner.start(`Converting gradle to maven from \`${bin}\` on \`${target}\`...`);
|
|
3084
3139
|
try {
|
|
3085
3140
|
// Run sbt with the init script we provide which should yield zero or more pom files.
|
|
3086
3141
|
// We have to figure out where to store those pom files such that we can upload them and predict them through the GitHub API.
|
|
@@ -3090,36 +3145,37 @@ async function convertGradleToMaven(target, bin, _out, verbose, gradleOpts) {
|
|
|
3090
3145
|
const initLocation = path.join(constants.rootDistPath, 'init.gradle');
|
|
3091
3146
|
const commandArgs = ['--init-script', initLocation, ...gradleOpts, 'pom'];
|
|
3092
3147
|
if (verbose) {
|
|
3093
|
-
spinner
|
|
3148
|
+
spinner.log('[VERBOSE] Executing:', bin, commandArgs);
|
|
3094
3149
|
}
|
|
3095
|
-
const output = await spawn(bin, commandArgs, {
|
|
3150
|
+
const output = await spawn.spawn(bin, commandArgs, {
|
|
3096
3151
|
cwd: target || '.'
|
|
3097
3152
|
});
|
|
3153
|
+
spinner.stop();
|
|
3098
3154
|
if (verbose) {
|
|
3099
|
-
|
|
3100
|
-
|
|
3101
|
-
|
|
3155
|
+
logger.logger.group('[VERBOSE] gradle stdout:');
|
|
3156
|
+
logger.logger.log(output);
|
|
3157
|
+
logger.logger.groupEnd();
|
|
3102
3158
|
}
|
|
3103
3159
|
if (output.stderr) {
|
|
3104
|
-
|
|
3160
|
+
logger.logger.error('There were errors while running gradle');
|
|
3105
3161
|
// (In verbose mode, stderr was printed above, no need to repeat it)
|
|
3106
3162
|
if (!verbose) {
|
|
3107
|
-
|
|
3108
|
-
|
|
3109
|
-
|
|
3163
|
+
logger.logger.group('[VERBOSE] stderr:');
|
|
3164
|
+
logger.logger.error(output.stderr);
|
|
3165
|
+
logger.logger.groupEnd();
|
|
3110
3166
|
}
|
|
3111
3167
|
process.exit(1);
|
|
3112
3168
|
}
|
|
3113
|
-
|
|
3114
|
-
|
|
3169
|
+
logger.logger.success('Executed gradle successfully');
|
|
3170
|
+
logger.logger.log('Reported exports:');
|
|
3115
3171
|
output.stdout.replace(/^POM file copied to: (.*)/gm, (_all, fn) => {
|
|
3116
|
-
|
|
3172
|
+
logger.logger.log('- ', fn);
|
|
3117
3173
|
return fn;
|
|
3118
3174
|
});
|
|
3119
3175
|
|
|
3120
3176
|
// const loc = output.stdout?.match(/Wrote (.*?.pom)\n/)?.[1]?.trim()
|
|
3121
3177
|
// if (!loc) {
|
|
3122
|
-
//
|
|
3178
|
+
// logger.error(
|
|
3123
3179
|
// 'There were no errors from sbt but could not find the location of resulting .pom file either'
|
|
3124
3180
|
// )
|
|
3125
3181
|
// process.exit(1)
|
|
@@ -3128,8 +3184,8 @@ async function convertGradleToMaven(target, bin, _out, verbose, gradleOpts) {
|
|
|
3128
3184
|
// // Move the pom file to ...? initial cwd? loc will be an absolute path, or dump to stdout
|
|
3129
3185
|
// if (out === '-') {
|
|
3130
3186
|
// spinner.start('Result:\n```')
|
|
3131
|
-
//
|
|
3132
|
-
//
|
|
3187
|
+
// spinner.log(await safeReadFile(loc, 'utf8'))
|
|
3188
|
+
// spinner.log('```')
|
|
3133
3189
|
// spinner.successAndStop(`OK`)
|
|
3134
3190
|
// } else {
|
|
3135
3191
|
// spinner.start()
|
|
@@ -3145,16 +3201,20 @@ async function convertGradleToMaven(target, bin, _out, verbose, gradleOpts) {
|
|
|
3145
3201
|
// spinner.successAndStop(`OK. File should be available in \`${out}\``)
|
|
3146
3202
|
// }
|
|
3147
3203
|
} catch (e) {
|
|
3148
|
-
spinner
|
|
3204
|
+
spinner.stop();
|
|
3205
|
+
logger.logger.error('There was an unexpected error while running this' + (verbose ? '' : ' (use --verbose for details)'));
|
|
3149
3206
|
if (verbose) {
|
|
3150
|
-
|
|
3151
|
-
|
|
3152
|
-
|
|
3207
|
+
logger.logger.group('[VERBOSE] error:');
|
|
3208
|
+
logger.logger.log(e);
|
|
3209
|
+
logger.logger.groupEnd();
|
|
3153
3210
|
}
|
|
3154
3211
|
process.exit(1);
|
|
3155
3212
|
}
|
|
3156
3213
|
}
|
|
3157
3214
|
|
|
3215
|
+
const {
|
|
3216
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$o
|
|
3217
|
+
} = constants;
|
|
3158
3218
|
const config$p = {
|
|
3159
3219
|
commandName: 'gradle',
|
|
3160
3220
|
description: '[beta] Use Gradle to generate a manifest file (`pom.xml`) for a Gradle/Java/Kotlin/etc project',
|
|
@@ -3242,22 +3302,23 @@ async function run$p(argv, importMeta, {
|
|
|
3242
3302
|
});
|
|
3243
3303
|
const verbose = Boolean(cli.flags['verbose']);
|
|
3244
3304
|
if (verbose) {
|
|
3245
|
-
|
|
3246
|
-
|
|
3247
|
-
|
|
3248
|
-
|
|
3249
|
-
|
|
3305
|
+
logger.logger.group('- ', parentName, config$p.commandName, ':');
|
|
3306
|
+
logger.logger.group('- flags:', cli.flags);
|
|
3307
|
+
logger.logger.groupEnd();
|
|
3308
|
+
logger.logger.log('- input:', cli.input);
|
|
3309
|
+
logger.logger.groupEnd();
|
|
3250
3310
|
}
|
|
3251
3311
|
const target = cli.input[0];
|
|
3252
3312
|
|
|
3253
|
-
// TODO: I'm not sure it's feasible to parse source file from stdin. We could
|
|
3254
|
-
|
|
3313
|
+
// TODO: I'm not sure it's feasible to parse source file from stdin. We could
|
|
3314
|
+
// try, store contents in a file in some folder, target that folder... what
|
|
3315
|
+
// would the file name be?
|
|
3255
3316
|
if (!target || target === '-' || cli.input.length > 1) {
|
|
3256
3317
|
// Use exit status of 2 to indicate incorrect usage, generally invalid
|
|
3257
3318
|
// options or missing arguments.
|
|
3258
3319
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
3259
3320
|
process.exitCode = 2;
|
|
3260
|
-
|
|
3321
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
3261
3322
|
- The DIR arg is required ${!target ? colors.red('(missing!)') : target === '-' ? colors.red('(stdin is not supported)') : colors.green('(ok)')}\n
|
|
3262
3323
|
- Can only accept one DIR (make sure to escape spaces!) ${cli.input.length > 1 ? colors.red(`(received ${cli.input.length}!)`) : colors.green('(ok)')}\n`);
|
|
3263
3324
|
return;
|
|
@@ -3276,64 +3337,66 @@ async function run$p(argv, importMeta, {
|
|
|
3276
3337
|
out = '-';
|
|
3277
3338
|
}
|
|
3278
3339
|
if (verbose) {
|
|
3279
|
-
|
|
3280
|
-
|
|
3281
|
-
|
|
3282
|
-
|
|
3283
|
-
|
|
3340
|
+
logger.logger.group();
|
|
3341
|
+
logger.logger.log('- target:', target);
|
|
3342
|
+
logger.logger.log('- gradle bin:', bin);
|
|
3343
|
+
logger.logger.log('- out:', out);
|
|
3344
|
+
logger.logger.groupEnd();
|
|
3284
3345
|
}
|
|
3285
3346
|
let gradleOpts = [];
|
|
3286
3347
|
if (cli.flags['gradleOpts']) {
|
|
3287
3348
|
gradleOpts = cli.flags['gradleOpts'].split(' ').map(s => s.trim()).filter(Boolean);
|
|
3288
3349
|
}
|
|
3289
3350
|
if (cli.flags['dryRun']) {
|
|
3290
|
-
|
|
3351
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$o);
|
|
3352
|
+
return;
|
|
3291
3353
|
}
|
|
3292
3354
|
await convertGradleToMaven(target, bin, out, verbose, gradleOpts);
|
|
3293
3355
|
}
|
|
3294
3356
|
|
|
3295
3357
|
async function convertSbtToMaven(target, bin, out, verbose, sbtOpts) {
|
|
3358
|
+
// Lazily access constants.spinner.
|
|
3359
|
+
const {
|
|
3360
|
+
spinner
|
|
3361
|
+
} = constants;
|
|
3296
3362
|
const rbin = path.resolve(bin);
|
|
3297
3363
|
const rtarget = path.resolve(target);
|
|
3298
|
-
// const rout = out === '-' ? '-' : path.resolve(out)
|
|
3299
|
-
|
|
3300
3364
|
if (verbose) {
|
|
3301
|
-
|
|
3302
|
-
|
|
3303
|
-
|
|
3304
|
-
//
|
|
3305
|
-
|
|
3365
|
+
logger.logger.group('sbt2maven:');
|
|
3366
|
+
logger.logger.log(`[VERBOSE] - Absolute bin path: \`${rbin}\``);
|
|
3367
|
+
logger.logger.log(`[VERBOSE] - Absolute target path: \`${rtarget}\``);
|
|
3368
|
+
// logger.log(`[VERBOSE] - Absolute out path: \`${rout}\``)
|
|
3369
|
+
logger.logger.groupEnd();
|
|
3306
3370
|
} else {
|
|
3307
|
-
|
|
3308
|
-
|
|
3309
|
-
|
|
3310
|
-
//
|
|
3311
|
-
|
|
3312
|
-
}
|
|
3313
|
-
|
|
3314
|
-
spinner$1.start(`Converting sbt to maven from \`${bin}\` on \`${target}\`...`);
|
|
3371
|
+
logger.logger.group('sbt2maven:');
|
|
3372
|
+
logger.logger.log(`- executing: \`${bin}\``);
|
|
3373
|
+
logger.logger.log(`- src dir: \`${target}\``);
|
|
3374
|
+
// logger.log(`- dst dir: \`${out}\``)
|
|
3375
|
+
logger.logger.groupEnd();
|
|
3376
|
+
}
|
|
3377
|
+
spinner.start(`Converting sbt to maven from \`${bin}\` on \`${target}\`...`);
|
|
3315
3378
|
try {
|
|
3316
3379
|
// Run sbt with the init script we provide which should yield zero or more
|
|
3317
3380
|
// pom files. We have to figure out where to store those pom files such that
|
|
3318
3381
|
// we can upload them and predict them through the GitHub API. We could do a
|
|
3319
3382
|
// .socket folder. We could do a socket.pom.gz with all the poms, although
|
|
3320
3383
|
// I'd prefer something plain-text if it is to be committed.
|
|
3321
|
-
const output = await spawn(bin, ['makePom'].concat(sbtOpts), {
|
|
3384
|
+
const output = await spawn.spawn(bin, ['makePom'].concat(sbtOpts), {
|
|
3322
3385
|
cwd: target || '.'
|
|
3323
3386
|
});
|
|
3324
|
-
spinner
|
|
3387
|
+
spinner.stop();
|
|
3325
3388
|
if (verbose) {
|
|
3326
|
-
|
|
3327
|
-
|
|
3328
|
-
|
|
3389
|
+
logger.logger.group('[VERBOSE] sbt stdout:');
|
|
3390
|
+
logger.logger.log(output);
|
|
3391
|
+
logger.logger.groupEnd();
|
|
3329
3392
|
}
|
|
3330
3393
|
if (output.stderr) {
|
|
3331
3394
|
logger.logger.error('There were errors while running sbt');
|
|
3332
3395
|
// (In verbose mode, stderr was printed above, no need to repeat it)
|
|
3333
3396
|
if (!verbose) {
|
|
3334
|
-
|
|
3335
|
-
|
|
3336
|
-
|
|
3397
|
+
logger.logger.group('[VERBOSE] stderr:');
|
|
3398
|
+
logger.logger.error(output.stderr);
|
|
3399
|
+
logger.logger.groupEnd();
|
|
3337
3400
|
}
|
|
3338
3401
|
process.exit(1);
|
|
3339
3402
|
}
|
|
@@ -3351,39 +3414,43 @@ async function convertSbtToMaven(target, bin, out, verbose, sbtOpts) {
|
|
|
3351
3414
|
// TODO: maybe we can add an option to target a specific file to dump to stdout
|
|
3352
3415
|
if (out === '-' && poms.length === 1) {
|
|
3353
3416
|
logger.logger.log('Result:\n```');
|
|
3354
|
-
|
|
3417
|
+
logger.logger.log(await index.safeReadFile(poms[0], 'utf8'));
|
|
3355
3418
|
logger.logger.log('```');
|
|
3356
3419
|
logger.logger.success(`OK`);
|
|
3357
3420
|
} else if (out === '-') {
|
|
3358
3421
|
logger.logger.error('Requested out target was stdout but there are multiple generated files');
|
|
3359
|
-
poms.forEach(fn =>
|
|
3360
|
-
|
|
3422
|
+
poms.forEach(fn => logger.logger.error('-', fn));
|
|
3423
|
+
logger.logger.error('Exiting now...');
|
|
3361
3424
|
process.exit(1);
|
|
3362
3425
|
} else {
|
|
3363
3426
|
// if (verbose) {
|
|
3364
|
-
//
|
|
3427
|
+
// logger.log(
|
|
3365
3428
|
// `Moving manifest file from \`${loc.replace(/^\/home\/[^/]*?\//, '~/')}\` to \`${out}\``
|
|
3366
3429
|
// )
|
|
3367
3430
|
// } else {
|
|
3368
|
-
//
|
|
3431
|
+
// logger.log('Moving output pom file')
|
|
3369
3432
|
// }
|
|
3370
3433
|
// TODO: do we prefer fs-extra? renaming can be gnarly on windows and fs-extra's version is better
|
|
3371
3434
|
// await renamep(loc, out)
|
|
3372
3435
|
logger.logger.success(`Generated ${poms.length} pom files`);
|
|
3373
|
-
poms.forEach(fn =>
|
|
3436
|
+
poms.forEach(fn => logger.logger.log('-', fn));
|
|
3374
3437
|
logger.logger.success(`OK`);
|
|
3375
3438
|
}
|
|
3376
3439
|
} catch (e) {
|
|
3377
|
-
spinner
|
|
3440
|
+
spinner.stop();
|
|
3441
|
+
logger.logger.error('There was an unexpected error while running this' + (verbose ? '' : ' (use --verbose for details)'));
|
|
3378
3442
|
if (verbose) {
|
|
3379
|
-
|
|
3380
|
-
|
|
3381
|
-
|
|
3443
|
+
logger.logger.group('[VERBOSE] error:');
|
|
3444
|
+
logger.logger.log(e);
|
|
3445
|
+
logger.logger.groupEnd();
|
|
3382
3446
|
}
|
|
3383
3447
|
process.exit(1);
|
|
3384
3448
|
}
|
|
3385
3449
|
}
|
|
3386
3450
|
|
|
3451
|
+
const {
|
|
3452
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$n
|
|
3453
|
+
} = constants;
|
|
3387
3454
|
const config$o = {
|
|
3388
3455
|
commandName: 'scala',
|
|
3389
3456
|
description: "[beta] Generate a manifest file (`pom.xml`) from Scala's `build.sbt` file",
|
|
@@ -3461,7 +3528,6 @@ const cmdManifestScala = {
|
|
|
3461
3528
|
async function run$o(argv, importMeta, {
|
|
3462
3529
|
parentName
|
|
3463
3530
|
}) {
|
|
3464
|
-
// console.log('scala', argv, parentName)
|
|
3465
3531
|
const cli = meowOrExit({
|
|
3466
3532
|
argv,
|
|
3467
3533
|
config: config$o,
|
|
@@ -3470,22 +3536,23 @@ async function run$o(argv, importMeta, {
|
|
|
3470
3536
|
});
|
|
3471
3537
|
const verbose = Boolean(cli.flags['verbose']);
|
|
3472
3538
|
if (verbose) {
|
|
3473
|
-
|
|
3474
|
-
|
|
3475
|
-
|
|
3476
|
-
|
|
3477
|
-
|
|
3539
|
+
logger.logger.group('- ', parentName, config$o.commandName, ':');
|
|
3540
|
+
logger.logger.group('- flags:', cli.flags);
|
|
3541
|
+
logger.logger.groupEnd();
|
|
3542
|
+
logger.logger.log('- input:', cli.input);
|
|
3543
|
+
logger.logger.groupEnd();
|
|
3478
3544
|
}
|
|
3479
3545
|
const target = cli.input[0];
|
|
3480
3546
|
|
|
3481
|
-
// TODO: I'm not sure it's feasible to parse source file from stdin. We could
|
|
3482
|
-
|
|
3547
|
+
// TODO: I'm not sure it's feasible to parse source file from stdin. We could
|
|
3548
|
+
// try, store contents in a file in some folder, target that folder... what
|
|
3549
|
+
// would the file name be?
|
|
3483
3550
|
if (!target || target === '-' || cli.input.length > 1) {
|
|
3484
3551
|
// Use exit status of 2 to indicate incorrect usage, generally invalid
|
|
3485
3552
|
// options or missing arguments.
|
|
3486
3553
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
3487
3554
|
process.exitCode = 2;
|
|
3488
|
-
|
|
3555
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
3489
3556
|
- The DIR or FILE arg is required ${!target ? colors.red('(missing!)') : target === '-' ? colors.red('(stdin is not supported)') : colors.green('(ok)')}\n
|
|
3490
3557
|
- Can only accept one DIR or FILE (make sure to escape spaces!) ${cli.input.length > 1 ? colors.red(`(received ${cli.input.length}!)`) : colors.green('(ok)')}\n`);
|
|
3491
3558
|
return;
|
|
@@ -3502,22 +3569,26 @@ async function run$o(argv, importMeta, {
|
|
|
3502
3569
|
out = '-';
|
|
3503
3570
|
}
|
|
3504
3571
|
if (verbose) {
|
|
3505
|
-
|
|
3506
|
-
|
|
3507
|
-
|
|
3508
|
-
|
|
3509
|
-
|
|
3572
|
+
logger.logger.group();
|
|
3573
|
+
logger.logger.log('- target:', target);
|
|
3574
|
+
logger.logger.log('- gradle bin:', bin);
|
|
3575
|
+
logger.logger.log('- out:', out);
|
|
3576
|
+
logger.logger.groupEnd();
|
|
3510
3577
|
}
|
|
3511
3578
|
let sbtOpts = [];
|
|
3512
3579
|
if (cli.flags['sbtOpts']) {
|
|
3513
3580
|
sbtOpts = cli.flags['sbtOpts'].split(' ').map(s => s.trim()).filter(Boolean);
|
|
3514
3581
|
}
|
|
3515
3582
|
if (cli.flags['dryRun']) {
|
|
3516
|
-
|
|
3583
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$n);
|
|
3584
|
+
return;
|
|
3517
3585
|
}
|
|
3518
3586
|
await convertSbtToMaven(target, bin, out, verbose, sbtOpts);
|
|
3519
3587
|
}
|
|
3520
3588
|
|
|
3589
|
+
const {
|
|
3590
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$m
|
|
3591
|
+
} = constants;
|
|
3521
3592
|
const config$n = {
|
|
3522
3593
|
commandName: 'auto',
|
|
3523
3594
|
description: 'Auto-detect build and attempt to generate manifest file',
|
|
@@ -3564,12 +3635,12 @@ async function run$n(argv, importMeta, {
|
|
|
3564
3635
|
const verbose = !!cli.flags['verbose'];
|
|
3565
3636
|
const cwd = cli.flags['cwd'] ?? process.cwd();
|
|
3566
3637
|
if (verbose) {
|
|
3567
|
-
|
|
3568
|
-
|
|
3569
|
-
|
|
3570
|
-
|
|
3571
|
-
|
|
3572
|
-
|
|
3638
|
+
logger.logger.group('- ', parentName, config$n.commandName, ':');
|
|
3639
|
+
logger.logger.group('- flags:', cli.flags);
|
|
3640
|
+
logger.logger.groupEnd();
|
|
3641
|
+
logger.logger.log('- input:', cli.input);
|
|
3642
|
+
logger.logger.log('- cwd:', cwd);
|
|
3643
|
+
logger.logger.groupEnd();
|
|
3573
3644
|
}
|
|
3574
3645
|
const subArgs = [];
|
|
3575
3646
|
if (verbose) {
|
|
@@ -3577,13 +3648,14 @@ async function run$n(argv, importMeta, {
|
|
|
3577
3648
|
}
|
|
3578
3649
|
const dir = cwd;
|
|
3579
3650
|
if (fs.existsSync(path.join(dir, 'build.sbt'))) {
|
|
3580
|
-
|
|
3651
|
+
logger.logger.log('Detected a Scala sbt build, running default Scala generator...');
|
|
3581
3652
|
if (cwd) {
|
|
3582
3653
|
subArgs.push('--cwd', cwd);
|
|
3583
3654
|
}
|
|
3584
3655
|
subArgs.push(dir);
|
|
3585
3656
|
if (cli.flags['dryRun']) {
|
|
3586
|
-
|
|
3657
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$m);
|
|
3658
|
+
return;
|
|
3587
3659
|
}
|
|
3588
3660
|
await cmdManifestScala.run(subArgs, importMeta, {
|
|
3589
3661
|
parentName
|
|
@@ -3591,13 +3663,14 @@ async function run$n(argv, importMeta, {
|
|
|
3591
3663
|
return;
|
|
3592
3664
|
}
|
|
3593
3665
|
if (fs.existsSync(path.join(dir, 'gradlew'))) {
|
|
3594
|
-
|
|
3666
|
+
logger.logger.log('Detected a gradle build, running default gradle generator...');
|
|
3595
3667
|
if (cwd) {
|
|
3596
3668
|
// This command takes the cwd as first arg.
|
|
3597
3669
|
subArgs.push(cwd);
|
|
3598
3670
|
}
|
|
3599
3671
|
if (cli.flags['dryRun']) {
|
|
3600
|
-
|
|
3672
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$m);
|
|
3673
|
+
return;
|
|
3601
3674
|
}
|
|
3602
3675
|
await cmdManifestGradle.run(subArgs, importMeta, {
|
|
3603
3676
|
parentName
|
|
@@ -3625,6 +3698,10 @@ async function run$n(argv, importMeta, {
|
|
|
3625
3698
|
}).showHelp();
|
|
3626
3699
|
}
|
|
3627
3700
|
|
|
3701
|
+
const {
|
|
3702
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$l
|
|
3703
|
+
} = constants;
|
|
3704
|
+
|
|
3628
3705
|
// TODO: we may want to dedupe some pieces for all gradle languages. I think it
|
|
3629
3706
|
// makes sense to have separate commands for them and I think it makes
|
|
3630
3707
|
// sense for the help panels to note the requested language, rather than
|
|
@@ -3717,22 +3794,23 @@ async function run$m(argv, importMeta, {
|
|
|
3717
3794
|
});
|
|
3718
3795
|
const verbose = Boolean(cli.flags['verbose']);
|
|
3719
3796
|
if (verbose) {
|
|
3720
|
-
|
|
3721
|
-
|
|
3722
|
-
|
|
3723
|
-
|
|
3724
|
-
|
|
3797
|
+
logger.logger.group('- ', parentName, config$m.commandName, ':');
|
|
3798
|
+
logger.logger.group('- flags:', cli.flags);
|
|
3799
|
+
logger.logger.groupEnd();
|
|
3800
|
+
logger.logger.log('- input:', cli.input);
|
|
3801
|
+
logger.logger.groupEnd();
|
|
3725
3802
|
}
|
|
3726
3803
|
const target = cli.input[0];
|
|
3727
3804
|
|
|
3728
|
-
// TODO: I'm not sure it's feasible to parse source file from stdin. We could
|
|
3729
|
-
|
|
3805
|
+
// TODO: I'm not sure it's feasible to parse source file from stdin. We could
|
|
3806
|
+
// try, store contents in a file in some folder, target that folder... what
|
|
3807
|
+
// would the file name be?
|
|
3730
3808
|
if (!target || target === '-' || cli.input.length > 1) {
|
|
3731
3809
|
// Use exit status of 2 to indicate incorrect usage, generally invalid
|
|
3732
3810
|
// options or missing arguments.
|
|
3733
3811
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
3734
3812
|
process.exitCode = 2;
|
|
3735
|
-
|
|
3813
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
3736
3814
|
- The DIR arg is required ${!target ? colors.red('(missing!)') : target === '-' ? colors.red('(stdin is not supported)') : colors.green('(ok)')}\n
|
|
3737
3815
|
- Can only accept one DIR (make sure to escape spaces!) ${cli.input.length > 1 ? colors.red(`(received ${cli.input.length}!)`) : colors.green('(ok)')}\n`);
|
|
3738
3816
|
return;
|
|
@@ -3751,18 +3829,19 @@ async function run$m(argv, importMeta, {
|
|
|
3751
3829
|
out = '-';
|
|
3752
3830
|
}
|
|
3753
3831
|
if (verbose) {
|
|
3754
|
-
|
|
3755
|
-
|
|
3756
|
-
|
|
3757
|
-
|
|
3758
|
-
|
|
3832
|
+
logger.logger.group();
|
|
3833
|
+
logger.logger.log('- target:', target);
|
|
3834
|
+
logger.logger.log('- gradle bin:', bin);
|
|
3835
|
+
logger.logger.log('- out:', out);
|
|
3836
|
+
logger.logger.groupEnd();
|
|
3759
3837
|
}
|
|
3760
3838
|
let gradleOpts = [];
|
|
3761
3839
|
if (cli.flags['gradleOpts']) {
|
|
3762
3840
|
gradleOpts = cli.flags['gradleOpts'].split(' ').map(s => s.trim()).filter(Boolean);
|
|
3763
3841
|
}
|
|
3764
3842
|
if (cli.flags['dryRun']) {
|
|
3765
|
-
|
|
3843
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$l);
|
|
3844
|
+
return;
|
|
3766
3845
|
}
|
|
3767
3846
|
await convertGradleToMaven(target, bin, out, verbose, gradleOpts);
|
|
3768
3847
|
}
|
|
@@ -3814,6 +3893,7 @@ async function wrapNpm(argv) {
|
|
|
3814
3893
|
}
|
|
3815
3894
|
|
|
3816
3895
|
const {
|
|
3896
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$k,
|
|
3817
3897
|
NPM: NPM$a
|
|
3818
3898
|
} = constants;
|
|
3819
3899
|
const config$k = {
|
|
@@ -3842,7 +3922,8 @@ async function run$k(argv, importMeta, {
|
|
|
3842
3922
|
parentName
|
|
3843
3923
|
});
|
|
3844
3924
|
if (cli.flags['dryRun']) {
|
|
3845
|
-
|
|
3925
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$k);
|
|
3926
|
+
return;
|
|
3846
3927
|
}
|
|
3847
3928
|
await wrapNpm(argv);
|
|
3848
3929
|
}
|
|
@@ -3858,6 +3939,7 @@ async function wrapNpx(argv) {
|
|
|
3858
3939
|
}
|
|
3859
3940
|
|
|
3860
3941
|
const {
|
|
3942
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$j,
|
|
3861
3943
|
NPX: NPX$1
|
|
3862
3944
|
} = constants;
|
|
3863
3945
|
const config$j = {
|
|
@@ -3886,11 +3968,15 @@ async function run$j(argv, importMeta, {
|
|
|
3886
3968
|
parentName
|
|
3887
3969
|
});
|
|
3888
3970
|
if (cli.flags['dryRun']) {
|
|
3889
|
-
|
|
3971
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$j);
|
|
3972
|
+
return;
|
|
3890
3973
|
}
|
|
3891
3974
|
await wrapNpx(argv);
|
|
3892
3975
|
}
|
|
3893
3976
|
|
|
3977
|
+
const {
|
|
3978
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$i
|
|
3979
|
+
} = constants;
|
|
3894
3980
|
const config$i = {
|
|
3895
3981
|
commandName: 'oops',
|
|
3896
3982
|
description: 'Trigger an intentional error (for development)',
|
|
@@ -3920,7 +4006,8 @@ async function run$i(argv, importMeta, {
|
|
|
3920
4006
|
parentName
|
|
3921
4007
|
});
|
|
3922
4008
|
if (cli.flags['dryRun']) {
|
|
3923
|
-
|
|
4009
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$i);
|
|
4010
|
+
return;
|
|
3924
4011
|
}
|
|
3925
4012
|
throw new Error('This error was intentionally left blank');
|
|
3926
4013
|
}
|
|
@@ -3973,7 +4060,7 @@ async function getAgentVersion(agentExecPath, cwd) {
|
|
|
3973
4060
|
try {
|
|
3974
4061
|
result = semver.coerce(
|
|
3975
4062
|
// All package managers support the "--version" flag.
|
|
3976
|
-
(await spawn(agentExecPath, ['--version'], {
|
|
4063
|
+
(await spawn.spawn(agentExecPath, ['--version'], {
|
|
3977
4064
|
cwd
|
|
3978
4065
|
})).stdout) ?? undefined;
|
|
3979
4066
|
} catch {}
|
|
@@ -4028,7 +4115,7 @@ const readLockFileByAgent = (() => {
|
|
|
4028
4115
|
// To print a Yarn lockfile to your console without writing it to disk
|
|
4029
4116
|
// use `bun bun.lockb`.
|
|
4030
4117
|
// https://bun.sh/guides/install/yarnlock
|
|
4031
|
-
return (await spawn(agentExecPath, [lockPath])).stdout.trim();
|
|
4118
|
+
return (await spawn.spawn(agentExecPath, [lockPath])).stdout.trim();
|
|
4032
4119
|
}
|
|
4033
4120
|
return undefined;
|
|
4034
4121
|
}),
|
|
@@ -4427,7 +4514,7 @@ function parseableToQueryStdout(stdout) {
|
|
|
4427
4514
|
async function npmQuery(npmExecPath, cwd) {
|
|
4428
4515
|
let stdout = '';
|
|
4429
4516
|
try {
|
|
4430
|
-
stdout = (await spawn(npmExecPath, ['query', ':not(.dev)'], {
|
|
4517
|
+
stdout = (await spawn.spawn(npmExecPath, ['query', ':not(.dev)'], {
|
|
4431
4518
|
cwd
|
|
4432
4519
|
})).stdout;
|
|
4433
4520
|
} catch {}
|
|
@@ -4437,7 +4524,7 @@ async function lsBun(agentExecPath, cwd) {
|
|
|
4437
4524
|
try {
|
|
4438
4525
|
// Bun does not support filtering by production packages yet.
|
|
4439
4526
|
// https://github.com/oven-sh/bun/issues/8283
|
|
4440
|
-
return (await spawn(agentExecPath, ['pm', 'ls', '--all'], {
|
|
4527
|
+
return (await spawn.spawn(agentExecPath, ['pm', 'ls', '--all'], {
|
|
4441
4528
|
cwd
|
|
4442
4529
|
})).stdout;
|
|
4443
4530
|
} catch {}
|
|
@@ -4456,7 +4543,7 @@ async function lsPnpm(agentExecPath, cwd, options) {
|
|
|
4456
4543
|
}
|
|
4457
4544
|
let stdout = '';
|
|
4458
4545
|
try {
|
|
4459
|
-
stdout = (await spawn(agentExecPath, ['ls', '--parseable', '--prod', '--depth', 'Infinity'], {
|
|
4546
|
+
stdout = (await spawn.spawn(agentExecPath, ['ls', '--parseable', '--prod', '--depth', 'Infinity'], {
|
|
4460
4547
|
cwd
|
|
4461
4548
|
})).stdout;
|
|
4462
4549
|
} catch {}
|
|
@@ -4465,7 +4552,7 @@ async function lsPnpm(agentExecPath, cwd, options) {
|
|
|
4465
4552
|
async function lsVlt(agentExecPath, cwd) {
|
|
4466
4553
|
let stdout = '';
|
|
4467
4554
|
try {
|
|
4468
|
-
stdout = (await spawn(agentExecPath, ['ls', '--view', 'human', ':not(.dev)'], {
|
|
4555
|
+
stdout = (await spawn.spawn(agentExecPath, ['ls', '--view', 'human', ':not(.dev)'], {
|
|
4469
4556
|
cwd
|
|
4470
4557
|
})).stdout;
|
|
4471
4558
|
} catch {}
|
|
@@ -4476,7 +4563,7 @@ async function lsYarnBerry(agentExecPath, cwd) {
|
|
|
4476
4563
|
return (
|
|
4477
4564
|
// Yarn Berry does not support filtering by production packages yet.
|
|
4478
4565
|
// https://github.com/yarnpkg/berry/issues/5117
|
|
4479
|
-
(await spawn(agentExecPath, ['info', '--recursive', '--name-only'], {
|
|
4566
|
+
(await spawn.spawn(agentExecPath, ['info', '--recursive', '--name-only'], {
|
|
4480
4567
|
cwd
|
|
4481
4568
|
})).stdout.trim()
|
|
4482
4569
|
);
|
|
@@ -4489,7 +4576,7 @@ async function lsYarnClassic(agentExecPath, cwd) {
|
|
|
4489
4576
|
// https://github.com/yarnpkg/yarn/releases/tag/v1.0.0
|
|
4490
4577
|
// > Fix: Excludes dev dependencies from the yarn list output when the
|
|
4491
4578
|
// environment is production
|
|
4492
|
-
return (await spawn(agentExecPath, ['list', '--prod'], {
|
|
4579
|
+
return (await spawn.spawn(agentExecPath, ['list', '--prod'], {
|
|
4493
4580
|
cwd
|
|
4494
4581
|
})).stdout.trim();
|
|
4495
4582
|
} catch {}
|
|
@@ -4614,14 +4701,73 @@ function pnpmUpdatePkgJson(editablePkgJson, overrides) {
|
|
|
4614
4701
|
}
|
|
4615
4702
|
const updateManifestByAgent = new Map([[BUN, updateResolutions], [NPM$4, updateOverrides], [PNPM$1, pnpmUpdatePkgJson], [VLT, updateOverrides], [YARN_BERRY, updateResolutions], [YARN_CLASSIC$1, updateResolutions]]);
|
|
4616
4703
|
|
|
4704
|
+
const {
|
|
4705
|
+
SOCKET_IPC_HANDSHAKE
|
|
4706
|
+
} = constants;
|
|
4707
|
+
function safeNpmInstall(options) {
|
|
4708
|
+
const {
|
|
4709
|
+
args = [],
|
|
4710
|
+
ipc,
|
|
4711
|
+
spinner,
|
|
4712
|
+
...spawnOptions
|
|
4713
|
+
} = {
|
|
4714
|
+
__proto__: null,
|
|
4715
|
+
...options
|
|
4716
|
+
};
|
|
4717
|
+
const terminatorPos = args.indexOf('--');
|
|
4718
|
+
const npmArgs = (terminatorPos === -1 ? args : args.slice(0, terminatorPos)).filter(a => !npm.isAuditFlag(a) && !npm.isFundFlag(a) && !npm.isProgressFlag(a));
|
|
4719
|
+
const otherArgs = terminatorPos === -1 ? [] : args.slice(terminatorPos);
|
|
4720
|
+
const useIpc = objects.isObject(ipc);
|
|
4721
|
+
const useDebug = debug.isDebug();
|
|
4722
|
+
const isSilent = !useDebug && !npmArgs.some(npm.isLoglevelFlag);
|
|
4723
|
+
const spawnPromise = spawn.spawn(
|
|
4724
|
+
// Lazily access constants.execPath.
|
|
4725
|
+
constants.execPath, [
|
|
4726
|
+
// Lazily access constants.nodeNoWarningsFlags.
|
|
4727
|
+
...constants.nodeNoWarningsFlags, '--require',
|
|
4728
|
+
// Lazily access constants.npmInjectionPath.
|
|
4729
|
+
constants.npmInjectionPath, npmPaths.getNpmBinPath(), 'install',
|
|
4730
|
+
// Even though the '--silent' flag is passed npm will still run through
|
|
4731
|
+
// code paths for 'audit' and 'fund' unless '--no-audit' and '--no-fund'
|
|
4732
|
+
// flags are passed.
|
|
4733
|
+
'--no-audit', '--no-fund',
|
|
4734
|
+
// Add `--no-progress` and `--silent` flags to fix input being swallowed
|
|
4735
|
+
// by the spinner when running the command with recent versions of npm.
|
|
4736
|
+
'--no-progress',
|
|
4737
|
+
// Add the '--silent' flag if a loglevel flag is not provided and the
|
|
4738
|
+
// SOCKET_CLI_DEBUG environment variable is not truthy.
|
|
4739
|
+
...(isSilent ? ['--silent'] : []), ...npmArgs, ...otherArgs], {
|
|
4740
|
+
spinner,
|
|
4741
|
+
// Set stdio to include 'ipc'.
|
|
4742
|
+
// See https://github.com/nodejs/node/blob/v23.6.0/lib/child_process.js#L161-L166
|
|
4743
|
+
// and https://github.com/nodejs/node/blob/v23.6.0/lib/internal/child_process.js#L238.
|
|
4744
|
+
stdio: isSilent ?
|
|
4745
|
+
// 'ignore'
|
|
4746
|
+
useIpc ? ['ignore', 'ignore', 'ignore', 'ipc'] : 'ignore' :
|
|
4747
|
+
// 'inherit'
|
|
4748
|
+
useIpc ? [0, 1, 2, 'ipc'] : 'inherit',
|
|
4749
|
+
...spawnOptions,
|
|
4750
|
+
env: {
|
|
4751
|
+
...process$1.env,
|
|
4752
|
+
...spawnOptions.env
|
|
4753
|
+
}
|
|
4754
|
+
});
|
|
4755
|
+
if (useIpc) {
|
|
4756
|
+
spawnPromise.process.send({
|
|
4757
|
+
[SOCKET_IPC_HANDSHAKE]: ipc
|
|
4758
|
+
});
|
|
4759
|
+
}
|
|
4760
|
+
return spawnPromise;
|
|
4761
|
+
}
|
|
4762
|
+
|
|
4617
4763
|
const {
|
|
4618
4764
|
NPM: NPM$3,
|
|
4619
|
-
abortSignal
|
|
4765
|
+
abortSignal
|
|
4620
4766
|
} = constants;
|
|
4621
4767
|
function runAgentInstall(agent, agentExecPath, options) {
|
|
4622
4768
|
// All package managers support the "install" command.
|
|
4623
4769
|
if (agent === NPM$3) {
|
|
4624
|
-
return
|
|
4770
|
+
return safeNpmInstall(options);
|
|
4625
4771
|
}
|
|
4626
4772
|
const {
|
|
4627
4773
|
args = [],
|
|
@@ -4631,13 +4777,10 @@ function runAgentInstall(agent, agentExecPath, options) {
|
|
|
4631
4777
|
__proto__: null,
|
|
4632
4778
|
...options
|
|
4633
4779
|
};
|
|
4634
|
-
const isSilent = !
|
|
4635
|
-
|
|
4636
|
-
|
|
4637
|
-
spinner
|
|
4638
|
-
}
|
|
4639
|
-
let spawnPromise = spawn(agentExecPath, ['install', ...args], {
|
|
4640
|
-
signal: abortSignal$2,
|
|
4780
|
+
const isSilent = !debug.isDebug();
|
|
4781
|
+
return spawn.spawn(agentExecPath, ['install', ...args], {
|
|
4782
|
+
signal: abortSignal,
|
|
4783
|
+
spinner,
|
|
4641
4784
|
stdio: isSilent ? 'ignore' : 'inherit',
|
|
4642
4785
|
...spawnOptions,
|
|
4643
4786
|
env: {
|
|
@@ -4645,22 +4788,12 @@ function runAgentInstall(agent, agentExecPath, options) {
|
|
|
4645
4788
|
...spawnOptions.env
|
|
4646
4789
|
}
|
|
4647
4790
|
});
|
|
4648
|
-
if (!isSilent && isSpinning) {
|
|
4649
|
-
const oldSpawnPromise = spawnPromise;
|
|
4650
|
-
spawnPromise = spawnPromise.finally(() => {
|
|
4651
|
-
spinner?.start();
|
|
4652
|
-
});
|
|
4653
|
-
spawnPromise.process = oldSpawnPromise.process;
|
|
4654
|
-
spawnPromise.stdin = spawnPromise.stdin;
|
|
4655
|
-
}
|
|
4656
|
-
return spawnPromise;
|
|
4657
4791
|
}
|
|
4658
4792
|
|
|
4659
4793
|
const {
|
|
4660
4794
|
NPM: NPM$2
|
|
4661
4795
|
} = constants;
|
|
4662
4796
|
const COMMAND_TITLE$1 = 'Socket Optimize';
|
|
4663
|
-
const NPM_OVERRIDE_PR_URL = 'https://github.com/npm/cli/pull/8089';
|
|
4664
4797
|
async function updatePackageLockJson(pkgEnvDetails, options) {
|
|
4665
4798
|
const {
|
|
4666
4799
|
logger,
|
|
@@ -4676,10 +4809,11 @@ async function updatePackageLockJson(pkgEnvDetails, options) {
|
|
|
4676
4809
|
});
|
|
4677
4810
|
spinner?.stop();
|
|
4678
4811
|
if (pkgEnvDetails.agent === NPM$2) {
|
|
4679
|
-
logger?.log(`💡 Re-run ${COMMAND_TITLE$1} whenever ${pkgEnvDetails.lockName} changes.\n This can be skipped once npm
|
|
4812
|
+
logger?.log(`💡 Re-run ${COMMAND_TITLE$1} whenever ${pkgEnvDetails.lockName} changes.\n This can be skipped once npm v11.2.0 is released.`);
|
|
4680
4813
|
}
|
|
4681
4814
|
} catch (e) {
|
|
4682
|
-
spinner?.
|
|
4815
|
+
spinner?.stop();
|
|
4816
|
+
logger?.error(`${COMMAND_TITLE$1}: ${pkgEnvDetails.agent} install failed to update ${pkgEnvDetails.lockName}`);
|
|
4683
4817
|
logger?.error(e);
|
|
4684
4818
|
}
|
|
4685
4819
|
}
|
|
@@ -4692,44 +4826,44 @@ const {
|
|
|
4692
4826
|
const COMMAND_TITLE = 'Socket Optimize';
|
|
4693
4827
|
const manifestNpmOverrides = registry.getManifestData(NPM$1);
|
|
4694
4828
|
async function applyOptimization(cwd, pin, prod) {
|
|
4695
|
-
const logger = console;
|
|
4696
4829
|
const pkgEnvDetails = await detectAndValidatePackageEnvironment(cwd, {
|
|
4697
|
-
logger,
|
|
4830
|
+
logger: logger.logger,
|
|
4698
4831
|
prod
|
|
4699
4832
|
});
|
|
4700
4833
|
if (!pkgEnvDetails) {
|
|
4701
4834
|
return;
|
|
4702
4835
|
}
|
|
4703
|
-
|
|
4704
|
-
|
|
4705
|
-
|
|
4706
|
-
|
|
4836
|
+
// Lazily access constants.spinner.
|
|
4837
|
+
const {
|
|
4838
|
+
spinner
|
|
4839
|
+
} = constants;
|
|
4840
|
+
spinner.start('Socket optimizing...');
|
|
4707
4841
|
const state = await addOverrides(pkgEnvDetails.pkgPath, pkgEnvDetails, {
|
|
4708
|
-
logger,
|
|
4842
|
+
logger: logger.logger,
|
|
4709
4843
|
pin,
|
|
4710
4844
|
prod,
|
|
4711
|
-
spinner
|
|
4845
|
+
spinner
|
|
4712
4846
|
});
|
|
4713
|
-
spinner
|
|
4847
|
+
spinner.stop();
|
|
4714
4848
|
const addedCount = state.added.size;
|
|
4715
4849
|
const updatedCount = state.updated.size;
|
|
4716
4850
|
const pkgJsonChanged = addedCount > 0 || updatedCount > 0;
|
|
4717
4851
|
if (pkgJsonChanged) {
|
|
4718
4852
|
if (updatedCount > 0) {
|
|
4719
|
-
logger?.log(`${createActionMessage('Updated', updatedCount, state.updatedInWorkspaces.size)}${addedCount ? '.' : '🚀'}`);
|
|
4853
|
+
logger.logger?.log(`${createActionMessage('Updated', updatedCount, state.updatedInWorkspaces.size)}${addedCount ? '.' : '🚀'}`);
|
|
4720
4854
|
}
|
|
4721
4855
|
if (addedCount > 0) {
|
|
4722
|
-
logger?.log(`${createActionMessage('Added', addedCount, state.addedInWorkspaces.size)} 🚀`);
|
|
4856
|
+
logger.logger?.log(`${createActionMessage('Added', addedCount, state.addedInWorkspaces.size)} 🚀`);
|
|
4723
4857
|
}
|
|
4724
4858
|
} else {
|
|
4725
|
-
logger?.log('Congratulations! Already Socket.dev optimized 🎉');
|
|
4859
|
+
logger.logger?.log('Congratulations! Already Socket.dev optimized 🎉');
|
|
4726
4860
|
}
|
|
4727
4861
|
if (pkgEnvDetails.agent === NPM$1 || pkgJsonChanged) {
|
|
4728
4862
|
// Always update package-lock.json until the npm overrides PR lands:
|
|
4729
4863
|
// https://github.com/npm/cli/pull/8089
|
|
4730
4864
|
await updatePackageLockJson(pkgEnvDetails, {
|
|
4731
|
-
logger,
|
|
4732
|
-
spinner
|
|
4865
|
+
logger: logger.logger,
|
|
4866
|
+
spinner
|
|
4733
4867
|
});
|
|
4734
4868
|
}
|
|
4735
4869
|
}
|
|
@@ -4915,6 +5049,9 @@ async function addOverrides(pkgPath, pkgEnvDetails, options) {
|
|
|
4915
5049
|
return state;
|
|
4916
5050
|
}
|
|
4917
5051
|
|
|
5052
|
+
const {
|
|
5053
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$h
|
|
5054
|
+
} = constants;
|
|
4918
5055
|
const config$h = {
|
|
4919
5056
|
commandName: 'optimize',
|
|
4920
5057
|
description: 'Optimize dependencies with @socketregistry overrides',
|
|
@@ -4960,7 +5097,8 @@ async function run$h(argv, importMeta, {
|
|
|
4960
5097
|
});
|
|
4961
5098
|
const cwd = process$1.cwd();
|
|
4962
5099
|
if (cli.flags['dryRun']) {
|
|
4963
|
-
|
|
5100
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$h);
|
|
5101
|
+
return;
|
|
4964
5102
|
}
|
|
4965
5103
|
await applyOptimization(cwd, Boolean(cli.flags['pin']), Boolean(cli.flags['prod']));
|
|
4966
5104
|
}
|
|
@@ -4973,21 +5111,24 @@ async function getOrganization(format = 'text') {
|
|
|
4973
5111
|
await printOrganizationsFromToken(apiToken, format);
|
|
4974
5112
|
}
|
|
4975
5113
|
async function printOrganizationsFromToken(apiToken, format = 'text') {
|
|
4976
|
-
|
|
4977
|
-
|
|
5114
|
+
// Lazily access constants.spinner.
|
|
5115
|
+
const {
|
|
5116
|
+
spinner
|
|
5117
|
+
} = constants;
|
|
5118
|
+
spinner.start('Fetching organizations...');
|
|
4978
5119
|
const socketSdk = await index.setupSdk(apiToken);
|
|
4979
5120
|
const result = await handleApiCall(socketSdk.getOrganizations(), 'looking up organizations');
|
|
4980
5121
|
if (!result.success) {
|
|
4981
|
-
handleUnsuccessfulApiResponse('getOrganizations', result, spinner
|
|
5122
|
+
handleUnsuccessfulApiResponse('getOrganizations', result, spinner);
|
|
4982
5123
|
return;
|
|
4983
5124
|
}
|
|
4984
|
-
spinner
|
|
5125
|
+
spinner.stop();
|
|
4985
5126
|
const organizations = Object.values(result.data.organizations);
|
|
4986
5127
|
const lastFiveOfApiToken = getLastFiveOfApiToken(apiToken);
|
|
4987
5128
|
switch (format) {
|
|
4988
5129
|
case 'json':
|
|
4989
5130
|
{
|
|
4990
|
-
|
|
5131
|
+
logger.logger.log(JSON.stringify(organizations.map(o => ({
|
|
4991
5132
|
name: o.name,
|
|
4992
5133
|
id: o.id,
|
|
4993
5134
|
plan: o.plan
|
|
@@ -5008,27 +5149,30 @@ async function printOrganizationsFromToken(apiToken, format = 'text') {
|
|
|
5008
5149
|
mw2 = Math.max(mw2, o.id.length);
|
|
5009
5150
|
mw3 = Math.max(mw3, o.plan.length);
|
|
5010
5151
|
}
|
|
5011
|
-
|
|
5012
|
-
|
|
5013
|
-
|
|
5014
|
-
|
|
5152
|
+
logger.logger.log('# Organizations\n');
|
|
5153
|
+
logger.logger.log(`List of organizations associated with your API key, ending with: ${colors.italic(lastFiveOfApiToken)}\n`);
|
|
5154
|
+
logger.logger.log(`| Name${' '.repeat(mw1 - 4)} | ID${' '.repeat(mw2 - 2)} | Plan${' '.repeat(mw3 - 4)} |`);
|
|
5155
|
+
logger.logger.log(`| ${'-'.repeat(mw1)} | ${'-'.repeat(mw2)} | ${'-'.repeat(mw3)} |`);
|
|
5015
5156
|
for (const o of organizations) {
|
|
5016
|
-
|
|
5157
|
+
logger.logger.log(`| ${(o.name || '').padEnd(mw1, ' ')} | ${(o.id || '').padEnd(mw2, ' ')} | ${(o.plan || '').padEnd(mw3, ' ')} |`);
|
|
5017
5158
|
}
|
|
5018
|
-
|
|
5159
|
+
logger.logger.log(`| ${'-'.repeat(mw1)} | ${'-'.repeat(mw2)} | ${'-'.repeat(mw3)} |`);
|
|
5019
5160
|
return;
|
|
5020
5161
|
}
|
|
5021
5162
|
default:
|
|
5022
5163
|
{
|
|
5023
|
-
|
|
5164
|
+
logger.logger.log(`List of organizations associated with your API key, ending with: ${colors.italic(lastFiveOfApiToken)}\n`);
|
|
5024
5165
|
// Just dump
|
|
5025
5166
|
for (const o of organizations) {
|
|
5026
|
-
|
|
5167
|
+
logger.logger.log(`- Name: ${colors.bold(o.name)}, ID: ${colors.bold(o.id)}, Plan: ${colors.bold(o.plan)}`);
|
|
5027
5168
|
}
|
|
5028
5169
|
}
|
|
5029
5170
|
}
|
|
5030
5171
|
}
|
|
5031
5172
|
|
|
5173
|
+
const {
|
|
5174
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$g
|
|
5175
|
+
} = constants;
|
|
5032
5176
|
const config$g = {
|
|
5033
5177
|
commandName: 'organizations',
|
|
5034
5178
|
description: 'List organizations associated with the API key used',
|
|
@@ -5066,31 +5210,25 @@ async function run$g(argv, importMeta, {
|
|
|
5066
5210
|
// options or missing arguments.
|
|
5067
5211
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
5068
5212
|
process.exitCode = 2;
|
|
5069
|
-
|
|
5213
|
+
logger.logger.error(`
|
|
5070
5214
|
${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
5071
5215
|
- The json and markdown flags cannot be both set, pick one
|
|
5072
5216
|
`);
|
|
5073
5217
|
return;
|
|
5074
5218
|
}
|
|
5075
5219
|
if (cli.flags['dryRun']) {
|
|
5076
|
-
|
|
5220
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$g);
|
|
5221
|
+
return;
|
|
5077
5222
|
}
|
|
5078
5223
|
await getOrganization(json ? 'json' : markdown ? 'markdown' : 'text');
|
|
5079
5224
|
}
|
|
5080
5225
|
|
|
5081
|
-
const {
|
|
5082
|
-
abortSignal: abortSignal$1
|
|
5083
|
-
} = constants;
|
|
5084
5226
|
async function runRawNpm(argv) {
|
|
5085
|
-
const spawnPromise = spawn(npmPaths.getNpmBinPath(), argv
|
|
5086
|
-
signal: abortSignal$1,
|
|
5227
|
+
const spawnPromise = spawn.spawn(npmPaths.getNpmBinPath(), argv, {
|
|
5087
5228
|
stdio: 'inherit'
|
|
5088
5229
|
});
|
|
5089
5230
|
// See https://nodejs.org/api/all.html#all_child_process_event-exit.
|
|
5090
5231
|
spawnPromise.process.on('exit', (code, signalName) => {
|
|
5091
|
-
if (abortSignal$1.aborted) {
|
|
5092
|
-
return;
|
|
5093
|
-
}
|
|
5094
5232
|
if (signalName) {
|
|
5095
5233
|
process$1.kill(process$1.pid, signalName);
|
|
5096
5234
|
} else if (code !== null) {
|
|
@@ -5101,6 +5239,7 @@ async function runRawNpm(argv) {
|
|
|
5101
5239
|
}
|
|
5102
5240
|
|
|
5103
5241
|
const {
|
|
5242
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$f,
|
|
5104
5243
|
NPM
|
|
5105
5244
|
} = constants;
|
|
5106
5245
|
const config$f = {
|
|
@@ -5135,24 +5274,18 @@ async function run$f(argv, importMeta, {
|
|
|
5135
5274
|
parentName
|
|
5136
5275
|
});
|
|
5137
5276
|
if (cli.flags['dryRun']) {
|
|
5138
|
-
|
|
5277
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$f);
|
|
5278
|
+
return;
|
|
5139
5279
|
}
|
|
5140
5280
|
await runRawNpm(argv);
|
|
5141
5281
|
}
|
|
5142
5282
|
|
|
5143
|
-
const {
|
|
5144
|
-
abortSignal
|
|
5145
|
-
} = constants;
|
|
5146
5283
|
async function runRawNpx(argv) {
|
|
5147
|
-
const spawnPromise = spawn(npmPaths.getNpxBinPath(), argv, {
|
|
5148
|
-
signal: abortSignal,
|
|
5284
|
+
const spawnPromise = spawn.spawn(npmPaths.getNpxBinPath(), argv, {
|
|
5149
5285
|
stdio: 'inherit'
|
|
5150
5286
|
});
|
|
5151
5287
|
// See https://nodejs.org/api/all.html#all_child_process_event-exit.
|
|
5152
5288
|
spawnPromise.process.on('exit', (code, signalName) => {
|
|
5153
|
-
if (abortSignal.aborted) {
|
|
5154
|
-
return;
|
|
5155
|
-
}
|
|
5156
5289
|
if (signalName) {
|
|
5157
5290
|
process$1.kill(process$1.pid, signalName);
|
|
5158
5291
|
} else if (code !== null) {
|
|
@@ -5163,6 +5296,7 @@ async function runRawNpx(argv) {
|
|
|
5163
5296
|
}
|
|
5164
5297
|
|
|
5165
5298
|
const {
|
|
5299
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$e,
|
|
5166
5300
|
NPX
|
|
5167
5301
|
} = constants;
|
|
5168
5302
|
const config$e = {
|
|
@@ -5197,18 +5331,26 @@ async function run$e(argv, importMeta, {
|
|
|
5197
5331
|
parentName
|
|
5198
5332
|
});
|
|
5199
5333
|
if (cli.flags['dryRun']) {
|
|
5200
|
-
|
|
5334
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$e);
|
|
5335
|
+
return;
|
|
5201
5336
|
}
|
|
5202
5337
|
await runRawNpx(argv);
|
|
5203
5338
|
}
|
|
5204
5339
|
|
|
5340
|
+
const {
|
|
5341
|
+
DRY_RUN_LABEL
|
|
5342
|
+
} = constants;
|
|
5205
5343
|
async function createReport(socketConfig, inputPaths, {
|
|
5206
5344
|
cwd,
|
|
5207
5345
|
dryRun
|
|
5208
5346
|
}) {
|
|
5347
|
+
// Lazily access constants.spinner.
|
|
5348
|
+
const {
|
|
5349
|
+
spinner
|
|
5350
|
+
} = constants;
|
|
5209
5351
|
const socketSdk = await index.setupSdk();
|
|
5210
5352
|
const supportedFiles = await socketSdk.getReportSupportedFiles().then(res => {
|
|
5211
|
-
if (!res.success) handleUnsuccessfulApiResponse('getReportSupportedFiles', res,
|
|
5353
|
+
if (!res.success) handleUnsuccessfulApiResponse('getReportSupportedFiles', res, spinner);
|
|
5212
5354
|
return res.data;
|
|
5213
5355
|
}).catch(cause => {
|
|
5214
5356
|
throw new Error('Failed getting supported files for report', {
|
|
@@ -5219,24 +5361,23 @@ async function createReport(socketConfig, inputPaths, {
|
|
|
5219
5361
|
const {
|
|
5220
5362
|
length: packagePathsCount
|
|
5221
5363
|
} = packagePaths;
|
|
5222
|
-
if (packagePathsCount &&
|
|
5364
|
+
if (packagePathsCount && debug.isDebug()) {
|
|
5223
5365
|
for (const pkgPath of packagePaths) {
|
|
5224
|
-
|
|
5366
|
+
debug.debugLog(`Uploading: ${pkgPath}`);
|
|
5225
5367
|
}
|
|
5226
5368
|
}
|
|
5227
5369
|
if (dryRun) {
|
|
5228
|
-
|
|
5370
|
+
debug.debugLog(`${DRY_RUN_LABEL}: Skipped actual upload`);
|
|
5229
5371
|
return undefined;
|
|
5230
5372
|
}
|
|
5231
|
-
|
|
5232
|
-
spinner$1.start(`Creating report with ${packagePathsCount} package ${words.pluralize('file', packagePathsCount)}`);
|
|
5373
|
+
spinner.start(`Creating report with ${packagePathsCount} package ${words.pluralize('file', packagePathsCount)}`);
|
|
5233
5374
|
const apiCall = socketSdk.createReportFromFilePaths(packagePaths, cwd, socketConfig?.issueRules);
|
|
5234
5375
|
const result = await handleApiCall(apiCall, 'creating report');
|
|
5235
5376
|
if (!result.success) {
|
|
5236
|
-
handleUnsuccessfulApiResponse('createReport', result, spinner
|
|
5377
|
+
handleUnsuccessfulApiResponse('createReport', result, spinner);
|
|
5237
5378
|
return undefined;
|
|
5238
5379
|
}
|
|
5239
|
-
spinner
|
|
5380
|
+
spinner.successAndStop();
|
|
5240
5381
|
return result;
|
|
5241
5382
|
}
|
|
5242
5383
|
|
|
@@ -5264,8 +5405,11 @@ async function getSocketConfig(absoluteConfigPath) {
|
|
|
5264
5405
|
const MAX_TIMEOUT_RETRY = 5;
|
|
5265
5406
|
const HTTP_CODE_TIMEOUT = 524;
|
|
5266
5407
|
async function fetchReportData(reportId, includeAllIssues, strict) {
|
|
5267
|
-
|
|
5268
|
-
|
|
5408
|
+
// Lazily access constants.spinner.
|
|
5409
|
+
const {
|
|
5410
|
+
spinner
|
|
5411
|
+
} = constants;
|
|
5412
|
+
spinner.start(`Fetching report with ID ${reportId} (this could take a while)`);
|
|
5269
5413
|
const socketSdk = await index.setupSdk();
|
|
5270
5414
|
let result;
|
|
5271
5415
|
for (let retry = 1; !result; ++retry) {
|
|
@@ -5274,43 +5418,43 @@ async function fetchReportData(reportId, includeAllIssues, strict) {
|
|
|
5274
5418
|
result = await handleApiCall(socketSdk.getReport(reportId), 'fetching report');
|
|
5275
5419
|
} catch (err) {
|
|
5276
5420
|
if (retry >= MAX_TIMEOUT_RETRY || !(err instanceof Error) || err.cause?.cause?.response?.statusCode !== HTTP_CODE_TIMEOUT) {
|
|
5277
|
-
spinner
|
|
5421
|
+
spinner.stop();
|
|
5278
5422
|
throw err;
|
|
5279
5423
|
}
|
|
5280
5424
|
}
|
|
5281
5425
|
}
|
|
5282
5426
|
if (!result.success) {
|
|
5283
|
-
return handleUnsuccessfulApiResponse('getReport', result, spinner
|
|
5427
|
+
return handleUnsuccessfulApiResponse('getReport', result, spinner);
|
|
5284
5428
|
}
|
|
5285
5429
|
|
|
5286
5430
|
// Conclude the status of the API call.
|
|
5287
5431
|
if (strict) {
|
|
5288
5432
|
if (result.data.healthy) {
|
|
5289
|
-
spinner
|
|
5433
|
+
spinner.success('Report result is healthy and great!');
|
|
5290
5434
|
} else {
|
|
5291
|
-
spinner
|
|
5435
|
+
spinner.error('Report result deemed unhealthy for project');
|
|
5292
5436
|
}
|
|
5293
5437
|
} else if (!result.data.healthy) {
|
|
5294
5438
|
const severityCount = getSeverityCount(result.data.issues, includeAllIssues ? undefined : 'high');
|
|
5295
5439
|
const issueSummary = formatSeverityCount(severityCount);
|
|
5296
|
-
spinner
|
|
5440
|
+
spinner.success(`Report has these issues: ${issueSummary}`);
|
|
5297
5441
|
} else {
|
|
5298
|
-
spinner
|
|
5442
|
+
spinner.success('Report has no issues');
|
|
5299
5443
|
}
|
|
5300
|
-
spinner
|
|
5444
|
+
spinner.stop();
|
|
5301
5445
|
return result.data;
|
|
5302
5446
|
}
|
|
5303
5447
|
|
|
5304
5448
|
function formatReportDataOutput(reportId, data, commandName, outputJson, outputMarkdown, strict) {
|
|
5305
5449
|
if (outputJson) {
|
|
5306
|
-
|
|
5450
|
+
logger.logger.log(JSON.stringify(data, undefined, 2));
|
|
5307
5451
|
} else {
|
|
5308
5452
|
const format = new index.ColorOrMarkdown(outputMarkdown);
|
|
5309
|
-
|
|
5453
|
+
logger.logger.log('\nDetailed info on socket.dev: ' + format.hyperlink(reportId, data.url, {
|
|
5310
5454
|
fallbackToUrl: true
|
|
5311
5455
|
}));
|
|
5312
5456
|
if (!outputMarkdown) {
|
|
5313
|
-
|
|
5457
|
+
logger.logger.log(colors.dim(`\nOr rerun ${colors.italic(commandName)} using the ${colors.italic('--json')} flag to get full JSON output`));
|
|
5314
5458
|
}
|
|
5315
5459
|
}
|
|
5316
5460
|
if (strict && !data.healthy) {
|
|
@@ -5331,6 +5475,9 @@ async function viewReport(reportId, {
|
|
|
5331
5475
|
}
|
|
5332
5476
|
}
|
|
5333
5477
|
|
|
5478
|
+
const {
|
|
5479
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$d
|
|
5480
|
+
} = constants;
|
|
5334
5481
|
const config$d = {
|
|
5335
5482
|
commandName: 'create',
|
|
5336
5483
|
description: 'Create a project report',
|
|
@@ -5401,7 +5548,8 @@ async function run$d(argv, importMeta, {
|
|
|
5401
5548
|
|
|
5402
5549
|
// Note exiting earlier to skirt a hidden auth requirement
|
|
5403
5550
|
if (cli.flags['dryRun']) {
|
|
5404
|
-
|
|
5551
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$d);
|
|
5552
|
+
return;
|
|
5405
5553
|
}
|
|
5406
5554
|
const socketConfig = await getSocketConfig(absoluteConfigPath);
|
|
5407
5555
|
const result = await createReport(socketConfig, cli.input, {
|
|
@@ -5420,17 +5568,19 @@ async function run$d(argv, importMeta, {
|
|
|
5420
5568
|
strict
|
|
5421
5569
|
});
|
|
5422
5570
|
} else if (json) {
|
|
5423
|
-
|
|
5424
|
-
return;
|
|
5571
|
+
logger.logger.log(JSON.stringify(result.data, undefined, 2));
|
|
5425
5572
|
} else {
|
|
5426
5573
|
const format = new index.ColorOrMarkdown(markdown);
|
|
5427
|
-
|
|
5574
|
+
logger.logger.log(`New report: ${format.hyperlink(result.data.id, result.data.url, {
|
|
5428
5575
|
fallbackToUrl: true
|
|
5429
5576
|
})}`);
|
|
5430
5577
|
}
|
|
5431
5578
|
}
|
|
5432
5579
|
}
|
|
5433
5580
|
|
|
5581
|
+
const {
|
|
5582
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$c
|
|
5583
|
+
} = constants;
|
|
5434
5584
|
const config$c = {
|
|
5435
5585
|
commandName: 'view',
|
|
5436
5586
|
description: 'View a project report',
|
|
@@ -5473,13 +5623,14 @@ async function run$c(argv, importMeta, {
|
|
|
5473
5623
|
// options or missing arguments.
|
|
5474
5624
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
5475
5625
|
process.exitCode = 2;
|
|
5476
|
-
|
|
5626
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
5477
5627
|
- Need at least one report ID ${!reportId ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
5478
5628
|
- Can only handle a single report ID ${extraInput.length < 2 ? colors.red(`(received ${extraInput.length}!)`) : colors.green('(ok)')}\n`);
|
|
5479
5629
|
return;
|
|
5480
5630
|
}
|
|
5481
5631
|
if (cli.flags['dryRun']) {
|
|
5482
|
-
|
|
5632
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$c);
|
|
5633
|
+
return;
|
|
5483
5634
|
}
|
|
5484
5635
|
await viewReport(reportId, {
|
|
5485
5636
|
all: Boolean(cli.flags['all']),
|
|
@@ -5519,8 +5670,11 @@ async function createRepo({
|
|
|
5519
5670
|
repoName,
|
|
5520
5671
|
visibility
|
|
5521
5672
|
}) {
|
|
5522
|
-
|
|
5523
|
-
|
|
5673
|
+
// Lazily access constants.spinner.
|
|
5674
|
+
const {
|
|
5675
|
+
spinner
|
|
5676
|
+
} = constants;
|
|
5677
|
+
spinner.start('Creating repository...');
|
|
5524
5678
|
const socketSdk = await index.setupSdk(apiToken);
|
|
5525
5679
|
const result = await handleApiCall(socketSdk.createOrgRepo(orgSlug, {
|
|
5526
5680
|
outputJson,
|
|
@@ -5533,12 +5687,15 @@ async function createRepo({
|
|
|
5533
5687
|
visibility
|
|
5534
5688
|
}), 'creating repository');
|
|
5535
5689
|
if (result.success) {
|
|
5536
|
-
spinner
|
|
5690
|
+
spinner.successAndStop('Repository created successfully');
|
|
5537
5691
|
} else {
|
|
5538
|
-
handleUnsuccessfulApiResponse('createOrgRepo', result, spinner
|
|
5692
|
+
handleUnsuccessfulApiResponse('createOrgRepo', result, spinner);
|
|
5539
5693
|
}
|
|
5540
5694
|
}
|
|
5541
5695
|
|
|
5696
|
+
const {
|
|
5697
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$b
|
|
5698
|
+
} = constants;
|
|
5542
5699
|
const config$b = {
|
|
5543
5700
|
commandName: 'create',
|
|
5544
5701
|
description: 'Create a repository in an organization',
|
|
@@ -5609,13 +5766,14 @@ async function run$b(argv, importMeta, {
|
|
|
5609
5766
|
// options or missing arguments.
|
|
5610
5767
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
5611
5768
|
process.exitCode = 2;
|
|
5612
|
-
|
|
5769
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
5613
5770
|
- Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
5614
5771
|
- Repository name using --repoName ${!repoName ? colors.red('(missing!)') : typeof repoName !== 'string' ? colors.red('(invalid!)') : colors.green('(ok)')}\n`);
|
|
5615
5772
|
return;
|
|
5616
5773
|
}
|
|
5617
5774
|
if (cli.flags['dryRun']) {
|
|
5618
|
-
|
|
5775
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$b);
|
|
5776
|
+
return;
|
|
5619
5777
|
}
|
|
5620
5778
|
const apiToken = index.getDefaultToken();
|
|
5621
5779
|
if (!apiToken) {
|
|
@@ -5635,17 +5793,23 @@ async function run$b(argv, importMeta, {
|
|
|
5635
5793
|
}
|
|
5636
5794
|
|
|
5637
5795
|
async function deleteRepo(orgSlug, repoName, apiToken) {
|
|
5638
|
-
|
|
5639
|
-
|
|
5796
|
+
// Lazily access constants.spinner.
|
|
5797
|
+
const {
|
|
5798
|
+
spinner
|
|
5799
|
+
} = constants;
|
|
5800
|
+
spinner.start('Deleting repository...');
|
|
5640
5801
|
const socketSdk = await index.setupSdk(apiToken);
|
|
5641
5802
|
const result = await handleApiCall(socketSdk.deleteOrgRepo(orgSlug, repoName), 'deleting repository');
|
|
5642
5803
|
if (result.success) {
|
|
5643
|
-
spinner
|
|
5804
|
+
spinner.successAndStop('Repository deleted successfully');
|
|
5644
5805
|
} else {
|
|
5645
|
-
handleUnsuccessfulApiResponse('deleteOrgRepo', result, spinner
|
|
5806
|
+
handleUnsuccessfulApiResponse('deleteOrgRepo', result, spinner);
|
|
5646
5807
|
}
|
|
5647
5808
|
}
|
|
5648
5809
|
|
|
5810
|
+
const {
|
|
5811
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$a
|
|
5812
|
+
} = constants;
|
|
5649
5813
|
const config$a = {
|
|
5650
5814
|
commandName: 'del',
|
|
5651
5815
|
description: 'Delete a repository in an organization',
|
|
@@ -5684,14 +5848,15 @@ async function run$a(argv, importMeta, {
|
|
|
5684
5848
|
// options or missing arguments.
|
|
5685
5849
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
5686
5850
|
process.exitCode = 2;
|
|
5687
|
-
|
|
5851
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
5688
5852
|
- Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
5689
5853
|
- Repository name as the second argument ${!repoName ? colors.red('(missing!)') : typeof repoName !== 'string' ? colors.red('(invalid!)') : colors.green('(ok)')}\n
|
|
5690
5854
|
- At least one TARGET (e.g. \`.\` or \`./package.json\`\n`);
|
|
5691
5855
|
return;
|
|
5692
5856
|
}
|
|
5693
5857
|
if (cli.flags['dryRun']) {
|
|
5694
|
-
|
|
5858
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$a);
|
|
5859
|
+
return;
|
|
5695
5860
|
}
|
|
5696
5861
|
const apiToken = index.getDefaultToken();
|
|
5697
5862
|
if (!apiToken) {
|
|
@@ -5711,10 +5876,11 @@ async function listRepos({
|
|
|
5711
5876
|
per_page,
|
|
5712
5877
|
sort
|
|
5713
5878
|
}) {
|
|
5714
|
-
|
|
5715
|
-
const
|
|
5716
|
-
|
|
5717
|
-
}
|
|
5879
|
+
// Lazily access constants.spinner.
|
|
5880
|
+
const {
|
|
5881
|
+
spinner
|
|
5882
|
+
} = constants;
|
|
5883
|
+
spinner.start('Listing repositories...');
|
|
5718
5884
|
const socketSdk = await index.setupSdk(apiToken);
|
|
5719
5885
|
const result = await handleApiCall(socketSdk.getOrgRepoList(orgSlug, {
|
|
5720
5886
|
outputJson,
|
|
@@ -5726,10 +5892,10 @@ async function listRepos({
|
|
|
5726
5892
|
page
|
|
5727
5893
|
}), 'listing repositories');
|
|
5728
5894
|
if (!result.success) {
|
|
5729
|
-
handleUnsuccessfulApiResponse('getOrgRepoList', result, spinner
|
|
5895
|
+
handleUnsuccessfulApiResponse('getOrgRepoList', result, spinner);
|
|
5730
5896
|
return;
|
|
5731
5897
|
}
|
|
5732
|
-
spinner
|
|
5898
|
+
spinner.stop();
|
|
5733
5899
|
if (outputJson) {
|
|
5734
5900
|
const data = result.data.results.map(o => ({
|
|
5735
5901
|
id: o.id,
|
|
@@ -5738,7 +5904,7 @@ async function listRepos({
|
|
|
5738
5904
|
defaultBranch: o.default_branch,
|
|
5739
5905
|
archived: o.archived
|
|
5740
5906
|
}));
|
|
5741
|
-
|
|
5907
|
+
logger.logger.log(JSON.stringify(data, null, 2));
|
|
5742
5908
|
return;
|
|
5743
5909
|
}
|
|
5744
5910
|
const options = {
|
|
@@ -5759,9 +5925,12 @@ async function listRepos({
|
|
|
5759
5925
|
name: colors.magenta('Archived')
|
|
5760
5926
|
}]
|
|
5761
5927
|
};
|
|
5762
|
-
|
|
5928
|
+
logger.logger.log(chalkTable(options, result.data.results));
|
|
5763
5929
|
}
|
|
5764
5930
|
|
|
5931
|
+
const {
|
|
5932
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$9
|
|
5933
|
+
} = constants;
|
|
5765
5934
|
const config$9 = {
|
|
5766
5935
|
commandName: 'list',
|
|
5767
5936
|
description: 'List repositories in an organization',
|
|
@@ -5824,13 +5993,14 @@ async function run$9(argv, importMeta, {
|
|
|
5824
5993
|
// options or missing arguments.
|
|
5825
5994
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
5826
5995
|
process.exitCode = 2;
|
|
5827
|
-
|
|
5996
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
5828
5997
|
- Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
5829
5998
|
- At least one TARGET (e.g. \`.\` or \`./package.json\`\n`);
|
|
5830
5999
|
return;
|
|
5831
6000
|
}
|
|
5832
6001
|
if (cli.flags['dryRun']) {
|
|
5833
|
-
|
|
6002
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$9);
|
|
6003
|
+
return;
|
|
5834
6004
|
}
|
|
5835
6005
|
const apiToken = index.getDefaultToken();
|
|
5836
6006
|
if (!apiToken) {
|
|
@@ -5859,10 +6029,11 @@ async function updateRepo({
|
|
|
5859
6029
|
repoName,
|
|
5860
6030
|
visibility
|
|
5861
6031
|
}) {
|
|
5862
|
-
|
|
5863
|
-
const
|
|
5864
|
-
|
|
5865
|
-
}
|
|
6032
|
+
// Lazily access constants.spinner.
|
|
6033
|
+
const {
|
|
6034
|
+
spinner
|
|
6035
|
+
} = constants;
|
|
6036
|
+
spinner.start('Updating repository...');
|
|
5866
6037
|
const socketSdk = await index.setupSdk(apiToken);
|
|
5867
6038
|
const result = await handleApiCall(socketSdk.updateOrgRepo(orgSlug, repoName, {
|
|
5868
6039
|
outputJson,
|
|
@@ -5875,12 +6046,15 @@ async function updateRepo({
|
|
|
5875
6046
|
visibility
|
|
5876
6047
|
}), 'updating repository');
|
|
5877
6048
|
if (result.success) {
|
|
5878
|
-
spinner
|
|
6049
|
+
spinner.successAndStop('Repository updated successfully');
|
|
5879
6050
|
} else {
|
|
5880
|
-
handleUnsuccessfulApiResponse('updateOrgRepo', result, spinner
|
|
6051
|
+
handleUnsuccessfulApiResponse('updateOrgRepo', result, spinner);
|
|
5881
6052
|
}
|
|
5882
6053
|
}
|
|
5883
6054
|
|
|
6055
|
+
const {
|
|
6056
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$8
|
|
6057
|
+
} = constants;
|
|
5884
6058
|
const config$8 = {
|
|
5885
6059
|
commandName: 'update',
|
|
5886
6060
|
description: 'Update a repository in an organization',
|
|
@@ -5951,14 +6125,15 @@ async function run$8(argv, importMeta, {
|
|
|
5951
6125
|
// options or missing arguments.
|
|
5952
6126
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
5953
6127
|
process.exitCode = 2;
|
|
5954
|
-
|
|
6128
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
5955
6129
|
- Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
5956
6130
|
- Repository name using --repoName ${!repoName ? colors.red('(missing!)') : typeof repoName !== 'string' ? colors.red('(invalid!)') : colors.green('(ok)')}\n
|
|
5957
6131
|
- At least one TARGET (e.g. \`.\` or \`./package.json\`\n`);
|
|
5958
6132
|
return;
|
|
5959
6133
|
}
|
|
5960
6134
|
if (cli.flags['dryRun']) {
|
|
5961
|
-
|
|
6135
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$8);
|
|
6136
|
+
return;
|
|
5962
6137
|
}
|
|
5963
6138
|
const apiToken = index.getDefaultToken();
|
|
5964
6139
|
if (!apiToken) {
|
|
@@ -5979,14 +6154,15 @@ async function run$8(argv, importMeta, {
|
|
|
5979
6154
|
|
|
5980
6155
|
// @ts-ignore
|
|
5981
6156
|
async function viewRepo(orgSlug, repoName, apiToken) {
|
|
5982
|
-
|
|
5983
|
-
const
|
|
5984
|
-
|
|
5985
|
-
}
|
|
6157
|
+
// Lazily access constants.spinner.
|
|
6158
|
+
const {
|
|
6159
|
+
spinner
|
|
6160
|
+
} = constants;
|
|
6161
|
+
spinner.start('Fetching repository...');
|
|
5986
6162
|
const socketSdk = await index.setupSdk(apiToken);
|
|
5987
6163
|
const result = await handleApiCall(socketSdk.getOrgRepo(orgSlug, repoName), 'fetching repository');
|
|
5988
6164
|
if (!result.success) {
|
|
5989
|
-
handleUnsuccessfulApiResponse('getOrgRepo', result, spinner
|
|
6165
|
+
handleUnsuccessfulApiResponse('getOrgRepo', result, spinner);
|
|
5990
6166
|
return;
|
|
5991
6167
|
}
|
|
5992
6168
|
const options = {
|
|
@@ -6013,9 +6189,12 @@ async function viewRepo(orgSlug, repoName, apiToken) {
|
|
|
6013
6189
|
name: colors.magenta('Created at')
|
|
6014
6190
|
}]
|
|
6015
6191
|
};
|
|
6016
|
-
spinner
|
|
6192
|
+
spinner.stop(chalkTable(options, [result.data]));
|
|
6017
6193
|
}
|
|
6018
6194
|
|
|
6195
|
+
const {
|
|
6196
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$7
|
|
6197
|
+
} = constants;
|
|
6019
6198
|
const config$7 = {
|
|
6020
6199
|
commandName: 'view',
|
|
6021
6200
|
description: 'View repositories in an organization',
|
|
@@ -6056,13 +6235,14 @@ async function run$7(argv, importMeta, {
|
|
|
6056
6235
|
// options or missing arguments.
|
|
6057
6236
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
6058
6237
|
process.exitCode = 2;
|
|
6059
|
-
|
|
6238
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
6060
6239
|
- Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
6061
6240
|
- Repository name using --repoName ${!repoName ? colors.red('(missing!)') : typeof repoName !== 'string' ? colors.red('(invalid!)') : colors.green('(ok)')}\n`);
|
|
6062
6241
|
return;
|
|
6063
6242
|
}
|
|
6064
6243
|
if (cli.flags['dryRun']) {
|
|
6065
|
-
|
|
6244
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$7);
|
|
6245
|
+
return;
|
|
6066
6246
|
}
|
|
6067
6247
|
const apiToken = index.getDefaultToken();
|
|
6068
6248
|
if (!apiToken) {
|
|
@@ -6189,7 +6369,7 @@ function dirNameToSlug(name) {
|
|
|
6189
6369
|
}
|
|
6190
6370
|
|
|
6191
6371
|
async function suggestBranchSlug(repoDefaultBranch) {
|
|
6192
|
-
const spawnResult =
|
|
6372
|
+
const spawnResult = spawn.spawnSync('git', ['branch', '--show-current']);
|
|
6193
6373
|
const currentBranch = spawnResult.stdout.toString('utf8').trim();
|
|
6194
6374
|
if (currentBranch && spawnResult.status === 0) {
|
|
6195
6375
|
const proceed = await prompts.select({
|
|
@@ -6249,10 +6429,14 @@ async function createFullScan({
|
|
|
6249
6429
|
targets,
|
|
6250
6430
|
tmp
|
|
6251
6431
|
}) {
|
|
6432
|
+
// Lazily access constants.spinner.
|
|
6433
|
+
const {
|
|
6434
|
+
spinner
|
|
6435
|
+
} = constants;
|
|
6252
6436
|
const socketSdk = await index.setupSdk();
|
|
6253
6437
|
const supportedFiles = await socketSdk.getReportSupportedFiles().then(res => {
|
|
6254
6438
|
if (!res.success) {
|
|
6255
|
-
handleUnsuccessfulApiResponse('getReportSupportedFiles', res,
|
|
6439
|
+
handleUnsuccessfulApiResponse('getReportSupportedFiles', res, spinner);
|
|
6256
6440
|
assert(false, 'handleUnsuccessfulApiResponse should unconditionally throw');
|
|
6257
6441
|
}
|
|
6258
6442
|
return res.data;
|
|
@@ -6309,7 +6493,7 @@ async function createFullScan({
|
|
|
6309
6493
|
// options or missing arguments.
|
|
6310
6494
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
6311
6495
|
process$1.exitCode = 2;
|
|
6312
|
-
|
|
6496
|
+
logger.logger.error(`
|
|
6313
6497
|
${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
6314
6498
|
- Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
6315
6499
|
- Repository name using --repo ${!repoName ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
@@ -6320,22 +6504,19 @@ async function createFullScan({
|
|
|
6320
6504
|
return;
|
|
6321
6505
|
}
|
|
6322
6506
|
if (updatedInput) {
|
|
6323
|
-
|
|
6324
|
-
|
|
6325
|
-
|
|
6326
|
-
|
|
6507
|
+
logger.logger.log('Note: You can invoke this command next time to skip the interactive questions:');
|
|
6508
|
+
logger.logger.log('```');
|
|
6509
|
+
logger.logger.log(` socket scan create [other flags...] --repo ${repoName} --branch ${branchName} ${orgSlug} ${targets.join(' ')}`);
|
|
6510
|
+
logger.logger.log('```');
|
|
6327
6511
|
}
|
|
6328
6512
|
if (!apiToken) {
|
|
6329
6513
|
throw new index.AuthError('User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.');
|
|
6330
6514
|
}
|
|
6331
6515
|
if (readOnly) {
|
|
6332
|
-
|
|
6516
|
+
logger.logger.log('[ReadOnly] Bailing now');
|
|
6333
6517
|
return;
|
|
6334
6518
|
}
|
|
6335
|
-
|
|
6336
|
-
const spinner$1 = new spinner.Spinner({
|
|
6337
|
-
text: spinnerText
|
|
6338
|
-
}).start();
|
|
6519
|
+
spinner.start('Creating a scan...');
|
|
6339
6520
|
const result = await handleApiCall(socketSdk.createOrgFullScan(orgSlug, {
|
|
6340
6521
|
repo: repoName,
|
|
6341
6522
|
branch: branchName,
|
|
@@ -6345,12 +6526,12 @@ async function createFullScan({
|
|
|
6345
6526
|
tmp
|
|
6346
6527
|
}, packagePaths, cwd), 'Creating scan');
|
|
6347
6528
|
if (!result.success) {
|
|
6348
|
-
handleUnsuccessfulApiResponse('CreateOrgFullScan', result, spinner
|
|
6529
|
+
handleUnsuccessfulApiResponse('CreateOrgFullScan', result, spinner);
|
|
6349
6530
|
return;
|
|
6350
6531
|
}
|
|
6351
|
-
spinner
|
|
6532
|
+
spinner.successAndStop('Scan created successfully');
|
|
6352
6533
|
const link = colors.underline(colors.cyan(`${result.data.html_report_url}`));
|
|
6353
|
-
|
|
6534
|
+
logger.logger.log(`Available at: ${link}`);
|
|
6354
6535
|
const rl = readline.createInterface({
|
|
6355
6536
|
input: process$1.stdin,
|
|
6356
6537
|
output: process$1.stdout
|
|
@@ -6362,6 +6543,9 @@ async function createFullScan({
|
|
|
6362
6543
|
rl.close();
|
|
6363
6544
|
}
|
|
6364
6545
|
|
|
6546
|
+
const {
|
|
6547
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$6
|
|
6548
|
+
} = constants;
|
|
6365
6549
|
const config$6 = {
|
|
6366
6550
|
commandName: 'create',
|
|
6367
6551
|
description: 'Create a scan',
|
|
@@ -6478,7 +6662,7 @@ async function run$6(argv, importMeta, {
|
|
|
6478
6662
|
// options or missing arguments.
|
|
6479
6663
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
6480
6664
|
process$1.exitCode = 2;
|
|
6481
|
-
|
|
6665
|
+
logger.logger.error(`
|
|
6482
6666
|
${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
6483
6667
|
- Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
6484
6668
|
- Repository name using --repo ${!repoName ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
@@ -6491,7 +6675,8 @@ async function run$6(argv, importMeta, {
|
|
|
6491
6675
|
|
|
6492
6676
|
// Note exiting earlier to skirt a hidden auth requirement
|
|
6493
6677
|
if (cli.flags['dryRun']) {
|
|
6494
|
-
|
|
6678
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$6);
|
|
6679
|
+
return;
|
|
6495
6680
|
}
|
|
6496
6681
|
await createFullScan({
|
|
6497
6682
|
branchName: branchName,
|
|
@@ -6511,17 +6696,23 @@ async function run$6(argv, importMeta, {
|
|
|
6511
6696
|
}
|
|
6512
6697
|
|
|
6513
6698
|
async function deleteOrgFullScan(orgSlug, fullScanId, apiToken) {
|
|
6514
|
-
|
|
6515
|
-
|
|
6699
|
+
// Lazily access constants.spinner.
|
|
6700
|
+
const {
|
|
6701
|
+
spinner
|
|
6702
|
+
} = constants;
|
|
6703
|
+
spinner.start('Deleting scan...');
|
|
6516
6704
|
const socketSdk = await index.setupSdk(apiToken);
|
|
6517
6705
|
const result = await handleApiCall(socketSdk.deleteOrgFullScan(orgSlug, fullScanId), 'Deleting scan');
|
|
6518
6706
|
if (!result.success) {
|
|
6519
|
-
handleUnsuccessfulApiResponse('deleteOrgFullScan', result, spinner
|
|
6707
|
+
handleUnsuccessfulApiResponse('deleteOrgFullScan', result, spinner);
|
|
6520
6708
|
return;
|
|
6521
6709
|
}
|
|
6522
|
-
spinner
|
|
6710
|
+
spinner.successAndStop('Scan deleted successfully');
|
|
6523
6711
|
}
|
|
6524
6712
|
|
|
6713
|
+
const {
|
|
6714
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$5
|
|
6715
|
+
} = constants;
|
|
6525
6716
|
const config$5 = {
|
|
6526
6717
|
commandName: 'del',
|
|
6527
6718
|
description: 'Delete a scan',
|
|
@@ -6561,13 +6752,14 @@ async function run$5(argv, importMeta, {
|
|
|
6561
6752
|
// options or missing arguments.
|
|
6562
6753
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
6563
6754
|
process.exitCode = 2;
|
|
6564
|
-
|
|
6755
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
6565
6756
|
- Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
6566
6757
|
- Full Scan ID to delete as second argument ${!fullScanId ? colors.red('(missing!)') : colors.green('(ok)')}\n`);
|
|
6567
6758
|
return;
|
|
6568
6759
|
}
|
|
6569
6760
|
if (cli.flags['dryRun']) {
|
|
6570
|
-
|
|
6761
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$5);
|
|
6762
|
+
return;
|
|
6571
6763
|
}
|
|
6572
6764
|
const apiToken = index.getDefaultToken();
|
|
6573
6765
|
if (!apiToken) {
|
|
@@ -6578,12 +6770,15 @@ async function run$5(argv, importMeta, {
|
|
|
6578
6770
|
|
|
6579
6771
|
// @ts-ignore
|
|
6580
6772
|
async function listFullScans(orgSlug, input, apiToken) {
|
|
6581
|
-
|
|
6582
|
-
|
|
6773
|
+
// Lazily access constants.spinner.
|
|
6774
|
+
const {
|
|
6775
|
+
spinner
|
|
6776
|
+
} = constants;
|
|
6777
|
+
spinner.start('Listing scans...');
|
|
6583
6778
|
const socketSdk = await index.setupSdk(apiToken);
|
|
6584
6779
|
const result = await handleApiCall(socketSdk.getOrgFullScanList(orgSlug, input), 'Listing scans');
|
|
6585
6780
|
if (!result.success) {
|
|
6586
|
-
handleUnsuccessfulApiResponse('getOrgFullScanList', result, spinner
|
|
6781
|
+
handleUnsuccessfulApiResponse('getOrgFullScanList', result, spinner);
|
|
6587
6782
|
return;
|
|
6588
6783
|
}
|
|
6589
6784
|
const options = {
|
|
@@ -6613,10 +6808,13 @@ async function listFullScans(orgSlug, input, apiToken) {
|
|
|
6613
6808
|
branch: d.branch
|
|
6614
6809
|
};
|
|
6615
6810
|
});
|
|
6616
|
-
spinner
|
|
6617
|
-
|
|
6811
|
+
spinner.stop(`Listing scans for: ${orgSlug}`);
|
|
6812
|
+
logger.logger.log(chalkTable(options, formattedResults));
|
|
6618
6813
|
}
|
|
6619
6814
|
|
|
6815
|
+
const {
|
|
6816
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$4
|
|
6817
|
+
} = constants;
|
|
6620
6818
|
const config$4 = {
|
|
6621
6819
|
commandName: 'list',
|
|
6622
6820
|
description: 'List the full scans for an organization',
|
|
@@ -6692,12 +6890,13 @@ async function run$4(argv, importMeta, {
|
|
|
6692
6890
|
// options or missing arguments.
|
|
6693
6891
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
6694
6892
|
process.exitCode = 2;
|
|
6695
|
-
|
|
6893
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
6696
6894
|
- Org name as the argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n`);
|
|
6697
6895
|
return;
|
|
6698
6896
|
}
|
|
6699
6897
|
if (cli.flags['dryRun']) {
|
|
6700
|
-
|
|
6898
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$4);
|
|
6899
|
+
return;
|
|
6701
6900
|
}
|
|
6702
6901
|
const apiToken = index.getDefaultToken();
|
|
6703
6902
|
if (!apiToken) {
|
|
@@ -6719,18 +6918,24 @@ async function run$4(argv, importMeta, {
|
|
|
6719
6918
|
}
|
|
6720
6919
|
|
|
6721
6920
|
async function getOrgScanMetadata(orgSlug, scanId, apiToken) {
|
|
6722
|
-
|
|
6723
|
-
|
|
6921
|
+
// Lazily access constants.spinner.
|
|
6922
|
+
const {
|
|
6923
|
+
spinner
|
|
6924
|
+
} = constants;
|
|
6925
|
+
spinner.start("Getting scan's metadata...");
|
|
6724
6926
|
const socketSdk = await index.setupSdk(apiToken);
|
|
6725
6927
|
const result = await handleApiCall(socketSdk.getOrgFullScanMetadata(orgSlug, scanId), 'Listing scans');
|
|
6726
6928
|
if (!result.success) {
|
|
6727
|
-
handleUnsuccessfulApiResponse('getOrgFullScanMetadata', result, spinner
|
|
6929
|
+
handleUnsuccessfulApiResponse('getOrgFullScanMetadata', result, spinner);
|
|
6728
6930
|
return;
|
|
6729
6931
|
}
|
|
6730
|
-
spinner
|
|
6731
|
-
|
|
6932
|
+
spinner.stop('Scan metadata:');
|
|
6933
|
+
logger.logger.log(result.data);
|
|
6732
6934
|
}
|
|
6733
6935
|
|
|
6936
|
+
const {
|
|
6937
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$3
|
|
6938
|
+
} = constants;
|
|
6734
6939
|
const config$3 = {
|
|
6735
6940
|
commandName: 'metadata',
|
|
6736
6941
|
description: "Get a full scan's metadata",
|
|
@@ -6770,13 +6975,14 @@ async function run$3(argv, importMeta, {
|
|
|
6770
6975
|
// options or missing arguments.
|
|
6771
6976
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
6772
6977
|
process.exitCode = 2;
|
|
6773
|
-
|
|
6978
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
6774
6979
|
- Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
6775
6980
|
- Full Scan ID to inspect as second argument ${!fullScanId ? colors.red('(missing!)') : colors.green('(ok)')}\n`);
|
|
6776
6981
|
return;
|
|
6777
6982
|
}
|
|
6778
6983
|
if (cli.flags['dryRun']) {
|
|
6779
|
-
|
|
6984
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$3);
|
|
6985
|
+
return;
|
|
6780
6986
|
}
|
|
6781
6987
|
const apiToken = index.getDefaultToken();
|
|
6782
6988
|
if (!apiToken) {
|
|
@@ -6786,18 +6992,24 @@ async function run$3(argv, importMeta, {
|
|
|
6786
6992
|
}
|
|
6787
6993
|
|
|
6788
6994
|
async function getFullScan(orgSlug, fullScanId, file, apiToken) {
|
|
6789
|
-
|
|
6790
|
-
|
|
6995
|
+
// Lazily access constants.spinner.
|
|
6996
|
+
const {
|
|
6997
|
+
spinner
|
|
6998
|
+
} = constants;
|
|
6999
|
+
spinner.start('Streaming scan...');
|
|
6791
7000
|
const socketSdk = await index.setupSdk(apiToken);
|
|
6792
7001
|
const data = await handleApiCall(socketSdk.getOrgFullScan(orgSlug, fullScanId, file === '-' ? undefined : file), 'Streaming a scan');
|
|
6793
7002
|
if (data?.success) {
|
|
6794
|
-
spinner
|
|
7003
|
+
spinner.stop(file ? `Full scan details written to ${file}` : '');
|
|
6795
7004
|
} else {
|
|
6796
|
-
handleUnsuccessfulApiResponse('getOrgFullScan', data, spinner
|
|
7005
|
+
handleUnsuccessfulApiResponse('getOrgFullScan', data, spinner);
|
|
6797
7006
|
}
|
|
6798
7007
|
return data;
|
|
6799
7008
|
}
|
|
6800
7009
|
|
|
7010
|
+
const {
|
|
7011
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$2
|
|
7012
|
+
} = constants;
|
|
6801
7013
|
const config$2 = {
|
|
6802
7014
|
commandName: 'stream',
|
|
6803
7015
|
description: 'Stream the output of a scan',
|
|
@@ -6839,13 +7051,14 @@ async function run$2(argv, importMeta, {
|
|
|
6839
7051
|
// options or missing arguments.
|
|
6840
7052
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
6841
7053
|
process.exitCode = 2;
|
|
6842
|
-
|
|
7054
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
6843
7055
|
- Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
6844
7056
|
- Full Scan ID to fetch as second argument ${!fullScanId ? colors.red('(missing!)') : colors.green('(ok)')}\n`);
|
|
6845
7057
|
return;
|
|
6846
7058
|
}
|
|
6847
7059
|
if (cli.flags['dryRun']) {
|
|
6848
|
-
|
|
7060
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$2);
|
|
7061
|
+
return;
|
|
6849
7062
|
}
|
|
6850
7063
|
const apiToken = index.getDefaultToken();
|
|
6851
7064
|
if (!apiToken) {
|
|
@@ -6883,8 +7096,11 @@ async function getThreatFeed({
|
|
|
6883
7096
|
page,
|
|
6884
7097
|
perPage
|
|
6885
7098
|
}) {
|
|
6886
|
-
|
|
6887
|
-
|
|
7099
|
+
// Lazily access constants.spinner.
|
|
7100
|
+
const {
|
|
7101
|
+
spinner
|
|
7102
|
+
} = constants;
|
|
7103
|
+
spinner.start('Looking up the threat feed');
|
|
6888
7104
|
const formattedQueryParams = formatQueryParams({
|
|
6889
7105
|
per_page: perPage,
|
|
6890
7106
|
page,
|
|
@@ -6893,9 +7109,9 @@ async function getThreatFeed({
|
|
|
6893
7109
|
}).join('&');
|
|
6894
7110
|
const response = await queryAPI(`threat-feed?${formattedQueryParams}`, apiToken);
|
|
6895
7111
|
const data = await response.json();
|
|
6896
|
-
spinner
|
|
7112
|
+
spinner.stop();
|
|
6897
7113
|
if (outputJson) {
|
|
6898
|
-
|
|
7114
|
+
logger.logger.log(data);
|
|
6899
7115
|
return;
|
|
6900
7116
|
}
|
|
6901
7117
|
const screen = new ScreenWidget();
|
|
@@ -6950,6 +7166,9 @@ function getMinDiff(start, end) {
|
|
|
6950
7166
|
return Math.floor((end - start) / 60000);
|
|
6951
7167
|
}
|
|
6952
7168
|
|
|
7169
|
+
const {
|
|
7170
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$1
|
|
7171
|
+
} = constants;
|
|
6953
7172
|
const config$1 = {
|
|
6954
7173
|
commandName: 'threat-feed',
|
|
6955
7174
|
description: 'Look up the threat feed',
|
|
@@ -7009,7 +7228,8 @@ async function run$1(argv, importMeta, {
|
|
|
7009
7228
|
parentName
|
|
7010
7229
|
});
|
|
7011
7230
|
if (cli.flags['dryRun']) {
|
|
7012
|
-
|
|
7231
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$1);
|
|
7232
|
+
return;
|
|
7013
7233
|
}
|
|
7014
7234
|
const apiToken = index.getDefaultToken();
|
|
7015
7235
|
if (!apiToken) {
|
|
@@ -7032,7 +7252,7 @@ function addSocketWrapper(file) {
|
|
|
7032
7252
|
}
|
|
7033
7253
|
// TODO: pretty sure you need to source the file or restart
|
|
7034
7254
|
// any terminal session before changes are reflected.
|
|
7035
|
-
|
|
7255
|
+
logger.logger.log(`
|
|
7036
7256
|
The alias was added to ${file}. Running 'npm install' will now be wrapped in Socket's "safe npm" 🎉
|
|
7037
7257
|
If you want to disable it at any time, run \`socket wrapper --disable\`
|
|
7038
7258
|
`);
|
|
@@ -7043,7 +7263,7 @@ function checkSocketWrapperSetup(file) {
|
|
|
7043
7263
|
const fileContent = fs.readFileSync(file, 'utf8');
|
|
7044
7264
|
const linesWithSocketAlias = fileContent.split('\n').filter(l => l === 'alias npm="socket npm"' || l === 'alias npx="socket npx"');
|
|
7045
7265
|
if (linesWithSocketAlias.length) {
|
|
7046
|
-
|
|
7266
|
+
logger.logger.log(`The Socket npm/npx wrapper is set up in your bash profile (${file}).`);
|
|
7047
7267
|
return true;
|
|
7048
7268
|
}
|
|
7049
7269
|
return false;
|
|
@@ -7065,7 +7285,7 @@ function postinstallWrapper() {
|
|
|
7065
7285
|
}
|
|
7066
7286
|
}
|
|
7067
7287
|
function installSafeNpm(query) {
|
|
7068
|
-
|
|
7288
|
+
logger.logger.log(`
|
|
7069
7289
|
_____ _ _
|
|
7070
7290
|
| __|___ ___| |_ ___| |_
|
|
7071
7291
|
|__ | . | _| '_| -_| _|
|
|
@@ -7108,24 +7328,27 @@ function askQuestion(rl, query) {
|
|
|
7108
7328
|
function removeSocketWrapper(file) {
|
|
7109
7329
|
return fs.readFile(file, 'utf8', function (err, data) {
|
|
7110
7330
|
if (err) {
|
|
7111
|
-
|
|
7331
|
+
logger.logger.error('There was an error removing the alias:');
|
|
7332
|
+
logger.logger.error(err);
|
|
7112
7333
|
return;
|
|
7113
7334
|
}
|
|
7114
7335
|
const linesWithoutSocketAlias = data.split('\n').filter(l => l !== 'alias npm="socket npm"' && l !== 'alias npx="socket npx"');
|
|
7115
7336
|
const updatedFileContent = linesWithoutSocketAlias.join('\n');
|
|
7116
7337
|
fs.writeFile(file, updatedFileContent, function (err) {
|
|
7117
7338
|
if (err) {
|
|
7118
|
-
|
|
7339
|
+
logger.logger.error(err);
|
|
7119
7340
|
return;
|
|
7120
|
-
} else {
|
|
7121
|
-
// TODO: pretty sure you need to source the file or restart
|
|
7122
|
-
// any terminal session before changes are reflected.
|
|
7123
|
-
console.log(`\nThe alias was removed from ${file}. Running 'npm install' will now run the standard npm command.\n`);
|
|
7124
7341
|
}
|
|
7342
|
+
// TODO: pretty sure you need to source the file or restart
|
|
7343
|
+
// any terminal session before changes are reflected.
|
|
7344
|
+
logger.logger.log(`The alias was removed from ${file}. Running 'npm install' will now run the standard npm command.`);
|
|
7125
7345
|
});
|
|
7126
7346
|
});
|
|
7127
7347
|
}
|
|
7128
7348
|
|
|
7349
|
+
const {
|
|
7350
|
+
DRY_RUN_BAIL_TEXT
|
|
7351
|
+
} = constants;
|
|
7129
7352
|
const config = {
|
|
7130
7353
|
commandName: 'wrapper',
|
|
7131
7354
|
description: 'Enable or disable the Socket npm/npx wrapper',
|
|
@@ -7182,12 +7405,13 @@ async function run(argv, importMeta, {
|
|
|
7182
7405
|
// options or missing arguments.
|
|
7183
7406
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
7184
7407
|
process.exitCode = 2;
|
|
7185
|
-
|
|
7408
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required flags:\n
|
|
7186
7409
|
- Must use --enabled or --disabled\n`);
|
|
7187
7410
|
return;
|
|
7188
7411
|
}
|
|
7189
7412
|
if (cli.flags['dryRun']) {
|
|
7190
|
-
|
|
7413
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT);
|
|
7414
|
+
return;
|
|
7191
7415
|
}
|
|
7192
7416
|
|
|
7193
7417
|
// Lazily access constants.bashRcPath and constants.zshRcPath.
|
|
@@ -7211,7 +7435,7 @@ async function run(argv, importMeta, {
|
|
|
7211
7435
|
}
|
|
7212
7436
|
}
|
|
7213
7437
|
if (!fs.existsSync(bashRcPath) && !fs.existsSync(zshRcPath)) {
|
|
7214
|
-
|
|
7438
|
+
logger.logger.error('There was an issue setting up the alias in your bash profile');
|
|
7215
7439
|
}
|
|
7216
7440
|
}
|
|
7217
7441
|
|
|
@@ -7286,10 +7510,10 @@ void (async () => {
|
|
|
7286
7510
|
}
|
|
7287
7511
|
logger.logger.error(`${colors.bgRed(colors.white(errorTitle + ':'))} ${errorMessage}`);
|
|
7288
7512
|
if (errorBody) {
|
|
7289
|
-
|
|
7513
|
+
logger.logger.error(`\n${errorBody}`);
|
|
7290
7514
|
}
|
|
7291
7515
|
await index.captureException(e);
|
|
7292
7516
|
}
|
|
7293
7517
|
})();
|
|
7294
|
-
//# debugId=
|
|
7518
|
+
//# debugId=f23df080-286e-4174-a361-db1fa42ece1
|
|
7295
7519
|
//# sourceMappingURL=cli.js.map
|