@socketsecurity/cli-with-sentry 0.14.51 → 0.14.53
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/cli.js +10 -15
- package/dist/constants.d.ts +29 -4
- package/dist/constants.js +8 -2
- package/dist/constants.js.map +1 -1
- package/dist/instrument-with-sentry.js +7 -10
- package/dist/instrument-with-sentry.js.map +1 -1
- package/dist/module-sync/cli.js +670 -446
- package/dist/module-sync/cli.js.map +1 -1
- package/dist/module-sync/edge.d.ts +1 -1
- package/dist/module-sync/index.d.ts +22 -22
- package/dist/module-sync/index.js +5 -4
- package/dist/module-sync/index.js.map +1 -1
- package/dist/module-sync/npm-paths.js +12 -23
- package/dist/module-sync/npm-paths.js.map +1 -1
- package/dist/module-sync/path-resolve.d.ts +1 -2
- package/dist/module-sync/reify.d.ts +8 -8
- package/dist/module-sync/settings.d.ts +1 -1
- package/dist/module-sync/shadow-bin.js +5 -10
- package/dist/module-sync/shadow-bin.js.map +1 -1
- package/dist/require/cli.js +670 -446
- package/dist/require/cli.js.map +1 -1
- package/package.json +5 -5
- package/dist/module-sync/debug.d.ts +0 -3
- package/dist/module-sync/npm.d.ts +0 -26
- package/dist/module-sync/npm.js +0 -113
- package/dist/module-sync/npm.js.map +0 -1
- package/dist/require/npm.js +0 -3
package/dist/module-sync/cli.js
CHANGED
|
@@ -25,14 +25,13 @@ var path = require('node:path');
|
|
|
25
25
|
var ndjson = _socketInterop(require('ndjson'));
|
|
26
26
|
var rest = _socketInterop(require('@octokit/rest'));
|
|
27
27
|
var index = require('./index.js');
|
|
28
|
+
var constants = require('./constants.js');
|
|
28
29
|
var meow = _socketInterop(require('meow'));
|
|
29
30
|
var objects = require('@socketsecurity/registry/lib/objects');
|
|
30
31
|
var regexps = require('@socketsecurity/registry/lib/regexps');
|
|
31
|
-
var constants = require('./constants.js');
|
|
32
32
|
var fs$1 = require('node:fs/promises');
|
|
33
33
|
var ScreenWidget = _socketInterop(require('blessed/lib/widgets/screen'));
|
|
34
34
|
var contrib = _socketInterop(require('blessed-contrib'));
|
|
35
|
-
var spinner = require('@socketsecurity/registry/lib/spinner');
|
|
36
35
|
var prompts = require('@socketsecurity/registry/lib/prompts');
|
|
37
36
|
var yargsParse = _socketInterop(require('yargs-parser'));
|
|
38
37
|
var words = require('@socketsecurity/registry/lib/words');
|
|
@@ -44,7 +43,7 @@ var packages = require('@socketsecurity/registry/lib/packages');
|
|
|
44
43
|
var registryConstants = require('@socketsecurity/registry/lib/constants');
|
|
45
44
|
var isInteractive = require('@socketregistry/is-interactive/index.cjs');
|
|
46
45
|
var terminalLink = _socketInterop(require('terminal-link'));
|
|
47
|
-
var spawn =
|
|
46
|
+
var spawn = require('@socketsecurity/registry/lib/spawn');
|
|
48
47
|
var npa = _socketInterop(require('npm-package-arg'));
|
|
49
48
|
var semver = _socketInterop(require('semver'));
|
|
50
49
|
var tinyglobby = _socketInterop(require('tinyglobby'));
|
|
@@ -55,14 +54,13 @@ var index_cjs = require('@socketregistry/hyrious__bun.lockb/index.cjs');
|
|
|
55
54
|
var sorts = require('@socketsecurity/registry/lib/sorts');
|
|
56
55
|
var strings = require('@socketsecurity/registry/lib/strings');
|
|
57
56
|
var yaml = _socketInterop(require('yaml'));
|
|
57
|
+
var debug = require('@socketsecurity/registry/lib/debug');
|
|
58
58
|
var npmPaths = require('./npm-paths.js');
|
|
59
|
-
var npm$1 = require('./npm.js');
|
|
60
59
|
var betterAjvErrors = _socketInterop(require('@apideck/better-ajv-errors'));
|
|
61
60
|
var config$A = require('@socketsecurity/config');
|
|
62
61
|
var assert = require('node:assert');
|
|
63
62
|
var readline = require('node:readline/promises');
|
|
64
63
|
var open = _socketInterop(require('open'));
|
|
65
|
-
var node_child_process = require('node:child_process');
|
|
66
64
|
var TableWidget = _socketInterop(require('blessed-contrib/lib/widget/table'));
|
|
67
65
|
var readline$1 = require('node:readline');
|
|
68
66
|
|
|
@@ -267,7 +265,6 @@ class Score {
|
|
|
267
265
|
}
|
|
268
266
|
|
|
269
267
|
// https://github.com/SocketDev/socket-python-cli/blob/6d4fc56faee68d3a4764f1f80f84710635bdaf05/socketsecurity/core/__init__.py
|
|
270
|
-
/* eslint-disable no-await-in-loop */
|
|
271
268
|
class Core {
|
|
272
269
|
securityPolicy = {};
|
|
273
270
|
constructor({
|
|
@@ -562,6 +559,7 @@ class Core {
|
|
|
562
559
|
diff.newPackages.push(purl);
|
|
563
560
|
consolidated.add(basePurl);
|
|
564
561
|
}
|
|
562
|
+
// eslint-disable-next-line no-await-in-loop
|
|
565
563
|
newScanAlerts = await this.createIssueAlerts({
|
|
566
564
|
pkg,
|
|
567
565
|
alerts: newScanAlerts,
|
|
@@ -579,6 +577,7 @@ class Core {
|
|
|
579
577
|
if (!(packageId in newPackages) && pkg.direct) {
|
|
580
578
|
diff.removedPackages.push(purl);
|
|
581
579
|
}
|
|
580
|
+
// eslint-disable-next-line no-await-in-loop
|
|
582
581
|
headScanAlerts = await this.createIssueAlerts({
|
|
583
582
|
pkg,
|
|
584
583
|
alerts: headScanAlerts,
|
|
@@ -644,7 +643,7 @@ class Core {
|
|
|
644
643
|
license: sbomArtifact.license
|
|
645
644
|
});
|
|
646
645
|
if (pkg.id in packages) {
|
|
647
|
-
|
|
646
|
+
logger.logger.log('Duplicate package?');
|
|
648
647
|
} else {
|
|
649
648
|
pkg = this.getLicenseDetails({
|
|
650
649
|
package: pkg
|
|
@@ -684,8 +683,8 @@ class Core {
|
|
|
684
683
|
});
|
|
685
684
|
}
|
|
686
685
|
}
|
|
687
|
-
} catch (
|
|
688
|
-
|
|
686
|
+
} catch (e) {
|
|
687
|
+
logger.logger.error(e);
|
|
689
688
|
}
|
|
690
689
|
const newFullScan = await this.createFullScan({
|
|
691
690
|
params
|
|
@@ -709,7 +708,6 @@ class Core {
|
|
|
709
708
|
}
|
|
710
709
|
|
|
711
710
|
// https://github.com/SocketDev/socket-python-cli/blob/6d4fc56faee68d3a4764f1f80f84710635bdaf05/socketsecurity/core/scm_comments.py
|
|
712
|
-
|
|
713
711
|
function checkForSocketComments({
|
|
714
712
|
comments
|
|
715
713
|
}) {
|
|
@@ -839,9 +837,9 @@ function getIgnoreOptions({
|
|
|
839
837
|
const data = `${name}/${version}`;
|
|
840
838
|
ignoreCommands.push(data);
|
|
841
839
|
}
|
|
842
|
-
} catch (
|
|
843
|
-
|
|
844
|
-
|
|
840
|
+
} catch (e) {
|
|
841
|
+
logger.logger.error(`Unable to process ignore command for ${comment}`);
|
|
842
|
+
logger.logger.error(e);
|
|
845
843
|
}
|
|
846
844
|
}
|
|
847
845
|
}
|
|
@@ -872,9 +870,9 @@ function removeAlerts({
|
|
|
872
870
|
const purl = `${fullName}/${alert.pkg_version}`;
|
|
873
871
|
const purlStar = `${fullName}/*`;
|
|
874
872
|
if (ignoreCommands.includes(purl) || ignoreCommands.includes(purlStar)) {
|
|
875
|
-
|
|
873
|
+
logger.logger.log(`Alerts for ${alert.pkg_name}@${alert.pkg_version} ignored`);
|
|
876
874
|
} else {
|
|
877
|
-
|
|
875
|
+
logger.logger.log(`Adding alert ${alert.type} for ${alert.pkg_name}@${alert.pkg_version}`);
|
|
878
876
|
alerts.push(alert);
|
|
879
877
|
}
|
|
880
878
|
}
|
|
@@ -912,7 +910,7 @@ class GitHub {
|
|
|
912
910
|
if (['opened', 'synchronize'].includes(eventAction)) {
|
|
913
911
|
return 'diff';
|
|
914
912
|
} else {
|
|
915
|
-
|
|
913
|
+
logger.logger.log(`Pull request action: ${eventAction} is not supported`);
|
|
916
914
|
process.exit();
|
|
917
915
|
}
|
|
918
916
|
case 'issue_comment':
|
|
@@ -1027,30 +1025,30 @@ class GitHub {
|
|
|
1027
1025
|
security: existingSecurityComment
|
|
1028
1026
|
} = comments;
|
|
1029
1027
|
if (newOverviewComment) {
|
|
1030
|
-
|
|
1028
|
+
logger.logger.log('New Dependency Overview comment');
|
|
1031
1029
|
if (existingOverviewComment !== undefined) {
|
|
1032
|
-
|
|
1030
|
+
logger.logger.log('Previous version of Dependency Overview, updating');
|
|
1033
1031
|
await this.updateComment({
|
|
1034
1032
|
body: overviewComment,
|
|
1035
1033
|
id: existingOverviewComment.id
|
|
1036
1034
|
});
|
|
1037
1035
|
} else {
|
|
1038
|
-
|
|
1036
|
+
logger.logger.log('No previous version of Dependency Overview, posting');
|
|
1039
1037
|
await this.postComment({
|
|
1040
1038
|
body: overviewComment
|
|
1041
1039
|
});
|
|
1042
1040
|
}
|
|
1043
1041
|
}
|
|
1044
1042
|
if (newSecurityComment) {
|
|
1045
|
-
|
|
1043
|
+
logger.logger.log('New Security Issue Comment');
|
|
1046
1044
|
if (existingSecurityComment !== undefined) {
|
|
1047
|
-
|
|
1045
|
+
logger.logger.log('Previous version of Security Issue comment, updating');
|
|
1048
1046
|
await this.updateComment({
|
|
1049
1047
|
body: securityComment,
|
|
1050
1048
|
id: existingSecurityComment.id
|
|
1051
1049
|
});
|
|
1052
1050
|
} else {
|
|
1053
|
-
|
|
1051
|
+
logger.logger.log('No Previous version of Security Issue comment, posting');
|
|
1054
1052
|
await this.postComment({
|
|
1055
1053
|
body: securityComment
|
|
1056
1054
|
});
|
|
@@ -1229,7 +1227,7 @@ async function runAction(githubEventBefore, githubEventAfter) {
|
|
|
1229
1227
|
const socket = new sdk.SocketSdk(index.getDefaultToken());
|
|
1230
1228
|
const git = simpleGit.simpleGit();
|
|
1231
1229
|
const changedFiles = (await git.diff(process.env['GITHUB_EVENT_NAME'] === 'pull_request' ? ['--name-only', 'HEAD^1', 'HEAD'] : ['--name-only', githubEventBefore, githubEventAfter])).split('\n');
|
|
1232
|
-
|
|
1230
|
+
logger.logger.log({
|
|
1233
1231
|
changedFiles
|
|
1234
1232
|
});
|
|
1235
1233
|
// supportedFiles have 3-level deep globs
|
|
@@ -1237,13 +1235,13 @@ async function runAction(githubEventBefore, githubEventAfter) {
|
|
|
1237
1235
|
const files = micromatch(changedFiles, patterns);
|
|
1238
1236
|
const scm = new GitHub();
|
|
1239
1237
|
if (scm.checkEventType() === 'comment') {
|
|
1240
|
-
|
|
1238
|
+
logger.logger.log('Comment initiated flow');
|
|
1241
1239
|
const comments = await scm.getCommentsForPR();
|
|
1242
1240
|
await scm.removeCommentAlerts({
|
|
1243
1241
|
comments
|
|
1244
1242
|
});
|
|
1245
1243
|
} else if (scm.checkEventType() === 'diff') {
|
|
1246
|
-
|
|
1244
|
+
logger.logger.log('Push initiated flow');
|
|
1247
1245
|
const core = new Core({
|
|
1248
1246
|
owner: scm.owner,
|
|
1249
1247
|
repo: scm.repo,
|
|
@@ -1265,17 +1263,17 @@ async function runAction(githubEventBefore, githubEventAfter) {
|
|
|
1265
1263
|
if (diff.newAlerts.length === 0) {
|
|
1266
1264
|
if (!updateOldSecurityComment) {
|
|
1267
1265
|
newSecurityComment = false;
|
|
1268
|
-
|
|
1266
|
+
logger.logger.log('No new alerts or security issue comment disabled');
|
|
1269
1267
|
} else {
|
|
1270
|
-
|
|
1268
|
+
logger.logger.log('Updated security comment with no new alerts');
|
|
1271
1269
|
}
|
|
1272
1270
|
}
|
|
1273
1271
|
if (diff.newPackages.length === 0 && diff.removedPackages.length === 0) {
|
|
1274
1272
|
if (!updateOldOverviewComment) {
|
|
1275
1273
|
newOverviewComment = false;
|
|
1276
|
-
|
|
1274
|
+
logger.logger.log('No new/removed packages or Dependency Overview comment disabled');
|
|
1277
1275
|
} else {
|
|
1278
|
-
|
|
1276
|
+
logger.logger.log('Updated overview comment with no dependencies');
|
|
1279
1277
|
}
|
|
1280
1278
|
}
|
|
1281
1279
|
await scm.addSocketComments({
|
|
@@ -1403,6 +1401,8 @@ const validationFlags = {
|
|
|
1403
1401
|
};
|
|
1404
1402
|
|
|
1405
1403
|
const {
|
|
1404
|
+
DRY_RUN_LABEL: DRY_RUN_LABEL$1,
|
|
1405
|
+
REDACTED,
|
|
1406
1406
|
SOCKET_CLI_SHOW_BANNER
|
|
1407
1407
|
} = constants;
|
|
1408
1408
|
async function meowWithSubcommands(subcommands, options) {
|
|
@@ -1440,7 +1440,7 @@ async function meowWithSubcommands(subcommands, options) {
|
|
|
1440
1440
|
// Temp disable until we clear the --json and --markdown usage
|
|
1441
1441
|
// Lazily access constants.ENV[SOCKET_CLI_SHOW_BANNER].
|
|
1442
1442
|
if (constants.ENV[SOCKET_CLI_SHOW_BANNER]) {
|
|
1443
|
-
|
|
1443
|
+
logger.logger.log(getAsciiHeader(name));
|
|
1444
1444
|
}
|
|
1445
1445
|
const cli = meow(`
|
|
1446
1446
|
Usage
|
|
@@ -1476,7 +1476,7 @@ async function meowWithSubcommands(subcommands, options) {
|
|
|
1476
1476
|
autoHelp: false // otherwise we can't exit(0)
|
|
1477
1477
|
});
|
|
1478
1478
|
if (!cli.flags['help'] && cli.flags['dryRun']) {
|
|
1479
|
-
|
|
1479
|
+
logger.logger.log(`${DRY_RUN_LABEL$1}: No-op, call a sub-command; ok`);
|
|
1480
1480
|
process.exitCode = 0;
|
|
1481
1481
|
} else {
|
|
1482
1482
|
cli.showHelp();
|
|
@@ -1498,7 +1498,7 @@ function meowOrExit({
|
|
|
1498
1498
|
// Temp disable until we clear the --json and --markdown usage.
|
|
1499
1499
|
// Lazily access constants.ENV[SOCKET_CLI_SHOW_BANNER].
|
|
1500
1500
|
if (constants.ENV[SOCKET_CLI_SHOW_BANNER]) {
|
|
1501
|
-
|
|
1501
|
+
logger.logger.log(getAsciiHeader(command));
|
|
1502
1502
|
}
|
|
1503
1503
|
|
|
1504
1504
|
// This exits if .printHelp() is called either by meow itself or by us.
|
|
@@ -1518,7 +1518,7 @@ function meowOrExit({
|
|
|
1518
1518
|
}
|
|
1519
1519
|
function getAsciiHeader(command) {
|
|
1520
1520
|
const cliVersion = // The '@rollup/plugin-replace' will replace "process.env['SOCKET_CLI_VERSION_HASH']".
|
|
1521
|
-
"0.14.
|
|
1521
|
+
"0.14.53:e7fcb39:b41fef49:pub";
|
|
1522
1522
|
const nodeVersion = process.version;
|
|
1523
1523
|
const apiToken = index.getSetting('apiToken');
|
|
1524
1524
|
const shownToken = apiToken ? getLastFiveOfApiToken(apiToken) : 'no';
|
|
@@ -1533,6 +1533,9 @@ function getAsciiHeader(command) {
|
|
|
1533
1533
|
|
|
1534
1534
|
// https://github.com/SocketDev/socket-python-cli/blob/6d4fc56faee68d3a4764f1f80f84710635bdaf05/socketsecurity/socketcli.py
|
|
1535
1535
|
|
|
1536
|
+
const {
|
|
1537
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$y
|
|
1538
|
+
} = constants;
|
|
1536
1539
|
const config$z = {
|
|
1537
1540
|
commandName: 'action',
|
|
1538
1541
|
description: 'Socket action command',
|
|
@@ -1583,7 +1586,8 @@ async function run$z(argv, importMeta, {
|
|
|
1583
1586
|
const githubEventBefore = String(cli.flags['githubEventBefore'] || '');
|
|
1584
1587
|
const githubEventAfter = String(cli.flags['githubEventAfter'] || '');
|
|
1585
1588
|
if (cli.flags['dryRun']) {
|
|
1586
|
-
|
|
1589
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$y);
|
|
1590
|
+
return;
|
|
1587
1591
|
}
|
|
1588
1592
|
await runAction(githubEventBefore, githubEventAfter);
|
|
1589
1593
|
}
|
|
@@ -1601,24 +1605,26 @@ async function displayAnalytics({
|
|
|
1601
1605
|
scope,
|
|
1602
1606
|
time
|
|
1603
1607
|
}) {
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1608
|
+
// Lazily access constants.spinner.
|
|
1609
|
+
const {
|
|
1610
|
+
spinner
|
|
1611
|
+
} = constants;
|
|
1612
|
+
spinner.start('Fetching analytics data');
|
|
1607
1613
|
let data;
|
|
1608
1614
|
if (scope === 'org') {
|
|
1609
|
-
data = await fetchOrgAnalyticsData(time, spinner
|
|
1615
|
+
data = await fetchOrgAnalyticsData(time, spinner, apiToken);
|
|
1610
1616
|
} else if (repo) {
|
|
1611
|
-
data = await fetchRepoAnalyticsData(repo, time, spinner
|
|
1617
|
+
data = await fetchRepoAnalyticsData(repo, time, spinner, apiToken);
|
|
1612
1618
|
}
|
|
1613
1619
|
if (data) {
|
|
1614
1620
|
if (outputJson && !filePath) {
|
|
1615
|
-
|
|
1621
|
+
logger.logger.log(data);
|
|
1616
1622
|
} else if (filePath) {
|
|
1617
1623
|
try {
|
|
1618
1624
|
await fs$1.writeFile(filePath, JSON.stringify(data), 'utf8');
|
|
1619
|
-
|
|
1625
|
+
logger.logger.log(`Data successfully written to ${filePath}`);
|
|
1620
1626
|
} catch (e) {
|
|
1621
|
-
|
|
1627
|
+
logger.logger.error(e);
|
|
1622
1628
|
}
|
|
1623
1629
|
} else {
|
|
1624
1630
|
const fdata = scope === 'org' ? formatData(data, 'org') : formatData(data, 'repo');
|
|
@@ -1667,7 +1673,7 @@ async function fetchOrgAnalyticsData(time, spinner, apiToken) {
|
|
|
1667
1673
|
}
|
|
1668
1674
|
spinner.stop();
|
|
1669
1675
|
if (!result.data.length) {
|
|
1670
|
-
|
|
1676
|
+
logger.logger.log('No analytics data is available for this organization yet.');
|
|
1671
1677
|
return undefined;
|
|
1672
1678
|
}
|
|
1673
1679
|
return result.data;
|
|
@@ -1681,7 +1687,7 @@ async function fetchRepoAnalyticsData(repo, time, spinner, apiToken) {
|
|
|
1681
1687
|
}
|
|
1682
1688
|
spinner.stop();
|
|
1683
1689
|
if (!result.data.length) {
|
|
1684
|
-
|
|
1690
|
+
logger.logger.log('No analytics data is available for this organization yet.');
|
|
1685
1691
|
return undefined;
|
|
1686
1692
|
}
|
|
1687
1693
|
return result.data;
|
|
@@ -1777,6 +1783,9 @@ function renderLineCharts(grid, screen, title, coords, data) {
|
|
|
1777
1783
|
line.setData([lineData]);
|
|
1778
1784
|
}
|
|
1779
1785
|
|
|
1786
|
+
const {
|
|
1787
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$x
|
|
1788
|
+
} = constants;
|
|
1780
1789
|
const config$y = {
|
|
1781
1790
|
commandName: 'analytics',
|
|
1782
1791
|
description: `Look up analytics data`,
|
|
@@ -1854,14 +1863,15 @@ async function run$y(argv, importMeta, {
|
|
|
1854
1863
|
// options or missing arguments.
|
|
1855
1864
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
1856
1865
|
process.exitCode = 2;
|
|
1857
|
-
|
|
1866
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
1858
1867
|
- Scope must be "repo" or "org" ${badScope ? colors.red('(bad!)') : colors.green('(ok)')}\n
|
|
1859
1868
|
- The time filter must either be 7, 30 or 90 ${badTime ? colors.red('(bad!)') : colors.green('(ok)')}\n
|
|
1860
1869
|
- Repository name using --repo when scope is "repo" ${badRepo ? colors.red('(bad!)') : colors.green('(ok)')}\n`);
|
|
1861
1870
|
return;
|
|
1862
1871
|
}
|
|
1863
1872
|
if (cli.flags['dryRun']) {
|
|
1864
|
-
|
|
1873
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$x);
|
|
1874
|
+
return;
|
|
1865
1875
|
}
|
|
1866
1876
|
const apiToken = index.getDefaultToken();
|
|
1867
1877
|
if (!apiToken) {
|
|
@@ -1886,9 +1896,11 @@ async function getAuditLog({
|
|
|
1886
1896
|
perPage,
|
|
1887
1897
|
type
|
|
1888
1898
|
}) {
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1899
|
+
// Lazily access constants.spinner.
|
|
1900
|
+
const {
|
|
1901
|
+
spinner
|
|
1902
|
+
} = constants;
|
|
1903
|
+
spinner.start(`Looking up audit log for ${orgSlug}`);
|
|
1892
1904
|
const socketSdk = await index.setupSdk(apiToken);
|
|
1893
1905
|
const result = await handleApiCall(socketSdk.getAuditLogEvents(orgSlug, {
|
|
1894
1906
|
outputJson,
|
|
@@ -1899,10 +1911,10 @@ async function getAuditLog({
|
|
|
1899
1911
|
per_page: perPage
|
|
1900
1912
|
}), `Looking up audit log for ${orgSlug}\n`);
|
|
1901
1913
|
if (!result.success) {
|
|
1902
|
-
handleUnsuccessfulApiResponse('getAuditLogEvents', result, spinner
|
|
1914
|
+
handleUnsuccessfulApiResponse('getAuditLogEvents', result, spinner);
|
|
1903
1915
|
return;
|
|
1904
1916
|
}
|
|
1905
|
-
spinner
|
|
1917
|
+
spinner.stop();
|
|
1906
1918
|
const data = [];
|
|
1907
1919
|
const logDetails = {};
|
|
1908
1920
|
for (const d of result.data.results) {
|
|
@@ -1921,13 +1933,16 @@ async function getAuditLog({
|
|
|
1921
1933
|
logDetails[name] = JSON.stringify(d.payload);
|
|
1922
1934
|
}
|
|
1923
1935
|
}
|
|
1924
|
-
|
|
1936
|
+
logger.logger.log(logDetails[await prompts.select({
|
|
1925
1937
|
message: type ? `\n Audit log for: ${orgSlug} with type: ${type}\n` : `\n Audit log for: ${orgSlug}\n`,
|
|
1926
1938
|
choices: data,
|
|
1927
1939
|
pageSize: 30
|
|
1928
1940
|
})]);
|
|
1929
1941
|
}
|
|
1930
1942
|
|
|
1943
|
+
const {
|
|
1944
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$w
|
|
1945
|
+
} = constants;
|
|
1931
1946
|
const config$x = {
|
|
1932
1947
|
commandName: 'audit-log',
|
|
1933
1948
|
description: 'Look up the audit log for an organization',
|
|
@@ -1986,12 +2001,13 @@ async function run$x(argv, importMeta, {
|
|
|
1986
2001
|
// options or missing arguments.
|
|
1987
2002
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
1988
2003
|
process.exitCode = 2;
|
|
1989
|
-
|
|
2004
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
1990
2005
|
- Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n`);
|
|
1991
2006
|
return;
|
|
1992
2007
|
}
|
|
1993
2008
|
if (cli.flags['dryRun']) {
|
|
1994
|
-
|
|
2009
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$w);
|
|
2010
|
+
return;
|
|
1995
2011
|
}
|
|
1996
2012
|
const apiToken = index.getDefaultToken();
|
|
1997
2013
|
if (!apiToken) {
|
|
@@ -2053,7 +2069,7 @@ async function runCycloneDX(yargv) {
|
|
|
2053
2069
|
}
|
|
2054
2070
|
const fullOutputPath = path.join(process$1.cwd(), yargv.output);
|
|
2055
2071
|
if (fs.existsSync(fullOutputPath)) {
|
|
2056
|
-
|
|
2072
|
+
logger.logger.log(colors.cyanBright(`${yargv.output} created!`));
|
|
2057
2073
|
}
|
|
2058
2074
|
}
|
|
2059
2075
|
function argvToArray(argv) {
|
|
@@ -2083,6 +2099,10 @@ function argvToArray(argv) {
|
|
|
2083
2099
|
}
|
|
2084
2100
|
|
|
2085
2101
|
// import { meowOrExit } from '../../utils/meow-with-subcommands'
|
|
2102
|
+
const {
|
|
2103
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$v
|
|
2104
|
+
} = constants;
|
|
2105
|
+
|
|
2086
2106
|
// TODO: convert yargs to meow. Or convert all the other things to yargs.
|
|
2087
2107
|
const toLower = arg => arg.toLowerCase();
|
|
2088
2108
|
const arrayToLower = arg => arg.map(toLower);
|
|
@@ -2187,7 +2207,7 @@ async function run$w(argv, importMeta, {
|
|
|
2187
2207
|
//
|
|
2188
2208
|
//
|
|
2189
2209
|
// if (cli.input.length)
|
|
2190
|
-
//
|
|
2210
|
+
// logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
2191
2211
|
// - Unexpected arguments\n
|
|
2192
2212
|
// `)
|
|
2193
2213
|
// config.help(parentName, config)
|
|
@@ -2208,14 +2228,15 @@ async function run$w(argv, importMeta, {
|
|
|
2208
2228
|
// options or missing arguments.
|
|
2209
2229
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
2210
2230
|
process$1.exitCode = 2;
|
|
2211
|
-
|
|
2231
|
+
logger.logger.error(`Unknown ${words.pluralize('argument', unknownLength)}: ${yargv._.join(', ')}`);
|
|
2212
2232
|
return;
|
|
2213
2233
|
}
|
|
2214
2234
|
if (yargv.output === undefined) {
|
|
2215
2235
|
yargv.output = 'socket-cdx.json';
|
|
2216
2236
|
}
|
|
2217
2237
|
if (cli.flags['dryRun']) {
|
|
2218
|
-
|
|
2238
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$v);
|
|
2239
|
+
return;
|
|
2219
2240
|
}
|
|
2220
2241
|
await runCycloneDX(yargv);
|
|
2221
2242
|
}
|
|
@@ -2230,21 +2251,23 @@ async function findDependencies({
|
|
|
2230
2251
|
if (!apiToken) {
|
|
2231
2252
|
throw new index.AuthError('User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.');
|
|
2232
2253
|
}
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2254
|
+
// Lazily access constants.spinner.
|
|
2255
|
+
const {
|
|
2256
|
+
spinner
|
|
2257
|
+
} = constants;
|
|
2258
|
+
spinner.start('Searching dependencies...');
|
|
2236
2259
|
const socketSdk = await index.setupSdk(apiToken);
|
|
2237
2260
|
const result = await handleApiCall(socketSdk.searchDependencies({
|
|
2238
2261
|
limit,
|
|
2239
2262
|
offset
|
|
2240
2263
|
}), 'Searching dependencies');
|
|
2241
2264
|
if (!result.success) {
|
|
2242
|
-
handleUnsuccessfulApiResponse('searchDependencies', result, spinner
|
|
2265
|
+
handleUnsuccessfulApiResponse('searchDependencies', result, spinner);
|
|
2243
2266
|
return;
|
|
2244
2267
|
}
|
|
2245
|
-
spinner
|
|
2268
|
+
spinner.stop('Organization dependencies:');
|
|
2246
2269
|
if (outputJson) {
|
|
2247
|
-
|
|
2270
|
+
logger.logger.log(result.data);
|
|
2248
2271
|
return;
|
|
2249
2272
|
}
|
|
2250
2273
|
const options = {
|
|
@@ -2271,9 +2294,12 @@ async function findDependencies({
|
|
|
2271
2294
|
name: colors.cyan('Direct')
|
|
2272
2295
|
}]
|
|
2273
2296
|
};
|
|
2274
|
-
|
|
2297
|
+
logger.logger.log(chalkTable(options, result.data.rows));
|
|
2275
2298
|
}
|
|
2276
2299
|
|
|
2300
|
+
const {
|
|
2301
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$u
|
|
2302
|
+
} = constants;
|
|
2277
2303
|
const config$v = {
|
|
2278
2304
|
commandName: 'dependencies',
|
|
2279
2305
|
description: 'Search for any dependency that is being used in your organization',
|
|
@@ -2320,7 +2346,8 @@ async function run$v(argv, importMeta, {
|
|
|
2320
2346
|
parentName
|
|
2321
2347
|
});
|
|
2322
2348
|
if (cli.flags['dryRun']) {
|
|
2323
|
-
|
|
2349
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$u);
|
|
2350
|
+
return;
|
|
2324
2351
|
}
|
|
2325
2352
|
|
|
2326
2353
|
// TODO: markdown flag is ignored
|
|
@@ -2338,38 +2365,44 @@ async function getDiffScan({
|
|
|
2338
2365
|
orgSlug,
|
|
2339
2366
|
outputJson
|
|
2340
2367
|
}, apiToken) {
|
|
2341
|
-
|
|
2342
|
-
|
|
2368
|
+
// Lazily access constants.spinner.
|
|
2369
|
+
const {
|
|
2370
|
+
spinner
|
|
2371
|
+
} = constants;
|
|
2372
|
+
spinner.start('Getting diff scan...');
|
|
2343
2373
|
const response = await queryAPI(`${orgSlug}/full-scans/diff?before=${before}&after=${after}&preview`, apiToken);
|
|
2344
2374
|
const data = await response.json();
|
|
2345
2375
|
if (!response.ok) {
|
|
2346
2376
|
const err = await handleAPIError(response.status);
|
|
2347
|
-
spinner
|
|
2377
|
+
spinner.errorAndStop(`${colors.bgRed(colors.white(response.statusText))}: ${err}`);
|
|
2348
2378
|
return;
|
|
2349
2379
|
}
|
|
2350
|
-
spinner
|
|
2380
|
+
spinner.stop();
|
|
2351
2381
|
if (file && !outputJson) {
|
|
2352
2382
|
fs.writeFile(file, JSON.stringify(data), err => {
|
|
2353
|
-
err ?
|
|
2383
|
+
err ? logger.logger.error(err) : logger.logger.log(`Data successfully written to ${file}`);
|
|
2354
2384
|
});
|
|
2355
2385
|
return;
|
|
2356
2386
|
}
|
|
2357
2387
|
if (outputJson) {
|
|
2358
|
-
|
|
2359
|
-
|
|
2388
|
+
logger.logger.log(`\n Diff scan result: \n`);
|
|
2389
|
+
logger.logger.log(util.inspect(data, {
|
|
2360
2390
|
showHidden: false,
|
|
2361
2391
|
depth: null,
|
|
2362
2392
|
colors: true
|
|
2363
2393
|
}));
|
|
2364
|
-
|
|
2394
|
+
logger.logger.log(`\n View this diff scan in the Socket dashboard: ${colors.cyan(data?.['diff_report_url'])}`);
|
|
2365
2395
|
return;
|
|
2366
2396
|
}
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2397
|
+
logger.logger.log('Diff scan result:');
|
|
2398
|
+
logger.logger.log(data);
|
|
2399
|
+
logger.logger.log(`\n 📝 To display the detailed report in the terminal, use the --json flag \n`);
|
|
2400
|
+
logger.logger.log(`\n View this diff scan in the Socket dashboard: ${colors.cyan(data?.['diff_report_url'])}`);
|
|
2371
2401
|
}
|
|
2372
2402
|
|
|
2403
|
+
const {
|
|
2404
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$t
|
|
2405
|
+
} = constants;
|
|
2373
2406
|
const config$u = {
|
|
2374
2407
|
commandName: 'get',
|
|
2375
2408
|
description: 'Get a diff scan for an organization',
|
|
@@ -2435,14 +2468,15 @@ async function run$u(argv, importMeta, {
|
|
|
2435
2468
|
// options or missing arguments.
|
|
2436
2469
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
2437
2470
|
process.exitCode = 2;
|
|
2438
|
-
|
|
2471
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
2439
2472
|
- Specify a before and after full scan ID ${!before && !after ? colors.red('(missing before and after!)') : !before ? colors.red('(missing before!)') : !after ? colors.red('(missing after!)') : colors.green('(ok)')}\n
|
|
2440
2473
|
- To get full scans IDs, you can run the command "socket scan list <your org slug>".
|
|
2441
2474
|
- Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n`);
|
|
2442
2475
|
return;
|
|
2443
2476
|
}
|
|
2444
2477
|
if (cli.flags['dryRun']) {
|
|
2445
|
-
|
|
2478
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$t);
|
|
2479
|
+
return;
|
|
2446
2480
|
}
|
|
2447
2481
|
const apiToken = index.getDefaultToken();
|
|
2448
2482
|
if (!apiToken) {
|
|
@@ -2485,7 +2519,11 @@ function isTopLevel(tree, node) {
|
|
|
2485
2519
|
return tree.children.get(node.name) === node;
|
|
2486
2520
|
}
|
|
2487
2521
|
async function runFix() {
|
|
2488
|
-
|
|
2522
|
+
// Lazily access constants.spinner.
|
|
2523
|
+
const {
|
|
2524
|
+
spinner
|
|
2525
|
+
} = constants;
|
|
2526
|
+
spinner.start();
|
|
2489
2527
|
const cwd = process.cwd();
|
|
2490
2528
|
const editablePkgJson = await packages.readPackageJson(cwd, {
|
|
2491
2529
|
editable: true
|
|
@@ -2516,7 +2554,7 @@ async function runFix() {
|
|
|
2516
2554
|
const tree = arb.idealTree;
|
|
2517
2555
|
const hasUpgrade = !!registry.getManifestData(NPM$d, name);
|
|
2518
2556
|
if (hasUpgrade) {
|
|
2519
|
-
spinner
|
|
2557
|
+
spinner.info(`Skipping ${name}. Socket Optimize package exists.`);
|
|
2520
2558
|
continue;
|
|
2521
2559
|
}
|
|
2522
2560
|
const nodes = index.findPackageNodes(tree, name);
|
|
@@ -2542,10 +2580,10 @@ async function runFix() {
|
|
|
2542
2580
|
try {
|
|
2543
2581
|
// eslint-disable-next-line no-await-in-loop
|
|
2544
2582
|
await npm.runScript('test', [], {
|
|
2545
|
-
spinner
|
|
2583
|
+
spinner,
|
|
2546
2584
|
stdio: 'ignore'
|
|
2547
2585
|
});
|
|
2548
|
-
spinner
|
|
2586
|
+
spinner.info(`Patched ${name} ${oldVersion} -> ${node.version}`);
|
|
2549
2587
|
if (isTopLevel(tree, node)) {
|
|
2550
2588
|
for (const depField of ['dependencies', 'optionalDependencies', 'peerDependencies']) {
|
|
2551
2589
|
const oldVersion = editablePkgJson.content[depField]?.[name];
|
|
@@ -2558,11 +2596,11 @@ async function runFix() {
|
|
|
2558
2596
|
// eslint-disable-next-line no-await-in-loop
|
|
2559
2597
|
await editablePkgJson.save();
|
|
2560
2598
|
} catch {
|
|
2561
|
-
spinner
|
|
2599
|
+
spinner.error(`Reverting ${name} to ${oldVersion}`);
|
|
2562
2600
|
arb.idealTree = revertToIdealTree;
|
|
2563
2601
|
}
|
|
2564
2602
|
} else {
|
|
2565
|
-
spinner
|
|
2603
|
+
spinner.error(`Could not patch ${name} ${oldVersion}`);
|
|
2566
2604
|
}
|
|
2567
2605
|
}
|
|
2568
2606
|
}
|
|
@@ -2574,9 +2612,12 @@ async function runFix() {
|
|
|
2574
2612
|
});
|
|
2575
2613
|
arb2.idealTree = arb.idealTree;
|
|
2576
2614
|
await arb2.reify();
|
|
2577
|
-
spinner
|
|
2615
|
+
spinner.stop();
|
|
2578
2616
|
}
|
|
2579
2617
|
|
|
2618
|
+
const {
|
|
2619
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$s
|
|
2620
|
+
} = constants;
|
|
2580
2621
|
const config$t = {
|
|
2581
2622
|
commandName: 'fix',
|
|
2582
2623
|
description: 'Fix "fixable" Socket alerts',
|
|
@@ -2607,7 +2648,8 @@ async function run$t(argv, importMeta, {
|
|
|
2607
2648
|
parentName
|
|
2608
2649
|
});
|
|
2609
2650
|
if (cli.flags['dryRun']) {
|
|
2610
|
-
|
|
2651
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$s);
|
|
2652
|
+
return;
|
|
2611
2653
|
}
|
|
2612
2654
|
await runFix();
|
|
2613
2655
|
}
|
|
@@ -2719,9 +2761,9 @@ function formatPackageInfo({
|
|
|
2719
2761
|
strict
|
|
2720
2762
|
}, spinner) {
|
|
2721
2763
|
if (outputJson) {
|
|
2722
|
-
|
|
2764
|
+
logger.logger.log(JSON.stringify(data, undefined, 2));
|
|
2723
2765
|
} else {
|
|
2724
|
-
|
|
2766
|
+
logger.logger.log('\nPackage report card:');
|
|
2725
2767
|
const scoreResult = {
|
|
2726
2768
|
'Supply Chain Risk': Math.floor(score.supplyChainRisk.score * 100),
|
|
2727
2769
|
Maintenance: Math.floor(score.maintenance.score * 100),
|
|
@@ -2729,8 +2771,8 @@ function formatPackageInfo({
|
|
|
2729
2771
|
Vulnerabilities: Math.floor(score.vulnerability.score * 100),
|
|
2730
2772
|
License: Math.floor(score.license.score * 100)
|
|
2731
2773
|
};
|
|
2732
|
-
Object.entries(scoreResult).map(score =>
|
|
2733
|
-
|
|
2774
|
+
Object.entries(scoreResult).map(score => logger.logger.log(`- ${score[0]}: ${formatScore(score[1])}`));
|
|
2775
|
+
logger.logger.log('\n');
|
|
2734
2776
|
if (objectSome(severityCount)) {
|
|
2735
2777
|
spinner[strict ? 'error' : 'success'](`Package has these issues: ${formatSeverityCount(severityCount)}`);
|
|
2736
2778
|
formatPackageIssuesDetails(data, outputMarkdown);
|
|
@@ -2739,18 +2781,18 @@ function formatPackageInfo({
|
|
|
2739
2781
|
}
|
|
2740
2782
|
const format = new index.ColorOrMarkdown(!!outputMarkdown);
|
|
2741
2783
|
const url = index.getSocketDevPackageOverviewUrl(NPM$c, pkgName, pkgVersion);
|
|
2742
|
-
|
|
2784
|
+
logger.logger.log('\n');
|
|
2743
2785
|
if (pkgVersion === 'latest') {
|
|
2744
|
-
|
|
2786
|
+
logger.logger.log(`Detailed info on socket.dev: ${format.hyperlink(`${pkgName}`, url, {
|
|
2745
2787
|
fallbackToUrl: true
|
|
2746
2788
|
})}`);
|
|
2747
2789
|
} else {
|
|
2748
|
-
|
|
2790
|
+
logger.logger.log(`Detailed info on socket.dev: ${format.hyperlink(`${pkgName} v${pkgVersion}`, url, {
|
|
2749
2791
|
fallbackToUrl: true
|
|
2750
2792
|
})}`);
|
|
2751
2793
|
}
|
|
2752
2794
|
if (!outputMarkdown) {
|
|
2753
|
-
|
|
2795
|
+
logger.logger.log(colors.dim(`\nOr rerun ${colors.italic(name)} using the ${colors.italic('--json')} flag to get full JSON output`));
|
|
2754
2796
|
}
|
|
2755
2797
|
}
|
|
2756
2798
|
if (strict && objectSome(severityCount)) {
|
|
@@ -2781,9 +2823,9 @@ function formatPackageIssuesDetails(packageData, outputMarkdown) {
|
|
|
2781
2823
|
fallbackToUrl: true
|
|
2782
2824
|
});
|
|
2783
2825
|
if (uniqueIssues[issue]?.count === 1) {
|
|
2784
|
-
|
|
2826
|
+
logger.logger.log(`- ${issueWithLink}`);
|
|
2785
2827
|
} else {
|
|
2786
|
-
|
|
2828
|
+
logger.logger.log(`- ${issueWithLink}: ${uniqueIssues[issue]?.count}`);
|
|
2787
2829
|
}
|
|
2788
2830
|
}
|
|
2789
2831
|
}
|
|
@@ -2805,11 +2847,12 @@ async function getPackageInfo({
|
|
|
2805
2847
|
pkgVersion,
|
|
2806
2848
|
strict
|
|
2807
2849
|
}) {
|
|
2808
|
-
|
|
2809
|
-
const
|
|
2810
|
-
|
|
2811
|
-
}
|
|
2812
|
-
|
|
2850
|
+
// Lazily access constants.spinner.
|
|
2851
|
+
const {
|
|
2852
|
+
spinner
|
|
2853
|
+
} = constants;
|
|
2854
|
+
spinner.start(pkgVersion === 'latest' ? `Looking up data for the latest version of ${pkgName}` : `Looking up data for version ${pkgVersion} of ${pkgName}`);
|
|
2855
|
+
const packageData = await fetchPackageInfo(pkgName, pkgVersion, includeAllIssues, spinner);
|
|
2813
2856
|
if (packageData) {
|
|
2814
2857
|
formatPackageInfo(packageData, {
|
|
2815
2858
|
name: commandName,
|
|
@@ -2818,10 +2861,13 @@ async function getPackageInfo({
|
|
|
2818
2861
|
pkgName,
|
|
2819
2862
|
pkgVersion,
|
|
2820
2863
|
strict
|
|
2821
|
-
}, spinner
|
|
2864
|
+
}, spinner);
|
|
2822
2865
|
}
|
|
2823
2866
|
}
|
|
2824
2867
|
|
|
2868
|
+
const {
|
|
2869
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$r
|
|
2870
|
+
} = constants;
|
|
2825
2871
|
const config$s = {
|
|
2826
2872
|
commandName: 'info',
|
|
2827
2873
|
description: 'Look up info regarding a package',
|
|
@@ -2863,7 +2909,7 @@ async function run$s(argv, importMeta, {
|
|
|
2863
2909
|
// options or missing arguments.
|
|
2864
2910
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
2865
2911
|
process.exitCode = 2;
|
|
2866
|
-
|
|
2912
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
2867
2913
|
- Expecting a package name ${!rawPkgName ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
2868
2914
|
- Can only accept one package at a time ${cli.input.length > 1 ? colors.red('(got ' + cli.input.length + '!)') : colors.green('(ok)')}\n`);
|
|
2869
2915
|
return;
|
|
@@ -2872,7 +2918,8 @@ async function run$s(argv, importMeta, {
|
|
|
2872
2918
|
const pkgName = versionSeparator < 1 ? rawPkgName : rawPkgName.slice(0, versionSeparator);
|
|
2873
2919
|
const pkgVersion = versionSeparator < 1 ? 'latest' : rawPkgName.slice(versionSeparator + 1);
|
|
2874
2920
|
if (cli.flags['dryRun']) {
|
|
2875
|
-
|
|
2921
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$r);
|
|
2922
|
+
return;
|
|
2876
2923
|
}
|
|
2877
2924
|
await getPackageInfo({
|
|
2878
2925
|
commandName: `${parentName} ${config$s.commandName}`,
|
|
@@ -2892,19 +2939,20 @@ function applyLogin(apiToken, enforcedOrgs, apiBaseUrl, apiProxy) {
|
|
|
2892
2939
|
index.updateSetting('apiProxy', apiProxy);
|
|
2893
2940
|
}
|
|
2894
2941
|
|
|
2895
|
-
// TODO: this type should come from a general Socket REST API type doc
|
|
2896
|
-
|
|
2897
2942
|
const {
|
|
2898
2943
|
SOCKET_PUBLIC_API_TOKEN
|
|
2899
2944
|
} = constants;
|
|
2900
2945
|
async function attemptLogin(apiBaseUrl, apiProxy) {
|
|
2946
|
+
apiBaseUrl ??= index.getSetting('apiBaseUrl') ?? undefined;
|
|
2947
|
+
apiProxy ??= index.getSetting('apiProxy') ?? undefined;
|
|
2901
2948
|
const apiToken = (await prompts.password({
|
|
2902
2949
|
message: `Enter your ${terminalLink('Socket.dev API key', 'https://docs.socket.dev/docs/api-keys')} (leave blank for a public key)`
|
|
2903
2950
|
})) || SOCKET_PUBLIC_API_TOKEN;
|
|
2904
|
-
|
|
2905
|
-
|
|
2906
|
-
|
|
2907
|
-
|
|
2951
|
+
// Lazily access constants.spinner.
|
|
2952
|
+
const {
|
|
2953
|
+
spinner
|
|
2954
|
+
} = constants;
|
|
2955
|
+
spinner.start('Verifying API key...');
|
|
2908
2956
|
let orgs;
|
|
2909
2957
|
try {
|
|
2910
2958
|
const sdk = await index.setupSdk(apiToken, apiBaseUrl, apiProxy);
|
|
@@ -2913,9 +2961,9 @@ async function attemptLogin(apiBaseUrl, apiProxy) {
|
|
|
2913
2961
|
throw new index.AuthError();
|
|
2914
2962
|
}
|
|
2915
2963
|
orgs = result.data;
|
|
2916
|
-
spinner
|
|
2964
|
+
spinner.success('API key verified');
|
|
2917
2965
|
} catch {
|
|
2918
|
-
spinner
|
|
2966
|
+
spinner.errorAndStop('Invalid API key');
|
|
2919
2967
|
return;
|
|
2920
2968
|
}
|
|
2921
2969
|
const enforcedChoices = Object.values(orgs.organizations).filter(org => org?.plan === 'enterprise').map(org => ({
|
|
@@ -2932,7 +2980,7 @@ async function attemptLogin(apiBaseUrl, apiProxy) {
|
|
|
2932
2980
|
description: 'Pick "None" if this is a personal device'
|
|
2933
2981
|
})
|
|
2934
2982
|
}, {
|
|
2935
|
-
spinner
|
|
2983
|
+
spinner
|
|
2936
2984
|
});
|
|
2937
2985
|
if (id) {
|
|
2938
2986
|
enforcedOrgs = [id];
|
|
@@ -2942,7 +2990,7 @@ async function attemptLogin(apiBaseUrl, apiProxy) {
|
|
|
2942
2990
|
message: `Should Socket enforce ${enforcedChoices[0]?.name}'s security policies system-wide?`,
|
|
2943
2991
|
default: true
|
|
2944
2992
|
}, {
|
|
2945
|
-
spinner
|
|
2993
|
+
spinner
|
|
2946
2994
|
});
|
|
2947
2995
|
if (confirmOrg) {
|
|
2948
2996
|
const existing = enforcedChoices[0];
|
|
@@ -2954,12 +3002,15 @@ async function attemptLogin(apiBaseUrl, apiProxy) {
|
|
|
2954
3002
|
const oldToken = index.getSetting('apiToken');
|
|
2955
3003
|
try {
|
|
2956
3004
|
applyLogin(apiToken, enforcedOrgs, apiBaseUrl, apiProxy);
|
|
2957
|
-
spinner
|
|
3005
|
+
spinner.successAndStop(`API credentials ${oldToken ? 'updated' : 'set'}`);
|
|
2958
3006
|
} catch {
|
|
2959
|
-
spinner
|
|
3007
|
+
spinner.errorAndStop(`API login failed`);
|
|
2960
3008
|
}
|
|
2961
3009
|
}
|
|
2962
3010
|
|
|
3011
|
+
const {
|
|
3012
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$q
|
|
3013
|
+
} = constants;
|
|
2963
3014
|
const config$r = {
|
|
2964
3015
|
commandName: 'login',
|
|
2965
3016
|
description: 'Socket API login',
|
|
@@ -3006,7 +3057,8 @@ async function run$r(argv, importMeta, {
|
|
|
3006
3057
|
let apiBaseUrl = cli.flags['apiBaseUrl'];
|
|
3007
3058
|
let apiProxy = cli.flags['apiProxy'];
|
|
3008
3059
|
if (cli.flags['dryRun']) {
|
|
3009
|
-
|
|
3060
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$q);
|
|
3061
|
+
return;
|
|
3010
3062
|
}
|
|
3011
3063
|
if (!isInteractive()) {
|
|
3012
3064
|
throw new index.InputError('Cannot prompt for credentials in a non-interactive shell');
|
|
@@ -3030,6 +3082,9 @@ function attemptLogout() {
|
|
|
3030
3082
|
}
|
|
3031
3083
|
}
|
|
3032
3084
|
|
|
3085
|
+
const {
|
|
3086
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$p
|
|
3087
|
+
} = constants;
|
|
3033
3088
|
const config$q = {
|
|
3034
3089
|
commandName: 'logout',
|
|
3035
3090
|
description: 'Socket API logout',
|
|
@@ -3059,31 +3114,31 @@ async function run$q(argv, importMeta, {
|
|
|
3059
3114
|
parentName
|
|
3060
3115
|
});
|
|
3061
3116
|
if (cli.flags['dryRun']) {
|
|
3062
|
-
|
|
3117
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$p);
|
|
3118
|
+
return;
|
|
3063
3119
|
}
|
|
3064
3120
|
attemptLogout();
|
|
3065
3121
|
}
|
|
3066
3122
|
|
|
3067
3123
|
async function convertGradleToMaven(target, bin, _out, verbose, gradleOpts) {
|
|
3124
|
+
// Lazily access constants.spinner.
|
|
3125
|
+
const {
|
|
3126
|
+
spinner
|
|
3127
|
+
} = constants;
|
|
3068
3128
|
const rbin = path.resolve(bin);
|
|
3069
3129
|
const rtarget = path.resolve(target);
|
|
3070
|
-
// const rout = out === '-' ? '-' : path.resolve(out)
|
|
3071
|
-
|
|
3072
3130
|
if (verbose) {
|
|
3073
|
-
|
|
3074
|
-
|
|
3075
|
-
|
|
3076
|
-
|
|
3077
|
-
console.groupEnd();
|
|
3131
|
+
logger.logger.group('gradle2maven:');
|
|
3132
|
+
logger.logger.log(`[VERBOSE] - Absolute bin path: \`${rbin}\``);
|
|
3133
|
+
logger.logger.log(`[VERBOSE] - Absolute target path: \`${rtarget}\``);
|
|
3134
|
+
logger.logger.groupEnd();
|
|
3078
3135
|
} else {
|
|
3079
|
-
|
|
3080
|
-
|
|
3081
|
-
|
|
3082
|
-
|
|
3083
|
-
|
|
3084
|
-
}
|
|
3085
|
-
const spinner$1 = new spinner.Spinner();
|
|
3086
|
-
spinner$1.start(`Converting gradle to maven from \`${bin}\` on \`${target}\`...`);
|
|
3136
|
+
logger.logger.group('gradle2maven:');
|
|
3137
|
+
logger.logger.log(`- executing: \`${bin}\``);
|
|
3138
|
+
logger.logger.log(`- src dir: \`${target}\``);
|
|
3139
|
+
logger.logger.groupEnd();
|
|
3140
|
+
}
|
|
3141
|
+
spinner.start(`Converting gradle to maven from \`${bin}\` on \`${target}\`...`);
|
|
3087
3142
|
try {
|
|
3088
3143
|
// Run sbt with the init script we provide which should yield zero or more pom files.
|
|
3089
3144
|
// We have to figure out where to store those pom files such that we can upload them and predict them through the GitHub API.
|
|
@@ -3093,36 +3148,37 @@ async function convertGradleToMaven(target, bin, _out, verbose, gradleOpts) {
|
|
|
3093
3148
|
const initLocation = path.join(constants.rootDistPath, 'init.gradle');
|
|
3094
3149
|
const commandArgs = ['--init-script', initLocation, ...gradleOpts, 'pom'];
|
|
3095
3150
|
if (verbose) {
|
|
3096
|
-
spinner
|
|
3151
|
+
spinner.log('[VERBOSE] Executing:', bin, commandArgs);
|
|
3097
3152
|
}
|
|
3098
|
-
const output = await spawn(bin, commandArgs, {
|
|
3153
|
+
const output = await spawn.spawn(bin, commandArgs, {
|
|
3099
3154
|
cwd: target || '.'
|
|
3100
3155
|
});
|
|
3156
|
+
spinner.stop();
|
|
3101
3157
|
if (verbose) {
|
|
3102
|
-
|
|
3103
|
-
|
|
3104
|
-
|
|
3158
|
+
logger.logger.group('[VERBOSE] gradle stdout:');
|
|
3159
|
+
logger.logger.log(output);
|
|
3160
|
+
logger.logger.groupEnd();
|
|
3105
3161
|
}
|
|
3106
3162
|
if (output.stderr) {
|
|
3107
|
-
|
|
3163
|
+
logger.logger.error('There were errors while running gradle');
|
|
3108
3164
|
// (In verbose mode, stderr was printed above, no need to repeat it)
|
|
3109
3165
|
if (!verbose) {
|
|
3110
|
-
|
|
3111
|
-
|
|
3112
|
-
|
|
3166
|
+
logger.logger.group('[VERBOSE] stderr:');
|
|
3167
|
+
logger.logger.error(output.stderr);
|
|
3168
|
+
logger.logger.groupEnd();
|
|
3113
3169
|
}
|
|
3114
3170
|
process.exit(1);
|
|
3115
3171
|
}
|
|
3116
|
-
|
|
3117
|
-
|
|
3172
|
+
logger.logger.success('Executed gradle successfully');
|
|
3173
|
+
logger.logger.log('Reported exports:');
|
|
3118
3174
|
output.stdout.replace(/^POM file copied to: (.*)/gm, (_all, fn) => {
|
|
3119
|
-
|
|
3175
|
+
logger.logger.log('- ', fn);
|
|
3120
3176
|
return fn;
|
|
3121
3177
|
});
|
|
3122
3178
|
|
|
3123
3179
|
// const loc = output.stdout?.match(/Wrote (.*?.pom)\n/)?.[1]?.trim()
|
|
3124
3180
|
// if (!loc) {
|
|
3125
|
-
//
|
|
3181
|
+
// logger.error(
|
|
3126
3182
|
// 'There were no errors from sbt but could not find the location of resulting .pom file either'
|
|
3127
3183
|
// )
|
|
3128
3184
|
// process.exit(1)
|
|
@@ -3131,8 +3187,8 @@ async function convertGradleToMaven(target, bin, _out, verbose, gradleOpts) {
|
|
|
3131
3187
|
// // Move the pom file to ...? initial cwd? loc will be an absolute path, or dump to stdout
|
|
3132
3188
|
// if (out === '-') {
|
|
3133
3189
|
// spinner.start('Result:\n```')
|
|
3134
|
-
//
|
|
3135
|
-
//
|
|
3190
|
+
// spinner.log(await safeReadFile(loc, 'utf8'))
|
|
3191
|
+
// spinner.log('```')
|
|
3136
3192
|
// spinner.successAndStop(`OK`)
|
|
3137
3193
|
// } else {
|
|
3138
3194
|
// spinner.start()
|
|
@@ -3148,16 +3204,20 @@ async function convertGradleToMaven(target, bin, _out, verbose, gradleOpts) {
|
|
|
3148
3204
|
// spinner.successAndStop(`OK. File should be available in \`${out}\``)
|
|
3149
3205
|
// }
|
|
3150
3206
|
} catch (e) {
|
|
3151
|
-
spinner
|
|
3207
|
+
spinner.stop();
|
|
3208
|
+
logger.logger.error('There was an unexpected error while running this' + (verbose ? '' : ' (use --verbose for details)'));
|
|
3152
3209
|
if (verbose) {
|
|
3153
|
-
|
|
3154
|
-
|
|
3155
|
-
|
|
3210
|
+
logger.logger.group('[VERBOSE] error:');
|
|
3211
|
+
logger.logger.log(e);
|
|
3212
|
+
logger.logger.groupEnd();
|
|
3156
3213
|
}
|
|
3157
3214
|
process.exit(1);
|
|
3158
3215
|
}
|
|
3159
3216
|
}
|
|
3160
3217
|
|
|
3218
|
+
const {
|
|
3219
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$o
|
|
3220
|
+
} = constants;
|
|
3161
3221
|
const config$p = {
|
|
3162
3222
|
commandName: 'gradle',
|
|
3163
3223
|
description: '[beta] Use Gradle to generate a manifest file (`pom.xml`) for a Gradle/Java/Kotlin/etc project',
|
|
@@ -3245,22 +3305,23 @@ async function run$p(argv, importMeta, {
|
|
|
3245
3305
|
});
|
|
3246
3306
|
const verbose = Boolean(cli.flags['verbose']);
|
|
3247
3307
|
if (verbose) {
|
|
3248
|
-
|
|
3249
|
-
|
|
3250
|
-
|
|
3251
|
-
|
|
3252
|
-
|
|
3308
|
+
logger.logger.group('- ', parentName, config$p.commandName, ':');
|
|
3309
|
+
logger.logger.group('- flags:', cli.flags);
|
|
3310
|
+
logger.logger.groupEnd();
|
|
3311
|
+
logger.logger.log('- input:', cli.input);
|
|
3312
|
+
logger.logger.groupEnd();
|
|
3253
3313
|
}
|
|
3254
3314
|
const target = cli.input[0];
|
|
3255
3315
|
|
|
3256
|
-
// TODO: I'm not sure it's feasible to parse source file from stdin. We could
|
|
3257
|
-
|
|
3316
|
+
// TODO: I'm not sure it's feasible to parse source file from stdin. We could
|
|
3317
|
+
// try, store contents in a file in some folder, target that folder... what
|
|
3318
|
+
// would the file name be?
|
|
3258
3319
|
if (!target || target === '-' || cli.input.length > 1) {
|
|
3259
3320
|
// Use exit status of 2 to indicate incorrect usage, generally invalid
|
|
3260
3321
|
// options or missing arguments.
|
|
3261
3322
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
3262
3323
|
process.exitCode = 2;
|
|
3263
|
-
|
|
3324
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
3264
3325
|
- The DIR arg is required ${!target ? colors.red('(missing!)') : target === '-' ? colors.red('(stdin is not supported)') : colors.green('(ok)')}\n
|
|
3265
3326
|
- Can only accept one DIR (make sure to escape spaces!) ${cli.input.length > 1 ? colors.red(`(received ${cli.input.length}!)`) : colors.green('(ok)')}\n`);
|
|
3266
3327
|
return;
|
|
@@ -3279,64 +3340,66 @@ async function run$p(argv, importMeta, {
|
|
|
3279
3340
|
out = '-';
|
|
3280
3341
|
}
|
|
3281
3342
|
if (verbose) {
|
|
3282
|
-
|
|
3283
|
-
|
|
3284
|
-
|
|
3285
|
-
|
|
3286
|
-
|
|
3343
|
+
logger.logger.group();
|
|
3344
|
+
logger.logger.log('- target:', target);
|
|
3345
|
+
logger.logger.log('- gradle bin:', bin);
|
|
3346
|
+
logger.logger.log('- out:', out);
|
|
3347
|
+
logger.logger.groupEnd();
|
|
3287
3348
|
}
|
|
3288
3349
|
let gradleOpts = [];
|
|
3289
3350
|
if (cli.flags['gradleOpts']) {
|
|
3290
3351
|
gradleOpts = cli.flags['gradleOpts'].split(' ').map(s => s.trim()).filter(Boolean);
|
|
3291
3352
|
}
|
|
3292
3353
|
if (cli.flags['dryRun']) {
|
|
3293
|
-
|
|
3354
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$o);
|
|
3355
|
+
return;
|
|
3294
3356
|
}
|
|
3295
3357
|
await convertGradleToMaven(target, bin, out, verbose, gradleOpts);
|
|
3296
3358
|
}
|
|
3297
3359
|
|
|
3298
3360
|
async function convertSbtToMaven(target, bin, out, verbose, sbtOpts) {
|
|
3361
|
+
// Lazily access constants.spinner.
|
|
3362
|
+
const {
|
|
3363
|
+
spinner
|
|
3364
|
+
} = constants;
|
|
3299
3365
|
const rbin = path.resolve(bin);
|
|
3300
3366
|
const rtarget = path.resolve(target);
|
|
3301
|
-
// const rout = out === '-' ? '-' : path.resolve(out)
|
|
3302
|
-
|
|
3303
3367
|
if (verbose) {
|
|
3304
|
-
|
|
3305
|
-
|
|
3306
|
-
|
|
3307
|
-
//
|
|
3308
|
-
|
|
3368
|
+
logger.logger.group('sbt2maven:');
|
|
3369
|
+
logger.logger.log(`[VERBOSE] - Absolute bin path: \`${rbin}\``);
|
|
3370
|
+
logger.logger.log(`[VERBOSE] - Absolute target path: \`${rtarget}\``);
|
|
3371
|
+
// logger.log(`[VERBOSE] - Absolute out path: \`${rout}\``)
|
|
3372
|
+
logger.logger.groupEnd();
|
|
3309
3373
|
} else {
|
|
3310
|
-
|
|
3311
|
-
|
|
3312
|
-
|
|
3313
|
-
//
|
|
3314
|
-
|
|
3315
|
-
}
|
|
3316
|
-
|
|
3317
|
-
spinner$1.start(`Converting sbt to maven from \`${bin}\` on \`${target}\`...`);
|
|
3374
|
+
logger.logger.group('sbt2maven:');
|
|
3375
|
+
logger.logger.log(`- executing: \`${bin}\``);
|
|
3376
|
+
logger.logger.log(`- src dir: \`${target}\``);
|
|
3377
|
+
// logger.log(`- dst dir: \`${out}\``)
|
|
3378
|
+
logger.logger.groupEnd();
|
|
3379
|
+
}
|
|
3380
|
+
spinner.start(`Converting sbt to maven from \`${bin}\` on \`${target}\`...`);
|
|
3318
3381
|
try {
|
|
3319
3382
|
// Run sbt with the init script we provide which should yield zero or more
|
|
3320
3383
|
// pom files. We have to figure out where to store those pom files such that
|
|
3321
3384
|
// we can upload them and predict them through the GitHub API. We could do a
|
|
3322
3385
|
// .socket folder. We could do a socket.pom.gz with all the poms, although
|
|
3323
3386
|
// I'd prefer something plain-text if it is to be committed.
|
|
3324
|
-
const output = await spawn(bin, ['makePom'].concat(sbtOpts), {
|
|
3387
|
+
const output = await spawn.spawn(bin, ['makePom'].concat(sbtOpts), {
|
|
3325
3388
|
cwd: target || '.'
|
|
3326
3389
|
});
|
|
3327
|
-
spinner
|
|
3390
|
+
spinner.stop();
|
|
3328
3391
|
if (verbose) {
|
|
3329
|
-
|
|
3330
|
-
|
|
3331
|
-
|
|
3392
|
+
logger.logger.group('[VERBOSE] sbt stdout:');
|
|
3393
|
+
logger.logger.log(output);
|
|
3394
|
+
logger.logger.groupEnd();
|
|
3332
3395
|
}
|
|
3333
3396
|
if (output.stderr) {
|
|
3334
3397
|
logger.logger.error('There were errors while running sbt');
|
|
3335
3398
|
// (In verbose mode, stderr was printed above, no need to repeat it)
|
|
3336
3399
|
if (!verbose) {
|
|
3337
|
-
|
|
3338
|
-
|
|
3339
|
-
|
|
3400
|
+
logger.logger.group('[VERBOSE] stderr:');
|
|
3401
|
+
logger.logger.error(output.stderr);
|
|
3402
|
+
logger.logger.groupEnd();
|
|
3340
3403
|
}
|
|
3341
3404
|
process.exit(1);
|
|
3342
3405
|
}
|
|
@@ -3354,39 +3417,43 @@ async function convertSbtToMaven(target, bin, out, verbose, sbtOpts) {
|
|
|
3354
3417
|
// TODO: maybe we can add an option to target a specific file to dump to stdout
|
|
3355
3418
|
if (out === '-' && poms.length === 1) {
|
|
3356
3419
|
logger.logger.log('Result:\n```');
|
|
3357
|
-
|
|
3420
|
+
logger.logger.log(await index.safeReadFile(poms[0], 'utf8'));
|
|
3358
3421
|
logger.logger.log('```');
|
|
3359
3422
|
logger.logger.success(`OK`);
|
|
3360
3423
|
} else if (out === '-') {
|
|
3361
3424
|
logger.logger.error('Requested out target was stdout but there are multiple generated files');
|
|
3362
|
-
poms.forEach(fn =>
|
|
3363
|
-
|
|
3425
|
+
poms.forEach(fn => logger.logger.error('-', fn));
|
|
3426
|
+
logger.logger.error('Exiting now...');
|
|
3364
3427
|
process.exit(1);
|
|
3365
3428
|
} else {
|
|
3366
3429
|
// if (verbose) {
|
|
3367
|
-
//
|
|
3430
|
+
// logger.log(
|
|
3368
3431
|
// `Moving manifest file from \`${loc.replace(/^\/home\/[^/]*?\//, '~/')}\` to \`${out}\``
|
|
3369
3432
|
// )
|
|
3370
3433
|
// } else {
|
|
3371
|
-
//
|
|
3434
|
+
// logger.log('Moving output pom file')
|
|
3372
3435
|
// }
|
|
3373
3436
|
// TODO: do we prefer fs-extra? renaming can be gnarly on windows and fs-extra's version is better
|
|
3374
3437
|
// await renamep(loc, out)
|
|
3375
3438
|
logger.logger.success(`Generated ${poms.length} pom files`);
|
|
3376
|
-
poms.forEach(fn =>
|
|
3439
|
+
poms.forEach(fn => logger.logger.log('-', fn));
|
|
3377
3440
|
logger.logger.success(`OK`);
|
|
3378
3441
|
}
|
|
3379
3442
|
} catch (e) {
|
|
3380
|
-
spinner
|
|
3443
|
+
spinner.stop();
|
|
3444
|
+
logger.logger.error('There was an unexpected error while running this' + (verbose ? '' : ' (use --verbose for details)'));
|
|
3381
3445
|
if (verbose) {
|
|
3382
|
-
|
|
3383
|
-
|
|
3384
|
-
|
|
3446
|
+
logger.logger.group('[VERBOSE] error:');
|
|
3447
|
+
logger.logger.log(e);
|
|
3448
|
+
logger.logger.groupEnd();
|
|
3385
3449
|
}
|
|
3386
3450
|
process.exit(1);
|
|
3387
3451
|
}
|
|
3388
3452
|
}
|
|
3389
3453
|
|
|
3454
|
+
const {
|
|
3455
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$n
|
|
3456
|
+
} = constants;
|
|
3390
3457
|
const config$o = {
|
|
3391
3458
|
commandName: 'scala',
|
|
3392
3459
|
description: "[beta] Generate a manifest file (`pom.xml`) from Scala's `build.sbt` file",
|
|
@@ -3464,7 +3531,6 @@ const cmdManifestScala = {
|
|
|
3464
3531
|
async function run$o(argv, importMeta, {
|
|
3465
3532
|
parentName
|
|
3466
3533
|
}) {
|
|
3467
|
-
// console.log('scala', argv, parentName)
|
|
3468
3534
|
const cli = meowOrExit({
|
|
3469
3535
|
argv,
|
|
3470
3536
|
config: config$o,
|
|
@@ -3473,22 +3539,23 @@ async function run$o(argv, importMeta, {
|
|
|
3473
3539
|
});
|
|
3474
3540
|
const verbose = Boolean(cli.flags['verbose']);
|
|
3475
3541
|
if (verbose) {
|
|
3476
|
-
|
|
3477
|
-
|
|
3478
|
-
|
|
3479
|
-
|
|
3480
|
-
|
|
3542
|
+
logger.logger.group('- ', parentName, config$o.commandName, ':');
|
|
3543
|
+
logger.logger.group('- flags:', cli.flags);
|
|
3544
|
+
logger.logger.groupEnd();
|
|
3545
|
+
logger.logger.log('- input:', cli.input);
|
|
3546
|
+
logger.logger.groupEnd();
|
|
3481
3547
|
}
|
|
3482
3548
|
const target = cli.input[0];
|
|
3483
3549
|
|
|
3484
|
-
// TODO: I'm not sure it's feasible to parse source file from stdin. We could
|
|
3485
|
-
|
|
3550
|
+
// TODO: I'm not sure it's feasible to parse source file from stdin. We could
|
|
3551
|
+
// try, store contents in a file in some folder, target that folder... what
|
|
3552
|
+
// would the file name be?
|
|
3486
3553
|
if (!target || target === '-' || cli.input.length > 1) {
|
|
3487
3554
|
// Use exit status of 2 to indicate incorrect usage, generally invalid
|
|
3488
3555
|
// options or missing arguments.
|
|
3489
3556
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
3490
3557
|
process.exitCode = 2;
|
|
3491
|
-
|
|
3558
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
3492
3559
|
- The DIR or FILE arg is required ${!target ? colors.red('(missing!)') : target === '-' ? colors.red('(stdin is not supported)') : colors.green('(ok)')}\n
|
|
3493
3560
|
- Can only accept one DIR or FILE (make sure to escape spaces!) ${cli.input.length > 1 ? colors.red(`(received ${cli.input.length}!)`) : colors.green('(ok)')}\n`);
|
|
3494
3561
|
return;
|
|
@@ -3505,22 +3572,26 @@ async function run$o(argv, importMeta, {
|
|
|
3505
3572
|
out = '-';
|
|
3506
3573
|
}
|
|
3507
3574
|
if (verbose) {
|
|
3508
|
-
|
|
3509
|
-
|
|
3510
|
-
|
|
3511
|
-
|
|
3512
|
-
|
|
3575
|
+
logger.logger.group();
|
|
3576
|
+
logger.logger.log('- target:', target);
|
|
3577
|
+
logger.logger.log('- gradle bin:', bin);
|
|
3578
|
+
logger.logger.log('- out:', out);
|
|
3579
|
+
logger.logger.groupEnd();
|
|
3513
3580
|
}
|
|
3514
3581
|
let sbtOpts = [];
|
|
3515
3582
|
if (cli.flags['sbtOpts']) {
|
|
3516
3583
|
sbtOpts = cli.flags['sbtOpts'].split(' ').map(s => s.trim()).filter(Boolean);
|
|
3517
3584
|
}
|
|
3518
3585
|
if (cli.flags['dryRun']) {
|
|
3519
|
-
|
|
3586
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$n);
|
|
3587
|
+
return;
|
|
3520
3588
|
}
|
|
3521
3589
|
await convertSbtToMaven(target, bin, out, verbose, sbtOpts);
|
|
3522
3590
|
}
|
|
3523
3591
|
|
|
3592
|
+
const {
|
|
3593
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$m
|
|
3594
|
+
} = constants;
|
|
3524
3595
|
const config$n = {
|
|
3525
3596
|
commandName: 'auto',
|
|
3526
3597
|
description: 'Auto-detect build and attempt to generate manifest file',
|
|
@@ -3567,12 +3638,12 @@ async function run$n(argv, importMeta, {
|
|
|
3567
3638
|
const verbose = !!cli.flags['verbose'];
|
|
3568
3639
|
const cwd = cli.flags['cwd'] ?? process.cwd();
|
|
3569
3640
|
if (verbose) {
|
|
3570
|
-
|
|
3571
|
-
|
|
3572
|
-
|
|
3573
|
-
|
|
3574
|
-
|
|
3575
|
-
|
|
3641
|
+
logger.logger.group('- ', parentName, config$n.commandName, ':');
|
|
3642
|
+
logger.logger.group('- flags:', cli.flags);
|
|
3643
|
+
logger.logger.groupEnd();
|
|
3644
|
+
logger.logger.log('- input:', cli.input);
|
|
3645
|
+
logger.logger.log('- cwd:', cwd);
|
|
3646
|
+
logger.logger.groupEnd();
|
|
3576
3647
|
}
|
|
3577
3648
|
const subArgs = [];
|
|
3578
3649
|
if (verbose) {
|
|
@@ -3580,13 +3651,14 @@ async function run$n(argv, importMeta, {
|
|
|
3580
3651
|
}
|
|
3581
3652
|
const dir = cwd;
|
|
3582
3653
|
if (fs.existsSync(path.join(dir, 'build.sbt'))) {
|
|
3583
|
-
|
|
3654
|
+
logger.logger.log('Detected a Scala sbt build, running default Scala generator...');
|
|
3584
3655
|
if (cwd) {
|
|
3585
3656
|
subArgs.push('--cwd', cwd);
|
|
3586
3657
|
}
|
|
3587
3658
|
subArgs.push(dir);
|
|
3588
3659
|
if (cli.flags['dryRun']) {
|
|
3589
|
-
|
|
3660
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$m);
|
|
3661
|
+
return;
|
|
3590
3662
|
}
|
|
3591
3663
|
await cmdManifestScala.run(subArgs, importMeta, {
|
|
3592
3664
|
parentName
|
|
@@ -3594,13 +3666,14 @@ async function run$n(argv, importMeta, {
|
|
|
3594
3666
|
return;
|
|
3595
3667
|
}
|
|
3596
3668
|
if (fs.existsSync(path.join(dir, 'gradlew'))) {
|
|
3597
|
-
|
|
3669
|
+
logger.logger.log('Detected a gradle build, running default gradle generator...');
|
|
3598
3670
|
if (cwd) {
|
|
3599
3671
|
// This command takes the cwd as first arg.
|
|
3600
3672
|
subArgs.push(cwd);
|
|
3601
3673
|
}
|
|
3602
3674
|
if (cli.flags['dryRun']) {
|
|
3603
|
-
|
|
3675
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$m);
|
|
3676
|
+
return;
|
|
3604
3677
|
}
|
|
3605
3678
|
await cmdManifestGradle.run(subArgs, importMeta, {
|
|
3606
3679
|
parentName
|
|
@@ -3628,6 +3701,10 @@ async function run$n(argv, importMeta, {
|
|
|
3628
3701
|
}).showHelp();
|
|
3629
3702
|
}
|
|
3630
3703
|
|
|
3704
|
+
const {
|
|
3705
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$l
|
|
3706
|
+
} = constants;
|
|
3707
|
+
|
|
3631
3708
|
// TODO: we may want to dedupe some pieces for all gradle languages. I think it
|
|
3632
3709
|
// makes sense to have separate commands for them and I think it makes
|
|
3633
3710
|
// sense for the help panels to note the requested language, rather than
|
|
@@ -3720,22 +3797,23 @@ async function run$m(argv, importMeta, {
|
|
|
3720
3797
|
});
|
|
3721
3798
|
const verbose = Boolean(cli.flags['verbose']);
|
|
3722
3799
|
if (verbose) {
|
|
3723
|
-
|
|
3724
|
-
|
|
3725
|
-
|
|
3726
|
-
|
|
3727
|
-
|
|
3800
|
+
logger.logger.group('- ', parentName, config$m.commandName, ':');
|
|
3801
|
+
logger.logger.group('- flags:', cli.flags);
|
|
3802
|
+
logger.logger.groupEnd();
|
|
3803
|
+
logger.logger.log('- input:', cli.input);
|
|
3804
|
+
logger.logger.groupEnd();
|
|
3728
3805
|
}
|
|
3729
3806
|
const target = cli.input[0];
|
|
3730
3807
|
|
|
3731
|
-
// TODO: I'm not sure it's feasible to parse source file from stdin. We could
|
|
3732
|
-
|
|
3808
|
+
// TODO: I'm not sure it's feasible to parse source file from stdin. We could
|
|
3809
|
+
// try, store contents in a file in some folder, target that folder... what
|
|
3810
|
+
// would the file name be?
|
|
3733
3811
|
if (!target || target === '-' || cli.input.length > 1) {
|
|
3734
3812
|
// Use exit status of 2 to indicate incorrect usage, generally invalid
|
|
3735
3813
|
// options or missing arguments.
|
|
3736
3814
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
3737
3815
|
process.exitCode = 2;
|
|
3738
|
-
|
|
3816
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
3739
3817
|
- The DIR arg is required ${!target ? colors.red('(missing!)') : target === '-' ? colors.red('(stdin is not supported)') : colors.green('(ok)')}\n
|
|
3740
3818
|
- Can only accept one DIR (make sure to escape spaces!) ${cli.input.length > 1 ? colors.red(`(received ${cli.input.length}!)`) : colors.green('(ok)')}\n`);
|
|
3741
3819
|
return;
|
|
@@ -3754,18 +3832,19 @@ async function run$m(argv, importMeta, {
|
|
|
3754
3832
|
out = '-';
|
|
3755
3833
|
}
|
|
3756
3834
|
if (verbose) {
|
|
3757
|
-
|
|
3758
|
-
|
|
3759
|
-
|
|
3760
|
-
|
|
3761
|
-
|
|
3835
|
+
logger.logger.group();
|
|
3836
|
+
logger.logger.log('- target:', target);
|
|
3837
|
+
logger.logger.log('- gradle bin:', bin);
|
|
3838
|
+
logger.logger.log('- out:', out);
|
|
3839
|
+
logger.logger.groupEnd();
|
|
3762
3840
|
}
|
|
3763
3841
|
let gradleOpts = [];
|
|
3764
3842
|
if (cli.flags['gradleOpts']) {
|
|
3765
3843
|
gradleOpts = cli.flags['gradleOpts'].split(' ').map(s => s.trim()).filter(Boolean);
|
|
3766
3844
|
}
|
|
3767
3845
|
if (cli.flags['dryRun']) {
|
|
3768
|
-
|
|
3846
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$l);
|
|
3847
|
+
return;
|
|
3769
3848
|
}
|
|
3770
3849
|
await convertGradleToMaven(target, bin, out, verbose, gradleOpts);
|
|
3771
3850
|
}
|
|
@@ -3817,6 +3896,7 @@ async function wrapNpm(argv) {
|
|
|
3817
3896
|
}
|
|
3818
3897
|
|
|
3819
3898
|
const {
|
|
3899
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$k,
|
|
3820
3900
|
NPM: NPM$a
|
|
3821
3901
|
} = constants;
|
|
3822
3902
|
const config$k = {
|
|
@@ -3845,7 +3925,8 @@ async function run$k(argv, importMeta, {
|
|
|
3845
3925
|
parentName
|
|
3846
3926
|
});
|
|
3847
3927
|
if (cli.flags['dryRun']) {
|
|
3848
|
-
|
|
3928
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$k);
|
|
3929
|
+
return;
|
|
3849
3930
|
}
|
|
3850
3931
|
await wrapNpm(argv);
|
|
3851
3932
|
}
|
|
@@ -3861,6 +3942,7 @@ async function wrapNpx(argv) {
|
|
|
3861
3942
|
}
|
|
3862
3943
|
|
|
3863
3944
|
const {
|
|
3945
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$j,
|
|
3864
3946
|
NPX: NPX$1
|
|
3865
3947
|
} = constants;
|
|
3866
3948
|
const config$j = {
|
|
@@ -3889,11 +3971,15 @@ async function run$j(argv, importMeta, {
|
|
|
3889
3971
|
parentName
|
|
3890
3972
|
});
|
|
3891
3973
|
if (cli.flags['dryRun']) {
|
|
3892
|
-
|
|
3974
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$j);
|
|
3975
|
+
return;
|
|
3893
3976
|
}
|
|
3894
3977
|
await wrapNpx(argv);
|
|
3895
3978
|
}
|
|
3896
3979
|
|
|
3980
|
+
const {
|
|
3981
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$i
|
|
3982
|
+
} = constants;
|
|
3897
3983
|
const config$i = {
|
|
3898
3984
|
commandName: 'oops',
|
|
3899
3985
|
description: 'Trigger an intentional error (for development)',
|
|
@@ -3923,7 +4009,8 @@ async function run$i(argv, importMeta, {
|
|
|
3923
4009
|
parentName
|
|
3924
4010
|
});
|
|
3925
4011
|
if (cli.flags['dryRun']) {
|
|
3926
|
-
|
|
4012
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$i);
|
|
4013
|
+
return;
|
|
3927
4014
|
}
|
|
3928
4015
|
throw new Error('This error was intentionally left blank');
|
|
3929
4016
|
}
|
|
@@ -3976,7 +4063,7 @@ async function getAgentVersion(agentExecPath, cwd) {
|
|
|
3976
4063
|
try {
|
|
3977
4064
|
result = semver.coerce(
|
|
3978
4065
|
// All package managers support the "--version" flag.
|
|
3979
|
-
(await spawn(agentExecPath, ['--version'], {
|
|
4066
|
+
(await spawn.spawn(agentExecPath, ['--version'], {
|
|
3980
4067
|
cwd
|
|
3981
4068
|
})).stdout) ?? undefined;
|
|
3982
4069
|
} catch {}
|
|
@@ -4031,7 +4118,7 @@ const readLockFileByAgent = (() => {
|
|
|
4031
4118
|
// To print a Yarn lockfile to your console without writing it to disk
|
|
4032
4119
|
// use `bun bun.lockb`.
|
|
4033
4120
|
// https://bun.sh/guides/install/yarnlock
|
|
4034
|
-
return (await spawn(agentExecPath, [lockPath])).stdout.trim();
|
|
4121
|
+
return (await spawn.spawn(agentExecPath, [lockPath])).stdout.trim();
|
|
4035
4122
|
}
|
|
4036
4123
|
return undefined;
|
|
4037
4124
|
}),
|
|
@@ -4430,7 +4517,7 @@ function parseableToQueryStdout(stdout) {
|
|
|
4430
4517
|
async function npmQuery(npmExecPath, cwd) {
|
|
4431
4518
|
let stdout = '';
|
|
4432
4519
|
try {
|
|
4433
|
-
stdout = (await spawn(npmExecPath, ['query', ':not(.dev)'], {
|
|
4520
|
+
stdout = (await spawn.spawn(npmExecPath, ['query', ':not(.dev)'], {
|
|
4434
4521
|
cwd
|
|
4435
4522
|
})).stdout;
|
|
4436
4523
|
} catch {}
|
|
@@ -4440,7 +4527,7 @@ async function lsBun(agentExecPath, cwd) {
|
|
|
4440
4527
|
try {
|
|
4441
4528
|
// Bun does not support filtering by production packages yet.
|
|
4442
4529
|
// https://github.com/oven-sh/bun/issues/8283
|
|
4443
|
-
return (await spawn(agentExecPath, ['pm', 'ls', '--all'], {
|
|
4530
|
+
return (await spawn.spawn(agentExecPath, ['pm', 'ls', '--all'], {
|
|
4444
4531
|
cwd
|
|
4445
4532
|
})).stdout;
|
|
4446
4533
|
} catch {}
|
|
@@ -4459,7 +4546,7 @@ async function lsPnpm(agentExecPath, cwd, options) {
|
|
|
4459
4546
|
}
|
|
4460
4547
|
let stdout = '';
|
|
4461
4548
|
try {
|
|
4462
|
-
stdout = (await spawn(agentExecPath, ['ls', '--parseable', '--prod', '--depth', 'Infinity'], {
|
|
4549
|
+
stdout = (await spawn.spawn(agentExecPath, ['ls', '--parseable', '--prod', '--depth', 'Infinity'], {
|
|
4463
4550
|
cwd
|
|
4464
4551
|
})).stdout;
|
|
4465
4552
|
} catch {}
|
|
@@ -4468,7 +4555,7 @@ async function lsPnpm(agentExecPath, cwd, options) {
|
|
|
4468
4555
|
async function lsVlt(agentExecPath, cwd) {
|
|
4469
4556
|
let stdout = '';
|
|
4470
4557
|
try {
|
|
4471
|
-
stdout = (await spawn(agentExecPath, ['ls', '--view', 'human', ':not(.dev)'], {
|
|
4558
|
+
stdout = (await spawn.spawn(agentExecPath, ['ls', '--view', 'human', ':not(.dev)'], {
|
|
4472
4559
|
cwd
|
|
4473
4560
|
})).stdout;
|
|
4474
4561
|
} catch {}
|
|
@@ -4479,7 +4566,7 @@ async function lsYarnBerry(agentExecPath, cwd) {
|
|
|
4479
4566
|
return (
|
|
4480
4567
|
// Yarn Berry does not support filtering by production packages yet.
|
|
4481
4568
|
// https://github.com/yarnpkg/berry/issues/5117
|
|
4482
|
-
(await spawn(agentExecPath, ['info', '--recursive', '--name-only'], {
|
|
4569
|
+
(await spawn.spawn(agentExecPath, ['info', '--recursive', '--name-only'], {
|
|
4483
4570
|
cwd
|
|
4484
4571
|
})).stdout.trim()
|
|
4485
4572
|
);
|
|
@@ -4492,7 +4579,7 @@ async function lsYarnClassic(agentExecPath, cwd) {
|
|
|
4492
4579
|
// https://github.com/yarnpkg/yarn/releases/tag/v1.0.0
|
|
4493
4580
|
// > Fix: Excludes dev dependencies from the yarn list output when the
|
|
4494
4581
|
// environment is production
|
|
4495
|
-
return (await spawn(agentExecPath, ['list', '--prod'], {
|
|
4582
|
+
return (await spawn.spawn(agentExecPath, ['list', '--prod'], {
|
|
4496
4583
|
cwd
|
|
4497
4584
|
})).stdout.trim();
|
|
4498
4585
|
} catch {}
|
|
@@ -4617,14 +4704,73 @@ function pnpmUpdatePkgJson(editablePkgJson, overrides) {
|
|
|
4617
4704
|
}
|
|
4618
4705
|
const updateManifestByAgent = new Map([[BUN, updateResolutions], [NPM$4, updateOverrides], [PNPM$1, pnpmUpdatePkgJson], [VLT, updateOverrides], [YARN_BERRY, updateResolutions], [YARN_CLASSIC$1, updateResolutions]]);
|
|
4619
4706
|
|
|
4707
|
+
const {
|
|
4708
|
+
SOCKET_IPC_HANDSHAKE
|
|
4709
|
+
} = constants;
|
|
4710
|
+
function safeNpmInstall(options) {
|
|
4711
|
+
const {
|
|
4712
|
+
args = [],
|
|
4713
|
+
ipc,
|
|
4714
|
+
spinner,
|
|
4715
|
+
...spawnOptions
|
|
4716
|
+
} = {
|
|
4717
|
+
__proto__: null,
|
|
4718
|
+
...options
|
|
4719
|
+
};
|
|
4720
|
+
const terminatorPos = args.indexOf('--');
|
|
4721
|
+
const npmArgs = (terminatorPos === -1 ? args : args.slice(0, terminatorPos)).filter(a => !npm.isAuditFlag(a) && !npm.isFundFlag(a) && !npm.isProgressFlag(a));
|
|
4722
|
+
const otherArgs = terminatorPos === -1 ? [] : args.slice(terminatorPos);
|
|
4723
|
+
const useIpc = objects.isObject(ipc);
|
|
4724
|
+
const useDebug = debug.isDebug();
|
|
4725
|
+
const isSilent = !useDebug && !npmArgs.some(npm.isLoglevelFlag);
|
|
4726
|
+
const spawnPromise = spawn.spawn(
|
|
4727
|
+
// Lazily access constants.execPath.
|
|
4728
|
+
constants.execPath, [
|
|
4729
|
+
// Lazily access constants.nodeNoWarningsFlags.
|
|
4730
|
+
...constants.nodeNoWarningsFlags, '--require',
|
|
4731
|
+
// Lazily access constants.npmInjectionPath.
|
|
4732
|
+
constants.npmInjectionPath, npmPaths.getNpmBinPath(), 'install',
|
|
4733
|
+
// Even though the '--silent' flag is passed npm will still run through
|
|
4734
|
+
// code paths for 'audit' and 'fund' unless '--no-audit' and '--no-fund'
|
|
4735
|
+
// flags are passed.
|
|
4736
|
+
'--no-audit', '--no-fund',
|
|
4737
|
+
// Add `--no-progress` and `--silent` flags to fix input being swallowed
|
|
4738
|
+
// by the spinner when running the command with recent versions of npm.
|
|
4739
|
+
'--no-progress',
|
|
4740
|
+
// Add the '--silent' flag if a loglevel flag is not provided and the
|
|
4741
|
+
// SOCKET_CLI_DEBUG environment variable is not truthy.
|
|
4742
|
+
...(isSilent ? ['--silent'] : []), ...npmArgs, ...otherArgs], {
|
|
4743
|
+
spinner,
|
|
4744
|
+
// Set stdio to include 'ipc'.
|
|
4745
|
+
// See https://github.com/nodejs/node/blob/v23.6.0/lib/child_process.js#L161-L166
|
|
4746
|
+
// and https://github.com/nodejs/node/blob/v23.6.0/lib/internal/child_process.js#L238.
|
|
4747
|
+
stdio: isSilent ?
|
|
4748
|
+
// 'ignore'
|
|
4749
|
+
useIpc ? ['ignore', 'ignore', 'ignore', 'ipc'] : 'ignore' :
|
|
4750
|
+
// 'inherit'
|
|
4751
|
+
useIpc ? [0, 1, 2, 'ipc'] : 'inherit',
|
|
4752
|
+
...spawnOptions,
|
|
4753
|
+
env: {
|
|
4754
|
+
...process$1.env,
|
|
4755
|
+
...spawnOptions.env
|
|
4756
|
+
}
|
|
4757
|
+
});
|
|
4758
|
+
if (useIpc) {
|
|
4759
|
+
spawnPromise.process.send({
|
|
4760
|
+
[SOCKET_IPC_HANDSHAKE]: ipc
|
|
4761
|
+
});
|
|
4762
|
+
}
|
|
4763
|
+
return spawnPromise;
|
|
4764
|
+
}
|
|
4765
|
+
|
|
4620
4766
|
const {
|
|
4621
4767
|
NPM: NPM$3,
|
|
4622
|
-
abortSignal
|
|
4768
|
+
abortSignal
|
|
4623
4769
|
} = constants;
|
|
4624
4770
|
function runAgentInstall(agent, agentExecPath, options) {
|
|
4625
4771
|
// All package managers support the "install" command.
|
|
4626
4772
|
if (agent === NPM$3) {
|
|
4627
|
-
return
|
|
4773
|
+
return safeNpmInstall(options);
|
|
4628
4774
|
}
|
|
4629
4775
|
const {
|
|
4630
4776
|
args = [],
|
|
@@ -4634,13 +4780,10 @@ function runAgentInstall(agent, agentExecPath, options) {
|
|
|
4634
4780
|
__proto__: null,
|
|
4635
4781
|
...options
|
|
4636
4782
|
};
|
|
4637
|
-
const isSilent = !
|
|
4638
|
-
|
|
4639
|
-
|
|
4640
|
-
spinner
|
|
4641
|
-
}
|
|
4642
|
-
let spawnPromise = spawn(agentExecPath, ['install', ...args], {
|
|
4643
|
-
signal: abortSignal$2,
|
|
4783
|
+
const isSilent = !debug.isDebug();
|
|
4784
|
+
return spawn.spawn(agentExecPath, ['install', ...args], {
|
|
4785
|
+
signal: abortSignal,
|
|
4786
|
+
spinner,
|
|
4644
4787
|
stdio: isSilent ? 'ignore' : 'inherit',
|
|
4645
4788
|
...spawnOptions,
|
|
4646
4789
|
env: {
|
|
@@ -4648,22 +4791,12 @@ function runAgentInstall(agent, agentExecPath, options) {
|
|
|
4648
4791
|
...spawnOptions.env
|
|
4649
4792
|
}
|
|
4650
4793
|
});
|
|
4651
|
-
if (!isSilent && isSpinning) {
|
|
4652
|
-
const oldSpawnPromise = spawnPromise;
|
|
4653
|
-
spawnPromise = spawnPromise.finally(() => {
|
|
4654
|
-
spinner?.start();
|
|
4655
|
-
});
|
|
4656
|
-
spawnPromise.process = oldSpawnPromise.process;
|
|
4657
|
-
spawnPromise.stdin = spawnPromise.stdin;
|
|
4658
|
-
}
|
|
4659
|
-
return spawnPromise;
|
|
4660
4794
|
}
|
|
4661
4795
|
|
|
4662
4796
|
const {
|
|
4663
4797
|
NPM: NPM$2
|
|
4664
4798
|
} = constants;
|
|
4665
4799
|
const COMMAND_TITLE$1 = 'Socket Optimize';
|
|
4666
|
-
const NPM_OVERRIDE_PR_URL = 'https://github.com/npm/cli/pull/8089';
|
|
4667
4800
|
async function updatePackageLockJson(pkgEnvDetails, options) {
|
|
4668
4801
|
const {
|
|
4669
4802
|
logger,
|
|
@@ -4679,10 +4812,11 @@ async function updatePackageLockJson(pkgEnvDetails, options) {
|
|
|
4679
4812
|
});
|
|
4680
4813
|
spinner?.stop();
|
|
4681
4814
|
if (pkgEnvDetails.agent === NPM$2) {
|
|
4682
|
-
logger?.log(`💡 Re-run ${COMMAND_TITLE$1} whenever ${pkgEnvDetails.lockName} changes.\n This can be skipped once npm
|
|
4815
|
+
logger?.log(`💡 Re-run ${COMMAND_TITLE$1} whenever ${pkgEnvDetails.lockName} changes.\n This can be skipped once npm v11.2.0 is released.`);
|
|
4683
4816
|
}
|
|
4684
4817
|
} catch (e) {
|
|
4685
|
-
spinner?.
|
|
4818
|
+
spinner?.stop();
|
|
4819
|
+
logger?.error(`${COMMAND_TITLE$1}: ${pkgEnvDetails.agent} install failed to update ${pkgEnvDetails.lockName}`);
|
|
4686
4820
|
logger?.error(e);
|
|
4687
4821
|
}
|
|
4688
4822
|
}
|
|
@@ -4695,44 +4829,44 @@ const {
|
|
|
4695
4829
|
const COMMAND_TITLE = 'Socket Optimize';
|
|
4696
4830
|
const manifestNpmOverrides = registry.getManifestData(NPM$1);
|
|
4697
4831
|
async function applyOptimization(cwd, pin, prod) {
|
|
4698
|
-
const logger = console;
|
|
4699
4832
|
const pkgEnvDetails = await detectAndValidatePackageEnvironment(cwd, {
|
|
4700
|
-
logger,
|
|
4833
|
+
logger: logger.logger,
|
|
4701
4834
|
prod
|
|
4702
4835
|
});
|
|
4703
4836
|
if (!pkgEnvDetails) {
|
|
4704
4837
|
return;
|
|
4705
4838
|
}
|
|
4706
|
-
|
|
4707
|
-
|
|
4708
|
-
|
|
4709
|
-
|
|
4839
|
+
// Lazily access constants.spinner.
|
|
4840
|
+
const {
|
|
4841
|
+
spinner
|
|
4842
|
+
} = constants;
|
|
4843
|
+
spinner.start('Socket optimizing...');
|
|
4710
4844
|
const state = await addOverrides(pkgEnvDetails.pkgPath, pkgEnvDetails, {
|
|
4711
|
-
logger,
|
|
4845
|
+
logger: logger.logger,
|
|
4712
4846
|
pin,
|
|
4713
4847
|
prod,
|
|
4714
|
-
spinner
|
|
4848
|
+
spinner
|
|
4715
4849
|
});
|
|
4716
|
-
spinner
|
|
4850
|
+
spinner.stop();
|
|
4717
4851
|
const addedCount = state.added.size;
|
|
4718
4852
|
const updatedCount = state.updated.size;
|
|
4719
4853
|
const pkgJsonChanged = addedCount > 0 || updatedCount > 0;
|
|
4720
4854
|
if (pkgJsonChanged) {
|
|
4721
4855
|
if (updatedCount > 0) {
|
|
4722
|
-
logger?.log(`${createActionMessage('Updated', updatedCount, state.updatedInWorkspaces.size)}${addedCount ? '.' : '🚀'}`);
|
|
4856
|
+
logger.logger?.log(`${createActionMessage('Updated', updatedCount, state.updatedInWorkspaces.size)}${addedCount ? '.' : '🚀'}`);
|
|
4723
4857
|
}
|
|
4724
4858
|
if (addedCount > 0) {
|
|
4725
|
-
logger?.log(`${createActionMessage('Added', addedCount, state.addedInWorkspaces.size)} 🚀`);
|
|
4859
|
+
logger.logger?.log(`${createActionMessage('Added', addedCount, state.addedInWorkspaces.size)} 🚀`);
|
|
4726
4860
|
}
|
|
4727
4861
|
} else {
|
|
4728
|
-
logger?.log('Congratulations! Already Socket.dev optimized 🎉');
|
|
4862
|
+
logger.logger?.log('Congratulations! Already Socket.dev optimized 🎉');
|
|
4729
4863
|
}
|
|
4730
4864
|
if (pkgEnvDetails.agent === NPM$1 || pkgJsonChanged) {
|
|
4731
4865
|
// Always update package-lock.json until the npm overrides PR lands:
|
|
4732
4866
|
// https://github.com/npm/cli/pull/8089
|
|
4733
4867
|
await updatePackageLockJson(pkgEnvDetails, {
|
|
4734
|
-
logger,
|
|
4735
|
-
spinner
|
|
4868
|
+
logger: logger.logger,
|
|
4869
|
+
spinner
|
|
4736
4870
|
});
|
|
4737
4871
|
}
|
|
4738
4872
|
}
|
|
@@ -4918,6 +5052,9 @@ async function addOverrides(pkgPath, pkgEnvDetails, options) {
|
|
|
4918
5052
|
return state;
|
|
4919
5053
|
}
|
|
4920
5054
|
|
|
5055
|
+
const {
|
|
5056
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$h
|
|
5057
|
+
} = constants;
|
|
4921
5058
|
const config$h = {
|
|
4922
5059
|
commandName: 'optimize',
|
|
4923
5060
|
description: 'Optimize dependencies with @socketregistry overrides',
|
|
@@ -4963,7 +5100,8 @@ async function run$h(argv, importMeta, {
|
|
|
4963
5100
|
});
|
|
4964
5101
|
const cwd = process$1.cwd();
|
|
4965
5102
|
if (cli.flags['dryRun']) {
|
|
4966
|
-
|
|
5103
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$h);
|
|
5104
|
+
return;
|
|
4967
5105
|
}
|
|
4968
5106
|
await applyOptimization(cwd, Boolean(cli.flags['pin']), Boolean(cli.flags['prod']));
|
|
4969
5107
|
}
|
|
@@ -4976,21 +5114,24 @@ async function getOrganization(format = 'text') {
|
|
|
4976
5114
|
await printOrganizationsFromToken(apiToken, format);
|
|
4977
5115
|
}
|
|
4978
5116
|
async function printOrganizationsFromToken(apiToken, format = 'text') {
|
|
4979
|
-
|
|
4980
|
-
|
|
5117
|
+
// Lazily access constants.spinner.
|
|
5118
|
+
const {
|
|
5119
|
+
spinner
|
|
5120
|
+
} = constants;
|
|
5121
|
+
spinner.start('Fetching organizations...');
|
|
4981
5122
|
const socketSdk = await index.setupSdk(apiToken);
|
|
4982
5123
|
const result = await handleApiCall(socketSdk.getOrganizations(), 'looking up organizations');
|
|
4983
5124
|
if (!result.success) {
|
|
4984
|
-
handleUnsuccessfulApiResponse('getOrganizations', result, spinner
|
|
5125
|
+
handleUnsuccessfulApiResponse('getOrganizations', result, spinner);
|
|
4985
5126
|
return;
|
|
4986
5127
|
}
|
|
4987
|
-
spinner
|
|
5128
|
+
spinner.stop();
|
|
4988
5129
|
const organizations = Object.values(result.data.organizations);
|
|
4989
5130
|
const lastFiveOfApiToken = getLastFiveOfApiToken(apiToken);
|
|
4990
5131
|
switch (format) {
|
|
4991
5132
|
case 'json':
|
|
4992
5133
|
{
|
|
4993
|
-
|
|
5134
|
+
logger.logger.log(JSON.stringify(organizations.map(o => ({
|
|
4994
5135
|
name: o.name,
|
|
4995
5136
|
id: o.id,
|
|
4996
5137
|
plan: o.plan
|
|
@@ -5011,27 +5152,30 @@ async function printOrganizationsFromToken(apiToken, format = 'text') {
|
|
|
5011
5152
|
mw2 = Math.max(mw2, o.id.length);
|
|
5012
5153
|
mw3 = Math.max(mw3, o.plan.length);
|
|
5013
5154
|
}
|
|
5014
|
-
|
|
5015
|
-
|
|
5016
|
-
|
|
5017
|
-
|
|
5155
|
+
logger.logger.log('# Organizations\n');
|
|
5156
|
+
logger.logger.log(`List of organizations associated with your API key, ending with: ${colors.italic(lastFiveOfApiToken)}\n`);
|
|
5157
|
+
logger.logger.log(`| Name${' '.repeat(mw1 - 4)} | ID${' '.repeat(mw2 - 2)} | Plan${' '.repeat(mw3 - 4)} |`);
|
|
5158
|
+
logger.logger.log(`| ${'-'.repeat(mw1)} | ${'-'.repeat(mw2)} | ${'-'.repeat(mw3)} |`);
|
|
5018
5159
|
for (const o of organizations) {
|
|
5019
|
-
|
|
5160
|
+
logger.logger.log(`| ${(o.name || '').padEnd(mw1, ' ')} | ${(o.id || '').padEnd(mw2, ' ')} | ${(o.plan || '').padEnd(mw3, ' ')} |`);
|
|
5020
5161
|
}
|
|
5021
|
-
|
|
5162
|
+
logger.logger.log(`| ${'-'.repeat(mw1)} | ${'-'.repeat(mw2)} | ${'-'.repeat(mw3)} |`);
|
|
5022
5163
|
return;
|
|
5023
5164
|
}
|
|
5024
5165
|
default:
|
|
5025
5166
|
{
|
|
5026
|
-
|
|
5167
|
+
logger.logger.log(`List of organizations associated with your API key, ending with: ${colors.italic(lastFiveOfApiToken)}\n`);
|
|
5027
5168
|
// Just dump
|
|
5028
5169
|
for (const o of organizations) {
|
|
5029
|
-
|
|
5170
|
+
logger.logger.log(`- Name: ${colors.bold(o.name)}, ID: ${colors.bold(o.id)}, Plan: ${colors.bold(o.plan)}`);
|
|
5030
5171
|
}
|
|
5031
5172
|
}
|
|
5032
5173
|
}
|
|
5033
5174
|
}
|
|
5034
5175
|
|
|
5176
|
+
const {
|
|
5177
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$g
|
|
5178
|
+
} = constants;
|
|
5035
5179
|
const config$g = {
|
|
5036
5180
|
commandName: 'organizations',
|
|
5037
5181
|
description: 'List organizations associated with the API key used',
|
|
@@ -5069,31 +5213,25 @@ async function run$g(argv, importMeta, {
|
|
|
5069
5213
|
// options or missing arguments.
|
|
5070
5214
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
5071
5215
|
process.exitCode = 2;
|
|
5072
|
-
|
|
5216
|
+
logger.logger.error(`
|
|
5073
5217
|
${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
5074
5218
|
- The json and markdown flags cannot be both set, pick one
|
|
5075
5219
|
`);
|
|
5076
5220
|
return;
|
|
5077
5221
|
}
|
|
5078
5222
|
if (cli.flags['dryRun']) {
|
|
5079
|
-
|
|
5223
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$g);
|
|
5224
|
+
return;
|
|
5080
5225
|
}
|
|
5081
5226
|
await getOrganization(json ? 'json' : markdown ? 'markdown' : 'text');
|
|
5082
5227
|
}
|
|
5083
5228
|
|
|
5084
|
-
const {
|
|
5085
|
-
abortSignal: abortSignal$1
|
|
5086
|
-
} = constants;
|
|
5087
5229
|
async function runRawNpm(argv) {
|
|
5088
|
-
const spawnPromise = spawn(npmPaths.getNpmBinPath(), argv
|
|
5089
|
-
signal: abortSignal$1,
|
|
5230
|
+
const spawnPromise = spawn.spawn(npmPaths.getNpmBinPath(), argv, {
|
|
5090
5231
|
stdio: 'inherit'
|
|
5091
5232
|
});
|
|
5092
5233
|
// See https://nodejs.org/api/all.html#all_child_process_event-exit.
|
|
5093
5234
|
spawnPromise.process.on('exit', (code, signalName) => {
|
|
5094
|
-
if (abortSignal$1.aborted) {
|
|
5095
|
-
return;
|
|
5096
|
-
}
|
|
5097
5235
|
if (signalName) {
|
|
5098
5236
|
process$1.kill(process$1.pid, signalName);
|
|
5099
5237
|
} else if (code !== null) {
|
|
@@ -5104,6 +5242,7 @@ async function runRawNpm(argv) {
|
|
|
5104
5242
|
}
|
|
5105
5243
|
|
|
5106
5244
|
const {
|
|
5245
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$f,
|
|
5107
5246
|
NPM
|
|
5108
5247
|
} = constants;
|
|
5109
5248
|
const config$f = {
|
|
@@ -5138,24 +5277,18 @@ async function run$f(argv, importMeta, {
|
|
|
5138
5277
|
parentName
|
|
5139
5278
|
});
|
|
5140
5279
|
if (cli.flags['dryRun']) {
|
|
5141
|
-
|
|
5280
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$f);
|
|
5281
|
+
return;
|
|
5142
5282
|
}
|
|
5143
5283
|
await runRawNpm(argv);
|
|
5144
5284
|
}
|
|
5145
5285
|
|
|
5146
|
-
const {
|
|
5147
|
-
abortSignal
|
|
5148
|
-
} = constants;
|
|
5149
5286
|
async function runRawNpx(argv) {
|
|
5150
|
-
const spawnPromise = spawn(npmPaths.getNpxBinPath(), argv, {
|
|
5151
|
-
signal: abortSignal,
|
|
5287
|
+
const spawnPromise = spawn.spawn(npmPaths.getNpxBinPath(), argv, {
|
|
5152
5288
|
stdio: 'inherit'
|
|
5153
5289
|
});
|
|
5154
5290
|
// See https://nodejs.org/api/all.html#all_child_process_event-exit.
|
|
5155
5291
|
spawnPromise.process.on('exit', (code, signalName) => {
|
|
5156
|
-
if (abortSignal.aborted) {
|
|
5157
|
-
return;
|
|
5158
|
-
}
|
|
5159
5292
|
if (signalName) {
|
|
5160
5293
|
process$1.kill(process$1.pid, signalName);
|
|
5161
5294
|
} else if (code !== null) {
|
|
@@ -5166,6 +5299,7 @@ async function runRawNpx(argv) {
|
|
|
5166
5299
|
}
|
|
5167
5300
|
|
|
5168
5301
|
const {
|
|
5302
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$e,
|
|
5169
5303
|
NPX
|
|
5170
5304
|
} = constants;
|
|
5171
5305
|
const config$e = {
|
|
@@ -5200,18 +5334,26 @@ async function run$e(argv, importMeta, {
|
|
|
5200
5334
|
parentName
|
|
5201
5335
|
});
|
|
5202
5336
|
if (cli.flags['dryRun']) {
|
|
5203
|
-
|
|
5337
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$e);
|
|
5338
|
+
return;
|
|
5204
5339
|
}
|
|
5205
5340
|
await runRawNpx(argv);
|
|
5206
5341
|
}
|
|
5207
5342
|
|
|
5343
|
+
const {
|
|
5344
|
+
DRY_RUN_LABEL
|
|
5345
|
+
} = constants;
|
|
5208
5346
|
async function createReport(socketConfig, inputPaths, {
|
|
5209
5347
|
cwd,
|
|
5210
5348
|
dryRun
|
|
5211
5349
|
}) {
|
|
5350
|
+
// Lazily access constants.spinner.
|
|
5351
|
+
const {
|
|
5352
|
+
spinner
|
|
5353
|
+
} = constants;
|
|
5212
5354
|
const socketSdk = await index.setupSdk();
|
|
5213
5355
|
const supportedFiles = await socketSdk.getReportSupportedFiles().then(res => {
|
|
5214
|
-
if (!res.success) handleUnsuccessfulApiResponse('getReportSupportedFiles', res,
|
|
5356
|
+
if (!res.success) handleUnsuccessfulApiResponse('getReportSupportedFiles', res, spinner);
|
|
5215
5357
|
return res.data;
|
|
5216
5358
|
}).catch(cause => {
|
|
5217
5359
|
throw new Error('Failed getting supported files for report', {
|
|
@@ -5222,24 +5364,23 @@ async function createReport(socketConfig, inputPaths, {
|
|
|
5222
5364
|
const {
|
|
5223
5365
|
length: packagePathsCount
|
|
5224
5366
|
} = packagePaths;
|
|
5225
|
-
if (packagePathsCount &&
|
|
5367
|
+
if (packagePathsCount && debug.isDebug()) {
|
|
5226
5368
|
for (const pkgPath of packagePaths) {
|
|
5227
|
-
|
|
5369
|
+
debug.debugLog(`Uploading: ${pkgPath}`);
|
|
5228
5370
|
}
|
|
5229
5371
|
}
|
|
5230
5372
|
if (dryRun) {
|
|
5231
|
-
|
|
5373
|
+
debug.debugLog(`${DRY_RUN_LABEL}: Skipped actual upload`);
|
|
5232
5374
|
return undefined;
|
|
5233
5375
|
}
|
|
5234
|
-
|
|
5235
|
-
spinner$1.start(`Creating report with ${packagePathsCount} package ${words.pluralize('file', packagePathsCount)}`);
|
|
5376
|
+
spinner.start(`Creating report with ${packagePathsCount} package ${words.pluralize('file', packagePathsCount)}`);
|
|
5236
5377
|
const apiCall = socketSdk.createReportFromFilePaths(packagePaths, cwd, socketConfig?.issueRules);
|
|
5237
5378
|
const result = await handleApiCall(apiCall, 'creating report');
|
|
5238
5379
|
if (!result.success) {
|
|
5239
|
-
handleUnsuccessfulApiResponse('createReport', result, spinner
|
|
5380
|
+
handleUnsuccessfulApiResponse('createReport', result, spinner);
|
|
5240
5381
|
return undefined;
|
|
5241
5382
|
}
|
|
5242
|
-
spinner
|
|
5383
|
+
spinner.successAndStop();
|
|
5243
5384
|
return result;
|
|
5244
5385
|
}
|
|
5245
5386
|
|
|
@@ -5267,8 +5408,11 @@ async function getSocketConfig(absoluteConfigPath) {
|
|
|
5267
5408
|
const MAX_TIMEOUT_RETRY = 5;
|
|
5268
5409
|
const HTTP_CODE_TIMEOUT = 524;
|
|
5269
5410
|
async function fetchReportData(reportId, includeAllIssues, strict) {
|
|
5270
|
-
|
|
5271
|
-
|
|
5411
|
+
// Lazily access constants.spinner.
|
|
5412
|
+
const {
|
|
5413
|
+
spinner
|
|
5414
|
+
} = constants;
|
|
5415
|
+
spinner.start(`Fetching report with ID ${reportId} (this could take a while)`);
|
|
5272
5416
|
const socketSdk = await index.setupSdk();
|
|
5273
5417
|
let result;
|
|
5274
5418
|
for (let retry = 1; !result; ++retry) {
|
|
@@ -5277,43 +5421,43 @@ async function fetchReportData(reportId, includeAllIssues, strict) {
|
|
|
5277
5421
|
result = await handleApiCall(socketSdk.getReport(reportId), 'fetching report');
|
|
5278
5422
|
} catch (err) {
|
|
5279
5423
|
if (retry >= MAX_TIMEOUT_RETRY || !(err instanceof Error) || err.cause?.cause?.response?.statusCode !== HTTP_CODE_TIMEOUT) {
|
|
5280
|
-
spinner
|
|
5424
|
+
spinner.stop();
|
|
5281
5425
|
throw err;
|
|
5282
5426
|
}
|
|
5283
5427
|
}
|
|
5284
5428
|
}
|
|
5285
5429
|
if (!result.success) {
|
|
5286
|
-
return handleUnsuccessfulApiResponse('getReport', result, spinner
|
|
5430
|
+
return handleUnsuccessfulApiResponse('getReport', result, spinner);
|
|
5287
5431
|
}
|
|
5288
5432
|
|
|
5289
5433
|
// Conclude the status of the API call.
|
|
5290
5434
|
if (strict) {
|
|
5291
5435
|
if (result.data.healthy) {
|
|
5292
|
-
spinner
|
|
5436
|
+
spinner.success('Report result is healthy and great!');
|
|
5293
5437
|
} else {
|
|
5294
|
-
spinner
|
|
5438
|
+
spinner.error('Report result deemed unhealthy for project');
|
|
5295
5439
|
}
|
|
5296
5440
|
} else if (!result.data.healthy) {
|
|
5297
5441
|
const severityCount = getSeverityCount(result.data.issues, includeAllIssues ? undefined : 'high');
|
|
5298
5442
|
const issueSummary = formatSeverityCount(severityCount);
|
|
5299
|
-
spinner
|
|
5443
|
+
spinner.success(`Report has these issues: ${issueSummary}`);
|
|
5300
5444
|
} else {
|
|
5301
|
-
spinner
|
|
5445
|
+
spinner.success('Report has no issues');
|
|
5302
5446
|
}
|
|
5303
|
-
spinner
|
|
5447
|
+
spinner.stop();
|
|
5304
5448
|
return result.data;
|
|
5305
5449
|
}
|
|
5306
5450
|
|
|
5307
5451
|
function formatReportDataOutput(reportId, data, commandName, outputJson, outputMarkdown, strict) {
|
|
5308
5452
|
if (outputJson) {
|
|
5309
|
-
|
|
5453
|
+
logger.logger.log(JSON.stringify(data, undefined, 2));
|
|
5310
5454
|
} else {
|
|
5311
5455
|
const format = new index.ColorOrMarkdown(outputMarkdown);
|
|
5312
|
-
|
|
5456
|
+
logger.logger.log('\nDetailed info on socket.dev: ' + format.hyperlink(reportId, data.url, {
|
|
5313
5457
|
fallbackToUrl: true
|
|
5314
5458
|
}));
|
|
5315
5459
|
if (!outputMarkdown) {
|
|
5316
|
-
|
|
5460
|
+
logger.logger.log(colors.dim(`\nOr rerun ${colors.italic(commandName)} using the ${colors.italic('--json')} flag to get full JSON output`));
|
|
5317
5461
|
}
|
|
5318
5462
|
}
|
|
5319
5463
|
if (strict && !data.healthy) {
|
|
@@ -5334,6 +5478,9 @@ async function viewReport(reportId, {
|
|
|
5334
5478
|
}
|
|
5335
5479
|
}
|
|
5336
5480
|
|
|
5481
|
+
const {
|
|
5482
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$d
|
|
5483
|
+
} = constants;
|
|
5337
5484
|
const config$d = {
|
|
5338
5485
|
commandName: 'create',
|
|
5339
5486
|
description: 'Create a project report',
|
|
@@ -5404,7 +5551,8 @@ async function run$d(argv, importMeta, {
|
|
|
5404
5551
|
|
|
5405
5552
|
// Note exiting earlier to skirt a hidden auth requirement
|
|
5406
5553
|
if (cli.flags['dryRun']) {
|
|
5407
|
-
|
|
5554
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$d);
|
|
5555
|
+
return;
|
|
5408
5556
|
}
|
|
5409
5557
|
const socketConfig = await getSocketConfig(absoluteConfigPath);
|
|
5410
5558
|
const result = await createReport(socketConfig, cli.input, {
|
|
@@ -5423,17 +5571,19 @@ async function run$d(argv, importMeta, {
|
|
|
5423
5571
|
strict
|
|
5424
5572
|
});
|
|
5425
5573
|
} else if (json) {
|
|
5426
|
-
|
|
5427
|
-
return;
|
|
5574
|
+
logger.logger.log(JSON.stringify(result.data, undefined, 2));
|
|
5428
5575
|
} else {
|
|
5429
5576
|
const format = new index.ColorOrMarkdown(markdown);
|
|
5430
|
-
|
|
5577
|
+
logger.logger.log(`New report: ${format.hyperlink(result.data.id, result.data.url, {
|
|
5431
5578
|
fallbackToUrl: true
|
|
5432
5579
|
})}`);
|
|
5433
5580
|
}
|
|
5434
5581
|
}
|
|
5435
5582
|
}
|
|
5436
5583
|
|
|
5584
|
+
const {
|
|
5585
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$c
|
|
5586
|
+
} = constants;
|
|
5437
5587
|
const config$c = {
|
|
5438
5588
|
commandName: 'view',
|
|
5439
5589
|
description: 'View a project report',
|
|
@@ -5476,13 +5626,14 @@ async function run$c(argv, importMeta, {
|
|
|
5476
5626
|
// options or missing arguments.
|
|
5477
5627
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
5478
5628
|
process.exitCode = 2;
|
|
5479
|
-
|
|
5629
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
5480
5630
|
- Need at least one report ID ${!reportId ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
5481
5631
|
- Can only handle a single report ID ${extraInput.length < 2 ? colors.red(`(received ${extraInput.length}!)`) : colors.green('(ok)')}\n`);
|
|
5482
5632
|
return;
|
|
5483
5633
|
}
|
|
5484
5634
|
if (cli.flags['dryRun']) {
|
|
5485
|
-
|
|
5635
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$c);
|
|
5636
|
+
return;
|
|
5486
5637
|
}
|
|
5487
5638
|
await viewReport(reportId, {
|
|
5488
5639
|
all: Boolean(cli.flags['all']),
|
|
@@ -5522,8 +5673,11 @@ async function createRepo({
|
|
|
5522
5673
|
repoName,
|
|
5523
5674
|
visibility
|
|
5524
5675
|
}) {
|
|
5525
|
-
|
|
5526
|
-
|
|
5676
|
+
// Lazily access constants.spinner.
|
|
5677
|
+
const {
|
|
5678
|
+
spinner
|
|
5679
|
+
} = constants;
|
|
5680
|
+
spinner.start('Creating repository...');
|
|
5527
5681
|
const socketSdk = await index.setupSdk(apiToken);
|
|
5528
5682
|
const result = await handleApiCall(socketSdk.createOrgRepo(orgSlug, {
|
|
5529
5683
|
outputJson,
|
|
@@ -5536,12 +5690,15 @@ async function createRepo({
|
|
|
5536
5690
|
visibility
|
|
5537
5691
|
}), 'creating repository');
|
|
5538
5692
|
if (result.success) {
|
|
5539
|
-
spinner
|
|
5693
|
+
spinner.successAndStop('Repository created successfully');
|
|
5540
5694
|
} else {
|
|
5541
|
-
handleUnsuccessfulApiResponse('createOrgRepo', result, spinner
|
|
5695
|
+
handleUnsuccessfulApiResponse('createOrgRepo', result, spinner);
|
|
5542
5696
|
}
|
|
5543
5697
|
}
|
|
5544
5698
|
|
|
5699
|
+
const {
|
|
5700
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$b
|
|
5701
|
+
} = constants;
|
|
5545
5702
|
const config$b = {
|
|
5546
5703
|
commandName: 'create',
|
|
5547
5704
|
description: 'Create a repository in an organization',
|
|
@@ -5612,13 +5769,14 @@ async function run$b(argv, importMeta, {
|
|
|
5612
5769
|
// options or missing arguments.
|
|
5613
5770
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
5614
5771
|
process.exitCode = 2;
|
|
5615
|
-
|
|
5772
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
5616
5773
|
- Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
5617
5774
|
- Repository name using --repoName ${!repoName ? colors.red('(missing!)') : typeof repoName !== 'string' ? colors.red('(invalid!)') : colors.green('(ok)')}\n`);
|
|
5618
5775
|
return;
|
|
5619
5776
|
}
|
|
5620
5777
|
if (cli.flags['dryRun']) {
|
|
5621
|
-
|
|
5778
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$b);
|
|
5779
|
+
return;
|
|
5622
5780
|
}
|
|
5623
5781
|
const apiToken = index.getDefaultToken();
|
|
5624
5782
|
if (!apiToken) {
|
|
@@ -5638,17 +5796,23 @@ async function run$b(argv, importMeta, {
|
|
|
5638
5796
|
}
|
|
5639
5797
|
|
|
5640
5798
|
async function deleteRepo(orgSlug, repoName, apiToken) {
|
|
5641
|
-
|
|
5642
|
-
|
|
5799
|
+
// Lazily access constants.spinner.
|
|
5800
|
+
const {
|
|
5801
|
+
spinner
|
|
5802
|
+
} = constants;
|
|
5803
|
+
spinner.start('Deleting repository...');
|
|
5643
5804
|
const socketSdk = await index.setupSdk(apiToken);
|
|
5644
5805
|
const result = await handleApiCall(socketSdk.deleteOrgRepo(orgSlug, repoName), 'deleting repository');
|
|
5645
5806
|
if (result.success) {
|
|
5646
|
-
spinner
|
|
5807
|
+
spinner.successAndStop('Repository deleted successfully');
|
|
5647
5808
|
} else {
|
|
5648
|
-
handleUnsuccessfulApiResponse('deleteOrgRepo', result, spinner
|
|
5809
|
+
handleUnsuccessfulApiResponse('deleteOrgRepo', result, spinner);
|
|
5649
5810
|
}
|
|
5650
5811
|
}
|
|
5651
5812
|
|
|
5813
|
+
const {
|
|
5814
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$a
|
|
5815
|
+
} = constants;
|
|
5652
5816
|
const config$a = {
|
|
5653
5817
|
commandName: 'del',
|
|
5654
5818
|
description: 'Delete a repository in an organization',
|
|
@@ -5687,14 +5851,15 @@ async function run$a(argv, importMeta, {
|
|
|
5687
5851
|
// options or missing arguments.
|
|
5688
5852
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
5689
5853
|
process.exitCode = 2;
|
|
5690
|
-
|
|
5854
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
5691
5855
|
- Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
5692
5856
|
- Repository name as the second argument ${!repoName ? colors.red('(missing!)') : typeof repoName !== 'string' ? colors.red('(invalid!)') : colors.green('(ok)')}\n
|
|
5693
5857
|
- At least one TARGET (e.g. \`.\` or \`./package.json\`\n`);
|
|
5694
5858
|
return;
|
|
5695
5859
|
}
|
|
5696
5860
|
if (cli.flags['dryRun']) {
|
|
5697
|
-
|
|
5861
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$a);
|
|
5862
|
+
return;
|
|
5698
5863
|
}
|
|
5699
5864
|
const apiToken = index.getDefaultToken();
|
|
5700
5865
|
if (!apiToken) {
|
|
@@ -5714,10 +5879,11 @@ async function listRepos({
|
|
|
5714
5879
|
per_page,
|
|
5715
5880
|
sort
|
|
5716
5881
|
}) {
|
|
5717
|
-
|
|
5718
|
-
const
|
|
5719
|
-
|
|
5720
|
-
}
|
|
5882
|
+
// Lazily access constants.spinner.
|
|
5883
|
+
const {
|
|
5884
|
+
spinner
|
|
5885
|
+
} = constants;
|
|
5886
|
+
spinner.start('Listing repositories...');
|
|
5721
5887
|
const socketSdk = await index.setupSdk(apiToken);
|
|
5722
5888
|
const result = await handleApiCall(socketSdk.getOrgRepoList(orgSlug, {
|
|
5723
5889
|
outputJson,
|
|
@@ -5729,10 +5895,10 @@ async function listRepos({
|
|
|
5729
5895
|
page
|
|
5730
5896
|
}), 'listing repositories');
|
|
5731
5897
|
if (!result.success) {
|
|
5732
|
-
handleUnsuccessfulApiResponse('getOrgRepoList', result, spinner
|
|
5898
|
+
handleUnsuccessfulApiResponse('getOrgRepoList', result, spinner);
|
|
5733
5899
|
return;
|
|
5734
5900
|
}
|
|
5735
|
-
spinner
|
|
5901
|
+
spinner.stop();
|
|
5736
5902
|
if (outputJson) {
|
|
5737
5903
|
const data = result.data.results.map(o => ({
|
|
5738
5904
|
id: o.id,
|
|
@@ -5741,7 +5907,7 @@ async function listRepos({
|
|
|
5741
5907
|
defaultBranch: o.default_branch,
|
|
5742
5908
|
archived: o.archived
|
|
5743
5909
|
}));
|
|
5744
|
-
|
|
5910
|
+
logger.logger.log(JSON.stringify(data, null, 2));
|
|
5745
5911
|
return;
|
|
5746
5912
|
}
|
|
5747
5913
|
const options = {
|
|
@@ -5762,9 +5928,12 @@ async function listRepos({
|
|
|
5762
5928
|
name: colors.magenta('Archived')
|
|
5763
5929
|
}]
|
|
5764
5930
|
};
|
|
5765
|
-
|
|
5931
|
+
logger.logger.log(chalkTable(options, result.data.results));
|
|
5766
5932
|
}
|
|
5767
5933
|
|
|
5934
|
+
const {
|
|
5935
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$9
|
|
5936
|
+
} = constants;
|
|
5768
5937
|
const config$9 = {
|
|
5769
5938
|
commandName: 'list',
|
|
5770
5939
|
description: 'List repositories in an organization',
|
|
@@ -5827,13 +5996,14 @@ async function run$9(argv, importMeta, {
|
|
|
5827
5996
|
// options or missing arguments.
|
|
5828
5997
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
5829
5998
|
process.exitCode = 2;
|
|
5830
|
-
|
|
5999
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
5831
6000
|
- Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
5832
6001
|
- At least one TARGET (e.g. \`.\` or \`./package.json\`\n`);
|
|
5833
6002
|
return;
|
|
5834
6003
|
}
|
|
5835
6004
|
if (cli.flags['dryRun']) {
|
|
5836
|
-
|
|
6005
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$9);
|
|
6006
|
+
return;
|
|
5837
6007
|
}
|
|
5838
6008
|
const apiToken = index.getDefaultToken();
|
|
5839
6009
|
if (!apiToken) {
|
|
@@ -5862,10 +6032,11 @@ async function updateRepo({
|
|
|
5862
6032
|
repoName,
|
|
5863
6033
|
visibility
|
|
5864
6034
|
}) {
|
|
5865
|
-
|
|
5866
|
-
const
|
|
5867
|
-
|
|
5868
|
-
}
|
|
6035
|
+
// Lazily access constants.spinner.
|
|
6036
|
+
const {
|
|
6037
|
+
spinner
|
|
6038
|
+
} = constants;
|
|
6039
|
+
spinner.start('Updating repository...');
|
|
5869
6040
|
const socketSdk = await index.setupSdk(apiToken);
|
|
5870
6041
|
const result = await handleApiCall(socketSdk.updateOrgRepo(orgSlug, repoName, {
|
|
5871
6042
|
outputJson,
|
|
@@ -5878,12 +6049,15 @@ async function updateRepo({
|
|
|
5878
6049
|
visibility
|
|
5879
6050
|
}), 'updating repository');
|
|
5880
6051
|
if (result.success) {
|
|
5881
|
-
spinner
|
|
6052
|
+
spinner.successAndStop('Repository updated successfully');
|
|
5882
6053
|
} else {
|
|
5883
|
-
handleUnsuccessfulApiResponse('updateOrgRepo', result, spinner
|
|
6054
|
+
handleUnsuccessfulApiResponse('updateOrgRepo', result, spinner);
|
|
5884
6055
|
}
|
|
5885
6056
|
}
|
|
5886
6057
|
|
|
6058
|
+
const {
|
|
6059
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$8
|
|
6060
|
+
} = constants;
|
|
5887
6061
|
const config$8 = {
|
|
5888
6062
|
commandName: 'update',
|
|
5889
6063
|
description: 'Update a repository in an organization',
|
|
@@ -5954,14 +6128,15 @@ async function run$8(argv, importMeta, {
|
|
|
5954
6128
|
// options or missing arguments.
|
|
5955
6129
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
5956
6130
|
process.exitCode = 2;
|
|
5957
|
-
|
|
6131
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
5958
6132
|
- Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
5959
6133
|
- Repository name using --repoName ${!repoName ? colors.red('(missing!)') : typeof repoName !== 'string' ? colors.red('(invalid!)') : colors.green('(ok)')}\n
|
|
5960
6134
|
- At least one TARGET (e.g. \`.\` or \`./package.json\`\n`);
|
|
5961
6135
|
return;
|
|
5962
6136
|
}
|
|
5963
6137
|
if (cli.flags['dryRun']) {
|
|
5964
|
-
|
|
6138
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$8);
|
|
6139
|
+
return;
|
|
5965
6140
|
}
|
|
5966
6141
|
const apiToken = index.getDefaultToken();
|
|
5967
6142
|
if (!apiToken) {
|
|
@@ -5982,14 +6157,15 @@ async function run$8(argv, importMeta, {
|
|
|
5982
6157
|
|
|
5983
6158
|
// @ts-ignore
|
|
5984
6159
|
async function viewRepo(orgSlug, repoName, apiToken) {
|
|
5985
|
-
|
|
5986
|
-
const
|
|
5987
|
-
|
|
5988
|
-
}
|
|
6160
|
+
// Lazily access constants.spinner.
|
|
6161
|
+
const {
|
|
6162
|
+
spinner
|
|
6163
|
+
} = constants;
|
|
6164
|
+
spinner.start('Fetching repository...');
|
|
5989
6165
|
const socketSdk = await index.setupSdk(apiToken);
|
|
5990
6166
|
const result = await handleApiCall(socketSdk.getOrgRepo(orgSlug, repoName), 'fetching repository');
|
|
5991
6167
|
if (!result.success) {
|
|
5992
|
-
handleUnsuccessfulApiResponse('getOrgRepo', result, spinner
|
|
6168
|
+
handleUnsuccessfulApiResponse('getOrgRepo', result, spinner);
|
|
5993
6169
|
return;
|
|
5994
6170
|
}
|
|
5995
6171
|
const options = {
|
|
@@ -6016,9 +6192,12 @@ async function viewRepo(orgSlug, repoName, apiToken) {
|
|
|
6016
6192
|
name: colors.magenta('Created at')
|
|
6017
6193
|
}]
|
|
6018
6194
|
};
|
|
6019
|
-
spinner
|
|
6195
|
+
spinner.stop(chalkTable(options, [result.data]));
|
|
6020
6196
|
}
|
|
6021
6197
|
|
|
6198
|
+
const {
|
|
6199
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$7
|
|
6200
|
+
} = constants;
|
|
6022
6201
|
const config$7 = {
|
|
6023
6202
|
commandName: 'view',
|
|
6024
6203
|
description: 'View repositories in an organization',
|
|
@@ -6059,13 +6238,14 @@ async function run$7(argv, importMeta, {
|
|
|
6059
6238
|
// options or missing arguments.
|
|
6060
6239
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
6061
6240
|
process.exitCode = 2;
|
|
6062
|
-
|
|
6241
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
6063
6242
|
- Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
6064
6243
|
- Repository name using --repoName ${!repoName ? colors.red('(missing!)') : typeof repoName !== 'string' ? colors.red('(invalid!)') : colors.green('(ok)')}\n`);
|
|
6065
6244
|
return;
|
|
6066
6245
|
}
|
|
6067
6246
|
if (cli.flags['dryRun']) {
|
|
6068
|
-
|
|
6247
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$7);
|
|
6248
|
+
return;
|
|
6069
6249
|
}
|
|
6070
6250
|
const apiToken = index.getDefaultToken();
|
|
6071
6251
|
if (!apiToken) {
|
|
@@ -6192,7 +6372,7 @@ function dirNameToSlug(name) {
|
|
|
6192
6372
|
}
|
|
6193
6373
|
|
|
6194
6374
|
async function suggestBranchSlug(repoDefaultBranch) {
|
|
6195
|
-
const spawnResult =
|
|
6375
|
+
const spawnResult = spawn.spawnSync('git', ['branch', '--show-current']);
|
|
6196
6376
|
const currentBranch = spawnResult.stdout.toString('utf8').trim();
|
|
6197
6377
|
if (currentBranch && spawnResult.status === 0) {
|
|
6198
6378
|
const proceed = await prompts.select({
|
|
@@ -6252,10 +6432,14 @@ async function createFullScan({
|
|
|
6252
6432
|
targets,
|
|
6253
6433
|
tmp
|
|
6254
6434
|
}) {
|
|
6435
|
+
// Lazily access constants.spinner.
|
|
6436
|
+
const {
|
|
6437
|
+
spinner
|
|
6438
|
+
} = constants;
|
|
6255
6439
|
const socketSdk = await index.setupSdk();
|
|
6256
6440
|
const supportedFiles = await socketSdk.getReportSupportedFiles().then(res => {
|
|
6257
6441
|
if (!res.success) {
|
|
6258
|
-
handleUnsuccessfulApiResponse('getReportSupportedFiles', res,
|
|
6442
|
+
handleUnsuccessfulApiResponse('getReportSupportedFiles', res, spinner);
|
|
6259
6443
|
assert(false, 'handleUnsuccessfulApiResponse should unconditionally throw');
|
|
6260
6444
|
}
|
|
6261
6445
|
return res.data;
|
|
@@ -6312,7 +6496,7 @@ async function createFullScan({
|
|
|
6312
6496
|
// options or missing arguments.
|
|
6313
6497
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
6314
6498
|
process$1.exitCode = 2;
|
|
6315
|
-
|
|
6499
|
+
logger.logger.error(`
|
|
6316
6500
|
${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
6317
6501
|
- Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
6318
6502
|
- Repository name using --repo ${!repoName ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
@@ -6323,22 +6507,19 @@ async function createFullScan({
|
|
|
6323
6507
|
return;
|
|
6324
6508
|
}
|
|
6325
6509
|
if (updatedInput) {
|
|
6326
|
-
|
|
6327
|
-
|
|
6328
|
-
|
|
6329
|
-
|
|
6510
|
+
logger.logger.log('Note: You can invoke this command next time to skip the interactive questions:');
|
|
6511
|
+
logger.logger.log('```');
|
|
6512
|
+
logger.logger.log(` socket scan create [other flags...] --repo ${repoName} --branch ${branchName} ${orgSlug} ${targets.join(' ')}`);
|
|
6513
|
+
logger.logger.log('```');
|
|
6330
6514
|
}
|
|
6331
6515
|
if (!apiToken) {
|
|
6332
6516
|
throw new index.AuthError('User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.');
|
|
6333
6517
|
}
|
|
6334
6518
|
if (readOnly) {
|
|
6335
|
-
|
|
6519
|
+
logger.logger.log('[ReadOnly] Bailing now');
|
|
6336
6520
|
return;
|
|
6337
6521
|
}
|
|
6338
|
-
|
|
6339
|
-
const spinner$1 = new spinner.Spinner({
|
|
6340
|
-
text: spinnerText
|
|
6341
|
-
}).start();
|
|
6522
|
+
spinner.start('Creating a scan...');
|
|
6342
6523
|
const result = await handleApiCall(socketSdk.createOrgFullScan(orgSlug, {
|
|
6343
6524
|
repo: repoName,
|
|
6344
6525
|
branch: branchName,
|
|
@@ -6348,12 +6529,12 @@ async function createFullScan({
|
|
|
6348
6529
|
tmp
|
|
6349
6530
|
}, packagePaths, cwd), 'Creating scan');
|
|
6350
6531
|
if (!result.success) {
|
|
6351
|
-
handleUnsuccessfulApiResponse('CreateOrgFullScan', result, spinner
|
|
6532
|
+
handleUnsuccessfulApiResponse('CreateOrgFullScan', result, spinner);
|
|
6352
6533
|
return;
|
|
6353
6534
|
}
|
|
6354
|
-
spinner
|
|
6535
|
+
spinner.successAndStop('Scan created successfully');
|
|
6355
6536
|
const link = colors.underline(colors.cyan(`${result.data.html_report_url}`));
|
|
6356
|
-
|
|
6537
|
+
logger.logger.log(`Available at: ${link}`);
|
|
6357
6538
|
const rl = readline.createInterface({
|
|
6358
6539
|
input: process$1.stdin,
|
|
6359
6540
|
output: process$1.stdout
|
|
@@ -6365,6 +6546,9 @@ async function createFullScan({
|
|
|
6365
6546
|
rl.close();
|
|
6366
6547
|
}
|
|
6367
6548
|
|
|
6549
|
+
const {
|
|
6550
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$6
|
|
6551
|
+
} = constants;
|
|
6368
6552
|
const config$6 = {
|
|
6369
6553
|
commandName: 'create',
|
|
6370
6554
|
description: 'Create a scan',
|
|
@@ -6481,7 +6665,7 @@ async function run$6(argv, importMeta, {
|
|
|
6481
6665
|
// options or missing arguments.
|
|
6482
6666
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
6483
6667
|
process$1.exitCode = 2;
|
|
6484
|
-
|
|
6668
|
+
logger.logger.error(`
|
|
6485
6669
|
${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
6486
6670
|
- Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
6487
6671
|
- Repository name using --repo ${!repoName ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
@@ -6494,7 +6678,8 @@ async function run$6(argv, importMeta, {
|
|
|
6494
6678
|
|
|
6495
6679
|
// Note exiting earlier to skirt a hidden auth requirement
|
|
6496
6680
|
if (cli.flags['dryRun']) {
|
|
6497
|
-
|
|
6681
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$6);
|
|
6682
|
+
return;
|
|
6498
6683
|
}
|
|
6499
6684
|
await createFullScan({
|
|
6500
6685
|
branchName: branchName,
|
|
@@ -6514,17 +6699,23 @@ async function run$6(argv, importMeta, {
|
|
|
6514
6699
|
}
|
|
6515
6700
|
|
|
6516
6701
|
async function deleteOrgFullScan(orgSlug, fullScanId, apiToken) {
|
|
6517
|
-
|
|
6518
|
-
|
|
6702
|
+
// Lazily access constants.spinner.
|
|
6703
|
+
const {
|
|
6704
|
+
spinner
|
|
6705
|
+
} = constants;
|
|
6706
|
+
spinner.start('Deleting scan...');
|
|
6519
6707
|
const socketSdk = await index.setupSdk(apiToken);
|
|
6520
6708
|
const result = await handleApiCall(socketSdk.deleteOrgFullScan(orgSlug, fullScanId), 'Deleting scan');
|
|
6521
6709
|
if (!result.success) {
|
|
6522
|
-
handleUnsuccessfulApiResponse('deleteOrgFullScan', result, spinner
|
|
6710
|
+
handleUnsuccessfulApiResponse('deleteOrgFullScan', result, spinner);
|
|
6523
6711
|
return;
|
|
6524
6712
|
}
|
|
6525
|
-
spinner
|
|
6713
|
+
spinner.successAndStop('Scan deleted successfully');
|
|
6526
6714
|
}
|
|
6527
6715
|
|
|
6716
|
+
const {
|
|
6717
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$5
|
|
6718
|
+
} = constants;
|
|
6528
6719
|
const config$5 = {
|
|
6529
6720
|
commandName: 'del',
|
|
6530
6721
|
description: 'Delete a scan',
|
|
@@ -6564,13 +6755,14 @@ async function run$5(argv, importMeta, {
|
|
|
6564
6755
|
// options or missing arguments.
|
|
6565
6756
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
6566
6757
|
process.exitCode = 2;
|
|
6567
|
-
|
|
6758
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
6568
6759
|
- Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
6569
6760
|
- Full Scan ID to delete as second argument ${!fullScanId ? colors.red('(missing!)') : colors.green('(ok)')}\n`);
|
|
6570
6761
|
return;
|
|
6571
6762
|
}
|
|
6572
6763
|
if (cli.flags['dryRun']) {
|
|
6573
|
-
|
|
6764
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$5);
|
|
6765
|
+
return;
|
|
6574
6766
|
}
|
|
6575
6767
|
const apiToken = index.getDefaultToken();
|
|
6576
6768
|
if (!apiToken) {
|
|
@@ -6581,12 +6773,15 @@ async function run$5(argv, importMeta, {
|
|
|
6581
6773
|
|
|
6582
6774
|
// @ts-ignore
|
|
6583
6775
|
async function listFullScans(orgSlug, input, apiToken) {
|
|
6584
|
-
|
|
6585
|
-
|
|
6776
|
+
// Lazily access constants.spinner.
|
|
6777
|
+
const {
|
|
6778
|
+
spinner
|
|
6779
|
+
} = constants;
|
|
6780
|
+
spinner.start('Listing scans...');
|
|
6586
6781
|
const socketSdk = await index.setupSdk(apiToken);
|
|
6587
6782
|
const result = await handleApiCall(socketSdk.getOrgFullScanList(orgSlug, input), 'Listing scans');
|
|
6588
6783
|
if (!result.success) {
|
|
6589
|
-
handleUnsuccessfulApiResponse('getOrgFullScanList', result, spinner
|
|
6784
|
+
handleUnsuccessfulApiResponse('getOrgFullScanList', result, spinner);
|
|
6590
6785
|
return;
|
|
6591
6786
|
}
|
|
6592
6787
|
const options = {
|
|
@@ -6616,10 +6811,13 @@ async function listFullScans(orgSlug, input, apiToken) {
|
|
|
6616
6811
|
branch: d.branch
|
|
6617
6812
|
};
|
|
6618
6813
|
});
|
|
6619
|
-
spinner
|
|
6620
|
-
|
|
6814
|
+
spinner.stop(`Listing scans for: ${orgSlug}`);
|
|
6815
|
+
logger.logger.log(chalkTable(options, formattedResults));
|
|
6621
6816
|
}
|
|
6622
6817
|
|
|
6818
|
+
const {
|
|
6819
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$4
|
|
6820
|
+
} = constants;
|
|
6623
6821
|
const config$4 = {
|
|
6624
6822
|
commandName: 'list',
|
|
6625
6823
|
description: 'List the full scans for an organization',
|
|
@@ -6695,12 +6893,13 @@ async function run$4(argv, importMeta, {
|
|
|
6695
6893
|
// options or missing arguments.
|
|
6696
6894
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
6697
6895
|
process.exitCode = 2;
|
|
6698
|
-
|
|
6896
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
6699
6897
|
- Org name as the argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n`);
|
|
6700
6898
|
return;
|
|
6701
6899
|
}
|
|
6702
6900
|
if (cli.flags['dryRun']) {
|
|
6703
|
-
|
|
6901
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$4);
|
|
6902
|
+
return;
|
|
6704
6903
|
}
|
|
6705
6904
|
const apiToken = index.getDefaultToken();
|
|
6706
6905
|
if (!apiToken) {
|
|
@@ -6722,18 +6921,24 @@ async function run$4(argv, importMeta, {
|
|
|
6722
6921
|
}
|
|
6723
6922
|
|
|
6724
6923
|
async function getOrgScanMetadata(orgSlug, scanId, apiToken) {
|
|
6725
|
-
|
|
6726
|
-
|
|
6924
|
+
// Lazily access constants.spinner.
|
|
6925
|
+
const {
|
|
6926
|
+
spinner
|
|
6927
|
+
} = constants;
|
|
6928
|
+
spinner.start("Getting scan's metadata...");
|
|
6727
6929
|
const socketSdk = await index.setupSdk(apiToken);
|
|
6728
6930
|
const result = await handleApiCall(socketSdk.getOrgFullScanMetadata(orgSlug, scanId), 'Listing scans');
|
|
6729
6931
|
if (!result.success) {
|
|
6730
|
-
handleUnsuccessfulApiResponse('getOrgFullScanMetadata', result, spinner
|
|
6932
|
+
handleUnsuccessfulApiResponse('getOrgFullScanMetadata', result, spinner);
|
|
6731
6933
|
return;
|
|
6732
6934
|
}
|
|
6733
|
-
spinner
|
|
6734
|
-
|
|
6935
|
+
spinner.stop('Scan metadata:');
|
|
6936
|
+
logger.logger.log(result.data);
|
|
6735
6937
|
}
|
|
6736
6938
|
|
|
6939
|
+
const {
|
|
6940
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$3
|
|
6941
|
+
} = constants;
|
|
6737
6942
|
const config$3 = {
|
|
6738
6943
|
commandName: 'metadata',
|
|
6739
6944
|
description: "Get a full scan's metadata",
|
|
@@ -6773,13 +6978,14 @@ async function run$3(argv, importMeta, {
|
|
|
6773
6978
|
// options or missing arguments.
|
|
6774
6979
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
6775
6980
|
process.exitCode = 2;
|
|
6776
|
-
|
|
6981
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
6777
6982
|
- Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
6778
6983
|
- Full Scan ID to inspect as second argument ${!fullScanId ? colors.red('(missing!)') : colors.green('(ok)')}\n`);
|
|
6779
6984
|
return;
|
|
6780
6985
|
}
|
|
6781
6986
|
if (cli.flags['dryRun']) {
|
|
6782
|
-
|
|
6987
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$3);
|
|
6988
|
+
return;
|
|
6783
6989
|
}
|
|
6784
6990
|
const apiToken = index.getDefaultToken();
|
|
6785
6991
|
if (!apiToken) {
|
|
@@ -6789,18 +6995,24 @@ async function run$3(argv, importMeta, {
|
|
|
6789
6995
|
}
|
|
6790
6996
|
|
|
6791
6997
|
async function getFullScan(orgSlug, fullScanId, file, apiToken) {
|
|
6792
|
-
|
|
6793
|
-
|
|
6998
|
+
// Lazily access constants.spinner.
|
|
6999
|
+
const {
|
|
7000
|
+
spinner
|
|
7001
|
+
} = constants;
|
|
7002
|
+
spinner.start('Streaming scan...');
|
|
6794
7003
|
const socketSdk = await index.setupSdk(apiToken);
|
|
6795
7004
|
const data = await handleApiCall(socketSdk.getOrgFullScan(orgSlug, fullScanId, file === '-' ? undefined : file), 'Streaming a scan');
|
|
6796
7005
|
if (data?.success) {
|
|
6797
|
-
spinner
|
|
7006
|
+
spinner.stop(file ? `Full scan details written to ${file}` : '');
|
|
6798
7007
|
} else {
|
|
6799
|
-
handleUnsuccessfulApiResponse('getOrgFullScan', data, spinner
|
|
7008
|
+
handleUnsuccessfulApiResponse('getOrgFullScan', data, spinner);
|
|
6800
7009
|
}
|
|
6801
7010
|
return data;
|
|
6802
7011
|
}
|
|
6803
7012
|
|
|
7013
|
+
const {
|
|
7014
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$2
|
|
7015
|
+
} = constants;
|
|
6804
7016
|
const config$2 = {
|
|
6805
7017
|
commandName: 'stream',
|
|
6806
7018
|
description: 'Stream the output of a scan',
|
|
@@ -6842,13 +7054,14 @@ async function run$2(argv, importMeta, {
|
|
|
6842
7054
|
// options or missing arguments.
|
|
6843
7055
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
6844
7056
|
process.exitCode = 2;
|
|
6845
|
-
|
|
7057
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
6846
7058
|
- Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
6847
7059
|
- Full Scan ID to fetch as second argument ${!fullScanId ? colors.red('(missing!)') : colors.green('(ok)')}\n`);
|
|
6848
7060
|
return;
|
|
6849
7061
|
}
|
|
6850
7062
|
if (cli.flags['dryRun']) {
|
|
6851
|
-
|
|
7063
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$2);
|
|
7064
|
+
return;
|
|
6852
7065
|
}
|
|
6853
7066
|
const apiToken = index.getDefaultToken();
|
|
6854
7067
|
if (!apiToken) {
|
|
@@ -6886,8 +7099,11 @@ async function getThreatFeed({
|
|
|
6886
7099
|
page,
|
|
6887
7100
|
perPage
|
|
6888
7101
|
}) {
|
|
6889
|
-
|
|
6890
|
-
|
|
7102
|
+
// Lazily access constants.spinner.
|
|
7103
|
+
const {
|
|
7104
|
+
spinner
|
|
7105
|
+
} = constants;
|
|
7106
|
+
spinner.start('Looking up the threat feed');
|
|
6891
7107
|
const formattedQueryParams = formatQueryParams({
|
|
6892
7108
|
per_page: perPage,
|
|
6893
7109
|
page,
|
|
@@ -6896,9 +7112,9 @@ async function getThreatFeed({
|
|
|
6896
7112
|
}).join('&');
|
|
6897
7113
|
const response = await queryAPI(`threat-feed?${formattedQueryParams}`, apiToken);
|
|
6898
7114
|
const data = await response.json();
|
|
6899
|
-
spinner
|
|
7115
|
+
spinner.stop();
|
|
6900
7116
|
if (outputJson) {
|
|
6901
|
-
|
|
7117
|
+
logger.logger.log(data);
|
|
6902
7118
|
return;
|
|
6903
7119
|
}
|
|
6904
7120
|
const screen = new ScreenWidget();
|
|
@@ -6953,6 +7169,9 @@ function getMinDiff(start, end) {
|
|
|
6953
7169
|
return Math.floor((end - start) / 60000);
|
|
6954
7170
|
}
|
|
6955
7171
|
|
|
7172
|
+
const {
|
|
7173
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$1
|
|
7174
|
+
} = constants;
|
|
6956
7175
|
const config$1 = {
|
|
6957
7176
|
commandName: 'threat-feed',
|
|
6958
7177
|
description: 'Look up the threat feed',
|
|
@@ -7012,7 +7231,8 @@ async function run$1(argv, importMeta, {
|
|
|
7012
7231
|
parentName
|
|
7013
7232
|
});
|
|
7014
7233
|
if (cli.flags['dryRun']) {
|
|
7015
|
-
|
|
7234
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$1);
|
|
7235
|
+
return;
|
|
7016
7236
|
}
|
|
7017
7237
|
const apiToken = index.getDefaultToken();
|
|
7018
7238
|
if (!apiToken) {
|
|
@@ -7035,7 +7255,7 @@ function addSocketWrapper(file) {
|
|
|
7035
7255
|
}
|
|
7036
7256
|
// TODO: pretty sure you need to source the file or restart
|
|
7037
7257
|
// any terminal session before changes are reflected.
|
|
7038
|
-
|
|
7258
|
+
logger.logger.log(`
|
|
7039
7259
|
The alias was added to ${file}. Running 'npm install' will now be wrapped in Socket's "safe npm" 🎉
|
|
7040
7260
|
If you want to disable it at any time, run \`socket wrapper --disable\`
|
|
7041
7261
|
`);
|
|
@@ -7046,7 +7266,7 @@ function checkSocketWrapperSetup(file) {
|
|
|
7046
7266
|
const fileContent = fs.readFileSync(file, 'utf8');
|
|
7047
7267
|
const linesWithSocketAlias = fileContent.split('\n').filter(l => l === 'alias npm="socket npm"' || l === 'alias npx="socket npx"');
|
|
7048
7268
|
if (linesWithSocketAlias.length) {
|
|
7049
|
-
|
|
7269
|
+
logger.logger.log(`The Socket npm/npx wrapper is set up in your bash profile (${file}).`);
|
|
7050
7270
|
return true;
|
|
7051
7271
|
}
|
|
7052
7272
|
return false;
|
|
@@ -7068,7 +7288,7 @@ function postinstallWrapper() {
|
|
|
7068
7288
|
}
|
|
7069
7289
|
}
|
|
7070
7290
|
function installSafeNpm(query) {
|
|
7071
|
-
|
|
7291
|
+
logger.logger.log(`
|
|
7072
7292
|
_____ _ _
|
|
7073
7293
|
| __|___ ___| |_ ___| |_
|
|
7074
7294
|
|__ | . | _| '_| -_| _|
|
|
@@ -7111,24 +7331,27 @@ function askQuestion(rl, query) {
|
|
|
7111
7331
|
function removeSocketWrapper(file) {
|
|
7112
7332
|
return fs.readFile(file, 'utf8', function (err, data) {
|
|
7113
7333
|
if (err) {
|
|
7114
|
-
|
|
7334
|
+
logger.logger.error('There was an error removing the alias:');
|
|
7335
|
+
logger.logger.error(err);
|
|
7115
7336
|
return;
|
|
7116
7337
|
}
|
|
7117
7338
|
const linesWithoutSocketAlias = data.split('\n').filter(l => l !== 'alias npm="socket npm"' && l !== 'alias npx="socket npx"');
|
|
7118
7339
|
const updatedFileContent = linesWithoutSocketAlias.join('\n');
|
|
7119
7340
|
fs.writeFile(file, updatedFileContent, function (err) {
|
|
7120
7341
|
if (err) {
|
|
7121
|
-
|
|
7342
|
+
logger.logger.error(err);
|
|
7122
7343
|
return;
|
|
7123
|
-
} else {
|
|
7124
|
-
// TODO: pretty sure you need to source the file or restart
|
|
7125
|
-
// any terminal session before changes are reflected.
|
|
7126
|
-
console.log(`\nThe alias was removed from ${file}. Running 'npm install' will now run the standard npm command.\n`);
|
|
7127
7344
|
}
|
|
7345
|
+
// TODO: pretty sure you need to source the file or restart
|
|
7346
|
+
// any terminal session before changes are reflected.
|
|
7347
|
+
logger.logger.log(`The alias was removed from ${file}. Running 'npm install' will now run the standard npm command.`);
|
|
7128
7348
|
});
|
|
7129
7349
|
});
|
|
7130
7350
|
}
|
|
7131
7351
|
|
|
7352
|
+
const {
|
|
7353
|
+
DRY_RUN_BAIL_TEXT
|
|
7354
|
+
} = constants;
|
|
7132
7355
|
const config = {
|
|
7133
7356
|
commandName: 'wrapper',
|
|
7134
7357
|
description: 'Enable or disable the Socket npm/npx wrapper',
|
|
@@ -7185,12 +7408,13 @@ async function run(argv, importMeta, {
|
|
|
7185
7408
|
// options or missing arguments.
|
|
7186
7409
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
7187
7410
|
process.exitCode = 2;
|
|
7188
|
-
|
|
7411
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required flags:\n
|
|
7189
7412
|
- Must use --enabled or --disabled\n`);
|
|
7190
7413
|
return;
|
|
7191
7414
|
}
|
|
7192
7415
|
if (cli.flags['dryRun']) {
|
|
7193
|
-
|
|
7416
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT);
|
|
7417
|
+
return;
|
|
7194
7418
|
}
|
|
7195
7419
|
|
|
7196
7420
|
// Lazily access constants.bashRcPath and constants.zshRcPath.
|
|
@@ -7214,7 +7438,7 @@ async function run(argv, importMeta, {
|
|
|
7214
7438
|
}
|
|
7215
7439
|
}
|
|
7216
7440
|
if (!fs.existsSync(bashRcPath) && !fs.existsSync(zshRcPath)) {
|
|
7217
|
-
|
|
7441
|
+
logger.logger.error('There was an issue setting up the alias in your bash profile');
|
|
7218
7442
|
}
|
|
7219
7443
|
}
|
|
7220
7444
|
|
|
@@ -7289,10 +7513,10 @@ void (async () => {
|
|
|
7289
7513
|
}
|
|
7290
7514
|
logger.logger.error(`${colors.bgRed(colors.white(errorTitle + ':'))} ${errorMessage}`);
|
|
7291
7515
|
if (errorBody) {
|
|
7292
|
-
|
|
7516
|
+
logger.logger.error(`\n${errorBody}`);
|
|
7293
7517
|
}
|
|
7294
7518
|
await index.captureException(e);
|
|
7295
7519
|
}
|
|
7296
7520
|
})();
|
|
7297
|
-
//# debugId=
|
|
7521
|
+
//# debugId=436f332e-aa2a-480e-ac61-6da13459f0cb
|
|
7298
7522
|
//# sourceMappingURL=cli.js.map
|