From 36232e7d05f303a96912c75cd627dd550fe78347 Mon Sep 17 00:00:00 2001 From: Ian VanSchooten Date: Mon, 16 Jan 2023 20:50:53 -0500 Subject: [PATCH 1/6] Move types into types.ts --- code/lib/builder-vite/src/index.ts | 26 +++---------------- code/lib/builder-vite/src/types.ts | 25 ++++++++++++++++++ .../src/types/extended-options.type.ts | 8 ------ code/lib/builder-vite/src/types/index.ts | 1 - 4 files changed, 29 insertions(+), 31 deletions(-) create mode 100644 code/lib/builder-vite/src/types.ts delete mode 100644 code/lib/builder-vite/src/types/extended-options.type.ts delete mode 100644 code/lib/builder-vite/src/types/index.ts diff --git a/code/lib/builder-vite/src/index.ts b/code/lib/builder-vite/src/index.ts index b9535c4a5e08..8e1e7b573ae1 100644 --- a/code/lib/builder-vite/src/index.ts +++ b/code/lib/builder-vite/src/index.ts @@ -1,37 +1,19 @@ // noinspection JSUnusedGlobalSymbols import * as fs from 'fs-extra'; -import type { Builder, StorybookConfig as StorybookBaseConfig, Options } from '@storybook/types'; import type { RequestHandler } from 'express'; -import type { InlineConfig, UserConfig, ViteDevServer } from 'vite'; +import type { ViteDevServer } from 'vite'; import express from 'express'; import { dirname, join, parse } from 'path'; import { transformIframeHtml } from './transform-iframe-html'; import { createViteServer } from './vite-server'; import { build as viteBuild } from './build'; -import type { ExtendedOptions } from './types'; +import type { ExtendedOptions, ViteBuilder } from './types'; export { withoutVitePlugins } from './utils/without-vite-plugins'; export { hasVitePlugins } from './utils/has-vite-plugins'; -// TODO remove -export type { TypescriptOptions } from '@storybook/types'; - -// Storybook's Stats are optional Webpack related property -export type ViteStats = { - toJson: () => any; -}; - -export type ViteBuilder = Builder; - -export type ViteFinal = ( - config: InlineConfig, - options: Options -) => InlineConfig | Promise; - -export type StorybookConfig = StorybookBaseConfig & { - viteFinal?: ViteFinal; -}; +export type { ViteFinal } from './types'; /** * @deprecated @@ -40,7 +22,7 @@ export type StorybookConfig = StorybookBaseConfig & { * * Or better yet, import from your framework. */ -export type StorybookViteConfig = StorybookConfig; +export type { StorybookViteConfig } from './types'; function iframeMiddleware(options: ExtendedOptions, server: ViteDevServer): RequestHandler { return async (req, res, next) => { diff --git a/code/lib/builder-vite/src/types.ts b/code/lib/builder-vite/src/types.ts new file mode 100644 index 000000000000..e7f09c08c14c --- /dev/null +++ b/code/lib/builder-vite/src/types.ts @@ -0,0 +1,25 @@ +import type { Builder, StorybookConfig as StorybookBaseConfig, Options } from '@storybook/types'; +import type { InlineConfig, UserConfig } from 'vite'; + +// Storybook's Stats are optional Webpack related property +type ViteStats = { + toJson: () => any; +}; + +export type ViteBuilder = Builder; + +export type ViteFinal = ( + config: InlineConfig, + options: Options +) => InlineConfig | Promise; + +export type StorybookViteConfig = StorybookBaseConfig & { + viteFinal?: ViteFinal; +}; + +// Using instead of `Record` to provide better aware of used options +type IframeOptions = { + title: string; +}; + +export type ExtendedOptions = Options & IframeOptions; diff --git a/code/lib/builder-vite/src/types/extended-options.type.ts b/code/lib/builder-vite/src/types/extended-options.type.ts deleted file mode 100644 index eaad5a8cc86c..000000000000 --- a/code/lib/builder-vite/src/types/extended-options.type.ts +++ /dev/null @@ -1,8 +0,0 @@ -import type { Options } from '@storybook/types'; - -// Using instead of `Record` to provide better aware of used options -type IframeOptions = { - title: string; -}; - -export type ExtendedOptions = Options & IframeOptions; diff --git a/code/lib/builder-vite/src/types/index.ts b/code/lib/builder-vite/src/types/index.ts deleted file mode 100644 index 937f58679fe6..000000000000 --- a/code/lib/builder-vite/src/types/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './extended-options.type'; From 0663100b12981c7c6c3a47c1817575106648e019 Mon Sep 17 00:00:00 2001 From: Ian VanSchooten Date: Mon, 16 Jan 2023 21:46:52 -0500 Subject: [PATCH 2/6] Improve types in Vite frameworks --- code/frameworks/html-vite/src/index.ts | 2 +- code/frameworks/html-vite/src/types.ts | 36 +++++++++++++++++++ code/frameworks/preact-vite/src/index.ts | 2 +- code/frameworks/preact-vite/src/types.ts | 36 +++++++++++++++++++ code/frameworks/react-vite/src/index.ts | 2 +- code/frameworks/react-vite/src/types.ts | 36 +++++++++++++++++++ code/frameworks/svelte-vite/src/index.ts | 2 +- code/frameworks/svelte-vite/src/types.ts | 36 +++++++++++++++++++ code/frameworks/sveltekit/src/index.ts | 2 +- code/frameworks/sveltekit/src/types.ts | 36 +++++++++++++++++++ code/frameworks/vue-vite/src/index.ts | 2 +- code/frameworks/vue-vite/src/types.ts | 36 +++++++++++++++++++ code/frameworks/vue3-vite/src/index.ts | 2 +- code/frameworks/vue3-vite/src/types.ts | 36 +++++++++++++++++++ .../web-components-vite/src/index.ts | 2 +- .../web-components-vite/src/types.ts | 36 +++++++++++++++++++ code/lib/builder-vite/src/index.ts | 11 +++--- code/lib/builder-vite/src/types.ts | 6 ++-- 18 files changed, 306 insertions(+), 15 deletions(-) create mode 100644 code/frameworks/html-vite/src/types.ts create mode 100644 code/frameworks/preact-vite/src/types.ts create mode 100644 code/frameworks/react-vite/src/types.ts create mode 100644 code/frameworks/svelte-vite/src/types.ts create mode 100644 code/frameworks/sveltekit/src/types.ts create mode 100644 code/frameworks/vue-vite/src/types.ts create mode 100644 code/frameworks/vue3-vite/src/types.ts create mode 100644 code/frameworks/web-components-vite/src/types.ts diff --git a/code/frameworks/html-vite/src/index.ts b/code/frameworks/html-vite/src/index.ts index d3ded0cdbbb9..fcb073fefcd6 100644 --- a/code/frameworks/html-vite/src/index.ts +++ b/code/frameworks/html-vite/src/index.ts @@ -1 +1 @@ -export type { StorybookConfig } from '@storybook/builder-vite'; +export * from './types'; diff --git a/code/frameworks/html-vite/src/types.ts b/code/frameworks/html-vite/src/types.ts new file mode 100644 index 000000000000..6c424c983077 --- /dev/null +++ b/code/frameworks/html-vite/src/types.ts @@ -0,0 +1,36 @@ +import type { StorybookConfig as StorybookConfigBase } from '@storybook/types'; +import type { StorybookConfigVite, BuilderOptions } from '@storybook/builder-vite'; + +type FrameworkName = '@storybook/html-vite'; +type BuilderName = '@storybook/builder-vite'; + +export type FrameworkOptions = { + builder?: BuilderOptions; +}; + +type StorybookConfigFramework = { + framework: + | FrameworkName + | { + name: FrameworkName; + options: FrameworkOptions; + }; + core?: { + builder?: + | BuilderName + | { + name: BuilderName; + options: BuilderOptions; + }; + }; +}; + +/** + * The interface for Storybook configuration in `main.ts` files. + */ +export type StorybookConfig = Omit< + StorybookConfigBase, + keyof StorybookConfigVite | keyof StorybookConfigFramework +> & + StorybookConfigVite & + StorybookConfigFramework; diff --git a/code/frameworks/preact-vite/src/index.ts b/code/frameworks/preact-vite/src/index.ts index d3ded0cdbbb9..fcb073fefcd6 100644 --- a/code/frameworks/preact-vite/src/index.ts +++ b/code/frameworks/preact-vite/src/index.ts @@ -1 +1 @@ -export type { StorybookConfig } from '@storybook/builder-vite'; +export * from './types'; diff --git a/code/frameworks/preact-vite/src/types.ts b/code/frameworks/preact-vite/src/types.ts new file mode 100644 index 000000000000..bba1e821e4c8 --- /dev/null +++ b/code/frameworks/preact-vite/src/types.ts @@ -0,0 +1,36 @@ +import type { StorybookConfig as StorybookConfigBase } from '@storybook/types'; +import type { StorybookConfigVite, BuilderOptions } from '@storybook/builder-vite'; + +type FrameworkName = '@storybook/preact-vite'; +type BuilderName = '@storybook/builder-vite'; + +export type FrameworkOptions = { + builder?: BuilderOptions; +}; + +type StorybookConfigFramework = { + framework: + | FrameworkName + | { + name: FrameworkName; + options: FrameworkOptions; + }; + core?: { + builder?: + | BuilderName + | { + name: BuilderName; + options: BuilderOptions; + }; + }; +}; + +/** + * The interface for Storybook configuration in `main.ts` files. + */ +export type StorybookConfig = Omit< + StorybookConfigBase, + keyof StorybookConfigVite | keyof StorybookConfigFramework +> & + StorybookConfigVite & + StorybookConfigFramework; diff --git a/code/frameworks/react-vite/src/index.ts b/code/frameworks/react-vite/src/index.ts index d3ded0cdbbb9..fcb073fefcd6 100644 --- a/code/frameworks/react-vite/src/index.ts +++ b/code/frameworks/react-vite/src/index.ts @@ -1 +1 @@ -export type { StorybookConfig } from '@storybook/builder-vite'; +export * from './types'; diff --git a/code/frameworks/react-vite/src/types.ts b/code/frameworks/react-vite/src/types.ts new file mode 100644 index 000000000000..b368009f9d75 --- /dev/null +++ b/code/frameworks/react-vite/src/types.ts @@ -0,0 +1,36 @@ +import type { StorybookConfig as StorybookConfigBase } from '@storybook/types'; +import type { StorybookConfigVite, BuilderOptions } from '@storybook/builder-vite'; + +type FrameworkName = '@storybook/react-vite'; +type BuilderName = '@storybook/builder-vite'; + +export type FrameworkOptions = { + builder?: BuilderOptions; +}; + +type StorybookConfigFramework = { + framework: + | FrameworkName + | { + name: FrameworkName; + options: FrameworkOptions; + }; + core?: { + builder?: + | BuilderName + | { + name: BuilderName; + options: BuilderOptions; + }; + }; +}; + +/** + * The interface for Storybook configuration in `main.ts` files. + */ +export type StorybookConfig = Omit< + StorybookConfigBase, + keyof StorybookConfigVite | keyof StorybookConfigFramework +> & + StorybookConfigVite & + StorybookConfigFramework; diff --git a/code/frameworks/svelte-vite/src/index.ts b/code/frameworks/svelte-vite/src/index.ts index d3ded0cdbbb9..fcb073fefcd6 100644 --- a/code/frameworks/svelte-vite/src/index.ts +++ b/code/frameworks/svelte-vite/src/index.ts @@ -1 +1 @@ -export type { StorybookConfig } from '@storybook/builder-vite'; +export * from './types'; diff --git a/code/frameworks/svelte-vite/src/types.ts b/code/frameworks/svelte-vite/src/types.ts new file mode 100644 index 000000000000..fdf93ab7b700 --- /dev/null +++ b/code/frameworks/svelte-vite/src/types.ts @@ -0,0 +1,36 @@ +import type { StorybookConfig as StorybookConfigBase } from '@storybook/types'; +import type { StorybookConfigVite, BuilderOptions } from '@storybook/builder-vite'; + +type FrameworkName = '@storybook/svelte-vite'; +type BuilderName = '@storybook/builder-vite'; + +export type FrameworkOptions = { + builder?: BuilderOptions; +}; + +type StorybookConfigFramework = { + framework: + | FrameworkName + | { + name: FrameworkName; + options: FrameworkOptions; + }; + core?: { + builder?: + | BuilderName + | { + name: BuilderName; + options: BuilderOptions; + }; + }; +}; + +/** + * The interface for Storybook configuration in `main.ts` files. + */ +export type StorybookConfig = Omit< + StorybookConfigBase, + keyof StorybookConfigVite | keyof StorybookConfigFramework +> & + StorybookConfigVite & + StorybookConfigFramework; diff --git a/code/frameworks/sveltekit/src/index.ts b/code/frameworks/sveltekit/src/index.ts index 1a8d7c1a6e62..fcb073fefcd6 100644 --- a/code/frameworks/sveltekit/src/index.ts +++ b/code/frameworks/sveltekit/src/index.ts @@ -1 +1 @@ -export * from '@storybook/svelte-vite'; +export * from './types'; diff --git a/code/frameworks/sveltekit/src/types.ts b/code/frameworks/sveltekit/src/types.ts new file mode 100644 index 000000000000..bfb6094ce317 --- /dev/null +++ b/code/frameworks/sveltekit/src/types.ts @@ -0,0 +1,36 @@ +import type { StorybookConfig as StorybookConfigBase } from '@storybook/types'; +import type { StorybookConfigVite, BuilderOptions } from '@storybook/builder-vite'; + +type FrameworkName = '@storybook/sveltekit'; +type BuilderName = '@storybook/builder-vite'; + +export type FrameworkOptions = { + builder?: BuilderOptions; +}; + +type StorybookConfigFramework = { + framework: + | FrameworkName + | { + name: FrameworkName; + options: FrameworkOptions; + }; + core?: { + builder?: + | BuilderName + | { + name: BuilderName; + options: BuilderOptions; + }; + }; +}; + +/** + * The interface for Storybook configuration in `main.ts` files. + */ +export type StorybookConfig = Omit< + StorybookConfigBase, + keyof StorybookConfigVite | keyof StorybookConfigFramework +> & + StorybookConfigVite & + StorybookConfigFramework; diff --git a/code/frameworks/vue-vite/src/index.ts b/code/frameworks/vue-vite/src/index.ts index d3ded0cdbbb9..fcb073fefcd6 100644 --- a/code/frameworks/vue-vite/src/index.ts +++ b/code/frameworks/vue-vite/src/index.ts @@ -1 +1 @@ -export type { StorybookConfig } from '@storybook/builder-vite'; +export * from './types'; diff --git a/code/frameworks/vue-vite/src/types.ts b/code/frameworks/vue-vite/src/types.ts new file mode 100644 index 000000000000..6b72ade8db41 --- /dev/null +++ b/code/frameworks/vue-vite/src/types.ts @@ -0,0 +1,36 @@ +import type { StorybookConfig as StorybookConfigBase } from '@storybook/types'; +import type { StorybookConfigVite, BuilderOptions } from '@storybook/builder-vite'; + +type FrameworkName = '@storybook/vue-vite'; +type BuilderName = '@storybook/builder-vite'; + +export type FrameworkOptions = { + builder?: BuilderOptions; +}; + +type StorybookConfigFramework = { + framework: + | FrameworkName + | { + name: FrameworkName; + options: FrameworkOptions; + }; + core?: { + builder?: + | BuilderName + | { + name: BuilderName; + options: BuilderOptions; + }; + }; +}; + +/** + * The interface for Storybook configuration in `main.ts` files. + */ +export type StorybookConfig = Omit< + StorybookConfigBase, + keyof StorybookConfigVite | keyof StorybookConfigFramework +> & + StorybookConfigVite & + StorybookConfigFramework; diff --git a/code/frameworks/vue3-vite/src/index.ts b/code/frameworks/vue3-vite/src/index.ts index d3ded0cdbbb9..fcb073fefcd6 100644 --- a/code/frameworks/vue3-vite/src/index.ts +++ b/code/frameworks/vue3-vite/src/index.ts @@ -1 +1 @@ -export type { StorybookConfig } from '@storybook/builder-vite'; +export * from './types'; diff --git a/code/frameworks/vue3-vite/src/types.ts b/code/frameworks/vue3-vite/src/types.ts new file mode 100644 index 000000000000..2780a44425cc --- /dev/null +++ b/code/frameworks/vue3-vite/src/types.ts @@ -0,0 +1,36 @@ +import type { StorybookConfig as StorybookConfigBase } from '@storybook/types'; +import type { StorybookConfigVite, BuilderOptions } from '@storybook/builder-vite'; + +type FrameworkName = '@storybook/vue3-vite'; +type BuilderName = '@storybook/builder-vite'; + +export type FrameworkOptions = { + builder?: BuilderOptions; +}; + +type StorybookConfigFramework = { + framework: + | FrameworkName + | { + name: FrameworkName; + options: FrameworkOptions; + }; + core?: { + builder?: + | BuilderName + | { + name: BuilderName; + options: BuilderOptions; + }; + }; +}; + +/** + * The interface for Storybook configuration in `main.ts` files. + */ +export type StorybookConfig = Omit< + StorybookConfigBase, + keyof StorybookConfigVite | keyof StorybookConfigFramework +> & + StorybookConfigVite & + StorybookConfigFramework; diff --git a/code/frameworks/web-components-vite/src/index.ts b/code/frameworks/web-components-vite/src/index.ts index d3ded0cdbbb9..fcb073fefcd6 100644 --- a/code/frameworks/web-components-vite/src/index.ts +++ b/code/frameworks/web-components-vite/src/index.ts @@ -1 +1 @@ -export type { StorybookConfig } from '@storybook/builder-vite'; +export * from './types'; diff --git a/code/frameworks/web-components-vite/src/types.ts b/code/frameworks/web-components-vite/src/types.ts new file mode 100644 index 000000000000..a4a2cacbdf95 --- /dev/null +++ b/code/frameworks/web-components-vite/src/types.ts @@ -0,0 +1,36 @@ +import type { StorybookConfig as StorybookConfigBase } from '@storybook/types'; +import type { StorybookConfigVite, BuilderOptions } from '@storybook/builder-vite'; + +type FrameworkName = '@storybook/web-components-vite'; +type BuilderName = '@storybook/builder-vite'; + +export type FrameworkOptions = { + builder?: BuilderOptions; +}; + +type StorybookConfigFramework = { + framework: + | FrameworkName + | { + name: FrameworkName; + options: FrameworkOptions; + }; + core?: { + builder?: + | BuilderName + | { + name: BuilderName; + options: BuilderOptions; + }; + }; +}; + +/** + * The interface for Storybook configuration in `main.ts` files. + */ +export type StorybookConfig = Omit< + StorybookConfigBase, + keyof StorybookConfigVite | keyof StorybookConfigFramework +> & + StorybookConfigVite & + StorybookConfigFramework; diff --git a/code/lib/builder-vite/src/index.ts b/code/lib/builder-vite/src/index.ts index 8e1e7b573ae1..0ff1fc5f34cd 100644 --- a/code/lib/builder-vite/src/index.ts +++ b/code/lib/builder-vite/src/index.ts @@ -5,24 +5,25 @@ import type { RequestHandler } from 'express'; import type { ViteDevServer } from 'vite'; import express from 'express'; import { dirname, join, parse } from 'path'; +import type { StorybookConfig as StorybookBaseConfig } from '@storybook/types'; import { transformIframeHtml } from './transform-iframe-html'; import { createViteServer } from './vite-server'; import { build as viteBuild } from './build'; -import type { ExtendedOptions, ViteBuilder } from './types'; +import type { ExtendedOptions, ViteBuilder, StorybookConfigVite } from './types'; export { withoutVitePlugins } from './utils/without-vite-plugins'; export { hasVitePlugins } from './utils/has-vite-plugins'; -export type { ViteFinal } from './types'; +export * from './types'; /** * @deprecated * - * Use `import { StorybookConfig } from '@storybook/builder-vite';` + * Import `StorybookConfig` from your framework, such as: * - * Or better yet, import from your framework. + * `import type { StorybookConfig } from '@storybook/react-vite';` */ -export type { StorybookViteConfig } from './types'; +export type StorybookViteConfig = StorybookBaseConfig & StorybookConfigVite; function iframeMiddleware(options: ExtendedOptions, server: ViteDevServer): RequestHandler { return async (req, res, next) => { diff --git a/code/lib/builder-vite/src/types.ts b/code/lib/builder-vite/src/types.ts index e7f09c08c14c..1792044dd586 100644 --- a/code/lib/builder-vite/src/types.ts +++ b/code/lib/builder-vite/src/types.ts @@ -1,5 +1,5 @@ -import type { Builder, StorybookConfig as StorybookBaseConfig, Options } from '@storybook/types'; import type { InlineConfig, UserConfig } from 'vite'; +import type { Builder, Options } from '@storybook/types'; // Storybook's Stats are optional Webpack related property type ViteStats = { @@ -13,10 +13,12 @@ export type ViteFinal = ( options: Options ) => InlineConfig | Promise; -export type StorybookViteConfig = StorybookBaseConfig & { +export type StorybookConfigVite = { viteFinal?: ViteFinal; }; +export type BuilderOptions = {}; + // Using instead of `Record` to provide better aware of used options type IframeOptions = { title: string; From 678c06c7c594150d9ff7ce8fb7901b23405af6ac Mon Sep 17 00:00:00 2001 From: Ian VanSchooten Date: Mon, 16 Jan 2023 22:09:58 -0500 Subject: [PATCH 3/6] Replace ExtendedOptions with standard Options type --- code/lib/builder-vite/input/iframe.html | 2 +- code/lib/builder-vite/src/build.ts | 4 ++-- code/lib/builder-vite/src/codegen-entries.ts | 3 +-- code/lib/builder-vite/src/codegen-iframe-script.ts | 5 ++--- .../builder-vite/src/codegen-modern-iframe-script.ts | 5 ++--- code/lib/builder-vite/src/envs.ts | 5 ++--- code/lib/builder-vite/src/index.ts | 12 ++++++------ code/lib/builder-vite/src/optimizeDeps.ts | 5 ++--- .../src/plugins/code-generator-plugin.ts | 5 ++--- code/lib/builder-vite/src/plugins/csf-plugin.ts | 5 ++--- code/lib/builder-vite/src/transform-iframe-html.ts | 8 +++----- code/lib/builder-vite/src/types.ts | 7 ------- code/lib/builder-vite/src/vite-config.ts | 6 +++--- code/lib/builder-vite/src/vite-server.ts | 4 ++-- 14 files changed, 30 insertions(+), 46 deletions(-) diff --git a/code/lib/builder-vite/input/iframe.html b/code/lib/builder-vite/input/iframe.html index 874cf855e9a7..911103d945a4 100644 --- a/code/lib/builder-vite/input/iframe.html +++ b/code/lib/builder-vite/input/iframe.html @@ -3,7 +3,7 @@ - <!-- [TITLE HERE] --> + Storybook