storybook 9.1.0-alpha.0 → 9.1.0-alpha.10

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 (112) hide show
  1. package/assets/browser/favicon-wrapper.svg +46 -0
  2. package/assets/browser/favicon.svg +1 -1
  3. package/dist/actions/index.cjs +16 -16
  4. package/dist/actions/index.d.ts +1 -38
  5. package/dist/actions/index.js +12 -12
  6. package/dist/bin/index.cjs +62 -69
  7. package/dist/bin/index.js +43 -50
  8. package/dist/builder-manager/index.cjs +379 -378
  9. package/dist/builder-manager/index.d.ts +567 -2
  10. package/dist/builder-manager/index.js +280 -279
  11. package/dist/cli/bin/index.cjs +945 -945
  12. package/dist/cli/bin/index.js +673 -672
  13. package/dist/cli/index.cjs +14965 -14973
  14. package/dist/cli/index.d.ts +713 -15
  15. package/dist/cli/index.js +13488 -13495
  16. package/dist/common/index.cjs +11211 -11103
  17. package/dist/common/index.d.ts +351 -72
  18. package/dist/common/index.js +18491 -18379
  19. package/dist/components/index.cjs +4606 -4425
  20. package/dist/components/index.d.ts +11 -12
  21. package/dist/components/index.js +3020 -2834
  22. package/dist/controls/index.cjs +16 -16
  23. package/dist/controls/index.d.ts +1 -36
  24. package/dist/core-server/index.cjs +6690 -6624
  25. package/dist/core-server/index.d.ts +14 -2
  26. package/dist/core-server/index.js +6088 -6023
  27. package/dist/core-server/presets/common-manager.js +3582 -3475
  28. package/dist/core-server/presets/common-preset.cjs +85015 -5213
  29. package/dist/core-server/presets/common-preset.js +85107 -5291
  30. package/dist/core-server/presets/webpack/loaders/storybook-mock-transform-loader.cjs +28728 -0
  31. package/dist/core-server/presets/webpack/loaders/storybook-mock-transform-loader.js +28729 -0
  32. package/dist/core-server/presets/webpack/loaders/webpack-automock-loader.cjs +29339 -0
  33. package/dist/core-server/presets/webpack/loaders/webpack-automock-loader.js +29340 -0
  34. package/dist/csf/index.cjs +3019 -104
  35. package/dist/csf/index.d.ts +301 -18
  36. package/dist/csf/index.js +3031 -98
  37. package/dist/csf-tools/index.cjs +489 -488
  38. package/dist/csf-tools/index.js +311 -309
  39. package/dist/highlight/index.cjs +15 -15
  40. package/dist/highlight/index.d.ts +1 -12
  41. package/dist/highlight/index.js +4 -4
  42. package/dist/instrumenter/index.cjs +1308 -1239
  43. package/dist/instrumenter/index.d.ts +25 -3
  44. package/dist/instrumenter/index.js +1345 -1280
  45. package/dist/manager/globals-module-info.cjs +1 -1
  46. package/dist/manager/globals-module-info.js +1 -1
  47. package/dist/manager/globals-runtime.js +42257 -44665
  48. package/dist/manager/runtime.js +3715 -3536
  49. package/dist/manager-api/index.cjs +74 -74
  50. package/dist/manager-api/index.d.ts +4 -1
  51. package/dist/manager-api/index.js +142 -142
  52. package/dist/node-logger/index.cjs +8520 -994
  53. package/dist/node-logger/index.d.ts +395 -2
  54. package/dist/node-logger/index.js +8535 -995
  55. package/dist/preview/runtime.js +13701 -16331
  56. package/dist/preview-api/index.cjs +1434 -1458
  57. package/dist/preview-api/index.d.ts +13 -10
  58. package/dist/preview-api/index.js +950 -976
  59. package/dist/server-errors.cjs +201 -242
  60. package/dist/server-errors.d.ts +1 -12
  61. package/dist/server-errors.js +182 -223
  62. package/dist/telemetry/index.cjs +1919 -1638
  63. package/dist/telemetry/index.d.ts +4 -2
  64. package/dist/telemetry/index.js +1972 -1690
  65. package/dist/test/index.cjs +9184 -9816
  66. package/dist/test/index.d.ts +8 -1
  67. package/dist/test/index.js +8390 -9029
  68. package/dist/types/index.d.ts +19 -17
  69. package/dist/viewport/index.cjs +17 -24
  70. package/dist/viewport/index.d.ts +9 -532
  71. package/dist/viewport/index.js +9 -16
  72. package/package.json +18 -187
  73. package/templates/mocker-runtime.template.js +89 -0
  74. package/dist/actions/preview.cjs +0 -159
  75. package/dist/actions/preview.d.ts +0 -555
  76. package/dist/actions/preview.js +0 -149
  77. package/dist/backgrounds/index.cjs +0 -148
  78. package/dist/backgrounds/index.d.ts +0 -592
  79. package/dist/backgrounds/index.js +0 -130
  80. package/dist/backgrounds/preview.cjs +0 -143
  81. package/dist/backgrounds/preview.d.ts +0 -555
  82. package/dist/backgrounds/preview.js +0 -127
  83. package/dist/component-testing/index.cjs +0 -23
  84. package/dist/component-testing/index.d.ts +0 -3
  85. package/dist/component-testing/index.js +0 -5
  86. package/dist/component-testing/preview.cjs +0 -40
  87. package/dist/component-testing/preview.d.ts +0 -5
  88. package/dist/component-testing/preview.js +0 -25
  89. package/dist/controls/preview.cjs +0 -26
  90. package/dist/controls/preview.d.ts +0 -555
  91. package/dist/controls/preview.js +0 -9
  92. package/dist/highlight/preview.cjs +0 -590
  93. package/dist/highlight/preview.d.ts +0 -555
  94. package/dist/highlight/preview.js +0 -574
  95. package/dist/measure/index.cjs +0 -476
  96. package/dist/measure/index.d.ts +0 -567
  97. package/dist/measure/index.js +0 -464
  98. package/dist/measure/preview.cjs +0 -466
  99. package/dist/measure/preview.d.ts +0 -560
  100. package/dist/measure/preview.js +0 -450
  101. package/dist/outline/index.cjs +0 -528
  102. package/dist/outline/index.d.ts +0 -567
  103. package/dist/outline/index.js +0 -500
  104. package/dist/outline/preview.cjs +0 -518
  105. package/dist/outline/preview.d.ts +0 -560
  106. package/dist/outline/preview.js +0 -486
  107. package/dist/test/preview.cjs +0 -73
  108. package/dist/test/preview.d.ts +0 -555
  109. package/dist/test/preview.js +0 -66
  110. package/dist/viewport/preview.cjs +0 -35
  111. package/dist/viewport/preview.d.ts +0 -569
  112. package/dist/viewport/preview.js +0 -19
