safelaunch 1.0.25 → 1.0.27

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "safelaunch",
3
- "version": "1.0.25",
3
+ "version": "1.0.27",
4
4
  "description": "Backend Reliability Infrastructure - catch what breaks production before it breaks",
5
5
  "main": "index.js",
6
6
  "bin": {
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 envPath = path.join(cwd, ".env");
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
- const output = hookMode
327
- ? renderHookOutput(blockers, warnings, infos, elapsed)
328
- : renderInteractiveOutput(blockers, warnings, infos, elapsed);
329
- process.stdout.write(output);
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 };
package/src/setup.js CHANGED
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- const { runScan } = require("./scan");
4
- const { installHook } = require("./hook");
5
- const init = require("./init");
3
+ const { runScan } = require("./scan");
4
+ const { installHook } = require("./hook");
5
+ const init = require("./init");
6
6
 
7
7
  const c = {
8
8
  reset: "\x1b[0m", bold: "\x1b[1m", dim: "\x1b[2m",
@@ -15,10 +15,11 @@ const yellow = (s) => `${c.yellow}${c.bold}${s}${c.reset}`;
15
15
  const gray = (s) => `${c.gray}${s}${c.reset}`;
16
16
  const dim = (s) => `${c.dim}${s}${c.reset}`;
17
17
  const bold = (s) => `${c.bold}${s}${c.reset}`;
18
+ const cyan = (s) => `${c.cyan}${s}${c.reset}`;
18
19
 
19
20
  const HR = gray("─".repeat(49));
20
21
 
21
- let version = "1.0.24";
22
+ let version = "1.0.26";
22
23
  try { version = require("../package.json").version; } catch {}
23
24
 
24
25
  async function run(options = {}) {
@@ -27,8 +28,8 @@ async function run(options = {}) {
27
28
  console.log(`\n${bold("safelaunch")} ${gray(`v${version}`)} — pre-deploy guardrail`);
28
29
  console.log(gray("Scanning your project...\n"));
29
30
 
30
- // hookMode: true = silent on clean, only prints issues if any
31
- const { blockers, warnings, infos, elapsed } = await runScan({ hookMode: true, cwd });
31
+ // quiet: true runScan returns results silently, setup owns all output
32
+ const { blockers, warnings, infos, elapsed } = await runScan({ hookMode: true, quiet: true, cwd });
32
33
 
33
34
  const totalChecks = 16;
34
35
  const issueCount = blockers.length + warnings.length;
@@ -37,8 +38,20 @@ async function run(options = {}) {
37
38
  if (issueCount === 0) {
38
39
  console.log(`${green("✓")} ${bold(`${totalChecks} checks passed`)} ${gray(`(${elapsed}ms)`)}\n`);
39
40
  } else {
41
+ for (const issue of blockers) {
42
+ console.log(`${red("✗")} ${bold(issue.title)}`);
43
+ console.log(` ${gray("Impact:")} ${issue.impact}`);
44
+ console.log(` ${cyan("→")} ${issue.fix}`);
45
+ console.log("");
46
+ }
47
+ for (const issue of warnings) {
48
+ console.log(`${yellow("⚠")} ${bold(issue.title)}`);
49
+ console.log(` ${gray("Impact:")} ${issue.impact}`);
50
+ console.log(` ${dim("→")} ${issue.fix}`);
51
+ console.log("");
52
+ }
40
53
  console.log(
41
- `\n${green("✓")} ${passed} check${passed !== 1 ? "s" : ""} passed` +
54
+ `${green("✓")} ${passed} check${passed !== 1 ? "s" : ""} passed` +
42
55
  (blockers.length ? ` ${red(`✗ ${blockers.length} blocker${blockers.length > 1 ? "s" : ""}`)}` : "") +
43
56
  (warnings.length ? ` ${yellow(`⚠ ${warnings.length} warning${warnings.length > 1 ? "s" : ""}`)}` : "") +
44
57
  "\n"
@@ -48,7 +61,10 @@ async function run(options = {}) {
48
61
  console.log(gray("Generating env.manifest.json..."));
49
62
  const manifestResult = await init.run({ cwd, silent: true });
50
63
  if (manifestResult && manifestResult.count > 0) {
51
- console.log(`${green("✓")} ${bold("env.manifest.json created")} ` + gray(`(${manifestResult.count} variable${manifestResult.count !== 1 ? "s" : ""} registered)`));
64
+ console.log(
65
+ `${green("✓")} ${bold("env.manifest.json created")} ` +
66
+ gray(`(${manifestResult.count} variable${manifestResult.count !== 1 ? "s" : ""} registered)`)
67
+ );
52
68
  } else {
53
69
  console.log(`${green("✓")} ${bold("env.manifest.json updated")}`);
54
70
  }
@@ -79,4 +95,4 @@ async function run(options = {}) {
79
95
  }
80
96
  }
81
97
 
82
- module.exports = { run };
98
+ module.exports = { run };