runtime-reporter 0.4.5 → 0.4.6
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/README.md +56 -51
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,8 +1,26 @@
|
|
|
1
1
|
# Runtime Reporter
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Replace ad-hoc logging with structured, code-based messaging that is also type-safe, centralized, and production-ready.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
```ts
|
|
6
|
+
// ./src/runtime-reporter.ts
|
|
7
|
+
|
|
8
|
+
import { createReporter } from "runtime-reporter";
|
|
9
|
+
|
|
10
|
+
export const reporter = createReporter({
|
|
11
|
+
ERR01: "Something went wrong",
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
// ./src/MyComponent.ts
|
|
15
|
+
|
|
16
|
+
import { reporter } from "./runtime-reporter";
|
|
17
|
+
|
|
18
|
+
export function MyComponent() {
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
reporter.error("ERR01");
|
|
21
|
+
}, []);
|
|
22
|
+
}
|
|
23
|
+
```
|
|
6
24
|
|
|
7
25
|
## Why?
|
|
8
26
|
|
|
@@ -20,7 +38,11 @@ by introducing these features:
|
|
|
20
38
|
- test assertions without string duplication
|
|
21
39
|
- safer production output (no sensitive data exposure)
|
|
22
40
|
|
|
23
|
-
in a lightweight, self-contained package (less than 1 KB).
|
|
41
|
+
in a lightweight, self-contained package (less than 1 KB gzipped).
|
|
42
|
+
|
|
43
|
+
## Who is this for?
|
|
44
|
+
|
|
45
|
+
Runtime Reporter is ideal for front-end frameworks and libraries. However, it is ultimately useful for any project looking for standardized console messaging.
|
|
24
46
|
|
|
25
47
|
## Installation
|
|
26
48
|
|
|
@@ -30,11 +52,9 @@ npm install runtime-reporter
|
|
|
30
52
|
|
|
31
53
|
## Quick start
|
|
32
54
|
|
|
33
|
-
A copy-and-paste example of how to use Runtime Reporter in your project
|
|
55
|
+
A full, copy-and-paste example of how to use Runtime Reporter in your project:
|
|
34
56
|
|
|
35
57
|
```ts
|
|
36
|
-
// src/runtime-reporter.ts
|
|
37
|
-
|
|
38
58
|
import { createReporter, type RuntimeReporterMessages } from "runtime-reporter";
|
|
39
59
|
|
|
40
60
|
const messages: RuntimeReporterMessages<
|
|
@@ -64,62 +84,57 @@ const reporter = createReporter(messages);
|
|
|
64
84
|
export default reporter;
|
|
65
85
|
```
|
|
66
86
|
|
|
67
|
-
|
|
87
|
+
## Features
|
|
68
88
|
|
|
69
|
-
|
|
70
|
-
// src/my-component.ts
|
|
89
|
+
If you are new to Runtime Reporter, take a moment to explore its core features.
|
|
71
90
|
|
|
72
|
-
|
|
91
|
+
### 1. Code-based messaging
|
|
73
92
|
|
|
74
|
-
|
|
75
|
-
useEffect(() => {
|
|
76
|
-
reporter.error("ERR01", { componentName: "MyComponent" });
|
|
77
|
-
}, []);
|
|
78
|
-
|
|
79
|
-
return <div>My Component</div>;
|
|
80
|
-
}
|
|
81
|
-
```
|
|
93
|
+
Replace inline strings with centralized, code-based identifiers.
|
|
82
94
|
|
|
83
|
-
|
|
95
|
+
```ts
|
|
96
|
+
// Without runtime-reporter
|
|
97
|
+
console.log("Something went wrong");
|
|
98
|
+
// ❌ Logs: "Something went wrong"
|
|
84
99
|
|
|
85
|
-
|
|
100
|
+
// With runtime-reporter
|
|
101
|
+
reporter.log("ERR01");
|
|
102
|
+
// ✅ Logs: "Something went wrong (ERR01)"
|
|
103
|
+
```
|
|
86
104
|
|
|
87
|
-
###
|
|
105
|
+
### 2. Dynamic messages
|
|
88
106
|
|
|
89
|
-
|
|
107
|
+
Inject runtime data into your messages via message templates and tokenized variables.
|
|
90
108
|
|
|
91
109
|
```ts
|
|
92
|
-
import { createReporter } from "runtime-reporter";
|
|
93
|
-
|
|
94
110
|
const reporter = createReporter({
|
|
95
|
-
ERR01: "
|
|
111
|
+
ERR01: "{{ componentName }} failed to mount",
|
|
96
112
|
});
|
|
97
113
|
|
|
98
|
-
reporter.error("ERR01");
|
|
114
|
+
reporter.error("ERR01", { componentName: "MyComponent" });
|
|
115
|
+
// Logs: "MyComponent failed to mount (ERR01)"
|
|
99
116
|
```
|
|
100
117
|
|
|
101
|
-
###
|
|
118
|
+
### 3. Development vs. production
|
|
102
119
|
|
|
103
|
-
|
|
120
|
+
Pass an empty object to the `createReporter` function in production environments for better security and a smaller bundle size.
|
|
104
121
|
|
|
105
122
|
```ts
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
// With runtime-reporter (logs "MyComponent failed to mount (ERR01)")
|
|
110
|
-
reporter.error("ERR01");
|
|
123
|
+
const reporter = createReporter(
|
|
124
|
+
process.env.NODE_ENV === "production" ? ({} as typeof messages) : messages
|
|
125
|
+
);
|
|
111
126
|
```
|
|
112
127
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
Inject runtime data into your messages via message templates and tokenized variables.
|
|
128
|
+
Development environments get detailed messaging, while production environments get as little as possible.
|
|
116
129
|
|
|
117
130
|
```ts
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
131
|
+
reporter.error("ERR01");
|
|
132
|
+
// In development, it logs: "Something went wrong (ERR01)"
|
|
133
|
+
// In production, it does not log
|
|
121
134
|
|
|
122
|
-
reporter.
|
|
135
|
+
reporter.fail("ERR01");
|
|
136
|
+
// In development, it throws: "Something went wrong (ERR01)"
|
|
137
|
+
// In production, it throws: "An error occurred (ERR01)"
|
|
123
138
|
```
|
|
124
139
|
|
|
125
140
|
### 4. Type safety
|
|
@@ -147,17 +162,7 @@ reporter.error("ERR02", { componentName: "MyComponent" });
|
|
|
147
162
|
reporter.error("ERR01");
|
|
148
163
|
```
|
|
149
164
|
|
|
150
|
-
### 5.
|
|
151
|
-
|
|
152
|
-
Pass an empty object to the `createReporter` function in production environments for better security and a smaller bundle size.
|
|
153
|
-
|
|
154
|
-
```ts
|
|
155
|
-
const reporter = createReporter(
|
|
156
|
-
process.env.NODE_ENV === "production" ? ({} as typeof messages) : messages
|
|
157
|
-
);
|
|
158
|
-
```
|
|
159
|
-
|
|
160
|
-
### 6. Test friendly
|
|
165
|
+
### 5. Test friendly
|
|
161
166
|
|
|
162
167
|
Assert against resolved messages without duplicating message text in your test environment.
|
|
163
168
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "runtime-reporter",
|
|
3
|
-
"version": "0.4.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.4.6",
|
|
4
|
+
"description": "Replace ad-hoc logging with structured, code-based messaging that is also type-safe, centralized, and production-ready",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
7
7
|
"module": "./dist/index.js",
|