From 635d4343ee23b4b37dff10210bdff40382b229e2 Mon Sep 17 00:00:00 2001 From: Norbert de Langen Date: Thu, 8 Dec 2022 16:31:10 +0100 Subject: [PATCH 1/4] fix check for devDependencies, but that key is not always defined. --- code/lib/cli/src/link.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/lib/cli/src/link.ts b/code/lib/cli/src/link.ts index f52ad93bd757..bfb45e171616 100644 --- a/code/lib/cli/src/link.ts +++ b/code/lib/cli/src/link.ts @@ -63,7 +63,7 @@ export const link = async ({ target, local, start }: LinkOptions) => { `Magic stuff related to @storybook/preset-create-react-app, we need to fix peerDependencies` ); - if (!reproPackageJson.devDependencies.vite) { + if (!reproPackageJson.devDependencies?.vite) { await exec(`yarn add -D webpack-hot-middleware`, { cwd: reproDir }); } From d67e466939dd9ae46f114228921c9951f005c5aa Mon Sep 17 00:00:00 2001 From: Norbert de Langen Date: Thu, 8 Dec 2022 16:35:47 +0100 Subject: [PATCH 2/4] fix a typo --- scripts/tasks/sandbox-parts.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/tasks/sandbox-parts.ts b/scripts/tasks/sandbox-parts.ts index 31a397445b50..d57257578379 100644 --- a/scripts/tasks/sandbox-parts.ts +++ b/scripts/tasks/sandbox-parts.ts @@ -143,7 +143,7 @@ function addEsbuildLoaderToStories(mainConfig: ConfigFile) { (config) => ({ ...config, module: { - ...config.modules, + ...config.module, rules: [ // Ensure esbuild-loader applies to all files in ./template-stories { From 77f0d4fede9ee7fc44aeab1e12aac7329e49085d Mon Sep 17 00:00:00 2001 From: Norbert de Langen Date: Thu, 8 Dec 2022 16:48:05 +0100 Subject: [PATCH 3/4] minor improvement in StorybookConfig type --- code/lib/types/src/modules/core-common.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/code/lib/types/src/modules/core-common.ts b/code/lib/types/src/modules/core-common.ts index 94fa3b310c0e..61dc1826649e 100644 --- a/code/lib/types/src/modules/core-common.ts +++ b/code/lib/types/src/modules/core-common.ts @@ -341,7 +341,7 @@ export interface StorybookConfig { /** * References external Storybooks */ - refs?: CoreCommon_StorybookRefs | ((config: any, options: Options) => CoreCommon_StorybookRefs); + refs?: PresetValue; /** * Modify or return babel config. @@ -364,17 +364,17 @@ export interface StorybookConfig { * * @deprecated use `previewAnnotations` or `/preview.js` file instead */ - config?: (entries: Entry[], options: Options) => Entry[]; + config?: PresetValue; /** * Add additional scripts to run in the preview a la `.storybook/preview.js` */ - previewAnnotations?: (entries: Entry[], options: Options) => Entry[]; + previewAnnotations?: PresetValue; /** * Process CSF files for the story index. */ - storyIndexers?: (indexers: StoryIndexer[], options: Options) => StoryIndexer[]; + storyIndexers?: PresetValue; /** * Docs related features in index generation @@ -386,11 +386,13 @@ export interface StorybookConfig { * The previewHead and previewBody functions accept a string, * which is the existing head/body, and return a modified string. */ - previewHead?: (head: string, options: Options) => string; + previewHead?: PresetValue; - previewBody?: (body: string, options: Options) => string; + previewBody?: PresetValue; } +export type PresetValue = T | ((config: T, options: Options) => T | Promise); + export type PresetProperty = | TStorybookConfig[K extends keyof TStorybookConfig ? K : never] | PresetPropertyFn; From 0694290115b97721995a6afd3bf976abf446ef42 Mon Sep 17 00:00:00 2001 From: Norbert de Langen Date: Thu, 8 Dec 2022 16:59:56 +0100 Subject: [PATCH 4/4] use constructorParameters to gain access to the options interface from the class --- code/lib/builder-webpack5/src/types.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/lib/builder-webpack5/src/types.ts b/code/lib/builder-webpack5/src/types.ts index 6b13b02adf99..6e55f145ca22 100644 --- a/code/lib/builder-webpack5/src/types.ts +++ b/code/lib/builder-webpack5/src/types.ts @@ -16,7 +16,7 @@ export interface TypescriptOptions extends TypeScriptOptionsBase { /** * Configures `fork-ts-checker-webpack-plugin` */ - checkOptions?: ForkTsCheckerWebpackPlugin['options']; + checkOptions?: ConstructorParameters[0]; } export interface StorybookConfigWebpack extends Pick {