syntropylog 0.9.13 → 0.9.14

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 CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.9.14
4
+
5
+ ### Patch Changes
6
+
7
+ - **Chalk optional for pretty console transports (Classic, Pretty, Compact, Colorful)**
8
+ - **Fix**: `ClassicConsoleTransport` (and other chalk-powered transports) now work in both ESM (tsx + `"type": "module"`) and CJS (e.g. ts-node) consumers. Chalk is loaded optionally via a small helper that uses `require` in CJS and `createRequire(import.meta.url)` in ESM; if chalk is missing or fails to load, a no-op is used so the same format is logged without colors.
9
+ - **README**: Clarified that chalk is optional — install it for colors, or use the same transports without it for plain-text output. Table updated to show "With chalk" / "Without chalk" and added ColorfulConsoleTransport.
10
+
3
11
  ## 0.9.13
4
12
 
5
13
  ### Patch Changes
package/CONTRIBUTING.md CHANGED
@@ -88,13 +88,21 @@ We welcome code contributions! To contribute code, please follow these steps:
88
88
 
89
89
  ## Release process (maintainers)
90
90
 
91
- Releases use [Changesets](https://github.com/changesets/changesets) and GitHub Actions:
91
+ Releases use [Changesets](https://github.com/changesets/changesets) and GitHub Actions. **Para que la versión suba en npm, siempre tienes que hacer una de estas dos cosas:**
92
92
 
93
- 1. **Add a changeset** when changing the library: `pnpm changeset` (choose version type and describe the change).
94
- 2. **Push to `main`** (or merge a PR that includes the changeset). The Release workflow runs and:
95
- - Creates a **"Version Packages"** PR with the version bump (e.g. 0.9.12 0.9.13) and CHANGELOG updates.
96
- - **Publishes to npm** from that same run (so npm may already have the new version).
97
- 3. **Merge the "Version Packages" PR** into `main`. This step is required so that `main` has the same `package.json` version and CHANGELOG as what was published to npm. If you skip it, `main` will stay on the old version while npm has the new one.
93
+ ### Opción A: Usar el PR que crea el action
94
+
95
+ 1. **Añade un changeset** al cambiar la librería: `pnpm changeset` (elige tipo de versión y describe el cambio).
96
+ 2. **Push a `main`**. El workflow crea un PR **"Version Packages"** con el bump (ej. 0.9.12 0.9.13) y el CHANGELOG actualizado. **Todavía no publica en npm.**
97
+ 3. **Mergea ese PR** en `main`. Ese merge vuelve a disparar el workflow y **ahí sí** se ejecuta `publish` y la nueva versión aparece en npm.
98
+
99
+ ### Opción B: Subir la versión a mano (sin PR)
100
+
101
+ 1. Con changesets ya en el repo, en local: `pnpm run version-packages`. Eso actualiza `package.json`, CHANGELOG y borra los changesets.
102
+ 2. **Commit** (package.json, CHANGELOG.md, y los .changeset/*.md borrados) y **push a `main`**.
103
+ 3. El workflow corre, no hay changesets que aplicar, y ejecuta **publish** → la versión sube a npm.
104
+
105
+ En ambos casos, **main** y **npm** quedan con la misma versión.
98
106
 
99
107
  ## Getting Help
100
108
 
package/README.md CHANGED
@@ -73,24 +73,25 @@ npm install syntropylog
73
73
 
74
74
  By default, SyntropyLog outputs **lightweight plain JSON to the console — automatically, with no configuration needed**. No imports, no setup, no extra dependencies.
75
75
 
76
- If you want **colored, human-readable output** for development, use one of the chalk-powered transports. These require `chalk` to be installed explicitly in your project to keep the base bundle small:
76
+ If you want **colored, human-readable output** for development, use one of the pretty console transports (`ClassicConsoleTransport`, `PrettyConsoleTransport`, `CompactConsoleTransport`, `ColorfulConsoleTransport`). **Chalk is optional:** if you install `chalk` in your project, those transports use it and you get colors; if you don't install it, the same format is shown in plain text (no colors). That keeps the base bundle small and avoids CJS/ESM load issues when chalk isn't present.
77
77
 
78
78
  ```bash
79
- npm install chalk
79
+ npm install chalk # optional — only if you want colors
80
80
  ```
81
81
 
82
- | Transport | Style | Color | Recommended for |
83
- | :--- | :--- | :---: | :--- |
84
- | *(default)* | Plain JSON | | Production / log aggregators |
85
- | `ClassicConsoleTransport` | Structured + colored | ✅ | Development |
86
- | `PrettyConsoleTransport` | Human-readable pretty print | ✅ | Development / debugging |
87
- | `CompactConsoleTransport` | Compact one-liner | ✅ | Development |
82
+ | Transport | Style | With chalk | Without chalk | Recommended for |
83
+ | :--- | :--- | :---: | :--- | :--- |
84
+ | *(default)* | Plain JSON | | — | Production / log aggregators |
85
+ | `ClassicConsoleTransport` | Structured single-line | ✅ Colored | Plain text | Development |
86
+ | `PrettyConsoleTransport` | Human-readable pretty | ✅ Colored | Plain text | Development / debugging |
87
+ | `CompactConsoleTransport` | Compact one-liner | ✅ Colored | Plain text | Development |
88
+ | `ColorfulConsoleTransport` | Full-line colored | ✅ Colored | Plain text | Development |
88
89
 
89
90
  ```typescript
90
91
  // Default — no import needed, works out of the box
91
92
  syntropyLog.init({ logger: { level: 'info', serviceName: 'my-app' } });
92
93
 
93
- // Want colors? Install chalk first, then import the transport:
94
+ // Pretty format: with chalk → colors; without chalk same format, no colors
94
95
  import { ClassicConsoleTransport } from 'syntropylog';
95
96
 
96
97
  syntropyLog.init({
package/dist/index.cjs CHANGED
@@ -7,9 +7,10 @@ var node_async_hooks = require('node:async_hooks');
7
7
  var crypto = require('crypto');
8
8
  var util = require('node:util');
9
9
  var flatted = require('flatted');
10
- var chalk = require('chalk');
10
+ var module$1 = require('module');
11
11
  var redis = require('redis');
12
12
 
13
+ var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
13
14
  function _interopNamespaceDefault(e) {
14
15
  var n = Object.create(null);
15
16
  if (e) {
@@ -2554,9 +2555,59 @@ class SyntropyLog extends events.EventEmitter {
2554
2555
  const syntropyLog = SyntropyLog.getInstance();
2555
2556
 
2556
2557
  /**
2557
- * @file src/logger/transports/BaseConsolePrettyTransport.ts
2558
- * @description An abstract base class for console transports that provide colored, human-readable output.
2558
+ * @file src/logger/transports/optionalChalk.ts
2559
+ * @description Load chalk optionally so that pretty console transports work in both
2560
+ * ESM (tsx + "type": "module") and CJS (ts-node) consumers. If chalk is missing or
2561
+ * fails to load, a no-op identity is used (no colors).
2559
2562
  */
2563
+ function createNoColorChalk() {
2564
+ const noColor = ((s) => s);
2565
+ noColor.white = noColor;
2566
+ noColor.bold = noColor;
2567
+ noColor.red = noColor;
2568
+ noColor.bgRed = noColor;
2569
+ noColor.yellow = noColor;
2570
+ noColor.cyan = noColor;
2571
+ noColor.green = noColor;
2572
+ noColor.gray = noColor;
2573
+ noColor.magenta = noColor;
2574
+ noColor.blue = noColor;
2575
+ noColor.bgWhite = noColor;
2576
+ noColor.dim = noColor;
2577
+ return noColor;
2578
+ }
2579
+ function getRequire() {
2580
+ if (typeof require !== 'undefined') {
2581
+ return require;
2582
+ }
2583
+ return module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)));
2584
+ }
2585
+ function loadChalkSync() {
2586
+ try {
2587
+ const c = getRequire()('chalk');
2588
+ const ch = (c?.default ?? c);
2589
+ if (ch && typeof ch.white !== 'undefined') {
2590
+ return ch;
2591
+ }
2592
+ }
2593
+ catch {
2594
+ // chalk not installed or failed to load (e.g. CJS/ESM interop)
2595
+ }
2596
+ return createNoColorChalk();
2597
+ }
2598
+ let cached = null;
2599
+ /**
2600
+ * Returns a chalk-like instance: real chalk if available and usable, otherwise
2601
+ * a no-op that returns the string unchanged. Safe to call from both ESM and CJS.
2602
+ */
2603
+ function getOptionalChalk() {
2604
+ if (cached !== null) {
2605
+ return cached;
2606
+ }
2607
+ cached = loadChalkSync();
2608
+ return cached;
2609
+ }
2610
+
2560
2611
  /**
2561
2612
  * @class BaseConsolePrettyTransport
2562
2613
  * @description Provides common functionality for "pretty" console transports,
@@ -2567,8 +2618,7 @@ const syntropyLog = SyntropyLog.getInstance();
2567
2618
  class BaseConsolePrettyTransport extends Transport {
2568
2619
  constructor(options) {
2569
2620
  super(options);
2570
- // Chalk v4 is used directly, not instantiated.
2571
- this.chalk = chalk;
2621
+ this.chalk = getOptionalChalk();
2572
2622
  }
2573
2623
  /**
2574
2624
  * The core log method. It handles common logic and delegates specific
@@ -2706,7 +2756,7 @@ class CompactConsoleTransport extends BaseConsolePrettyTransport {
2706
2756
  // Simple stringify for objects/arrays in metadata.
2707
2757
  const formattedValue = typeof value === 'object' && value !== null
2708
2758
  ? JSON.stringify(value)
2709
- : value;
2759
+ : String(value);
2710
2760
  return `${this.chalk.dim(key)}=${this.chalk.gray(formattedValue)}`;
2711
2761
  })
2712
2762
  .join(' ');