@@ -2,24 +2,19 @@ import * as storybook_internal_types from 'storybook/internal/types';
2
2
  import { PresetConfig, CoreCommon_ResolvedAddonPreset, CoreCommon_ResolvedAddonVirtual, CLIOptions, LoadOptions, BuilderOptions, StorybookConfigRaw, LoadedPreset, Presets, PackageJson, CoreCommon_AddonInfo, SupportedFrameworks, SupportedRenderers, Options as Options$1, CoreCommon_StorybookInfo, Ref, StorybookConfig, StoriesEntry, NormalizedStoriesSpecifier } from 'storybook/internal/types';
3
3
  export { PackageJson } from 'storybook/internal/types';
4
4
  import { WriteStream } from 'node:fs';
5
- import { Stream } from 'node:stream';
5
+ import { Buffer } from 'node:buffer';
6
+ import { ChildProcess } from 'node:child_process';
7
+ import { Readable, Writable, Stream } from 'node:stream';
6
8
  import { ConfigFile } from 'storybook/internal/csf-tools';
7
9
 
8
10
  declare const _default: {
9
11
  '@storybook/addon-a11y': string;
10
- '@storybook/addon-actions': string;
11
- '@storybook/addon-backgrounds': string;
12
- '@storybook/addon-controls': string;
13
12
  '@storybook/addon-docs': string;
14
13
  '@storybook/addon-jest': string;
15
14
  '@storybook/addon-links': string;
16
- '@storybook/addon-measure': string;
17
15
  '@storybook/addon-onboarding': string;
18
- '@storybook/addon-outline': string;
19
16
  'storybook-addon-pseudo-states': string;
20
17
  '@storybook/addon-themes': string;
21
- '@storybook/addon-toolbars': string;
22
- '@storybook/addon-viewport': string;
23
18
  '@storybook/addon-vitest': string;
24
19
  '@storybook/builder-vite': string;
25
20
  '@storybook/builder-webpack5': string;
@@ -446,6 +441,211 @@ type CommonOptions<EncodingType extends EncodingOption = DefaultEncodingOption>
446
441
  readonly verbose?: boolean;
447
442
  };
448
443
 
