From 797c6050cecb5a4531e9e1fa74bc6c8ef0f79ad9 Mon Sep 17 00:00:00 2001 From: Charles Gruenais Date: Tue, 16 Mar 2021 22:02:54 +0100 Subject: [PATCH] Reused Storybook's Options core type and applied fix to vue3 framework --- addons/docs/src/frameworks/vue/preset.ts | 16 +++------------- addons/docs/src/frameworks/vue3/preset.ts | 18 ++++++++++++++++-- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/addons/docs/src/frameworks/vue/preset.ts b/addons/docs/src/frameworks/vue/preset.ts index 568958f34de6..5650c588cc67 100644 --- a/addons/docs/src/frameworks/vue/preset.ts +++ b/addons/docs/src/frameworks/vue/preset.ts @@ -1,19 +1,9 @@ -interface Preset { - readonly name: string; - readonly options: any; -} - -interface PresetOptions { - readonly presetsList: Preset[]; -} +import type { Options } from '@storybook/core-common'; -export function webpackFinal( - webpackConfig: any = {}, - options: PresetOptions = { presetsList: [] } -) { +export function webpackFinal(webpackConfig: any = {}, options: Options) { let vueDocgenOptions = {}; - options.presetsList.forEach((preset) => { + options.presetsList?.forEach((preset) => { if (preset.name.includes('addon-docs') && preset.options.vueDocgenOptions) { const appendableOptions = preset.options.vueDocgenOptions; vueDocgenOptions = { diff --git a/addons/docs/src/frameworks/vue3/preset.ts b/addons/docs/src/frameworks/vue3/preset.ts index dd03fb874d00..c8e044caf8e2 100644 --- a/addons/docs/src/frameworks/vue3/preset.ts +++ b/addons/docs/src/frameworks/vue3/preset.ts @@ -1,4 +1,18 @@ -export function webpackFinal(webpackConfig: any = {}, options: any = {}) { +import type { Options } from '@storybook/core-common'; + +export function webpackFinal(webpackConfig: any = {}, options: Options) { + let vueDocgenOptions = {}; + + options.presetsList?.forEach((preset) => { + if (preset.name.includes('addon-docs') && preset.options.vueDocgenOptions) { + const appendableOptions = preset.options.vueDocgenOptions; + vueDocgenOptions = { + ...vueDocgenOptions, + ...appendableOptions, + }; + } + }); + webpackConfig.module.rules.push({ test: /\.vue$/, loader: require.resolve('vue-docgen-loader', { paths: [require.resolve('@storybook/vue3')] }), @@ -6,7 +20,7 @@ export function webpackFinal(webpackConfig: any = {}, options: any = {}) { options: { docgenOptions: { alias: webpackConfig.resolve.alias, - ...options.vueDocgenOptions, + ...vueDocgenOptions, }, }, });