Skip to content

Commit 9fe80f1

Browse files
committed
fix: fix storybook build
1 parent 670f700 commit 9fe80f1

5 files changed

Lines changed: 48 additions & 14 deletions

File tree

.storybook/main.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,38 @@ const config = {
77
features: {
88
backgrounds: false,
99
},
10+
async viteFinal(config) {
11+
// Replace the built-in vue-docgen plugin with a fault-tolerant version.
12+
// vue-docgen-api can crash on components that import types from other
13+
// .vue files (it tries to parse the SFC with @babel/parser as plain TS).
14+
// This wrapper catches those errors so the build doesn't fail.
15+
const docgenPlugin = config.plugins?.find(
16+
(p): p is Extract<typeof p, { name: string }> =>
17+
!!p && typeof p === 'object' && 'name' in p && p.name === 'storybook:vue-docgen-plugin',
18+
)
19+
20+
if (docgenPlugin && 'transform' in docgenPlugin) {
21+
const hook = docgenPlugin.transform
22+
// Vite plugin hooks can be a function or an object with a `handler` property
23+
const originalFn = typeof hook === 'function' ? hook : hook?.handler
24+
if (originalFn) {
25+
const wrapped = async function (this: unknown, ...args: unknown[]) {
26+
try {
27+
return await originalFn.apply(this, args)
28+
} catch {
29+
return undefined
30+
}
31+
}
32+
if (typeof hook === 'function') {
33+
docgenPlugin.transform = wrapped as typeof hook
34+
} else if (hook) {
35+
hook.handler = wrapped as typeof hook.handler
36+
}
37+
}
38+
}
39+
40+
return config
41+
},
1042
} satisfies StorybookConfig
1143

1244
export default config

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1000,8 +1000,8 @@ Global application settings are added to the Storybook toolbar for easy testing
10001000
10011001
- Changing `i18n` in the toolbar doesn't update the language. A manual story reload is required.
10021002
- `autodocs` currently is non-functional due bugs, its usage is discouraged at this time.
1003-
- `pnpm build-storybook` currently fails, use `pnpm storybook` to view the stories for the time being.
10041003
- `pnpm storybook` may log warnings or non-breaking errors for Nuxt modules due to the lack of mocks. If the UI renders correctly, these can be safely ignored.
1004+
- Do not `import type` from `.vue` files. The `vue-docgen-api` parser used by `@storybook/addon-docs` cannot follow type imports across SFCs and will crash. Extract shared types into a separate `.ts` file instead.
10051005
10061006
## Submitting changes
10071007

app/components/Select/Base.vue

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,8 @@
11
<script setup lang="ts">
2-
const model = defineModel<string | undefined>({ default: undefined })
3-
4-
const SELECT_SIZES = {
5-
none: '',
6-
sm: 'text-xs px-2 py-1.75 rounded-md',
7-
md: 'text-sm px-3 py-2.25 rounded-lg',
8-
lg: 'text-base px-6 py-4 rounded-xl',
9-
}
2+
import type { SelectBaseProps } from './types'
3+
import { SELECT_SIZES } from './types'
104
11-
export type SelectBaseProps = {
12-
disabled?: boolean
13-
size?: keyof typeof SELECT_SIZES
14-
}
5+
const model = defineModel<string | undefined>({ default: undefined })
156
167
const props = withDefaults(defineProps<SelectBaseProps>(), {
178
size: 'md',

app/components/Select/Field.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script setup lang="ts">
2-
import type { SelectBaseProps } from './Base.vue'
2+
import type { SelectBaseProps } from './types'
33
44
const SELECT_FIELD_SIZES = {
55
sm: 'text-xs py-1.75 ps-2 pe-6 rounded-md',

app/components/Select/types.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export const SELECT_SIZES = {
2+
none: '',
3+
sm: 'text-xs px-2 py-1.75 rounded-md',
4+
md: 'text-sm px-3 py-2.25 rounded-lg',
5+
lg: 'text-base px-6 py-4 rounded-xl',
6+
}
7+
8+
export type SelectBaseProps = {
9+
disabled?: boolean
10+
size?: keyof typeof SELECT_SIZES
11+
}

0 commit comments

Comments
 (0)