index.d.ts 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. import { PresetConfig, CoreCommon_ResolvedAddonPreset, CoreCommon_ResolvedAddonVirtual, LoadedPreset, Presets, CLIOptions, LoadOptions, BuilderOptions, StorybookConfig, CoreCommon_AddonInfo, Options as Options$2, PackageJson, CoreCommon_StorybookInfo, Ref, StoriesEntry, NormalizedStoriesSpecifier } from '@storybook/types';
  2. import * as Cache from 'file-system-cache';
  3. import Cache__default from 'file-system-cache';
  4. type InterPresetOptions = Omit<CLIOptions & LoadOptions & BuilderOptions & {
  5. isCritical?: boolean;
  6. build?: StorybookConfig['build'];
  7. }, 'frameworkPresets'>;
  8. declare function filterPresetsConfig(presetsConfig: PresetConfig[]): PresetConfig[];
  9. /**
  10. * Parse an addon into either a managerEntries or a preset. Throw on invalid input.
  11. *
  12. * Valid inputs:
  13. * - '@storybook/addon-actions/manager'
  14. * => { type: 'virtual', item }
  15. *
  16. * - '@storybook/addon-docs/preset'
  17. * => { type: 'presets', item }
  18. *
  19. * - '@storybook/addon-docs'
  20. * => { type: 'presets', item: '@storybook/addon-docs/preset' }
  21. *
  22. * - { name: '@storybook/addon-docs(/preset)?', options: { ... } }
  23. * => { type: 'presets', item: { name: '@storybook/addon-docs/preset', options } }
  24. */
  25. declare const resolveAddonName: (configDir: string, name: string, options: any) => CoreCommon_ResolvedAddonPreset | CoreCommon_ResolvedAddonVirtual | undefined;
  26. declare function loadPreset(input: PresetConfig, level: number, storybookOptions: InterPresetOptions): Promise<LoadedPreset[]>;
  27. declare function getPresets(presets: PresetConfig[], storybookOptions: InterPresetOptions): Promise<Presets>;
  28. declare function loadAllPresets(options: CLIOptions & LoadOptions & BuilderOptions & {
  29. corePresets: PresetConfig[];
  30. overridePresets: PresetConfig[];
  31. /** Whether preset failures should be critical or not */
  32. isCritical?: boolean;
  33. build?: StorybookConfig['build'];
  34. }): Promise<Presets>;
  35. declare const cache: Cache.FileSystemCache;
  36. interface Options$1 {
  37. before: CoreCommon_AddonInfo;
  38. after: CoreCommon_AddonInfo;
  39. configFile: string;
  40. getConfig: (path: string) => any;
  41. }
  42. declare const checkAddonOrder: ({ before, after, configFile, getConfig }: Options$1) => Promise<void>;
  43. declare function loadEnvs(options?: {
  44. production?: boolean;
  45. }): {
  46. stringified: Record<string, string>;
  47. raw: Record<string, string>;
  48. };
  49. declare const stringifyEnvs: (raw: Record<string, string>) => Record<string, string>;
  50. declare const stringifyProcessEnvs: (raw: Record<string, string>) => Record<string, string>;
  51. declare const findDistEsm: (cwd: string, relativePath: string) => string;
  52. declare const commonGlobOptions: (glob: string) => {
  53. ignore?: undefined;
  54. } | {
  55. ignore: string[];
  56. };
  57. /**
  58. * Builder options can be specified in `core.builder.options` or `framework.options.builder`.
  59. * Preference is given here to `framework.options.builder` if both are specified.
  60. */
  61. declare function getBuilderOptions<T extends Record<string, any>>(options: Options$2): Promise<T | Record<string, never>>;
  62. /**
  63. * Framework can be a string or an object. This utility always returns the string name.
  64. */
  65. declare function getFrameworkName(options: Options$2): Promise<string>;
  66. /**
  67. * Render is set as a string on core. It must be set by the framework
  68. */
  69. declare function getRendererName(options: Options$2): Promise<string>;
  70. declare function getStorybookConfiguration(storybookScript: string, shortName: string, longName: string): string | null;
  71. declare const rendererPackages: Record<string, string>;
  72. declare const frameworkPackages: Record<string, string>;
  73. declare const builderPackages: string[];
  74. declare const findConfigFile: (prefix: string, configDir: string) => string | null;
  75. declare const getStorybookInfo: (packageJson: PackageJson, configDir?: string) => CoreCommon_StorybookInfo;
  76. declare const getAutoRefs: (options: Options$2) => Promise<Record<string, Ref>>;
  77. declare function getRefs(options: Options$2): Promise<Record<string, Ref>>;
  78. declare function globToRegexp(glob: string): RegExp;
  79. declare function handlebars(source: string, data: any): string;
  80. /**
  81. * Return a string corresponding to template filled with bindings using following pattern:
  82. * For each (key, value) of `bindings` replace, in template, `{{key}}` by escaped version of `value`
  83. *
  84. * @param template {String} Template with `{{binding}}`
  85. * @param bindings {Object} key-value object use to fill the template, `{{key}}` will be replaced by `escaped(value)`
  86. * @returns {String} Filled template
  87. */
  88. declare const interpolate: (template: string, bindings: Record<string, string>) => string;
  89. declare const boost: Set<string>;
  90. declare function getInterpretedFile(pathToFile: string): string | undefined;
  91. declare function getInterpretedFileWithExt(pathToFile: string): {
  92. path: string;
  93. ext: string;
  94. } | undefined;
  95. declare function interopRequireDefault(filePath: string): any;
  96. declare function serverRequire(filePath: string | string[]): any;
  97. declare function serverResolve(filePath: string | string[]): string | null;
  98. declare function loadCustomPresets({ configDir }: {
  99. configDir: string;
  100. }): PresetConfig[];
  101. declare function loadMainConfig({ configDir, noCache, }: {
  102. configDir: string;
  103. noCache?: boolean;
  104. }): Promise<StorybookConfig>;
  105. declare function loadManagerOrAddonsFile({ configDir }: {
  106. configDir: string;
  107. }): string | undefined;
  108. declare function loadPreviewOrConfigFile({ configDir }: {
  109. configDir: string;
  110. }): string | undefined;
  111. declare function logConfig(caption: unknown, config: unknown): void;
  112. declare const getDirectoryFromWorkingDir: ({ configDir, workingDir, directory, }: NormalizeOptions & {
  113. directory: string;
  114. }) => string;
  115. declare const normalizeStoriesEntry: (entry: StoriesEntry, { configDir, workingDir, defaultFilesPattern }: NormalizeOptions) => NormalizedStoriesSpecifier;
  116. interface NormalizeOptions {
  117. configDir: string;
  118. workingDir: string;
  119. defaultFilesPattern?: string;
  120. }
  121. declare const normalizeStories: (entries: StoriesEntry[], options: NormalizeOptions) => NormalizedStoriesSpecifier[];
  122. declare const getProjectRoot: () => string;
  123. declare const nodePathsToArray: (nodePath: string) => string[];
  124. /**
  125. * Ensures that a path starts with `./` or `../`, or is entirely `.` or `..`
  126. */
  127. declare function normalizeStoryPath(filename: string): string;
  128. declare function readTemplate(filename: string): Promise<string>;
  129. /**
  130. * Get the path of the file or directory with input name inside the Storybook cache directory:
  131. * - `node_modules/.cache/storybook/{directoryName}` in a Node.js project or npm package
  132. * - `.cache/storybook/{directoryName}` otherwise
  133. *
  134. * @param fileOrDirectoryName {string} Name of the file or directory
  135. * @return {string} Absolute path to the file or directory
  136. */
  137. declare function resolvePathInStorybookCache(fileOrDirectoryName: string): string;
  138. declare function isPreservingSymlinks(): boolean | undefined;
  139. declare function getPreviewBodyTemplate(configDirPath: string, interpolations?: Record<string, string>): string;
  140. declare function getPreviewHeadTemplate(configDirPath: string, interpolations?: Record<string, string>): string;
  141. declare function validateFrameworkName(frameworkName: string | undefined): asserts frameworkName is string;
  142. declare function validateConfigurationFiles(configDir: string): Promise<void>;
  143. /**
  144. * Mimicking the satisfies operator until we can upgrade to TS4.9
  145. */
  146. declare function satisfies<A>(): <T extends A>(x: T) => T;
  147. declare function stripAbsNodeModulesPath(absPath: string): string;
  148. type Options = Parameters<typeof Cache__default>['0'];
  149. type FileSystemCache = ReturnType<typeof Cache__default>;
  150. declare function createFileSystemCache(options: Options): FileSystemCache;
  151. export { boost, builderPackages, cache, checkAddonOrder, commonGlobOptions, createFileSystemCache, filterPresetsConfig, findConfigFile, findDistEsm, frameworkPackages, getAutoRefs, getBuilderOptions, getDirectoryFromWorkingDir, getFrameworkName, getInterpretedFile, getInterpretedFileWithExt, getPresets, getPreviewBodyTemplate, getPreviewHeadTemplate, getProjectRoot, getRefs, getRendererName, getStorybookConfiguration, getStorybookInfo, globToRegexp, handlebars, interopRequireDefault, interpolate, isPreservingSymlinks, loadAllPresets, loadCustomPresets, loadEnvs, loadMainConfig, loadManagerOrAddonsFile, loadPreset, loadPreviewOrConfigFile, logConfig, nodePathsToArray, normalizeStories, normalizeStoriesEntry, normalizeStoryPath, readTemplate, rendererPackages, resolveAddonName, resolvePathInStorybookCache, satisfies, serverRequire, serverResolve, stringifyEnvs, stringifyProcessEnvs, stripAbsNodeModulesPath, validateConfigurationFiles, validateFrameworkName };