444
+ type StdoutStderrAll = string | Buffer | undefined;
445
+
446
+ type ExecaReturnBase<StdoutStderrType extends StdoutStderrAll> = {
447
+ /**
448
+ The file and arguments that were run, for logging purposes.
449
+
450
+ This is not escaped and should not be executed directly as a process, including using `execa()` or `execaCommand()`.
451
+ */
452
+ command: string;
453
+
454
+ /**
455
+ Same as `command` but escaped.
456
+
457
+ This is meant to be copy and pasted into a shell, for debugging purposes.
458
+ Since the escaping is fairly basic, this should not be executed directly as a process, including using `execa()` or `execaCommand()`.
459
+ */
460
+ escapedCommand: string;
461
+
462
+ /**
463
+ The numeric exit code of the process that was run.
464
+ */
465
+ exitCode: number;
466
+
467
+ /**
468
+ The output of the process on stdout.
469
+ */
470
+ stdout: StdoutStderrType;
471
+
472
+ /**
473
+ The output of the process on stderr.
474
+ */
475
+ stderr: StdoutStderrType;
476
+
477
+ /**
478
+ Whether the process failed to run.
479
+ */
480
+ failed: boolean;
481
+
482
+ /**
483
+ Whether the process timed out.
484
+ */
485
+ timedOut: boolean;
486
+
487
+ /**
488
+ Whether the process was killed.
489
+ */
490
+ killed: boolean;
491
+
492
+ /**
493
+ The name of the signal that was used to terminate the process. For example, `SIGFPE`.
494
+
495
+ If a signal terminated the process, this property is defined and included in the error message. Otherwise it is `undefined`.
496
+ */
497
+ signal?: string;
498
+
499
+ /**
500
+ A human-friendly description of the signal that was used to terminate the process. For example, `Floating point arithmetic error`.
501
+
502
+ 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.
503
+ */
504
+ signalDescription?: string;
505
+
506
+ /**
507
+ The `cwd` of the command if provided in the command options. Otherwise it is `process.cwd()`.
508
+ */
509
+ cwd: string;
510
+ };
511
+
512
+ type ExecaSyncReturnValue<StdoutStderrType extends StdoutStderrAll = string> = {
513
+ } & ExecaReturnBase<StdoutStderrType>;
514
+
515
+ /**
516
+ Result of a child process execution. On success this is a plain object. On failure this is also an `Error` instance.
517
+
518
+ The child process fails when:
519
+ - its exit code is not `0`
520
+ - it was killed with a signal
521
+ - timing out
522
+ - being canceled
523
+ - there's not enough memory or there are already too many child processes
524
+ */
525
+ type ExecaReturnValue<StdoutStderrType extends StdoutStderrAll = string> = {
526
+ /**
527
+ The output of the process with `stdout` and `stderr` interleaved.
528
+
529
+ This is `undefined` if either:
530
+ - the `all` option is `false` (default value)
531
+ - `execaSync()` was used
532
+ */
533
+ all?: StdoutStderrType;
534
+
535
+ /**
536
+ Whether the process was canceled.
537
+
538
+ You can cancel the spawned process using the [`signal`](https://github.com/sindresorhus/execa#signal-1) option.
539
+ */
540
+ isCanceled: boolean;
541
+ } & ExecaSyncReturnValue<StdoutStderrType>;
542
+
543
+ type ExecaSyncError<StdoutStderrType extends StdoutStderrAll = string> = {
544
+ /**
545
+ 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.
546
+
547
+ The child process stderr then stdout are appended to the end, separated with newlines and not interleaved.
548
+ */
549
+ message: string;
550
+
551
+ /**
552
+ This is the same as the `message` property except it does not include the child process stdout/stderr.
553
+ */
554
+ shortMessage: string;
555
+
556
+ /**
557
+ 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.
558
+
559
+ This is `undefined` unless the child process exited due to an `error` event or a timeout.
560
+ */
561
+ originalMessage?: string;
562
+ } & Error & ExecaReturnBase<StdoutStderrType>;
563
+
564
+ type ExecaError<StdoutStderrType extends StdoutStderrAll = string> = {
565
+ /**
566
+ The output of the process with `stdout` and `stderr` interleaved.
567
+
568
+ This is `undefined` if either:
569
+ - the `all` option is `false` (default value)
570
+ - `execaSync()` was used
571
+ */
572
+ all?: StdoutStderrType;
573
+
574
+ /**
575
+ Whether the process was canceled.
576
+ */
577
+ isCanceled: boolean;
578
+ } & ExecaSyncError<StdoutStderrType>;
579
+
580
+ type KillOptions = {
581
+ /**
582
+ Milliseconds to wait for the child process to terminate before sending `SIGKILL`.
583
+
584
+ Can be disabled with `false`.
585
+
586
+ @default 5000
587
+ */
588
+ forceKillAfterTimeout?: number | false;
589
+ };
590
+
591
+ type ExecaChildPromise<StdoutStderrType extends StdoutStderrAll> = {
592
+ /**
593
+ 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).
594
+
595
+ This is `undefined` if either:
596
+ - the `all` option is `false` (the default value)
597
+ - 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)
598
+ */
599
+ all?: Readable;
600
+
601
+ catch<ResultType = never>(
602
+ onRejected?: (reason: ExecaError<StdoutStderrType>) => ResultType | PromiseLike<ResultType>
603
+ ): Promise<ExecaReturnValue<StdoutStderrType> | ResultType>;
604
+
605
+ /**
606
+ 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).
607
+ */
608
+ kill(signal?: string, options?: KillOptions): void;
609
+
610
+ /**
611
+ 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.
612
+ */
613
+ cancel(): void;
614
+
615
+ /**
616
+ [Pipe](https://nodejs.org/api/stream.html#readablepipedestination-options) the child process's `stdout` to `target`, which can be:
617
+ - Another `execa()` return value
618
+ - A writable stream
619
+ - A file path string
620
+
621
+ 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.
622
+
623
+ The `stdout` option] must be kept as `pipe`, its default value.
624
+ */
625
+ pipeStdout?<Target extends ExecaChildPromise<StdoutStderrAll>>(target: Target): Target;
626
+ pipeStdout?(target: Writable | string): ExecaChildProcess<StdoutStderrType>;
627
+
628
+ /**
629
+ Like `pipeStdout()` but piping the child process's `stderr` instead.
630
+
631
+ The `stderr` option must be kept as `pipe`, its default value.
632
+ */
633
+ pipeStderr?<Target extends ExecaChildPromise<StdoutStderrAll>>(target: Target): Target;
634
+ pipeStderr?(target: Writable | string): ExecaChildProcess<StdoutStderrType>;
635
+
636
+ /**
637
+ Combines both `pipeStdout()` and `pipeStderr()`.
638
+
639
+ 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`.
640
+ */
641
+ pipeAll?<Target extends ExecaChildPromise<StdoutStderrAll>>(target: Target): Target;
642
+ pipeAll?(target: Writable | string): ExecaChildProcess<StdoutStderrType>;
643
+ };
644
+
645
+ type ExecaChildProcess<StdoutStderrType extends StdoutStderrAll = string> = ChildProcess &
646
+ ExecaChildPromise<StdoutStderrType> &
647
+ Promise<ExecaReturnValue<StdoutStderrType>>;
648
+
449
649
  type PackageJsonWithDepsAndDevDeps = PackageJson & Required<Pick<PackageJson, 'dependencies' | 'devDependencies'>>;
