@socketsecurity/cli-with-sentry 0.14.51 → 0.14.52
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/constants.d.ts +27 -2
- 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 +592 -396
- package/dist/module-sync/cli.js.map +1 -1
- 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/npm.js +4 -3
- package/dist/module-sync/npm.js.map +1 -1
- package/dist/module-sync/path-resolve.d.ts +1 -2
- package/dist/require/cli.js +592 -396
- package/dist/require/cli.js.map +1 -1
- package/package.json +5 -4
- package/dist/module-sync/debug.d.ts +0 -3
package/dist/module-sync/cli.js
CHANGED
|
@@ -25,14 +25,13 @@ var path = require('node:path');
|
|
|
25
25
|
var ndjson = _socketInterop(require('ndjson'));
|
|
26
26
|
var rest = _socketInterop(require('@octokit/rest'));
|
|
27
27
|
var index = require('./index.js');
|
|
28
|
+
var constants = require('./constants.js');
|
|
28
29
|
var meow = _socketInterop(require('meow'));
|
|
29
30
|
var objects = require('@socketsecurity/registry/lib/objects');
|
|
30
31
|
var regexps = require('@socketsecurity/registry/lib/regexps');
|
|
31
|
-
var constants = require('./constants.js');
|
|
32
32
|
var fs$1 = require('node:fs/promises');
|
|
33
33
|
var ScreenWidget = _socketInterop(require('blessed/lib/widgets/screen'));
|
|
34
34
|
var contrib = _socketInterop(require('blessed-contrib'));
|
|
35
|
-
var spinner = require('@socketsecurity/registry/lib/spinner');
|
|
36
35
|
var prompts = require('@socketsecurity/registry/lib/prompts');
|
|
37
36
|
var yargsParse = _socketInterop(require('yargs-parser'));
|
|
38
37
|
var words = require('@socketsecurity/registry/lib/words');
|
|
@@ -55,8 +54,9 @@ var index_cjs = require('@socketregistry/hyrious__bun.lockb/index.cjs');
|
|
|
55
54
|
var sorts = require('@socketsecurity/registry/lib/sorts');
|
|
56
55
|
var strings = require('@socketsecurity/registry/lib/strings');
|
|
57
56
|
var yaml = _socketInterop(require('yaml'));
|
|
58
|
-
var
|
|
57
|
+
var debug = require('@socketsecurity/registry/lib/debug');
|
|
59
58
|
var npm$1 = require('./npm.js');
|
|
59
|
+
var npmPaths = require('./npm-paths.js');
|
|
60
60
|
var betterAjvErrors = _socketInterop(require('@apideck/better-ajv-errors'));
|
|
61
61
|
var config$A = require('@socketsecurity/config');
|
|
62
62
|
var assert = require('node:assert');
|
|
@@ -267,7 +267,6 @@ class Score {
|
|
|
267
267
|
}
|
|
268
268
|
|
|
269
269
|
// https://github.com/SocketDev/socket-python-cli/blob/6d4fc56faee68d3a4764f1f80f84710635bdaf05/socketsecurity/core/__init__.py
|
|
270
|
-
/* eslint-disable no-await-in-loop */
|
|
271
270
|
class Core {
|
|
272
271
|
securityPolicy = {};
|
|
273
272
|
constructor({
|
|
@@ -562,6 +561,7 @@ class Core {
|
|
|
562
561
|
diff.newPackages.push(purl);
|
|
563
562
|
consolidated.add(basePurl);
|
|
564
563
|
}
|
|
564
|
+
// eslint-disable-next-line no-await-in-loop
|
|
565
565
|
newScanAlerts = await this.createIssueAlerts({
|
|
566
566
|
pkg,
|
|
567
567
|
alerts: newScanAlerts,
|
|
@@ -579,6 +579,7 @@ class Core {
|
|
|
579
579
|
if (!(packageId in newPackages) && pkg.direct) {
|
|
580
580
|
diff.removedPackages.push(purl);
|
|
581
581
|
}
|
|
582
|
+
// eslint-disable-next-line no-await-in-loop
|
|
582
583
|
headScanAlerts = await this.createIssueAlerts({
|
|
583
584
|
pkg,
|
|
584
585
|
alerts: headScanAlerts,
|
|
@@ -644,7 +645,7 @@ class Core {
|
|
|
644
645
|
license: sbomArtifact.license
|
|
645
646
|
});
|
|
646
647
|
if (pkg.id in packages) {
|
|
647
|
-
|
|
648
|
+
logger.logger.log('Duplicate package?');
|
|
648
649
|
} else {
|
|
649
650
|
pkg = this.getLicenseDetails({
|
|
650
651
|
package: pkg
|
|
@@ -684,8 +685,8 @@ class Core {
|
|
|
684
685
|
});
|
|
685
686
|
}
|
|
686
687
|
}
|
|
687
|
-
} catch (
|
|
688
|
-
|
|
688
|
+
} catch (e) {
|
|
689
|
+
logger.logger.error(e);
|
|
689
690
|
}
|
|
690
691
|
const newFullScan = await this.createFullScan({
|
|
691
692
|
params
|
|
@@ -709,7 +710,6 @@ class Core {
|
|
|
709
710
|
}
|
|
710
711
|
|
|
711
712
|
// https://github.com/SocketDev/socket-python-cli/blob/6d4fc56faee68d3a4764f1f80f84710635bdaf05/socketsecurity/core/scm_comments.py
|
|
712
|
-
|
|
713
713
|
function checkForSocketComments({
|
|
714
714
|
comments
|
|
715
715
|
}) {
|
|
@@ -839,9 +839,9 @@ function getIgnoreOptions({
|
|
|
839
839
|
const data = `${name}/${version}`;
|
|
840
840
|
ignoreCommands.push(data);
|
|
841
841
|
}
|
|
842
|
-
} catch (
|
|
843
|
-
|
|
844
|
-
|
|
842
|
+
} catch (e) {
|
|
843
|
+
logger.logger.error(`Unable to process ignore command for ${comment}`);
|
|
844
|
+
logger.logger.error(e);
|
|
845
845
|
}
|
|
846
846
|
}
|
|
847
847
|
}
|
|
@@ -872,9 +872,9 @@ function removeAlerts({
|
|
|
872
872
|
const purl = `${fullName}/${alert.pkg_version}`;
|
|
873
873
|
const purlStar = `${fullName}/*`;
|
|
874
874
|
if (ignoreCommands.includes(purl) || ignoreCommands.includes(purlStar)) {
|
|
875
|
-
|
|
875
|
+
logger.logger.log(`Alerts for ${alert.pkg_name}@${alert.pkg_version} ignored`);
|
|
876
876
|
} else {
|
|
877
|
-
|
|
877
|
+
logger.logger.log(`Adding alert ${alert.type} for ${alert.pkg_name}@${alert.pkg_version}`);
|
|
878
878
|
alerts.push(alert);
|
|
879
879
|
}
|
|
880
880
|
}
|
|
@@ -912,7 +912,7 @@ class GitHub {
|
|
|
912
912
|
if (['opened', 'synchronize'].includes(eventAction)) {
|
|
913
913
|
return 'diff';
|
|
914
914
|
} else {
|
|
915
|
-
|
|
915
|
+
logger.logger.log(`Pull request action: ${eventAction} is not supported`);
|
|
916
916
|
process.exit();
|
|
917
917
|
}
|
|
918
918
|
case 'issue_comment':
|
|
@@ -1027,30 +1027,30 @@ class GitHub {
|
|
|
1027
1027
|
security: existingSecurityComment
|
|
1028
1028
|
} = comments;
|
|
1029
1029
|
if (newOverviewComment) {
|
|
1030
|
-
|
|
1030
|
+
logger.logger.log('New Dependency Overview comment');
|
|
1031
1031
|
if (existingOverviewComment !== undefined) {
|
|
1032
|
-
|
|
1032
|
+
logger.logger.log('Previous version of Dependency Overview, updating');
|
|
1033
1033
|
await this.updateComment({
|
|
1034
1034
|
body: overviewComment,
|
|
1035
1035
|
id: existingOverviewComment.id
|
|
1036
1036
|
});
|
|
1037
1037
|
} else {
|
|
1038
|
-
|
|
1038
|
+
logger.logger.log('No previous version of Dependency Overview, posting');
|
|
1039
1039
|
await this.postComment({
|
|
1040
1040
|
body: overviewComment
|
|
1041
1041
|
});
|
|
1042
1042
|
}
|
|
1043
1043
|
}
|
|
1044
1044
|
if (newSecurityComment) {
|
|
1045
|
-
|
|
1045
|
+
logger.logger.log('New Security Issue Comment');
|
|
1046
1046
|
if (existingSecurityComment !== undefined) {
|
|
1047
|
-
|
|
1047
|
+
logger.logger.log('Previous version of Security Issue comment, updating');
|
|
1048
1048
|
await this.updateComment({
|
|
1049
1049
|
body: securityComment,
|
|
1050
1050
|
id: existingSecurityComment.id
|
|
1051
1051
|
});
|
|
1052
1052
|
} else {
|
|
1053
|
-
|
|
1053
|
+
logger.logger.log('No Previous version of Security Issue comment, posting');
|
|
1054
1054
|
await this.postComment({
|
|
1055
1055
|
body: securityComment
|
|
1056
1056
|
});
|
|
@@ -1229,7 +1229,7 @@ async function runAction(githubEventBefore, githubEventAfter) {
|
|
|
1229
1229
|
const socket = new sdk.SocketSdk(index.getDefaultToken());
|
|
1230
1230
|
const git = simpleGit.simpleGit();
|
|
1231
1231
|
const changedFiles = (await git.diff(process.env['GITHUB_EVENT_NAME'] === 'pull_request' ? ['--name-only', 'HEAD^1', 'HEAD'] : ['--name-only', githubEventBefore, githubEventAfter])).split('\n');
|
|
1232
|
-
|
|
1232
|
+
logger.logger.log({
|
|
1233
1233
|
changedFiles
|
|
1234
1234
|
});
|
|
1235
1235
|
// supportedFiles have 3-level deep globs
|
|
@@ -1237,13 +1237,13 @@ async function runAction(githubEventBefore, githubEventAfter) {
|
|
|
1237
1237
|
const files = micromatch(changedFiles, patterns);
|
|
1238
1238
|
const scm = new GitHub();
|
|
1239
1239
|
if (scm.checkEventType() === 'comment') {
|
|
1240
|
-
|
|
1240
|
+
logger.logger.log('Comment initiated flow');
|
|
1241
1241
|
const comments = await scm.getCommentsForPR();
|
|
1242
1242
|
await scm.removeCommentAlerts({
|
|
1243
1243
|
comments
|
|
1244
1244
|
});
|
|
1245
1245
|
} else if (scm.checkEventType() === 'diff') {
|
|
1246
|
-
|
|
1246
|
+
logger.logger.log('Push initiated flow');
|
|
1247
1247
|
const core = new Core({
|
|
1248
1248
|
owner: scm.owner,
|
|
1249
1249
|
repo: scm.repo,
|
|
@@ -1265,17 +1265,17 @@ async function runAction(githubEventBefore, githubEventAfter) {
|
|
|
1265
1265
|
if (diff.newAlerts.length === 0) {
|
|
1266
1266
|
if (!updateOldSecurityComment) {
|
|
1267
1267
|
newSecurityComment = false;
|
|
1268
|
-
|
|
1268
|
+
logger.logger.log('No new alerts or security issue comment disabled');
|
|
1269
1269
|
} else {
|
|
1270
|
-
|
|
1270
|
+
logger.logger.log('Updated security comment with no new alerts');
|
|
1271
1271
|
}
|
|
1272
1272
|
}
|
|
1273
1273
|
if (diff.newPackages.length === 0 && diff.removedPackages.length === 0) {
|
|
1274
1274
|
if (!updateOldOverviewComment) {
|
|
1275
1275
|
newOverviewComment = false;
|
|
1276
|
-
|
|
1276
|
+
logger.logger.log('No new/removed packages or Dependency Overview comment disabled');
|
|
1277
1277
|
} else {
|
|
1278
|
-
|
|
1278
|
+
logger.logger.log('Updated overview comment with no dependencies');
|
|
1279
1279
|
}
|
|
1280
1280
|
}
|
|
1281
1281
|
await scm.addSocketComments({
|
|
@@ -1403,6 +1403,8 @@ const validationFlags = {
|
|
|
1403
1403
|
};
|
|
1404
1404
|
|
|
1405
1405
|
const {
|
|
1406
|
+
DRY_RUN_LABEL: DRY_RUN_LABEL$1,
|
|
1407
|
+
REDACTED,
|
|
1406
1408
|
SOCKET_CLI_SHOW_BANNER
|
|
1407
1409
|
} = constants;
|
|
1408
1410
|
async function meowWithSubcommands(subcommands, options) {
|
|
@@ -1440,7 +1442,7 @@ async function meowWithSubcommands(subcommands, options) {
|
|
|
1440
1442
|
// Temp disable until we clear the --json and --markdown usage
|
|
1441
1443
|
// Lazily access constants.ENV[SOCKET_CLI_SHOW_BANNER].
|
|
1442
1444
|
if (constants.ENV[SOCKET_CLI_SHOW_BANNER]) {
|
|
1443
|
-
|
|
1445
|
+
logger.logger.log(getAsciiHeader(name));
|
|
1444
1446
|
}
|
|
1445
1447
|
const cli = meow(`
|
|
1446
1448
|
Usage
|
|
@@ -1476,7 +1478,7 @@ async function meowWithSubcommands(subcommands, options) {
|
|
|
1476
1478
|
autoHelp: false // otherwise we can't exit(0)
|
|
1477
1479
|
});
|
|
1478
1480
|
if (!cli.flags['help'] && cli.flags['dryRun']) {
|
|
1479
|
-
|
|
1481
|
+
logger.logger.log(`${DRY_RUN_LABEL$1}: No-op, call a sub-command; ok`);
|
|
1480
1482
|
process.exitCode = 0;
|
|
1481
1483
|
} else {
|
|
1482
1484
|
cli.showHelp();
|
|
@@ -1498,7 +1500,7 @@ function meowOrExit({
|
|
|
1498
1500
|
// Temp disable until we clear the --json and --markdown usage.
|
|
1499
1501
|
// Lazily access constants.ENV[SOCKET_CLI_SHOW_BANNER].
|
|
1500
1502
|
if (constants.ENV[SOCKET_CLI_SHOW_BANNER]) {
|
|
1501
|
-
|
|
1503
|
+
logger.logger.log(getAsciiHeader(command));
|
|
1502
1504
|
}
|
|
1503
1505
|
|
|
1504
1506
|
// This exits if .printHelp() is called either by meow itself or by us.
|
|
@@ -1518,7 +1520,7 @@ function meowOrExit({
|
|
|
1518
1520
|
}
|
|
1519
1521
|
function getAsciiHeader(command) {
|
|
1520
1522
|
const cliVersion = // The '@rollup/plugin-replace' will replace "process.env['SOCKET_CLI_VERSION_HASH']".
|
|
1521
|
-
"0.14.
|
|
1523
|
+
"0.14.52:709a145:a30d9dfd:pub";
|
|
1522
1524
|
const nodeVersion = process.version;
|
|
1523
1525
|
const apiToken = index.getSetting('apiToken');
|
|
1524
1526
|
const shownToken = apiToken ? getLastFiveOfApiToken(apiToken) : 'no';
|
|
@@ -1533,6 +1535,9 @@ function getAsciiHeader(command) {
|
|
|
1533
1535
|
|
|
1534
1536
|
// https://github.com/SocketDev/socket-python-cli/blob/6d4fc56faee68d3a4764f1f80f84710635bdaf05/socketsecurity/socketcli.py
|
|
1535
1537
|
|
|
1538
|
+
const {
|
|
1539
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$y
|
|
1540
|
+
} = constants;
|
|
1536
1541
|
const config$z = {
|
|
1537
1542
|
commandName: 'action',
|
|
1538
1543
|
description: 'Socket action command',
|
|
@@ -1583,7 +1588,8 @@ async function run$z(argv, importMeta, {
|
|
|
1583
1588
|
const githubEventBefore = String(cli.flags['githubEventBefore'] || '');
|
|
1584
1589
|
const githubEventAfter = String(cli.flags['githubEventAfter'] || '');
|
|
1585
1590
|
if (cli.flags['dryRun']) {
|
|
1586
|
-
|
|
1591
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$y);
|
|
1592
|
+
return;
|
|
1587
1593
|
}
|
|
1588
1594
|
await runAction(githubEventBefore, githubEventAfter);
|
|
1589
1595
|
}
|
|
@@ -1601,24 +1607,26 @@ async function displayAnalytics({
|
|
|
1601
1607
|
scope,
|
|
1602
1608
|
time
|
|
1603
1609
|
}) {
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1610
|
+
// Lazily access constants.spinner.
|
|
1611
|
+
const {
|
|
1612
|
+
spinner
|
|
1613
|
+
} = constants;
|
|
1614
|
+
spinner.start('Fetching analytics data');
|
|
1607
1615
|
let data;
|
|
1608
1616
|
if (scope === 'org') {
|
|
1609
|
-
data = await fetchOrgAnalyticsData(time, spinner
|
|
1617
|
+
data = await fetchOrgAnalyticsData(time, spinner, apiToken);
|
|
1610
1618
|
} else if (repo) {
|
|
1611
|
-
data = await fetchRepoAnalyticsData(repo, time, spinner
|
|
1619
|
+
data = await fetchRepoAnalyticsData(repo, time, spinner, apiToken);
|
|
1612
1620
|
}
|
|
1613
1621
|
if (data) {
|
|
1614
1622
|
if (outputJson && !filePath) {
|
|
1615
|
-
|
|
1623
|
+
logger.logger.log(data);
|
|
1616
1624
|
} else if (filePath) {
|
|
1617
1625
|
try {
|
|
1618
1626
|
await fs$1.writeFile(filePath, JSON.stringify(data), 'utf8');
|
|
1619
|
-
|
|
1627
|
+
logger.logger.log(`Data successfully written to ${filePath}`);
|
|
1620
1628
|
} catch (e) {
|
|
1621
|
-
|
|
1629
|
+
logger.logger.error(e);
|
|
1622
1630
|
}
|
|
1623
1631
|
} else {
|
|
1624
1632
|
const fdata = scope === 'org' ? formatData(data, 'org') : formatData(data, 'repo');
|
|
@@ -1667,7 +1675,7 @@ async function fetchOrgAnalyticsData(time, spinner, apiToken) {
|
|
|
1667
1675
|
}
|
|
1668
1676
|
spinner.stop();
|
|
1669
1677
|
if (!result.data.length) {
|
|
1670
|
-
|
|
1678
|
+
logger.logger.log('No analytics data is available for this organization yet.');
|
|
1671
1679
|
return undefined;
|
|
1672
1680
|
}
|
|
1673
1681
|
return result.data;
|
|
@@ -1681,7 +1689,7 @@ async function fetchRepoAnalyticsData(repo, time, spinner, apiToken) {
|
|
|
1681
1689
|
}
|
|
1682
1690
|
spinner.stop();
|
|
1683
1691
|
if (!result.data.length) {
|
|
1684
|
-
|
|
1692
|
+
logger.logger.log('No analytics data is available for this organization yet.');
|
|
1685
1693
|
return undefined;
|
|
1686
1694
|
}
|
|
1687
1695
|
return result.data;
|
|
@@ -1777,6 +1785,9 @@ function renderLineCharts(grid, screen, title, coords, data) {
|
|
|
1777
1785
|
line.setData([lineData]);
|
|
1778
1786
|
}
|
|
1779
1787
|
|
|
1788
|
+
const {
|
|
1789
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$x
|
|
1790
|
+
} = constants;
|
|
1780
1791
|
const config$y = {
|
|
1781
1792
|
commandName: 'analytics',
|
|
1782
1793
|
description: `Look up analytics data`,
|
|
@@ -1854,14 +1865,15 @@ async function run$y(argv, importMeta, {
|
|
|
1854
1865
|
// options or missing arguments.
|
|
1855
1866
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
1856
1867
|
process.exitCode = 2;
|
|
1857
|
-
|
|
1868
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
1858
1869
|
- Scope must be "repo" or "org" ${badScope ? colors.red('(bad!)') : colors.green('(ok)')}\n
|
|
1859
1870
|
- The time filter must either be 7, 30 or 90 ${badTime ? colors.red('(bad!)') : colors.green('(ok)')}\n
|
|
1860
1871
|
- Repository name using --repo when scope is "repo" ${badRepo ? colors.red('(bad!)') : colors.green('(ok)')}\n`);
|
|
1861
1872
|
return;
|
|
1862
1873
|
}
|
|
1863
1874
|
if (cli.flags['dryRun']) {
|
|
1864
|
-
|
|
1875
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$x);
|
|
1876
|
+
return;
|
|
1865
1877
|
}
|
|
1866
1878
|
const apiToken = index.getDefaultToken();
|
|
1867
1879
|
if (!apiToken) {
|
|
@@ -1886,9 +1898,11 @@ async function getAuditLog({
|
|
|
1886
1898
|
perPage,
|
|
1887
1899
|
type
|
|
1888
1900
|
}) {
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1901
|
+
// Lazily access constants.spinner.
|
|
1902
|
+
const {
|
|
1903
|
+
spinner
|
|
1904
|
+
} = constants;
|
|
1905
|
+
spinner.start(`Looking up audit log for ${orgSlug}`);
|
|
1892
1906
|
const socketSdk = await index.setupSdk(apiToken);
|
|
1893
1907
|
const result = await handleApiCall(socketSdk.getAuditLogEvents(orgSlug, {
|
|
1894
1908
|
outputJson,
|
|
@@ -1899,10 +1913,10 @@ async function getAuditLog({
|
|
|
1899
1913
|
per_page: perPage
|
|
1900
1914
|
}), `Looking up audit log for ${orgSlug}\n`);
|
|
1901
1915
|
if (!result.success) {
|
|
1902
|
-
handleUnsuccessfulApiResponse('getAuditLogEvents', result, spinner
|
|
1916
|
+
handleUnsuccessfulApiResponse('getAuditLogEvents', result, spinner);
|
|
1903
1917
|
return;
|
|
1904
1918
|
}
|
|
1905
|
-
spinner
|
|
1919
|
+
spinner.stop();
|
|
1906
1920
|
const data = [];
|
|
1907
1921
|
const logDetails = {};
|
|
1908
1922
|
for (const d of result.data.results) {
|
|
@@ -1921,13 +1935,16 @@ async function getAuditLog({
|
|
|
1921
1935
|
logDetails[name] = JSON.stringify(d.payload);
|
|
1922
1936
|
}
|
|
1923
1937
|
}
|
|
1924
|
-
|
|
1938
|
+
logger.logger.log(logDetails[await prompts.select({
|
|
1925
1939
|
message: type ? `\n Audit log for: ${orgSlug} with type: ${type}\n` : `\n Audit log for: ${orgSlug}\n`,
|
|
1926
1940
|
choices: data,
|
|
1927
1941
|
pageSize: 30
|
|
1928
1942
|
})]);
|
|
1929
1943
|
}
|
|
1930
1944
|
|
|
1945
|
+
const {
|
|
1946
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$w
|
|
1947
|
+
} = constants;
|
|
1931
1948
|
const config$x = {
|
|
1932
1949
|
commandName: 'audit-log',
|
|
1933
1950
|
description: 'Look up the audit log for an organization',
|
|
@@ -1986,12 +2003,13 @@ async function run$x(argv, importMeta, {
|
|
|
1986
2003
|
// options or missing arguments.
|
|
1987
2004
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
1988
2005
|
process.exitCode = 2;
|
|
1989
|
-
|
|
2006
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
1990
2007
|
- Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n`);
|
|
1991
2008
|
return;
|
|
1992
2009
|
}
|
|
1993
2010
|
if (cli.flags['dryRun']) {
|
|
1994
|
-
|
|
2011
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$w);
|
|
2012
|
+
return;
|
|
1995
2013
|
}
|
|
1996
2014
|
const apiToken = index.getDefaultToken();
|
|
1997
2015
|
if (!apiToken) {
|
|
@@ -2053,7 +2071,7 @@ async function runCycloneDX(yargv) {
|
|
|
2053
2071
|
}
|
|
2054
2072
|
const fullOutputPath = path.join(process$1.cwd(), yargv.output);
|
|
2055
2073
|
if (fs.existsSync(fullOutputPath)) {
|
|
2056
|
-
|
|
2074
|
+
logger.logger.log(colors.cyanBright(`${yargv.output} created!`));
|
|
2057
2075
|
}
|
|
2058
2076
|
}
|
|
2059
2077
|
function argvToArray(argv) {
|
|
@@ -2083,6 +2101,10 @@ function argvToArray(argv) {
|
|
|
2083
2101
|
}
|
|
2084
2102
|
|
|
2085
2103
|
// import { meowOrExit } from '../../utils/meow-with-subcommands'
|
|
2104
|
+
const {
|
|
2105
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$v
|
|
2106
|
+
} = constants;
|
|
2107
|
+
|
|
2086
2108
|
// TODO: convert yargs to meow. Or convert all the other things to yargs.
|
|
2087
2109
|
const toLower = arg => arg.toLowerCase();
|
|
2088
2110
|
const arrayToLower = arg => arg.map(toLower);
|
|
@@ -2187,7 +2209,7 @@ async function run$w(argv, importMeta, {
|
|
|
2187
2209
|
//
|
|
2188
2210
|
//
|
|
2189
2211
|
// if (cli.input.length)
|
|
2190
|
-
//
|
|
2212
|
+
// logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
2191
2213
|
// - Unexpected arguments\n
|
|
2192
2214
|
// `)
|
|
2193
2215
|
// config.help(parentName, config)
|
|
@@ -2208,14 +2230,15 @@ async function run$w(argv, importMeta, {
|
|
|
2208
2230
|
// options or missing arguments.
|
|
2209
2231
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
2210
2232
|
process$1.exitCode = 2;
|
|
2211
|
-
|
|
2233
|
+
logger.logger.error(`Unknown ${words.pluralize('argument', unknownLength)}: ${yargv._.join(', ')}`);
|
|
2212
2234
|
return;
|
|
2213
2235
|
}
|
|
2214
2236
|
if (yargv.output === undefined) {
|
|
2215
2237
|
yargv.output = 'socket-cdx.json';
|
|
2216
2238
|
}
|
|
2217
2239
|
if (cli.flags['dryRun']) {
|
|
2218
|
-
|
|
2240
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$v);
|
|
2241
|
+
return;
|
|
2219
2242
|
}
|
|
2220
2243
|
await runCycloneDX(yargv);
|
|
2221
2244
|
}
|
|
@@ -2230,21 +2253,23 @@ async function findDependencies({
|
|
|
2230
2253
|
if (!apiToken) {
|
|
2231
2254
|
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.');
|
|
2232
2255
|
}
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2256
|
+
// Lazily access constants.spinner.
|
|
2257
|
+
const {
|
|
2258
|
+
spinner
|
|
2259
|
+
} = constants;
|
|
2260
|
+
spinner.start('Searching dependencies...');
|
|
2236
2261
|
const socketSdk = await index.setupSdk(apiToken);
|
|
2237
2262
|
const result = await handleApiCall(socketSdk.searchDependencies({
|
|
2238
2263
|
limit,
|
|
2239
2264
|
offset
|
|
2240
2265
|
}), 'Searching dependencies');
|
|
2241
2266
|
if (!result.success) {
|
|
2242
|
-
handleUnsuccessfulApiResponse('searchDependencies', result, spinner
|
|
2267
|
+
handleUnsuccessfulApiResponse('searchDependencies', result, spinner);
|
|
2243
2268
|
return;
|
|
2244
2269
|
}
|
|
2245
|
-
spinner
|
|
2270
|
+
spinner.stop('Organization dependencies:');
|
|
2246
2271
|
if (outputJson) {
|
|
2247
|
-
|
|
2272
|
+
logger.logger.log(result.data);
|
|
2248
2273
|
return;
|
|
2249
2274
|
}
|
|
2250
2275
|
const options = {
|
|
@@ -2271,9 +2296,12 @@ async function findDependencies({
|
|
|
2271
2296
|
name: colors.cyan('Direct')
|
|
2272
2297
|
}]
|
|
2273
2298
|
};
|
|
2274
|
-
|
|
2299
|
+
logger.logger.log(chalkTable(options, result.data.rows));
|
|
2275
2300
|
}
|
|
2276
2301
|
|
|
2302
|
+
const {
|
|
2303
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$u
|
|
2304
|
+
} = constants;
|
|
2277
2305
|
const config$v = {
|
|
2278
2306
|
commandName: 'dependencies',
|
|
2279
2307
|
description: 'Search for any dependency that is being used in your organization',
|
|
@@ -2320,7 +2348,8 @@ async function run$v(argv, importMeta, {
|
|
|
2320
2348
|
parentName
|
|
2321
2349
|
});
|
|
2322
2350
|
if (cli.flags['dryRun']) {
|
|
2323
|
-
|
|
2351
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$u);
|
|
2352
|
+
return;
|
|
2324
2353
|
}
|
|
2325
2354
|
|
|
2326
2355
|
// TODO: markdown flag is ignored
|
|
@@ -2338,38 +2367,44 @@ async function getDiffScan({
|
|
|
2338
2367
|
orgSlug,
|
|
2339
2368
|
outputJson
|
|
2340
2369
|
}, apiToken) {
|
|
2341
|
-
|
|
2342
|
-
|
|
2370
|
+
// Lazily access constants.spinner.
|
|
2371
|
+
const {
|
|
2372
|
+
spinner
|
|
2373
|
+
} = constants;
|
|
2374
|
+
spinner.start('Getting diff scan...');
|
|
2343
2375
|
const response = await queryAPI(`${orgSlug}/full-scans/diff?before=${before}&after=${after}&preview`, apiToken);
|
|
2344
2376
|
const data = await response.json();
|
|
2345
2377
|
if (!response.ok) {
|
|
2346
2378
|
const err = await handleAPIError(response.status);
|
|
2347
|
-
spinner
|
|
2379
|
+
spinner.errorAndStop(`${colors.bgRed(colors.white(response.statusText))}: ${err}`);
|
|
2348
2380
|
return;
|
|
2349
2381
|
}
|
|
2350
|
-
spinner
|
|
2382
|
+
spinner.stop();
|
|
2351
2383
|
if (file && !outputJson) {
|
|
2352
2384
|
fs.writeFile(file, JSON.stringify(data), err => {
|
|
2353
|
-
err ?
|
|
2385
|
+
err ? logger.logger.error(err) : logger.logger.log(`Data successfully written to ${file}`);
|
|
2354
2386
|
});
|
|
2355
2387
|
return;
|
|
2356
2388
|
}
|
|
2357
2389
|
if (outputJson) {
|
|
2358
|
-
|
|
2359
|
-
|
|
2390
|
+
logger.logger.log(`\n Diff scan result: \n`);
|
|
2391
|
+
logger.logger.log(util.inspect(data, {
|
|
2360
2392
|
showHidden: false,
|
|
2361
2393
|
depth: null,
|
|
2362
2394
|
colors: true
|
|
2363
2395
|
}));
|
|
2364
|
-
|
|
2396
|
+
logger.logger.log(`\n View this diff scan in the Socket dashboard: ${colors.cyan(data?.['diff_report_url'])}`);
|
|
2365
2397
|
return;
|
|
2366
2398
|
}
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2399
|
+
logger.logger.log('Diff scan result:');
|
|
2400
|
+
logger.logger.log(data);
|
|
2401
|
+
logger.logger.log(`\n 📝 To display the detailed report in the terminal, use the --json flag \n`);
|
|
2402
|
+
logger.logger.log(`\n View this diff scan in the Socket dashboard: ${colors.cyan(data?.['diff_report_url'])}`);
|
|
2371
2403
|
}
|
|
2372
2404
|
|
|
2405
|
+
const {
|
|
2406
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$t
|
|
2407
|
+
} = constants;
|
|
2373
2408
|
const config$u = {
|
|
2374
2409
|
commandName: 'get',
|
|
2375
2410
|
description: 'Get a diff scan for an organization',
|
|
@@ -2435,14 +2470,15 @@ async function run$u(argv, importMeta, {
|
|
|
2435
2470
|
// options or missing arguments.
|
|
2436
2471
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
2437
2472
|
process.exitCode = 2;
|
|
2438
|
-
|
|
2473
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
2439
2474
|
- 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
|
|
2440
2475
|
- To get full scans IDs, you can run the command "socket scan list <your org slug>".
|
|
2441
2476
|
- Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n`);
|
|
2442
2477
|
return;
|
|
2443
2478
|
}
|
|
2444
2479
|
if (cli.flags['dryRun']) {
|
|
2445
|
-
|
|
2480
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$t);
|
|
2481
|
+
return;
|
|
2446
2482
|
}
|
|
2447
2483
|
const apiToken = index.getDefaultToken();
|
|
2448
2484
|
if (!apiToken) {
|
|
@@ -2485,7 +2521,11 @@ function isTopLevel(tree, node) {
|
|
|
2485
2521
|
return tree.children.get(node.name) === node;
|
|
2486
2522
|
}
|
|
2487
2523
|
async function runFix() {
|
|
2488
|
-
|
|
2524
|
+
// Lazily access constants.spinner.
|
|
2525
|
+
const {
|
|
2526
|
+
spinner
|
|
2527
|
+
} = constants;
|
|
2528
|
+
spinner.start();
|
|
2489
2529
|
const cwd = process.cwd();
|
|
2490
2530
|
const editablePkgJson = await packages.readPackageJson(cwd, {
|
|
2491
2531
|
editable: true
|
|
@@ -2516,7 +2556,7 @@ async function runFix() {
|
|
|
2516
2556
|
const tree = arb.idealTree;
|
|
2517
2557
|
const hasUpgrade = !!registry.getManifestData(NPM$d, name);
|
|
2518
2558
|
if (hasUpgrade) {
|
|
2519
|
-
spinner
|
|
2559
|
+
spinner.info(`Skipping ${name}. Socket Optimize package exists.`);
|
|
2520
2560
|
continue;
|
|
2521
2561
|
}
|
|
2522
2562
|
const nodes = index.findPackageNodes(tree, name);
|
|
@@ -2542,10 +2582,10 @@ async function runFix() {
|
|
|
2542
2582
|
try {
|
|
2543
2583
|
// eslint-disable-next-line no-await-in-loop
|
|
2544
2584
|
await npm.runScript('test', [], {
|
|
2545
|
-
spinner
|
|
2585
|
+
spinner,
|
|
2546
2586
|
stdio: 'ignore'
|
|
2547
2587
|
});
|
|
2548
|
-
spinner
|
|
2588
|
+
spinner.info(`Patched ${name} ${oldVersion} -> ${node.version}`);
|
|
2549
2589
|
if (isTopLevel(tree, node)) {
|
|
2550
2590
|
for (const depField of ['dependencies', 'optionalDependencies', 'peerDependencies']) {
|
|
2551
2591
|
const oldVersion = editablePkgJson.content[depField]?.[name];
|
|
@@ -2558,11 +2598,11 @@ async function runFix() {
|
|
|
2558
2598
|
// eslint-disable-next-line no-await-in-loop
|
|
2559
2599
|
await editablePkgJson.save();
|
|
2560
2600
|
} catch {
|
|
2561
|
-
spinner
|
|
2601
|
+
spinner.error(`Reverting ${name} to ${oldVersion}`);
|
|
2562
2602
|
arb.idealTree = revertToIdealTree;
|
|
2563
2603
|
}
|
|
2564
2604
|
} else {
|
|
2565
|
-
spinner
|
|
2605
|
+
spinner.error(`Could not patch ${name} ${oldVersion}`);
|
|
2566
2606
|
}
|
|
2567
2607
|
}
|
|
2568
2608
|
}
|
|
@@ -2574,9 +2614,12 @@ async function runFix() {
|
|
|
2574
2614
|
});
|
|
2575
2615
|
arb2.idealTree = arb.idealTree;
|
|
2576
2616
|
await arb2.reify();
|
|
2577
|
-
spinner
|
|
2617
|
+
spinner.stop();
|
|
2578
2618
|
}
|
|
2579
2619
|
|
|
2620
|
+
const {
|
|
2621
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$s
|
|
2622
|
+
} = constants;
|
|
2580
2623
|
const config$t = {
|
|
2581
2624
|
commandName: 'fix',
|
|
2582
2625
|
description: 'Fix "fixable" Socket alerts',
|
|
@@ -2607,7 +2650,8 @@ async function run$t(argv, importMeta, {
|
|
|
2607
2650
|
parentName
|
|
2608
2651
|
});
|
|
2609
2652
|
if (cli.flags['dryRun']) {
|
|
2610
|
-
|
|
2653
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$s);
|
|
2654
|
+
return;
|
|
2611
2655
|
}
|
|
2612
2656
|
await runFix();
|
|
2613
2657
|
}
|
|
@@ -2719,9 +2763,9 @@ function formatPackageInfo({
|
|
|
2719
2763
|
strict
|
|
2720
2764
|
}, spinner) {
|
|
2721
2765
|
if (outputJson) {
|
|
2722
|
-
|
|
2766
|
+
logger.logger.log(JSON.stringify(data, undefined, 2));
|
|
2723
2767
|
} else {
|
|
2724
|
-
|
|
2768
|
+
logger.logger.log('\nPackage report card:');
|
|
2725
2769
|
const scoreResult = {
|
|
2726
2770
|
'Supply Chain Risk': Math.floor(score.supplyChainRisk.score * 100),
|
|
2727
2771
|
Maintenance: Math.floor(score.maintenance.score * 100),
|
|
@@ -2729,8 +2773,8 @@ function formatPackageInfo({
|
|
|
2729
2773
|
Vulnerabilities: Math.floor(score.vulnerability.score * 100),
|
|
2730
2774
|
License: Math.floor(score.license.score * 100)
|
|
2731
2775
|
};
|
|
2732
|
-
Object.entries(scoreResult).map(score =>
|
|
2733
|
-
|
|
2776
|
+
Object.entries(scoreResult).map(score => logger.logger.log(`- ${score[0]}: ${formatScore(score[1])}`));
|
|
2777
|
+
logger.logger.log('\n');
|
|
2734
2778
|
if (objectSome(severityCount)) {
|
|
2735
2779
|
spinner[strict ? 'error' : 'success'](`Package has these issues: ${formatSeverityCount(severityCount)}`);
|
|
2736
2780
|
formatPackageIssuesDetails(data, outputMarkdown);
|
|
@@ -2739,18 +2783,18 @@ function formatPackageInfo({
|
|
|
2739
2783
|
}
|
|
2740
2784
|
const format = new index.ColorOrMarkdown(!!outputMarkdown);
|
|
2741
2785
|
const url = index.getSocketDevPackageOverviewUrl(NPM$c, pkgName, pkgVersion);
|
|
2742
|
-
|
|
2786
|
+
logger.logger.log('\n');
|
|
2743
2787
|
if (pkgVersion === 'latest') {
|
|
2744
|
-
|
|
2788
|
+
logger.logger.log(`Detailed info on socket.dev: ${format.hyperlink(`${pkgName}`, url, {
|
|
2745
2789
|
fallbackToUrl: true
|
|
2746
2790
|
})}`);
|
|
2747
2791
|
} else {
|
|
2748
|
-
|
|
2792
|
+
logger.logger.log(`Detailed info on socket.dev: ${format.hyperlink(`${pkgName} v${pkgVersion}`, url, {
|
|
2749
2793
|
fallbackToUrl: true
|
|
2750
2794
|
})}`);
|
|
2751
2795
|
}
|
|
2752
2796
|
if (!outputMarkdown) {
|
|
2753
|
-
|
|
2797
|
+
logger.logger.log(colors.dim(`\nOr rerun ${colors.italic(name)} using the ${colors.italic('--json')} flag to get full JSON output`));
|
|
2754
2798
|
}
|
|
2755
2799
|
}
|
|
2756
2800
|
if (strict && objectSome(severityCount)) {
|
|
@@ -2781,9 +2825,9 @@ function formatPackageIssuesDetails(packageData, outputMarkdown) {
|
|
|
2781
2825
|
fallbackToUrl: true
|
|
2782
2826
|
});
|
|
2783
2827
|
if (uniqueIssues[issue]?.count === 1) {
|
|
2784
|
-
|
|
2828
|
+
logger.logger.log(`- ${issueWithLink}`);
|
|
2785
2829
|
} else {
|
|
2786
|
-
|
|
2830
|
+
logger.logger.log(`- ${issueWithLink}: ${uniqueIssues[issue]?.count}`);
|
|
2787
2831
|
}
|
|
2788
2832
|
}
|
|
2789
2833
|
}
|
|
@@ -2805,11 +2849,12 @@ async function getPackageInfo({
|
|
|
2805
2849
|
pkgVersion,
|
|
2806
2850
|
strict
|
|
2807
2851
|
}) {
|
|
2808
|
-
|
|
2809
|
-
const
|
|
2810
|
-
|
|
2811
|
-
}
|
|
2812
|
-
|
|
2852
|
+
// Lazily access constants.spinner.
|
|
2853
|
+
const {
|
|
2854
|
+
spinner
|
|
2855
|
+
} = constants;
|
|
2856
|
+
spinner.start(pkgVersion === 'latest' ? `Looking up data for the latest version of ${pkgName}` : `Looking up data for version ${pkgVersion} of ${pkgName}`);
|
|
2857
|
+
const packageData = await fetchPackageInfo(pkgName, pkgVersion, includeAllIssues, spinner);
|
|
2813
2858
|
if (packageData) {
|
|
2814
2859
|
formatPackageInfo(packageData, {
|
|
2815
2860
|
name: commandName,
|
|
@@ -2818,10 +2863,13 @@ async function getPackageInfo({
|
|
|
2818
2863
|
pkgName,
|
|
2819
2864
|
pkgVersion,
|
|
2820
2865
|
strict
|
|
2821
|
-
}, spinner
|
|
2866
|
+
}, spinner);
|
|
2822
2867
|
}
|
|
2823
2868
|
}
|
|
2824
2869
|
|
|
2870
|
+
const {
|
|
2871
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$r
|
|
2872
|
+
} = constants;
|
|
2825
2873
|
const config$s = {
|
|
2826
2874
|
commandName: 'info',
|
|
2827
2875
|
description: 'Look up info regarding a package',
|
|
@@ -2863,7 +2911,7 @@ async function run$s(argv, importMeta, {
|
|
|
2863
2911
|
// options or missing arguments.
|
|
2864
2912
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
2865
2913
|
process.exitCode = 2;
|
|
2866
|
-
|
|
2914
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
2867
2915
|
- Expecting a package name ${!rawPkgName ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
2868
2916
|
- Can only accept one package at a time ${cli.input.length > 1 ? colors.red('(got ' + cli.input.length + '!)') : colors.green('(ok)')}\n`);
|
|
2869
2917
|
return;
|
|
@@ -2872,7 +2920,8 @@ async function run$s(argv, importMeta, {
|
|
|
2872
2920
|
const pkgName = versionSeparator < 1 ? rawPkgName : rawPkgName.slice(0, versionSeparator);
|
|
2873
2921
|
const pkgVersion = versionSeparator < 1 ? 'latest' : rawPkgName.slice(versionSeparator + 1);
|
|
2874
2922
|
if (cli.flags['dryRun']) {
|
|
2875
|
-
|
|
2923
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$r);
|
|
2924
|
+
return;
|
|
2876
2925
|
}
|
|
2877
2926
|
await getPackageInfo({
|
|
2878
2927
|
commandName: `${parentName} ${config$s.commandName}`,
|
|
@@ -2898,13 +2947,16 @@ const {
|
|
|
2898
2947
|
SOCKET_PUBLIC_API_TOKEN
|
|
2899
2948
|
} = constants;
|
|
2900
2949
|
async function attemptLogin(apiBaseUrl, apiProxy) {
|
|
2950
|
+
apiBaseUrl ??= index.getSetting('apiBaseUrl') ?? undefined;
|
|
2951
|
+
apiProxy ??= index.getSetting('apiProxy') ?? undefined;
|
|
2901
2952
|
const apiToken = (await prompts.password({
|
|
2902
2953
|
message: `Enter your ${terminalLink('Socket.dev API key', 'https://docs.socket.dev/docs/api-keys')} (leave blank for a public key)`
|
|
2903
2954
|
})) || SOCKET_PUBLIC_API_TOKEN;
|
|
2904
|
-
|
|
2905
|
-
|
|
2906
|
-
|
|
2907
|
-
|
|
2955
|
+
// Lazily access constants.spinner.
|
|
2956
|
+
const {
|
|
2957
|
+
spinner
|
|
2958
|
+
} = constants;
|
|
2959
|
+
spinner.start('Verifying API key...');
|
|
2908
2960
|
let orgs;
|
|
2909
2961
|
try {
|
|
2910
2962
|
const sdk = await index.setupSdk(apiToken, apiBaseUrl, apiProxy);
|
|
@@ -2913,9 +2965,9 @@ async function attemptLogin(apiBaseUrl, apiProxy) {
|
|
|
2913
2965
|
throw new index.AuthError();
|
|
2914
2966
|
}
|
|
2915
2967
|
orgs = result.data;
|
|
2916
|
-
spinner
|
|
2968
|
+
spinner.success('API key verified');
|
|
2917
2969
|
} catch {
|
|
2918
|
-
spinner
|
|
2970
|
+
spinner.errorAndStop('Invalid API key');
|
|
2919
2971
|
return;
|
|
2920
2972
|
}
|
|
2921
2973
|
const enforcedChoices = Object.values(orgs.organizations).filter(org => org?.plan === 'enterprise').map(org => ({
|
|
@@ -2932,7 +2984,7 @@ async function attemptLogin(apiBaseUrl, apiProxy) {
|
|
|
2932
2984
|
description: 'Pick "None" if this is a personal device'
|
|
2933
2985
|
})
|
|
2934
2986
|
}, {
|
|
2935
|
-
spinner
|
|
2987
|
+
spinner
|
|
2936
2988
|
});
|
|
2937
2989
|
if (id) {
|
|
2938
2990
|
enforcedOrgs = [id];
|
|
@@ -2942,7 +2994,7 @@ async function attemptLogin(apiBaseUrl, apiProxy) {
|
|
|
2942
2994
|
message: `Should Socket enforce ${enforcedChoices[0]?.name}'s security policies system-wide?`,
|
|
2943
2995
|
default: true
|
|
2944
2996
|
}, {
|
|
2945
|
-
spinner
|
|
2997
|
+
spinner
|
|
2946
2998
|
});
|
|
2947
2999
|
if (confirmOrg) {
|
|
2948
3000
|
const existing = enforcedChoices[0];
|
|
@@ -2954,12 +3006,15 @@ async function attemptLogin(apiBaseUrl, apiProxy) {
|
|
|
2954
3006
|
const oldToken = index.getSetting('apiToken');
|
|
2955
3007
|
try {
|
|
2956
3008
|
applyLogin(apiToken, enforcedOrgs, apiBaseUrl, apiProxy);
|
|
2957
|
-
spinner
|
|
3009
|
+
spinner.successAndStop(`API credentials ${oldToken ? 'updated' : 'set'}`);
|
|
2958
3010
|
} catch {
|
|
2959
|
-
spinner
|
|
3011
|
+
spinner.errorAndStop(`API login failed`);
|
|
2960
3012
|
}
|
|
2961
3013
|
}
|
|
2962
3014
|
|
|
3015
|
+
const {
|
|
3016
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$q
|
|
3017
|
+
} = constants;
|
|
2963
3018
|
const config$r = {
|
|
2964
3019
|
commandName: 'login',
|
|
2965
3020
|
description: 'Socket API login',
|
|
@@ -3006,7 +3061,8 @@ async function run$r(argv, importMeta, {
|
|
|
3006
3061
|
let apiBaseUrl = cli.flags['apiBaseUrl'];
|
|
3007
3062
|
let apiProxy = cli.flags['apiProxy'];
|
|
3008
3063
|
if (cli.flags['dryRun']) {
|
|
3009
|
-
|
|
3064
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$q);
|
|
3065
|
+
return;
|
|
3010
3066
|
}
|
|
3011
3067
|
if (!isInteractive()) {
|
|
3012
3068
|
throw new index.InputError('Cannot prompt for credentials in a non-interactive shell');
|
|
@@ -3030,6 +3086,9 @@ function attemptLogout() {
|
|
|
3030
3086
|
}
|
|
3031
3087
|
}
|
|
3032
3088
|
|
|
3089
|
+
const {
|
|
3090
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$p
|
|
3091
|
+
} = constants;
|
|
3033
3092
|
const config$q = {
|
|
3034
3093
|
commandName: 'logout',
|
|
3035
3094
|
description: 'Socket API logout',
|
|
@@ -3059,31 +3118,31 @@ async function run$q(argv, importMeta, {
|
|
|
3059
3118
|
parentName
|
|
3060
3119
|
});
|
|
3061
3120
|
if (cli.flags['dryRun']) {
|
|
3062
|
-
|
|
3121
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$p);
|
|
3122
|
+
return;
|
|
3063
3123
|
}
|
|
3064
3124
|
attemptLogout();
|
|
3065
3125
|
}
|
|
3066
3126
|
|
|
3067
3127
|
async function convertGradleToMaven(target, bin, _out, verbose, gradleOpts) {
|
|
3128
|
+
// Lazily access constants.spinner.
|
|
3129
|
+
const {
|
|
3130
|
+
spinner
|
|
3131
|
+
} = constants;
|
|
3068
3132
|
const rbin = path.resolve(bin);
|
|
3069
3133
|
const rtarget = path.resolve(target);
|
|
3070
|
-
// const rout = out === '-' ? '-' : path.resolve(out)
|
|
3071
|
-
|
|
3072
3134
|
if (verbose) {
|
|
3073
|
-
|
|
3074
|
-
|
|
3075
|
-
|
|
3076
|
-
|
|
3077
|
-
console.groupEnd();
|
|
3135
|
+
logger.logger.group('gradle2maven:');
|
|
3136
|
+
logger.logger.log(`[VERBOSE] - Absolute bin path: \`${rbin}\``);
|
|
3137
|
+
logger.logger.log(`[VERBOSE] - Absolute target path: \`${rtarget}\``);
|
|
3138
|
+
logger.logger.groupEnd();
|
|
3078
3139
|
} else {
|
|
3079
|
-
|
|
3080
|
-
|
|
3081
|
-
|
|
3082
|
-
|
|
3083
|
-
|
|
3084
|
-
}
|
|
3085
|
-
const spinner$1 = new spinner.Spinner();
|
|
3086
|
-
spinner$1.start(`Converting gradle to maven from \`${bin}\` on \`${target}\`...`);
|
|
3140
|
+
logger.logger.group('gradle2maven:');
|
|
3141
|
+
logger.logger.log(`- executing: \`${bin}\``);
|
|
3142
|
+
logger.logger.log(`- src dir: \`${target}\``);
|
|
3143
|
+
logger.logger.groupEnd();
|
|
3144
|
+
}
|
|
3145
|
+
spinner.start(`Converting gradle to maven from \`${bin}\` on \`${target}\`...`);
|
|
3087
3146
|
try {
|
|
3088
3147
|
// Run sbt with the init script we provide which should yield zero or more pom files.
|
|
3089
3148
|
// We have to figure out where to store those pom files such that we can upload them and predict them through the GitHub API.
|
|
@@ -3093,36 +3152,37 @@ async function convertGradleToMaven(target, bin, _out, verbose, gradleOpts) {
|
|
|
3093
3152
|
const initLocation = path.join(constants.rootDistPath, 'init.gradle');
|
|
3094
3153
|
const commandArgs = ['--init-script', initLocation, ...gradleOpts, 'pom'];
|
|
3095
3154
|
if (verbose) {
|
|
3096
|
-
spinner
|
|
3155
|
+
spinner.log('[VERBOSE] Executing:', bin, commandArgs);
|
|
3097
3156
|
}
|
|
3098
3157
|
const output = await spawn(bin, commandArgs, {
|
|
3099
3158
|
cwd: target || '.'
|
|
3100
3159
|
});
|
|
3160
|
+
spinner.stop();
|
|
3101
3161
|
if (verbose) {
|
|
3102
|
-
|
|
3103
|
-
|
|
3104
|
-
|
|
3162
|
+
logger.logger.group('[VERBOSE] gradle stdout:');
|
|
3163
|
+
logger.logger.log(output);
|
|
3164
|
+
logger.logger.groupEnd();
|
|
3105
3165
|
}
|
|
3106
3166
|
if (output.stderr) {
|
|
3107
|
-
|
|
3167
|
+
logger.logger.error('There were errors while running gradle');
|
|
3108
3168
|
// (In verbose mode, stderr was printed above, no need to repeat it)
|
|
3109
3169
|
if (!verbose) {
|
|
3110
|
-
|
|
3111
|
-
|
|
3112
|
-
|
|
3170
|
+
logger.logger.group('[VERBOSE] stderr:');
|
|
3171
|
+
logger.logger.error(output.stderr);
|
|
3172
|
+
logger.logger.groupEnd();
|
|
3113
3173
|
}
|
|
3114
3174
|
process.exit(1);
|
|
3115
3175
|
}
|
|
3116
|
-
|
|
3117
|
-
|
|
3176
|
+
logger.logger.success('Executed gradle successfully');
|
|
3177
|
+
logger.logger.log('Reported exports:');
|
|
3118
3178
|
output.stdout.replace(/^POM file copied to: (.*)/gm, (_all, fn) => {
|
|
3119
|
-
|
|
3179
|
+
logger.logger.log('- ', fn);
|
|
3120
3180
|
return fn;
|
|
3121
3181
|
});
|
|
3122
3182
|
|
|
3123
3183
|
// const loc = output.stdout?.match(/Wrote (.*?.pom)\n/)?.[1]?.trim()
|
|
3124
3184
|
// if (!loc) {
|
|
3125
|
-
//
|
|
3185
|
+
// logger.error(
|
|
3126
3186
|
// 'There were no errors from sbt but could not find the location of resulting .pom file either'
|
|
3127
3187
|
// )
|
|
3128
3188
|
// process.exit(1)
|
|
@@ -3131,8 +3191,8 @@ async function convertGradleToMaven(target, bin, _out, verbose, gradleOpts) {
|
|
|
3131
3191
|
// // Move the pom file to ...? initial cwd? loc will be an absolute path, or dump to stdout
|
|
3132
3192
|
// if (out === '-') {
|
|
3133
3193
|
// spinner.start('Result:\n```')
|
|
3134
|
-
//
|
|
3135
|
-
//
|
|
3194
|
+
// spinner.log(await safeReadFile(loc, 'utf8'))
|
|
3195
|
+
// spinner.log('```')
|
|
3136
3196
|
// spinner.successAndStop(`OK`)
|
|
3137
3197
|
// } else {
|
|
3138
3198
|
// spinner.start()
|
|
@@ -3148,16 +3208,20 @@ async function convertGradleToMaven(target, bin, _out, verbose, gradleOpts) {
|
|
|
3148
3208
|
// spinner.successAndStop(`OK. File should be available in \`${out}\``)
|
|
3149
3209
|
// }
|
|
3150
3210
|
} catch (e) {
|
|
3151
|
-
spinner
|
|
3211
|
+
spinner.stop();
|
|
3212
|
+
logger.logger.error('There was an unexpected error while running this' + (verbose ? '' : ' (use --verbose for details)'));
|
|
3152
3213
|
if (verbose) {
|
|
3153
|
-
|
|
3154
|
-
|
|
3155
|
-
|
|
3214
|
+
logger.logger.group('[VERBOSE] error:');
|
|
3215
|
+
logger.logger.log(e);
|
|
3216
|
+
logger.logger.groupEnd();
|
|
3156
3217
|
}
|
|
3157
3218
|
process.exit(1);
|
|
3158
3219
|
}
|
|
3159
3220
|
}
|
|
3160
3221
|
|
|
3222
|
+
const {
|
|
3223
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$o
|
|
3224
|
+
} = constants;
|
|
3161
3225
|
const config$p = {
|
|
3162
3226
|
commandName: 'gradle',
|
|
3163
3227
|
description: '[beta] Use Gradle to generate a manifest file (`pom.xml`) for a Gradle/Java/Kotlin/etc project',
|
|
@@ -3245,22 +3309,23 @@ async function run$p(argv, importMeta, {
|
|
|
3245
3309
|
});
|
|
3246
3310
|
const verbose = Boolean(cli.flags['verbose']);
|
|
3247
3311
|
if (verbose) {
|
|
3248
|
-
|
|
3249
|
-
|
|
3250
|
-
|
|
3251
|
-
|
|
3252
|
-
|
|
3312
|
+
logger.logger.group('- ', parentName, config$p.commandName, ':');
|
|
3313
|
+
logger.logger.group('- flags:', cli.flags);
|
|
3314
|
+
logger.logger.groupEnd();
|
|
3315
|
+
logger.logger.log('- input:', cli.input);
|
|
3316
|
+
logger.logger.groupEnd();
|
|
3253
3317
|
}
|
|
3254
3318
|
const target = cli.input[0];
|
|
3255
3319
|
|
|
3256
|
-
// TODO: I'm not sure it's feasible to parse source file from stdin. We could
|
|
3257
|
-
|
|
3320
|
+
// TODO: I'm not sure it's feasible to parse source file from stdin. We could
|
|
3321
|
+
// try, store contents in a file in some folder, target that folder... what
|
|
3322
|
+
// would the file name be?
|
|
3258
3323
|
if (!target || target === '-' || cli.input.length > 1) {
|
|
3259
3324
|
// Use exit status of 2 to indicate incorrect usage, generally invalid
|
|
3260
3325
|
// options or missing arguments.
|
|
3261
3326
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
3262
3327
|
process.exitCode = 2;
|
|
3263
|
-
|
|
3328
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
3264
3329
|
- The DIR arg is required ${!target ? colors.red('(missing!)') : target === '-' ? colors.red('(stdin is not supported)') : colors.green('(ok)')}\n
|
|
3265
3330
|
- Can only accept one DIR (make sure to escape spaces!) ${cli.input.length > 1 ? colors.red(`(received ${cli.input.length}!)`) : colors.green('(ok)')}\n`);
|
|
3266
3331
|
return;
|
|
@@ -3279,42 +3344,44 @@ async function run$p(argv, importMeta, {
|
|
|
3279
3344
|
out = '-';
|
|
3280
3345
|
}
|
|
3281
3346
|
if (verbose) {
|
|
3282
|
-
|
|
3283
|
-
|
|
3284
|
-
|
|
3285
|
-
|
|
3286
|
-
|
|
3347
|
+
logger.logger.group();
|
|
3348
|
+
logger.logger.log('- target:', target);
|
|
3349
|
+
logger.logger.log('- gradle bin:', bin);
|
|
3350
|
+
logger.logger.log('- out:', out);
|
|
3351
|
+
logger.logger.groupEnd();
|
|
3287
3352
|
}
|
|
3288
3353
|
let gradleOpts = [];
|
|
3289
3354
|
if (cli.flags['gradleOpts']) {
|
|
3290
3355
|
gradleOpts = cli.flags['gradleOpts'].split(' ').map(s => s.trim()).filter(Boolean);
|
|
3291
3356
|
}
|
|
3292
3357
|
if (cli.flags['dryRun']) {
|
|
3293
|
-
|
|
3358
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$o);
|
|
3359
|
+
return;
|
|
3294
3360
|
}
|
|
3295
3361
|
await convertGradleToMaven(target, bin, out, verbose, gradleOpts);
|
|
3296
3362
|
}
|
|
3297
3363
|
|
|
3298
3364
|
async function convertSbtToMaven(target, bin, out, verbose, sbtOpts) {
|
|
3365
|
+
// Lazily access constants.spinner.
|
|
3366
|
+
const {
|
|
3367
|
+
spinner
|
|
3368
|
+
} = constants;
|
|
3299
3369
|
const rbin = path.resolve(bin);
|
|
3300
3370
|
const rtarget = path.resolve(target);
|
|
3301
|
-
// const rout = out === '-' ? '-' : path.resolve(out)
|
|
3302
|
-
|
|
3303
3371
|
if (verbose) {
|
|
3304
|
-
|
|
3305
|
-
|
|
3306
|
-
|
|
3307
|
-
//
|
|
3308
|
-
|
|
3372
|
+
logger.logger.group('sbt2maven:');
|
|
3373
|
+
logger.logger.log(`[VERBOSE] - Absolute bin path: \`${rbin}\``);
|
|
3374
|
+
logger.logger.log(`[VERBOSE] - Absolute target path: \`${rtarget}\``);
|
|
3375
|
+
// logger.log(`[VERBOSE] - Absolute out path: \`${rout}\``)
|
|
3376
|
+
logger.logger.groupEnd();
|
|
3309
3377
|
} else {
|
|
3310
|
-
|
|
3311
|
-
|
|
3312
|
-
|
|
3313
|
-
//
|
|
3314
|
-
|
|
3315
|
-
}
|
|
3316
|
-
|
|
3317
|
-
spinner$1.start(`Converting sbt to maven from \`${bin}\` on \`${target}\`...`);
|
|
3378
|
+
logger.logger.group('sbt2maven:');
|
|
3379
|
+
logger.logger.log(`- executing: \`${bin}\``);
|
|
3380
|
+
logger.logger.log(`- src dir: \`${target}\``);
|
|
3381
|
+
// logger.log(`- dst dir: \`${out}\``)
|
|
3382
|
+
logger.logger.groupEnd();
|
|
3383
|
+
}
|
|
3384
|
+
spinner.start(`Converting sbt to maven from \`${bin}\` on \`${target}\`...`);
|
|
3318
3385
|
try {
|
|
3319
3386
|
// Run sbt with the init script we provide which should yield zero or more
|
|
3320
3387
|
// pom files. We have to figure out where to store those pom files such that
|
|
@@ -3324,19 +3391,19 @@ async function convertSbtToMaven(target, bin, out, verbose, sbtOpts) {
|
|
|
3324
3391
|
const output = await spawn(bin, ['makePom'].concat(sbtOpts), {
|
|
3325
3392
|
cwd: target || '.'
|
|
3326
3393
|
});
|
|
3327
|
-
spinner
|
|
3394
|
+
spinner.stop();
|
|
3328
3395
|
if (verbose) {
|
|
3329
|
-
|
|
3330
|
-
|
|
3331
|
-
|
|
3396
|
+
logger.logger.group('[VERBOSE] sbt stdout:');
|
|
3397
|
+
logger.logger.log(output);
|
|
3398
|
+
logger.logger.groupEnd();
|
|
3332
3399
|
}
|
|
3333
3400
|
if (output.stderr) {
|
|
3334
3401
|
logger.logger.error('There were errors while running sbt');
|
|
3335
3402
|
// (In verbose mode, stderr was printed above, no need to repeat it)
|
|
3336
3403
|
if (!verbose) {
|
|
3337
|
-
|
|
3338
|
-
|
|
3339
|
-
|
|
3404
|
+
logger.logger.group('[VERBOSE] stderr:');
|
|
3405
|
+
logger.logger.error(output.stderr);
|
|
3406
|
+
logger.logger.groupEnd();
|
|
3340
3407
|
}
|
|
3341
3408
|
process.exit(1);
|
|
3342
3409
|
}
|
|
@@ -3354,39 +3421,43 @@ async function convertSbtToMaven(target, bin, out, verbose, sbtOpts) {
|
|
|
3354
3421
|
// TODO: maybe we can add an option to target a specific file to dump to stdout
|
|
3355
3422
|
if (out === '-' && poms.length === 1) {
|
|
3356
3423
|
logger.logger.log('Result:\n```');
|
|
3357
|
-
|
|
3424
|
+
logger.logger.log(await index.safeReadFile(poms[0], 'utf8'));
|
|
3358
3425
|
logger.logger.log('```');
|
|
3359
3426
|
logger.logger.success(`OK`);
|
|
3360
3427
|
} else if (out === '-') {
|
|
3361
3428
|
logger.logger.error('Requested out target was stdout but there are multiple generated files');
|
|
3362
|
-
poms.forEach(fn =>
|
|
3363
|
-
|
|
3429
|
+
poms.forEach(fn => logger.logger.error('-', fn));
|
|
3430
|
+
logger.logger.error('Exiting now...');
|
|
3364
3431
|
process.exit(1);
|
|
3365
3432
|
} else {
|
|
3366
3433
|
// if (verbose) {
|
|
3367
|
-
//
|
|
3434
|
+
// logger.log(
|
|
3368
3435
|
// `Moving manifest file from \`${loc.replace(/^\/home\/[^/]*?\//, '~/')}\` to \`${out}\``
|
|
3369
3436
|
// )
|
|
3370
3437
|
// } else {
|
|
3371
|
-
//
|
|
3438
|
+
// logger.log('Moving output pom file')
|
|
3372
3439
|
// }
|
|
3373
3440
|
// TODO: do we prefer fs-extra? renaming can be gnarly on windows and fs-extra's version is better
|
|
3374
3441
|
// await renamep(loc, out)
|
|
3375
3442
|
logger.logger.success(`Generated ${poms.length} pom files`);
|
|
3376
|
-
poms.forEach(fn =>
|
|
3443
|
+
poms.forEach(fn => logger.logger.log('-', fn));
|
|
3377
3444
|
logger.logger.success(`OK`);
|
|
3378
3445
|
}
|
|
3379
3446
|
} catch (e) {
|
|
3380
|
-
spinner
|
|
3447
|
+
spinner.stop();
|
|
3448
|
+
logger.logger.error('There was an unexpected error while running this' + (verbose ? '' : ' (use --verbose for details)'));
|
|
3381
3449
|
if (verbose) {
|
|
3382
|
-
|
|
3383
|
-
|
|
3384
|
-
|
|
3450
|
+
logger.logger.group('[VERBOSE] error:');
|
|
3451
|
+
logger.logger.log(e);
|
|
3452
|
+
logger.logger.groupEnd();
|
|
3385
3453
|
}
|
|
3386
3454
|
process.exit(1);
|
|
3387
3455
|
}
|
|
3388
3456
|
}
|
|
3389
3457
|
|
|
3458
|
+
const {
|
|
3459
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$n
|
|
3460
|
+
} = constants;
|
|
3390
3461
|
const config$o = {
|
|
3391
3462
|
commandName: 'scala',
|
|
3392
3463
|
description: "[beta] Generate a manifest file (`pom.xml`) from Scala's `build.sbt` file",
|
|
@@ -3464,7 +3535,6 @@ const cmdManifestScala = {
|
|
|
3464
3535
|
async function run$o(argv, importMeta, {
|
|
3465
3536
|
parentName
|
|
3466
3537
|
}) {
|
|
3467
|
-
// console.log('scala', argv, parentName)
|
|
3468
3538
|
const cli = meowOrExit({
|
|
3469
3539
|
argv,
|
|
3470
3540
|
config: config$o,
|
|
@@ -3473,22 +3543,23 @@ async function run$o(argv, importMeta, {
|
|
|
3473
3543
|
});
|
|
3474
3544
|
const verbose = Boolean(cli.flags['verbose']);
|
|
3475
3545
|
if (verbose) {
|
|
3476
|
-
|
|
3477
|
-
|
|
3478
|
-
|
|
3479
|
-
|
|
3480
|
-
|
|
3546
|
+
logger.logger.group('- ', parentName, config$o.commandName, ':');
|
|
3547
|
+
logger.logger.group('- flags:', cli.flags);
|
|
3548
|
+
logger.logger.groupEnd();
|
|
3549
|
+
logger.logger.log('- input:', cli.input);
|
|
3550
|
+
logger.logger.groupEnd();
|
|
3481
3551
|
}
|
|
3482
3552
|
const target = cli.input[0];
|
|
3483
3553
|
|
|
3484
|
-
// TODO: I'm not sure it's feasible to parse source file from stdin. We could
|
|
3485
|
-
|
|
3554
|
+
// TODO: I'm not sure it's feasible to parse source file from stdin. We could
|
|
3555
|
+
// try, store contents in a file in some folder, target that folder... what
|
|
3556
|
+
// would the file name be?
|
|
3486
3557
|
if (!target || target === '-' || cli.input.length > 1) {
|
|
3487
3558
|
// Use exit status of 2 to indicate incorrect usage, generally invalid
|
|
3488
3559
|
// options or missing arguments.
|
|
3489
3560
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
3490
3561
|
process.exitCode = 2;
|
|
3491
|
-
|
|
3562
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
3492
3563
|
- The DIR or FILE arg is required ${!target ? colors.red('(missing!)') : target === '-' ? colors.red('(stdin is not supported)') : colors.green('(ok)')}\n
|
|
3493
3564
|
- 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`);
|
|
3494
3565
|
return;
|
|
@@ -3505,22 +3576,26 @@ async function run$o(argv, importMeta, {
|
|
|
3505
3576
|
out = '-';
|
|
3506
3577
|
}
|
|
3507
3578
|
if (verbose) {
|
|
3508
|
-
|
|
3509
|
-
|
|
3510
|
-
|
|
3511
|
-
|
|
3512
|
-
|
|
3579
|
+
logger.logger.group();
|
|
3580
|
+
logger.logger.log('- target:', target);
|
|
3581
|
+
logger.logger.log('- gradle bin:', bin);
|
|
3582
|
+
logger.logger.log('- out:', out);
|
|
3583
|
+
logger.logger.groupEnd();
|
|
3513
3584
|
}
|
|
3514
3585
|
let sbtOpts = [];
|
|
3515
3586
|
if (cli.flags['sbtOpts']) {
|
|
3516
3587
|
sbtOpts = cli.flags['sbtOpts'].split(' ').map(s => s.trim()).filter(Boolean);
|
|
3517
3588
|
}
|
|
3518
3589
|
if (cli.flags['dryRun']) {
|
|
3519
|
-
|
|
3590
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$n);
|
|
3591
|
+
return;
|
|
3520
3592
|
}
|
|
3521
3593
|
await convertSbtToMaven(target, bin, out, verbose, sbtOpts);
|
|
3522
3594
|
}
|
|
3523
3595
|
|
|
3596
|
+
const {
|
|
3597
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$m
|
|
3598
|
+
} = constants;
|
|
3524
3599
|
const config$n = {
|
|
3525
3600
|
commandName: 'auto',
|
|
3526
3601
|
description: 'Auto-detect build and attempt to generate manifest file',
|
|
@@ -3567,12 +3642,12 @@ async function run$n(argv, importMeta, {
|
|
|
3567
3642
|
const verbose = !!cli.flags['verbose'];
|
|
3568
3643
|
const cwd = cli.flags['cwd'] ?? process.cwd();
|
|
3569
3644
|
if (verbose) {
|
|
3570
|
-
|
|
3571
|
-
|
|
3572
|
-
|
|
3573
|
-
|
|
3574
|
-
|
|
3575
|
-
|
|
3645
|
+
logger.logger.group('- ', parentName, config$n.commandName, ':');
|
|
3646
|
+
logger.logger.group('- flags:', cli.flags);
|
|
3647
|
+
logger.logger.groupEnd();
|
|
3648
|
+
logger.logger.log('- input:', cli.input);
|
|
3649
|
+
logger.logger.log('- cwd:', cwd);
|
|
3650
|
+
logger.logger.groupEnd();
|
|
3576
3651
|
}
|
|
3577
3652
|
const subArgs = [];
|
|
3578
3653
|
if (verbose) {
|
|
@@ -3580,13 +3655,14 @@ async function run$n(argv, importMeta, {
|
|
|
3580
3655
|
}
|
|
3581
3656
|
const dir = cwd;
|
|
3582
3657
|
if (fs.existsSync(path.join(dir, 'build.sbt'))) {
|
|
3583
|
-
|
|
3658
|
+
logger.logger.log('Detected a Scala sbt build, running default Scala generator...');
|
|
3584
3659
|
if (cwd) {
|
|
3585
3660
|
subArgs.push('--cwd', cwd);
|
|
3586
3661
|
}
|
|
3587
3662
|
subArgs.push(dir);
|
|
3588
3663
|
if (cli.flags['dryRun']) {
|
|
3589
|
-
|
|
3664
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$m);
|
|
3665
|
+
return;
|
|
3590
3666
|
}
|
|
3591
3667
|
await cmdManifestScala.run(subArgs, importMeta, {
|
|
3592
3668
|
parentName
|
|
@@ -3594,13 +3670,14 @@ async function run$n(argv, importMeta, {
|
|
|
3594
3670
|
return;
|
|
3595
3671
|
}
|
|
3596
3672
|
if (fs.existsSync(path.join(dir, 'gradlew'))) {
|
|
3597
|
-
|
|
3673
|
+
logger.logger.log('Detected a gradle build, running default gradle generator...');
|
|
3598
3674
|
if (cwd) {
|
|
3599
3675
|
// This command takes the cwd as first arg.
|
|
3600
3676
|
subArgs.push(cwd);
|
|
3601
3677
|
}
|
|
3602
3678
|
if (cli.flags['dryRun']) {
|
|
3603
|
-
|
|
3679
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$m);
|
|
3680
|
+
return;
|
|
3604
3681
|
}
|
|
3605
3682
|
await cmdManifestGradle.run(subArgs, importMeta, {
|
|
3606
3683
|
parentName
|
|
@@ -3628,6 +3705,10 @@ async function run$n(argv, importMeta, {
|
|
|
3628
3705
|
}).showHelp();
|
|
3629
3706
|
}
|
|
3630
3707
|
|
|
3708
|
+
const {
|
|
3709
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$l
|
|
3710
|
+
} = constants;
|
|
3711
|
+
|
|
3631
3712
|
// TODO: we may want to dedupe some pieces for all gradle languages. I think it
|
|
3632
3713
|
// makes sense to have separate commands for them and I think it makes
|
|
3633
3714
|
// sense for the help panels to note the requested language, rather than
|
|
@@ -3720,22 +3801,23 @@ async function run$m(argv, importMeta, {
|
|
|
3720
3801
|
});
|
|
3721
3802
|
const verbose = Boolean(cli.flags['verbose']);
|
|
3722
3803
|
if (verbose) {
|
|
3723
|
-
|
|
3724
|
-
|
|
3725
|
-
|
|
3726
|
-
|
|
3727
|
-
|
|
3804
|
+
logger.logger.group('- ', parentName, config$m.commandName, ':');
|
|
3805
|
+
logger.logger.group('- flags:', cli.flags);
|
|
3806
|
+
logger.logger.groupEnd();
|
|
3807
|
+
logger.logger.log('- input:', cli.input);
|
|
3808
|
+
logger.logger.groupEnd();
|
|
3728
3809
|
}
|
|
3729
3810
|
const target = cli.input[0];
|
|
3730
3811
|
|
|
3731
|
-
// TODO: I'm not sure it's feasible to parse source file from stdin. We could
|
|
3732
|
-
|
|
3812
|
+
// TODO: I'm not sure it's feasible to parse source file from stdin. We could
|
|
3813
|
+
// try, store contents in a file in some folder, target that folder... what
|
|
3814
|
+
// would the file name be?
|
|
3733
3815
|
if (!target || target === '-' || cli.input.length > 1) {
|
|
3734
3816
|
// Use exit status of 2 to indicate incorrect usage, generally invalid
|
|
3735
3817
|
// options or missing arguments.
|
|
3736
3818
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
3737
3819
|
process.exitCode = 2;
|
|
3738
|
-
|
|
3820
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
3739
3821
|
- The DIR arg is required ${!target ? colors.red('(missing!)') : target === '-' ? colors.red('(stdin is not supported)') : colors.green('(ok)')}\n
|
|
3740
3822
|
- Can only accept one DIR (make sure to escape spaces!) ${cli.input.length > 1 ? colors.red(`(received ${cli.input.length}!)`) : colors.green('(ok)')}\n`);
|
|
3741
3823
|
return;
|
|
@@ -3754,18 +3836,19 @@ async function run$m(argv, importMeta, {
|
|
|
3754
3836
|
out = '-';
|
|
3755
3837
|
}
|
|
3756
3838
|
if (verbose) {
|
|
3757
|
-
|
|
3758
|
-
|
|
3759
|
-
|
|
3760
|
-
|
|
3761
|
-
|
|
3839
|
+
logger.logger.group();
|
|
3840
|
+
logger.logger.log('- target:', target);
|
|
3841
|
+
logger.logger.log('- gradle bin:', bin);
|
|
3842
|
+
logger.logger.log('- out:', out);
|
|
3843
|
+
logger.logger.groupEnd();
|
|
3762
3844
|
}
|
|
3763
3845
|
let gradleOpts = [];
|
|
3764
3846
|
if (cli.flags['gradleOpts']) {
|
|
3765
3847
|
gradleOpts = cli.flags['gradleOpts'].split(' ').map(s => s.trim()).filter(Boolean);
|
|
3766
3848
|
}
|
|
3767
3849
|
if (cli.flags['dryRun']) {
|
|
3768
|
-
|
|
3850
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$l);
|
|
3851
|
+
return;
|
|
3769
3852
|
}
|
|
3770
3853
|
await convertGradleToMaven(target, bin, out, verbose, gradleOpts);
|
|
3771
3854
|
}
|
|
@@ -3817,6 +3900,7 @@ async function wrapNpm(argv) {
|
|
|
3817
3900
|
}
|
|
3818
3901
|
|
|
3819
3902
|
const {
|
|
3903
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$k,
|
|
3820
3904
|
NPM: NPM$a
|
|
3821
3905
|
} = constants;
|
|
3822
3906
|
const config$k = {
|
|
@@ -3845,7 +3929,8 @@ async function run$k(argv, importMeta, {
|
|
|
3845
3929
|
parentName
|
|
3846
3930
|
});
|
|
3847
3931
|
if (cli.flags['dryRun']) {
|
|
3848
|
-
|
|
3932
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$k);
|
|
3933
|
+
return;
|
|
3849
3934
|
}
|
|
3850
3935
|
await wrapNpm(argv);
|
|
3851
3936
|
}
|
|
@@ -3861,6 +3946,7 @@ async function wrapNpx(argv) {
|
|
|
3861
3946
|
}
|
|
3862
3947
|
|
|
3863
3948
|
const {
|
|
3949
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$j,
|
|
3864
3950
|
NPX: NPX$1
|
|
3865
3951
|
} = constants;
|
|
3866
3952
|
const config$j = {
|
|
@@ -3889,11 +3975,15 @@ async function run$j(argv, importMeta, {
|
|
|
3889
3975
|
parentName
|
|
3890
3976
|
});
|
|
3891
3977
|
if (cli.flags['dryRun']) {
|
|
3892
|
-
|
|
3978
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$j);
|
|
3979
|
+
return;
|
|
3893
3980
|
}
|
|
3894
3981
|
await wrapNpx(argv);
|
|
3895
3982
|
}
|
|
3896
3983
|
|
|
3984
|
+
const {
|
|
3985
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$i
|
|
3986
|
+
} = constants;
|
|
3897
3987
|
const config$i = {
|
|
3898
3988
|
commandName: 'oops',
|
|
3899
3989
|
description: 'Trigger an intentional error (for development)',
|
|
@@ -3923,7 +4013,8 @@ async function run$i(argv, importMeta, {
|
|
|
3923
4013
|
parentName
|
|
3924
4014
|
});
|
|
3925
4015
|
if (cli.flags['dryRun']) {
|
|
3926
|
-
|
|
4016
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$i);
|
|
4017
|
+
return;
|
|
3927
4018
|
}
|
|
3928
4019
|
throw new Error('This error was intentionally left blank');
|
|
3929
4020
|
}
|
|
@@ -4634,7 +4725,7 @@ function runAgentInstall(agent, agentExecPath, options) {
|
|
|
4634
4725
|
__proto__: null,
|
|
4635
4726
|
...options
|
|
4636
4727
|
};
|
|
4637
|
-
const isSilent = !
|
|
4728
|
+
const isSilent = !debug.isDebug();
|
|
4638
4729
|
const isSpinning = spinner?.isSpinning ?? false;
|
|
4639
4730
|
if (!isSilent) {
|
|
4640
4731
|
spinner?.stop();
|
|
@@ -4682,7 +4773,8 @@ async function updatePackageLockJson(pkgEnvDetails, options) {
|
|
|
4682
4773
|
logger?.log(`💡 Re-run ${COMMAND_TITLE$1} whenever ${pkgEnvDetails.lockName} changes.\n This can be skipped once npm ships ${NPM_OVERRIDE_PR_URL}.`);
|
|
4683
4774
|
}
|
|
4684
4775
|
} catch (e) {
|
|
4685
|
-
spinner?.
|
|
4776
|
+
spinner?.stop();
|
|
4777
|
+
logger?.error(`${COMMAND_TITLE$1}: ${pkgEnvDetails.agent} install failed to update ${pkgEnvDetails.lockName}`);
|
|
4686
4778
|
logger?.error(e);
|
|
4687
4779
|
}
|
|
4688
4780
|
}
|
|
@@ -4695,44 +4787,44 @@ const {
|
|
|
4695
4787
|
const COMMAND_TITLE = 'Socket Optimize';
|
|
4696
4788
|
const manifestNpmOverrides = registry.getManifestData(NPM$1);
|
|
4697
4789
|
async function applyOptimization(cwd, pin, prod) {
|
|
4698
|
-
const logger = console;
|
|
4699
4790
|
const pkgEnvDetails = await detectAndValidatePackageEnvironment(cwd, {
|
|
4700
|
-
logger,
|
|
4791
|
+
logger: logger.logger,
|
|
4701
4792
|
prod
|
|
4702
4793
|
});
|
|
4703
4794
|
if (!pkgEnvDetails) {
|
|
4704
4795
|
return;
|
|
4705
4796
|
}
|
|
4706
|
-
|
|
4707
|
-
|
|
4708
|
-
|
|
4709
|
-
|
|
4797
|
+
// Lazily access constants.spinner.
|
|
4798
|
+
const {
|
|
4799
|
+
spinner
|
|
4800
|
+
} = constants;
|
|
4801
|
+
spinner.start('Socket optimizing...');
|
|
4710
4802
|
const state = await addOverrides(pkgEnvDetails.pkgPath, pkgEnvDetails, {
|
|
4711
|
-
logger,
|
|
4803
|
+
logger: logger.logger,
|
|
4712
4804
|
pin,
|
|
4713
4805
|
prod,
|
|
4714
|
-
spinner
|
|
4806
|
+
spinner
|
|
4715
4807
|
});
|
|
4716
|
-
spinner
|
|
4808
|
+
spinner.stop();
|
|
4717
4809
|
const addedCount = state.added.size;
|
|
4718
4810
|
const updatedCount = state.updated.size;
|
|
4719
4811
|
const pkgJsonChanged = addedCount > 0 || updatedCount > 0;
|
|
4720
4812
|
if (pkgJsonChanged) {
|
|
4721
4813
|
if (updatedCount > 0) {
|
|
4722
|
-
logger?.log(`${createActionMessage('Updated', updatedCount, state.updatedInWorkspaces.size)}${addedCount ? '.' : '🚀'}`);
|
|
4814
|
+
logger.logger?.log(`${createActionMessage('Updated', updatedCount, state.updatedInWorkspaces.size)}${addedCount ? '.' : '🚀'}`);
|
|
4723
4815
|
}
|
|
4724
4816
|
if (addedCount > 0) {
|
|
4725
|
-
logger?.log(`${createActionMessage('Added', addedCount, state.addedInWorkspaces.size)} 🚀`);
|
|
4817
|
+
logger.logger?.log(`${createActionMessage('Added', addedCount, state.addedInWorkspaces.size)} 🚀`);
|
|
4726
4818
|
}
|
|
4727
4819
|
} else {
|
|
4728
|
-
logger?.log('Congratulations! Already Socket.dev optimized 🎉');
|
|
4820
|
+
logger.logger?.log('Congratulations! Already Socket.dev optimized 🎉');
|
|
4729
4821
|
}
|
|
4730
4822
|
if (pkgEnvDetails.agent === NPM$1 || pkgJsonChanged) {
|
|
4731
4823
|
// Always update package-lock.json until the npm overrides PR lands:
|
|
4732
4824
|
// https://github.com/npm/cli/pull/8089
|
|
4733
4825
|
await updatePackageLockJson(pkgEnvDetails, {
|
|
4734
|
-
logger,
|
|
4735
|
-
spinner
|
|
4826
|
+
logger: logger.logger,
|
|
4827
|
+
spinner
|
|
4736
4828
|
});
|
|
4737
4829
|
}
|
|
4738
4830
|
}
|
|
@@ -4918,6 +5010,9 @@ async function addOverrides(pkgPath, pkgEnvDetails, options) {
|
|
|
4918
5010
|
return state;
|
|
4919
5011
|
}
|
|
4920
5012
|
|
|
5013
|
+
const {
|
|
5014
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$h
|
|
5015
|
+
} = constants;
|
|
4921
5016
|
const config$h = {
|
|
4922
5017
|
commandName: 'optimize',
|
|
4923
5018
|
description: 'Optimize dependencies with @socketregistry overrides',
|
|
@@ -4963,7 +5058,8 @@ async function run$h(argv, importMeta, {
|
|
|
4963
5058
|
});
|
|
4964
5059
|
const cwd = process$1.cwd();
|
|
4965
5060
|
if (cli.flags['dryRun']) {
|
|
4966
|
-
|
|
5061
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$h);
|
|
5062
|
+
return;
|
|
4967
5063
|
}
|
|
4968
5064
|
await applyOptimization(cwd, Boolean(cli.flags['pin']), Boolean(cli.flags['prod']));
|
|
4969
5065
|
}
|
|
@@ -4976,21 +5072,24 @@ async function getOrganization(format = 'text') {
|
|
|
4976
5072
|
await printOrganizationsFromToken(apiToken, format);
|
|
4977
5073
|
}
|
|
4978
5074
|
async function printOrganizationsFromToken(apiToken, format = 'text') {
|
|
4979
|
-
|
|
4980
|
-
|
|
5075
|
+
// Lazily access constants.spinner.
|
|
5076
|
+
const {
|
|
5077
|
+
spinner
|
|
5078
|
+
} = constants;
|
|
5079
|
+
spinner.start('Fetching organizations...');
|
|
4981
5080
|
const socketSdk = await index.setupSdk(apiToken);
|
|
4982
5081
|
const result = await handleApiCall(socketSdk.getOrganizations(), 'looking up organizations');
|
|
4983
5082
|
if (!result.success) {
|
|
4984
|
-
handleUnsuccessfulApiResponse('getOrganizations', result, spinner
|
|
5083
|
+
handleUnsuccessfulApiResponse('getOrganizations', result, spinner);
|
|
4985
5084
|
return;
|
|
4986
5085
|
}
|
|
4987
|
-
spinner
|
|
5086
|
+
spinner.stop();
|
|
4988
5087
|
const organizations = Object.values(result.data.organizations);
|
|
4989
5088
|
const lastFiveOfApiToken = getLastFiveOfApiToken(apiToken);
|
|
4990
5089
|
switch (format) {
|
|
4991
5090
|
case 'json':
|
|
4992
5091
|
{
|
|
4993
|
-
|
|
5092
|
+
logger.logger.log(JSON.stringify(organizations.map(o => ({
|
|
4994
5093
|
name: o.name,
|
|
4995
5094
|
id: o.id,
|
|
4996
5095
|
plan: o.plan
|
|
@@ -5011,27 +5110,30 @@ async function printOrganizationsFromToken(apiToken, format = 'text') {
|
|
|
5011
5110
|
mw2 = Math.max(mw2, o.id.length);
|
|
5012
5111
|
mw3 = Math.max(mw3, o.plan.length);
|
|
5013
5112
|
}
|
|
5014
|
-
|
|
5015
|
-
|
|
5016
|
-
|
|
5017
|
-
|
|
5113
|
+
logger.logger.log('# Organizations\n');
|
|
5114
|
+
logger.logger.log(`List of organizations associated with your API key, ending with: ${colors.italic(lastFiveOfApiToken)}\n`);
|
|
5115
|
+
logger.logger.log(`| Name${' '.repeat(mw1 - 4)} | ID${' '.repeat(mw2 - 2)} | Plan${' '.repeat(mw3 - 4)} |`);
|
|
5116
|
+
logger.logger.log(`| ${'-'.repeat(mw1)} | ${'-'.repeat(mw2)} | ${'-'.repeat(mw3)} |`);
|
|
5018
5117
|
for (const o of organizations) {
|
|
5019
|
-
|
|
5118
|
+
logger.logger.log(`| ${(o.name || '').padEnd(mw1, ' ')} | ${(o.id || '').padEnd(mw2, ' ')} | ${(o.plan || '').padEnd(mw3, ' ')} |`);
|
|
5020
5119
|
}
|
|
5021
|
-
|
|
5120
|
+
logger.logger.log(`| ${'-'.repeat(mw1)} | ${'-'.repeat(mw2)} | ${'-'.repeat(mw3)} |`);
|
|
5022
5121
|
return;
|
|
5023
5122
|
}
|
|
5024
5123
|
default:
|
|
5025
5124
|
{
|
|
5026
|
-
|
|
5125
|
+
logger.logger.log(`List of organizations associated with your API key, ending with: ${colors.italic(lastFiveOfApiToken)}\n`);
|
|
5027
5126
|
// Just dump
|
|
5028
5127
|
for (const o of organizations) {
|
|
5029
|
-
|
|
5128
|
+
logger.logger.log(`- Name: ${colors.bold(o.name)}, ID: ${colors.bold(o.id)}, Plan: ${colors.bold(o.plan)}`);
|
|
5030
5129
|
}
|
|
5031
5130
|
}
|
|
5032
5131
|
}
|
|
5033
5132
|
}
|
|
5034
5133
|
|
|
5134
|
+
const {
|
|
5135
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$g
|
|
5136
|
+
} = constants;
|
|
5035
5137
|
const config$g = {
|
|
5036
5138
|
commandName: 'organizations',
|
|
5037
5139
|
description: 'List organizations associated with the API key used',
|
|
@@ -5069,14 +5171,15 @@ async function run$g(argv, importMeta, {
|
|
|
5069
5171
|
// options or missing arguments.
|
|
5070
5172
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
5071
5173
|
process.exitCode = 2;
|
|
5072
|
-
|
|
5174
|
+
logger.logger.error(`
|
|
5073
5175
|
${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
5074
5176
|
- The json and markdown flags cannot be both set, pick one
|
|
5075
5177
|
`);
|
|
5076
5178
|
return;
|
|
5077
5179
|
}
|
|
5078
5180
|
if (cli.flags['dryRun']) {
|
|
5079
|
-
|
|
5181
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$g);
|
|
5182
|
+
return;
|
|
5080
5183
|
}
|
|
5081
5184
|
await getOrganization(json ? 'json' : markdown ? 'markdown' : 'text');
|
|
5082
5185
|
}
|
|
@@ -5104,6 +5207,7 @@ async function runRawNpm(argv) {
|
|
|
5104
5207
|
}
|
|
5105
5208
|
|
|
5106
5209
|
const {
|
|
5210
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$f,
|
|
5107
5211
|
NPM
|
|
5108
5212
|
} = constants;
|
|
5109
5213
|
const config$f = {
|
|
@@ -5138,7 +5242,8 @@ async function run$f(argv, importMeta, {
|
|
|
5138
5242
|
parentName
|
|
5139
5243
|
});
|
|
5140
5244
|
if (cli.flags['dryRun']) {
|
|
5141
|
-
|
|
5245
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$f);
|
|
5246
|
+
return;
|
|
5142
5247
|
}
|
|
5143
5248
|
await runRawNpm(argv);
|
|
5144
5249
|
}
|
|
@@ -5166,6 +5271,7 @@ async function runRawNpx(argv) {
|
|
|
5166
5271
|
}
|
|
5167
5272
|
|
|
5168
5273
|
const {
|
|
5274
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$e,
|
|
5169
5275
|
NPX
|
|
5170
5276
|
} = constants;
|
|
5171
5277
|
const config$e = {
|
|
@@ -5200,18 +5306,26 @@ async function run$e(argv, importMeta, {
|
|
|
5200
5306
|
parentName
|
|
5201
5307
|
});
|
|
5202
5308
|
if (cli.flags['dryRun']) {
|
|
5203
|
-
|
|
5309
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$e);
|
|
5310
|
+
return;
|
|
5204
5311
|
}
|
|
5205
5312
|
await runRawNpx(argv);
|
|
5206
5313
|
}
|
|
5207
5314
|
|
|
5315
|
+
const {
|
|
5316
|
+
DRY_RUN_LABEL
|
|
5317
|
+
} = constants;
|
|
5208
5318
|
async function createReport(socketConfig, inputPaths, {
|
|
5209
5319
|
cwd,
|
|
5210
5320
|
dryRun
|
|
5211
5321
|
}) {
|
|
5322
|
+
// Lazily access constants.spinner.
|
|
5323
|
+
const {
|
|
5324
|
+
spinner
|
|
5325
|
+
} = constants;
|
|
5212
5326
|
const socketSdk = await index.setupSdk();
|
|
5213
5327
|
const supportedFiles = await socketSdk.getReportSupportedFiles().then(res => {
|
|
5214
|
-
if (!res.success) handleUnsuccessfulApiResponse('getReportSupportedFiles', res,
|
|
5328
|
+
if (!res.success) handleUnsuccessfulApiResponse('getReportSupportedFiles', res, spinner);
|
|
5215
5329
|
return res.data;
|
|
5216
5330
|
}).catch(cause => {
|
|
5217
5331
|
throw new Error('Failed getting supported files for report', {
|
|
@@ -5222,24 +5336,23 @@ async function createReport(socketConfig, inputPaths, {
|
|
|
5222
5336
|
const {
|
|
5223
5337
|
length: packagePathsCount
|
|
5224
5338
|
} = packagePaths;
|
|
5225
|
-
if (packagePathsCount &&
|
|
5339
|
+
if (packagePathsCount && debug.isDebug()) {
|
|
5226
5340
|
for (const pkgPath of packagePaths) {
|
|
5227
|
-
|
|
5341
|
+
debug.debugLog(`Uploading: ${pkgPath}`);
|
|
5228
5342
|
}
|
|
5229
5343
|
}
|
|
5230
5344
|
if (dryRun) {
|
|
5231
|
-
|
|
5345
|
+
debug.debugLog(`${DRY_RUN_LABEL}: Skipped actual upload`);
|
|
5232
5346
|
return undefined;
|
|
5233
5347
|
}
|
|
5234
|
-
|
|
5235
|
-
spinner$1.start(`Creating report with ${packagePathsCount} package ${words.pluralize('file', packagePathsCount)}`);
|
|
5348
|
+
spinner.start(`Creating report with ${packagePathsCount} package ${words.pluralize('file', packagePathsCount)}`);
|
|
5236
5349
|
const apiCall = socketSdk.createReportFromFilePaths(packagePaths, cwd, socketConfig?.issueRules);
|
|
5237
5350
|
const result = await handleApiCall(apiCall, 'creating report');
|
|
5238
5351
|
if (!result.success) {
|
|
5239
|
-
handleUnsuccessfulApiResponse('createReport', result, spinner
|
|
5352
|
+
handleUnsuccessfulApiResponse('createReport', result, spinner);
|
|
5240
5353
|
return undefined;
|
|
5241
5354
|
}
|
|
5242
|
-
spinner
|
|
5355
|
+
spinner.successAndStop();
|
|
5243
5356
|
return result;
|
|
5244
5357
|
}
|
|
5245
5358
|
|
|
@@ -5267,8 +5380,11 @@ async function getSocketConfig(absoluteConfigPath) {
|
|
|
5267
5380
|
const MAX_TIMEOUT_RETRY = 5;
|
|
5268
5381
|
const HTTP_CODE_TIMEOUT = 524;
|
|
5269
5382
|
async function fetchReportData(reportId, includeAllIssues, strict) {
|
|
5270
|
-
|
|
5271
|
-
|
|
5383
|
+
// Lazily access constants.spinner.
|
|
5384
|
+
const {
|
|
5385
|
+
spinner
|
|
5386
|
+
} = constants;
|
|
5387
|
+
spinner.start(`Fetching report with ID ${reportId} (this could take a while)`);
|
|
5272
5388
|
const socketSdk = await index.setupSdk();
|
|
5273
5389
|
let result;
|
|
5274
5390
|
for (let retry = 1; !result; ++retry) {
|
|
@@ -5277,43 +5393,43 @@ async function fetchReportData(reportId, includeAllIssues, strict) {
|
|
|
5277
5393
|
result = await handleApiCall(socketSdk.getReport(reportId), 'fetching report');
|
|
5278
5394
|
} catch (err) {
|
|
5279
5395
|
if (retry >= MAX_TIMEOUT_RETRY || !(err instanceof Error) || err.cause?.cause?.response?.statusCode !== HTTP_CODE_TIMEOUT) {
|
|
5280
|
-
spinner
|
|
5396
|
+
spinner.stop();
|
|
5281
5397
|
throw err;
|
|
5282
5398
|
}
|
|
5283
5399
|
}
|
|
5284
5400
|
}
|
|
5285
5401
|
if (!result.success) {
|
|
5286
|
-
return handleUnsuccessfulApiResponse('getReport', result, spinner
|
|
5402
|
+
return handleUnsuccessfulApiResponse('getReport', result, spinner);
|
|
5287
5403
|
}
|
|
5288
5404
|
|
|
5289
5405
|
// Conclude the status of the API call.
|
|
5290
5406
|
if (strict) {
|
|
5291
5407
|
if (result.data.healthy) {
|
|
5292
|
-
spinner
|
|
5408
|
+
spinner.success('Report result is healthy and great!');
|
|
5293
5409
|
} else {
|
|
5294
|
-
spinner
|
|
5410
|
+
spinner.error('Report result deemed unhealthy for project');
|
|
5295
5411
|
}
|
|
5296
5412
|
} else if (!result.data.healthy) {
|
|
5297
5413
|
const severityCount = getSeverityCount(result.data.issues, includeAllIssues ? undefined : 'high');
|
|
5298
5414
|
const issueSummary = formatSeverityCount(severityCount);
|
|
5299
|
-
spinner
|
|
5415
|
+
spinner.success(`Report has these issues: ${issueSummary}`);
|
|
5300
5416
|
} else {
|
|
5301
|
-
spinner
|
|
5417
|
+
spinner.success('Report has no issues');
|
|
5302
5418
|
}
|
|
5303
|
-
spinner
|
|
5419
|
+
spinner.stop();
|
|
5304
5420
|
return result.data;
|
|
5305
5421
|
}
|
|
5306
5422
|
|
|
5307
5423
|
function formatReportDataOutput(reportId, data, commandName, outputJson, outputMarkdown, strict) {
|
|
5308
5424
|
if (outputJson) {
|
|
5309
|
-
|
|
5425
|
+
logger.logger.log(JSON.stringify(data, undefined, 2));
|
|
5310
5426
|
} else {
|
|
5311
5427
|
const format = new index.ColorOrMarkdown(outputMarkdown);
|
|
5312
|
-
|
|
5428
|
+
logger.logger.log('\nDetailed info on socket.dev: ' + format.hyperlink(reportId, data.url, {
|
|
5313
5429
|
fallbackToUrl: true
|
|
5314
5430
|
}));
|
|
5315
5431
|
if (!outputMarkdown) {
|
|
5316
|
-
|
|
5432
|
+
logger.logger.log(colors.dim(`\nOr rerun ${colors.italic(commandName)} using the ${colors.italic('--json')} flag to get full JSON output`));
|
|
5317
5433
|
}
|
|
5318
5434
|
}
|
|
5319
5435
|
if (strict && !data.healthy) {
|
|
@@ -5334,6 +5450,9 @@ async function viewReport(reportId, {
|
|
|
5334
5450
|
}
|
|
5335
5451
|
}
|
|
5336
5452
|
|
|
5453
|
+
const {
|
|
5454
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$d
|
|
5455
|
+
} = constants;
|
|
5337
5456
|
const config$d = {
|
|
5338
5457
|
commandName: 'create',
|
|
5339
5458
|
description: 'Create a project report',
|
|
@@ -5404,7 +5523,8 @@ async function run$d(argv, importMeta, {
|
|
|
5404
5523
|
|
|
5405
5524
|
// Note exiting earlier to skirt a hidden auth requirement
|
|
5406
5525
|
if (cli.flags['dryRun']) {
|
|
5407
|
-
|
|
5526
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$d);
|
|
5527
|
+
return;
|
|
5408
5528
|
}
|
|
5409
5529
|
const socketConfig = await getSocketConfig(absoluteConfigPath);
|
|
5410
5530
|
const result = await createReport(socketConfig, cli.input, {
|
|
@@ -5423,17 +5543,19 @@ async function run$d(argv, importMeta, {
|
|
|
5423
5543
|
strict
|
|
5424
5544
|
});
|
|
5425
5545
|
} else if (json) {
|
|
5426
|
-
|
|
5427
|
-
return;
|
|
5546
|
+
logger.logger.log(JSON.stringify(result.data, undefined, 2));
|
|
5428
5547
|
} else {
|
|
5429
5548
|
const format = new index.ColorOrMarkdown(markdown);
|
|
5430
|
-
|
|
5549
|
+
logger.logger.log(`New report: ${format.hyperlink(result.data.id, result.data.url, {
|
|
5431
5550
|
fallbackToUrl: true
|
|
5432
5551
|
})}`);
|
|
5433
5552
|
}
|
|
5434
5553
|
}
|
|
5435
5554
|
}
|
|
5436
5555
|
|
|
5556
|
+
const {
|
|
5557
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$c
|
|
5558
|
+
} = constants;
|
|
5437
5559
|
const config$c = {
|
|
5438
5560
|
commandName: 'view',
|
|
5439
5561
|
description: 'View a project report',
|
|
@@ -5476,13 +5598,14 @@ async function run$c(argv, importMeta, {
|
|
|
5476
5598
|
// options or missing arguments.
|
|
5477
5599
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
5478
5600
|
process.exitCode = 2;
|
|
5479
|
-
|
|
5601
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
5480
5602
|
- Need at least one report ID ${!reportId ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
5481
5603
|
- Can only handle a single report ID ${extraInput.length < 2 ? colors.red(`(received ${extraInput.length}!)`) : colors.green('(ok)')}\n`);
|
|
5482
5604
|
return;
|
|
5483
5605
|
}
|
|
5484
5606
|
if (cli.flags['dryRun']) {
|
|
5485
|
-
|
|
5607
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$c);
|
|
5608
|
+
return;
|
|
5486
5609
|
}
|
|
5487
5610
|
await viewReport(reportId, {
|
|
5488
5611
|
all: Boolean(cli.flags['all']),
|
|
@@ -5522,8 +5645,11 @@ async function createRepo({
|
|
|
5522
5645
|
repoName,
|
|
5523
5646
|
visibility
|
|
5524
5647
|
}) {
|
|
5525
|
-
|
|
5526
|
-
|
|
5648
|
+
// Lazily access constants.spinner.
|
|
5649
|
+
const {
|
|
5650
|
+
spinner
|
|
5651
|
+
} = constants;
|
|
5652
|
+
spinner.start('Creating repository...');
|
|
5527
5653
|
const socketSdk = await index.setupSdk(apiToken);
|
|
5528
5654
|
const result = await handleApiCall(socketSdk.createOrgRepo(orgSlug, {
|
|
5529
5655
|
outputJson,
|
|
@@ -5536,12 +5662,15 @@ async function createRepo({
|
|
|
5536
5662
|
visibility
|
|
5537
5663
|
}), 'creating repository');
|
|
5538
5664
|
if (result.success) {
|
|
5539
|
-
spinner
|
|
5665
|
+
spinner.successAndStop('Repository created successfully');
|
|
5540
5666
|
} else {
|
|
5541
|
-
handleUnsuccessfulApiResponse('createOrgRepo', result, spinner
|
|
5667
|
+
handleUnsuccessfulApiResponse('createOrgRepo', result, spinner);
|
|
5542
5668
|
}
|
|
5543
5669
|
}
|
|
5544
5670
|
|
|
5671
|
+
const {
|
|
5672
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$b
|
|
5673
|
+
} = constants;
|
|
5545
5674
|
const config$b = {
|
|
5546
5675
|
commandName: 'create',
|
|
5547
5676
|
description: 'Create a repository in an organization',
|
|
@@ -5612,13 +5741,14 @@ async function run$b(argv, importMeta, {
|
|
|
5612
5741
|
// options or missing arguments.
|
|
5613
5742
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
5614
5743
|
process.exitCode = 2;
|
|
5615
|
-
|
|
5744
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
5616
5745
|
- Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
5617
5746
|
- Repository name using --repoName ${!repoName ? colors.red('(missing!)') : typeof repoName !== 'string' ? colors.red('(invalid!)') : colors.green('(ok)')}\n`);
|
|
5618
5747
|
return;
|
|
5619
5748
|
}
|
|
5620
5749
|
if (cli.flags['dryRun']) {
|
|
5621
|
-
|
|
5750
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$b);
|
|
5751
|
+
return;
|
|
5622
5752
|
}
|
|
5623
5753
|
const apiToken = index.getDefaultToken();
|
|
5624
5754
|
if (!apiToken) {
|
|
@@ -5638,17 +5768,23 @@ async function run$b(argv, importMeta, {
|
|
|
5638
5768
|
}
|
|
5639
5769
|
|
|
5640
5770
|
async function deleteRepo(orgSlug, repoName, apiToken) {
|
|
5641
|
-
|
|
5642
|
-
|
|
5771
|
+
// Lazily access constants.spinner.
|
|
5772
|
+
const {
|
|
5773
|
+
spinner
|
|
5774
|
+
} = constants;
|
|
5775
|
+
spinner.start('Deleting repository...');
|
|
5643
5776
|
const socketSdk = await index.setupSdk(apiToken);
|
|
5644
5777
|
const result = await handleApiCall(socketSdk.deleteOrgRepo(orgSlug, repoName), 'deleting repository');
|
|
5645
5778
|
if (result.success) {
|
|
5646
|
-
spinner
|
|
5779
|
+
spinner.successAndStop('Repository deleted successfully');
|
|
5647
5780
|
} else {
|
|
5648
|
-
handleUnsuccessfulApiResponse('deleteOrgRepo', result, spinner
|
|
5781
|
+
handleUnsuccessfulApiResponse('deleteOrgRepo', result, spinner);
|
|
5649
5782
|
}
|
|
5650
5783
|
}
|
|
5651
5784
|
|
|
5785
|
+
const {
|
|
5786
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$a
|
|
5787
|
+
} = constants;
|
|
5652
5788
|
const config$a = {
|
|
5653
5789
|
commandName: 'del',
|
|
5654
5790
|
description: 'Delete a repository in an organization',
|
|
@@ -5687,14 +5823,15 @@ async function run$a(argv, importMeta, {
|
|
|
5687
5823
|
// options or missing arguments.
|
|
5688
5824
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
5689
5825
|
process.exitCode = 2;
|
|
5690
|
-
|
|
5826
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
5691
5827
|
- Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
5692
5828
|
- Repository name as the second argument ${!repoName ? colors.red('(missing!)') : typeof repoName !== 'string' ? colors.red('(invalid!)') : colors.green('(ok)')}\n
|
|
5693
5829
|
- At least one TARGET (e.g. \`.\` or \`./package.json\`\n`);
|
|
5694
5830
|
return;
|
|
5695
5831
|
}
|
|
5696
5832
|
if (cli.flags['dryRun']) {
|
|
5697
|
-
|
|
5833
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$a);
|
|
5834
|
+
return;
|
|
5698
5835
|
}
|
|
5699
5836
|
const apiToken = index.getDefaultToken();
|
|
5700
5837
|
if (!apiToken) {
|
|
@@ -5714,10 +5851,11 @@ async function listRepos({
|
|
|
5714
5851
|
per_page,
|
|
5715
5852
|
sort
|
|
5716
5853
|
}) {
|
|
5717
|
-
|
|
5718
|
-
const
|
|
5719
|
-
|
|
5720
|
-
}
|
|
5854
|
+
// Lazily access constants.spinner.
|
|
5855
|
+
const {
|
|
5856
|
+
spinner
|
|
5857
|
+
} = constants;
|
|
5858
|
+
spinner.start('Listing repositories...');
|
|
5721
5859
|
const socketSdk = await index.setupSdk(apiToken);
|
|
5722
5860
|
const result = await handleApiCall(socketSdk.getOrgRepoList(orgSlug, {
|
|
5723
5861
|
outputJson,
|
|
@@ -5729,10 +5867,10 @@ async function listRepos({
|
|
|
5729
5867
|
page
|
|
5730
5868
|
}), 'listing repositories');
|
|
5731
5869
|
if (!result.success) {
|
|
5732
|
-
handleUnsuccessfulApiResponse('getOrgRepoList', result, spinner
|
|
5870
|
+
handleUnsuccessfulApiResponse('getOrgRepoList', result, spinner);
|
|
5733
5871
|
return;
|
|
5734
5872
|
}
|
|
5735
|
-
spinner
|
|
5873
|
+
spinner.stop();
|
|
5736
5874
|
if (outputJson) {
|
|
5737
5875
|
const data = result.data.results.map(o => ({
|
|
5738
5876
|
id: o.id,
|
|
@@ -5741,7 +5879,7 @@ async function listRepos({
|
|
|
5741
5879
|
defaultBranch: o.default_branch,
|
|
5742
5880
|
archived: o.archived
|
|
5743
5881
|
}));
|
|
5744
|
-
|
|
5882
|
+
logger.logger.log(JSON.stringify(data, null, 2));
|
|
5745
5883
|
return;
|
|
5746
5884
|
}
|
|
5747
5885
|
const options = {
|
|
@@ -5762,9 +5900,12 @@ async function listRepos({
|
|
|
5762
5900
|
name: colors.magenta('Archived')
|
|
5763
5901
|
}]
|
|
5764
5902
|
};
|
|
5765
|
-
|
|
5903
|
+
logger.logger.log(chalkTable(options, result.data.results));
|
|
5766
5904
|
}
|
|
5767
5905
|
|
|
5906
|
+
const {
|
|
5907
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$9
|
|
5908
|
+
} = constants;
|
|
5768
5909
|
const config$9 = {
|
|
5769
5910
|
commandName: 'list',
|
|
5770
5911
|
description: 'List repositories in an organization',
|
|
@@ -5827,13 +5968,14 @@ async function run$9(argv, importMeta, {
|
|
|
5827
5968
|
// options or missing arguments.
|
|
5828
5969
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
5829
5970
|
process.exitCode = 2;
|
|
5830
|
-
|
|
5971
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
5831
5972
|
- Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
5832
5973
|
- At least one TARGET (e.g. \`.\` or \`./package.json\`\n`);
|
|
5833
5974
|
return;
|
|
5834
5975
|
}
|
|
5835
5976
|
if (cli.flags['dryRun']) {
|
|
5836
|
-
|
|
5977
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$9);
|
|
5978
|
+
return;
|
|
5837
5979
|
}
|
|
5838
5980
|
const apiToken = index.getDefaultToken();
|
|
5839
5981
|
if (!apiToken) {
|
|
@@ -5862,10 +6004,11 @@ async function updateRepo({
|
|
|
5862
6004
|
repoName,
|
|
5863
6005
|
visibility
|
|
5864
6006
|
}) {
|
|
5865
|
-
|
|
5866
|
-
const
|
|
5867
|
-
|
|
5868
|
-
}
|
|
6007
|
+
// Lazily access constants.spinner.
|
|
6008
|
+
const {
|
|
6009
|
+
spinner
|
|
6010
|
+
} = constants;
|
|
6011
|
+
spinner.start('Updating repository...');
|
|
5869
6012
|
const socketSdk = await index.setupSdk(apiToken);
|
|
5870
6013
|
const result = await handleApiCall(socketSdk.updateOrgRepo(orgSlug, repoName, {
|
|
5871
6014
|
outputJson,
|
|
@@ -5878,12 +6021,15 @@ async function updateRepo({
|
|
|
5878
6021
|
visibility
|
|
5879
6022
|
}), 'updating repository');
|
|
5880
6023
|
if (result.success) {
|
|
5881
|
-
spinner
|
|
6024
|
+
spinner.successAndStop('Repository updated successfully');
|
|
5882
6025
|
} else {
|
|
5883
|
-
handleUnsuccessfulApiResponse('updateOrgRepo', result, spinner
|
|
6026
|
+
handleUnsuccessfulApiResponse('updateOrgRepo', result, spinner);
|
|
5884
6027
|
}
|
|
5885
6028
|
}
|
|
5886
6029
|
|
|
6030
|
+
const {
|
|
6031
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$8
|
|
6032
|
+
} = constants;
|
|
5887
6033
|
const config$8 = {
|
|
5888
6034
|
commandName: 'update',
|
|
5889
6035
|
description: 'Update a repository in an organization',
|
|
@@ -5954,14 +6100,15 @@ async function run$8(argv, importMeta, {
|
|
|
5954
6100
|
// options or missing arguments.
|
|
5955
6101
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
5956
6102
|
process.exitCode = 2;
|
|
5957
|
-
|
|
6103
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
5958
6104
|
- Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
5959
6105
|
- Repository name using --repoName ${!repoName ? colors.red('(missing!)') : typeof repoName !== 'string' ? colors.red('(invalid!)') : colors.green('(ok)')}\n
|
|
5960
6106
|
- At least one TARGET (e.g. \`.\` or \`./package.json\`\n`);
|
|
5961
6107
|
return;
|
|
5962
6108
|
}
|
|
5963
6109
|
if (cli.flags['dryRun']) {
|
|
5964
|
-
|
|
6110
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$8);
|
|
6111
|
+
return;
|
|
5965
6112
|
}
|
|
5966
6113
|
const apiToken = index.getDefaultToken();
|
|
5967
6114
|
if (!apiToken) {
|
|
@@ -5982,14 +6129,15 @@ async function run$8(argv, importMeta, {
|
|
|
5982
6129
|
|
|
5983
6130
|
// @ts-ignore
|
|
5984
6131
|
async function viewRepo(orgSlug, repoName, apiToken) {
|
|
5985
|
-
|
|
5986
|
-
const
|
|
5987
|
-
|
|
5988
|
-
}
|
|
6132
|
+
// Lazily access constants.spinner.
|
|
6133
|
+
const {
|
|
6134
|
+
spinner
|
|
6135
|
+
} = constants;
|
|
6136
|
+
spinner.start('Fetching repository...');
|
|
5989
6137
|
const socketSdk = await index.setupSdk(apiToken);
|
|
5990
6138
|
const result = await handleApiCall(socketSdk.getOrgRepo(orgSlug, repoName), 'fetching repository');
|
|
5991
6139
|
if (!result.success) {
|
|
5992
|
-
handleUnsuccessfulApiResponse('getOrgRepo', result, spinner
|
|
6140
|
+
handleUnsuccessfulApiResponse('getOrgRepo', result, spinner);
|
|
5993
6141
|
return;
|
|
5994
6142
|
}
|
|
5995
6143
|
const options = {
|
|
@@ -6016,9 +6164,12 @@ async function viewRepo(orgSlug, repoName, apiToken) {
|
|
|
6016
6164
|
name: colors.magenta('Created at')
|
|
6017
6165
|
}]
|
|
6018
6166
|
};
|
|
6019
|
-
spinner
|
|
6167
|
+
spinner.stop(chalkTable(options, [result.data]));
|
|
6020
6168
|
}
|
|
6021
6169
|
|
|
6170
|
+
const {
|
|
6171
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$7
|
|
6172
|
+
} = constants;
|
|
6022
6173
|
const config$7 = {
|
|
6023
6174
|
commandName: 'view',
|
|
6024
6175
|
description: 'View repositories in an organization',
|
|
@@ -6059,13 +6210,14 @@ async function run$7(argv, importMeta, {
|
|
|
6059
6210
|
// options or missing arguments.
|
|
6060
6211
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
6061
6212
|
process.exitCode = 2;
|
|
6062
|
-
|
|
6213
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
6063
6214
|
- Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
6064
6215
|
- Repository name using --repoName ${!repoName ? colors.red('(missing!)') : typeof repoName !== 'string' ? colors.red('(invalid!)') : colors.green('(ok)')}\n`);
|
|
6065
6216
|
return;
|
|
6066
6217
|
}
|
|
6067
6218
|
if (cli.flags['dryRun']) {
|
|
6068
|
-
|
|
6219
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$7);
|
|
6220
|
+
return;
|
|
6069
6221
|
}
|
|
6070
6222
|
const apiToken = index.getDefaultToken();
|
|
6071
6223
|
if (!apiToken) {
|
|
@@ -6252,10 +6404,14 @@ async function createFullScan({
|
|
|
6252
6404
|
targets,
|
|
6253
6405
|
tmp
|
|
6254
6406
|
}) {
|
|
6407
|
+
// Lazily access constants.spinner.
|
|
6408
|
+
const {
|
|
6409
|
+
spinner
|
|
6410
|
+
} = constants;
|
|
6255
6411
|
const socketSdk = await index.setupSdk();
|
|
6256
6412
|
const supportedFiles = await socketSdk.getReportSupportedFiles().then(res => {
|
|
6257
6413
|
if (!res.success) {
|
|
6258
|
-
handleUnsuccessfulApiResponse('getReportSupportedFiles', res,
|
|
6414
|
+
handleUnsuccessfulApiResponse('getReportSupportedFiles', res, spinner);
|
|
6259
6415
|
assert(false, 'handleUnsuccessfulApiResponse should unconditionally throw');
|
|
6260
6416
|
}
|
|
6261
6417
|
return res.data;
|
|
@@ -6312,7 +6468,7 @@ async function createFullScan({
|
|
|
6312
6468
|
// options or missing arguments.
|
|
6313
6469
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
6314
6470
|
process$1.exitCode = 2;
|
|
6315
|
-
|
|
6471
|
+
logger.logger.error(`
|
|
6316
6472
|
${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
6317
6473
|
- Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
6318
6474
|
- Repository name using --repo ${!repoName ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
@@ -6323,22 +6479,19 @@ async function createFullScan({
|
|
|
6323
6479
|
return;
|
|
6324
6480
|
}
|
|
6325
6481
|
if (updatedInput) {
|
|
6326
|
-
|
|
6327
|
-
|
|
6328
|
-
|
|
6329
|
-
|
|
6482
|
+
logger.logger.log('Note: You can invoke this command next time to skip the interactive questions:');
|
|
6483
|
+
logger.logger.log('```');
|
|
6484
|
+
logger.logger.log(` socket scan create [other flags...] --repo ${repoName} --branch ${branchName} ${orgSlug} ${targets.join(' ')}`);
|
|
6485
|
+
logger.logger.log('```');
|
|
6330
6486
|
}
|
|
6331
6487
|
if (!apiToken) {
|
|
6332
6488
|
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.');
|
|
6333
6489
|
}
|
|
6334
6490
|
if (readOnly) {
|
|
6335
|
-
|
|
6491
|
+
logger.logger.log('[ReadOnly] Bailing now');
|
|
6336
6492
|
return;
|
|
6337
6493
|
}
|
|
6338
|
-
|
|
6339
|
-
const spinner$1 = new spinner.Spinner({
|
|
6340
|
-
text: spinnerText
|
|
6341
|
-
}).start();
|
|
6494
|
+
spinner.start('Creating a scan...');
|
|
6342
6495
|
const result = await handleApiCall(socketSdk.createOrgFullScan(orgSlug, {
|
|
6343
6496
|
repo: repoName,
|
|
6344
6497
|
branch: branchName,
|
|
@@ -6348,12 +6501,12 @@ async function createFullScan({
|
|
|
6348
6501
|
tmp
|
|
6349
6502
|
}, packagePaths, cwd), 'Creating scan');
|
|
6350
6503
|
if (!result.success) {
|
|
6351
|
-
handleUnsuccessfulApiResponse('CreateOrgFullScan', result, spinner
|
|
6504
|
+
handleUnsuccessfulApiResponse('CreateOrgFullScan', result, spinner);
|
|
6352
6505
|
return;
|
|
6353
6506
|
}
|
|
6354
|
-
spinner
|
|
6507
|
+
spinner.successAndStop('Scan created successfully');
|
|
6355
6508
|
const link = colors.underline(colors.cyan(`${result.data.html_report_url}`));
|
|
6356
|
-
|
|
6509
|
+
logger.logger.log(`Available at: ${link}`);
|
|
6357
6510
|
const rl = readline.createInterface({
|
|
6358
6511
|
input: process$1.stdin,
|
|
6359
6512
|
output: process$1.stdout
|
|
@@ -6365,6 +6518,9 @@ async function createFullScan({
|
|
|
6365
6518
|
rl.close();
|
|
6366
6519
|
}
|
|
6367
6520
|
|
|
6521
|
+
const {
|
|
6522
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$6
|
|
6523
|
+
} = constants;
|
|
6368
6524
|
const config$6 = {
|
|
6369
6525
|
commandName: 'create',
|
|
6370
6526
|
description: 'Create a scan',
|
|
@@ -6481,7 +6637,7 @@ async function run$6(argv, importMeta, {
|
|
|
6481
6637
|
// options or missing arguments.
|
|
6482
6638
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
6483
6639
|
process$1.exitCode = 2;
|
|
6484
|
-
|
|
6640
|
+
logger.logger.error(`
|
|
6485
6641
|
${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
6486
6642
|
- Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
6487
6643
|
- Repository name using --repo ${!repoName ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
@@ -6494,7 +6650,8 @@ async function run$6(argv, importMeta, {
|
|
|
6494
6650
|
|
|
6495
6651
|
// Note exiting earlier to skirt a hidden auth requirement
|
|
6496
6652
|
if (cli.flags['dryRun']) {
|
|
6497
|
-
|
|
6653
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$6);
|
|
6654
|
+
return;
|
|
6498
6655
|
}
|
|
6499
6656
|
await createFullScan({
|
|
6500
6657
|
branchName: branchName,
|
|
@@ -6514,17 +6671,23 @@ async function run$6(argv, importMeta, {
|
|
|
6514
6671
|
}
|
|
6515
6672
|
|
|
6516
6673
|
async function deleteOrgFullScan(orgSlug, fullScanId, apiToken) {
|
|
6517
|
-
|
|
6518
|
-
|
|
6674
|
+
// Lazily access constants.spinner.
|
|
6675
|
+
const {
|
|
6676
|
+
spinner
|
|
6677
|
+
} = constants;
|
|
6678
|
+
spinner.start('Deleting scan...');
|
|
6519
6679
|
const socketSdk = await index.setupSdk(apiToken);
|
|
6520
6680
|
const result = await handleApiCall(socketSdk.deleteOrgFullScan(orgSlug, fullScanId), 'Deleting scan');
|
|
6521
6681
|
if (!result.success) {
|
|
6522
|
-
handleUnsuccessfulApiResponse('deleteOrgFullScan', result, spinner
|
|
6682
|
+
handleUnsuccessfulApiResponse('deleteOrgFullScan', result, spinner);
|
|
6523
6683
|
return;
|
|
6524
6684
|
}
|
|
6525
|
-
spinner
|
|
6685
|
+
spinner.successAndStop('Scan deleted successfully');
|
|
6526
6686
|
}
|
|
6527
6687
|
|
|
6688
|
+
const {
|
|
6689
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$5
|
|
6690
|
+
} = constants;
|
|
6528
6691
|
const config$5 = {
|
|
6529
6692
|
commandName: 'del',
|
|
6530
6693
|
description: 'Delete a scan',
|
|
@@ -6564,13 +6727,14 @@ async function run$5(argv, importMeta, {
|
|
|
6564
6727
|
// options or missing arguments.
|
|
6565
6728
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
6566
6729
|
process.exitCode = 2;
|
|
6567
|
-
|
|
6730
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
6568
6731
|
- Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
6569
6732
|
- Full Scan ID to delete as second argument ${!fullScanId ? colors.red('(missing!)') : colors.green('(ok)')}\n`);
|
|
6570
6733
|
return;
|
|
6571
6734
|
}
|
|
6572
6735
|
if (cli.flags['dryRun']) {
|
|
6573
|
-
|
|
6736
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$5);
|
|
6737
|
+
return;
|
|
6574
6738
|
}
|
|
6575
6739
|
const apiToken = index.getDefaultToken();
|
|
6576
6740
|
if (!apiToken) {
|
|
@@ -6581,12 +6745,15 @@ async function run$5(argv, importMeta, {
|
|
|
6581
6745
|
|
|
6582
6746
|
// @ts-ignore
|
|
6583
6747
|
async function listFullScans(orgSlug, input, apiToken) {
|
|
6584
|
-
|
|
6585
|
-
|
|
6748
|
+
// Lazily access constants.spinner.
|
|
6749
|
+
const {
|
|
6750
|
+
spinner
|
|
6751
|
+
} = constants;
|
|
6752
|
+
spinner.start('Listing scans...');
|
|
6586
6753
|
const socketSdk = await index.setupSdk(apiToken);
|
|
6587
6754
|
const result = await handleApiCall(socketSdk.getOrgFullScanList(orgSlug, input), 'Listing scans');
|
|
6588
6755
|
if (!result.success) {
|
|
6589
|
-
handleUnsuccessfulApiResponse('getOrgFullScanList', result, spinner
|
|
6756
|
+
handleUnsuccessfulApiResponse('getOrgFullScanList', result, spinner);
|
|
6590
6757
|
return;
|
|
6591
6758
|
}
|
|
6592
6759
|
const options = {
|
|
@@ -6616,10 +6783,13 @@ async function listFullScans(orgSlug, input, apiToken) {
|
|
|
6616
6783
|
branch: d.branch
|
|
6617
6784
|
};
|
|
6618
6785
|
});
|
|
6619
|
-
spinner
|
|
6620
|
-
|
|
6786
|
+
spinner.stop(`Listing scans for: ${orgSlug}`);
|
|
6787
|
+
logger.logger.log(chalkTable(options, formattedResults));
|
|
6621
6788
|
}
|
|
6622
6789
|
|
|
6790
|
+
const {
|
|
6791
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$4
|
|
6792
|
+
} = constants;
|
|
6623
6793
|
const config$4 = {
|
|
6624
6794
|
commandName: 'list',
|
|
6625
6795
|
description: 'List the full scans for an organization',
|
|
@@ -6695,12 +6865,13 @@ async function run$4(argv, importMeta, {
|
|
|
6695
6865
|
// options or missing arguments.
|
|
6696
6866
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
6697
6867
|
process.exitCode = 2;
|
|
6698
|
-
|
|
6868
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
6699
6869
|
- Org name as the argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n`);
|
|
6700
6870
|
return;
|
|
6701
6871
|
}
|
|
6702
6872
|
if (cli.flags['dryRun']) {
|
|
6703
|
-
|
|
6873
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$4);
|
|
6874
|
+
return;
|
|
6704
6875
|
}
|
|
6705
6876
|
const apiToken = index.getDefaultToken();
|
|
6706
6877
|
if (!apiToken) {
|
|
@@ -6722,18 +6893,24 @@ async function run$4(argv, importMeta, {
|
|
|
6722
6893
|
}
|
|
6723
6894
|
|
|
6724
6895
|
async function getOrgScanMetadata(orgSlug, scanId, apiToken) {
|
|
6725
|
-
|
|
6726
|
-
|
|
6896
|
+
// Lazily access constants.spinner.
|
|
6897
|
+
const {
|
|
6898
|
+
spinner
|
|
6899
|
+
} = constants;
|
|
6900
|
+
spinner.start("Getting scan's metadata...");
|
|
6727
6901
|
const socketSdk = await index.setupSdk(apiToken);
|
|
6728
6902
|
const result = await handleApiCall(socketSdk.getOrgFullScanMetadata(orgSlug, scanId), 'Listing scans');
|
|
6729
6903
|
if (!result.success) {
|
|
6730
|
-
handleUnsuccessfulApiResponse('getOrgFullScanMetadata', result, spinner
|
|
6904
|
+
handleUnsuccessfulApiResponse('getOrgFullScanMetadata', result, spinner);
|
|
6731
6905
|
return;
|
|
6732
6906
|
}
|
|
6733
|
-
spinner
|
|
6734
|
-
|
|
6907
|
+
spinner.stop('Scan metadata:');
|
|
6908
|
+
logger.logger.log(result.data);
|
|
6735
6909
|
}
|
|
6736
6910
|
|
|
6911
|
+
const {
|
|
6912
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$3
|
|
6913
|
+
} = constants;
|
|
6737
6914
|
const config$3 = {
|
|
6738
6915
|
commandName: 'metadata',
|
|
6739
6916
|
description: "Get a full scan's metadata",
|
|
@@ -6773,13 +6950,14 @@ async function run$3(argv, importMeta, {
|
|
|
6773
6950
|
// options or missing arguments.
|
|
6774
6951
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
6775
6952
|
process.exitCode = 2;
|
|
6776
|
-
|
|
6953
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
6777
6954
|
- Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
6778
6955
|
- Full Scan ID to inspect as second argument ${!fullScanId ? colors.red('(missing!)') : colors.green('(ok)')}\n`);
|
|
6779
6956
|
return;
|
|
6780
6957
|
}
|
|
6781
6958
|
if (cli.flags['dryRun']) {
|
|
6782
|
-
|
|
6959
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$3);
|
|
6960
|
+
return;
|
|
6783
6961
|
}
|
|
6784
6962
|
const apiToken = index.getDefaultToken();
|
|
6785
6963
|
if (!apiToken) {
|
|
@@ -6789,18 +6967,24 @@ async function run$3(argv, importMeta, {
|
|
|
6789
6967
|
}
|
|
6790
6968
|
|
|
6791
6969
|
async function getFullScan(orgSlug, fullScanId, file, apiToken) {
|
|
6792
|
-
|
|
6793
|
-
|
|
6970
|
+
// Lazily access constants.spinner.
|
|
6971
|
+
const {
|
|
6972
|
+
spinner
|
|
6973
|
+
} = constants;
|
|
6974
|
+
spinner.start('Streaming scan...');
|
|
6794
6975
|
const socketSdk = await index.setupSdk(apiToken);
|
|
6795
6976
|
const data = await handleApiCall(socketSdk.getOrgFullScan(orgSlug, fullScanId, file === '-' ? undefined : file), 'Streaming a scan');
|
|
6796
6977
|
if (data?.success) {
|
|
6797
|
-
spinner
|
|
6978
|
+
spinner.stop(file ? `Full scan details written to ${file}` : '');
|
|
6798
6979
|
} else {
|
|
6799
|
-
handleUnsuccessfulApiResponse('getOrgFullScan', data, spinner
|
|
6980
|
+
handleUnsuccessfulApiResponse('getOrgFullScan', data, spinner);
|
|
6800
6981
|
}
|
|
6801
6982
|
return data;
|
|
6802
6983
|
}
|
|
6803
6984
|
|
|
6985
|
+
const {
|
|
6986
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$2
|
|
6987
|
+
} = constants;
|
|
6804
6988
|
const config$2 = {
|
|
6805
6989
|
commandName: 'stream',
|
|
6806
6990
|
description: 'Stream the output of a scan',
|
|
@@ -6842,13 +7026,14 @@ async function run$2(argv, importMeta, {
|
|
|
6842
7026
|
// options or missing arguments.
|
|
6843
7027
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
6844
7028
|
process.exitCode = 2;
|
|
6845
|
-
|
|
7029
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
6846
7030
|
- Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
6847
7031
|
- Full Scan ID to fetch as second argument ${!fullScanId ? colors.red('(missing!)') : colors.green('(ok)')}\n`);
|
|
6848
7032
|
return;
|
|
6849
7033
|
}
|
|
6850
7034
|
if (cli.flags['dryRun']) {
|
|
6851
|
-
|
|
7035
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$2);
|
|
7036
|
+
return;
|
|
6852
7037
|
}
|
|
6853
7038
|
const apiToken = index.getDefaultToken();
|
|
6854
7039
|
if (!apiToken) {
|
|
@@ -6886,8 +7071,11 @@ async function getThreatFeed({
|
|
|
6886
7071
|
page,
|
|
6887
7072
|
perPage
|
|
6888
7073
|
}) {
|
|
6889
|
-
|
|
6890
|
-
|
|
7074
|
+
// Lazily access constants.spinner.
|
|
7075
|
+
const {
|
|
7076
|
+
spinner
|
|
7077
|
+
} = constants;
|
|
7078
|
+
spinner.start('Looking up the threat feed');
|
|
6891
7079
|
const formattedQueryParams = formatQueryParams({
|
|
6892
7080
|
per_page: perPage,
|
|
6893
7081
|
page,
|
|
@@ -6896,9 +7084,9 @@ async function getThreatFeed({
|
|
|
6896
7084
|
}).join('&');
|
|
6897
7085
|
const response = await queryAPI(`threat-feed?${formattedQueryParams}`, apiToken);
|
|
6898
7086
|
const data = await response.json();
|
|
6899
|
-
spinner
|
|
7087
|
+
spinner.stop();
|
|
6900
7088
|
if (outputJson) {
|
|
6901
|
-
|
|
7089
|
+
logger.logger.log(data);
|
|
6902
7090
|
return;
|
|
6903
7091
|
}
|
|
6904
7092
|
const screen = new ScreenWidget();
|
|
@@ -6953,6 +7141,9 @@ function getMinDiff(start, end) {
|
|
|
6953
7141
|
return Math.floor((end - start) / 60000);
|
|
6954
7142
|
}
|
|
6955
7143
|
|
|
7144
|
+
const {
|
|
7145
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$1
|
|
7146
|
+
} = constants;
|
|
6956
7147
|
const config$1 = {
|
|
6957
7148
|
commandName: 'threat-feed',
|
|
6958
7149
|
description: 'Look up the threat feed',
|
|
@@ -7012,7 +7203,8 @@ async function run$1(argv, importMeta, {
|
|
|
7012
7203
|
parentName
|
|
7013
7204
|
});
|
|
7014
7205
|
if (cli.flags['dryRun']) {
|
|
7015
|
-
|
|
7206
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$1);
|
|
7207
|
+
return;
|
|
7016
7208
|
}
|
|
7017
7209
|
const apiToken = index.getDefaultToken();
|
|
7018
7210
|
if (!apiToken) {
|
|
@@ -7035,7 +7227,7 @@ function addSocketWrapper(file) {
|
|
|
7035
7227
|
}
|
|
7036
7228
|
// TODO: pretty sure you need to source the file or restart
|
|
7037
7229
|
// any terminal session before changes are reflected.
|
|
7038
|
-
|
|
7230
|
+
logger.logger.log(`
|
|
7039
7231
|
The alias was added to ${file}. Running 'npm install' will now be wrapped in Socket's "safe npm" 🎉
|
|
7040
7232
|
If you want to disable it at any time, run \`socket wrapper --disable\`
|
|
7041
7233
|
`);
|
|
@@ -7046,7 +7238,7 @@ function checkSocketWrapperSetup(file) {
|
|
|
7046
7238
|
const fileContent = fs.readFileSync(file, 'utf8');
|
|
7047
7239
|
const linesWithSocketAlias = fileContent.split('\n').filter(l => l === 'alias npm="socket npm"' || l === 'alias npx="socket npx"');
|
|
7048
7240
|
if (linesWithSocketAlias.length) {
|
|
7049
|
-
|
|
7241
|
+
logger.logger.log(`The Socket npm/npx wrapper is set up in your bash profile (${file}).`);
|
|
7050
7242
|
return true;
|
|
7051
7243
|
}
|
|
7052
7244
|
return false;
|
|
@@ -7068,7 +7260,7 @@ function postinstallWrapper() {
|
|
|
7068
7260
|
}
|
|
7069
7261
|
}
|
|
7070
7262
|
function installSafeNpm(query) {
|
|
7071
|
-
|
|
7263
|
+
logger.logger.log(`
|
|
7072
7264
|
_____ _ _
|
|
7073
7265
|
| __|___ ___| |_ ___| |_
|
|
7074
7266
|
|__ | . | _| '_| -_| _|
|
|
@@ -7111,24 +7303,27 @@ function askQuestion(rl, query) {
|
|
|
7111
7303
|
function removeSocketWrapper(file) {
|
|
7112
7304
|
return fs.readFile(file, 'utf8', function (err, data) {
|
|
7113
7305
|
if (err) {
|
|
7114
|
-
|
|
7306
|
+
logger.logger.error('There was an error removing the alias:');
|
|
7307
|
+
logger.logger.error(err);
|
|
7115
7308
|
return;
|
|
7116
7309
|
}
|
|
7117
7310
|
const linesWithoutSocketAlias = data.split('\n').filter(l => l !== 'alias npm="socket npm"' && l !== 'alias npx="socket npx"');
|
|
7118
7311
|
const updatedFileContent = linesWithoutSocketAlias.join('\n');
|
|
7119
7312
|
fs.writeFile(file, updatedFileContent, function (err) {
|
|
7120
7313
|
if (err) {
|
|
7121
|
-
|
|
7314
|
+
logger.logger.error(err);
|
|
7122
7315
|
return;
|
|
7123
|
-
} else {
|
|
7124
|
-
// TODO: pretty sure you need to source the file or restart
|
|
7125
|
-
// any terminal session before changes are reflected.
|
|
7126
|
-
console.log(`\nThe alias was removed from ${file}. Running 'npm install' will now run the standard npm command.\n`);
|
|
7127
7316
|
}
|
|
7317
|
+
// TODO: pretty sure you need to source the file or restart
|
|
7318
|
+
// any terminal session before changes are reflected.
|
|
7319
|
+
logger.logger.log(`The alias was removed from ${file}. Running 'npm install' will now run the standard npm command.`);
|
|
7128
7320
|
});
|
|
7129
7321
|
});
|
|
7130
7322
|
}
|
|
7131
7323
|
|
|
7324
|
+
const {
|
|
7325
|
+
DRY_RUN_BAIL_TEXT
|
|
7326
|
+
} = constants;
|
|
7132
7327
|
const config = {
|
|
7133
7328
|
commandName: 'wrapper',
|
|
7134
7329
|
description: 'Enable or disable the Socket npm/npx wrapper',
|
|
@@ -7185,12 +7380,13 @@ async function run(argv, importMeta, {
|
|
|
7185
7380
|
// options or missing arguments.
|
|
7186
7381
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
7187
7382
|
process.exitCode = 2;
|
|
7188
|
-
|
|
7383
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required flags:\n
|
|
7189
7384
|
- Must use --enabled or --disabled\n`);
|
|
7190
7385
|
return;
|
|
7191
7386
|
}
|
|
7192
7387
|
if (cli.flags['dryRun']) {
|
|
7193
|
-
|
|
7388
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT);
|
|
7389
|
+
return;
|
|
7194
7390
|
}
|
|
7195
7391
|
|
|
7196
7392
|
// Lazily access constants.bashRcPath and constants.zshRcPath.
|
|
@@ -7214,7 +7410,7 @@ async function run(argv, importMeta, {
|
|
|
7214
7410
|
}
|
|
7215
7411
|
}
|
|
7216
7412
|
if (!fs.existsSync(bashRcPath) && !fs.existsSync(zshRcPath)) {
|
|
7217
|
-
|
|
7413
|
+
logger.logger.error('There was an issue setting up the alias in your bash profile');
|
|
7218
7414
|
}
|
|
7219
7415
|
}
|
|
7220
7416
|
|
|
@@ -7289,10 +7485,10 @@ void (async () => {
|
|
|
7289
7485
|
}
|
|
7290
7486
|
logger.logger.error(`${colors.bgRed(colors.white(errorTitle + ':'))} ${errorMessage}`);
|
|
7291
7487
|
if (errorBody) {
|
|
7292
|
-
|
|
7488
|
+
logger.logger.error(`\n${errorBody}`);
|
|
7293
7489
|
}
|
|
7294
7490
|
await index.captureException(e);
|
|
7295
7491
|
}
|
|
7296
7492
|
})();
|
|
7297
|
-
//# debugId=
|
|
7493
|
+
//# debugId=9ba118ee-ceb1-4f74-9334-3ae81bcb81f3
|
|
7298
7494
|
//# sourceMappingURL=cli.js.map
|