errlens 1.0.6 → 1.0.8

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.
Files changed (3) hide show
  1. package/README.md +26 -2
  2. package/bin/index.js +56 -32
  3. package/package.json +3 -3
package/README.md CHANGED
@@ -54,8 +54,32 @@ npm install -g errlens
54
54
 
55
55
  ---
56
56
 
57
+ ## ⚡ Quick Start
58
+
59
+ ```bash
60
+ # Analyze an error message
61
+ errlens analyze "TypeError: Cannot read property 'name' of undefined"
62
+
63
+ # Run a script with error monitoring
64
+ errlens run your-script.js
65
+
66
+ # Get JSON output for CI/CD pipelines
67
+ errlens analyze "is not a function" --json
68
+ ```
69
+
70
+ ---
71
+
57
72
  ## 🛠 Usage
58
73
 
74
+ ### Available Commands
75
+
76
+ ```bash
77
+ errlens run <file> [--json] # Run a script and analyze any crashes
78
+ errlens analyze <error> [--json] # Analyze a specific error message
79
+ errlens --version # Show version information
80
+ errlens --help # Show help
81
+ ```
82
+
59
83
  ### 1️⃣ Automatic Monitoring (The "Pro" Way)
60
84
 
61
85
  Run your script through ErrLens. If it crashes, ErrLens intercepts the error and explains the fix before the process exits.
@@ -71,7 +95,7 @@ errlens run your-app.js
71
95
  Found a weird error in your logs? Just paste the message:
72
96
 
73
97
  ```bash
74
- errlens "TypeError: Cannot read properties of undefined"
98
+ errlens analyze "TypeError: Cannot read properties of undefined"
75
99
  ```
76
100
 
77
101
  ---
@@ -81,7 +105,7 @@ errlens "TypeError: Cannot read properties of undefined"
81
105
  Get machine-readable results for your own tooling or automated reports:
82
106
 
83
107
  ```bash
84
- errlens "is not a function" --json
108
+ errlens analyze "is not a function" --json
85
109
  ```
86
110
 
87
111
  Run a script and write the JSON report directly to a file in CI:
package/bin/index.js CHANGED
@@ -2,34 +2,40 @@
2
2
 
3
3
  const { Command } = require("commander");
4
4
  const { spawn } = require("child_process");
5
- const ora = require("ora").default;
6
5
  const chalk = require("chalk");
7
6
  const path = require("path");
8
7
  const { findError } = require("../lib/matcher");
9
8
  const { formatError } = require("../lib/formatter");
9
+ const { version } = require("../package.json");
10
10
 
11
11
  const program = new Command();
12
12
 
13
13
  program
14
14
  .name("errlens")
15
15
  .description("Professional JS Error Analytics")
16
- .version("1.3.1");
16
+ .version(version)
17
+ .option("--json", "Output JSON instead of pretty UI"); // ✅ GLOBAL OPTION
17
18
 
18
19
  // ----------------- RUN COMMAND -----------------
19
20
  program
20
21
  .command("run <file>")
21
- .option('--json', 'Output JSON instead of pretty UI')
22
22
  .description("Run a Javascript file and analyze crashes")