450
650
  type PackageJsonWithMaybeDeps = Partial<Pick<PackageJson, 'dependencies' | 'devDependencies' | 'peerDependencies' | 'files'>>;
451
651
 
@@ -476,36 +676,54 @@ declare const COMMON_ENV_VARS: {
476
676
  declare function getPackageDetails(pkg: string): [string, string?];
477
677
  interface JsPackageManagerOptions {
478
678
  cwd?: string;
679
+ configDir?: string;
680
+ storiesPaths?: string[];
479
681
  }
682
+ type PackageJsonInfo = {
683
+ packageJsonPath: string;
684
+ operationDir: string;
685
+ packageJson: PackageJsonWithDepsAndDevDeps;
686
+ };
480
687
  declare abstract class JsPackageManager {
688
+ #private;
481
689
  abstract readonly type: PackageManagerName;
482
- abstract initPackageJson(): Promise<void>;
483
- abstract getRunStorybookCommand(): string;
484
- abstract getRunCommand(command: string): string;
485
- abstract getRemoteRunCommand(): string;
486
- readonly cwd?: string;
487
- abstract getPackageJSON(packageName: string, basePath?: string): Promise<PackageJson | null>;
488
- /** Get the INSTALLED version of a package from the package.json file */
489
- getPackageVersion(packageName: string, basePath?: string | undefined): Promise<string | null>;
490
- constructor(options?: JsPackageManagerOptions);
690
+ /** The path to the primary package.json file (contains the `storybook` dependency). */
691
+ readonly primaryPackageJson: PackageJsonInfo;
692
+ /** The paths to all package.json files in the project root. */
693
+ packageJsonPaths: string[];
491
694
  /**
492
- * Detect whether Storybook gets initialized in a mono-repository/workspace environment The cwd
493
- * doesn't have to be the root of the monorepo, it can be a subdirectory
494
- *
495
- * @returns `true`, if Storybook is initialized inside a mono-repository/workspace
695
+ * The path to the Storybook instance directory. This is used to find the primary package.json
696
+ * file in a repository.
496
697
  */
497
- isStorybookInMonorepo(): boolean;
498
- /** Install dependencies listed in `package.json` */
499
- installDependencies(): Promise<void>;
500
- packageJsonPath(): string;
501
- readPackageJson(): Promise<PackageJson>;
502
- writePackageJson(packageJson: PackageJson): Promise<void>;
698
+ readonly instanceDir: string;
699
+ /** The current working directory. */
700
+ protected readonly cwd: string;
701
+ /** Cache for latest version results to avoid repeated network calls. */
702
+ static readonly latestVersionCache: Map<string, string | null>;
703
+ /** Cache for installed version results to avoid repeated file system calls. */
704
+ static readonly installedVersionCache: Map<string, string | null>;
705
+ constructor(options?: JsPackageManagerOptions);
706
+ /** Runs arbitrary package scripts. */
707
+ abstract getRunCommand(command: string): string;
503
708
  /**
504
- * Read the `package.json` file available in the directory the command was call from If there is
505
- * no `package.json` it will create one.
709
+ * Run a command from a local or remote. Fetches a package from the registry without installing it
710
+ * as a dependency, hotloads it, and runs whatever default command binary it exposes.
506
711
  */
507
- retrievePackageJson(): Promise<PackageJsonWithDepsAndDevDeps>;
508
- getAllDependencies(): Promise<Partial<Record<string, string>>>;
712
+ abstract getRemoteRunCommand(pkg: string, args: string[], specifier?: string): string;
713
+ /** Get the package.json file for a given module. */
714
+ abstract getModulePackageJSON(packageName: string): PackageJson | null;
715
+ isStorybookInMonorepo(): boolean;
716
+ installDependencies(options?: {
717
+ force?: boolean;
718
+ }): Promise<void>;
719
+ dedupeDependencies(options?: {
720
+ force?: boolean;
721
+ }): Promise<void>;
722
+ /** Read the `package.json` file available in the provided directory */
723
+ static getPackageJson(packageJsonPath: string): PackageJsonWithDepsAndDevDeps;
724
+ writePackageJson(packageJson: PackageJson, directory?: string): void;
725
+ getAllDependencies(): Record<string, string>;
726
+ isDependencyInstalled(dependency: string): boolean;
509
727
  /**
510
728
  * Add dependencies to a project using `yarn add` or `npm install`.
511
729
  *
@@ -523,28 +741,29 @@ declare abstract class JsPackageManager {
523
741
  * @param {Array} dependencies Contains a list of packages to add.
524
742
  */
525
743
  addDependencies(options: {
526
- skipInstall?: boolean;
527
- installAsDevDependencies?: boolean;
528
- packageJson?: PackageJson;
744
+ skipInstall: true;
745
+ type: 'dependencies' | 'devDependencies' | 'peerDependencies';
746
+ writeOutputToFile?: boolean;
747
+ packageJsonInfo?: PackageJsonInfo;
748
+ } | {
749
+ skipInstall?: false;
750
+ type: 'dependencies' | 'devDependencies';
529
751
  writeOutputToFile?: boolean;
530
- }, dependencies: string[]): Promise<void>;
752
+ packageJsonInfo?: PackageJsonInfo;
753
+ }, dependencies: string[]): Promise<void | ExecaChildProcess>;
531
754
  /**
532
- * Remove dependencies from a project using `yarn remove` or `npm uninstall`.
755
+ * Removing dependencies from the package.json file, which is found first starting from the
756
+ * instance root. The method does not run a package manager install like `npm install`.
533
757
  *
534
758
  * @example
535
759
  *
536
760
  * ```ts
537
- * removeDependencies(options, [`@storybook/react`]);
761
+ * removeDependencies([`@storybook/react`]);
538
762
  * ```
539
763
  *
540
- * @param {Object} options Contains `skipInstall`, `packageJson` and `installAsDevDependencies`
541
- * which we use to determine how we install packages.
542
- * @param {Array} dependencies Contains a list of packages to remove.
764
+ * @param dependencies Contains a list of packages to remove.
543
765
  */
