shelving 1.234.0 → 1.234.1
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/package.json +1 -1
- package/util/ansi.d.ts +20 -8
- package/util/ansi.js +22 -10
- package/util/env.d.ts +0 -2
- package/util/env.js +0 -2
package/package.json
CHANGED
package/util/ansi.d.ts
CHANGED
|
@@ -14,12 +14,24 @@ export declare const ANSI_UNDERLINE: "\u001B[4m";
|
|
|
14
14
|
export declare const ANSI_STRIKE: "\u001B[9m";
|
|
15
15
|
export declare const ANSI_INVERSE: "\u001B[7m";
|
|
16
16
|
export declare const ANSI_RESET = "\u001B[0m";
|
|
17
|
-
/**
|
|
17
|
+
/**
|
|
18
|
+
* Wrap a string in the ANSI color/style codes (at the start), and `ANSI_RESET` at the end.
|
|
19
|
+
*
|
|
20
|
+
* - The `NO_COLOR` environment variable is read live on every call, so runtimes that populate `process.env` late (e.g. Cloudflare Workers, where `[vars]` bindings are only reliably available within the request scope) are honoured rather than baking in whatever `NO_COLOR` was at module-load time.
|
|
21
|
+
*/
|
|
18
22
|
export declare function ansiWrap(input: string, ...wrappers: ImmutableArray<string>): string;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
export
|
|
25
|
-
|
|
23
|
+
/**
|
|
24
|
+
* A lazily-coloured icon that re-evaluates its ANSI colouring against the live `NO_COLOR` environment variable every time it is converted to a string.
|
|
25
|
+
*
|
|
26
|
+
* - Used directly inside template literals (`${ANSI_SUCCESS}`), where JavaScript invokes `toString()` automatically, so the icon is coloured at use-time, not at module-load time.
|
|
27
|
+
*/
|
|
28
|
+
export type AnsiIcon = {
|
|
29
|
+
toString(): string;
|
|
30
|
+
};
|
|
31
|
+
export declare const ANSI_WAITING: AnsiIcon;
|
|
32
|
+
export declare const ANSI_SUCCESS: AnsiIcon;
|
|
33
|
+
export declare const ANSI_FAILURE: AnsiIcon;
|
|
34
|
+
export declare const ANSI_UP: AnsiIcon;
|
|
35
|
+
export declare const ANSI_DOWN: AnsiIcon;
|
|
36
|
+
export declare const ANSI_RIGHT: AnsiIcon;
|
|
37
|
+
export declare const ANSI_LEFT: AnsiIcon;
|
package/util/ansi.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DOWN, FAILURE, LEFT, RIGHT, SUCCESS, UP, WAITING } from "./constants.js";
|
|
2
|
-
import {
|
|
2
|
+
import { getEnvBoolean } from "./env.js";
|
|
3
3
|
// Colors.
|
|
4
4
|
export const ANSI_DEFAULT = "\x1b[39m";
|
|
5
5
|
export const ANSI_BLACK = "\x1b[30m";
|
|
@@ -18,17 +18,29 @@ export const ANSI_STRIKE = "\x1b[9m";
|
|
|
18
18
|
export const ANSI_INVERSE = "\x1b[7m";
|
|
19
19
|
// Reset.
|
|
20
20
|
export const ANSI_RESET = "\x1b[0m";
|
|
21
|
-
/**
|
|
21
|
+
/**
|
|
22
|
+
* Wrap a string in the ANSI color/style codes (at the start), and `ANSI_RESET` at the end.
|
|
23
|
+
*
|
|
24
|
+
* - The `NO_COLOR` environment variable is read live on every call, so runtimes that populate `process.env` late (e.g. Cloudflare Workers, where `[vars]` bindings are only reliably available within the request scope) are honoured rather than baking in whatever `NO_COLOR` was at module-load time.
|
|
25
|
+
*/
|
|
22
26
|
export function ansiWrap(input, ...wrappers) {
|
|
23
|
-
if (NO_COLOR)
|
|
27
|
+
if (getEnvBoolean("NO_COLOR"))
|
|
24
28
|
return input;
|
|
25
29
|
return `${wrappers.join("")}${input}${ANSI_RESET}`;
|
|
26
30
|
}
|
|
31
|
+
/** Create a lazily-coloured {@link AnsiIcon} that wraps `icon` in `wrappers` on each `toString()`. */
|
|
32
|
+
function _createAnsiIcon(icon, ...wrappers) {
|
|
33
|
+
return {
|
|
34
|
+
toString() {
|
|
35
|
+
return ansiWrap(icon, ...wrappers);
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
}
|
|
27
39
|
// Coloured icons.
|
|
28
|
-
export const ANSI_WAITING =
|
|
29
|
-
export const ANSI_SUCCESS =
|
|
30
|
-
export const ANSI_FAILURE =
|
|
31
|
-
export const ANSI_UP =
|
|
32
|
-
export const ANSI_DOWN =
|
|
33
|
-
export const ANSI_RIGHT =
|
|
34
|
-
export const ANSI_LEFT =
|
|
40
|
+
export const ANSI_WAITING = _createAnsiIcon(WAITING, ANSI_BLUE);
|
|
41
|
+
export const ANSI_SUCCESS = _createAnsiIcon(SUCCESS, ANSI_GREEN);
|
|
42
|
+
export const ANSI_FAILURE = _createAnsiIcon(FAILURE, ANSI_RED);
|
|
43
|
+
export const ANSI_UP = _createAnsiIcon(UP, ANSI_BLUE);
|
|
44
|
+
export const ANSI_DOWN = _createAnsiIcon(DOWN, ANSI_BLUE);
|
|
45
|
+
export const ANSI_RIGHT = _createAnsiIcon(RIGHT, ANSI_BLUE);
|
|
46
|
+
export const ANSI_LEFT = _createAnsiIcon(LEFT, ANSI_BLUE);
|
package/util/env.d.ts
CHANGED
|
@@ -19,5 +19,3 @@ export declare function getEnvBoolean(name: string): boolean | undefined;
|
|
|
19
19
|
* @throws `RequiredError` if the env variable is any other value.
|
|
20
20
|
*/
|
|
21
21
|
export declare function requireEnvBoolean(name: string, caller?: AnyCaller): boolean;
|
|
22
|
-
/** The `NO_COLOR` environment variable is commonly used to indicate that ANSI output shouldn't have color. */
|
|
23
|
-
export declare const NO_COLOR: boolean;
|
package/util/env.js
CHANGED
|
@@ -40,5 +40,3 @@ export function requireEnvBoolean(name, caller = requireEnvBoolean) {
|
|
|
40
40
|
throw new RequiredError(`Environment variable "${name}" must be boolean`, { caller });
|
|
41
41
|
return env;
|
|
42
42
|
}
|
|
43
|
-
/** The `NO_COLOR` environment variable is commonly used to indicate that ANSI output shouldn't have color. */
|
|
44
|
-
export const NO_COLOR = getEnvBoolean("NO_COLOR") ?? false;
|