Skip to content

Commit ad82e64

Browse files
tekeuange23fraxken
andauthored
Add a warning when NODE_SECURE_TOKEN is missing (#115)
* Add a warning when NODE_SECURE_TOKEN is missing * refacto: the condition, error catching & message stdout * refacto: removed test & updated the warning message * refactor: remove async try/catch Co-authored-by: Gentilhomme <gentilhomme.thomas@gmail.com>
1 parent 604ce59 commit ad82e64

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

bin/index.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,17 @@ defaultScannerCommand("cwd", { strategy: vuln.strategies.NPM_AUDIT })
4141
.describe(i18n.getToken("cli.commands.cwd.desc"))
4242
.option("-n, --nolock", i18n.getToken("cli.commands.cwd.option_nolock"), false)
4343
.option("-f, --full", i18n.getToken("cli.commands.cwd.option_full"), false)
44-
.action(commands.scanner.cwd);
44+
.action(async(_, __, opts) => {
45+
checkNodeSecureToken();
46+
await commands.scanner.cwd(opts);
47+
});
4548

4649
defaultScannerCommand("from <package>")
4750
.describe(i18n.getToken("cli.commands.from.desc"))
48-
.action(commands.scanner.from);
51+
.action(async(packageName, _, opts) => {
52+
checkNodeSecureToken();
53+
await commands.scanner.from(packageName, opts);
54+
});
4955

5056
defaultScannerCommand("auto [package]", { includeOutput: false, strategy: vuln.strategies.SECURITY_WG })
5157
.describe(i18n.getToken("cli.commands.auto.desc"))
@@ -62,7 +68,10 @@ prog
6268
.command("verify [package]")
6369
.describe(i18n.getToken("cli.commands.verify.desc"))
6470
.option("-j, --json", i18n.getToken("cli.commands.verify.option_json"), false)
65-
.action(commands.verify.main);
71+
.action(async(packageName, _, opts) => {
72+
checkNodeSecureToken();
73+
await commands.verify.main(packageName, opts);
74+
});
6675

6776
prog
6877
.command("summary [json]")
@@ -102,3 +111,13 @@ function defaultScannerCommand(name, options = {}) {
102111

103112
return cmd;
104113
}
114+
115+
function checkNodeSecureToken() {
116+
if (!process.env.NODE_SECURE_TOKEN) {
117+
console.log(
118+
kleur.white().bold(
119+
`\n ${kleur.yellow().bold(`Environment variable ${"\"NODE_SECURE_TOKEN\""} is missing.`)}`
120+
)
121+
);
122+
}
123+
}

test/commands/summary.spec.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
// Import Node.js Dependencies
2+
import dotenv from "dotenv";
23
import { spawn } from "child_process";
34
import { fileURLToPath } from "url";
45
import path from "path";
56

7+
dotenv.config();
8+
69
// Import Third-party Dependencies
710
import test from "tape";
811
import splitByLine from "split2";

0 commit comments

Comments
 (0)