544
- removeDependencies(options: {
545
- skipInstall?: boolean;
546
- packageJson?: PackageJson;
547
- }, dependencies: string[]): Promise<void>;
766
+ removeDependencies(dependencies: string[]): Promise<void>;
548
767
  /**
549
768
  * Return an array of strings matching following format: `<package_name>@<package_latest_version>`
550
769
  *
@@ -582,16 +801,36 @@ declare abstract class JsPackageManager {
582
801
  * @param packageName Name of the package
583
802
  * @param constraint Version range to use to constraint the returned version
584
803
  */
585
- latestVersion(packageName: string, constraint?: string): Promise<string>;
804
+ latestVersion(packageName: string, constraint?: string): Promise<string | null>;
805
+ /**
806
+ * Clear the latest version cache. Useful for testing or when you want to refresh version
807
+ * information.
808
+ *
809
+ * @param packageName Optional package name to clear only specific entries. If not provided,
810
+ * clears all cache.
811
+ */
812
+ static clearLatestVersionCache(packageName?: string): void;
813
+ /**
814
+ * Clear the installed version cache for a specific package or all packages.
815
+ *
816
+ * @param packageName Optional package name to clear from cache. If not provided, clears all.
817
+ */
818
+ clearInstalledVersionCache(packageName?: string): void;
819
+ /**
820
+ * Clear both the latest version cache and installed version cache. This should be called after
821
+ * any operation that modifies dependencies.
822
+ */
823
+ clearAllVersionCaches(): void;
586
824
  addStorybookCommandInScripts(options?: {
587
825
  port: number;
588
826
  preCommand?: string;
589
- }): Promise<void>;
590
- addScripts(scripts: Record<string, string>): Promise<void>;
591
- addPackageResolutions(versions: Record<string, string>): Promise<void>;
592
- protected abstract runInstall(): Promise<void>;
593
- protected abstract runAddDeps(dependencies: string[], installAsDevDependencies: boolean, writeOutputToFile?: boolean): Promise<void>;
594
- protected abstract runRemoveDeps(dependencies: string[]): Promise<void>;
827
+ }): void;
828
+ addScripts(scripts: Record<string, string>): void;
829
+ addPackageResolutions(versions: Record<string, string>): void;
830
+ protected abstract runInstall(options?: {
831
+ force?: boolean;
832
+ }): ExecaChildProcess;
833
+ protected abstract runAddDeps(dependencies: string[], installAsDevDependencies: boolean, writeOutputToFile?: boolean): ExecaChildProcess;
595
834
  protected abstract getResolutions(packageJson: PackageJson, versions: Record<string, string>): Record<string, any>;
