@devicecloud.dev/dcd 5.16.0-beta.2 → 5.16.0-beta.3

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.
@@ -2,9 +2,10 @@
2
2
  * Centralized styling utilities for CLI output
3
3
  * Provides consistent, developer-friendly visual formatting
4
4
  *
5
- * Colours come from Node's `util.styleText`. Text is styled only when stdout
6
- * takes colour (see {@link takesColour}); text bound for stderr goes through
7
- * {@link forStderr}.
5
+ * Text is styled only when stdout takes colour (see {@link takesColour}); text
6
+ * bound for stderr goes through {@link forStderr}. The escape codes come from
7
+ * `util.inspect.colors`, the table Node's `styleText` reads, and are applied
8
+ * by {@link style}.
8
9
  */
9
10
  /** Strip ANSI color escape sequences for visible-width calculations. */
10
11
  export declare const stripAnsi: (s: string) => string;
@@ -1,12 +1,13 @@
1
- import { styleText } from 'node:util';
1
+ import { inspect } from 'node:util';
2
2
  import { findEnvByApiUrl } from '../config/environments.js';
3
3
  /**
4
4
  * Centralized styling utilities for CLI output
5
5
  * Provides consistent, developer-friendly visual formatting
6
6
  *
7
- * Colours come from Node's `util.styleText`. Text is styled only when stdout
8
- * takes colour (see {@link takesColour}); text bound for stderr goes through
9
- * {@link forStderr}.
7
+ * Text is styled only when stdout takes colour (see {@link takesColour}); text
8
+ * bound for stderr goes through {@link forStderr}. The escape codes come from
9
+ * `util.inspect.colors`, the table Node's `styleText` reads, and are applied
10
+ * by {@link style}.
10
11
  */
11
12
  /** Strip ANSI color escape sequences for visible-width calculations. */
12
13
  // eslint-disable-next-line no-control-regex -- matches ANSI escape sequences
@@ -16,10 +17,6 @@ export const stripAnsi = (s) => s.replace(/\u001B\[[0-9;]*m/g, '');
16
17
  * `FORCE_COLOR` decides when set; otherwise the stream must be a terminal
17
18
  * whose colour depth (which folds in `NO_COLOR`, `NODE_DISABLE_COLORS` and
18
19
  * `TERM=dumb`) is above monochrome.
19
- *
20
- * Decided here rather than left to `styleText`'s own check because not every
21
- * runtime makes that check: bun 1.3, which compiles the standalone binaries,
22
- * and Node before 22.8 colour unconditionally.
23
20
  */
24
21
  function takesColour(stream) {
25
22
  const force = process.env.FORCE_COLOR;
@@ -29,13 +26,33 @@ function takesColour(stream) {
29
26
  (typeof stream.getColorDepth !== 'function' || stream.getColorDepth() > 2));
30
27
  }
31
28
  /**
32
- * Apply `format` to `text` when stdout takes colour. `styleText` throws on
33
- * anything but a string, so a value the types call a string but an API sent
34
- * as null or a number is printed, never fatal.
29
+ * Apply `format` to `text` when stdout takes colour.
30
+ *
31
+ * This is not left to `util.styleText`, because its output differs across the
32
+ * runtimes the CLI ships on: bun 1.3 (which compiles the standalone binaries)
33
+ * and Node before 22.20 drop the outer colour after a nested span, and bun 1.3
34
+ * and Node before 22.8 colour even when the stream can't show it. The rules
35
+ * here are the ones chalk applied, so output is the same everywhere:
36
+ * - an inner span that ends this style's colour re-opens it, so text after
37
+ * the span keeps the outer colour;
38
+ * - each line is closed and re-opened, so a line read on its own (a CI log, a
39
+ * pager) still carries its colour;
40
+ * - an empty string stays empty.
41
+ *
42
+ * Anything but a string is printed as `String(value)`, never fatal: the types
43
+ * may call a value a string that an API sent as null or a number.
35
44
  */
36
45
  function style(format, text) {
37
46
  const s = String(text);
38
- return takesColour(process.stdout) ? styleText(format, s, { validateStream: false }) : s;
47
+ const codes = inspect.colors[format];
48
+ if (s === '' || !codes || !takesColour(process.stdout))
49
+ return s;
50
+ const open = `\u001B[${codes[0]}m`;
51
+ const close = `\u001B[${codes[1]}m`;
52
+ const body = s
53
+ .replaceAll(close, close + open)
54
+ .replaceAll(/\r?\n/g, (lineBreak) => close + lineBreak + open);
55
+ return open + body + close;
39
56
  }
40
57
  const paint = (format) => (text) => style(format, text);
41
58
  const cyan = paint('cyan');
package/package.json CHANGED
@@ -64,7 +64,7 @@
64
64
  "test:unit": "node scripts/test-runner.mjs --unit",
65
65
  "typecheck": "tsc --noEmit -p tsconfig.test.json"
66
66
  },
67
- "version": "5.16.0-beta.2",
67
+ "version": "5.16.0-beta.3",
68
68
  "bugs": {
69
69
  "url": "https://discord.gg/gm3mJwcNw8"
70
70
  },