storybook 9.0.11 → 9.0.12

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.
Files changed (35) hide show
  1. package/dist/bin/index.cjs +43 -43
  2. package/dist/bin/index.js +43 -43
  3. package/dist/cli/bin/index.cjs +629 -629
  4. package/dist/cli/bin/index.js +202 -201
  5. package/dist/cli/index.cjs +13788 -13797
  6. package/dist/cli/index.d.ts +712 -15
  7. package/dist/cli/index.js +12364 -12372
  8. package/dist/common/index.cjs +10997 -10888
  9. package/dist/common/index.d.ts +348 -66
  10. package/dist/common/index.js +24318 -24206
  11. package/dist/components/index.cjs +5 -3
  12. package/dist/components/index.d.ts +2 -1
  13. package/dist/components/index.js +5 -3
  14. package/dist/core-server/index.cjs +4838 -4791
  15. package/dist/core-server/index.d.ts +10 -1
  16. package/dist/core-server/index.js +5746 -5699
  17. package/dist/core-server/presets/common-manager.js +257 -243
  18. package/dist/core-server/presets/common-preset.cjs +1047 -1045
  19. package/dist/core-server/presets/common-preset.js +2053 -2048
  20. package/dist/csf-tools/index.cjs +226 -224
  21. package/dist/csf-tools/index.js +116 -112
  22. package/dist/manager/globals-runtime.js +6 -4
  23. package/dist/manager-api/index.cjs +73 -73
  24. package/dist/manager-api/index.js +140 -140
  25. package/dist/node-logger/index.cjs +8520 -994
  26. package/dist/node-logger/index.d.ts +395 -2
  27. package/dist/node-logger/index.js +8535 -995
  28. package/dist/server-errors.cjs +201 -242
  29. package/dist/server-errors.d.ts +1 -12
  30. package/dist/server-errors.js +182 -223
  31. package/dist/telemetry/index.cjs +1224 -1223
  32. package/dist/telemetry/index.d.ts +3 -2
  33. package/dist/telemetry/index.js +1069 -1066
  34. package/dist/types/index.d.ts +3 -3
  35. package/package.json +2 -1
@@ -1,5 +1,8 @@
1
1
  /// <reference types="node" />
2
2
  import { EventEmitter } from 'events';
3
+ import { Buffer } from 'node:buffer';
4
+ import { ChildProcess } from 'node:child_process';
5
+ import { Readable, Writable } from 'node:stream';
3
6
 
