@visulima/pail 4.0.1 → 4.1.0
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/CHANGELOG.md +16 -0
- package/LICENSE.md +346 -0
- package/MIGRATION-GUIDE.md +459 -0
- package/README.md +17 -0
- package/dist/error.d.ts +69 -69
- package/dist/index.browser.d.ts +446 -445
- package/dist/index.browser.js +17 -17
- package/dist/index.server.d.ts +582 -582
- package/dist/index.server.js +27 -27
- package/dist/middleware/elysia.d.ts +44 -42
- package/dist/middleware/elysia.js +1 -1
- package/dist/middleware/express.d.ts +58 -59
- package/dist/middleware/express.js +1 -1
- package/dist/middleware/fastify.d.ts +55 -56
- package/dist/middleware/fastify.js +1 -1
- package/dist/middleware/hono.d.ts +56 -57
- package/dist/middleware/hono.js +1 -1
- package/dist/middleware/next/handler.d.ts +67 -68
- package/dist/middleware/next/handler.js +1 -1
- package/dist/middleware/sveltekit.d.ts +72 -73
- package/dist/middleware/sveltekit.js +1 -1
- package/dist/object-tree.d.ts +44 -44
- package/dist/packem_shared/AbstractJsonReporter-BpWRnN0L.js +1 -0
- package/dist/packem_shared/AbstractJsonReporter-DxZwImm5.js +1 -0
- package/dist/packem_shared/JsonReporter-9IcELa1m.js +2 -0
- package/dist/packem_shared/JsonReporter-Dd3kuj8X.js +1 -0
- package/dist/packem_shared/{PrettyReporter-DsHfKOU7.js → PrettyReporter-BUWNEg3_.js} +1 -1
- package/dist/packem_shared/{PrettyReporter-CcDdPQSt.js → PrettyReporter-DbgD89ck.js} +56 -30
- package/dist/packem_shared/abstract-json-reporter.d-B6NoO-hG.d.ts +61 -0
- package/dist/packem_shared/{abstract-pretty-reporter-DrLBJ6ds.js → abstract-pretty-reporter-CyfTvmKf.js} +41 -39
- package/dist/packem_shared/create-middleware-logger.d-BRkkBMlk.d.ts +47 -0
- package/dist/packem_shared/headers-DI58djdG.js +1 -0
- package/dist/packem_shared/index-CbkPnylC.js +1 -0
- package/dist/packem_shared/serializeError-52C4oiKx-CrnRcq9R.js +1 -0
- package/dist/packem_shared/storage-DVcJumyk.js +1 -0
- package/dist/packem_shared/types.d-4ge_rME4.d.ts +246 -0
- package/dist/packem_shared/{types.d-Cz9S7jZh.d.ts → types.d-BW8kAXUv.d.ts} +95 -95
- package/dist/packem_shared/types.d-DGHeA2iJ.d.ts +194 -0
- package/dist/packem_shared/useLogger-7p55yvvc.js +1 -0
- package/dist/packem_shared/wide-event.d-BMLastMR.d.ts +716 -0
- package/dist/packem_shared/write-stream-ytl_vhg_.js +1 -0
- package/dist/processor/caller/caller-processor.d.ts +32 -33
- package/dist/processor/environment-processor.d.ts +83 -84
- package/dist/processor/message-formatter-processor.d.ts +40 -45
- package/dist/processor/message-formatter-processor.js +1 -1
- package/dist/processor/opentelemetry-processor.d.ts +51 -52
- package/dist/processor/redact-processor.d.ts +57 -65
- package/dist/processor/sampling-processor.d.ts +90 -91
- package/dist/reporter/file/json-file-reporter.d.ts +77 -78
- package/dist/reporter/file/json-file-reporter.js +1 -1
- package/dist/reporter/http/abstract-http-reporter.d.ts +125 -121
- package/dist/reporter/http/abstract-http-reporter.js +2 -2
- package/dist/reporter/http/http-reporter.d.ts +33 -34
- package/dist/reporter/http/http-reporter.edge-light.d.ts +235 -230
- package/dist/reporter/http/http-reporter.edge-light.js +2 -2
- package/dist/reporter/json/index.browser.d.ts +62 -61
- package/dist/reporter/json/index.browser.js +1 -1
- package/dist/reporter/json/index.d.ts +36 -37
- package/dist/reporter/json/index.js +1 -1
- package/dist/reporter/pretty/index.browser.d.ts +57 -56
- package/dist/reporter/pretty/index.browser.js +1 -1
- package/dist/reporter/pretty/index.d.ts +133 -133
- package/dist/reporter/pretty/index.js +1 -1
- package/dist/reporter/simple/simple-reporter.server.d.ts +91 -90
- package/dist/reporter/simple/simple-reporter.server.js +7 -7
- package/dist/wide-event.d.ts +2 -3
- package/dist/wide-event.js +1 -1
- package/package.json +58 -36
- package/dist/packem_shared/AbstractJsonReporter-Bp_JCrMQ.js +0 -1
- package/dist/packem_shared/AbstractJsonReporter-w_bGGiD-.js +0 -1
- package/dist/packem_shared/JsonReporter-Sd_lJGS-.js +0 -2
- package/dist/packem_shared/JsonReporter-bmem9lcg.js +0 -1
- package/dist/packem_shared/abstract-json-reporter.d-wfESoEa-.d.ts +0 -62
- package/dist/packem_shared/addKnownErrorConstructor-C1OJTj2D-0FlJMfXz.js +0 -25
- package/dist/packem_shared/create-middleware-logger.d-B-JmQ1Sl.d.ts +0 -47
- package/dist/packem_shared/headers-DH0H2s8W.js +0 -1
- package/dist/packem_shared/index-Q1764hvO.js +0 -1
- package/dist/packem_shared/serializeError-C-NFvZ8_-D0CA_Qlx.js +0 -1
- package/dist/packem_shared/storage-DaXAlpiO.js +0 -1
- package/dist/packem_shared/types.d-bWnqHJKL.d.ts +0 -211
- package/dist/packem_shared/types.d-xxE3FOD3.d.ts +0 -229
- package/dist/packem_shared/useLogger-DB34CuU5.js +0 -1
- package/dist/packem_shared/wide-event.d-D3ATYpoK.d.ts +0 -717
- package/dist/packem_shared/write-stream-C7jxLxIT.js +0 -1
|
@@ -0,0 +1,459 @@
|
|
|
1
|
+
# Migration Guide
|
|
2
|
+
|
|
3
|
+
This guide documents breaking changes and migration steps for the `@visulima/pail` package.
|
|
4
|
+
|
|
5
|
+
## Version 4.0.0
|
|
6
|
+
|
|
7
|
+
### Breaking Changes Summary
|
|
8
|
+
|
|
9
|
+
- **Spinner removed**: `createSpinner()` and `createMultiSpinner()` removed — use `@visulima/spinner`
|
|
10
|
+
- **Progress bar removed**: `createProgressBar()` and `createMultiProgressBar()` removed — use `@visulima/progress-bar`
|
|
11
|
+
- **Interactive manager extracted**: `@visulima/pail/interactive` export removed — use `@visulima/interactive-manager`
|
|
12
|
+
- **Spinner/progress-bar exports removed**: `@visulima/pail/spinner` and `@visulima/pail/progress-bar` no longer exist
|
|
13
|
+
|
|
14
|
+
### Install New Packages
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
pnpm add @visulima/spinner @visulima/progress-bar
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
`@visulima/interactive-manager` is automatically installed as a dependency of both packages and of pail itself.
|
|
21
|
+
|
|
22
|
+
### Spinner Migration
|
|
23
|
+
|
|
24
|
+
#### Before (v3.x)
|
|
25
|
+
|
|
26
|
+
```typescript
|
|
27
|
+
import { createPail } from "@visulima/pail";
|
|
28
|
+
|
|
29
|
+
const logger = createPail({ interactive: true });
|
|
30
|
+
|
|
31
|
+
const spinner = logger.createSpinner({ name: "dots" });
|
|
32
|
+
spinner.start("Loading...");
|
|
33
|
+
spinner.succeed("Done!");
|
|
34
|
+
|
|
35
|
+
const multi = logger.createMultiSpinner({ name: "dots" });
|
|
36
|
+
const s1 = multi.create("Task 1");
|
|
37
|
+
s1.start();
|
|
38
|
+
s1.succeed("Done");
|
|
39
|
+
multi.stop();
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
#### After (v4.x)
|
|
43
|
+
|
|
44
|
+
```typescript
|
|
45
|
+
import { createPail } from "@visulima/pail";
|
|
46
|
+
import { MultiSpinner, Spinner } from "@visulima/spinner";
|
|
47
|
+
|
|
48
|
+
const logger = createPail({ interactive: true });
|
|
49
|
+
const manager = logger.getInteractiveManager();
|
|
50
|
+
|
|
51
|
+
const spinner = new Spinner({ name: "dots" }, manager);
|
|
52
|
+
spinner.start("Loading...");
|
|
53
|
+
spinner.succeed("Done!");
|
|
54
|
+
|
|
55
|
+
const multi = new MultiSpinner({ name: "dots" }, manager);
|
|
56
|
+
const s1 = multi.create("Task 1");
|
|
57
|
+
s1.start();
|
|
58
|
+
s1.succeed("Done");
|
|
59
|
+
multi.stop();
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### Progress Bar Migration
|
|
63
|
+
|
|
64
|
+
#### Before (v3.x)
|
|
65
|
+
|
|
66
|
+
```typescript
|
|
67
|
+
import { createPail } from "@visulima/pail";
|
|
68
|
+
|
|
69
|
+
const logger = createPail({ interactive: true });
|
|
70
|
+
|
|
71
|
+
const bar = logger.createProgressBar({
|
|
72
|
+
total: 100,
|
|
73
|
+
format: "Downloading [{bar}] {percentage}%",
|
|
74
|
+
});
|
|
75
|
+
bar.start();
|
|
76
|
+
bar.update(50);
|
|
77
|
+
bar.stop();
|
|
78
|
+
|
|
79
|
+
const multi = logger.createMultiProgressBar();
|
|
80
|
+
const b1 = multi.create(100);
|
|
81
|
+
b1.update(50);
|
|
82
|
+
multi.stop();
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
#### After (v4.x)
|
|
86
|
+
|
|
87
|
+
```typescript
|
|
88
|
+
import { createPail } from "@visulima/pail";
|
|
89
|
+
import { MultiProgressBar, ProgressBar } from "@visulima/progress-bar";
|
|
90
|
+
|
|
91
|
+
const logger = createPail({ interactive: true });
|
|
92
|
+
const manager = logger.getInteractiveManager();
|
|
93
|
+
|
|
94
|
+
const bar = new ProgressBar(
|
|
95
|
+
{
|
|
96
|
+
total: 100,
|
|
97
|
+
format: "Downloading [{bar}] {percentage}%",
|
|
98
|
+
},
|
|
99
|
+
manager,
|
|
100
|
+
);
|
|
101
|
+
bar.start();
|
|
102
|
+
bar.update(50);
|
|
103
|
+
bar.stop();
|
|
104
|
+
|
|
105
|
+
const multi = new MultiProgressBar({}, manager);
|
|
106
|
+
const b1 = multi.create(100);
|
|
107
|
+
b1.update(50);
|
|
108
|
+
multi.stop();
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### Interactive Manager Migration
|
|
112
|
+
|
|
113
|
+
#### Before (v3.x)
|
|
114
|
+
|
|
115
|
+
```typescript
|
|
116
|
+
import { InteractiveManager, InteractiveStreamHook } from "@visulima/pail/interactive";
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
#### After (v4.x)
|
|
120
|
+
|
|
121
|
+
```typescript
|
|
122
|
+
import { InteractiveManager, InteractiveStreamHook } from "@visulima/interactive-manager";
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### Spinner/Progress-Bar Type Imports
|
|
126
|
+
|
|
127
|
+
#### Before (v3.x)
|
|
128
|
+
|
|
129
|
+
```typescript
|
|
130
|
+
import type { SpinnerOptions, SpinnerIcons } from "@visulima/pail";
|
|
131
|
+
import type { ProgressBarOptions, MultiBarOptions } from "@visulima/pail";
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
#### After (v4.x)
|
|
135
|
+
|
|
136
|
+
```typescript
|
|
137
|
+
import type { SpinnerOptions, SpinnerIcons } from "@visulima/spinner";
|
|
138
|
+
import type { ProgressBarOptions, MultiBarOptions } from "@visulima/progress-bar";
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### Spinner API Changes
|
|
142
|
+
|
|
143
|
+
The new `@visulima/spinner` package has a few API differences from pail's old spinner:
|
|
144
|
+
|
|
145
|
+
| Old (pail) | New (@visulima/spinner) | Notes |
|
|
146
|
+
| ----------------------------------- | -------------------------------------------------- | -------------------------------------------------------- |
|
|
147
|
+
| `logger.createSpinner(opts)` | `new Spinner(opts, manager)` | Pass manager as 2nd arg |
|
|
148
|
+
| `spinner.fail(text)` | `spinner.failed(text)` | Method renamed |
|
|
149
|
+
| `SpinnerStyle` object with colorize | `style: (text) => string` or `SpinnerStyle` object | Style is now a function or uses Node.js `util.styleText` |
|
|
150
|
+
|
|
151
|
+
### What Stays the Same
|
|
152
|
+
|
|
153
|
+
- `getInteractiveManager()` — still available on pail, returns the manager instance
|
|
154
|
+
- Interactive mode — still enabled via `{ interactive: true }`
|
|
155
|
+
- All logging methods — unchanged
|
|
156
|
+
- Reporters — unchanged
|
|
157
|
+
- Processors — unchanged
|
|
158
|
+
- Middleware — unchanged
|
|
159
|
+
|
|
160
|
+
### Why This Change?
|
|
161
|
+
|
|
162
|
+
Spinners and progress bars are now **independent packages** that can be used without pail:
|
|
163
|
+
|
|
164
|
+
- **`@visulima/spinner`** — 109 spinner animations, styling, multi-spinner support
|
|
165
|
+
- **`@visulima/progress-bar`** — 7 styles, gradients, multi-bar, composite mode
|
|
166
|
+
- **`@visulima/interactive-manager`** — terminal stream coordination
|
|
167
|
+
|
|
168
|
+
This reduces pail's bundle size and allows these features to be used in any CLI tool, not just with pail.
|
|
169
|
+
|
|
170
|
+
---
|
|
171
|
+
|
|
172
|
+
## Version 3.0.0
|
|
173
|
+
|
|
174
|
+
### Breaking Changes Summary
|
|
175
|
+
|
|
176
|
+
- **Minimum Node.js version**: 20.19+ required
|
|
177
|
+
- **Module format**: ESM-only (CommonJS removed)
|
|
178
|
+
- **Reporter imports**: Changed to granular paths
|
|
179
|
+
- **Internal dependencies**: Consolidated with @visulima/string
|
|
180
|
+
|
|
181
|
+
### Dependency Consolidation
|
|
182
|
+
|
|
183
|
+
In version 3.0.0, we consolidated external dependencies by replacing them with internal `@visulima/string` package utilities.
|
|
184
|
+
|
|
185
|
+
#### Replaced Dependencies
|
|
186
|
+
|
|
187
|
+
| Previous | New | Reason |
|
|
188
|
+
| --------------- | ----------------------------------- | ---------------------------------------- |
|
|
189
|
+
| `wrap-ansi` | `@visulima/string` (wordWrap) | Consolidated text wrapping functionality |
|
|
190
|
+
| `string-length` | `@visulima/string` (getStringWidth) | Consolidated string width calculation |
|
|
191
|
+
|
|
192
|
+
#### Benefits
|
|
193
|
+
|
|
194
|
+
- **Reduced bundle size**: Fewer external dependencies
|
|
195
|
+
- **Better maintenance**: Internal package control
|
|
196
|
+
- **Consistent API**: Unified string utilities across visulima packages
|
|
197
|
+
- **Performance**: Optimized internal implementations
|
|
198
|
+
|
|
199
|
+
#### Backward Compatibility
|
|
200
|
+
|
|
201
|
+
The dependency consolidation changes are **backward compatible** for pail users. The internal API changes don't affect the public pail API. The CJS export removal and reporter export structure changes are **breaking changes** that require migration.
|
|
202
|
+
|
|
203
|
+
### Reporter Export Structure Changes
|
|
204
|
+
|
|
205
|
+
The reporter export structure has been reorganized to provide more granular access to individual reporter types.
|
|
206
|
+
|
|
207
|
+
#### Old Export Structure
|
|
208
|
+
|
|
209
|
+
```javascript
|
|
210
|
+
import { JsonReporter, JsonFileReporter, PrettyReporter, SimpleReporter } from "@visulima/pail/reporter";
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
#### New Granular Export Structure
|
|
214
|
+
|
|
215
|
+
```javascript
|
|
216
|
+
import { JsonReporter } from "@visulima/pail/reporter/json";
|
|
217
|
+
import { JsonFileReporter } from "@visulima/pail/reporter/file";
|
|
218
|
+
import { PrettyReporter } from "@visulima/pail/reporter/pretty";
|
|
219
|
+
import { SimpleReporter } from "@visulima/pail/reporter/simple";
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
#### Benefits
|
|
223
|
+
|
|
224
|
+
- **Smaller bundle sizes**: Only import the reporters you need
|
|
225
|
+
- **Better tree-shaking**: Unused reporters are excluded from bundles
|
|
226
|
+
- **Clearer dependencies**: Explicit imports make dependencies obvious
|
|
227
|
+
- **Improved performance**: Reduced bundle size and faster loading
|
|
228
|
+
|
|
229
|
+
### CommonJS (CJS) Export Removed
|
|
230
|
+
|
|
231
|
+
The CommonJS (CJS) export has been removed in favor of ECMAScript Modules (ESM) only. For CJS compatibility in Node.js 20.19+, use dynamic imports.
|
|
232
|
+
|
|
233
|
+
#### Before (v2.x)
|
|
234
|
+
|
|
235
|
+
```javascript
|
|
236
|
+
// This no longer works
|
|
237
|
+
const { createPail, pail } = require("@visulima/pail");
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
#### After (v3.x) - Node.js 20.19+
|
|
241
|
+
|
|
242
|
+
```javascript
|
|
243
|
+
// Use dynamic import for ESM modules from CJS
|
|
244
|
+
const { createPail, pail } = await import("@visulima/pail");
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
#### Alternative: Convert to ESM
|
|
248
|
+
|
|
249
|
+
For better compatibility and performance, convert your project to use ESM:
|
|
250
|
+
|
|
251
|
+
```json
|
|
252
|
+
// package.json
|
|
253
|
+
{
|
|
254
|
+
"name": "your-project",
|
|
255
|
+
"type": "module"
|
|
256
|
+
}
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
```typescript
|
|
260
|
+
// Your files can now use ESM imports
|
|
261
|
+
import { createPail, pail } from "@visulima/pail";
|
|
262
|
+
|
|
263
|
+
const logger = createPail({
|
|
264
|
+
reporters: [new JsonReporter()],
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
logger.info("Hello ESM world!");
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
### Why ESM Only?
|
|
271
|
+
|
|
272
|
+
#### Benefits of ESM for Pail
|
|
273
|
+
|
|
274
|
+
- **Standards Compliance**: ESM follows the official JavaScript module specification
|
|
275
|
+
- **Tree Shaking**: Better dead code elimination in bundlers
|
|
276
|
+
- **Static Analysis**: Improved tooling and IDE support
|
|
277
|
+
- **Future-Proof**: ESM is the standard for modern JavaScript
|
|
278
|
+
- **Bundle Optimization**: Smaller bundle sizes with better optimization
|
|
279
|
+
|
|
280
|
+
### Migration Steps
|
|
281
|
+
|
|
282
|
+
#### 1. Update Reporter Imports
|
|
283
|
+
|
|
284
|
+
Replace old reporter imports with new granular imports:
|
|
285
|
+
|
|
286
|
+
```javascript
|
|
287
|
+
// Before
|
|
288
|
+
import { JsonReporter, JsonFileReporter, PrettyReporter, SimpleReporter } from "@visulima/pail/reporter";
|
|
289
|
+
|
|
290
|
+
// After
|
|
291
|
+
import { JsonReporter } from "@visulima/pail/reporter/json";
|
|
292
|
+
import { JsonFileReporter } from "@visulima/pail/reporter/file";
|
|
293
|
+
import { PrettyReporter } from "@visulima/pail/reporter/pretty";
|
|
294
|
+
import { SimpleReporter } from "@visulima/pail/reporter/simple";
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
#### 2. Use Dynamic Imports for CJS
|
|
298
|
+
|
|
299
|
+
Replace `require()` calls with dynamic `import()`:
|
|
300
|
+
|
|
301
|
+
```javascript
|
|
302
|
+
// Before
|
|
303
|
+
const { createPail } = require("@visulima/pail");
|
|
304
|
+
|
|
305
|
+
// After
|
|
306
|
+
const { createPail } = await import("@visulima/pail");
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
#### 3. Convert to ESM (Recommended)
|
|
310
|
+
|
|
311
|
+
For the best experience, convert your project to use ESM:
|
|
312
|
+
|
|
313
|
+
```json
|
|
314
|
+
// package.json
|
|
315
|
+
{
|
|
316
|
+
"name": "your-project",
|
|
317
|
+
"type": "module",
|
|
318
|
+
"scripts": {
|
|
319
|
+
"start": "node src/index.js"
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
```typescript
|
|
325
|
+
// src/index.ts
|
|
326
|
+
import { createPail, pail } from "@visulima/pail";
|
|
327
|
+
import { JsonReporter } from "@visulima/pail/reporter/json";
|
|
328
|
+
|
|
329
|
+
async function main() {
|
|
330
|
+
const logger = createPail({
|
|
331
|
+
reporters: [new JsonReporter()],
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
logger.info("Project started");
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
main().catch(console.error);
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
### Migration Issues & Solutions
|
|
341
|
+
|
|
342
|
+
#### 1. Old Reporter Imports No Longer Work
|
|
343
|
+
|
|
344
|
+
**Problem**: `import { JsonReporter } from "@visulima/pail/reporter"` throws "module not found" error.
|
|
345
|
+
|
|
346
|
+
**Solution**: Use new granular reporter imports:
|
|
347
|
+
|
|
348
|
+
```javascript
|
|
349
|
+
// Before
|
|
350
|
+
import { JsonReporter, JsonFileReporter, PrettyReporter, SimpleReporter } from "@visulima/pail/reporter";
|
|
351
|
+
|
|
352
|
+
// After
|
|
353
|
+
import { JsonReporter } from "@visulima/pail/reporter/json";
|
|
354
|
+
import { JsonFileReporter } from "@visulima/pail/reporter/file";
|
|
355
|
+
import { PrettyReporter } from "@visulima/pail/reporter/pretty";
|
|
356
|
+
import { SimpleReporter } from "@visulima/pail/reporter/simple";
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
#### 2. require() Calls No Longer Work
|
|
360
|
+
|
|
361
|
+
**Problem**: `require('@visulima/pail')` throws "module not found" error.
|
|
362
|
+
|
|
363
|
+
**Solution**: Use dynamic imports:
|
|
364
|
+
|
|
365
|
+
```javascript
|
|
366
|
+
// Dynamic import for ESM modules from CJS
|
|
367
|
+
const { createPail, pail } = await import("@visulima/pail");
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
#### 3. Async Context Required
|
|
371
|
+
|
|
372
|
+
**Problem**: Functions using pail must be async when using dynamic imports.
|
|
373
|
+
|
|
374
|
+
**Solution**: Mark functions as async and await the import:
|
|
375
|
+
|
|
376
|
+
```typescript
|
|
377
|
+
// Before
|
|
378
|
+
function setupLogger() {
|
|
379
|
+
const { createPail } = require("@visulima/pail");
|
|
380
|
+
|
|
381
|
+
return createPail();
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
// After
|
|
385
|
+
async function setupLogger() {
|
|
386
|
+
const { createPail } = await import("@visulima/pail");
|
|
387
|
+
|
|
388
|
+
return createPail();
|
|
389
|
+
}
|
|
390
|
+
```
|
|
391
|
+
|
|
392
|
+
### Verification Steps
|
|
393
|
+
|
|
394
|
+
1. **Test new reporter imports**:
|
|
395
|
+
|
|
396
|
+
```javascript
|
|
397
|
+
// test-reporters.mjs
|
|
398
|
+
import { JsonReporter } from "@visulima/pail/reporter/json";
|
|
399
|
+
import { JsonFileReporter } from "@visulima/pail/reporter/file";
|
|
400
|
+
import { PrettyReporter } from "@visulima/pail/reporter/pretty";
|
|
401
|
+
import { SimpleReporter } from "@visulima/pail/reporter/simple";
|
|
402
|
+
import { createPail } from "@visulima/pail";
|
|
403
|
+
|
|
404
|
+
async function test() {
|
|
405
|
+
const logger = createPail({
|
|
406
|
+
reporters: [new JsonReporter(), new JsonFileReporter({ filePath: "/tmp/test.log" }), new PrettyReporter(), new SimpleReporter()],
|
|
407
|
+
});
|
|
408
|
+
|
|
409
|
+
logger.info("All reporter imports successful");
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
test().catch(console.error);
|
|
413
|
+
```
|
|
414
|
+
|
|
415
|
+
2. **Test ESM imports**:
|
|
416
|
+
|
|
417
|
+
```javascript
|
|
418
|
+
// test.mjs
|
|
419
|
+
import { createPail } from "@visulima/pail";
|
|
420
|
+
|
|
421
|
+
async function test() {
|
|
422
|
+
const logger = createPail();
|
|
423
|
+
|
|
424
|
+
logger.info("ESM import successful");
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
test().catch(console.error);
|
|
428
|
+
```
|
|
429
|
+
|
|
430
|
+
3. **Test dynamic imports from CJS**:
|
|
431
|
+
|
|
432
|
+
```javascript
|
|
433
|
+
// test.cjs
|
|
434
|
+
async function test() {
|
|
435
|
+
const { createPail } = await import("@visulima/pail");
|
|
436
|
+
const logger = createPail();
|
|
437
|
+
|
|
438
|
+
logger.info("Dynamic import successful");
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
test().catch(console.error);
|
|
442
|
+
```
|
|
443
|
+
|
|
444
|
+
### Migration Benefits
|
|
445
|
+
|
|
446
|
+
#### Reporter Import Benefits
|
|
447
|
+
|
|
448
|
+
- **Smaller bundle sizes**: Only import the reporters you need
|
|
449
|
+
- **Better tree-shaking**: Unused reporters are excluded from bundles
|
|
450
|
+
- **Clearer dependencies**: Explicit imports make dependencies obvious
|
|
451
|
+
- **Improved performance**: Reduced bundle size and faster loading
|
|
452
|
+
|
|
453
|
+
#### ESM Migration Benefits
|
|
454
|
+
|
|
455
|
+
- **Better Performance**: ESM's improved module caching in Node.js 20.19+
|
|
456
|
+
- **Modern JavaScript**: Consistent module syntax across environments
|
|
457
|
+
- **Bundle Optimization**: Better tree-shaking and dead code elimination
|
|
458
|
+
- **Developer Experience**: Improved IDE support and error messages
|
|
459
|
+
- **Future-Proof**: Aligned with JavaScript ecosystem direction
|
package/README.md
CHANGED
|
@@ -180,6 +180,23 @@ pail.complete({
|
|
|
180
180
|
|
|
181
181
|

|
|
182
182
|
|
|
183
|
+
### Which build `@visulima/pail` resolves to
|
|
184
|
+
|
|
185
|
+
The `.` entry point picks a build from the export conditions your runtime or bundler sets:
|
|
186
|
+
|
|
187
|
+
| Runtime | Condition matched | Build | Default reporter |
|
|
188
|
+
| ------------------------------------------- | ------------------------ | ----------------------- | ---------------------- |
|
|
189
|
+
| Node.js, Bun, Deno (Node compat) | `import` | `dist/index.server.js` | Pretty (stdout/stderr) |
|
|
190
|
+
| Browsers and bundlers targeting the browser | `browser` | `dist/index.browser.js` | JSON (console) |
|
|
191
|
+
| Cloudflare Workers, Vercel Edge | `workerd` / `edge-light` | `dist/index.browser.js` | JSON (console) |
|
|
192
|
+
|
|
193
|
+
The server build writes to `process.stdout` / `process.stderr` and measures the terminal, so it needs
|
|
194
|
+
Node's core modules. Edge runtimes get the console-based build instead, which keeps `.` importable on
|
|
195
|
+
Cloudflare Workers **without** the `nodejs_compat` flag and on Vercel Edge.
|
|
196
|
+
|
|
197
|
+
Importing `@visulima/pail/server` always gives you the server build, on every runtime — use it only
|
|
198
|
+
where Node core is available (on Cloudflare Workers that means enabling `nodejs_compat`).
|
|
199
|
+
|
|
183
200
|
### Custom Loggers
|
|
184
201
|
|
|
185
202
|
To create a custom logger define an `options` object yielding a types field with the logger data and pass it as argument to the createPail function.
|
package/dist/error.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Options for creating a PailError.
|
|
3
|
-
*
|
|
4
|
-
* Extends standard error properties with self-documenting fields
|
|
5
|
-
* that provide actionable context for debugging, particularly useful
|
|
6
|
-
* for AI-assisted log analysis.
|
|
7
|
-
*/
|
|
2
|
+
* Options for creating a PailError.
|
|
3
|
+
*
|
|
4
|
+
* Extends standard error properties with self-documenting fields
|
|
5
|
+
* that provide actionable context for debugging, particularly useful
|
|
6
|
+
* for AI-assisted log analysis.
|
|
7
|
+
*/
|
|
8
8
|
interface PailErrorOptions {
|
|
9
9
|
/** The root cause of this error */
|
|
10
10
|
cause?: unknown;
|
|
@@ -20,41 +20,41 @@ interface PailErrorOptions {
|
|
|
20
20
|
why?: string;
|
|
21
21
|
}
|
|
22
22
|
/**
|
|
23
|
-
* Self-documenting error class for structured logging.
|
|
24
|
-
*
|
|
25
|
-
* Inspired by evlog's structured error approach, PailError extends the native
|
|
26
|
-
* Error class with additional fields that make log entries immediately actionable:
|
|
27
|
-
* - `why`: Explains what caused the failure
|
|
28
|
-
* - `fix`: Suggests how to resolve the issue
|
|
29
|
-
* - `link`: Points to relevant documentation
|
|
30
|
-
* - `status`: HTTP status code for request-related errors
|
|
31
|
-
*
|
|
32
|
-
* These fields are preserved through the logging pipeline and displayed by reporters,
|
|
33
|
-
* making it easier for both humans and AI agents to understand and resolve issues.
|
|
34
|
-
* @example
|
|
35
|
-
* ```typescript
|
|
36
|
-
* import { PailError, createPailError } from "@visulima/pail/error";
|
|
37
|
-
*
|
|
38
|
-
* // Using the class directly
|
|
39
|
-
* throw new PailError({
|
|
40
|
-
* message: "Payment processing failed",
|
|
41
|
-
* status: 402,
|
|
42
|
-
* why: "The customer's card was declined by the payment provider",
|
|
43
|
-
* fix: "Retry with a different payment method or contact the card issuer",
|
|
44
|
-
* link: "https://docs.example.com/payments/declined",
|
|
45
|
-
* });
|
|
46
|
-
*
|
|
47
|
-
* // Using the factory function
|
|
48
|
-
* throw createPailError("Connection timeout");
|
|
49
|
-
*
|
|
50
|
-
* // With full options
|
|
51
|
-
* throw createPailError({
|
|
52
|
-
* message: "Database connection failed",
|
|
53
|
-
* why: "Connection pool exhausted after 30s timeout",
|
|
54
|
-
* fix: "Increase pool size or check for connection leaks",
|
|
55
|
-
* });
|
|
56
|
-
* ```
|
|
57
|
-
*/
|
|
23
|
+
* Self-documenting error class for structured logging.
|
|
24
|
+
*
|
|
25
|
+
* Inspired by evlog's structured error approach, PailError extends the native
|
|
26
|
+
* Error class with additional fields that make log entries immediately actionable:
|
|
27
|
+
* - `why`: Explains what caused the failure
|
|
28
|
+
* - `fix`: Suggests how to resolve the issue
|
|
29
|
+
* - `link`: Points to relevant documentation
|
|
30
|
+
* - `status`: HTTP status code for request-related errors
|
|
31
|
+
*
|
|
32
|
+
* These fields are preserved through the logging pipeline and displayed by reporters,
|
|
33
|
+
* making it easier for both humans and AI agents to understand and resolve issues.
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
* import { PailError, createPailError } from "@visulima/pail/error";
|
|
37
|
+
*
|
|
38
|
+
* // Using the class directly
|
|
39
|
+
* throw new PailError({
|
|
40
|
+
* message: "Payment processing failed",
|
|
41
|
+
* status: 402,
|
|
42
|
+
* why: "The customer's card was declined by the payment provider",
|
|
43
|
+
* fix: "Retry with a different payment method or contact the card issuer",
|
|
44
|
+
* link: "https://docs.example.com/payments/declined",
|
|
45
|
+
* });
|
|
46
|
+
*
|
|
47
|
+
* // Using the factory function
|
|
48
|
+
* throw createPailError("Connection timeout");
|
|
49
|
+
*
|
|
50
|
+
* // With full options
|
|
51
|
+
* throw createPailError({
|
|
52
|
+
* message: "Database connection failed",
|
|
53
|
+
* why: "Connection pool exhausted after 30s timeout",
|
|
54
|
+
* fix: "Increase pool size or check for connection leaks",
|
|
55
|
+
* });
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
58
|
declare class PailError extends Error {
|
|
59
59
|
/** HTTP status code (defaults to 500) */
|
|
60
60
|
readonly status: number;
|
|
@@ -66,38 +66,38 @@ declare class PailError extends Error {
|
|
|
66
66
|
readonly link: string | undefined;
|
|
67
67
|
constructor(options: PailErrorOptions | string);
|
|
68
68
|
/**
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
69
|
+
* Converts the error to a JSON-serializable object.
|
|
70
|
+
*
|
|
71
|
+
* Includes all self-documenting fields in the output for structured logging.
|
|
72
|
+
* @returns A plain object representation of the error
|
|
73
|
+
*/
|
|
74
74
|
toJSON(): Record<string, unknown>;
|
|
75
75
|
/**
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
76
|
+
* Returns a formatted string representation including self-documenting fields.
|
|
77
|
+
* @returns Formatted error string with why/fix/link context
|
|
78
|
+
*/
|
|
79
79
|
override toString(): string;
|
|
80
80
|
}
|
|
81
81
|
/**
|
|
82
|
-
* Factory function for creating PailError instances.
|
|
83
|
-
*
|
|
84
|
-
* A convenient shorthand for creating PailError objects. Accepts either
|
|
85
|
-
* a string message or a full PailErrorOptions object.
|
|
86
|
-
* @param options Error message string or PailErrorOptions object
|
|
87
|
-
* @returns A new PailError instance
|
|
88
|
-
* @example
|
|
89
|
-
* ```typescript
|
|
90
|
-
* import { createPailError } from "@visulima/pail/error";
|
|
91
|
-
*
|
|
92
|
-
* throw createPailError("Something went wrong");
|
|
93
|
-
*
|
|
94
|
-
* throw createPailError({
|
|
95
|
-
* message: "Auth failed",
|
|
96
|
-
* status: 401,
|
|
97
|
-
* why: "Token expired",
|
|
98
|
-
* fix: "Refresh the authentication token",
|
|
99
|
-
* });
|
|
100
|
-
* ```
|
|
101
|
-
*/
|
|
82
|
+
* Factory function for creating PailError instances.
|
|
83
|
+
*
|
|
84
|
+
* A convenient shorthand for creating PailError objects. Accepts either
|
|
85
|
+
* a string message or a full PailErrorOptions object.
|
|
86
|
+
* @param options Error message string or PailErrorOptions object
|
|
87
|
+
* @returns A new PailError instance
|
|
88
|
+
* @example
|
|
89
|
+
* ```typescript
|
|
90
|
+
* import { createPailError } from "@visulima/pail/error";
|
|
91
|
+
*
|
|
92
|
+
* throw createPailError("Something went wrong");
|
|
93
|
+
*
|
|
94
|
+
* throw createPailError({
|
|
95
|
+
* message: "Auth failed",
|
|
96
|
+
* status: 401,
|
|
97
|
+
* why: "Token expired",
|
|
98
|
+
* fix: "Refresh the authentication token",
|
|
99
|
+
* });
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
102
|
declare const createPailError: (options: PailErrorOptions | string) => PailError;
|
|
103
103
|
export { PailError, type PailErrorOptions, createPailError };
|