@socketsecurity/lib 3.0.1 → 3.0.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.
- package/CHANGELOG.md +24 -0
- package/dist/abort.js +60 -1
- package/dist/abort.js.map +2 -2
- package/dist/agent.js +289 -1
- package/dist/agent.js.map +2 -2
- package/dist/ansi.js +60 -1
- package/dist/ansi.js.map +2 -2
- package/dist/argv/flags.js +282 -1
- package/dist/argv/flags.js.map +2 -2
- package/dist/argv/parse.js +171 -1
- package/dist/argv/parse.js.map +2 -2
- package/dist/arrays.js +85 -1
- package/dist/arrays.js.map +2 -2
- package/dist/bin.js +419 -5
- package/dist/bin.js.map +2 -2
- package/dist/cacache.js +139 -1
- package/dist/cacache.js.map +2 -2
- package/dist/cache-with-ttl.js +223 -1
- package/dist/cache-with-ttl.js.map +2 -2
- package/dist/constants/agents.js +126 -1
- package/dist/constants/agents.js.map +2 -2
- package/dist/constants/core.d.ts +1 -1
- package/dist/constants/core.js +57 -2
- package/dist/constants/core.js.map +3 -3
- package/dist/constants/encoding.js +48 -1
- package/dist/constants/encoding.js.map +2 -2
- package/dist/constants/github.js +30 -1
- package/dist/constants/github.js.map +2 -2
- package/dist/constants/licenses.js +66 -1
- package/dist/constants/licenses.js.map +2 -2
- package/dist/constants/node.js +185 -1
- package/dist/constants/node.js.map +2 -2
- package/dist/constants/packages.js +128 -1
- package/dist/constants/packages.js.map +2 -2
- package/dist/constants/paths.js +150 -1
- package/dist/constants/paths.js.map +2 -2
- package/dist/constants/platform.js +41 -1
- package/dist/constants/platform.js.map +2 -2
- package/dist/constants/process.js +52 -1
- package/dist/constants/process.js.map +2 -2
- package/dist/constants/socket.js +102 -1
- package/dist/constants/socket.js.map +2 -2
- package/dist/constants/testing.js +36 -1
- package/dist/constants/testing.js.map +2 -2
- package/dist/constants/time.js +39 -1
- package/dist/constants/time.js.map +2 -2
- package/dist/constants/typescript.js +54 -1
- package/dist/constants/typescript.js.map +2 -2
- package/dist/cover/code.js +135 -1
- package/dist/cover/code.js.map +2 -2
- package/dist/cover/formatters.js +101 -11
- package/dist/cover/formatters.js.map +2 -2
- package/dist/cover/type.js +63 -1
- package/dist/cover/type.js.map +2 -2
- package/dist/cover/types.js +15 -1
- package/dist/cover/types.js.map +2 -2
- package/dist/debug.js +337 -2
- package/dist/debug.js.map +2 -2
- package/dist/dlx-binary.js +408 -7
- package/dist/dlx-binary.js.map +2 -2
- package/dist/dlx-package.js +278 -7
- package/dist/dlx-package.js.map +2 -2
- package/dist/dlx.js +214 -7
- package/dist/dlx.js.map +3 -3
- package/dist/effects/pulse-frames.js +64 -1
- package/dist/effects/pulse-frames.js.map +2 -2
- package/dist/effects/text-shimmer.js +174 -1
- package/dist/effects/text-shimmer.js.map +2 -2
- package/dist/effects/types.js +15 -1
- package/dist/effects/types.js.map +2 -2
- package/dist/effects/ultra.js +61 -1
- package/dist/effects/ultra.js.map +2 -2
- package/dist/env/ci.js +31 -1
- package/dist/env/ci.js.map +2 -2
- package/dist/env/debug.js +30 -1
- package/dist/env/debug.js.map +2 -2
- package/dist/env/github.js +65 -1
- package/dist/env/github.js.map +2 -2
- package/dist/env/helpers.js +47 -1
- package/dist/env/helpers.js.map +2 -2
- package/dist/env/home.js +30 -1
- package/dist/env/home.js.map +2 -2
- package/dist/env/locale.js +40 -1
- package/dist/env/locale.js.map +2 -2
- package/dist/env/node-auth-token.js +30 -1
- package/dist/env/node-auth-token.js.map +2 -2
- package/dist/env/node-env.js +30 -1
- package/dist/env/node-env.js.map +2 -2
- package/dist/env/npm.js +50 -1
- package/dist/env/npm.js.map +2 -2
- package/dist/env/package-manager.js +73 -1
- package/dist/env/package-manager.js.map +2 -2
- package/dist/env/path.js +30 -1
- package/dist/env/path.js.map +2 -2
- package/dist/env/pre-commit.js +31 -1
- package/dist/env/pre-commit.js.map +2 -2
- package/dist/env/rewire.js +72 -1
- package/dist/env/rewire.js.map +2 -2
- package/dist/env/shell.js +30 -1
- package/dist/env/shell.js.map +2 -2
- package/dist/env/socket-cli-shadow.js +51 -1
- package/dist/env/socket-cli-shadow.js.map +2 -2
- package/dist/env/socket-cli.js +86 -1
- package/dist/env/socket-cli.js.map +2 -2
- package/dist/env/socket.js +101 -1
- package/dist/env/socket.js.map +2 -2
- package/dist/env/temp-dir.js +40 -1
- package/dist/env/temp-dir.js.map +2 -2
- package/dist/env/term.js +30 -1
- package/dist/env/term.js.map +2 -2
- package/dist/env/test.js +43 -1
- package/dist/env/test.js.map +2 -2
- package/dist/env/windows.js +45 -1
- package/dist/env/windows.js.map +2 -2
- package/dist/env/xdg.js +40 -1
- package/dist/env/xdg.js.map +2 -2
- package/dist/env.js +170 -1
- package/dist/env.js.map +2 -2
- package/dist/fs.js +670 -7
- package/dist/fs.js.map +2 -2
- package/dist/functions.js +68 -1
- package/dist/functions.js.map +2 -2
- package/dist/git.js +329 -2
- package/dist/git.js.map +2 -2
- package/dist/github.js +202 -1
- package/dist/github.js.map +2 -2
- package/dist/globs.js +149 -1
- package/dist/globs.js.map +3 -3
- package/dist/http-request.js +335 -3
- package/dist/http-request.js.map +2 -2
- package/dist/index.js +69 -1
- package/dist/index.js.map +2 -2
- package/dist/ipc.js +244 -1
- package/dist/ipc.js.map +2 -2
- package/dist/json.js +73 -1
- package/dist/json.js.map +2 -2
- package/dist/links/index.js +60 -1
- package/dist/links/index.js.map +2 -2
- package/dist/logger.js +1384 -1
- package/dist/logger.js.map +2 -2
- package/dist/maintained-node-versions.js +35 -1
- package/dist/maintained-node-versions.js.map +2 -2
- package/dist/memoization.js +210 -1
- package/dist/memoization.js.map +2 -2
- package/dist/objects.js +311 -1
- package/dist/objects.js.map +2 -2
- package/dist/packages/editable.js +356 -9
- package/dist/packages/editable.js.map +2 -2
- package/dist/packages/exports.js +162 -1
- package/dist/packages/exports.js.map +2 -2
- package/dist/packages/isolation.js +187 -1
- package/dist/packages/isolation.js.map +2 -2
- package/dist/packages/licenses.js +214 -1
- package/dist/packages/licenses.js.map +2 -2
- package/dist/packages/manifest.js +190 -1
- package/dist/packages/manifest.js.map +2 -2
- package/dist/packages/normalize.js +132 -1
- package/dist/packages/normalize.js.map +2 -2
- package/dist/packages/operations.js +320 -1
- package/dist/packages/operations.js.map +2 -2
- package/dist/packages/paths.js +53 -1
- package/dist/packages/paths.js.map +2 -2
- package/dist/packages/provenance.js +178 -1
- package/dist/packages/provenance.js.map +2 -2
- package/dist/packages/specs.js +83 -1
- package/dist/packages/specs.js.map +2 -2
- package/dist/packages/validation.js +51 -1
- package/dist/packages/validation.js.map +2 -2
- package/dist/packages.js +129 -1
- package/dist/packages.js.map +2 -2
- package/dist/path.js +446 -1
- package/dist/path.js.map +2 -2
- package/dist/paths/rewire.js +79 -1
- package/dist/paths/rewire.js.map +2 -2
- package/dist/paths.js +190 -1
- package/dist/paths.js.map +2 -2
- package/dist/performance.js +216 -15
- package/dist/performance.js.map +2 -2
- package/dist/process-lock.js +287 -8
- package/dist/process-lock.js.map +2 -2
- package/dist/promise-queue.js +109 -1
- package/dist/promise-queue.js.map +2 -2
- package/dist/promises.js +267 -1
- package/dist/promises.js.map +2 -2
- package/dist/prompts/index.js +45 -1
- package/dist/prompts/index.js.map +2 -2
- package/dist/prompts.js +58 -1
- package/dist/prompts.js.map +2 -2
- package/dist/regexps.js +30 -1
- package/dist/regexps.js.map +2 -2
- package/dist/sea.js +44 -1
- package/dist/sea.js.map +2 -2
- package/dist/shadow.js +58 -1
- package/dist/shadow.js.map +2 -2
- package/dist/signal-exit.js +248 -1
- package/dist/signal-exit.js.map +3 -3
- package/dist/sorts.js +94 -1
- package/dist/sorts.js.map +3 -3
- package/dist/spawn.js +200 -1
- package/dist/spawn.js.map +2 -2
- package/dist/spinner.js +961 -1
- package/dist/spinner.js.map +2 -2
- package/dist/ssri.js +71 -1
- package/dist/ssri.js.map +2 -2
- package/dist/stdio/clear.js +82 -1
- package/dist/stdio/clear.js.map +2 -2
- package/dist/stdio/divider.js +89 -3
- package/dist/stdio/divider.js.map +2 -2
- package/dist/stdio/footer.js +94 -2
- package/dist/stdio/footer.js.map +2 -2
- package/dist/stdio/header.js +100 -2
- package/dist/stdio/header.js.map +2 -2
- package/dist/stdio/mask.js +207 -5
- package/dist/stdio/mask.js.map +2 -2
- package/dist/stdio/progress.js +209 -2
- package/dist/stdio/progress.js.map +2 -2
- package/dist/stdio/prompts.js +88 -1
- package/dist/stdio/prompts.js.map +2 -2
- package/dist/stdio/stderr.js +89 -2
- package/dist/stdio/stderr.js.map +2 -2
- package/dist/stdio/stdout.js +103 -2
- package/dist/stdio/stdout.js.map +2 -2
- package/dist/streams.js +78 -1
- package/dist/streams.js.map +2 -2
- package/dist/strings.js +251 -3
- package/dist/strings.js.map +2 -2
- package/dist/suppress-warnings.js +98 -1
- package/dist/suppress-warnings.js.map +2 -2
- package/dist/tables.js +128 -3
- package/dist/tables.js.map +2 -2
- package/dist/temporary-executor.js +53 -1
- package/dist/temporary-executor.js.map +2 -2
- package/dist/themes/context.js +71 -1
- package/dist/themes/context.js.map +2 -2
- package/dist/themes/index.js +57 -1
- package/dist/themes/index.js.map +2 -2
- package/dist/themes/themes.js +195 -1
- package/dist/themes/themes.js.map +2 -2
- package/dist/themes/types.js +15 -1
- package/dist/themes/types.js.map +2 -2
- package/dist/themes/utils.js +116 -1
- package/dist/themes/utils.js.map +2 -2
- package/dist/types.js +59 -1
- package/dist/types.js.map +2 -2
- package/dist/url.js +142 -1
- package/dist/url.js.map +2 -2
- package/dist/utils/get-ipc.js +58 -1
- package/dist/utils/get-ipc.js.map +2 -2
- package/dist/validation/json-parser.js +127 -1
- package/dist/validation/json-parser.js.map +2 -2
- package/dist/validation/types.js +15 -1
- package/dist/validation/types.js.map +2 -2
- package/dist/versions.js +154 -1
- package/dist/versions.js.map +2 -2
- package/dist/words.js +50 -1
- package/dist/words.js.map +2 -2
- package/dist/zod.js +27 -1
- package/dist/zod.js.map +2 -2
- package/package.json +1 -1
package/dist/spinner.js
CHANGED
|
@@ -1,3 +1,963 @@
|
|
|
1
1
|
/* Socket Lib - Built with esbuild */
|
|
2
|
-
var
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc2) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc2 = __getOwnPropDesc(from, key)) || desc2.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var spinner_exports = {};
|
|
30
|
+
__export(spinner_exports, {
|
|
31
|
+
Spinner: () => Spinner,
|
|
32
|
+
ciSpinner: () => ciSpinner,
|
|
33
|
+
getCliSpinners: () => getCliSpinners,
|
|
34
|
+
getDefaultSpinner: () => getDefaultSpinner,
|
|
35
|
+
toRgb: () => toRgb,
|
|
36
|
+
withSpinner: () => withSpinner,
|
|
37
|
+
withSpinnerRestore: () => withSpinnerRestore,
|
|
38
|
+
withSpinnerSync: () => withSpinnerSync
|
|
39
|
+
});
|
|
40
|
+
module.exports = __toCommonJS(spinner_exports);
|
|
41
|
+
var import_ci = require("#env/ci");
|
|
42
|
+
var import_pulse_frames = require("./effects/pulse-frames");
|
|
43
|
+
var import_text_shimmer = require("./effects/text-shimmer");
|
|
44
|
+
var import_yocto_spinner = __toESM(require("./external/@socketregistry/yocto-spinner"));
|
|
45
|
+
var import_objects = require("./objects");
|
|
46
|
+
var import_strings = require("./strings");
|
|
47
|
+
var import_context = require("./themes/context");
|
|
48
|
+
var import_utils = require("./themes/utils");
|
|
49
|
+
const colorToRgb = {
|
|
50
|
+
__proto__: null,
|
|
51
|
+
black: [0, 0, 0],
|
|
52
|
+
blue: [0, 0, 255],
|
|
53
|
+
blueBright: [100, 149, 237],
|
|
54
|
+
cyan: [0, 255, 255],
|
|
55
|
+
cyanBright: [0, 255, 255],
|
|
56
|
+
gray: [128, 128, 128],
|
|
57
|
+
green: [0, 128, 0],
|
|
58
|
+
greenBright: [0, 255, 0],
|
|
59
|
+
magenta: [255, 0, 255],
|
|
60
|
+
magentaBright: [255, 105, 180],
|
|
61
|
+
red: [255, 0, 0],
|
|
62
|
+
redBright: [255, 69, 0],
|
|
63
|
+
white: [255, 255, 255],
|
|
64
|
+
whiteBright: [255, 255, 255],
|
|
65
|
+
yellow: [255, 255, 0],
|
|
66
|
+
yellowBright: [255, 255, 153]
|
|
67
|
+
};
|
|
68
|
+
function isRgbTuple(value) {
|
|
69
|
+
return Array.isArray(value);
|
|
70
|
+
}
|
|
71
|
+
function toRgb(color) {
|
|
72
|
+
if (isRgbTuple(color)) {
|
|
73
|
+
return color;
|
|
74
|
+
}
|
|
75
|
+
return colorToRgb[color];
|
|
76
|
+
}
|
|
77
|
+
const ciSpinner = {
|
|
78
|
+
frames: [""],
|
|
79
|
+
interval: 2147483647
|
|
80
|
+
};
|
|
81
|
+
function desc(value) {
|
|
82
|
+
return {
|
|
83
|
+
__proto__: null,
|
|
84
|
+
configurable: true,
|
|
85
|
+
value,
|
|
86
|
+
writable: true
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
function normalizeText(value) {
|
|
90
|
+
return typeof value === "string" ? value.trimStart() : "";
|
|
91
|
+
}
|
|
92
|
+
function formatProgress(progress) {
|
|
93
|
+
const { current, total, unit } = progress;
|
|
94
|
+
const percentage = Math.round(current / total * 100);
|
|
95
|
+
const bar = renderProgressBar(percentage);
|
|
96
|
+
const count = unit ? `${current}/${total} ${unit}` : `${current}/${total}`;
|
|
97
|
+
return `${bar} ${percentage}% (${count})`;
|
|
98
|
+
}
|
|
99
|
+
function renderProgressBar(percentage, width = 20) {
|
|
100
|
+
const filled = Math.round(percentage / 100 * width);
|
|
101
|
+
const empty = width - filled;
|
|
102
|
+
const bar = "\u2588".repeat(filled) + "\u2591".repeat(empty);
|
|
103
|
+
const colors = require("./external/yoctocolors-cjs");
|
|
104
|
+
return colors.cyan(bar);
|
|
105
|
+
}
|
|
106
|
+
let _cliSpinners;
|
|
107
|
+
// @__NO_SIDE_EFFECTS__
|
|
108
|
+
function getCliSpinners(styleName) {
|
|
109
|
+
if (_cliSpinners === void 0) {
|
|
110
|
+
const YoctoCtor = import_yocto_spinner.default;
|
|
111
|
+
const tempInstance = YoctoCtor({});
|
|
112
|
+
const YoctoSpinnerClass = tempInstance.constructor;
|
|
113
|
+
_cliSpinners = {
|
|
114
|
+
__proto__: null,
|
|
115
|
+
...YoctoSpinnerClass.spinners,
|
|
116
|
+
socket: (0, import_pulse_frames.generateSocketSpinnerFrames)()
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
if (typeof styleName === "string" && _cliSpinners) {
|
|
120
|
+
return (0, import_objects.hasOwn)(_cliSpinners, styleName) ? _cliSpinners[styleName] : void 0;
|
|
121
|
+
}
|
|
122
|
+
return _cliSpinners;
|
|
123
|
+
}
|
|
124
|
+
let _Spinner;
|
|
125
|
+
let _defaultSpinner;
|
|
126
|
+
// @__NO_SIDE_EFFECTS__
|
|
127
|
+
function Spinner(options) {
|
|
128
|
+
if (_Spinner === void 0) {
|
|
129
|
+
const YoctoCtor = import_yocto_spinner.default;
|
|
130
|
+
const tempInstance = YoctoCtor({});
|
|
131
|
+
const YoctoSpinnerClass = tempInstance.constructor;
|
|
132
|
+
_Spinner = class SpinnerClass extends YoctoSpinnerClass {
|
|
133
|
+
#baseText = "";
|
|
134
|
+
#indentation = "";
|
|
135
|
+
#progress;
|
|
136
|
+
#shimmer;
|
|
137
|
+
#shimmerSavedConfig;
|
|
138
|
+
constructor(options2) {
|
|
139
|
+
const opts = { __proto__: null, ...options2 };
|
|
140
|
+
const theme = (0, import_context.getTheme)();
|
|
141
|
+
let defaultColor = theme.colors.primary;
|
|
142
|
+
if (theme.effects?.spinner?.color) {
|
|
143
|
+
const resolved = (0, import_utils.resolveColor)(
|
|
144
|
+
theme.effects.spinner.color,
|
|
145
|
+
theme.colors
|
|
146
|
+
);
|
|
147
|
+
if (resolved === "inherit" || Array.isArray(resolved[0])) {
|
|
148
|
+
defaultColor = theme.colors.primary;
|
|
149
|
+
} else {
|
|
150
|
+
defaultColor = resolved;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
const spinnerColor = opts.color ?? defaultColor;
|
|
154
|
+
if (isRgbTuple(spinnerColor) && (spinnerColor.length !== 3 || !spinnerColor.every(
|
|
155
|
+
(n) => typeof n === "number" && n >= 0 && n <= 255
|
|
156
|
+
))) {
|
|
157
|
+
throw new TypeError(
|
|
158
|
+
"RGB color must be an array of 3 numbers between 0 and 255"
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
const spinnerColorRgb = toRgb(spinnerColor);
|
|
162
|
+
let shimmerInfo;
|
|
163
|
+
if (opts.shimmer) {
|
|
164
|
+
let shimmerDir;
|
|
165
|
+
let shimmerColor;
|
|
166
|
+
let shimmerSpeed = 1 / 3;
|
|
167
|
+
if (typeof opts.shimmer === "string") {
|
|
168
|
+
shimmerDir = opts.shimmer;
|
|
169
|
+
} else {
|
|
170
|
+
const shimmerConfig = {
|
|
171
|
+
__proto__: null,
|
|
172
|
+
...opts.shimmer
|
|
173
|
+
};
|
|
174
|
+
shimmerDir = shimmerConfig.dir ?? import_text_shimmer.DIR_LTR;
|
|
175
|
+
shimmerColor = shimmerConfig.color ?? import_text_shimmer.COLOR_INHERIT;
|
|
176
|
+
shimmerSpeed = shimmerConfig.speed ?? 1 / 3;
|
|
177
|
+
}
|
|
178
|
+
shimmerInfo = {
|
|
179
|
+
__proto__: null,
|
|
180
|
+
color: shimmerColor === void 0 ? import_text_shimmer.COLOR_INHERIT : shimmerColor,
|
|
181
|
+
currentDir: import_text_shimmer.DIR_LTR,
|
|
182
|
+
mode: shimmerDir,
|
|
183
|
+
speed: shimmerSpeed,
|
|
184
|
+
step: 0
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
super({
|
|
188
|
+
signal: require("#constants/process").getAbortSignal(),
|
|
189
|
+
...opts,
|
|
190
|
+
// Pass RGB color directly to yocto-spinner (it now supports RGB).
|
|
191
|
+
color: spinnerColorRgb,
|
|
192
|
+
// onRenderFrame callback provides full control over frame + text layout.
|
|
193
|
+
// Calculates spacing based on frame width to prevent text jumping.
|
|
194
|
+
onRenderFrame: (frame, text, applyColor) => {
|
|
195
|
+
const width = (0, import_strings.stringWidth)(frame);
|
|
196
|
+
const spacing = width === 1 ? " " : " ";
|
|
197
|
+
return frame ? `${applyColor(frame)}${spacing}${text}` : text;
|
|
198
|
+
},
|
|
199
|
+
// onFrameUpdate callback is called by yocto-spinner whenever a frame advances.
|
|
200
|
+
// This ensures shimmer updates are perfectly synchronized with animation beats.
|
|
201
|
+
onFrameUpdate: shimmerInfo ? () => {
|
|
202
|
+
if (this.#baseText) {
|
|
203
|
+
super.text = this.#buildDisplayText();
|
|
204
|
+
}
|
|
205
|
+
} : void 0
|
|
206
|
+
});
|
|
207
|
+
this.#shimmer = shimmerInfo;
|
|
208
|
+
this.#shimmerSavedConfig = shimmerInfo;
|
|
209
|
+
}
|
|
210
|
+
// Override color getter to ensure it's always RGB.
|
|
211
|
+
get color() {
|
|
212
|
+
const value = super.color;
|
|
213
|
+
return isRgbTuple(value) ? value : toRgb(value);
|
|
214
|
+
}
|
|
215
|
+
// Override color setter to always convert to RGB before passing to yocto-spinner.
|
|
216
|
+
set color(value) {
|
|
217
|
+
super.color = isRgbTuple(value) ? value : toRgb(value);
|
|
218
|
+
}
|
|
219
|
+
// Getter to expose current shimmer state.
|
|
220
|
+
get shimmerState() {
|
|
221
|
+
if (!this.#shimmer) {
|
|
222
|
+
return void 0;
|
|
223
|
+
}
|
|
224
|
+
return {
|
|
225
|
+
color: this.#shimmer.color,
|
|
226
|
+
currentDir: this.#shimmer.currentDir,
|
|
227
|
+
mode: this.#shimmer.mode,
|
|
228
|
+
speed: this.#shimmer.speed,
|
|
229
|
+
step: this.#shimmer.step
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Apply a yocto-spinner method and update logger state.
|
|
234
|
+
* Handles text normalization, extra arguments, and logger tracking.
|
|
235
|
+
* @private
|
|
236
|
+
*/
|
|
237
|
+
#apply(methodName, args) {
|
|
238
|
+
let extras;
|
|
239
|
+
let text = args.at(0);
|
|
240
|
+
if (typeof text === "string") {
|
|
241
|
+
extras = args.slice(1);
|
|
242
|
+
} else {
|
|
243
|
+
extras = args;
|
|
244
|
+
text = "";
|
|
245
|
+
}
|
|
246
|
+
const wasSpinning = this.isSpinning;
|
|
247
|
+
const normalized = normalizeText(text);
|
|
248
|
+
super[methodName](normalized);
|
|
249
|
+
const {
|
|
250
|
+
getDefaultLogger,
|
|
251
|
+
incLogCallCountSymbol,
|
|
252
|
+
lastWasBlankSymbol
|
|
253
|
+
} = require("./logger.js");
|
|
254
|
+
const logger = getDefaultLogger();
|
|
255
|
+
if (methodName === "stop") {
|
|
256
|
+
if (wasSpinning && normalized) {
|
|
257
|
+
logger[lastWasBlankSymbol]((0, import_strings.isBlankString)(normalized));
|
|
258
|
+
logger[incLogCallCountSymbol]();
|
|
259
|
+
}
|
|
260
|
+
} else {
|
|
261
|
+
logger[lastWasBlankSymbol](false);
|
|
262
|
+
logger[incLogCallCountSymbol]();
|
|
263
|
+
}
|
|
264
|
+
if (extras.length) {
|
|
265
|
+
logger.log(...extras);
|
|
266
|
+
logger[lastWasBlankSymbol](false);
|
|
267
|
+
}
|
|
268
|
+
return this;
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Build the complete display text with progress, shimmer, and indentation.
|
|
272
|
+
* Combines base text, progress bar, shimmer effects, and indentation.
|
|
273
|
+
* @private
|
|
274
|
+
*/
|
|
275
|
+
#buildDisplayText() {
|
|
276
|
+
let displayText = this.#baseText;
|
|
277
|
+
if (this.#progress) {
|
|
278
|
+
const progressText = formatProgress(this.#progress);
|
|
279
|
+
displayText = displayText ? `${displayText} ${progressText}` : progressText;
|
|
280
|
+
}
|
|
281
|
+
if (displayText && this.#shimmer) {
|
|
282
|
+
let shimmerColor;
|
|
283
|
+
if (this.#shimmer.color === import_text_shimmer.COLOR_INHERIT) {
|
|
284
|
+
shimmerColor = this.color;
|
|
285
|
+
} else if (Array.isArray(this.#shimmer.color[0])) {
|
|
286
|
+
shimmerColor = this.#shimmer.color;
|
|
287
|
+
} else {
|
|
288
|
+
shimmerColor = toRgb(this.#shimmer.color);
|
|
289
|
+
}
|
|
290
|
+
displayText = (0, import_text_shimmer.applyShimmer)(displayText, this.#shimmer, {
|
|
291
|
+
color: shimmerColor,
|
|
292
|
+
direction: this.#shimmer.mode
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
if (this.#indentation && displayText) {
|
|
296
|
+
displayText = this.#indentation + displayText;
|
|
297
|
+
}
|
|
298
|
+
return displayText;
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Show a status message without stopping the spinner.
|
|
302
|
+
* Outputs the symbol and message to stderr, then continues spinning.
|
|
303
|
+
*/
|
|
304
|
+
#showStatusAndKeepSpinning(symbolType, args) {
|
|
305
|
+
let text = args.at(0);
|
|
306
|
+
let extras;
|
|
307
|
+
if (typeof text === "string") {
|
|
308
|
+
extras = args.slice(1);
|
|
309
|
+
} else {
|
|
310
|
+
extras = args;
|
|
311
|
+
text = "";
|
|
312
|
+
}
|
|
313
|
+
const {
|
|
314
|
+
LOG_SYMBOLS,
|
|
315
|
+
getDefaultLogger
|
|
316
|
+
} = require("./logger.js");
|
|
317
|
+
const logger = getDefaultLogger();
|
|
318
|
+
logger.error(`${LOG_SYMBOLS[symbolType]} ${text}`, ...extras);
|
|
319
|
+
return this;
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* Update the spinner's displayed text.
|
|
323
|
+
* Rebuilds display text and triggers render.
|
|
324
|
+
* @private
|
|
325
|
+
*/
|
|
326
|
+
#updateSpinnerText() {
|
|
327
|
+
super.text = this.#buildDisplayText();
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Show a debug message (ℹ) without stopping the spinner.
|
|
331
|
+
* Only displays if debug mode is enabled via environment variable.
|
|
332
|
+
* Outputs to stderr and continues spinning.
|
|
333
|
+
*
|
|
334
|
+
* @param text - Debug message to display
|
|
335
|
+
* @param extras - Additional values to log
|
|
336
|
+
* @returns This spinner for chaining
|
|
337
|
+
*/
|
|
338
|
+
debug(text, ...extras) {
|
|
339
|
+
const { isDebug } = require("./debug.js");
|
|
340
|
+
if (isDebug()) {
|
|
341
|
+
return this.#showStatusAndKeepSpinning("info", [text, ...extras]);
|
|
342
|
+
}
|
|
343
|
+
return this;
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* Show a debug message (ℹ) and stop the spinner.
|
|
347
|
+
* Only displays if debug mode is enabled via environment variable.
|
|
348
|
+
* Auto-clears the spinner line before displaying the message.
|
|
349
|
+
*
|
|
350
|
+
* @param text - Debug message to display
|
|
351
|
+
* @param extras - Additional values to log
|
|
352
|
+
* @returns This spinner for chaining
|
|
353
|
+
*/
|
|
354
|
+
debugAndStop(text, ...extras) {
|
|
355
|
+
const { isDebug } = require("./debug.js");
|
|
356
|
+
if (isDebug()) {
|
|
357
|
+
return this.#apply("info", [text, ...extras]);
|
|
358
|
+
}
|
|
359
|
+
return this;
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* Decrease indentation level by removing spaces from the left.
|
|
363
|
+
* Pass 0 to reset indentation to zero completely.
|
|
364
|
+
*
|
|
365
|
+
* @param spaces - Number of spaces to remove
|
|
366
|
+
* @returns This spinner for chaining
|
|
367
|
+
* @default spaces=2
|
|
368
|
+
*
|
|
369
|
+
* @example
|
|
370
|
+
* ```ts
|
|
371
|
+
* spinner.dedent() // Remove 2 spaces
|
|
372
|
+
* spinner.dedent(4) // Remove 4 spaces
|
|
373
|
+
* spinner.dedent(0) // Reset to zero indentation
|
|
374
|
+
* ```
|
|
375
|
+
*/
|
|
376
|
+
dedent(spaces) {
|
|
377
|
+
if (spaces === 0) {
|
|
378
|
+
this.#indentation = "";
|
|
379
|
+
} else {
|
|
380
|
+
const amount = spaces ?? 2;
|
|
381
|
+
const newLength = Math.max(0, this.#indentation.length - amount);
|
|
382
|
+
this.#indentation = this.#indentation.slice(0, newLength);
|
|
383
|
+
}
|
|
384
|
+
this.#updateSpinnerText();
|
|
385
|
+
return this;
|
|
386
|
+
}
|
|
387
|
+
/**
|
|
388
|
+
* Show a done/success message (✓) without stopping the spinner.
|
|
389
|
+
* Alias for `success()` with a shorter name.
|
|
390
|
+
*
|
|
391
|
+
* DESIGN DECISION: Unlike yocto-spinner, our `done()` does NOT stop the spinner.
|
|
392
|
+
* Use `doneAndStop()` if you want to stop the spinner.
|
|
393
|
+
*
|
|
394
|
+
* @param text - Message to display
|
|
395
|
+
* @param extras - Additional values to log
|
|
396
|
+
* @returns This spinner for chaining
|
|
397
|
+
*/
|
|
398
|
+
done(text, ...extras) {
|
|
399
|
+
return this.#showStatusAndKeepSpinning("success", [text, ...extras]);
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* Show a done/success message (✓) and stop the spinner.
|
|
403
|
+
* Auto-clears the spinner line before displaying the success message.
|
|
404
|
+
*
|
|
405
|
+
* @param text - Message to display
|
|
406
|
+
* @param extras - Additional values to log
|
|
407
|
+
* @returns This spinner for chaining
|
|
408
|
+
*/
|
|
409
|
+
doneAndStop(text, ...extras) {
|
|
410
|
+
return this.#apply("success", [text, ...extras]);
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* Show a failure message (✗) without stopping the spinner.
|
|
414
|
+
* DESIGN DECISION: Unlike yocto-spinner, our `fail()` does NOT stop the spinner.
|
|
415
|
+
* This allows displaying errors while continuing to spin.
|
|
416
|
+
* Use `failAndStop()` if you want to stop the spinner.
|
|
417
|
+
*
|
|
418
|
+
* @param text - Error message to display
|
|
419
|
+
* @param extras - Additional values to log
|
|
420
|
+
* @returns This spinner for chaining
|
|
421
|
+
*/
|
|
422
|
+
fail(text, ...extras) {
|
|
423
|
+
return this.#showStatusAndKeepSpinning("fail", [text, ...extras]);
|
|
424
|
+
}
|
|
425
|
+
/**
|
|
426
|
+
* Show a failure message (✗) and stop the spinner.
|
|
427
|
+
* Auto-clears the spinner line before displaying the error message.
|
|
428
|
+
*
|
|
429
|
+
* @param text - Error message to display
|
|
430
|
+
* @param extras - Additional values to log
|
|
431
|
+
* @returns This spinner for chaining
|
|
432
|
+
*/
|
|
433
|
+
failAndStop(text, ...extras) {
|
|
434
|
+
return this.#apply("error", [text, ...extras]);
|
|
435
|
+
}
|
|
436
|
+
/**
|
|
437
|
+
* Increase indentation level by adding spaces to the left.
|
|
438
|
+
* Pass 0 to reset indentation to zero completely.
|
|
439
|
+
*
|
|
440
|
+
* @param spaces - Number of spaces to add
|
|
441
|
+
* @returns This spinner for chaining
|
|
442
|
+
* @default spaces=2
|
|
443
|
+
*
|
|
444
|
+
* @example
|
|
445
|
+
* ```ts
|
|
446
|
+
* spinner.indent() // Add 2 spaces
|
|
447
|
+
* spinner.indent(4) // Add 4 spaces
|
|
448
|
+
* spinner.indent(0) // Reset to zero indentation
|
|
449
|
+
* ```
|
|
450
|
+
*/
|
|
451
|
+
indent(spaces) {
|
|
452
|
+
if (spaces === 0) {
|
|
453
|
+
this.#indentation = "";
|
|
454
|
+
} else {
|
|
455
|
+
const amount = spaces ?? 2;
|
|
456
|
+
this.#indentation += " ".repeat(amount);
|
|
457
|
+
}
|
|
458
|
+
this.#updateSpinnerText();
|
|
459
|
+
return this;
|
|
460
|
+
}
|
|
461
|
+
/**
|
|
462
|
+
* Show an info message (ℹ) without stopping the spinner.
|
|
463
|
+
* Outputs to stderr and continues spinning.
|
|
464
|
+
*
|
|
465
|
+
* @param text - Info message to display
|
|
466
|
+
* @param extras - Additional values to log
|
|
467
|
+
* @returns This spinner for chaining
|
|
468
|
+
*/
|
|
469
|
+
info(text, ...extras) {
|
|
470
|
+
return this.#showStatusAndKeepSpinning("info", [text, ...extras]);
|
|
471
|
+
}
|
|
472
|
+
/**
|
|
473
|
+
* Show an info message (ℹ) and stop the spinner.
|
|
474
|
+
* Auto-clears the spinner line before displaying the message.
|
|
475
|
+
*
|
|
476
|
+
* @param text - Info message to display
|
|
477
|
+
* @param extras - Additional values to log
|
|
478
|
+
* @returns This spinner for chaining
|
|
479
|
+
*/
|
|
480
|
+
infoAndStop(text, ...extras) {
|
|
481
|
+
return this.#apply("info", [text, ...extras]);
|
|
482
|
+
}
|
|
483
|
+
/**
|
|
484
|
+
* Log a message to stdout without stopping the spinner.
|
|
485
|
+
* Unlike other status methods, this outputs to stdout for data logging.
|
|
486
|
+
*
|
|
487
|
+
* @param args - Values to log to stdout
|
|
488
|
+
* @returns This spinner for chaining
|
|
489
|
+
*/
|
|
490
|
+
log(...args) {
|
|
491
|
+
const { getDefaultLogger } = require("./logger.js");
|
|
492
|
+
const logger = getDefaultLogger();
|
|
493
|
+
logger.log(...args);
|
|
494
|
+
return this;
|
|
495
|
+
}
|
|
496
|
+
/**
|
|
497
|
+
* Log a message to stdout and stop the spinner.
|
|
498
|
+
* Auto-clears the spinner line before displaying the message.
|
|
499
|
+
*
|
|
500
|
+
* @param text - Message to display
|
|
501
|
+
* @param extras - Additional values to log
|
|
502
|
+
* @returns This spinner for chaining
|
|
503
|
+
*/
|
|
504
|
+
logAndStop(text, ...extras) {
|
|
505
|
+
return this.#apply("stop", [text, ...extras]);
|
|
506
|
+
}
|
|
507
|
+
/**
|
|
508
|
+
* Update progress information displayed with the spinner.
|
|
509
|
+
* Shows a progress bar with percentage and optional unit label.
|
|
510
|
+
*
|
|
511
|
+
* @param current - Current progress value
|
|
512
|
+
* @param total - Total/maximum progress value
|
|
513
|
+
* @param unit - Optional unit label (e.g., 'files', 'items')
|
|
514
|
+
* @returns This spinner for chaining
|
|
515
|
+
*
|
|
516
|
+
* @example
|
|
517
|
+
* ```ts
|
|
518
|
+
* spinner.progress(5, 10) // "███████░░░░░░░░░░░░░ 50% (5/10)"
|
|
519
|
+
* spinner.progress(7, 20, 'files') // "███████░░░░░░░░░░░░░ 35% (7/20 files)"
|
|
520
|
+
* ```
|
|
521
|
+
*/
|
|
522
|
+
progress = (current, total, unit) => {
|
|
523
|
+
this.#progress = {
|
|
524
|
+
__proto__: null,
|
|
525
|
+
current,
|
|
526
|
+
total,
|
|
527
|
+
...unit ? { unit } : {}
|
|
528
|
+
};
|
|
529
|
+
this.#updateSpinnerText();
|
|
530
|
+
return this;
|
|
531
|
+
};
|
|
532
|
+
/**
|
|
533
|
+
* Increment progress by a specified amount.
|
|
534
|
+
* Updates the progress bar displayed with the spinner.
|
|
535
|
+
* Clamps the result between 0 and the total value.
|
|
536
|
+
*
|
|
537
|
+
* @param amount - Amount to increment by
|
|
538
|
+
* @returns This spinner for chaining
|
|
539
|
+
* @default amount=1
|
|
540
|
+
*
|
|
541
|
+
* @example
|
|
542
|
+
* ```ts
|
|
543
|
+
* spinner.progress(0, 10, 'files')
|
|
544
|
+
* spinner.progressStep() // Progress: 1/10
|
|
545
|
+
* spinner.progressStep(3) // Progress: 4/10
|
|
546
|
+
* ```
|
|
547
|
+
*/
|
|
548
|
+
progressStep(amount = 1) {
|
|
549
|
+
if (this.#progress) {
|
|
550
|
+
const newCurrent = this.#progress.current + amount;
|
|
551
|
+
this.#progress = {
|
|
552
|
+
__proto__: null,
|
|
553
|
+
current: Math.max(0, Math.min(newCurrent, this.#progress.total)),
|
|
554
|
+
total: this.#progress.total,
|
|
555
|
+
...this.#progress.unit ? { unit: this.#progress.unit } : {}
|
|
556
|
+
};
|
|
557
|
+
this.#updateSpinnerText();
|
|
558
|
+
}
|
|
559
|
+
return this;
|
|
560
|
+
}
|
|
561
|
+
/**
|
|
562
|
+
* Start the spinner animation with optional text.
|
|
563
|
+
* Begins displaying the animated spinner on stderr.
|
|
564
|
+
*
|
|
565
|
+
* @param text - Optional text to display with the spinner
|
|
566
|
+
* @returns This spinner for chaining
|
|
567
|
+
*
|
|
568
|
+
* @example
|
|
569
|
+
* ```ts
|
|
570
|
+
* spinner.start('Loading…')
|
|
571
|
+
* // Later:
|
|
572
|
+
* spinner.successAndStop('Done!')
|
|
573
|
+
* ```
|
|
574
|
+
*/
|
|
575
|
+
start(...args) {
|
|
576
|
+
if (args.length) {
|
|
577
|
+
const text = args.at(0);
|
|
578
|
+
const normalized = normalizeText(text);
|
|
579
|
+
if (!normalized) {
|
|
580
|
+
this.#baseText = "";
|
|
581
|
+
super.text = "";
|
|
582
|
+
} else {
|
|
583
|
+
this.#baseText = normalized;
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
this.#updateSpinnerText();
|
|
587
|
+
return this.#apply("start", []);
|
|
588
|
+
}
|
|
589
|
+
/**
|
|
590
|
+
* Log a main step message to stderr without stopping the spinner.
|
|
591
|
+
* Adds a blank line before the message for visual separation.
|
|
592
|
+
* Aligns with `logger.step()` to use stderr for status messages.
|
|
593
|
+
*
|
|
594
|
+
* @param text - Step message to display
|
|
595
|
+
* @param extras - Additional values to log
|
|
596
|
+
* @returns This spinner for chaining
|
|
597
|
+
*
|
|
598
|
+
* @example
|
|
599
|
+
* ```ts
|
|
600
|
+
* spinner.step('Building application')
|
|
601
|
+
* spinner.substep('Compiling TypeScript')
|
|
602
|
+
* spinner.substep('Bundling assets')
|
|
603
|
+
* ```
|
|
604
|
+
*/
|
|
605
|
+
step(text, ...extras) {
|
|
606
|
+
const { getDefaultLogger } = require("./logger.js");
|
|
607
|
+
if (typeof text === "string") {
|
|
608
|
+
const logger = getDefaultLogger();
|
|
609
|
+
logger.error("");
|
|
610
|
+
logger.error(text, ...extras);
|
|
611
|
+
}
|
|
612
|
+
return this;
|
|
613
|
+
}
|
|
614
|
+
/**
|
|
615
|
+
* Log an indented substep message to stderr without stopping the spinner.
|
|
616
|
+
* Adds 2-space indentation to the message.
|
|
617
|
+
* Aligns with `logger.substep()` to use stderr for status messages.
|
|
618
|
+
*
|
|
619
|
+
* @param text - Substep message to display
|
|
620
|
+
* @param extras - Additional values to log
|
|
621
|
+
* @returns This spinner for chaining
|
|
622
|
+
*
|
|
623
|
+
* @example
|
|
624
|
+
* ```ts
|
|
625
|
+
* spinner.step('Building application')
|
|
626
|
+
* spinner.substep('Compiling TypeScript')
|
|
627
|
+
* spinner.substep('Bundling assets')
|
|
628
|
+
* ```
|
|
629
|
+
*/
|
|
630
|
+
substep(text, ...extras) {
|
|
631
|
+
if (typeof text === "string") {
|
|
632
|
+
const { getDefaultLogger } = require("./logger.js");
|
|
633
|
+
const logger = getDefaultLogger();
|
|
634
|
+
logger.error(` ${text}`, ...extras);
|
|
635
|
+
}
|
|
636
|
+
return this;
|
|
637
|
+
}
|
|
638
|
+
/**
|
|
639
|
+
* Stop the spinner animation and clear internal state.
|
|
640
|
+
* Auto-clears the spinner line via yocto-spinner.stop().
|
|
641
|
+
* Resets progress, shimmer, and text state.
|
|
642
|
+
*
|
|
643
|
+
* @param text - Optional final text to display after stopping
|
|
644
|
+
* @returns This spinner for chaining
|
|
645
|
+
*
|
|
646
|
+
* @example
|
|
647
|
+
* ```ts
|
|
648
|
+
* spinner.start('Processing…')
|
|
649
|
+
* // Do work
|
|
650
|
+
* spinner.stop() // Just stop, no message
|
|
651
|
+
* // or
|
|
652
|
+
* spinner.stop('Finished processing')
|
|
653
|
+
* ```
|
|
654
|
+
*/
|
|
655
|
+
stop(...args) {
|
|
656
|
+
this.#baseText = "";
|
|
657
|
+
this.#progress = void 0;
|
|
658
|
+
if (this.#shimmer) {
|
|
659
|
+
this.#shimmer.currentDir = import_text_shimmer.DIR_LTR;
|
|
660
|
+
this.#shimmer.step = 0;
|
|
661
|
+
}
|
|
662
|
+
const result = this.#apply("stop", args);
|
|
663
|
+
super.text = "";
|
|
664
|
+
return result;
|
|
665
|
+
}
|
|
666
|
+
/**
|
|
667
|
+
* Show a success message (✓) without stopping the spinner.
|
|
668
|
+
* DESIGN DECISION: Unlike yocto-spinner, our `success()` does NOT stop the spinner.
|
|
669
|
+
* This allows displaying success messages while continuing to spin for multi-step operations.
|
|
670
|
+
* Use `successAndStop()` if you want to stop the spinner.
|
|
671
|
+
*
|
|
672
|
+
* @param text - Success message to display
|
|
673
|
+
* @param extras - Additional values to log
|
|
674
|
+
* @returns This spinner for chaining
|
|
675
|
+
*/
|
|
676
|
+
success(text, ...extras) {
|
|
677
|
+
return this.#showStatusAndKeepSpinning("success", [text, ...extras]);
|
|
678
|
+
}
|
|
679
|
+
/**
|
|
680
|
+
* Show a success message (✓) and stop the spinner.
|
|
681
|
+
* Auto-clears the spinner line before displaying the success message.
|
|
682
|
+
*
|
|
683
|
+
* @param text - Success message to display
|
|
684
|
+
* @param extras - Additional values to log
|
|
685
|
+
* @returns This spinner for chaining
|
|
686
|
+
*/
|
|
687
|
+
successAndStop(text, ...extras) {
|
|
688
|
+
return this.#apply("success", [text, ...extras]);
|
|
689
|
+
}
|
|
690
|
+
text(value) {
|
|
691
|
+
if (arguments.length === 0) {
|
|
692
|
+
return this.#baseText;
|
|
693
|
+
}
|
|
694
|
+
this.#baseText = value ?? "";
|
|
695
|
+
this.#updateSpinnerText();
|
|
696
|
+
return this;
|
|
697
|
+
}
|
|
698
|
+
/**
|
|
699
|
+
* Show a warning message (⚠) without stopping the spinner.
|
|
700
|
+
* Outputs to stderr and continues spinning.
|
|
701
|
+
*
|
|
702
|
+
* @param text - Warning message to display
|
|
703
|
+
* @param extras - Additional values to log
|
|
704
|
+
* @returns This spinner for chaining
|
|
705
|
+
*/
|
|
706
|
+
warn(text, ...extras) {
|
|
707
|
+
return this.#showStatusAndKeepSpinning("warn", [text, ...extras]);
|
|
708
|
+
}
|
|
709
|
+
/**
|
|
710
|
+
* Show a warning message (⚠) and stop the spinner.
|
|
711
|
+
* Auto-clears the spinner line before displaying the warning message.
|
|
712
|
+
*
|
|
713
|
+
* @param text - Warning message to display
|
|
714
|
+
* @param extras - Additional values to log
|
|
715
|
+
* @returns This spinner for chaining
|
|
716
|
+
*/
|
|
717
|
+
warnAndStop(text, ...extras) {
|
|
718
|
+
return this.#apply("warning", [text, ...extras]);
|
|
719
|
+
}
|
|
720
|
+
/**
|
|
721
|
+
* Enable shimmer effect.
|
|
722
|
+
* Restores saved config or uses defaults if no saved config exists.
|
|
723
|
+
*
|
|
724
|
+
* @returns This spinner for chaining
|
|
725
|
+
*
|
|
726
|
+
* @example
|
|
727
|
+
* spinner.enableShimmer()
|
|
728
|
+
*/
|
|
729
|
+
enableShimmer() {
|
|
730
|
+
if (this.#shimmerSavedConfig) {
|
|
731
|
+
this.#shimmer = { ...this.#shimmerSavedConfig };
|
|
732
|
+
} else {
|
|
733
|
+
this.#shimmer = {
|
|
734
|
+
color: import_text_shimmer.COLOR_INHERIT,
|
|
735
|
+
currentDir: import_text_shimmer.DIR_LTR,
|
|
736
|
+
mode: import_text_shimmer.DIR_LTR,
|
|
737
|
+
speed: 1 / 3,
|
|
738
|
+
step: 0
|
|
739
|
+
};
|
|
740
|
+
this.#shimmerSavedConfig = this.#shimmer;
|
|
741
|
+
}
|
|
742
|
+
this.#updateSpinnerText();
|
|
743
|
+
return this;
|
|
744
|
+
}
|
|
745
|
+
/**
|
|
746
|
+
* Disable shimmer effect.
|
|
747
|
+
* Preserves config for later re-enable via enableShimmer().
|
|
748
|
+
*
|
|
749
|
+
* @returns This spinner for chaining
|
|
750
|
+
*
|
|
751
|
+
* @example
|
|
752
|
+
* spinner.disableShimmer()
|
|
753
|
+
*/
|
|
754
|
+
disableShimmer() {
|
|
755
|
+
this.#shimmer = void 0;
|
|
756
|
+
this.#updateSpinnerText();
|
|
757
|
+
return this;
|
|
758
|
+
}
|
|
759
|
+
/**
|
|
760
|
+
* Set complete shimmer configuration.
|
|
761
|
+
* Replaces any existing shimmer config with the provided values.
|
|
762
|
+
*
|
|
763
|
+
* @param config - Complete shimmer configuration
|
|
764
|
+
* @returns This spinner for chaining
|
|
765
|
+
*
|
|
766
|
+
* @example
|
|
767
|
+
* spinner.setShimmer({
|
|
768
|
+
* color: [255, 0, 0],
|
|
769
|
+
* dir: 'rtl',
|
|
770
|
+
* speed: 0.5
|
|
771
|
+
* })
|
|
772
|
+
*/
|
|
773
|
+
setShimmer(config) {
|
|
774
|
+
this.#shimmer = {
|
|
775
|
+
color: config.color,
|
|
776
|
+
currentDir: import_text_shimmer.DIR_LTR,
|
|
777
|
+
mode: config.dir,
|
|
778
|
+
speed: config.speed,
|
|
779
|
+
step: 0
|
|
780
|
+
};
|
|
781
|
+
this.#shimmerSavedConfig = this.#shimmer;
|
|
782
|
+
this.#updateSpinnerText();
|
|
783
|
+
return this;
|
|
784
|
+
}
|
|
785
|
+
/**
|
|
786
|
+
* Update partial shimmer configuration.
|
|
787
|
+
* Merges with existing config, enabling shimmer if currently disabled.
|
|
788
|
+
*
|
|
789
|
+
* @param config - Partial shimmer configuration to merge
|
|
790
|
+
* @returns This spinner for chaining
|
|
791
|
+
*
|
|
792
|
+
* @example
|
|
793
|
+
* // Update just the speed
|
|
794
|
+
* spinner.updateShimmer({ speed: 0.5 })
|
|
795
|
+
*
|
|
796
|
+
* // Update direction
|
|
797
|
+
* spinner.updateShimmer({ dir: 'rtl' })
|
|
798
|
+
*
|
|
799
|
+
* // Update multiple properties
|
|
800
|
+
* spinner.updateShimmer({ color: [255, 0, 0], speed: 0.8 })
|
|
801
|
+
*/
|
|
802
|
+
updateShimmer(config) {
|
|
803
|
+
const partialConfig = {
|
|
804
|
+
__proto__: null,
|
|
805
|
+
...config
|
|
806
|
+
};
|
|
807
|
+
if (this.#shimmer) {
|
|
808
|
+
this.#shimmer = {
|
|
809
|
+
...this.#shimmer,
|
|
810
|
+
...partialConfig.color !== void 0 ? { color: partialConfig.color } : {},
|
|
811
|
+
...partialConfig.dir !== void 0 ? { mode: partialConfig.dir } : {},
|
|
812
|
+
...partialConfig.speed !== void 0 ? { speed: partialConfig.speed } : {}
|
|
813
|
+
};
|
|
814
|
+
this.#shimmerSavedConfig = this.#shimmer;
|
|
815
|
+
} else if (this.#shimmerSavedConfig) {
|
|
816
|
+
this.#shimmer = {
|
|
817
|
+
...this.#shimmerSavedConfig,
|
|
818
|
+
...partialConfig.color !== void 0 ? { color: partialConfig.color } : {},
|
|
819
|
+
...partialConfig.dir !== void 0 ? { mode: partialConfig.dir } : {},
|
|
820
|
+
...partialConfig.speed !== void 0 ? { speed: partialConfig.speed } : {}
|
|
821
|
+
};
|
|
822
|
+
this.#shimmerSavedConfig = this.#shimmer;
|
|
823
|
+
} else {
|
|
824
|
+
this.#shimmer = {
|
|
825
|
+
color: partialConfig.color ?? import_text_shimmer.COLOR_INHERIT,
|
|
826
|
+
currentDir: import_text_shimmer.DIR_LTR,
|
|
827
|
+
mode: partialConfig.dir ?? import_text_shimmer.DIR_LTR,
|
|
828
|
+
speed: partialConfig.speed ?? 1 / 3,
|
|
829
|
+
step: 0
|
|
830
|
+
};
|
|
831
|
+
this.#shimmerSavedConfig = this.#shimmer;
|
|
832
|
+
}
|
|
833
|
+
this.#updateSpinnerText();
|
|
834
|
+
return this;
|
|
835
|
+
}
|
|
836
|
+
};
|
|
837
|
+
Object.defineProperties(_Spinner.prototype, {
|
|
838
|
+
error: desc(_Spinner.prototype.fail),
|
|
839
|
+
errorAndStop: desc(_Spinner.prototype.failAndStop),
|
|
840
|
+
warning: desc(_Spinner.prototype.warn),
|
|
841
|
+
warningAndStop: desc(_Spinner.prototype.warnAndStop)
|
|
842
|
+
});
|
|
843
|
+
_defaultSpinner = (0, import_ci.getCI)() ? ciSpinner : /* @__PURE__ */ getCliSpinners("socket");
|
|
844
|
+
}
|
|
845
|
+
return new _Spinner({
|
|
846
|
+
spinner: _defaultSpinner,
|
|
847
|
+
...options
|
|
848
|
+
});
|
|
849
|
+
}
|
|
850
|
+
let _spinner;
|
|
851
|
+
function getDefaultSpinner() {
|
|
852
|
+
if (_spinner === void 0) {
|
|
853
|
+
_spinner = /* @__PURE__ */ Spinner();
|
|
854
|
+
}
|
|
855
|
+
return _spinner;
|
|
856
|
+
}
|
|
857
|
+
async function withSpinner(options) {
|
|
858
|
+
const { message, operation, spinner, withOptions } = {
|
|
859
|
+
__proto__: null,
|
|
860
|
+
...options
|
|
861
|
+
};
|
|
862
|
+
if (!spinner) {
|
|
863
|
+
return await operation();
|
|
864
|
+
}
|
|
865
|
+
const savedColor = withOptions?.color !== void 0 ? spinner.color : void 0;
|
|
866
|
+
const savedShimmerState = withOptions?.shimmer !== void 0 ? spinner.shimmerState : void 0;
|
|
867
|
+
if (withOptions?.color !== void 0) {
|
|
868
|
+
spinner.color = toRgb(withOptions.color);
|
|
869
|
+
}
|
|
870
|
+
if (withOptions?.shimmer !== void 0) {
|
|
871
|
+
if (typeof withOptions.shimmer === "string") {
|
|
872
|
+
spinner.updateShimmer({ dir: withOptions.shimmer });
|
|
873
|
+
} else {
|
|
874
|
+
spinner.setShimmer(withOptions.shimmer);
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
spinner.start(message);
|
|
878
|
+
try {
|
|
879
|
+
return await operation();
|
|
880
|
+
} finally {
|
|
881
|
+
spinner.stop();
|
|
882
|
+
if (savedColor !== void 0) {
|
|
883
|
+
spinner.color = savedColor;
|
|
884
|
+
}
|
|
885
|
+
if (withOptions?.shimmer !== void 0) {
|
|
886
|
+
if (savedShimmerState) {
|
|
887
|
+
spinner.setShimmer({
|
|
888
|
+
color: savedShimmerState.color,
|
|
889
|
+
dir: savedShimmerState.mode,
|
|
890
|
+
speed: savedShimmerState.speed
|
|
891
|
+
});
|
|
892
|
+
} else {
|
|
893
|
+
spinner.disableShimmer();
|
|
894
|
+
}
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
async function withSpinnerRestore(options) {
|
|
899
|
+
const { operation, spinner, wasSpinning } = {
|
|
900
|
+
__proto__: null,
|
|
901
|
+
...options
|
|
902
|
+
};
|
|
903
|
+
try {
|
|
904
|
+
return await operation();
|
|
905
|
+
} finally {
|
|
906
|
+
if (spinner && wasSpinning) {
|
|
907
|
+
spinner.start();
|
|
908
|
+
}
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
function withSpinnerSync(options) {
|
|
912
|
+
const { message, operation, spinner, withOptions } = {
|
|
913
|
+
__proto__: null,
|
|
914
|
+
...options
|
|
915
|
+
};
|
|
916
|
+
if (!spinner) {
|
|
917
|
+
return operation();
|
|
918
|
+
}
|
|
919
|
+
const savedColor = withOptions?.color !== void 0 ? spinner.color : void 0;
|
|
920
|
+
const savedShimmerState = withOptions?.shimmer !== void 0 ? spinner.shimmerState : void 0;
|
|
921
|
+
if (withOptions?.color !== void 0) {
|
|
922
|
+
spinner.color = toRgb(withOptions.color);
|
|
923
|
+
}
|
|
924
|
+
if (withOptions?.shimmer !== void 0) {
|
|
925
|
+
if (typeof withOptions.shimmer === "string") {
|
|
926
|
+
spinner.updateShimmer({ dir: withOptions.shimmer });
|
|
927
|
+
} else {
|
|
928
|
+
spinner.setShimmer(withOptions.shimmer);
|
|
929
|
+
}
|
|
930
|
+
}
|
|
931
|
+
spinner.start(message);
|
|
932
|
+
try {
|
|
933
|
+
return operation();
|
|
934
|
+
} finally {
|
|
935
|
+
spinner.stop();
|
|
936
|
+
if (savedColor !== void 0) {
|
|
937
|
+
spinner.color = savedColor;
|
|
938
|
+
}
|
|
939
|
+
if (withOptions?.shimmer !== void 0) {
|
|
940
|
+
if (savedShimmerState) {
|
|
941
|
+
spinner.setShimmer({
|
|
942
|
+
color: savedShimmerState.color,
|
|
943
|
+
dir: savedShimmerState.mode,
|
|
944
|
+
speed: savedShimmerState.speed
|
|
945
|
+
});
|
|
946
|
+
} else {
|
|
947
|
+
spinner.disableShimmer();
|
|
948
|
+
}
|
|
949
|
+
}
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
953
|
+
0 && (module.exports = {
|
|
954
|
+
Spinner,
|
|
955
|
+
ciSpinner,
|
|
956
|
+
getCliSpinners,
|
|
957
|
+
getDefaultSpinner,
|
|
958
|
+
toRgb,
|
|
959
|
+
withSpinner,
|
|
960
|
+
withSpinnerRestore,
|
|
961
|
+
withSpinnerSync
|
|
962
|
+
});
|
|
3
963
|
//# sourceMappingURL=spinner.js.map
|