safelaunch 1.0.25 → 1.0.26
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/package.json +1 -1
- package/src/scan.js +26 -8
package/package.json
CHANGED
package/src/scan.js
CHANGED
|
@@ -4,6 +4,14 @@ const fs = require("fs");
|
|
|
4
4
|
const path = require("path");
|
|
5
5
|
const { execSync } = require("child_process");
|
|
6
6
|
|
|
7
|
+
let _track = async () => {};
|
|
8
|
+
let _shutdown = async () => {};
|
|
9
|
+
try {
|
|
10
|
+
const t = require('./telemetry');
|
|
11
|
+
_track = t.track || _track;
|
|
12
|
+
_shutdown = t.shutdown || _shutdown;
|
|
13
|
+
} catch {}
|
|
14
|
+
|
|
7
15
|
const c = {
|
|
8
16
|
reset: "\x1b[0m", bold: "\x1b[1m", dim: "\x1b[2m",
|
|
9
17
|
red: "\x1b[31m", green: "\x1b[32m", yellow: "\x1b[33m",
|
|
@@ -73,8 +81,7 @@ const IMPACTS = {
|
|
|
73
81
|
};
|
|
74
82
|
|
|
75
83
|
function loadEnvFile(cwd) {
|
|
76
|
-
const
|
|
77
|
-
const content = readFileSafe(envPath);
|
|
84
|
+
const content = readFileSafe(path.join(cwd, ".env"));
|
|
78
85
|
if (!content) return {};
|
|
79
86
|
const vars = {};
|
|
80
87
|
for (const line of content.split("\n")) {
|
|
@@ -304,7 +311,7 @@ function renderInteractiveOutput(blockers, warnings, infos, elapsed) {
|
|
|
304
311
|
}
|
|
305
312
|
|
|
306
313
|
async function runScan(options = {}) {
|
|
307
|
-
const { hookMode = false, cwd = process.cwd() } = options;
|
|
314
|
+
const { hookMode = false, quiet = false, cwd = process.cwd() } = options;
|
|
308
315
|
const start = Date.now();
|
|
309
316
|
const envVars = loadEnvFile(cwd);
|
|
310
317
|
const manifest = loadManifest(cwd);
|
|
@@ -323,11 +330,22 @@ async function runScan(options = {}) {
|
|
|
323
330
|
const warnings = allIssues.filter((i) => i.severity === "warn");
|
|
324
331
|
const infos = allIssues.filter((i) => i.severity === "info");
|
|
325
332
|
const elapsed = Date.now() - start;
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
333
|
+
if (!quiet) {
|
|
334
|
+
const output = hookMode
|
|
335
|
+
? renderHookOutput(blockers, warnings, infos, elapsed)
|
|
336
|
+
: renderInteractiveOutput(blockers, warnings, infos, elapsed);
|
|
337
|
+
process.stdout.write(output);
|
|
338
|
+
}
|
|
339
|
+
try {
|
|
340
|
+
await _track("safelaunch_scan_run", {
|
|
341
|
+
blockers: blockers.length,
|
|
342
|
+
warnings: warnings.length,
|
|
343
|
+
hook_mode: hookMode,
|
|
344
|
+
elapsed,
|
|
345
|
+
});
|
|
346
|
+
await _shutdown();
|
|
347
|
+
} catch {}
|
|
330
348
|
return { blockers, warnings, infos, elapsed };
|
|
331
349
|
}
|
|
332
350
|
|
|
333
|
-
module.exports = { runScan };
|
|
351
|
+
module.exports = { runScan };
|