4
7
  declare namespace npmlog {
5
8
  // TODO: newStream, newGroup, setGaugeTemplate and setGaugeTemplateSet need to be added
@@ -81,6 +84,375 @@ declare namespace npmlog {
81
84
 
82
85
  declare var npmlog: npmlog.Logger;
83
86
 
87
+ /** Detects URLs in text and prevents them from being broken across lines */
88
+ declare function protectUrls(text: string, options?: {
89
+ maxUrlLength?: number;
90
+ maxLineWidth?: number;
91
+ }): string;
92
+ /**
93
+ * Creates a hyperlink with custom title text if supported, otherwise falls back to "title: url"
94
+ * format
95
+ */
96
+ declare function createHyperlink(title: string, url: string): string;
97
+ declare function wrapTextForClack(text: string, width?: number): string;
98
+
99
+ type LogLevel = 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'silent';
100
+
101
+ type Primitive = Readonly<string | boolean | number>;
102
+ type Option<T> = T extends Primitive ? {
103
+ value: T;
104
+ label?: string;
105
+ hint?: string;
106
+ } : {
107
+ value: T;
108
+ label: string;
109
+ hint?: string;
110
+ };
111
+ interface BasePromptOptions {
112
+ message: string;
113
+ }
114
+ interface TextPromptOptions extends BasePromptOptions {
115
+ placeholder?: string;
116
+ initialValue?: string;
117
+ validate?: (value: string) => string | Error | undefined;
118
+ }
119
+ interface ConfirmPromptOptions extends BasePromptOptions {
120
+ initialValue?: boolean;
121
+ active?: string;
122
+ inactive?: string;
123
+ }
124
+ interface SelectPromptOptions<T> extends BasePromptOptions {
125
+ options: Option<T>[];
126
+ initialValue?: T;
127
+ }
128
+ interface MultiSelectPromptOptions<T> extends BasePromptOptions {
129
+ options: Option<T>[];
130
+ initialValues?: T[];
131
+ required?: boolean;
132
+ }
133
+ interface PromptOptions {
134
+ onCancel?: () => void;
135
+ }
136
+ interface SpinnerInstance {
137
+ start: (message?: string) => void;
138
+ stop: (message?: string) => void;
139
+ message: (text: string) => void;
140
+ }
141
+ interface TaskLogInstance {
142
+ message: (text: string) => void;
143
+ success: (message: string, options?: {
144
+ showLog?: boolean;
145
+ }) => void;
146
+ error: (message: string) => void;
147
+ }
148
+ interface SpinnerOptions {
149
+ /** The id of the task, to be used by the log tracker. */
150
+ id: string;
151
+ }
152
+ interface TaskLogOptions {
153
+ /** The id of the task, to be used by the log tracker. */
154
+ id: string;
155
+ title: string;
156
+ retainLog?: boolean;
157
+ limit?: number;
158
+ }
159
+ declare abstract class PromptProvider {
160
+ abstract text(options: TextPromptOptions, promptOptions?: PromptOptions): Promise<string>;
161
+ abstract confirm(options: ConfirmPromptOptions, promptOptions?: PromptOptions): Promise<boolean>;
162
+ abstract select<T>(options: SelectPromptOptions<T>, promptOptions?: PromptOptions): Promise<T>;
163
+ abstract multiselect<T>(options: MultiSelectPromptOptions<T>, promptOptions?: PromptOptions): Promise<T[]>;
164
+ abstract spinner(options: SpinnerOptions): SpinnerInstance;
165
+ abstract taskLog(options: TaskLogOptions): TaskLogInstance;
166
+ }
167
+
168
+ type StdoutStderrAll = string | Buffer | undefined;
169
+
170
+ type ExecaReturnBase<StdoutStderrType extends StdoutStderrAll> = {
171
+ /**
172
+ The file and arguments that were run, for logging purposes.
173
+
174
+ This is not escaped and should not be executed directly as a process, including using `execa()` or `execaCommand()`.
175
+ */
176
+ command: string;
177
+
178
+ /**
179
+ Same as `command` but escaped.
180
+
181
+ This is meant to be copy and pasted into a shell, for debugging purposes.
182
+ Since the escaping is fairly basic, this should not be executed directly as a process, including using `execa()` or `execaCommand()`.
183
+ */
184
+ escapedCommand: string;
185
+
186
+ /**
187
+ The numeric exit code of the process that was run.
188
+ */
189
+ exitCode: number;
190
+
191
+ /**
192
+ The output of the process on stdout.
193
+ */
194
+ stdout: StdoutStderrType;
195
+
196
+ /**
197
+ The output of the process on stderr.
198
+ */
199
+ stderr: StdoutStderrType;
200
+
201
+ /**
202
+ Whether the process failed to run.
203
+ */
204
+ failed: boolean;
205
+
206
+ /**
207
+ Whether the process timed out.
208
+ */
209
+ timedOut: boolean;
210
+
211
+ /**
212
+ Whether the process was killed.
213
+ */
214
+ killed: boolean;
215
+
216
+ /**
217
+ The name of the signal that was used to terminate the process. For example, `SIGFPE`.
218
+
219
+ If a signal terminated the process, this property is defined and included in the error message. Otherwise it is `undefined`.
220
+ */
221
+ signal?: string;
222
+
223
+ /**
224
+ A human-friendly description of the signal that was used to terminate the process. For example, `Floating point arithmetic error`.
225
+
226
+ If a signal terminated the process, this property is defined and included in the error message. Otherwise it is `undefined`. It is also `undefined` when the signal is very uncommon which should seldomly happen.
227
+ */
228
+ signalDescription?: string;
229
+
230
+ /**
231
+ The `cwd` of the command if provided in the command options. Otherwise it is `process.cwd()`.
232
+ */
233
+ cwd: string;
234
+ };
235
+
236
+ type ExecaSyncReturnValue<StdoutStderrType extends StdoutStderrAll = string> = {
237
+ } & ExecaReturnBase<StdoutStderrType>;
238
+
239
+ /**
240
+ Result of a child process execution. On success this is a plain object. On failure this is also an `Error` instance.
241
+
242
+ The child process fails when:
243
+ - its exit code is not `0`
244
+ - it was killed with a signal
245
+ - timing out
246
+ - being canceled
247
+ - there's not enough memory or there are already too many child processes
248
+ */
249
+ type ExecaReturnValue<StdoutStderrType extends StdoutStderrAll = string> = {
250
+ /**
251
+ The output of the process with `stdout` and `stderr` interleaved.
252
+
253
+ This is `undefined` if either:
254
+ - the `all` option is `false` (default value)
255
+ - `execaSync()` was used
256
+ */
257
+ all?: StdoutStderrType;
258
+
259
+ /**
260
+ Whether the process was canceled.
261
+
262
+ You can cancel the spawned process using the [`signal`](https://github.com/sindresorhus/execa#signal-1) option.
263
+ */
264
+ isCanceled: boolean;
265
+ } & ExecaSyncReturnValue<StdoutStderrType>;
266
+
267
+ type ExecaSyncError<StdoutStderrType extends StdoutStderrAll = string> = {
268
+ /**
269
+ Error message when the child process failed to run. In addition to the underlying error message, it also contains some information related to why the child process errored.
270
+
271
+ The child process stderr then stdout are appended to the end, separated with newlines and not interleaved.
272
+ */
273
+ message: string;
274
+
275
+ /**
276
+ This is the same as the `message` property except it does not include the child process stdout/stderr.
277
+ */
278
+ shortMessage: string;
279
+
280
+ /**
281
+ Original error message. This is the same as the `message` property except it includes neither the child process stdout/stderr nor some additional information added by Execa.
282
+
283
+ This is `undefined` unless the child process exited due to an `error` event or a timeout.
284
+ */
285
+ originalMessage?: string;
286
+ } & Error & ExecaReturnBase<StdoutStderrType>;
287
+
288
+ type ExecaError<StdoutStderrType extends StdoutStderrAll = string> = {
289
+ /**
290
+ The output of the process with `stdout` and `stderr` interleaved.
291
+
292
+ This is `undefined` if either:
293
+ - the `all` option is `false` (default value)
294
+ - `execaSync()` was used
295
+ */
296
+ all?: StdoutStderrType;
297
+
298
+ /**
299
+ Whether the process was canceled.
300
+ */
301
+ isCanceled: boolean;
302
+ } & ExecaSyncError<StdoutStderrType>;
303
+
304
+ type KillOptions = {
305
+ /**
306
+ Milliseconds to wait for the child process to terminate before sending `SIGKILL`.
307
+
308
+ Can be disabled with `false`.
309
+
310
+ @default 5000
311
+ */
312
+ forceKillAfterTimeout?: number | false;
313
+ };
314
+
315
+ type ExecaChildPromise<StdoutStderrType extends StdoutStderrAll> = {
316
+ /**
317
+ Stream combining/interleaving [`stdout`](https://nodejs.org/api/child_process.html#child_process_subprocess_stdout) and [`stderr`](https://nodejs.org/api/child_process.html#child_process_subprocess_stderr).
318
+
319
+ This is `undefined` if either:
320
+ - the `all` option is `false` (the default value)
321
+ - both `stdout` and `stderr` options are set to [`'inherit'`, `'ipc'`, `Stream` or `integer`](https://nodejs.org/dist/latest-v6.x/docs/api/child_process.html#child_process_options_stdio)
322
+ */
323
+ all?: Readable;
324
+
325
+ catch<ResultType = never>(
326
+ onRejected?: (reason: ExecaError<StdoutStderrType>) => ResultType | PromiseLike<ResultType>
327
+ ): Promise<ExecaReturnValue<StdoutStderrType> | ResultType>;
328
+
329
+ /**
330
+ Same as the original [`child_process#kill()`](https://nodejs.org/api/child_process.html#child_process_subprocess_kill_signal), except if `signal` is `SIGTERM` (the default value) and the child process is not terminated after 5 seconds, force it by sending `SIGKILL`. Note that this graceful termination does not work on Windows, because Windows [doesn't support signals](https://nodejs.org/api/process.html#process_signal_events) (`SIGKILL` and `SIGTERM` has the same effect of force-killing the process immediately.) If you want to achieve graceful termination on Windows, you have to use other means, such as [`taskkill`](https://github.com/sindresorhus/taskkill).
331
+ */
332
+ kill(signal?: string, options?: KillOptions): void;
333
+
334
+ /**
335
+ Similar to [`childProcess.kill()`](https://nodejs.org/api/child_process.html#child_process_subprocess_kill_signal). This used to be preferred when cancelling the child process execution as the error is more descriptive and [`childProcessResult.isCanceled`](#iscanceled) is set to `true`. But now this is deprecated and you should either use `.kill()` or the `signal` option when creating the child process.
336
+ */
337
+ cancel(): void;
338
+
339
+ /**
340
+ [Pipe](https://nodejs.org/api/stream.html#readablepipedestination-options) the child process's `stdout` to `target`, which can be:
341
+ - Another `execa()` return value
342
+ - A writable stream
343
+ - A file path string
344
+
345
+ If the `target` is another `execa()` return value, it is returned. Otherwise, the original `execa()` return value is returned. This allows chaining `pipeStdout()` then `await`ing the final result.
346
+
347
+ The `stdout` option] must be kept as `pipe`, its default value.
348
+ */
349
+ pipeStdout?<Target extends ExecaChildPromise<StdoutStderrAll>>(target: Target): Target;
350
+ pipeStdout?(target: Writable | string): ExecaChildProcess<StdoutStderrType>;
351
+
352
+ /**
353
+ Like `pipeStdout()` but piping the child process's `stderr` instead.
354
+
355
+ The `stderr` option must be kept as `pipe`, its default value.
356
+ */
357
+ pipeStderr?<Target extends ExecaChildPromise<StdoutStderrAll>>(target: Target): Target;
358
+ pipeStderr?(target: Writable | string): ExecaChildProcess<StdoutStderrType>;
359
+
360
+ /**
361
+ Combines both `pipeStdout()` and `pipeStderr()`.
362
+
363
+ Either the `stdout` option or the `stderr` option must be kept as `pipe`, their default value. Also, the `all` option must be set to `true`.
364
+ */
365
+ pipeAll?<Target extends ExecaChildPromise<StdoutStderrAll>>(target: Target): Target;
366
+ pipeAll?(target: Writable | string): ExecaChildProcess<StdoutStderrType>;
367
+ };
368
+
369
+ type ExecaChildProcess<StdoutStderrType extends StdoutStderrAll = string> = ChildProcess &
370
+ ExecaChildPromise<StdoutStderrType> &
371
+ Promise<ExecaReturnValue<StdoutStderrType>>;
372
+
373
+ declare const prompt: {
374
+ executeTask: (childProcessFactories: (() => ExecaChildProcess) | (() => ExecaChildProcess)[], { id, intro, error, success, limitLines, }: {
375
+ id: string;
376
+ intro: string;
377
+ error: string;
378
+ success: string;
379
+ limitLines?: number;
380
+ }) => Promise<void>;
381
+ executeTaskWithSpinner: (childProcessFactories: (() => ExecaChildProcess) | (() => ExecaChildProcess)[], { id, intro, error, success }: {
382
+ id: string;
383
+ intro: string;
384
+ error: string;
385
+ success: string;
386
+ }) => Promise<void>;
387
+ setPromptLibrary: (library: "clack" | "prompts") => void;
388
+ getPromptLibrary: () => "clack" | "prompts";
389
+ getPromptProvider: () => PromptProvider;
390
+ isClackEnabled: () => boolean;
391
+ isPromptsEnabled: () => boolean;
392
+ getPreferredStdio: () => "inherit" | "pipe";
393
+ text: (options: TextPromptOptions, promptOptions?: PromptOptions) => Promise<string>;
394
+ confirm: (options: ConfirmPromptOptions, promptOptions?: PromptOptions) => Promise<boolean>;
395
+ select: <T>(options: SelectPromptOptions<T>, promptOptions?: PromptOptions) => Promise<T>;
396
+ multiselect: <T>(options: MultiSelectPromptOptions<T>, promptOptions?: PromptOptions) => Promise<T[]>;
397
+ spinner: (options: SpinnerOptions) => SpinnerInstance;
398
+ taskLog: (options: TaskLogOptions) => TaskLogInstance;
399
+ };
400
+
401
+ type Metadata = Record<string, any>;
402
+ interface LogEntry {
403
+ timestamp: Date;
404
+ level: LogLevel | 'prompt';
405
+ message: string;
406
+ metadata?: Metadata;
407
+ }
408
+ /**
409
+ * Tracks and manages logs for Storybook CLI operations. Provides functionality to collect, store
410
+ * and write logs to a file.
411
+ */
412
+ declare class LogTracker {
413
+ #private;
414
+ constructor();
415
+ /** Enables writing logs to file. */
416
+ enableLogWriting(): void;
417
+ /** Returns whether logs should be written to file. */
418
+ get shouldWriteLogsToFile(): boolean;
419
+ /** Returns the configured log file path. */
420
+ get logFilePath(): string;
421
+ /** Returns a copy of all stored logs. */
422
+ get logs(): LogEntry[];
423
+ /**
424
+ * Adds a new log entry.
425
+ *
426
+ * @param level - The log level
427
+ * @param message - The log message
428
+ * @param metadata - Optional metadata to attach to the log, can be any JSON serializable value
429
+ */
430
+ addLog(level: LogEntry['level'], message: string, metadata?: Metadata): void;
431
+ /** Clears all stored logs. */
432
+ clear(): void;
433
+ /**
434
+ * Writes all stored logs to a file and clears the log store.
435
+ *
436
+ * @param filePath - Optional custom file path to write logs to
437
+ * @returns The path where logs were written, by default is debug-storybook.log in current working
438
+ * directory
439
+ */
440
+ writeToFile(filePath?: string): Promise<string>;
441
+ }
442
+ declare const logTracker: LogTracker;
443
+
444
+ type Formatter = (input: string | number | null | undefined) => string
445
+
446
+ declare const CLI_COLORS: {
447
+ success: Formatter;
448
+ error: Formatter;
449
+ warning: Formatter;
450
+ info: Formatter;
451
+ debug: Formatter;
452
+ cta: Formatter;
453
+ };
454
+
455
+ /** @deprecated Use CLI_COLORS instead */
84
456
  declare const colors: {
85
457
  pink: (text: string) => string;
86
458
  purple: (text: string) => string;
@@ -100,8 +472,29 @@ declare const logger: {
100
472
  message: string;
101
473
  time: [number, number];
102
474
  }) => void;
103
- setLevel: (level?: string) => void;
475
+ setLevel: (level?: LogLevel) => void;
104
476
  error: (message: Error | string) => void;
477
+ setLogLevel: (level: LogLevel) => void;
478
+ getLogLevel: () => LogLevel;
479
+ shouldLog: (level: LogLevel) => boolean;
480
+ debug: (...args: any[]) => void;
481
+ log: (...args: any[]) => void;
482
+ logBox: (message: string, options?: {
483
+ borderStyle?: "round" | "none";
484
+ padding?: number;
485
+ title?: string;
486
+ titleAlignment?: "left" | "center" | "right";
487
+ borderColor?: string;
488
+ backgroundColor?: string;
489
+ }) => void;
490
+ intro: (message: string) => void;
491
+ outro: (message: string) => void;
492
+ step: (message: string) => void;
493
+ SYMBOLS: {
494
+ success: string;
495
+ error: string;
496
+ };
497
+ wrapTextForClack: typeof wrapTextForClack;
105
498
  };
106
499
 
107
500
  declare const once: {
@@ -114,4 +507,4 @@ declare const once: {
114
507
  };
115
508
  declare const deprecate: (message: string) => void;
116
509
 
117
- export { colors, deprecate, npmlog as instance, logger, once };
510
+ export { CLI_COLORS, type SpinnerInstance, type TaskLogInstance, colors, createHyperlink, deprecate, npmlog as instance, logTracker, logger, once, prompt, protectUrls };