596
835
  /**
597
836
  * Get the latest or all versions of the input package available on npmjs.com
@@ -601,8 +840,9 @@ declare abstract class JsPackageManager {
601
840
  */
602
841
  protected abstract runGetVersions<T extends boolean>(packageName: string, fetchAllVersions: T): Promise<T extends true ? string[] : string>;
603
842
  abstract getRegistryURL(): Promise<string | undefined>;
604
- abstract runPackageCommand(command: string, args: string[], cwd?: string, stdio?: string): Promise<string>;
605
- abstract runPackageCommandSync(command: string, args: string[], cwd?: string, stdio?: 'inherit' | 'pipe'): string;
843
+ abstract runInternalCommand(command: string, args: string[], cwd?: string, stdio?: 'inherit' | 'pipe' | 'ignore'): ExecaChildProcess;
844
+ abstract runPackageCommand(command: string, args: string[], cwd?: string, stdio?: 'inherit' | 'pipe' | 'ignore'): ExecaChildProcess;
845
+ abstract runPackageCommandSync(command: string, args: string[], cwd?: string, stdio?: 'inherit' | 'pipe' | 'ignore'): string;
606
846
  abstract findInstallations(pattern?: string[]): Promise<InstallationMetadata | undefined>;
607
847
  abstract findInstallations(pattern?: string[], options?: {
608
848
  depth: number;
@@ -614,19 +854,55 @@ declare abstract class JsPackageManager {
614
854
  cwd?: string;
615
855
  ignoreError?: boolean;
616
856
  }): string;
617
- /** Returns the installed (within node_modules or pnp zip) version of a specified package */
618
- getInstalledVersion(packageName: string): Promise<string | null>;
857
+ /**
858
+ * Execute a command asynchronously and return the execa process. This allows you to hook into
859
+ * stdout/stderr streams and monitor the process.
860
+ *
861
+ * @example Const process = packageManager.executeCommand({ command: 'npm', args: ['install'] });
862
+ * process.stdout?.on('data', (data) => console.log(data.toString())); const result = await
863
+ * process;
864
+ */
619
865
  executeCommand({ command, args, stdio, cwd, ignoreError, env, ...execaOptions }: CommonOptions<'utf8'> & {
620
866
  command: string;
621
867
  args: string[];
622
868
  cwd?: string;
623
869
  ignoreError?: boolean;
624
- }): Promise<string>;
870
+ }): ExecaChildProcess;
871
+ /** Returns the installed (within node_modules or pnp zip) version of a specified package */
872
+ getInstalledVersion(packageName: string): Promise<string | null>;
873
+ isPackageInstalled(packageName: string): Promise<boolean>;
874
+ /**
875
+ * Searches for a dependency/devDependency in all package.json files and returns the version of
876
+ * the dependency.
877
+ */
878
+ getDependencyVersion(dependency: string): string | null;
879
+ static hasStorybookDependency(packageJsonPath: string): boolean;
880
+ static hasAnyStorybookDependency(packageJsonPath: string): boolean;
881
+ /** List all package.json files starting from the given directory and stopping at the project root. */
882
+ static listAllPackageJsonPaths(instanceDir: string, storiesPaths?: string[]): string[];
883
+ static getPackageJsonInfo(packageJsonPath: string): PackageJsonInfo;
625
884
  }
626
885
 
