Skip to content

Commit

Permalink
fix: add vue-docgen-api peer dep, improve error
Browse files Browse the repository at this point in the history
  • Loading branch information
adalinesimonian authored and IanVS committed Sep 28, 2022
1 parent 14cf3c0 commit 337ea70
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
4 changes: 4 additions & 0 deletions packages/builder-vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
"@storybook/mdx2-csf": "^0.0.3",
"@sveltejs/vite-plugin-svelte": "^1.0.0",
"@vitejs/plugin-vue": "^3.0.0",
"vue-docgen-api": "^4.40.0",
"vite": ">= 3.0.0"
},
"peerDependenciesMeta": {
Expand All @@ -78,6 +79,9 @@
"@sveltejs/vite-plugin-svelte": {
"optional": true
},
"vue-docgen-api": {
"optional": true
},
"@vitejs/plugin-vue": {
"optional": true
}
Expand Down
31 changes: 27 additions & 4 deletions packages/builder-vite/vite-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@ export async function pluginConfig(options: ExtendedOptions, _type: PluginConfig
try {
const vuePlugin = is27 ? require('@vitejs/plugin-vue2') : require('vite-plugin-vue2').createVuePlugin;
plugins.push(vuePlugin());
const { vueDocgen } = await import('./plugins/vue-docgen');
plugins.push(vueDocgen(2));
} catch (err) {
if ((err as NodeJS.ErrnoException).code === 'MODULE_NOT_FOUND') {
throw new Error(`
Expand All @@ -104,14 +102,25 @@ export async function pluginConfig(options: ExtendedOptions, _type: PluginConfig
}
throw err;
}
try {
const { vueDocgen } = await import('./plugins/vue-docgen');
plugins.push(vueDocgen(2));
} catch (err) {
if ((err as NodeJS.ErrnoException).code === 'MODULE_NOT_FOUND') {
throw new Error(
'@storybook/builder-vite requires vue-docgen-api to be installed ' +
'when using @storybook/vue.' +
' Please install it and start storybook again.'
);
}
throw err;
}
}

if (framework === 'vue3') {
try {
const vuePlugin = require('@vitejs/plugin-vue');
plugins.push(vuePlugin());
const { vueDocgen } = await import('./plugins/vue-docgen');
plugins.push(vueDocgen(3));
} catch (err) {
if ((err as NodeJS.ErrnoException).code === 'MODULE_NOT_FOUND') {
throw new Error(`
Expand All @@ -121,6 +130,20 @@ export async function pluginConfig(options: ExtendedOptions, _type: PluginConfig
}
throw err;
}

try {
const { vueDocgen } = await import('./plugins/vue-docgen');
plugins.push(vueDocgen(3);
} catch (err) {
if ((err as NodeJS.ErrnoException).code === 'MODULE_NOT_FOUND') {
throw new Error(
'@storybook/builder-vite requires vue-docgen-api to be installed ' +
'when using @storybook/vue3.' +
' Please install it and start storybook again.'
);
}
throw err;
}
}

if (framework === 'svelte') {
Expand Down

0 comments on commit 337ea70

Please sign in to comment.