@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/require/cli.js
CHANGED
|
@@ -24,13 +24,12 @@ var fs = require('node:fs');
|
|
|
24
24
|
var path = require('node:path');
|
|
25
25
|
var ndjson = _socketInterop(require('ndjson'));
|
|
26
26
|
var index = require('./index.js');
|
|
27
|
+
var constants = require('./constants.js');
|
|
27
28
|
var objects = require('@socketsecurity/registry/lib/objects');
|
|
28
29
|
var regexps = require('@socketsecurity/registry/lib/regexps');
|
|
29
|
-
var constants = require('./constants.js');
|
|
30
30
|
var fs$1 = require('node:fs/promises');
|
|
31
31
|
var ScreenWidget = _socketInterop(require('blessed/lib/widgets/screen'));
|
|
32
32
|
var contrib = _socketInterop(require('blessed-contrib'));
|
|
33
|
-
var spinner = require('@socketsecurity/registry/lib/spinner');
|
|
34
33
|
var prompts = require('@socketsecurity/registry/lib/prompts');
|
|
35
34
|
var yargsParse = _socketInterop(require('yargs-parser'));
|
|
36
35
|
var words = require('@socketsecurity/registry/lib/words');
|
|
@@ -53,8 +52,9 @@ var index_cjs = require('@socketregistry/hyrious__bun.lockb/index.cjs');
|
|
|
53
52
|
var sorts = require('@socketsecurity/registry/lib/sorts');
|
|
54
53
|
var strings = require('@socketsecurity/registry/lib/strings');
|
|
55
54
|
var yaml = _socketInterop(require('yaml'));
|
|
56
|
-
var
|
|
55
|
+
var debug = require('@socketsecurity/registry/lib/debug');
|
|
57
56
|
var npm$1 = require('./npm.js');
|
|
57
|
+
var npmPaths = require('./npm-paths.js');
|
|
58
58
|
var betterAjvErrors = _socketInterop(require('@apideck/better-ajv-errors'));
|
|
59
59
|
var config$A = require('@socketsecurity/config');
|
|
60
60
|
var assert = require('node:assert');
|
|
@@ -264,7 +264,6 @@ class Score {
|
|
|
264
264
|
}
|
|
265
265
|
|
|
266
266
|
// https://github.com/SocketDev/socket-python-cli/blob/6d4fc56faee68d3a4764f1f80f84710635bdaf05/socketsecurity/core/__init__.py
|
|
267
|
-
/* eslint-disable no-await-in-loop */
|
|
268
267
|
class Core {
|
|
269
268
|
securityPolicy = {};
|
|
270
269
|
constructor({
|
|
@@ -559,6 +558,7 @@ class Core {
|
|
|
559
558
|
diff.newPackages.push(purl);
|
|
560
559
|
consolidated.add(basePurl);
|
|
561
560
|
}
|
|
561
|
+
// eslint-disable-next-line no-await-in-loop
|
|
562
562
|
newScanAlerts = await this.createIssueAlerts({
|
|
563
563
|
pkg,
|
|
564
564
|
alerts: newScanAlerts,
|
|
@@ -576,6 +576,7 @@ class Core {
|
|
|
576
576
|
if (!(packageId in newPackages) && pkg.direct) {
|
|
577
577
|
diff.removedPackages.push(purl);
|
|
578
578
|
}
|
|
579
|
+
// eslint-disable-next-line no-await-in-loop
|
|
579
580
|
headScanAlerts = await this.createIssueAlerts({
|
|
580
581
|
pkg,
|
|
581
582
|
alerts: headScanAlerts,
|
|
@@ -641,7 +642,7 @@ class Core {
|
|
|
641
642
|
license: sbomArtifact.license
|
|
642
643
|
});
|
|
643
644
|
if (pkg.id in packages) {
|
|
644
|
-
|
|
645
|
+
logger.logger.log('Duplicate package?');
|
|
645
646
|
} else {
|
|
646
647
|
pkg = this.getLicenseDetails({
|
|
647
648
|
package: pkg
|
|
@@ -681,8 +682,8 @@ class Core {
|
|
|
681
682
|
});
|
|
682
683
|
}
|
|
683
684
|
}
|
|
684
|
-
} catch (
|
|
685
|
-
|
|
685
|
+
} catch (e) {
|
|
686
|
+
logger.logger.error(e);
|
|
686
687
|
}
|
|
687
688
|
const newFullScan = await this.createFullScan({
|
|
688
689
|
params
|
|
@@ -706,7 +707,6 @@ class Core {
|
|
|
706
707
|
}
|
|
707
708
|
|
|
708
709
|
// https://github.com/SocketDev/socket-python-cli/blob/6d4fc56faee68d3a4764f1f80f84710635bdaf05/socketsecurity/core/scm_comments.py
|
|
709
|
-
|
|
710
710
|
function checkForSocketComments({
|
|
711
711
|
comments
|
|
712
712
|
}) {
|
|
@@ -836,9 +836,9 @@ function getIgnoreOptions({
|
|
|
836
836
|
const data = `${name}/${version}`;
|
|
837
837
|
ignoreCommands.push(data);
|
|
838
838
|
}
|
|
839
|
-
} catch (
|
|
840
|
-
|
|
841
|
-
|
|
839
|
+
} catch (e) {
|
|
840
|
+
logger.logger.error(`Unable to process ignore command for ${comment}`);
|
|
841
|
+
logger.logger.error(e);
|
|
842
842
|
}
|
|
843
843
|
}
|
|
844
844
|
}
|
|
@@ -869,9 +869,9 @@ function removeAlerts({
|
|
|
869
869
|
const purl = `${fullName}/${alert.pkg_version}`;
|
|
870
870
|
const purlStar = `${fullName}/*`;
|
|
871
871
|
if (ignoreCommands.includes(purl) || ignoreCommands.includes(purlStar)) {
|
|
872
|
-
|
|
872
|
+
logger.logger.log(`Alerts for ${alert.pkg_name}@${alert.pkg_version} ignored`);
|
|
873
873
|
} else {
|
|
874
|
-
|
|
874
|
+
logger.logger.log(`Adding alert ${alert.type} for ${alert.pkg_name}@${alert.pkg_version}`);
|
|
875
875
|
alerts.push(alert);
|
|
876
876
|
}
|
|
877
877
|
}
|
|
@@ -909,7 +909,7 @@ class GitHub {
|
|
|
909
909
|
if (['opened', 'synchronize'].includes(eventAction)) {
|
|
910
910
|
return 'diff';
|
|
911
911
|
} else {
|
|
912
|
-
|
|
912
|
+
logger.logger.log(`Pull request action: ${eventAction} is not supported`);
|
|
913
913
|
process.exit();
|
|
914
914
|
}
|
|
915
915
|
case 'issue_comment':
|
|
@@ -1024,30 +1024,30 @@ class GitHub {
|
|
|
1024
1024
|
security: existingSecurityComment
|
|
1025
1025
|
} = comments;
|
|
1026
1026
|
if (newOverviewComment) {
|
|
1027
|
-
|
|
1027
|
+
logger.logger.log('New Dependency Overview comment');
|
|
1028
1028
|
if (existingOverviewComment !== undefined) {
|
|
1029
|
-
|
|
1029
|
+
logger.logger.log('Previous version of Dependency Overview, updating');
|
|
1030
1030
|
await this.updateComment({
|
|
1031
1031
|
body: overviewComment,
|
|
1032
1032
|
id: existingOverviewComment.id
|
|
1033
1033
|
});
|
|
1034
1034
|
} else {
|
|
1035
|
-
|
|
1035
|
+
logger.logger.log('No previous version of Dependency Overview, posting');
|
|
1036
1036
|
await this.postComment({
|
|
1037
1037
|
body: overviewComment
|
|
1038
1038
|
});
|
|
1039
1039
|
}
|
|
1040
1040
|
}
|
|
1041
1041
|
if (newSecurityComment) {
|
|
1042
|
-
|
|
1042
|
+
logger.logger.log('New Security Issue Comment');
|
|
1043
1043
|
if (existingSecurityComment !== undefined) {
|
|
1044
|
-
|
|
1044
|
+
logger.logger.log('Previous version of Security Issue comment, updating');
|
|
1045
1045
|
await this.updateComment({
|
|
1046
1046
|
body: securityComment,
|
|
1047
1047
|
id: existingSecurityComment.id
|
|
1048
1048
|
});
|
|
1049
1049
|
} else {
|
|
1050
|
-
|
|
1050
|
+
logger.logger.log('No Previous version of Security Issue comment, posting');
|
|
1051
1051
|
await this.postComment({
|
|
1052
1052
|
body: securityComment
|
|
1053
1053
|
});
|
|
@@ -1226,7 +1226,7 @@ async function runAction(githubEventBefore, githubEventAfter) {
|
|
|
1226
1226
|
const socket = new sdk.SocketSdk(index.getDefaultToken());
|
|
1227
1227
|
const git = simpleGit.simpleGit();
|
|
1228
1228
|
const changedFiles = (await git.diff(process.env['GITHUB_EVENT_NAME'] === 'pull_request' ? ['--name-only', 'HEAD^1', 'HEAD'] : ['--name-only', githubEventBefore, githubEventAfter])).split('\n');
|
|
1229
|
-
|
|
1229
|
+
logger.logger.log({
|
|
1230
1230
|
changedFiles
|
|
1231
1231
|
});
|
|
1232
1232
|
// supportedFiles have 3-level deep globs
|
|
@@ -1234,13 +1234,13 @@ async function runAction(githubEventBefore, githubEventAfter) {
|
|
|
1234
1234
|
const files = micromatch(changedFiles, patterns);
|
|
1235
1235
|
const scm = new GitHub();
|
|
1236
1236
|
if (scm.checkEventType() === 'comment') {
|
|
1237
|
-
|
|
1237
|
+
logger.logger.log('Comment initiated flow');
|
|
1238
1238
|
const comments = await scm.getCommentsForPR();
|
|
1239
1239
|
await scm.removeCommentAlerts({
|
|
1240
1240
|
comments
|
|
1241
1241
|
});
|
|
1242
1242
|
} else if (scm.checkEventType() === 'diff') {
|
|
1243
|
-
|
|
1243
|
+
logger.logger.log('Push initiated flow');
|
|
1244
1244
|
const core = new Core({
|
|
1245
1245
|
owner: scm.owner,
|
|
1246
1246
|
repo: scm.repo,
|
|
@@ -1262,17 +1262,17 @@ async function runAction(githubEventBefore, githubEventAfter) {
|
|
|
1262
1262
|
if (diff.newAlerts.length === 0) {
|
|
1263
1263
|
if (!updateOldSecurityComment) {
|
|
1264
1264
|
newSecurityComment = false;
|
|
1265
|
-
|
|
1265
|
+
logger.logger.log('No new alerts or security issue comment disabled');
|
|
1266
1266
|
} else {
|
|
1267
|
-
|
|
1267
|
+
logger.logger.log('Updated security comment with no new alerts');
|
|
1268
1268
|
}
|
|
1269
1269
|
}
|
|
1270
1270
|
if (diff.newPackages.length === 0 && diff.removedPackages.length === 0) {
|
|
1271
1271
|
if (!updateOldOverviewComment) {
|
|
1272
1272
|
newOverviewComment = false;
|
|
1273
|
-
|
|
1273
|
+
logger.logger.log('No new/removed packages or Dependency Overview comment disabled');
|
|
1274
1274
|
} else {
|
|
1275
|
-
|
|
1275
|
+
logger.logger.log('Updated overview comment with no dependencies');
|
|
1276
1276
|
}
|
|
1277
1277
|
}
|
|
1278
1278
|
await scm.addSocketComments({
|
|
@@ -1400,6 +1400,8 @@ const validationFlags = {
|
|
|
1400
1400
|
};
|
|
1401
1401
|
|
|
1402
1402
|
const {
|
|
1403
|
+
DRY_RUN_LABEL: DRY_RUN_LABEL$1,
|
|
1404
|
+
REDACTED,
|
|
1403
1405
|
SOCKET_CLI_SHOW_BANNER
|
|
1404
1406
|
} = constants;
|
|
1405
1407
|
async function meowWithSubcommands(subcommands, options) {
|
|
@@ -1437,7 +1439,7 @@ async function meowWithSubcommands(subcommands, options) {
|
|
|
1437
1439
|
// Temp disable until we clear the --json and --markdown usage
|
|
1438
1440
|
// Lazily access constants.ENV[SOCKET_CLI_SHOW_BANNER].
|
|
1439
1441
|
if (constants.ENV[SOCKET_CLI_SHOW_BANNER]) {
|
|
1440
|
-
|
|
1442
|
+
logger.logger.log(getAsciiHeader(name));
|
|
1441
1443
|
}
|
|
1442
1444
|
const cli = vendor.meow(`
|
|
1443
1445
|
Usage
|
|
@@ -1473,7 +1475,7 @@ async function meowWithSubcommands(subcommands, options) {
|
|
|
1473
1475
|
autoHelp: false // otherwise we can't exit(0)
|
|
1474
1476
|
});
|
|
1475
1477
|
if (!cli.flags['help'] && cli.flags['dryRun']) {
|
|
1476
|
-
|
|
1478
|
+
logger.logger.log(`${DRY_RUN_LABEL$1}: No-op, call a sub-command; ok`);
|
|
1477
1479
|
process.exitCode = 0;
|
|
1478
1480
|
} else {
|
|
1479
1481
|
cli.showHelp();
|
|
@@ -1495,7 +1497,7 @@ function meowOrExit({
|
|
|
1495
1497
|
// Temp disable until we clear the --json and --markdown usage.
|
|
1496
1498
|
// Lazily access constants.ENV[SOCKET_CLI_SHOW_BANNER].
|
|
1497
1499
|
if (constants.ENV[SOCKET_CLI_SHOW_BANNER]) {
|
|
1498
|
-
|
|
1500
|
+
logger.logger.log(getAsciiHeader(command));
|
|
1499
1501
|
}
|
|
1500
1502
|
|
|
1501
1503
|
// This exits if .printHelp() is called either by meow itself or by us.
|
|
@@ -1515,7 +1517,7 @@ function meowOrExit({
|
|
|
1515
1517
|
}
|
|
1516
1518
|
function getAsciiHeader(command) {
|
|
1517
1519
|
const cliVersion = // The '@rollup/plugin-replace' will replace "process.env['SOCKET_CLI_VERSION_HASH']".
|
|
1518
|
-
"0.14.
|
|
1520
|
+
"0.14.52:709a145:a30d9dfd:pub";
|
|
1519
1521
|
const nodeVersion = process.version;
|
|
1520
1522
|
const apiToken = index.getSetting('apiToken');
|
|
1521
1523
|
const shownToken = apiToken ? getLastFiveOfApiToken(apiToken) : 'no';
|
|
@@ -1530,6 +1532,9 @@ function getAsciiHeader(command) {
|
|
|
1530
1532
|
|
|
1531
1533
|
// https://github.com/SocketDev/socket-python-cli/blob/6d4fc56faee68d3a4764f1f80f84710635bdaf05/socketsecurity/socketcli.py
|
|
1532
1534
|
|
|
1535
|
+
const {
|
|
1536
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$y
|
|
1537
|
+
} = constants;
|
|
1533
1538
|
const config$z = {
|
|
1534
1539
|
commandName: 'action',
|
|
1535
1540
|
description: 'Socket action command',
|
|
@@ -1580,7 +1585,8 @@ async function run$z(argv, importMeta, {
|
|
|
1580
1585
|
const githubEventBefore = String(cli.flags['githubEventBefore'] || '');
|
|
1581
1586
|
const githubEventAfter = String(cli.flags['githubEventAfter'] || '');
|
|
1582
1587
|
if (cli.flags['dryRun']) {
|
|
1583
|
-
|
|
1588
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$y);
|
|
1589
|
+
return;
|
|
1584
1590
|
}
|
|
1585
1591
|
await runAction(githubEventBefore, githubEventAfter);
|
|
1586
1592
|
}
|
|
@@ -1598,24 +1604,26 @@ async function displayAnalytics({
|
|
|
1598
1604
|
scope,
|
|
1599
1605
|
time
|
|
1600
1606
|
}) {
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1607
|
+
// Lazily access constants.spinner.
|
|
1608
|
+
const {
|
|
1609
|
+
spinner
|
|
1610
|
+
} = constants;
|
|
1611
|
+
spinner.start('Fetching analytics data');
|
|
1604
1612
|
let data;
|
|
1605
1613
|
if (scope === 'org') {
|
|
1606
|
-
data = await fetchOrgAnalyticsData(time, spinner
|
|
1614
|
+
data = await fetchOrgAnalyticsData(time, spinner, apiToken);
|
|
1607
1615
|
} else if (repo) {
|
|
1608
|
-
data = await fetchRepoAnalyticsData(repo, time, spinner
|
|
1616
|
+
data = await fetchRepoAnalyticsData(repo, time, spinner, apiToken);
|
|
1609
1617
|
}
|
|
1610
1618
|
if (data) {
|
|
1611
1619
|
if (outputJson && !filePath) {
|
|
1612
|
-
|
|
1620
|
+
logger.logger.log(data);
|
|
1613
1621
|
} else if (filePath) {
|
|
1614
1622
|
try {
|
|
1615
1623
|
await fs$1.writeFile(filePath, JSON.stringify(data), 'utf8');
|
|
1616
|
-
|
|
1624
|
+
logger.logger.log(`Data successfully written to ${filePath}`);
|
|
1617
1625
|
} catch (e) {
|
|
1618
|
-
|
|
1626
|
+
logger.logger.error(e);
|
|
1619
1627
|
}
|
|
1620
1628
|
} else {
|
|
1621
1629
|
const fdata = scope === 'org' ? formatData(data, 'org') : formatData(data, 'repo');
|
|
@@ -1664,7 +1672,7 @@ async function fetchOrgAnalyticsData(time, spinner, apiToken) {
|
|
|
1664
1672
|
}
|
|
1665
1673
|
spinner.stop();
|
|
1666
1674
|
if (!result.data.length) {
|
|
1667
|
-
|
|
1675
|
+
logger.logger.log('No analytics data is available for this organization yet.');
|
|
1668
1676
|
return undefined;
|
|
1669
1677
|
}
|
|
1670
1678
|
return result.data;
|
|
@@ -1678,7 +1686,7 @@ async function fetchRepoAnalyticsData(repo, time, spinner, apiToken) {
|
|
|
1678
1686
|
}
|
|
1679
1687
|
spinner.stop();
|
|
1680
1688
|
if (!result.data.length) {
|
|
1681
|
-
|
|
1689
|
+
logger.logger.log('No analytics data is available for this organization yet.');
|
|
1682
1690
|
return undefined;
|
|
1683
1691
|
}
|
|
1684
1692
|
return result.data;
|
|
@@ -1774,6 +1782,9 @@ function renderLineCharts(grid, screen, title, coords, data) {
|
|
|
1774
1782
|
line.setData([lineData]);
|
|
1775
1783
|
}
|
|
1776
1784
|
|
|
1785
|
+
const {
|
|
1786
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$x
|
|
1787
|
+
} = constants;
|
|
1777
1788
|
const config$y = {
|
|
1778
1789
|
commandName: 'analytics',
|
|
1779
1790
|
description: `Look up analytics data`,
|
|
@@ -1851,14 +1862,15 @@ async function run$y(argv, importMeta, {
|
|
|
1851
1862
|
// options or missing arguments.
|
|
1852
1863
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
1853
1864
|
process.exitCode = 2;
|
|
1854
|
-
|
|
1865
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
1855
1866
|
- Scope must be "repo" or "org" ${badScope ? colors.red('(bad!)') : colors.green('(ok)')}\n
|
|
1856
1867
|
- The time filter must either be 7, 30 or 90 ${badTime ? colors.red('(bad!)') : colors.green('(ok)')}\n
|
|
1857
1868
|
- Repository name using --repo when scope is "repo" ${badRepo ? colors.red('(bad!)') : colors.green('(ok)')}\n`);
|
|
1858
1869
|
return;
|
|
1859
1870
|
}
|
|
1860
1871
|
if (cli.flags['dryRun']) {
|
|
1861
|
-
|
|
1872
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$x);
|
|
1873
|
+
return;
|
|
1862
1874
|
}
|
|
1863
1875
|
const apiToken = index.getDefaultToken();
|
|
1864
1876
|
if (!apiToken) {
|
|
@@ -1883,9 +1895,11 @@ async function getAuditLog({
|
|
|
1883
1895
|
perPage,
|
|
1884
1896
|
type
|
|
1885
1897
|
}) {
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1898
|
+
// Lazily access constants.spinner.
|
|
1899
|
+
const {
|
|
1900
|
+
spinner
|
|
1901
|
+
} = constants;
|
|
1902
|
+
spinner.start(`Looking up audit log for ${orgSlug}`);
|
|
1889
1903
|
const socketSdk = await index.setupSdk(apiToken);
|
|
1890
1904
|
const result = await handleApiCall(socketSdk.getAuditLogEvents(orgSlug, {
|
|
1891
1905
|
outputJson,
|
|
@@ -1896,10 +1910,10 @@ async function getAuditLog({
|
|
|
1896
1910
|
per_page: perPage
|
|
1897
1911
|
}), `Looking up audit log for ${orgSlug}\n`);
|
|
1898
1912
|
if (!result.success) {
|
|
1899
|
-
handleUnsuccessfulApiResponse('getAuditLogEvents', result, spinner
|
|
1913
|
+
handleUnsuccessfulApiResponse('getAuditLogEvents', result, spinner);
|
|
1900
1914
|
return;
|
|
1901
1915
|
}
|
|
1902
|
-
spinner
|
|
1916
|
+
spinner.stop();
|
|
1903
1917
|
const data = [];
|
|
1904
1918
|
const logDetails = {};
|
|
1905
1919
|
for (const d of result.data.results) {
|
|
@@ -1918,13 +1932,16 @@ async function getAuditLog({
|
|
|
1918
1932
|
logDetails[name] = JSON.stringify(d.payload);
|
|
1919
1933
|
}
|
|
1920
1934
|
}
|
|
1921
|
-
|
|
1935
|
+
logger.logger.log(logDetails[await prompts.select({
|
|
1922
1936
|
message: type ? `\n Audit log for: ${orgSlug} with type: ${type}\n` : `\n Audit log for: ${orgSlug}\n`,
|
|
1923
1937
|
choices: data,
|
|
1924
1938
|
pageSize: 30
|
|
1925
1939
|
})]);
|
|
1926
1940
|
}
|
|
1927
1941
|
|
|
1942
|
+
const {
|
|
1943
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$w
|
|
1944
|
+
} = constants;
|
|
1928
1945
|
const config$x = {
|
|
1929
1946
|
commandName: 'audit-log',
|
|
1930
1947
|
description: 'Look up the audit log for an organization',
|
|
@@ -1983,12 +2000,13 @@ async function run$x(argv, importMeta, {
|
|
|
1983
2000
|
// options or missing arguments.
|
|
1984
2001
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
1985
2002
|
process.exitCode = 2;
|
|
1986
|
-
|
|
2003
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
1987
2004
|
- Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n`);
|
|
1988
2005
|
return;
|
|
1989
2006
|
}
|
|
1990
2007
|
if (cli.flags['dryRun']) {
|
|
1991
|
-
|
|
2008
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$w);
|
|
2009
|
+
return;
|
|
1992
2010
|
}
|
|
1993
2011
|
const apiToken = index.getDefaultToken();
|
|
1994
2012
|
if (!apiToken) {
|
|
@@ -2050,7 +2068,7 @@ async function runCycloneDX(yargv) {
|
|
|
2050
2068
|
}
|
|
2051
2069
|
const fullOutputPath = path.join(process$1.cwd(), yargv.output);
|
|
2052
2070
|
if (fs.existsSync(fullOutputPath)) {
|
|
2053
|
-
|
|
2071
|
+
logger.logger.log(colors.cyanBright(`${yargv.output} created!`));
|
|
2054
2072
|
}
|
|
2055
2073
|
}
|
|
2056
2074
|
function argvToArray(argv) {
|
|
@@ -2080,6 +2098,10 @@ function argvToArray(argv) {
|
|
|
2080
2098
|
}
|
|
2081
2099
|
|
|
2082
2100
|
// import { meowOrExit } from '../../utils/meow-with-subcommands'
|
|
2101
|
+
const {
|
|
2102
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$v
|
|
2103
|
+
} = constants;
|
|
2104
|
+
|
|
2083
2105
|
// TODO: convert yargs to meow. Or convert all the other things to yargs.
|
|
2084
2106
|
const toLower = arg => arg.toLowerCase();
|
|
2085
2107
|
const arrayToLower = arg => arg.map(toLower);
|
|
@@ -2184,7 +2206,7 @@ async function run$w(argv, importMeta, {
|
|
|
2184
2206
|
//
|
|
2185
2207
|
//
|
|
2186
2208
|
// if (cli.input.length)
|
|
2187
|
-
//
|
|
2209
|
+
// logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
2188
2210
|
// - Unexpected arguments\n
|
|
2189
2211
|
// `)
|
|
2190
2212
|
// config.help(parentName, config)
|
|
@@ -2205,14 +2227,15 @@ async function run$w(argv, importMeta, {
|
|
|
2205
2227
|
// options or missing arguments.
|
|
2206
2228
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
2207
2229
|
process$1.exitCode = 2;
|
|
2208
|
-
|
|
2230
|
+
logger.logger.error(`Unknown ${words.pluralize('argument', unknownLength)}: ${yargv._.join(', ')}`);
|
|
2209
2231
|
return;
|
|
2210
2232
|
}
|
|
2211
2233
|
if (yargv.output === undefined) {
|
|
2212
2234
|
yargv.output = 'socket-cdx.json';
|
|
2213
2235
|
}
|
|
2214
2236
|
if (cli.flags['dryRun']) {
|
|
2215
|
-
|
|
2237
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$v);
|
|
2238
|
+
return;
|
|
2216
2239
|
}
|
|
2217
2240
|
await runCycloneDX(yargv);
|
|
2218
2241
|
}
|
|
@@ -2227,21 +2250,23 @@ async function findDependencies({
|
|
|
2227
2250
|
if (!apiToken) {
|
|
2228
2251
|
throw new index.AuthError('User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.');
|
|
2229
2252
|
}
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2253
|
+
// Lazily access constants.spinner.
|
|
2254
|
+
const {
|
|
2255
|
+
spinner
|
|
2256
|
+
} = constants;
|
|
2257
|
+
spinner.start('Searching dependencies...');
|
|
2233
2258
|
const socketSdk = await index.setupSdk(apiToken);
|
|
2234
2259
|
const result = await handleApiCall(socketSdk.searchDependencies({
|
|
2235
2260
|
limit,
|
|
2236
2261
|
offset
|
|
2237
2262
|
}), 'Searching dependencies');
|
|
2238
2263
|
if (!result.success) {
|
|
2239
|
-
handleUnsuccessfulApiResponse('searchDependencies', result, spinner
|
|
2264
|
+
handleUnsuccessfulApiResponse('searchDependencies', result, spinner);
|
|
2240
2265
|
return;
|
|
2241
2266
|
}
|
|
2242
|
-
spinner
|
|
2267
|
+
spinner.stop('Organization dependencies:');
|
|
2243
2268
|
if (outputJson) {
|
|
2244
|
-
|
|
2269
|
+
logger.logger.log(result.data);
|
|
2245
2270
|
return;
|
|
2246
2271
|
}
|
|
2247
2272
|
const options = {
|
|
@@ -2268,9 +2293,12 @@ async function findDependencies({
|
|
|
2268
2293
|
name: colors.cyan('Direct')
|
|
2269
2294
|
}]
|
|
2270
2295
|
};
|
|
2271
|
-
|
|
2296
|
+
logger.logger.log(chalkTable(options, result.data.rows));
|
|
2272
2297
|
}
|
|
2273
2298
|
|
|
2299
|
+
const {
|
|
2300
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$u
|
|
2301
|
+
} = constants;
|
|
2274
2302
|
const config$v = {
|
|
2275
2303
|
commandName: 'dependencies',
|
|
2276
2304
|
description: 'Search for any dependency that is being used in your organization',
|
|
@@ -2317,7 +2345,8 @@ async function run$v(argv, importMeta, {
|
|
|
2317
2345
|
parentName
|
|
2318
2346
|
});
|
|
2319
2347
|
if (cli.flags['dryRun']) {
|
|
2320
|
-
|
|
2348
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$u);
|
|
2349
|
+
return;
|
|
2321
2350
|
}
|
|
2322
2351
|
|
|
2323
2352
|
// TODO: markdown flag is ignored
|
|
@@ -2335,38 +2364,44 @@ async function getDiffScan({
|
|
|
2335
2364
|
orgSlug,
|
|
2336
2365
|
outputJson
|
|
2337
2366
|
}, apiToken) {
|
|
2338
|
-
|
|
2339
|
-
|
|
2367
|
+
// Lazily access constants.spinner.
|
|
2368
|
+
const {
|
|
2369
|
+
spinner
|
|
2370
|
+
} = constants;
|
|
2371
|
+
spinner.start('Getting diff scan...');
|
|
2340
2372
|
const response = await queryAPI(`${orgSlug}/full-scans/diff?before=${before}&after=${after}&preview`, apiToken);
|
|
2341
2373
|
const data = await response.json();
|
|
2342
2374
|
if (!response.ok) {
|
|
2343
2375
|
const err = await handleAPIError(response.status);
|
|
2344
|
-
spinner
|
|
2376
|
+
spinner.errorAndStop(`${colors.bgRed(colors.white(response.statusText))}: ${err}`);
|
|
2345
2377
|
return;
|
|
2346
2378
|
}
|
|
2347
|
-
spinner
|
|
2379
|
+
spinner.stop();
|
|
2348
2380
|
if (file && !outputJson) {
|
|
2349
2381
|
fs.writeFile(file, JSON.stringify(data), err => {
|
|
2350
|
-
err ?
|
|
2382
|
+
err ? logger.logger.error(err) : logger.logger.log(`Data successfully written to ${file}`);
|
|
2351
2383
|
});
|
|
2352
2384
|
return;
|
|
2353
2385
|
}
|
|
2354
2386
|
if (outputJson) {
|
|
2355
|
-
|
|
2356
|
-
|
|
2387
|
+
logger.logger.log(`\n Diff scan result: \n`);
|
|
2388
|
+
logger.logger.log(require$$0$1.inspect(data, {
|
|
2357
2389
|
showHidden: false,
|
|
2358
2390
|
depth: null,
|
|
2359
2391
|
colors: true
|
|
2360
2392
|
}));
|
|
2361
|
-
|
|
2393
|
+
logger.logger.log(`\n View this diff scan in the Socket dashboard: ${colors.cyan(data?.['diff_report_url'])}`);
|
|
2362
2394
|
return;
|
|
2363
2395
|
}
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2396
|
+
logger.logger.log('Diff scan result:');
|
|
2397
|
+
logger.logger.log(data);
|
|
2398
|
+
logger.logger.log(`\n 📝 To display the detailed report in the terminal, use the --json flag \n`);
|
|
2399
|
+
logger.logger.log(`\n View this diff scan in the Socket dashboard: ${colors.cyan(data?.['diff_report_url'])}`);
|
|
2368
2400
|
}
|
|
2369
2401
|
|
|
2402
|
+
const {
|
|
2403
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$t
|
|
2404
|
+
} = constants;
|
|
2370
2405
|
const config$u = {
|
|
2371
2406
|
commandName: 'get',
|
|
2372
2407
|
description: 'Get a diff scan for an organization',
|
|
@@ -2432,14 +2467,15 @@ async function run$u(argv, importMeta, {
|
|
|
2432
2467
|
// options or missing arguments.
|
|
2433
2468
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
2434
2469
|
process.exitCode = 2;
|
|
2435
|
-
|
|
2470
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
2436
2471
|
- Specify a before and after full scan ID ${!before && !after ? colors.red('(missing before and after!)') : !before ? colors.red('(missing before!)') : !after ? colors.red('(missing after!)') : colors.green('(ok)')}\n
|
|
2437
2472
|
- To get full scans IDs, you can run the command "socket scan list <your org slug>".
|
|
2438
2473
|
- Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n`);
|
|
2439
2474
|
return;
|
|
2440
2475
|
}
|
|
2441
2476
|
if (cli.flags['dryRun']) {
|
|
2442
|
-
|
|
2477
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$t);
|
|
2478
|
+
return;
|
|
2443
2479
|
}
|
|
2444
2480
|
const apiToken = index.getDefaultToken();
|
|
2445
2481
|
if (!apiToken) {
|
|
@@ -2482,7 +2518,11 @@ function isTopLevel(tree, node) {
|
|
|
2482
2518
|
return tree.children.get(node.name) === node;
|
|
2483
2519
|
}
|
|
2484
2520
|
async function runFix() {
|
|
2485
|
-
|
|
2521
|
+
// Lazily access constants.spinner.
|
|
2522
|
+
const {
|
|
2523
|
+
spinner
|
|
2524
|
+
} = constants;
|
|
2525
|
+
spinner.start();
|
|
2486
2526
|
const cwd = process.cwd();
|
|
2487
2527
|
const editablePkgJson = await packages.readPackageJson(cwd, {
|
|
2488
2528
|
editable: true
|
|
@@ -2513,7 +2553,7 @@ async function runFix() {
|
|
|
2513
2553
|
const tree = arb.idealTree;
|
|
2514
2554
|
const hasUpgrade = !!registry.getManifestData(NPM$d, name);
|
|
2515
2555
|
if (hasUpgrade) {
|
|
2516
|
-
spinner
|
|
2556
|
+
spinner.info(`Skipping ${name}. Socket Optimize package exists.`);
|
|
2517
2557
|
continue;
|
|
2518
2558
|
}
|
|
2519
2559
|
const nodes = index.findPackageNodes(tree, name);
|
|
@@ -2539,10 +2579,10 @@ async function runFix() {
|
|
|
2539
2579
|
try {
|
|
2540
2580
|
// eslint-disable-next-line no-await-in-loop
|
|
2541
2581
|
await npm.runScript('test', [], {
|
|
2542
|
-
spinner
|
|
2582
|
+
spinner,
|
|
2543
2583
|
stdio: 'ignore'
|
|
2544
2584
|
});
|
|
2545
|
-
spinner
|
|
2585
|
+
spinner.info(`Patched ${name} ${oldVersion} -> ${node.version}`);
|
|
2546
2586
|
if (isTopLevel(tree, node)) {
|
|
2547
2587
|
for (const depField of ['dependencies', 'optionalDependencies', 'peerDependencies']) {
|
|
2548
2588
|
const oldVersion = editablePkgJson.content[depField]?.[name];
|
|
@@ -2555,11 +2595,11 @@ async function runFix() {
|
|
|
2555
2595
|
// eslint-disable-next-line no-await-in-loop
|
|
2556
2596
|
await editablePkgJson.save();
|
|
2557
2597
|
} catch {
|
|
2558
|
-
spinner
|
|
2598
|
+
spinner.error(`Reverting ${name} to ${oldVersion}`);
|
|
2559
2599
|
arb.idealTree = revertToIdealTree;
|
|
2560
2600
|
}
|
|
2561
2601
|
} else {
|
|
2562
|
-
spinner
|
|
2602
|
+
spinner.error(`Could not patch ${name} ${oldVersion}`);
|
|
2563
2603
|
}
|
|
2564
2604
|
}
|
|
2565
2605
|
}
|
|
@@ -2571,9 +2611,12 @@ async function runFix() {
|
|
|
2571
2611
|
});
|
|
2572
2612
|
arb2.idealTree = arb.idealTree;
|
|
2573
2613
|
await arb2.reify();
|
|
2574
|
-
spinner
|
|
2614
|
+
spinner.stop();
|
|
2575
2615
|
}
|
|
2576
2616
|
|
|
2617
|
+
const {
|
|
2618
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$s
|
|
2619
|
+
} = constants;
|
|
2577
2620
|
const config$t = {
|
|
2578
2621
|
commandName: 'fix',
|
|
2579
2622
|
description: 'Fix "fixable" Socket alerts',
|
|
@@ -2604,7 +2647,8 @@ async function run$t(argv, importMeta, {
|
|
|
2604
2647
|
parentName
|
|
2605
2648
|
});
|
|
2606
2649
|
if (cli.flags['dryRun']) {
|
|
2607
|
-
|
|
2650
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$s);
|
|
2651
|
+
return;
|
|
2608
2652
|
}
|
|
2609
2653
|
await runFix();
|
|
2610
2654
|
}
|
|
@@ -2716,9 +2760,9 @@ function formatPackageInfo({
|
|
|
2716
2760
|
strict
|
|
2717
2761
|
}, spinner) {
|
|
2718
2762
|
if (outputJson) {
|
|
2719
|
-
|
|
2763
|
+
logger.logger.log(JSON.stringify(data, undefined, 2));
|
|
2720
2764
|
} else {
|
|
2721
|
-
|
|
2765
|
+
logger.logger.log('\nPackage report card:');
|
|
2722
2766
|
const scoreResult = {
|
|
2723
2767
|
'Supply Chain Risk': Math.floor(score.supplyChainRisk.score * 100),
|
|
2724
2768
|
Maintenance: Math.floor(score.maintenance.score * 100),
|
|
@@ -2726,8 +2770,8 @@ function formatPackageInfo({
|
|
|
2726
2770
|
Vulnerabilities: Math.floor(score.vulnerability.score * 100),
|
|
2727
2771
|
License: Math.floor(score.license.score * 100)
|
|
2728
2772
|
};
|
|
2729
|
-
Object.entries(scoreResult).map(score =>
|
|
2730
|
-
|
|
2773
|
+
Object.entries(scoreResult).map(score => logger.logger.log(`- ${score[0]}: ${formatScore(score[1])}`));
|
|
2774
|
+
logger.logger.log('\n');
|
|
2731
2775
|
if (objectSome(severityCount)) {
|
|
2732
2776
|
spinner[strict ? 'error' : 'success'](`Package has these issues: ${formatSeverityCount(severityCount)}`);
|
|
2733
2777
|
formatPackageIssuesDetails(data, outputMarkdown);
|
|
@@ -2736,18 +2780,18 @@ function formatPackageInfo({
|
|
|
2736
2780
|
}
|
|
2737
2781
|
const format = new index.ColorOrMarkdown(!!outputMarkdown);
|
|
2738
2782
|
const url = index.getSocketDevPackageOverviewUrl(NPM$c, pkgName, pkgVersion);
|
|
2739
|
-
|
|
2783
|
+
logger.logger.log('\n');
|
|
2740
2784
|
if (pkgVersion === 'latest') {
|
|
2741
|
-
|
|
2785
|
+
logger.logger.log(`Detailed info on socket.dev: ${format.hyperlink(`${pkgName}`, url, {
|
|
2742
2786
|
fallbackToUrl: true
|
|
2743
2787
|
})}`);
|
|
2744
2788
|
} else {
|
|
2745
|
-
|
|
2789
|
+
logger.logger.log(`Detailed info on socket.dev: ${format.hyperlink(`${pkgName} v${pkgVersion}`, url, {
|
|
2746
2790
|
fallbackToUrl: true
|
|
2747
2791
|
})}`);
|
|
2748
2792
|
}
|
|
2749
2793
|
if (!outputMarkdown) {
|
|
2750
|
-
|
|
2794
|
+
logger.logger.log(colors.dim(`\nOr rerun ${colors.italic(name)} using the ${colors.italic('--json')} flag to get full JSON output`));
|
|
2751
2795
|
}
|
|
2752
2796
|
}
|
|
2753
2797
|
if (strict && objectSome(severityCount)) {
|
|
@@ -2778,9 +2822,9 @@ function formatPackageIssuesDetails(packageData, outputMarkdown) {
|
|
|
2778
2822
|
fallbackToUrl: true
|
|
2779
2823
|
});
|
|
2780
2824
|
if (uniqueIssues[issue]?.count === 1) {
|
|
2781
|
-
|
|
2825
|
+
logger.logger.log(`- ${issueWithLink}`);
|
|
2782
2826
|
} else {
|
|
2783
|
-
|
|
2827
|
+
logger.logger.log(`- ${issueWithLink}: ${uniqueIssues[issue]?.count}`);
|
|
2784
2828
|
}
|
|
2785
2829
|
}
|
|
2786
2830
|
}
|
|
@@ -2802,11 +2846,12 @@ async function getPackageInfo({
|
|
|
2802
2846
|
pkgVersion,
|
|
2803
2847
|
strict
|
|
2804
2848
|
}) {
|
|
2805
|
-
|
|
2806
|
-
const
|
|
2807
|
-
|
|
2808
|
-
}
|
|
2809
|
-
|
|
2849
|
+
// Lazily access constants.spinner.
|
|
2850
|
+
const {
|
|
2851
|
+
spinner
|
|
2852
|
+
} = constants;
|
|
2853
|
+
spinner.start(pkgVersion === 'latest' ? `Looking up data for the latest version of ${pkgName}` : `Looking up data for version ${pkgVersion} of ${pkgName}`);
|
|
2854
|
+
const packageData = await fetchPackageInfo(pkgName, pkgVersion, includeAllIssues, spinner);
|
|
2810
2855
|
if (packageData) {
|
|
2811
2856
|
formatPackageInfo(packageData, {
|
|
2812
2857
|
name: commandName,
|
|
@@ -2815,10 +2860,13 @@ async function getPackageInfo({
|
|
|
2815
2860
|
pkgName,
|
|
2816
2861
|
pkgVersion,
|
|
2817
2862
|
strict
|
|
2818
|
-
}, spinner
|
|
2863
|
+
}, spinner);
|
|
2819
2864
|
}
|
|
2820
2865
|
}
|
|
2821
2866
|
|
|
2867
|
+
const {
|
|
2868
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$r
|
|
2869
|
+
} = constants;
|
|
2822
2870
|
const config$s = {
|
|
2823
2871
|
commandName: 'info',
|
|
2824
2872
|
description: 'Look up info regarding a package',
|
|
@@ -2860,7 +2908,7 @@ async function run$s(argv, importMeta, {
|
|
|
2860
2908
|
// options or missing arguments.
|
|
2861
2909
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
2862
2910
|
process.exitCode = 2;
|
|
2863
|
-
|
|
2911
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
2864
2912
|
- Expecting a package name ${!rawPkgName ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
2865
2913
|
- Can only accept one package at a time ${cli.input.length > 1 ? colors.red('(got ' + cli.input.length + '!)') : colors.green('(ok)')}\n`);
|
|
2866
2914
|
return;
|
|
@@ -2869,7 +2917,8 @@ async function run$s(argv, importMeta, {
|
|
|
2869
2917
|
const pkgName = versionSeparator < 1 ? rawPkgName : rawPkgName.slice(0, versionSeparator);
|
|
2870
2918
|
const pkgVersion = versionSeparator < 1 ? 'latest' : rawPkgName.slice(versionSeparator + 1);
|
|
2871
2919
|
if (cli.flags['dryRun']) {
|
|
2872
|
-
|
|
2920
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$r);
|
|
2921
|
+
return;
|
|
2873
2922
|
}
|
|
2874
2923
|
await getPackageInfo({
|
|
2875
2924
|
commandName: `${parentName} ${config$s.commandName}`,
|
|
@@ -2895,13 +2944,16 @@ const {
|
|
|
2895
2944
|
SOCKET_PUBLIC_API_TOKEN
|
|
2896
2945
|
} = constants;
|
|
2897
2946
|
async function attemptLogin(apiBaseUrl, apiProxy) {
|
|
2947
|
+
apiBaseUrl ??= index.getSetting('apiBaseUrl') ?? undefined;
|
|
2948
|
+
apiProxy ??= index.getSetting('apiProxy') ?? undefined;
|
|
2898
2949
|
const apiToken = (await prompts.password({
|
|
2899
2950
|
message: `Enter your ${terminalLink('Socket.dev API key', 'https://docs.socket.dev/docs/api-keys')} (leave blank for a public key)`
|
|
2900
2951
|
})) || SOCKET_PUBLIC_API_TOKEN;
|
|
2901
|
-
|
|
2902
|
-
|
|
2903
|
-
|
|
2904
|
-
|
|
2952
|
+
// Lazily access constants.spinner.
|
|
2953
|
+
const {
|
|
2954
|
+
spinner
|
|
2955
|
+
} = constants;
|
|
2956
|
+
spinner.start('Verifying API key...');
|
|
2905
2957
|
let orgs;
|
|
2906
2958
|
try {
|
|
2907
2959
|
const sdk = await index.setupSdk(apiToken, apiBaseUrl, apiProxy);
|
|
@@ -2910,9 +2962,9 @@ async function attemptLogin(apiBaseUrl, apiProxy) {
|
|
|
2910
2962
|
throw new index.AuthError();
|
|
2911
2963
|
}
|
|
2912
2964
|
orgs = result.data;
|
|
2913
|
-
spinner
|
|
2965
|
+
spinner.success('API key verified');
|
|
2914
2966
|
} catch {
|
|
2915
|
-
spinner
|
|
2967
|
+
spinner.errorAndStop('Invalid API key');
|
|
2916
2968
|
return;
|
|
2917
2969
|
}
|
|
2918
2970
|
const enforcedChoices = Object.values(orgs.organizations).filter(org => org?.plan === 'enterprise').map(org => ({
|
|
@@ -2929,7 +2981,7 @@ async function attemptLogin(apiBaseUrl, apiProxy) {
|
|
|
2929
2981
|
description: 'Pick "None" if this is a personal device'
|
|
2930
2982
|
})
|
|
2931
2983
|
}, {
|
|
2932
|
-
spinner
|
|
2984
|
+
spinner
|
|
2933
2985
|
});
|
|
2934
2986
|
if (id) {
|
|
2935
2987
|
enforcedOrgs = [id];
|
|
@@ -2939,7 +2991,7 @@ async function attemptLogin(apiBaseUrl, apiProxy) {
|
|
|
2939
2991
|
message: `Should Socket enforce ${enforcedChoices[0]?.name}'s security policies system-wide?`,
|
|
2940
2992
|
default: true
|
|
2941
2993
|
}, {
|
|
2942
|
-
spinner
|
|
2994
|
+
spinner
|
|
2943
2995
|
});
|
|
2944
2996
|
if (confirmOrg) {
|
|
2945
2997
|
const existing = enforcedChoices[0];
|
|
@@ -2951,12 +3003,15 @@ async function attemptLogin(apiBaseUrl, apiProxy) {
|
|
|
2951
3003
|
const oldToken = index.getSetting('apiToken');
|
|
2952
3004
|
try {
|
|
2953
3005
|
applyLogin(apiToken, enforcedOrgs, apiBaseUrl, apiProxy);
|
|
2954
|
-
spinner
|
|
3006
|
+
spinner.successAndStop(`API credentials ${oldToken ? 'updated' : 'set'}`);
|
|
2955
3007
|
} catch {
|
|
2956
|
-
spinner
|
|
3008
|
+
spinner.errorAndStop(`API login failed`);
|
|
2957
3009
|
}
|
|
2958
3010
|
}
|
|
2959
3011
|
|
|
3012
|
+
const {
|
|
3013
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$q
|
|
3014
|
+
} = constants;
|
|
2960
3015
|
const config$r = {
|
|
2961
3016
|
commandName: 'login',
|
|
2962
3017
|
description: 'Socket API login',
|
|
@@ -3003,7 +3058,8 @@ async function run$r(argv, importMeta, {
|
|
|
3003
3058
|
let apiBaseUrl = cli.flags['apiBaseUrl'];
|
|
3004
3059
|
let apiProxy = cli.flags['apiProxy'];
|
|
3005
3060
|
if (cli.flags['dryRun']) {
|
|
3006
|
-
|
|
3061
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$q);
|
|
3062
|
+
return;
|
|
3007
3063
|
}
|
|
3008
3064
|
if (!isInteractive()) {
|
|
3009
3065
|
throw new index.InputError('Cannot prompt for credentials in a non-interactive shell');
|
|
@@ -3027,6 +3083,9 @@ function attemptLogout() {
|
|
|
3027
3083
|
}
|
|
3028
3084
|
}
|
|
3029
3085
|
|
|
3086
|
+
const {
|
|
3087
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$p
|
|
3088
|
+
} = constants;
|
|
3030
3089
|
const config$q = {
|
|
3031
3090
|
commandName: 'logout',
|
|
3032
3091
|
description: 'Socket API logout',
|
|
@@ -3056,31 +3115,31 @@ async function run$q(argv, importMeta, {
|
|
|
3056
3115
|
parentName
|
|
3057
3116
|
});
|
|
3058
3117
|
if (cli.flags['dryRun']) {
|
|
3059
|
-
|
|
3118
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$p);
|
|
3119
|
+
return;
|
|
3060
3120
|
}
|
|
3061
3121
|
attemptLogout();
|
|
3062
3122
|
}
|
|
3063
3123
|
|
|
3064
3124
|
async function convertGradleToMaven(target, bin, _out, verbose, gradleOpts) {
|
|
3125
|
+
// Lazily access constants.spinner.
|
|
3126
|
+
const {
|
|
3127
|
+
spinner
|
|
3128
|
+
} = constants;
|
|
3065
3129
|
const rbin = path.resolve(bin);
|
|
3066
3130
|
const rtarget = path.resolve(target);
|
|
3067
|
-
// const rout = out === '-' ? '-' : path.resolve(out)
|
|
3068
|
-
|
|
3069
3131
|
if (verbose) {
|
|
3070
|
-
|
|
3071
|
-
|
|
3072
|
-
|
|
3073
|
-
|
|
3074
|
-
console.groupEnd();
|
|
3132
|
+
logger.logger.group('gradle2maven:');
|
|
3133
|
+
logger.logger.log(`[VERBOSE] - Absolute bin path: \`${rbin}\``);
|
|
3134
|
+
logger.logger.log(`[VERBOSE] - Absolute target path: \`${rtarget}\``);
|
|
3135
|
+
logger.logger.groupEnd();
|
|
3075
3136
|
} else {
|
|
3076
|
-
|
|
3077
|
-
|
|
3078
|
-
|
|
3079
|
-
|
|
3080
|
-
|
|
3081
|
-
}
|
|
3082
|
-
const spinner$1 = new spinner.Spinner();
|
|
3083
|
-
spinner$1.start(`Converting gradle to maven from \`${bin}\` on \`${target}\`...`);
|
|
3137
|
+
logger.logger.group('gradle2maven:');
|
|
3138
|
+
logger.logger.log(`- executing: \`${bin}\``);
|
|
3139
|
+
logger.logger.log(`- src dir: \`${target}\``);
|
|
3140
|
+
logger.logger.groupEnd();
|
|
3141
|
+
}
|
|
3142
|
+
spinner.start(`Converting gradle to maven from \`${bin}\` on \`${target}\`...`);
|
|
3084
3143
|
try {
|
|
3085
3144
|
// Run sbt with the init script we provide which should yield zero or more pom files.
|
|
3086
3145
|
// We have to figure out where to store those pom files such that we can upload them and predict them through the GitHub API.
|
|
@@ -3090,36 +3149,37 @@ async function convertGradleToMaven(target, bin, _out, verbose, gradleOpts) {
|
|
|
3090
3149
|
const initLocation = path.join(constants.rootDistPath, 'init.gradle');
|
|
3091
3150
|
const commandArgs = ['--init-script', initLocation, ...gradleOpts, 'pom'];
|
|
3092
3151
|
if (verbose) {
|
|
3093
|
-
spinner
|
|
3152
|
+
spinner.log('[VERBOSE] Executing:', bin, commandArgs);
|
|
3094
3153
|
}
|
|
3095
3154
|
const output = await spawn(bin, commandArgs, {
|
|
3096
3155
|
cwd: target || '.'
|
|
3097
3156
|
});
|
|
3157
|
+
spinner.stop();
|
|
3098
3158
|
if (verbose) {
|
|
3099
|
-
|
|
3100
|
-
|
|
3101
|
-
|
|
3159
|
+
logger.logger.group('[VERBOSE] gradle stdout:');
|
|
3160
|
+
logger.logger.log(output);
|
|
3161
|
+
logger.logger.groupEnd();
|
|
3102
3162
|
}
|
|
3103
3163
|
if (output.stderr) {
|
|
3104
|
-
|
|
3164
|
+
logger.logger.error('There were errors while running gradle');
|
|
3105
3165
|
// (In verbose mode, stderr was printed above, no need to repeat it)
|
|
3106
3166
|
if (!verbose) {
|
|
3107
|
-
|
|
3108
|
-
|
|
3109
|
-
|
|
3167
|
+
logger.logger.group('[VERBOSE] stderr:');
|
|
3168
|
+
logger.logger.error(output.stderr);
|
|
3169
|
+
logger.logger.groupEnd();
|
|
3110
3170
|
}
|
|
3111
3171
|
process.exit(1);
|
|
3112
3172
|
}
|
|
3113
|
-
|
|
3114
|
-
|
|
3173
|
+
logger.logger.success('Executed gradle successfully');
|
|
3174
|
+
logger.logger.log('Reported exports:');
|
|
3115
3175
|
output.stdout.replace(/^POM file copied to: (.*)/gm, (_all, fn) => {
|
|
3116
|
-
|
|
3176
|
+
logger.logger.log('- ', fn);
|
|
3117
3177
|
return fn;
|
|
3118
3178
|
});
|
|
3119
3179
|
|
|
3120
3180
|
// const loc = output.stdout?.match(/Wrote (.*?.pom)\n/)?.[1]?.trim()
|
|
3121
3181
|
// if (!loc) {
|
|
3122
|
-
//
|
|
3182
|
+
// logger.error(
|
|
3123
3183
|
// 'There were no errors from sbt but could not find the location of resulting .pom file either'
|
|
3124
3184
|
// )
|
|
3125
3185
|
// process.exit(1)
|
|
@@ -3128,8 +3188,8 @@ async function convertGradleToMaven(target, bin, _out, verbose, gradleOpts) {
|
|
|
3128
3188
|
// // Move the pom file to ...? initial cwd? loc will be an absolute path, or dump to stdout
|
|
3129
3189
|
// if (out === '-') {
|
|
3130
3190
|
// spinner.start('Result:\n```')
|
|
3131
|
-
//
|
|
3132
|
-
//
|
|
3191
|
+
// spinner.log(await safeReadFile(loc, 'utf8'))
|
|
3192
|
+
// spinner.log('```')
|
|
3133
3193
|
// spinner.successAndStop(`OK`)
|
|
3134
3194
|
// } else {
|
|
3135
3195
|
// spinner.start()
|
|
@@ -3145,16 +3205,20 @@ async function convertGradleToMaven(target, bin, _out, verbose, gradleOpts) {
|
|
|
3145
3205
|
// spinner.successAndStop(`OK. File should be available in \`${out}\``)
|
|
3146
3206
|
// }
|
|
3147
3207
|
} catch (e) {
|
|
3148
|
-
spinner
|
|
3208
|
+
spinner.stop();
|
|
3209
|
+
logger.logger.error('There was an unexpected error while running this' + (verbose ? '' : ' (use --verbose for details)'));
|
|
3149
3210
|
if (verbose) {
|
|
3150
|
-
|
|
3151
|
-
|
|
3152
|
-
|
|
3211
|
+
logger.logger.group('[VERBOSE] error:');
|
|
3212
|
+
logger.logger.log(e);
|
|
3213
|
+
logger.logger.groupEnd();
|
|
3153
3214
|
}
|
|
3154
3215
|
process.exit(1);
|
|
3155
3216
|
}
|
|
3156
3217
|
}
|
|
3157
3218
|
|
|
3219
|
+
const {
|
|
3220
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$o
|
|
3221
|
+
} = constants;
|
|
3158
3222
|
const config$p = {
|
|
3159
3223
|
commandName: 'gradle',
|
|
3160
3224
|
description: '[beta] Use Gradle to generate a manifest file (`pom.xml`) for a Gradle/Java/Kotlin/etc project',
|
|
@@ -3242,22 +3306,23 @@ async function run$p(argv, importMeta, {
|
|
|
3242
3306
|
});
|
|
3243
3307
|
const verbose = Boolean(cli.flags['verbose']);
|
|
3244
3308
|
if (verbose) {
|
|
3245
|
-
|
|
3246
|
-
|
|
3247
|
-
|
|
3248
|
-
|
|
3249
|
-
|
|
3309
|
+
logger.logger.group('- ', parentName, config$p.commandName, ':');
|
|
3310
|
+
logger.logger.group('- flags:', cli.flags);
|
|
3311
|
+
logger.logger.groupEnd();
|
|
3312
|
+
logger.logger.log('- input:', cli.input);
|
|
3313
|
+
logger.logger.groupEnd();
|
|
3250
3314
|
}
|
|
3251
3315
|
const target = cli.input[0];
|
|
3252
3316
|
|
|
3253
|
-
// TODO: I'm not sure it's feasible to parse source file from stdin. We could
|
|
3254
|
-
|
|
3317
|
+
// TODO: I'm not sure it's feasible to parse source file from stdin. We could
|
|
3318
|
+
// try, store contents in a file in some folder, target that folder... what
|
|
3319
|
+
// would the file name be?
|
|
3255
3320
|
if (!target || target === '-' || cli.input.length > 1) {
|
|
3256
3321
|
// Use exit status of 2 to indicate incorrect usage, generally invalid
|
|
3257
3322
|
// options or missing arguments.
|
|
3258
3323
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
3259
3324
|
process.exitCode = 2;
|
|
3260
|
-
|
|
3325
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
3261
3326
|
- The DIR arg is required ${!target ? colors.red('(missing!)') : target === '-' ? colors.red('(stdin is not supported)') : colors.green('(ok)')}\n
|
|
3262
3327
|
- Can only accept one DIR (make sure to escape spaces!) ${cli.input.length > 1 ? colors.red(`(received ${cli.input.length}!)`) : colors.green('(ok)')}\n`);
|
|
3263
3328
|
return;
|
|
@@ -3276,42 +3341,44 @@ async function run$p(argv, importMeta, {
|
|
|
3276
3341
|
out = '-';
|
|
3277
3342
|
}
|
|
3278
3343
|
if (verbose) {
|
|
3279
|
-
|
|
3280
|
-
|
|
3281
|
-
|
|
3282
|
-
|
|
3283
|
-
|
|
3344
|
+
logger.logger.group();
|
|
3345
|
+
logger.logger.log('- target:', target);
|
|
3346
|
+
logger.logger.log('- gradle bin:', bin);
|
|
3347
|
+
logger.logger.log('- out:', out);
|
|
3348
|
+
logger.logger.groupEnd();
|
|
3284
3349
|
}
|
|
3285
3350
|
let gradleOpts = [];
|
|
3286
3351
|
if (cli.flags['gradleOpts']) {
|
|
3287
3352
|
gradleOpts = cli.flags['gradleOpts'].split(' ').map(s => s.trim()).filter(Boolean);
|
|
3288
3353
|
}
|
|
3289
3354
|
if (cli.flags['dryRun']) {
|
|
3290
|
-
|
|
3355
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$o);
|
|
3356
|
+
return;
|
|
3291
3357
|
}
|
|
3292
3358
|
await convertGradleToMaven(target, bin, out, verbose, gradleOpts);
|
|
3293
3359
|
}
|
|
3294
3360
|
|
|
3295
3361
|
async function convertSbtToMaven(target, bin, out, verbose, sbtOpts) {
|
|
3362
|
+
// Lazily access constants.spinner.
|
|
3363
|
+
const {
|
|
3364
|
+
spinner
|
|
3365
|
+
} = constants;
|
|
3296
3366
|
const rbin = path.resolve(bin);
|
|
3297
3367
|
const rtarget = path.resolve(target);
|
|
3298
|
-
// const rout = out === '-' ? '-' : path.resolve(out)
|
|
3299
|
-
|
|
3300
3368
|
if (verbose) {
|
|
3301
|
-
|
|
3302
|
-
|
|
3303
|
-
|
|
3304
|
-
//
|
|
3305
|
-
|
|
3369
|
+
logger.logger.group('sbt2maven:');
|
|
3370
|
+
logger.logger.log(`[VERBOSE] - Absolute bin path: \`${rbin}\``);
|
|
3371
|
+
logger.logger.log(`[VERBOSE] - Absolute target path: \`${rtarget}\``);
|
|
3372
|
+
// logger.log(`[VERBOSE] - Absolute out path: \`${rout}\``)
|
|
3373
|
+
logger.logger.groupEnd();
|
|
3306
3374
|
} else {
|
|
3307
|
-
|
|
3308
|
-
|
|
3309
|
-
|
|
3310
|
-
//
|
|
3311
|
-
|
|
3312
|
-
}
|
|
3313
|
-
|
|
3314
|
-
spinner$1.start(`Converting sbt to maven from \`${bin}\` on \`${target}\`...`);
|
|
3375
|
+
logger.logger.group('sbt2maven:');
|
|
3376
|
+
logger.logger.log(`- executing: \`${bin}\``);
|
|
3377
|
+
logger.logger.log(`- src dir: \`${target}\``);
|
|
3378
|
+
// logger.log(`- dst dir: \`${out}\``)
|
|
3379
|
+
logger.logger.groupEnd();
|
|
3380
|
+
}
|
|
3381
|
+
spinner.start(`Converting sbt to maven from \`${bin}\` on \`${target}\`...`);
|
|
3315
3382
|
try {
|
|
3316
3383
|
// Run sbt with the init script we provide which should yield zero or more
|
|
3317
3384
|
// pom files. We have to figure out where to store those pom files such that
|
|
@@ -3321,19 +3388,19 @@ async function convertSbtToMaven(target, bin, out, verbose, sbtOpts) {
|
|
|
3321
3388
|
const output = await spawn(bin, ['makePom'].concat(sbtOpts), {
|
|
3322
3389
|
cwd: target || '.'
|
|
3323
3390
|
});
|
|
3324
|
-
spinner
|
|
3391
|
+
spinner.stop();
|
|
3325
3392
|
if (verbose) {
|
|
3326
|
-
|
|
3327
|
-
|
|
3328
|
-
|
|
3393
|
+
logger.logger.group('[VERBOSE] sbt stdout:');
|
|
3394
|
+
logger.logger.log(output);
|
|
3395
|
+
logger.logger.groupEnd();
|
|
3329
3396
|
}
|
|
3330
3397
|
if (output.stderr) {
|
|
3331
3398
|
logger.logger.error('There were errors while running sbt');
|
|
3332
3399
|
// (In verbose mode, stderr was printed above, no need to repeat it)
|
|
3333
3400
|
if (!verbose) {
|
|
3334
|
-
|
|
3335
|
-
|
|
3336
|
-
|
|
3401
|
+
logger.logger.group('[VERBOSE] stderr:');
|
|
3402
|
+
logger.logger.error(output.stderr);
|
|
3403
|
+
logger.logger.groupEnd();
|
|
3337
3404
|
}
|
|
3338
3405
|
process.exit(1);
|
|
3339
3406
|
}
|
|
@@ -3351,39 +3418,43 @@ async function convertSbtToMaven(target, bin, out, verbose, sbtOpts) {
|
|
|
3351
3418
|
// TODO: maybe we can add an option to target a specific file to dump to stdout
|
|
3352
3419
|
if (out === '-' && poms.length === 1) {
|
|
3353
3420
|
logger.logger.log('Result:\n```');
|
|
3354
|
-
|
|
3421
|
+
logger.logger.log(await index.safeReadFile(poms[0], 'utf8'));
|
|
3355
3422
|
logger.logger.log('```');
|
|
3356
3423
|
logger.logger.success(`OK`);
|
|
3357
3424
|
} else if (out === '-') {
|
|
3358
3425
|
logger.logger.error('Requested out target was stdout but there are multiple generated files');
|
|
3359
|
-
poms.forEach(fn =>
|
|
3360
|
-
|
|
3426
|
+
poms.forEach(fn => logger.logger.error('-', fn));
|
|
3427
|
+
logger.logger.error('Exiting now...');
|
|
3361
3428
|
process.exit(1);
|
|
3362
3429
|
} else {
|
|
3363
3430
|
// if (verbose) {
|
|
3364
|
-
//
|
|
3431
|
+
// logger.log(
|
|
3365
3432
|
// `Moving manifest file from \`${loc.replace(/^\/home\/[^/]*?\//, '~/')}\` to \`${out}\``
|
|
3366
3433
|
// )
|
|
3367
3434
|
// } else {
|
|
3368
|
-
//
|
|
3435
|
+
// logger.log('Moving output pom file')
|
|
3369
3436
|
// }
|
|
3370
3437
|
// TODO: do we prefer fs-extra? renaming can be gnarly on windows and fs-extra's version is better
|
|
3371
3438
|
// await renamep(loc, out)
|
|
3372
3439
|
logger.logger.success(`Generated ${poms.length} pom files`);
|
|
3373
|
-
poms.forEach(fn =>
|
|
3440
|
+
poms.forEach(fn => logger.logger.log('-', fn));
|
|
3374
3441
|
logger.logger.success(`OK`);
|
|
3375
3442
|
}
|
|
3376
3443
|
} catch (e) {
|
|
3377
|
-
spinner
|
|
3444
|
+
spinner.stop();
|
|
3445
|
+
logger.logger.error('There was an unexpected error while running this' + (verbose ? '' : ' (use --verbose for details)'));
|
|
3378
3446
|
if (verbose) {
|
|
3379
|
-
|
|
3380
|
-
|
|
3381
|
-
|
|
3447
|
+
logger.logger.group('[VERBOSE] error:');
|
|
3448
|
+
logger.logger.log(e);
|
|
3449
|
+
logger.logger.groupEnd();
|
|
3382
3450
|
}
|
|
3383
3451
|
process.exit(1);
|
|
3384
3452
|
}
|
|
3385
3453
|
}
|
|
3386
3454
|
|
|
3455
|
+
const {
|
|
3456
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$n
|
|
3457
|
+
} = constants;
|
|
3387
3458
|
const config$o = {
|
|
3388
3459
|
commandName: 'scala',
|
|
3389
3460
|
description: "[beta] Generate a manifest file (`pom.xml`) from Scala's `build.sbt` file",
|
|
@@ -3461,7 +3532,6 @@ const cmdManifestScala = {
|
|
|
3461
3532
|
async function run$o(argv, importMeta, {
|
|
3462
3533
|
parentName
|
|
3463
3534
|
}) {
|
|
3464
|
-
// console.log('scala', argv, parentName)
|
|
3465
3535
|
const cli = meowOrExit({
|
|
3466
3536
|
argv,
|
|
3467
3537
|
config: config$o,
|
|
@@ -3470,22 +3540,23 @@ async function run$o(argv, importMeta, {
|
|
|
3470
3540
|
});
|
|
3471
3541
|
const verbose = Boolean(cli.flags['verbose']);
|
|
3472
3542
|
if (verbose) {
|
|
3473
|
-
|
|
3474
|
-
|
|
3475
|
-
|
|
3476
|
-
|
|
3477
|
-
|
|
3543
|
+
logger.logger.group('- ', parentName, config$o.commandName, ':');
|
|
3544
|
+
logger.logger.group('- flags:', cli.flags);
|
|
3545
|
+
logger.logger.groupEnd();
|
|
3546
|
+
logger.logger.log('- input:', cli.input);
|
|
3547
|
+
logger.logger.groupEnd();
|
|
3478
3548
|
}
|
|
3479
3549
|
const target = cli.input[0];
|
|
3480
3550
|
|
|
3481
|
-
// TODO: I'm not sure it's feasible to parse source file from stdin. We could
|
|
3482
|
-
|
|
3551
|
+
// TODO: I'm not sure it's feasible to parse source file from stdin. We could
|
|
3552
|
+
// try, store contents in a file in some folder, target that folder... what
|
|
3553
|
+
// would the file name be?
|
|
3483
3554
|
if (!target || target === '-' || cli.input.length > 1) {
|
|
3484
3555
|
// Use exit status of 2 to indicate incorrect usage, generally invalid
|
|
3485
3556
|
// options or missing arguments.
|
|
3486
3557
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
3487
3558
|
process.exitCode = 2;
|
|
3488
|
-
|
|
3559
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
3489
3560
|
- The DIR or FILE arg is required ${!target ? colors.red('(missing!)') : target === '-' ? colors.red('(stdin is not supported)') : colors.green('(ok)')}\n
|
|
3490
3561
|
- Can only accept one DIR or FILE (make sure to escape spaces!) ${cli.input.length > 1 ? colors.red(`(received ${cli.input.length}!)`) : colors.green('(ok)')}\n`);
|
|
3491
3562
|
return;
|
|
@@ -3502,22 +3573,26 @@ async function run$o(argv, importMeta, {
|
|
|
3502
3573
|
out = '-';
|
|
3503
3574
|
}
|
|
3504
3575
|
if (verbose) {
|
|
3505
|
-
|
|
3506
|
-
|
|
3507
|
-
|
|
3508
|
-
|
|
3509
|
-
|
|
3576
|
+
logger.logger.group();
|
|
3577
|
+
logger.logger.log('- target:', target);
|
|
3578
|
+
logger.logger.log('- gradle bin:', bin);
|
|
3579
|
+
logger.logger.log('- out:', out);
|
|
3580
|
+
logger.logger.groupEnd();
|
|
3510
3581
|
}
|
|
3511
3582
|
let sbtOpts = [];
|
|
3512
3583
|
if (cli.flags['sbtOpts']) {
|
|
3513
3584
|
sbtOpts = cli.flags['sbtOpts'].split(' ').map(s => s.trim()).filter(Boolean);
|
|
3514
3585
|
}
|
|
3515
3586
|
if (cli.flags['dryRun']) {
|
|
3516
|
-
|
|
3587
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$n);
|
|
3588
|
+
return;
|
|
3517
3589
|
}
|
|
3518
3590
|
await convertSbtToMaven(target, bin, out, verbose, sbtOpts);
|
|
3519
3591
|
}
|
|
3520
3592
|
|
|
3593
|
+
const {
|
|
3594
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$m
|
|
3595
|
+
} = constants;
|
|
3521
3596
|
const config$n = {
|
|
3522
3597
|
commandName: 'auto',
|
|
3523
3598
|
description: 'Auto-detect build and attempt to generate manifest file',
|
|
@@ -3564,12 +3639,12 @@ async function run$n(argv, importMeta, {
|
|
|
3564
3639
|
const verbose = !!cli.flags['verbose'];
|
|
3565
3640
|
const cwd = cli.flags['cwd'] ?? process.cwd();
|
|
3566
3641
|
if (verbose) {
|
|
3567
|
-
|
|
3568
|
-
|
|
3569
|
-
|
|
3570
|
-
|
|
3571
|
-
|
|
3572
|
-
|
|
3642
|
+
logger.logger.group('- ', parentName, config$n.commandName, ':');
|
|
3643
|
+
logger.logger.group('- flags:', cli.flags);
|
|
3644
|
+
logger.logger.groupEnd();
|
|
3645
|
+
logger.logger.log('- input:', cli.input);
|
|
3646
|
+
logger.logger.log('- cwd:', cwd);
|
|
3647
|
+
logger.logger.groupEnd();
|
|
3573
3648
|
}
|
|
3574
3649
|
const subArgs = [];
|
|
3575
3650
|
if (verbose) {
|
|
@@ -3577,13 +3652,14 @@ async function run$n(argv, importMeta, {
|
|
|
3577
3652
|
}
|
|
3578
3653
|
const dir = cwd;
|
|
3579
3654
|
if (fs.existsSync(path.join(dir, 'build.sbt'))) {
|
|
3580
|
-
|
|
3655
|
+
logger.logger.log('Detected a Scala sbt build, running default Scala generator...');
|
|
3581
3656
|
if (cwd) {
|
|
3582
3657
|
subArgs.push('--cwd', cwd);
|
|
3583
3658
|
}
|
|
3584
3659
|
subArgs.push(dir);
|
|
3585
3660
|
if (cli.flags['dryRun']) {
|
|
3586
|
-
|
|
3661
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$m);
|
|
3662
|
+
return;
|
|
3587
3663
|
}
|
|
3588
3664
|
await cmdManifestScala.run(subArgs, importMeta, {
|
|
3589
3665
|
parentName
|
|
@@ -3591,13 +3667,14 @@ async function run$n(argv, importMeta, {
|
|
|
3591
3667
|
return;
|
|
3592
3668
|
}
|
|
3593
3669
|
if (fs.existsSync(path.join(dir, 'gradlew'))) {
|
|
3594
|
-
|
|
3670
|
+
logger.logger.log('Detected a gradle build, running default gradle generator...');
|
|
3595
3671
|
if (cwd) {
|
|
3596
3672
|
// This command takes the cwd as first arg.
|
|
3597
3673
|
subArgs.push(cwd);
|
|
3598
3674
|
}
|
|
3599
3675
|
if (cli.flags['dryRun']) {
|
|
3600
|
-
|
|
3676
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$m);
|
|
3677
|
+
return;
|
|
3601
3678
|
}
|
|
3602
3679
|
await cmdManifestGradle.run(subArgs, importMeta, {
|
|
3603
3680
|
parentName
|
|
@@ -3625,6 +3702,10 @@ async function run$n(argv, importMeta, {
|
|
|
3625
3702
|
}).showHelp();
|
|
3626
3703
|
}
|
|
3627
3704
|
|
|
3705
|
+
const {
|
|
3706
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$l
|
|
3707
|
+
} = constants;
|
|
3708
|
+
|
|
3628
3709
|
// TODO: we may want to dedupe some pieces for all gradle languages. I think it
|
|
3629
3710
|
// makes sense to have separate commands for them and I think it makes
|
|
3630
3711
|
// sense for the help panels to note the requested language, rather than
|
|
@@ -3717,22 +3798,23 @@ async function run$m(argv, importMeta, {
|
|
|
3717
3798
|
});
|
|
3718
3799
|
const verbose = Boolean(cli.flags['verbose']);
|
|
3719
3800
|
if (verbose) {
|
|
3720
|
-
|
|
3721
|
-
|
|
3722
|
-
|
|
3723
|
-
|
|
3724
|
-
|
|
3801
|
+
logger.logger.group('- ', parentName, config$m.commandName, ':');
|
|
3802
|
+
logger.logger.group('- flags:', cli.flags);
|
|
3803
|
+
logger.logger.groupEnd();
|
|
3804
|
+
logger.logger.log('- input:', cli.input);
|
|
3805
|
+
logger.logger.groupEnd();
|
|
3725
3806
|
}
|
|
3726
3807
|
const target = cli.input[0];
|
|
3727
3808
|
|
|
3728
|
-
// TODO: I'm not sure it's feasible to parse source file from stdin. We could
|
|
3729
|
-
|
|
3809
|
+
// TODO: I'm not sure it's feasible to parse source file from stdin. We could
|
|
3810
|
+
// try, store contents in a file in some folder, target that folder... what
|
|
3811
|
+
// would the file name be?
|
|
3730
3812
|
if (!target || target === '-' || cli.input.length > 1) {
|
|
3731
3813
|
// Use exit status of 2 to indicate incorrect usage, generally invalid
|
|
3732
3814
|
// options or missing arguments.
|
|
3733
3815
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
3734
3816
|
process.exitCode = 2;
|
|
3735
|
-
|
|
3817
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
3736
3818
|
- The DIR arg is required ${!target ? colors.red('(missing!)') : target === '-' ? colors.red('(stdin is not supported)') : colors.green('(ok)')}\n
|
|
3737
3819
|
- Can only accept one DIR (make sure to escape spaces!) ${cli.input.length > 1 ? colors.red(`(received ${cli.input.length}!)`) : colors.green('(ok)')}\n`);
|
|
3738
3820
|
return;
|
|
@@ -3751,18 +3833,19 @@ async function run$m(argv, importMeta, {
|
|
|
3751
3833
|
out = '-';
|
|
3752
3834
|
}
|
|
3753
3835
|
if (verbose) {
|
|
3754
|
-
|
|
3755
|
-
|
|
3756
|
-
|
|
3757
|
-
|
|
3758
|
-
|
|
3836
|
+
logger.logger.group();
|
|
3837
|
+
logger.logger.log('- target:', target);
|
|
3838
|
+
logger.logger.log('- gradle bin:', bin);
|
|
3839
|
+
logger.logger.log('- out:', out);
|
|
3840
|
+
logger.logger.groupEnd();
|
|
3759
3841
|
}
|
|
3760
3842
|
let gradleOpts = [];
|
|
3761
3843
|
if (cli.flags['gradleOpts']) {
|
|
3762
3844
|
gradleOpts = cli.flags['gradleOpts'].split(' ').map(s => s.trim()).filter(Boolean);
|
|
3763
3845
|
}
|
|
3764
3846
|
if (cli.flags['dryRun']) {
|
|
3765
|
-
|
|
3847
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$l);
|
|
3848
|
+
return;
|
|
3766
3849
|
}
|
|
3767
3850
|
await convertGradleToMaven(target, bin, out, verbose, gradleOpts);
|
|
3768
3851
|
}
|
|
@@ -3814,6 +3897,7 @@ async function wrapNpm(argv) {
|
|
|
3814
3897
|
}
|
|
3815
3898
|
|
|
3816
3899
|
const {
|
|
3900
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$k,
|
|
3817
3901
|
NPM: NPM$a
|
|
3818
3902
|
} = constants;
|
|
3819
3903
|
const config$k = {
|
|
@@ -3842,7 +3926,8 @@ async function run$k(argv, importMeta, {
|
|
|
3842
3926
|
parentName
|
|
3843
3927
|
});
|
|
3844
3928
|
if (cli.flags['dryRun']) {
|
|
3845
|
-
|
|
3929
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$k);
|
|
3930
|
+
return;
|
|
3846
3931
|
}
|
|
3847
3932
|
await wrapNpm(argv);
|
|
3848
3933
|
}
|
|
@@ -3858,6 +3943,7 @@ async function wrapNpx(argv) {
|
|
|
3858
3943
|
}
|
|
3859
3944
|
|
|
3860
3945
|
const {
|
|
3946
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$j,
|
|
3861
3947
|
NPX: NPX$1
|
|
3862
3948
|
} = constants;
|
|
3863
3949
|
const config$j = {
|
|
@@ -3886,11 +3972,15 @@ async function run$j(argv, importMeta, {
|
|
|
3886
3972
|
parentName
|
|
3887
3973
|
});
|
|
3888
3974
|
if (cli.flags['dryRun']) {
|
|
3889
|
-
|
|
3975
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$j);
|
|
3976
|
+
return;
|
|
3890
3977
|
}
|
|
3891
3978
|
await wrapNpx(argv);
|
|
3892
3979
|
}
|
|
3893
3980
|
|
|
3981
|
+
const {
|
|
3982
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$i
|
|
3983
|
+
} = constants;
|
|
3894
3984
|
const config$i = {
|
|
3895
3985
|
commandName: 'oops',
|
|
3896
3986
|
description: 'Trigger an intentional error (for development)',
|
|
@@ -3920,7 +4010,8 @@ async function run$i(argv, importMeta, {
|
|
|
3920
4010
|
parentName
|
|
3921
4011
|
});
|
|
3922
4012
|
if (cli.flags['dryRun']) {
|
|
3923
|
-
|
|
4013
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$i);
|
|
4014
|
+
return;
|
|
3924
4015
|
}
|
|
3925
4016
|
throw new Error('This error was intentionally left blank');
|
|
3926
4017
|
}
|
|
@@ -4631,7 +4722,7 @@ function runAgentInstall(agent, agentExecPath, options) {
|
|
|
4631
4722
|
__proto__: null,
|
|
4632
4723
|
...options
|
|
4633
4724
|
};
|
|
4634
|
-
const isSilent = !
|
|
4725
|
+
const isSilent = !debug.isDebug();
|
|
4635
4726
|
const isSpinning = spinner?.isSpinning ?? false;
|
|
4636
4727
|
if (!isSilent) {
|
|
4637
4728
|
spinner?.stop();
|
|
@@ -4679,7 +4770,8 @@ async function updatePackageLockJson(pkgEnvDetails, options) {
|
|
|
4679
4770
|
logger?.log(`💡 Re-run ${COMMAND_TITLE$1} whenever ${pkgEnvDetails.lockName} changes.\n This can be skipped once npm ships ${NPM_OVERRIDE_PR_URL}.`);
|
|
4680
4771
|
}
|
|
4681
4772
|
} catch (e) {
|
|
4682
|
-
spinner?.
|
|
4773
|
+
spinner?.stop();
|
|
4774
|
+
logger?.error(`${COMMAND_TITLE$1}: ${pkgEnvDetails.agent} install failed to update ${pkgEnvDetails.lockName}`);
|
|
4683
4775
|
logger?.error(e);
|
|
4684
4776
|
}
|
|
4685
4777
|
}
|
|
@@ -4692,44 +4784,44 @@ const {
|
|
|
4692
4784
|
const COMMAND_TITLE = 'Socket Optimize';
|
|
4693
4785
|
const manifestNpmOverrides = registry.getManifestData(NPM$1);
|
|
4694
4786
|
async function applyOptimization(cwd, pin, prod) {
|
|
4695
|
-
const logger = console;
|
|
4696
4787
|
const pkgEnvDetails = await detectAndValidatePackageEnvironment(cwd, {
|
|
4697
|
-
logger,
|
|
4788
|
+
logger: logger.logger,
|
|
4698
4789
|
prod
|
|
4699
4790
|
});
|
|
4700
4791
|
if (!pkgEnvDetails) {
|
|
4701
4792
|
return;
|
|
4702
4793
|
}
|
|
4703
|
-
|
|
4704
|
-
|
|
4705
|
-
|
|
4706
|
-
|
|
4794
|
+
// Lazily access constants.spinner.
|
|
4795
|
+
const {
|
|
4796
|
+
spinner
|
|
4797
|
+
} = constants;
|
|
4798
|
+
spinner.start('Socket optimizing...');
|
|
4707
4799
|
const state = await addOverrides(pkgEnvDetails.pkgPath, pkgEnvDetails, {
|
|
4708
|
-
logger,
|
|
4800
|
+
logger: logger.logger,
|
|
4709
4801
|
pin,
|
|
4710
4802
|
prod,
|
|
4711
|
-
spinner
|
|
4803
|
+
spinner
|
|
4712
4804
|
});
|
|
4713
|
-
spinner
|
|
4805
|
+
spinner.stop();
|
|
4714
4806
|
const addedCount = state.added.size;
|
|
4715
4807
|
const updatedCount = state.updated.size;
|
|
4716
4808
|
const pkgJsonChanged = addedCount > 0 || updatedCount > 0;
|
|
4717
4809
|
if (pkgJsonChanged) {
|
|
4718
4810
|
if (updatedCount > 0) {
|
|
4719
|
-
logger?.log(`${createActionMessage('Updated', updatedCount, state.updatedInWorkspaces.size)}${addedCount ? '.' : '🚀'}`);
|
|
4811
|
+
logger.logger?.log(`${createActionMessage('Updated', updatedCount, state.updatedInWorkspaces.size)}${addedCount ? '.' : '🚀'}`);
|
|
4720
4812
|
}
|
|
4721
4813
|
if (addedCount > 0) {
|
|
4722
|
-
logger?.log(`${createActionMessage('Added', addedCount, state.addedInWorkspaces.size)} 🚀`);
|
|
4814
|
+
logger.logger?.log(`${createActionMessage('Added', addedCount, state.addedInWorkspaces.size)} 🚀`);
|
|
4723
4815
|
}
|
|
4724
4816
|
} else {
|
|
4725
|
-
logger?.log('Congratulations! Already Socket.dev optimized 🎉');
|
|
4817
|
+
logger.logger?.log('Congratulations! Already Socket.dev optimized 🎉');
|
|
4726
4818
|
}
|
|
4727
4819
|
if (pkgEnvDetails.agent === NPM$1 || pkgJsonChanged) {
|
|
4728
4820
|
// Always update package-lock.json until the npm overrides PR lands:
|
|
4729
4821
|
// https://github.com/npm/cli/pull/8089
|
|
4730
4822
|
await updatePackageLockJson(pkgEnvDetails, {
|
|
4731
|
-
logger,
|
|
4732
|
-
spinner
|
|
4823
|
+
logger: logger.logger,
|
|
4824
|
+
spinner
|
|
4733
4825
|
});
|
|
4734
4826
|
}
|
|
4735
4827
|
}
|
|
@@ -4915,6 +5007,9 @@ async function addOverrides(pkgPath, pkgEnvDetails, options) {
|
|
|
4915
5007
|
return state;
|
|
4916
5008
|
}
|
|
4917
5009
|
|
|
5010
|
+
const {
|
|
5011
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$h
|
|
5012
|
+
} = constants;
|
|
4918
5013
|
const config$h = {
|
|
4919
5014
|
commandName: 'optimize',
|
|
4920
5015
|
description: 'Optimize dependencies with @socketregistry overrides',
|
|
@@ -4960,7 +5055,8 @@ async function run$h(argv, importMeta, {
|
|
|
4960
5055
|
});
|
|
4961
5056
|
const cwd = process$1.cwd();
|
|
4962
5057
|
if (cli.flags['dryRun']) {
|
|
4963
|
-
|
|
5058
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$h);
|
|
5059
|
+
return;
|
|
4964
5060
|
}
|
|
4965
5061
|
await applyOptimization(cwd, Boolean(cli.flags['pin']), Boolean(cli.flags['prod']));
|
|
4966
5062
|
}
|
|
@@ -4973,21 +5069,24 @@ async function getOrganization(format = 'text') {
|
|
|
4973
5069
|
await printOrganizationsFromToken(apiToken, format);
|
|
4974
5070
|
}
|
|
4975
5071
|
async function printOrganizationsFromToken(apiToken, format = 'text') {
|
|
4976
|
-
|
|
4977
|
-
|
|
5072
|
+
// Lazily access constants.spinner.
|
|
5073
|
+
const {
|
|
5074
|
+
spinner
|
|
5075
|
+
} = constants;
|
|
5076
|
+
spinner.start('Fetching organizations...');
|
|
4978
5077
|
const socketSdk = await index.setupSdk(apiToken);
|
|
4979
5078
|
const result = await handleApiCall(socketSdk.getOrganizations(), 'looking up organizations');
|
|
4980
5079
|
if (!result.success) {
|
|
4981
|
-
handleUnsuccessfulApiResponse('getOrganizations', result, spinner
|
|
5080
|
+
handleUnsuccessfulApiResponse('getOrganizations', result, spinner);
|
|
4982
5081
|
return;
|
|
4983
5082
|
}
|
|
4984
|
-
spinner
|
|
5083
|
+
spinner.stop();
|
|
4985
5084
|
const organizations = Object.values(result.data.organizations);
|
|
4986
5085
|
const lastFiveOfApiToken = getLastFiveOfApiToken(apiToken);
|
|
4987
5086
|
switch (format) {
|
|
4988
5087
|
case 'json':
|
|
4989
5088
|
{
|
|
4990
|
-
|
|
5089
|
+
logger.logger.log(JSON.stringify(organizations.map(o => ({
|
|
4991
5090
|
name: o.name,
|
|
4992
5091
|
id: o.id,
|
|
4993
5092
|
plan: o.plan
|
|
@@ -5008,27 +5107,30 @@ async function printOrganizationsFromToken(apiToken, format = 'text') {
|
|
|
5008
5107
|
mw2 = Math.max(mw2, o.id.length);
|
|
5009
5108
|
mw3 = Math.max(mw3, o.plan.length);
|
|
5010
5109
|
}
|
|
5011
|
-
|
|
5012
|
-
|
|
5013
|
-
|
|
5014
|
-
|
|
5110
|
+
logger.logger.log('# Organizations\n');
|
|
5111
|
+
logger.logger.log(`List of organizations associated with your API key, ending with: ${colors.italic(lastFiveOfApiToken)}\n`);
|
|
5112
|
+
logger.logger.log(`| Name${' '.repeat(mw1 - 4)} | ID${' '.repeat(mw2 - 2)} | Plan${' '.repeat(mw3 - 4)} |`);
|
|
5113
|
+
logger.logger.log(`| ${'-'.repeat(mw1)} | ${'-'.repeat(mw2)} | ${'-'.repeat(mw3)} |`);
|
|
5015
5114
|
for (const o of organizations) {
|
|
5016
|
-
|
|
5115
|
+
logger.logger.log(`| ${(o.name || '').padEnd(mw1, ' ')} | ${(o.id || '').padEnd(mw2, ' ')} | ${(o.plan || '').padEnd(mw3, ' ')} |`);
|
|
5017
5116
|
}
|
|
5018
|
-
|
|
5117
|
+
logger.logger.log(`| ${'-'.repeat(mw1)} | ${'-'.repeat(mw2)} | ${'-'.repeat(mw3)} |`);
|
|
5019
5118
|
return;
|
|
5020
5119
|
}
|
|
5021
5120
|
default:
|
|
5022
5121
|
{
|
|
5023
|
-
|
|
5122
|
+
logger.logger.log(`List of organizations associated with your API key, ending with: ${colors.italic(lastFiveOfApiToken)}\n`);
|
|
5024
5123
|
// Just dump
|
|
5025
5124
|
for (const o of organizations) {
|
|
5026
|
-
|
|
5125
|
+
logger.logger.log(`- Name: ${colors.bold(o.name)}, ID: ${colors.bold(o.id)}, Plan: ${colors.bold(o.plan)}`);
|
|
5027
5126
|
}
|
|
5028
5127
|
}
|
|
5029
5128
|
}
|
|
5030
5129
|
}
|
|
5031
5130
|
|
|
5131
|
+
const {
|
|
5132
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$g
|
|
5133
|
+
} = constants;
|
|
5032
5134
|
const config$g = {
|
|
5033
5135
|
commandName: 'organizations',
|
|
5034
5136
|
description: 'List organizations associated with the API key used',
|
|
@@ -5066,14 +5168,15 @@ async function run$g(argv, importMeta, {
|
|
|
5066
5168
|
// options or missing arguments.
|
|
5067
5169
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
5068
5170
|
process.exitCode = 2;
|
|
5069
|
-
|
|
5171
|
+
logger.logger.error(`
|
|
5070
5172
|
${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
5071
5173
|
- The json and markdown flags cannot be both set, pick one
|
|
5072
5174
|
`);
|
|
5073
5175
|
return;
|
|
5074
5176
|
}
|
|
5075
5177
|
if (cli.flags['dryRun']) {
|
|
5076
|
-
|
|
5178
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$g);
|
|
5179
|
+
return;
|
|
5077
5180
|
}
|
|
5078
5181
|
await getOrganization(json ? 'json' : markdown ? 'markdown' : 'text');
|
|
5079
5182
|
}
|
|
@@ -5101,6 +5204,7 @@ async function runRawNpm(argv) {
|
|
|
5101
5204
|
}
|
|
5102
5205
|
|
|
5103
5206
|
const {
|
|
5207
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$f,
|
|
5104
5208
|
NPM
|
|
5105
5209
|
} = constants;
|
|
5106
5210
|
const config$f = {
|
|
@@ -5135,7 +5239,8 @@ async function run$f(argv, importMeta, {
|
|
|
5135
5239
|
parentName
|
|
5136
5240
|
});
|
|
5137
5241
|
if (cli.flags['dryRun']) {
|
|
5138
|
-
|
|
5242
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$f);
|
|
5243
|
+
return;
|
|
5139
5244
|
}
|
|
5140
5245
|
await runRawNpm(argv);
|
|
5141
5246
|
}
|
|
@@ -5163,6 +5268,7 @@ async function runRawNpx(argv) {
|
|
|
5163
5268
|
}
|
|
5164
5269
|
|
|
5165
5270
|
const {
|
|
5271
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$e,
|
|
5166
5272
|
NPX
|
|
5167
5273
|
} = constants;
|
|
5168
5274
|
const config$e = {
|
|
@@ -5197,18 +5303,26 @@ async function run$e(argv, importMeta, {
|
|
|
5197
5303
|
parentName
|
|
5198
5304
|
});
|
|
5199
5305
|
if (cli.flags['dryRun']) {
|
|
5200
|
-
|
|
5306
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$e);
|
|
5307
|
+
return;
|
|
5201
5308
|
}
|
|
5202
5309
|
await runRawNpx(argv);
|
|
5203
5310
|
}
|
|
5204
5311
|
|
|
5312
|
+
const {
|
|
5313
|
+
DRY_RUN_LABEL
|
|
5314
|
+
} = constants;
|
|
5205
5315
|
async function createReport(socketConfig, inputPaths, {
|
|
5206
5316
|
cwd,
|
|
5207
5317
|
dryRun
|
|
5208
5318
|
}) {
|
|
5319
|
+
// Lazily access constants.spinner.
|
|
5320
|
+
const {
|
|
5321
|
+
spinner
|
|
5322
|
+
} = constants;
|
|
5209
5323
|
const socketSdk = await index.setupSdk();
|
|
5210
5324
|
const supportedFiles = await socketSdk.getReportSupportedFiles().then(res => {
|
|
5211
|
-
if (!res.success) handleUnsuccessfulApiResponse('getReportSupportedFiles', res,
|
|
5325
|
+
if (!res.success) handleUnsuccessfulApiResponse('getReportSupportedFiles', res, spinner);
|
|
5212
5326
|
return res.data;
|
|
5213
5327
|
}).catch(cause => {
|
|
5214
5328
|
throw new Error('Failed getting supported files for report', {
|
|
@@ -5219,24 +5333,23 @@ async function createReport(socketConfig, inputPaths, {
|
|
|
5219
5333
|
const {
|
|
5220
5334
|
length: packagePathsCount
|
|
5221
5335
|
} = packagePaths;
|
|
5222
|
-
if (packagePathsCount &&
|
|
5336
|
+
if (packagePathsCount && debug.isDebug()) {
|
|
5223
5337
|
for (const pkgPath of packagePaths) {
|
|
5224
|
-
|
|
5338
|
+
debug.debugLog(`Uploading: ${pkgPath}`);
|
|
5225
5339
|
}
|
|
5226
5340
|
}
|
|
5227
5341
|
if (dryRun) {
|
|
5228
|
-
|
|
5342
|
+
debug.debugLog(`${DRY_RUN_LABEL}: Skipped actual upload`);
|
|
5229
5343
|
return undefined;
|
|
5230
5344
|
}
|
|
5231
|
-
|
|
5232
|
-
spinner$1.start(`Creating report with ${packagePathsCount} package ${words.pluralize('file', packagePathsCount)}`);
|
|
5345
|
+
spinner.start(`Creating report with ${packagePathsCount} package ${words.pluralize('file', packagePathsCount)}`);
|
|
5233
5346
|
const apiCall = socketSdk.createReportFromFilePaths(packagePaths, cwd, socketConfig?.issueRules);
|
|
5234
5347
|
const result = await handleApiCall(apiCall, 'creating report');
|
|
5235
5348
|
if (!result.success) {
|
|
5236
|
-
handleUnsuccessfulApiResponse('createReport', result, spinner
|
|
5349
|
+
handleUnsuccessfulApiResponse('createReport', result, spinner);
|
|
5237
5350
|
return undefined;
|
|
5238
5351
|
}
|
|
5239
|
-
spinner
|
|
5352
|
+
spinner.successAndStop();
|
|
5240
5353
|
return result;
|
|
5241
5354
|
}
|
|
5242
5355
|
|
|
@@ -5264,8 +5377,11 @@ async function getSocketConfig(absoluteConfigPath) {
|
|
|
5264
5377
|
const MAX_TIMEOUT_RETRY = 5;
|
|
5265
5378
|
const HTTP_CODE_TIMEOUT = 524;
|
|
5266
5379
|
async function fetchReportData(reportId, includeAllIssues, strict) {
|
|
5267
|
-
|
|
5268
|
-
|
|
5380
|
+
// Lazily access constants.spinner.
|
|
5381
|
+
const {
|
|
5382
|
+
spinner
|
|
5383
|
+
} = constants;
|
|
5384
|
+
spinner.start(`Fetching report with ID ${reportId} (this could take a while)`);
|
|
5269
5385
|
const socketSdk = await index.setupSdk();
|
|
5270
5386
|
let result;
|
|
5271
5387
|
for (let retry = 1; !result; ++retry) {
|
|
@@ -5274,43 +5390,43 @@ async function fetchReportData(reportId, includeAllIssues, strict) {
|
|
|
5274
5390
|
result = await handleApiCall(socketSdk.getReport(reportId), 'fetching report');
|
|
5275
5391
|
} catch (err) {
|
|
5276
5392
|
if (retry >= MAX_TIMEOUT_RETRY || !(err instanceof Error) || err.cause?.cause?.response?.statusCode !== HTTP_CODE_TIMEOUT) {
|
|
5277
|
-
spinner
|
|
5393
|
+
spinner.stop();
|
|
5278
5394
|
throw err;
|
|
5279
5395
|
}
|
|
5280
5396
|
}
|
|
5281
5397
|
}
|
|
5282
5398
|
if (!result.success) {
|
|
5283
|
-
return handleUnsuccessfulApiResponse('getReport', result, spinner
|
|
5399
|
+
return handleUnsuccessfulApiResponse('getReport', result, spinner);
|
|
5284
5400
|
}
|
|
5285
5401
|
|
|
5286
5402
|
// Conclude the status of the API call.
|
|
5287
5403
|
if (strict) {
|
|
5288
5404
|
if (result.data.healthy) {
|
|
5289
|
-
spinner
|
|
5405
|
+
spinner.success('Report result is healthy and great!');
|
|
5290
5406
|
} else {
|
|
5291
|
-
spinner
|
|
5407
|
+
spinner.error('Report result deemed unhealthy for project');
|
|
5292
5408
|
}
|
|
5293
5409
|
} else if (!result.data.healthy) {
|
|
5294
5410
|
const severityCount = getSeverityCount(result.data.issues, includeAllIssues ? undefined : 'high');
|
|
5295
5411
|
const issueSummary = formatSeverityCount(severityCount);
|
|
5296
|
-
spinner
|
|
5412
|
+
spinner.success(`Report has these issues: ${issueSummary}`);
|
|
5297
5413
|
} else {
|
|
5298
|
-
spinner
|
|
5414
|
+
spinner.success('Report has no issues');
|
|
5299
5415
|
}
|
|
5300
|
-
spinner
|
|
5416
|
+
spinner.stop();
|
|
5301
5417
|
return result.data;
|
|
5302
5418
|
}
|
|
5303
5419
|
|
|
5304
5420
|
function formatReportDataOutput(reportId, data, commandName, outputJson, outputMarkdown, strict) {
|
|
5305
5421
|
if (outputJson) {
|
|
5306
|
-
|
|
5422
|
+
logger.logger.log(JSON.stringify(data, undefined, 2));
|
|
5307
5423
|
} else {
|
|
5308
5424
|
const format = new index.ColorOrMarkdown(outputMarkdown);
|
|
5309
|
-
|
|
5425
|
+
logger.logger.log('\nDetailed info on socket.dev: ' + format.hyperlink(reportId, data.url, {
|
|
5310
5426
|
fallbackToUrl: true
|
|
5311
5427
|
}));
|
|
5312
5428
|
if (!outputMarkdown) {
|
|
5313
|
-
|
|
5429
|
+
logger.logger.log(colors.dim(`\nOr rerun ${colors.italic(commandName)} using the ${colors.italic('--json')} flag to get full JSON output`));
|
|
5314
5430
|
}
|
|
5315
5431
|
}
|
|
5316
5432
|
if (strict && !data.healthy) {
|
|
@@ -5331,6 +5447,9 @@ async function viewReport(reportId, {
|
|
|
5331
5447
|
}
|
|
5332
5448
|
}
|
|
5333
5449
|
|
|
5450
|
+
const {
|
|
5451
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$d
|
|
5452
|
+
} = constants;
|
|
5334
5453
|
const config$d = {
|
|
5335
5454
|
commandName: 'create',
|
|
5336
5455
|
description: 'Create a project report',
|
|
@@ -5401,7 +5520,8 @@ async function run$d(argv, importMeta, {
|
|
|
5401
5520
|
|
|
5402
5521
|
// Note exiting earlier to skirt a hidden auth requirement
|
|
5403
5522
|
if (cli.flags['dryRun']) {
|
|
5404
|
-
|
|
5523
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$d);
|
|
5524
|
+
return;
|
|
5405
5525
|
}
|
|
5406
5526
|
const socketConfig = await getSocketConfig(absoluteConfigPath);
|
|
5407
5527
|
const result = await createReport(socketConfig, cli.input, {
|
|
@@ -5420,17 +5540,19 @@ async function run$d(argv, importMeta, {
|
|
|
5420
5540
|
strict
|
|
5421
5541
|
});
|
|
5422
5542
|
} else if (json) {
|
|
5423
|
-
|
|
5424
|
-
return;
|
|
5543
|
+
logger.logger.log(JSON.stringify(result.data, undefined, 2));
|
|
5425
5544
|
} else {
|
|
5426
5545
|
const format = new index.ColorOrMarkdown(markdown);
|
|
5427
|
-
|
|
5546
|
+
logger.logger.log(`New report: ${format.hyperlink(result.data.id, result.data.url, {
|
|
5428
5547
|
fallbackToUrl: true
|
|
5429
5548
|
})}`);
|
|
5430
5549
|
}
|
|
5431
5550
|
}
|
|
5432
5551
|
}
|
|
5433
5552
|
|
|
5553
|
+
const {
|
|
5554
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$c
|
|
5555
|
+
} = constants;
|
|
5434
5556
|
const config$c = {
|
|
5435
5557
|
commandName: 'view',
|
|
5436
5558
|
description: 'View a project report',
|
|
@@ -5473,13 +5595,14 @@ async function run$c(argv, importMeta, {
|
|
|
5473
5595
|
// options or missing arguments.
|
|
5474
5596
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
5475
5597
|
process.exitCode = 2;
|
|
5476
|
-
|
|
5598
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
5477
5599
|
- Need at least one report ID ${!reportId ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
5478
5600
|
- Can only handle a single report ID ${extraInput.length < 2 ? colors.red(`(received ${extraInput.length}!)`) : colors.green('(ok)')}\n`);
|
|
5479
5601
|
return;
|
|
5480
5602
|
}
|
|
5481
5603
|
if (cli.flags['dryRun']) {
|
|
5482
|
-
|
|
5604
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$c);
|
|
5605
|
+
return;
|
|
5483
5606
|
}
|
|
5484
5607
|
await viewReport(reportId, {
|
|
5485
5608
|
all: Boolean(cli.flags['all']),
|
|
@@ -5519,8 +5642,11 @@ async function createRepo({
|
|
|
5519
5642
|
repoName,
|
|
5520
5643
|
visibility
|
|
5521
5644
|
}) {
|
|
5522
|
-
|
|
5523
|
-
|
|
5645
|
+
// Lazily access constants.spinner.
|
|
5646
|
+
const {
|
|
5647
|
+
spinner
|
|
5648
|
+
} = constants;
|
|
5649
|
+
spinner.start('Creating repository...');
|
|
5524
5650
|
const socketSdk = await index.setupSdk(apiToken);
|
|
5525
5651
|
const result = await handleApiCall(socketSdk.createOrgRepo(orgSlug, {
|
|
5526
5652
|
outputJson,
|
|
@@ -5533,12 +5659,15 @@ async function createRepo({
|
|
|
5533
5659
|
visibility
|
|
5534
5660
|
}), 'creating repository');
|
|
5535
5661
|
if (result.success) {
|
|
5536
|
-
spinner
|
|
5662
|
+
spinner.successAndStop('Repository created successfully');
|
|
5537
5663
|
} else {
|
|
5538
|
-
handleUnsuccessfulApiResponse('createOrgRepo', result, spinner
|
|
5664
|
+
handleUnsuccessfulApiResponse('createOrgRepo', result, spinner);
|
|
5539
5665
|
}
|
|
5540
5666
|
}
|
|
5541
5667
|
|
|
5668
|
+
const {
|
|
5669
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$b
|
|
5670
|
+
} = constants;
|
|
5542
5671
|
const config$b = {
|
|
5543
5672
|
commandName: 'create',
|
|
5544
5673
|
description: 'Create a repository in an organization',
|
|
@@ -5609,13 +5738,14 @@ async function run$b(argv, importMeta, {
|
|
|
5609
5738
|
// options or missing arguments.
|
|
5610
5739
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
5611
5740
|
process.exitCode = 2;
|
|
5612
|
-
|
|
5741
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
5613
5742
|
- Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
5614
5743
|
- Repository name using --repoName ${!repoName ? colors.red('(missing!)') : typeof repoName !== 'string' ? colors.red('(invalid!)') : colors.green('(ok)')}\n`);
|
|
5615
5744
|
return;
|
|
5616
5745
|
}
|
|
5617
5746
|
if (cli.flags['dryRun']) {
|
|
5618
|
-
|
|
5747
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$b);
|
|
5748
|
+
return;
|
|
5619
5749
|
}
|
|
5620
5750
|
const apiToken = index.getDefaultToken();
|
|
5621
5751
|
if (!apiToken) {
|
|
@@ -5635,17 +5765,23 @@ async function run$b(argv, importMeta, {
|
|
|
5635
5765
|
}
|
|
5636
5766
|
|
|
5637
5767
|
async function deleteRepo(orgSlug, repoName, apiToken) {
|
|
5638
|
-
|
|
5639
|
-
|
|
5768
|
+
// Lazily access constants.spinner.
|
|
5769
|
+
const {
|
|
5770
|
+
spinner
|
|
5771
|
+
} = constants;
|
|
5772
|
+
spinner.start('Deleting repository...');
|
|
5640
5773
|
const socketSdk = await index.setupSdk(apiToken);
|
|
5641
5774
|
const result = await handleApiCall(socketSdk.deleteOrgRepo(orgSlug, repoName), 'deleting repository');
|
|
5642
5775
|
if (result.success) {
|
|
5643
|
-
spinner
|
|
5776
|
+
spinner.successAndStop('Repository deleted successfully');
|
|
5644
5777
|
} else {
|
|
5645
|
-
handleUnsuccessfulApiResponse('deleteOrgRepo', result, spinner
|
|
5778
|
+
handleUnsuccessfulApiResponse('deleteOrgRepo', result, spinner);
|
|
5646
5779
|
}
|
|
5647
5780
|
}
|
|
5648
5781
|
|
|
5782
|
+
const {
|
|
5783
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$a
|
|
5784
|
+
} = constants;
|
|
5649
5785
|
const config$a = {
|
|
5650
5786
|
commandName: 'del',
|
|
5651
5787
|
description: 'Delete a repository in an organization',
|
|
@@ -5684,14 +5820,15 @@ async function run$a(argv, importMeta, {
|
|
|
5684
5820
|
// options or missing arguments.
|
|
5685
5821
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
5686
5822
|
process.exitCode = 2;
|
|
5687
|
-
|
|
5823
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
5688
5824
|
- Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
5689
5825
|
- Repository name as the second argument ${!repoName ? colors.red('(missing!)') : typeof repoName !== 'string' ? colors.red('(invalid!)') : colors.green('(ok)')}\n
|
|
5690
5826
|
- At least one TARGET (e.g. \`.\` or \`./package.json\`\n`);
|
|
5691
5827
|
return;
|
|
5692
5828
|
}
|
|
5693
5829
|
if (cli.flags['dryRun']) {
|
|
5694
|
-
|
|
5830
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$a);
|
|
5831
|
+
return;
|
|
5695
5832
|
}
|
|
5696
5833
|
const apiToken = index.getDefaultToken();
|
|
5697
5834
|
if (!apiToken) {
|
|
@@ -5711,10 +5848,11 @@ async function listRepos({
|
|
|
5711
5848
|
per_page,
|
|
5712
5849
|
sort
|
|
5713
5850
|
}) {
|
|
5714
|
-
|
|
5715
|
-
const
|
|
5716
|
-
|
|
5717
|
-
}
|
|
5851
|
+
// Lazily access constants.spinner.
|
|
5852
|
+
const {
|
|
5853
|
+
spinner
|
|
5854
|
+
} = constants;
|
|
5855
|
+
spinner.start('Listing repositories...');
|
|
5718
5856
|
const socketSdk = await index.setupSdk(apiToken);
|
|
5719
5857
|
const result = await handleApiCall(socketSdk.getOrgRepoList(orgSlug, {
|
|
5720
5858
|
outputJson,
|
|
@@ -5726,10 +5864,10 @@ async function listRepos({
|
|
|
5726
5864
|
page
|
|
5727
5865
|
}), 'listing repositories');
|
|
5728
5866
|
if (!result.success) {
|
|
5729
|
-
handleUnsuccessfulApiResponse('getOrgRepoList', result, spinner
|
|
5867
|
+
handleUnsuccessfulApiResponse('getOrgRepoList', result, spinner);
|
|
5730
5868
|
return;
|
|
5731
5869
|
}
|
|
5732
|
-
spinner
|
|
5870
|
+
spinner.stop();
|
|
5733
5871
|
if (outputJson) {
|
|
5734
5872
|
const data = result.data.results.map(o => ({
|
|
5735
5873
|
id: o.id,
|
|
@@ -5738,7 +5876,7 @@ async function listRepos({
|
|
|
5738
5876
|
defaultBranch: o.default_branch,
|
|
5739
5877
|
archived: o.archived
|
|
5740
5878
|
}));
|
|
5741
|
-
|
|
5879
|
+
logger.logger.log(JSON.stringify(data, null, 2));
|
|
5742
5880
|
return;
|
|
5743
5881
|
}
|
|
5744
5882
|
const options = {
|
|
@@ -5759,9 +5897,12 @@ async function listRepos({
|
|
|
5759
5897
|
name: colors.magenta('Archived')
|
|
5760
5898
|
}]
|
|
5761
5899
|
};
|
|
5762
|
-
|
|
5900
|
+
logger.logger.log(chalkTable(options, result.data.results));
|
|
5763
5901
|
}
|
|
5764
5902
|
|
|
5903
|
+
const {
|
|
5904
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$9
|
|
5905
|
+
} = constants;
|
|
5765
5906
|
const config$9 = {
|
|
5766
5907
|
commandName: 'list',
|
|
5767
5908
|
description: 'List repositories in an organization',
|
|
@@ -5824,13 +5965,14 @@ async function run$9(argv, importMeta, {
|
|
|
5824
5965
|
// options or missing arguments.
|
|
5825
5966
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
5826
5967
|
process.exitCode = 2;
|
|
5827
|
-
|
|
5968
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
5828
5969
|
- Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
5829
5970
|
- At least one TARGET (e.g. \`.\` or \`./package.json\`\n`);
|
|
5830
5971
|
return;
|
|
5831
5972
|
}
|
|
5832
5973
|
if (cli.flags['dryRun']) {
|
|
5833
|
-
|
|
5974
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$9);
|
|
5975
|
+
return;
|
|
5834
5976
|
}
|
|
5835
5977
|
const apiToken = index.getDefaultToken();
|
|
5836
5978
|
if (!apiToken) {
|
|
@@ -5859,10 +6001,11 @@ async function updateRepo({
|
|
|
5859
6001
|
repoName,
|
|
5860
6002
|
visibility
|
|
5861
6003
|
}) {
|
|
5862
|
-
|
|
5863
|
-
const
|
|
5864
|
-
|
|
5865
|
-
}
|
|
6004
|
+
// Lazily access constants.spinner.
|
|
6005
|
+
const {
|
|
6006
|
+
spinner
|
|
6007
|
+
} = constants;
|
|
6008
|
+
spinner.start('Updating repository...');
|
|
5866
6009
|
const socketSdk = await index.setupSdk(apiToken);
|
|
5867
6010
|
const result = await handleApiCall(socketSdk.updateOrgRepo(orgSlug, repoName, {
|
|
5868
6011
|
outputJson,
|
|
@@ -5875,12 +6018,15 @@ async function updateRepo({
|
|
|
5875
6018
|
visibility
|
|
5876
6019
|
}), 'updating repository');
|
|
5877
6020
|
if (result.success) {
|
|
5878
|
-
spinner
|
|
6021
|
+
spinner.successAndStop('Repository updated successfully');
|
|
5879
6022
|
} else {
|
|
5880
|
-
handleUnsuccessfulApiResponse('updateOrgRepo', result, spinner
|
|
6023
|
+
handleUnsuccessfulApiResponse('updateOrgRepo', result, spinner);
|
|
5881
6024
|
}
|
|
5882
6025
|
}
|
|
5883
6026
|
|
|
6027
|
+
const {
|
|
6028
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$8
|
|
6029
|
+
} = constants;
|
|
5884
6030
|
const config$8 = {
|
|
5885
6031
|
commandName: 'update',
|
|
5886
6032
|
description: 'Update a repository in an organization',
|
|
@@ -5951,14 +6097,15 @@ async function run$8(argv, importMeta, {
|
|
|
5951
6097
|
// options or missing arguments.
|
|
5952
6098
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
5953
6099
|
process.exitCode = 2;
|
|
5954
|
-
|
|
6100
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
5955
6101
|
- Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
5956
6102
|
- Repository name using --repoName ${!repoName ? colors.red('(missing!)') : typeof repoName !== 'string' ? colors.red('(invalid!)') : colors.green('(ok)')}\n
|
|
5957
6103
|
- At least one TARGET (e.g. \`.\` or \`./package.json\`\n`);
|
|
5958
6104
|
return;
|
|
5959
6105
|
}
|
|
5960
6106
|
if (cli.flags['dryRun']) {
|
|
5961
|
-
|
|
6107
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$8);
|
|
6108
|
+
return;
|
|
5962
6109
|
}
|
|
5963
6110
|
const apiToken = index.getDefaultToken();
|
|
5964
6111
|
if (!apiToken) {
|
|
@@ -5979,14 +6126,15 @@ async function run$8(argv, importMeta, {
|
|
|
5979
6126
|
|
|
5980
6127
|
// @ts-ignore
|
|
5981
6128
|
async function viewRepo(orgSlug, repoName, apiToken) {
|
|
5982
|
-
|
|
5983
|
-
const
|
|
5984
|
-
|
|
5985
|
-
}
|
|
6129
|
+
// Lazily access constants.spinner.
|
|
6130
|
+
const {
|
|
6131
|
+
spinner
|
|
6132
|
+
} = constants;
|
|
6133
|
+
spinner.start('Fetching repository...');
|
|
5986
6134
|
const socketSdk = await index.setupSdk(apiToken);
|
|
5987
6135
|
const result = await handleApiCall(socketSdk.getOrgRepo(orgSlug, repoName), 'fetching repository');
|
|
5988
6136
|
if (!result.success) {
|
|
5989
|
-
handleUnsuccessfulApiResponse('getOrgRepo', result, spinner
|
|
6137
|
+
handleUnsuccessfulApiResponse('getOrgRepo', result, spinner);
|
|
5990
6138
|
return;
|
|
5991
6139
|
}
|
|
5992
6140
|
const options = {
|
|
@@ -6013,9 +6161,12 @@ async function viewRepo(orgSlug, repoName, apiToken) {
|
|
|
6013
6161
|
name: colors.magenta('Created at')
|
|
6014
6162
|
}]
|
|
6015
6163
|
};
|
|
6016
|
-
spinner
|
|
6164
|
+
spinner.stop(chalkTable(options, [result.data]));
|
|
6017
6165
|
}
|
|
6018
6166
|
|
|
6167
|
+
const {
|
|
6168
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$7
|
|
6169
|
+
} = constants;
|
|
6019
6170
|
const config$7 = {
|
|
6020
6171
|
commandName: 'view',
|
|
6021
6172
|
description: 'View repositories in an organization',
|
|
@@ -6056,13 +6207,14 @@ async function run$7(argv, importMeta, {
|
|
|
6056
6207
|
// options or missing arguments.
|
|
6057
6208
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
6058
6209
|
process.exitCode = 2;
|
|
6059
|
-
|
|
6210
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
6060
6211
|
- Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
6061
6212
|
- Repository name using --repoName ${!repoName ? colors.red('(missing!)') : typeof repoName !== 'string' ? colors.red('(invalid!)') : colors.green('(ok)')}\n`);
|
|
6062
6213
|
return;
|
|
6063
6214
|
}
|
|
6064
6215
|
if (cli.flags['dryRun']) {
|
|
6065
|
-
|
|
6216
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$7);
|
|
6217
|
+
return;
|
|
6066
6218
|
}
|
|
6067
6219
|
const apiToken = index.getDefaultToken();
|
|
6068
6220
|
if (!apiToken) {
|
|
@@ -6249,10 +6401,14 @@ async function createFullScan({
|
|
|
6249
6401
|
targets,
|
|
6250
6402
|
tmp
|
|
6251
6403
|
}) {
|
|
6404
|
+
// Lazily access constants.spinner.
|
|
6405
|
+
const {
|
|
6406
|
+
spinner
|
|
6407
|
+
} = constants;
|
|
6252
6408
|
const socketSdk = await index.setupSdk();
|
|
6253
6409
|
const supportedFiles = await socketSdk.getReportSupportedFiles().then(res => {
|
|
6254
6410
|
if (!res.success) {
|
|
6255
|
-
handleUnsuccessfulApiResponse('getReportSupportedFiles', res,
|
|
6411
|
+
handleUnsuccessfulApiResponse('getReportSupportedFiles', res, spinner);
|
|
6256
6412
|
assert(false, 'handleUnsuccessfulApiResponse should unconditionally throw');
|
|
6257
6413
|
}
|
|
6258
6414
|
return res.data;
|
|
@@ -6309,7 +6465,7 @@ async function createFullScan({
|
|
|
6309
6465
|
// options or missing arguments.
|
|
6310
6466
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
6311
6467
|
process$1.exitCode = 2;
|
|
6312
|
-
|
|
6468
|
+
logger.logger.error(`
|
|
6313
6469
|
${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
6314
6470
|
- Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
6315
6471
|
- Repository name using --repo ${!repoName ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
@@ -6320,22 +6476,19 @@ async function createFullScan({
|
|
|
6320
6476
|
return;
|
|
6321
6477
|
}
|
|
6322
6478
|
if (updatedInput) {
|
|
6323
|
-
|
|
6324
|
-
|
|
6325
|
-
|
|
6326
|
-
|
|
6479
|
+
logger.logger.log('Note: You can invoke this command next time to skip the interactive questions:');
|
|
6480
|
+
logger.logger.log('```');
|
|
6481
|
+
logger.logger.log(` socket scan create [other flags...] --repo ${repoName} --branch ${branchName} ${orgSlug} ${targets.join(' ')}`);
|
|
6482
|
+
logger.logger.log('```');
|
|
6327
6483
|
}
|
|
6328
6484
|
if (!apiToken) {
|
|
6329
6485
|
throw new index.AuthError('User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.');
|
|
6330
6486
|
}
|
|
6331
6487
|
if (readOnly) {
|
|
6332
|
-
|
|
6488
|
+
logger.logger.log('[ReadOnly] Bailing now');
|
|
6333
6489
|
return;
|
|
6334
6490
|
}
|
|
6335
|
-
|
|
6336
|
-
const spinner$1 = new spinner.Spinner({
|
|
6337
|
-
text: spinnerText
|
|
6338
|
-
}).start();
|
|
6491
|
+
spinner.start('Creating a scan...');
|
|
6339
6492
|
const result = await handleApiCall(socketSdk.createOrgFullScan(orgSlug, {
|
|
6340
6493
|
repo: repoName,
|
|
6341
6494
|
branch: branchName,
|
|
@@ -6345,12 +6498,12 @@ async function createFullScan({
|
|
|
6345
6498
|
tmp
|
|
6346
6499
|
}, packagePaths, cwd), 'Creating scan');
|
|
6347
6500
|
if (!result.success) {
|
|
6348
|
-
handleUnsuccessfulApiResponse('CreateOrgFullScan', result, spinner
|
|
6501
|
+
handleUnsuccessfulApiResponse('CreateOrgFullScan', result, spinner);
|
|
6349
6502
|
return;
|
|
6350
6503
|
}
|
|
6351
|
-
spinner
|
|
6504
|
+
spinner.successAndStop('Scan created successfully');
|
|
6352
6505
|
const link = colors.underline(colors.cyan(`${result.data.html_report_url}`));
|
|
6353
|
-
|
|
6506
|
+
logger.logger.log(`Available at: ${link}`);
|
|
6354
6507
|
const rl = readline.createInterface({
|
|
6355
6508
|
input: process$1.stdin,
|
|
6356
6509
|
output: process$1.stdout
|
|
@@ -6362,6 +6515,9 @@ async function createFullScan({
|
|
|
6362
6515
|
rl.close();
|
|
6363
6516
|
}
|
|
6364
6517
|
|
|
6518
|
+
const {
|
|
6519
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$6
|
|
6520
|
+
} = constants;
|
|
6365
6521
|
const config$6 = {
|
|
6366
6522
|
commandName: 'create',
|
|
6367
6523
|
description: 'Create a scan',
|
|
@@ -6478,7 +6634,7 @@ async function run$6(argv, importMeta, {
|
|
|
6478
6634
|
// options or missing arguments.
|
|
6479
6635
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
6480
6636
|
process$1.exitCode = 2;
|
|
6481
|
-
|
|
6637
|
+
logger.logger.error(`
|
|
6482
6638
|
${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
6483
6639
|
- Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
6484
6640
|
- Repository name using --repo ${!repoName ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
@@ -6491,7 +6647,8 @@ async function run$6(argv, importMeta, {
|
|
|
6491
6647
|
|
|
6492
6648
|
// Note exiting earlier to skirt a hidden auth requirement
|
|
6493
6649
|
if (cli.flags['dryRun']) {
|
|
6494
|
-
|
|
6650
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$6);
|
|
6651
|
+
return;
|
|
6495
6652
|
}
|
|
6496
6653
|
await createFullScan({
|
|
6497
6654
|
branchName: branchName,
|
|
@@ -6511,17 +6668,23 @@ async function run$6(argv, importMeta, {
|
|
|
6511
6668
|
}
|
|
6512
6669
|
|
|
6513
6670
|
async function deleteOrgFullScan(orgSlug, fullScanId, apiToken) {
|
|
6514
|
-
|
|
6515
|
-
|
|
6671
|
+
// Lazily access constants.spinner.
|
|
6672
|
+
const {
|
|
6673
|
+
spinner
|
|
6674
|
+
} = constants;
|
|
6675
|
+
spinner.start('Deleting scan...');
|
|
6516
6676
|
const socketSdk = await index.setupSdk(apiToken);
|
|
6517
6677
|
const result = await handleApiCall(socketSdk.deleteOrgFullScan(orgSlug, fullScanId), 'Deleting scan');
|
|
6518
6678
|
if (!result.success) {
|
|
6519
|
-
handleUnsuccessfulApiResponse('deleteOrgFullScan', result, spinner
|
|
6679
|
+
handleUnsuccessfulApiResponse('deleteOrgFullScan', result, spinner);
|
|
6520
6680
|
return;
|
|
6521
6681
|
}
|
|
6522
|
-
spinner
|
|
6682
|
+
spinner.successAndStop('Scan deleted successfully');
|
|
6523
6683
|
}
|
|
6524
6684
|
|
|
6685
|
+
const {
|
|
6686
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$5
|
|
6687
|
+
} = constants;
|
|
6525
6688
|
const config$5 = {
|
|
6526
6689
|
commandName: 'del',
|
|
6527
6690
|
description: 'Delete a scan',
|
|
@@ -6561,13 +6724,14 @@ async function run$5(argv, importMeta, {
|
|
|
6561
6724
|
// options or missing arguments.
|
|
6562
6725
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
6563
6726
|
process.exitCode = 2;
|
|
6564
|
-
|
|
6727
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
6565
6728
|
- Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
6566
6729
|
- Full Scan ID to delete as second argument ${!fullScanId ? colors.red('(missing!)') : colors.green('(ok)')}\n`);
|
|
6567
6730
|
return;
|
|
6568
6731
|
}
|
|
6569
6732
|
if (cli.flags['dryRun']) {
|
|
6570
|
-
|
|
6733
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$5);
|
|
6734
|
+
return;
|
|
6571
6735
|
}
|
|
6572
6736
|
const apiToken = index.getDefaultToken();
|
|
6573
6737
|
if (!apiToken) {
|
|
@@ -6578,12 +6742,15 @@ async function run$5(argv, importMeta, {
|
|
|
6578
6742
|
|
|
6579
6743
|
// @ts-ignore
|
|
6580
6744
|
async function listFullScans(orgSlug, input, apiToken) {
|
|
6581
|
-
|
|
6582
|
-
|
|
6745
|
+
// Lazily access constants.spinner.
|
|
6746
|
+
const {
|
|
6747
|
+
spinner
|
|
6748
|
+
} = constants;
|
|
6749
|
+
spinner.start('Listing scans...');
|
|
6583
6750
|
const socketSdk = await index.setupSdk(apiToken);
|
|
6584
6751
|
const result = await handleApiCall(socketSdk.getOrgFullScanList(orgSlug, input), 'Listing scans');
|
|
6585
6752
|
if (!result.success) {
|
|
6586
|
-
handleUnsuccessfulApiResponse('getOrgFullScanList', result, spinner
|
|
6753
|
+
handleUnsuccessfulApiResponse('getOrgFullScanList', result, spinner);
|
|
6587
6754
|
return;
|
|
6588
6755
|
}
|
|
6589
6756
|
const options = {
|
|
@@ -6613,10 +6780,13 @@ async function listFullScans(orgSlug, input, apiToken) {
|
|
|
6613
6780
|
branch: d.branch
|
|
6614
6781
|
};
|
|
6615
6782
|
});
|
|
6616
|
-
spinner
|
|
6617
|
-
|
|
6783
|
+
spinner.stop(`Listing scans for: ${orgSlug}`);
|
|
6784
|
+
logger.logger.log(chalkTable(options, formattedResults));
|
|
6618
6785
|
}
|
|
6619
6786
|
|
|
6787
|
+
const {
|
|
6788
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$4
|
|
6789
|
+
} = constants;
|
|
6620
6790
|
const config$4 = {
|
|
6621
6791
|
commandName: 'list',
|
|
6622
6792
|
description: 'List the full scans for an organization',
|
|
@@ -6692,12 +6862,13 @@ async function run$4(argv, importMeta, {
|
|
|
6692
6862
|
// options or missing arguments.
|
|
6693
6863
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
6694
6864
|
process.exitCode = 2;
|
|
6695
|
-
|
|
6865
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
6696
6866
|
- Org name as the argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n`);
|
|
6697
6867
|
return;
|
|
6698
6868
|
}
|
|
6699
6869
|
if (cli.flags['dryRun']) {
|
|
6700
|
-
|
|
6870
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$4);
|
|
6871
|
+
return;
|
|
6701
6872
|
}
|
|
6702
6873
|
const apiToken = index.getDefaultToken();
|
|
6703
6874
|
if (!apiToken) {
|
|
@@ -6719,18 +6890,24 @@ async function run$4(argv, importMeta, {
|
|
|
6719
6890
|
}
|
|
6720
6891
|
|
|
6721
6892
|
async function getOrgScanMetadata(orgSlug, scanId, apiToken) {
|
|
6722
|
-
|
|
6723
|
-
|
|
6893
|
+
// Lazily access constants.spinner.
|
|
6894
|
+
const {
|
|
6895
|
+
spinner
|
|
6896
|
+
} = constants;
|
|
6897
|
+
spinner.start("Getting scan's metadata...");
|
|
6724
6898
|
const socketSdk = await index.setupSdk(apiToken);
|
|
6725
6899
|
const result = await handleApiCall(socketSdk.getOrgFullScanMetadata(orgSlug, scanId), 'Listing scans');
|
|
6726
6900
|
if (!result.success) {
|
|
6727
|
-
handleUnsuccessfulApiResponse('getOrgFullScanMetadata', result, spinner
|
|
6901
|
+
handleUnsuccessfulApiResponse('getOrgFullScanMetadata', result, spinner);
|
|
6728
6902
|
return;
|
|
6729
6903
|
}
|
|
6730
|
-
spinner
|
|
6731
|
-
|
|
6904
|
+
spinner.stop('Scan metadata:');
|
|
6905
|
+
logger.logger.log(result.data);
|
|
6732
6906
|
}
|
|
6733
6907
|
|
|
6908
|
+
const {
|
|
6909
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$3
|
|
6910
|
+
} = constants;
|
|
6734
6911
|
const config$3 = {
|
|
6735
6912
|
commandName: 'metadata',
|
|
6736
6913
|
description: "Get a full scan's metadata",
|
|
@@ -6770,13 +6947,14 @@ async function run$3(argv, importMeta, {
|
|
|
6770
6947
|
// options or missing arguments.
|
|
6771
6948
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
6772
6949
|
process.exitCode = 2;
|
|
6773
|
-
|
|
6950
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
6774
6951
|
- Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
6775
6952
|
- Full Scan ID to inspect as second argument ${!fullScanId ? colors.red('(missing!)') : colors.green('(ok)')}\n`);
|
|
6776
6953
|
return;
|
|
6777
6954
|
}
|
|
6778
6955
|
if (cli.flags['dryRun']) {
|
|
6779
|
-
|
|
6956
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$3);
|
|
6957
|
+
return;
|
|
6780
6958
|
}
|
|
6781
6959
|
const apiToken = index.getDefaultToken();
|
|
6782
6960
|
if (!apiToken) {
|
|
@@ -6786,18 +6964,24 @@ async function run$3(argv, importMeta, {
|
|
|
6786
6964
|
}
|
|
6787
6965
|
|
|
6788
6966
|
async function getFullScan(orgSlug, fullScanId, file, apiToken) {
|
|
6789
|
-
|
|
6790
|
-
|
|
6967
|
+
// Lazily access constants.spinner.
|
|
6968
|
+
const {
|
|
6969
|
+
spinner
|
|
6970
|
+
} = constants;
|
|
6971
|
+
spinner.start('Streaming scan...');
|
|
6791
6972
|
const socketSdk = await index.setupSdk(apiToken);
|
|
6792
6973
|
const data = await handleApiCall(socketSdk.getOrgFullScan(orgSlug, fullScanId, file === '-' ? undefined : file), 'Streaming a scan');
|
|
6793
6974
|
if (data?.success) {
|
|
6794
|
-
spinner
|
|
6975
|
+
spinner.stop(file ? `Full scan details written to ${file}` : '');
|
|
6795
6976
|
} else {
|
|
6796
|
-
handleUnsuccessfulApiResponse('getOrgFullScan', data, spinner
|
|
6977
|
+
handleUnsuccessfulApiResponse('getOrgFullScan', data, spinner);
|
|
6797
6978
|
}
|
|
6798
6979
|
return data;
|
|
6799
6980
|
}
|
|
6800
6981
|
|
|
6982
|
+
const {
|
|
6983
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$2
|
|
6984
|
+
} = constants;
|
|
6801
6985
|
const config$2 = {
|
|
6802
6986
|
commandName: 'stream',
|
|
6803
6987
|
description: 'Stream the output of a scan',
|
|
@@ -6839,13 +7023,14 @@ async function run$2(argv, importMeta, {
|
|
|
6839
7023
|
// options or missing arguments.
|
|
6840
7024
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
6841
7025
|
process.exitCode = 2;
|
|
6842
|
-
|
|
7026
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
6843
7027
|
- Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
6844
7028
|
- Full Scan ID to fetch as second argument ${!fullScanId ? colors.red('(missing!)') : colors.green('(ok)')}\n`);
|
|
6845
7029
|
return;
|
|
6846
7030
|
}
|
|
6847
7031
|
if (cli.flags['dryRun']) {
|
|
6848
|
-
|
|
7032
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$2);
|
|
7033
|
+
return;
|
|
6849
7034
|
}
|
|
6850
7035
|
const apiToken = index.getDefaultToken();
|
|
6851
7036
|
if (!apiToken) {
|
|
@@ -6883,8 +7068,11 @@ async function getThreatFeed({
|
|
|
6883
7068
|
page,
|
|
6884
7069
|
perPage
|
|
6885
7070
|
}) {
|
|
6886
|
-
|
|
6887
|
-
|
|
7071
|
+
// Lazily access constants.spinner.
|
|
7072
|
+
const {
|
|
7073
|
+
spinner
|
|
7074
|
+
} = constants;
|
|
7075
|
+
spinner.start('Looking up the threat feed');
|
|
6888
7076
|
const formattedQueryParams = formatQueryParams({
|
|
6889
7077
|
per_page: perPage,
|
|
6890
7078
|
page,
|
|
@@ -6893,9 +7081,9 @@ async function getThreatFeed({
|
|
|
6893
7081
|
}).join('&');
|
|
6894
7082
|
const response = await queryAPI(`threat-feed?${formattedQueryParams}`, apiToken);
|
|
6895
7083
|
const data = await response.json();
|
|
6896
|
-
spinner
|
|
7084
|
+
spinner.stop();
|
|
6897
7085
|
if (outputJson) {
|
|
6898
|
-
|
|
7086
|
+
logger.logger.log(data);
|
|
6899
7087
|
return;
|
|
6900
7088
|
}
|
|
6901
7089
|
const screen = new ScreenWidget();
|
|
@@ -6950,6 +7138,9 @@ function getMinDiff(start, end) {
|
|
|
6950
7138
|
return Math.floor((end - start) / 60000);
|
|
6951
7139
|
}
|
|
6952
7140
|
|
|
7141
|
+
const {
|
|
7142
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$1
|
|
7143
|
+
} = constants;
|
|
6953
7144
|
const config$1 = {
|
|
6954
7145
|
commandName: 'threat-feed',
|
|
6955
7146
|
description: 'Look up the threat feed',
|
|
@@ -7009,7 +7200,8 @@ async function run$1(argv, importMeta, {
|
|
|
7009
7200
|
parentName
|
|
7010
7201
|
});
|
|
7011
7202
|
if (cli.flags['dryRun']) {
|
|
7012
|
-
|
|
7203
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$1);
|
|
7204
|
+
return;
|
|
7013
7205
|
}
|
|
7014
7206
|
const apiToken = index.getDefaultToken();
|
|
7015
7207
|
if (!apiToken) {
|
|
@@ -7032,7 +7224,7 @@ function addSocketWrapper(file) {
|
|
|
7032
7224
|
}
|
|
7033
7225
|
// TODO: pretty sure you need to source the file or restart
|
|
7034
7226
|
// any terminal session before changes are reflected.
|
|
7035
|
-
|
|
7227
|
+
logger.logger.log(`
|
|
7036
7228
|
The alias was added to ${file}. Running 'npm install' will now be wrapped in Socket's "safe npm" 🎉
|
|
7037
7229
|
If you want to disable it at any time, run \`socket wrapper --disable\`
|
|
7038
7230
|
`);
|
|
@@ -7043,7 +7235,7 @@ function checkSocketWrapperSetup(file) {
|
|
|
7043
7235
|
const fileContent = fs.readFileSync(file, 'utf8');
|
|
7044
7236
|
const linesWithSocketAlias = fileContent.split('\n').filter(l => l === 'alias npm="socket npm"' || l === 'alias npx="socket npx"');
|
|
7045
7237
|
if (linesWithSocketAlias.length) {
|
|
7046
|
-
|
|
7238
|
+
logger.logger.log(`The Socket npm/npx wrapper is set up in your bash profile (${file}).`);
|
|
7047
7239
|
return true;
|
|
7048
7240
|
}
|
|
7049
7241
|
return false;
|
|
@@ -7065,7 +7257,7 @@ function postinstallWrapper() {
|
|
|
7065
7257
|
}
|
|
7066
7258
|
}
|
|
7067
7259
|
function installSafeNpm(query) {
|
|
7068
|
-
|
|
7260
|
+
logger.logger.log(`
|
|
7069
7261
|
_____ _ _
|
|
7070
7262
|
| __|___ ___| |_ ___| |_
|
|
7071
7263
|
|__ | . | _| '_| -_| _|
|
|
@@ -7108,24 +7300,27 @@ function askQuestion(rl, query) {
|
|
|
7108
7300
|
function removeSocketWrapper(file) {
|
|
7109
7301
|
return fs.readFile(file, 'utf8', function (err, data) {
|
|
7110
7302
|
if (err) {
|
|
7111
|
-
|
|
7303
|
+
logger.logger.error('There was an error removing the alias:');
|
|
7304
|
+
logger.logger.error(err);
|
|
7112
7305
|
return;
|
|
7113
7306
|
}
|
|
7114
7307
|
const linesWithoutSocketAlias = data.split('\n').filter(l => l !== 'alias npm="socket npm"' && l !== 'alias npx="socket npx"');
|
|
7115
7308
|
const updatedFileContent = linesWithoutSocketAlias.join('\n');
|
|
7116
7309
|
fs.writeFile(file, updatedFileContent, function (err) {
|
|
7117
7310
|
if (err) {
|
|
7118
|
-
|
|
7311
|
+
logger.logger.error(err);
|
|
7119
7312
|
return;
|
|
7120
|
-
} else {
|
|
7121
|
-
// TODO: pretty sure you need to source the file or restart
|
|
7122
|
-
// any terminal session before changes are reflected.
|
|
7123
|
-
console.log(`\nThe alias was removed from ${file}. Running 'npm install' will now run the standard npm command.\n`);
|
|
7124
7313
|
}
|
|
7314
|
+
// TODO: pretty sure you need to source the file or restart
|
|
7315
|
+
// any terminal session before changes are reflected.
|
|
7316
|
+
logger.logger.log(`The alias was removed from ${file}. Running 'npm install' will now run the standard npm command.`);
|
|
7125
7317
|
});
|
|
7126
7318
|
});
|
|
7127
7319
|
}
|
|
7128
7320
|
|
|
7321
|
+
const {
|
|
7322
|
+
DRY_RUN_BAIL_TEXT
|
|
7323
|
+
} = constants;
|
|
7129
7324
|
const config = {
|
|
7130
7325
|
commandName: 'wrapper',
|
|
7131
7326
|
description: 'Enable or disable the Socket npm/npx wrapper',
|
|
@@ -7182,12 +7377,13 @@ async function run(argv, importMeta, {
|
|
|
7182
7377
|
// options or missing arguments.
|
|
7183
7378
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
7184
7379
|
process.exitCode = 2;
|
|
7185
|
-
|
|
7380
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required flags:\n
|
|
7186
7381
|
- Must use --enabled or --disabled\n`);
|
|
7187
7382
|
return;
|
|
7188
7383
|
}
|
|
7189
7384
|
if (cli.flags['dryRun']) {
|
|
7190
|
-
|
|
7385
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT);
|
|
7386
|
+
return;
|
|
7191
7387
|
}
|
|
7192
7388
|
|
|
7193
7389
|
// Lazily access constants.bashRcPath and constants.zshRcPath.
|
|
@@ -7211,7 +7407,7 @@ async function run(argv, importMeta, {
|
|
|
7211
7407
|
}
|
|
7212
7408
|
}
|
|
7213
7409
|
if (!fs.existsSync(bashRcPath) && !fs.existsSync(zshRcPath)) {
|
|
7214
|
-
|
|
7410
|
+
logger.logger.error('There was an issue setting up the alias in your bash profile');
|
|
7215
7411
|
}
|
|
7216
7412
|
}
|
|
7217
7413
|
|
|
@@ -7286,10 +7482,10 @@ void (async () => {
|
|
|
7286
7482
|
}
|
|
7287
7483
|
logger.logger.error(`${colors.bgRed(colors.white(errorTitle + ':'))} ${errorMessage}`);
|
|
7288
7484
|
if (errorBody) {
|
|
7289
|
-
|
|
7485
|
+
logger.logger.error(`\n${errorBody}`);
|
|
7290
7486
|
}
|
|
7291
7487
|
await index.captureException(e);
|
|
7292
7488
|
}
|
|
7293
7489
|
})();
|
|
7294
|
-
//# debugId=
|
|
7490
|
+
//# debugId=58e6ceed-07a5-4b32-b0e9-9fef0ceef6d7
|
|
7295
7491
|
//# sourceMappingURL=cli.js.map
|