627
886
  declare class JsPackageManagerFactory {
628
- static getPackageManager({ force }?: {
887
+ /** Cache for package manager instances */
888
+ private static cache;
889
+ /** Generate a cache key based on the parameters */
890
+ private static getCacheKey;
891
+ /** Clear the package manager cache */
892
+ static clearCache(): void;
893
+ /**
894
+ * Determine which package manager type to use based on lockfiles, commands, and environment
895
+ *
896
+ * @param cwd - Current working directory
897
+ * @returns Package manager type as string: 'npm', 'pnpm', 'bun', 'yarn1', or 'yarn2'
898
+ * @throws Error if no usable package manager is found
899
+ */
900
+ static getPackageManagerType(cwd?: string): PackageManagerName;
901
+ static getPackageManager({ force, configDir, storiesPaths, ignoreCache, }?: {
629
902
  force?: PackageManagerName;
903
+ configDir?: string;
904
+ storiesPaths?: string[];
905
+ ignoreCache?: boolean;
630
906
  }, cwd?: string): JsPackageManager;
631
907
  /** Look up map of package manager proxies by name */
632
908
  private static PROXY_MAP;
@@ -788,13 +1064,13 @@ declare const rendererPackages: Record<string, string>;
788
1064
  declare const frameworkPackages: Record<string, SupportedFrameworks>;
789
1065
  declare const builderPackages: string[];
790
1066
  declare const findConfigFile: (prefix: string, configDir: string) => string | null;
791
- declare const getConfigInfo: (packageJson: PackageJson, configDir?: string) => {
1067
+ declare const getConfigInfo: (configDir?: string) => {
792
1068
  configDir: string;
793
- mainConfig: string | null;
794
- previewConfig: string | null;
795
- managerConfig: string | null;
1069
+ mainConfigPath: string | null;
1070
+ previewConfigPath: string | null;
1071
+ managerConfigPath: string | null;
796
1072
  };
797
- declare const getStorybookInfo: (packageJson: PackageJson, configDir?: string) => CoreCommon_StorybookInfo;
1073
+ declare const getStorybookInfo: (configDir?: string) => CoreCommon_StorybookInfo;
798
1074
 
799
1075
  declare const getAutoRefs: (options: Options$1) => Promise<Record<string, Ref>>;
800
1076
  declare function getRefs(options: Options$1): Promise<Record<string, Ref>>;
@@ -832,9 +1108,10 @@ declare function loadCustomPresets({ configDir }: {
832
1108
  configDir: string;
833
1109
  }): PresetConfig[];
834
1110
 
835
- declare function loadMainConfig({ configDir, noCache, }: {
1111
+ declare function loadMainConfig({ configDir, noCache, cwd, }: {
836
1112
  configDir: string;
837
1113
  noCache?: boolean;
1114
+ cwd?: string;
838
1115
  }): Promise<StorybookConfig>;
839
1116
 
840
1117
  declare function loadManagerOrAddonsFile({ configDir }: {
@@ -865,12 +1142,18 @@ interface NormalizeOptions {
865
1142
  declare const normalizeStories: (entries: StoriesEntry[], options: NormalizeOptions) => NormalizedStoriesSpecifier[];
866
1143
 
867
1144
  declare const getProjectRoot: () => string;
1145
+ declare const invalidateProjectRootCache: () => void;
868
1146
  declare const nodePathsToArray: (nodePath: string) => string[];
869
1147
  /** Ensures that a path starts with `./` or `../`, or is entirely `.` or `..` */
870
1148
  declare function normalizeStoryPath(filename: string): string;
871
1149
 
872
1150
  declare function readTemplate(filename: string): Promise<string>;
873
1151
 
1152
+ type RemoveAddonOptions = {
1153
+ packageManager: JsPackageManager;
1154
+ configDir?: string;
1155
+ skipInstall?: boolean;
1156
+ };
874
1157
  /**
875
1158
  * Remove the given addon package and remove it from main.js
876
1159
  *
@@ -880,11 +1163,7 @@ declare function readTemplate(filename: string): Promise<string>;
880
1163
  * sb remove @storybook/addon-links
881
1164
  * ```
882
1165
  */
883
- declare function removeAddon(addon: string, options?: {
884
- packageManager?: PackageManagerName;
885
- cwd?: string;
886
- configDir?: string;
887
- }): Promise<void>;
1166
+ declare function removeAddon(addon: string, options: RemoveAddonOptions): Promise<void>;
888
1167
 
889
1168
  /**
890
1169
  * Get the path of the file or directory with input name inside the Storybook cache directory:
@@ -904,7 +1183,7 @@ declare function getPreviewHeadTemplate(configDirPath: string, interpolations?:
904
1183
 
905
1184
  declare function validateFrameworkName(frameworkName: string | undefined): asserts frameworkName is string;
906
1185
 
907
- declare function validateConfigurationFiles(configDir: string): Promise<void>;
1186
+ declare function validateConfigurationFiles(configDir: string, cwd?: string): Promise<void>;
908
1187
 
909
1188
  /** Mimicking the satisfies operator until we can upgrade to TS4.9 */
910
1189
  declare function satisfies<A>(): <T extends A>(x: T) => T;
@@ -940,8 +1219,8 @@ declare const posix: (localPath: string, seperator?: string) => string;
940
1219
 
941
1220
  declare const getAddonNames: (mainConfig: StorybookConfig) => string[];
942
1221
 
943
- declare function syncStorybookAddons(mainConfig: StorybookConfig, previewConfigPath: string): Promise<void>;
944
- declare function getSyncedStorybookAddons(mainConfig: StorybookConfig, previewConfig: ConfigFile): Promise<ConfigFile>;
1222
+ declare function syncStorybookAddons(mainConfig: StorybookConfig, previewConfigPath: string, configDir: string): Promise<void>;
1223
+ declare function getSyncedStorybookAddons(mainConfig: StorybookConfig, previewConfig: ConfigFile, configDir: string): Promise<ConfigFile>;
945
1224
 
946
1225
  /**
947
1226
  * Helper function to scan for files matching a glob pattern and transform them
@@ -970,4 +1249,4 @@ declare const transformImportFiles: (files: string[], renamedImports: Record<str
970
1249
  error: Error;
971
1250
  }[]>;
972
1251
 
973
- export { COMMON_ENV_VARS, DEFAULT_FILES_PATTERN, type FileOptions, FileSystemCache, HandledError, type InstallationMetadata, JsPackageManager, JsPackageManagerFactory, type PackageJsonWithDepsAndDevDeps, type PackageJsonWithMaybeDeps, type PackageManagerName, type PackageMetadata, boost, builderPackages, cache, checkAddonOrder, codeLog, commandLog, commonGlobOptions, createFileSystemCache, createLogStream, extractProperFrameworkName, extractProperRendererNameFromFramework, filterPresetsConfig, findConfigFile, formatFileContent, frameworkPackages, frameworkToRenderer, getAddonNames, getAutoRefs, getBuilderOptions, getChars, getCoercedStorybookVersion, getConfigInfo, getDirectoryFromWorkingDir, getEnvConfig, getFrameworkName, getInterpretedFile, getInterpretedFileWithExt, getPackageDetails, getPresets, getPreviewBodyTemplate, getPreviewHeadTemplate, getProjectRoot, getRefs, getRendererName, getStoryId, getStoryTitle, getStorybookConfiguration, getStorybookInfo, getSyncedStorybookAddons, globToRegexp, interopRequireDefault, interpolate, isCorePackage, isPreservingSymlinks, isSatelliteAddon, loadAllPresets, loadCustomPresets, loadEnvs, loadMainConfig, loadManagerOrAddonsFile, loadPreset, loadPreviewOrConfigFile, logConfig, nodePathsToArray, normalizeStories, normalizeStoriesEntry, normalizeStoryPath, paddedLog, parseList, posix, readTemplate, removeAddon, rendererPackages, resolveAddonName, resolvePathInStorybookCache, satisfies, scanAndTransformFiles, serverRequire, serverResolve, stringifyEnvs, stringifyProcessEnvs, stripAbsNodeModulesPath, syncStorybookAddons, temporaryDirectory, temporaryFile, transformImportFiles, validateConfigurationFiles, validateFrameworkName, _default as versions };
1252
+ export { COMMON_ENV_VARS, DEFAULT_FILES_PATTERN, type FileOptions, FileSystemCache, HandledError, type InstallationMetadata, JsPackageManager, JsPackageManagerFactory, type PackageJsonInfo, type PackageJsonWithDepsAndDevDeps, type PackageJsonWithMaybeDeps, type PackageManagerName, type PackageMetadata, type RemoveAddonOptions, boost, builderPackages, cache, checkAddonOrder, codeLog, commandLog, commonGlobOptions, createFileSystemCache, createLogStream, extractProperFrameworkName, extractProperRendererNameFromFramework, filterPresetsConfig, findConfigFile, formatFileContent, frameworkPackages, frameworkToRenderer, getAddonNames, getAutoRefs, getBuilderOptions, getChars, getCoercedStorybookVersion, getConfigInfo, getDirectoryFromWorkingDir, getEnvConfig, getFrameworkName, getInterpretedFile, getInterpretedFileWithExt, getPackageDetails, getPresets, getPreviewBodyTemplate, getPreviewHeadTemplate, getProjectRoot, getRefs, getRendererName, getStoryId, getStoryTitle, getStorybookConfiguration, getStorybookInfo, getSyncedStorybookAddons, globToRegexp, interopRequireDefault, interpolate, invalidateProjectRootCache, isCorePackage, isPreservingSymlinks, isSatelliteAddon, loadAllPresets, loadCustomPresets, loadEnvs, loadMainConfig, loadManagerOrAddonsFile, loadPreset, loadPreviewOrConfigFile, logConfig, nodePathsToArray, normalizeStories, normalizeStoriesEntry, normalizeStoryPath, paddedLog, parseList, posix, readTemplate, removeAddon, rendererPackages, resolveAddonName, resolvePathInStorybookCache, satisfies, scanAndTransformFiles, serverRequire, serverResolve, stringifyEnvs, stringifyProcessEnvs, stripAbsNodeModulesPath, syncStorybookAddons, temporaryDirectory, temporaryFile, transformImportFiles, validateConfigurationFiles, validateFrameworkName, _default as versions };