23
- .action((file, options) => {
23
+ .action(async (file) => {
24
+ const { default: ora } = await import("ora");
25
+
26
+ const isJson = Boolean(program.opts().json);
24
27
  const filePath = path.resolve(process.cwd(), file);
25
- const isJson = Boolean(options.json || process.argv.includes("--json"));
26
- const spinner = isJson ? null : ora(`Running ${chalk.yellow(file)}...`).start();
28
+ const spinner = isJson
29
+ ? null
30
+ : ora(`Running ${chalk.yellow(file)}...`).start();
27
31
 
28
- const child = spawn(process.execPath, [filePath], { stdio: ["inherit", "pipe", "pipe"] });
32
+ const child = spawn(process.execPath, [filePath], {
33
+ stdio: ["inherit", "pipe", "pipe"],
34
+ });
29
35
 
30
36
  let errorOutput = "";
31
37
 
32
- // Stream logs to terminal in real-time
38
+ // Stream stdout only in pretty mode
33
39
  child.stdout.on("data", (data) => {
34
40
  if (!isJson) {
35
41
  spinner.stop();
@@ -38,7 +44,7 @@ program
38
44
  }
39
45
  });
40
46
 
41
- // Capture stderr for analysis
47
+ // Capture stderr (DO NOT print in JSON mode)
42
48
  child.stderr.on("data", (data) => {
43
49
  errorOutput += data.toString();
44
50
 
@@ -48,34 +54,46 @@ program
48
54
  });
49
55
 
50
56
  child.on("close", (code, signal) => {
51
- if (!isJson) {
57
+ if (!isJson && spinner) {
52
58
  spinner.stop();
53
59
  }
54
60
 
55
61
  const { count, matches } = findError(errorOutput);
56
62
 
63
+ // Process killed by signal
57
64
  if (code === null) {
65
+ const result = { code: 1, count, matches };
66
+
58
67
  if (isJson) {
59
- const result = { code: 1, count, matches };
60
68
  console.log(JSON.stringify(result, null, 2));
61
69
  } else {
62
- console.log(chalk.red.bold(`\n⚠️ Process killed by signal: ${signal}`));
70
+ console.log(
71
+ chalk.red.bold(`\n⚠️ Process killed by signal: ${signal}`)
72
+ );
63
73
  }
74
+
64
75
  process.exit(1);
65
- return;
66
76
  }
67
77
 
78
+ // JSON MODE
68
79
  if (isJson) {
69
- const result = { code, count, matches };
70
- console.log(JSON.stringify(result, null, 2));
71
- } else if (code === 0) {
72
- console.log(chalk.green.bold("\n✨ Process finished successfully."));
80
+ console.log(JSON.stringify({ code, count, matches }, null, 2));
81
+ process.exit(code ?? 1);
82
+ }
83
+
84
+ // PRETTY MODE
85
+ if (code === 0) {
86
+ console.log(chalk.green.bold("\n✨ Process finished successfully."));
73
87
  } else {
74
88
  if (count > 0) {
75
- console.log(chalk.bold.cyan(`\n🚀 ErrLens Analysis (${count} Issue(s)):`));
76
- matches.forEach(m => console.log(formatError(m))); // Pretty UI only here
89
+ console.log(
90
+ chalk.bold.cyan(`\n🚀 ErrLens Analysis (${count} Issue(s)):`)
91
+ );
92
+ matches.forEach((m) => console.log(formatError(m)));
77
93
  } else {
78
- console.log(chalk.red.bold("\n❌ Crash detected (No known fix in database):"));
94
+ console.log(
95
+ chalk.red.bold("\n❌ Crash detected (No known fix in database):")
96
+ );
79
97
  console.log(chalk.gray(errorOutput));
80
98
  }
81
99
  }
@@ -84,42 +102,48 @@ program
84
102
  });
85
103
 
86
104
  child.on("error", (err) => {
105
+ const result = { code: 1, count: 0, matches: [] };
106
+
87
107
  if (isJson) {
88
- const result = { code: 1, count: 0, matches: [] };
89
108
  console.log(JSON.stringify(result, null, 2));
90
109
  } else {
91
- spinner.fail(chalk.red(`System Error: ${err.message}`));
110
+ console.log(chalk.red(`System Error: ${err.message}`));
92
111
  }
112
+
93
113
  process.exit(1);
94
114
  });
95
115
  });
96
116
 
97
117
  // ----------------- ANALYZE COMMAND -----------------
98
118
  program
99
- .arguments("<errorString>") // default command if no "run"
119
+ .command("analyze <errorString>")
100
120
  .description("Analyze a specific error string")
101
- .option('--json', 'Output result in JSON format')
102
- .action((errorString, options) => {
121
+ .action((errorString) => {
122
+ const isJson = Boolean(program.opts().json);
103
123
  const { count, matches } = findError(errorString);
104
124
  const exitCode = count > 0 ? 1 : 0;
105
- const isJson = Boolean(options.json || process.argv.includes("--json"));
106
125
 
107
126
  if (isJson) {
108
- console.log(JSON.stringify({ code: exitCode, count, matches }, null, 2));
127
+ console.log(
128
+ JSON.stringify({ code: exitCode, count, matches }, null, 2)
129
+ );
109
130
  process.exit(exitCode);
110
- return;
111
131
  }
112
132
 
113
133
  if (count > 0) {
114
- console.log(chalk.bold.cyan(`\n🚀 ErrLens Analysis (${count} Issue(s)):`));
115
- matches.forEach(m => console.log(formatError(m))); // Pretty UI
134
+ console.log(
135
+ chalk.bold.cyan(`\n🚀 ErrLens Analysis (${count} Issue(s)):`)
136
+ );
137
+ matches.forEach((m) => console.log(formatError(m)));
116
138
  } else {
117
- console.log(chalk.red.bold("\n❌ Crash detected (No known fix in database):"));
139
+ console.log(
140
+ chalk.red.bold("\n❌ Crash detected (No known fix in database):")
141
+ );
118
142
  console.log(chalk.gray(errorString));
119
143
  }
120
144
 
121
145
  process.exit(exitCode);
122
146
  });
123
147
 
124
- // ----------------- PARSE ARGUMENTS -----------------
148
+ // ----------------- PARSE -----------------
125
149
  program.parse(process.argv);
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "errlens",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "description": "Professional CLI tool that explains JavaScript and Node.js errors in plain English with actionable fixes directly in your terminal.",
5
5
  "main": "./bin/index.js",
6
6
  "bin": {
7
- "errlens": "./bin/index.js"
7
+ "errlens": "bin/index.js"
8
8
  },
9
9
  "author": "BeyteFlow (https://github.com/BeyteFlow)",
10
10
  "license": "MIT",
@@ -36,7 +36,7 @@
36
36
  },
37
37
  "repository": {
38
38
  "type": "git",
39
- "url": "https://github.com/BeyteFlow/errlens.git"
39
+ "url": "git+https://github.com/BeyteFlow/errlens.git"
40
40
  },
41
41
  "bugs": {
42
42
  "url": "https://github.com/BeyteFlow/errlens/issues"