Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: vite mergeConfig doesn't accept callback params #568

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions packages/histoire/src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,18 @@ export async function loadConfigFile (configFile: string): Promise<Partial<Histo
export const mergeConfig = createDefu((obj: any, key, value) => {
if (obj[key] && key === 'vite') {
const initialValue = obj[key]
if (typeof value === 'function') {
obj[key] = async (...args) => {
const result = await value(...args)
return mergeViteConfig(initialValue, result)
}
} else {
obj[key] = mergeViteConfig(initialValue, value)

// Convert to functions
const initialFn: (...args: any[]) => Promise<any> = typeof initialValue === 'function' ? initialValue : async () => initialValue
const valueFn: (...args: any[]) => Promise<any> = typeof value === 'function' ? value : async () => value

obj[key] = async (...args) => {
// `mergeViteConfig` doesn't accept functions so we need to call them
const initialResult = await initialFn(...args)
const valueResult = await valueFn(...args)
return mergeViteConfig(initialResult, valueResult)
}

return true
}

Expand Down
Loading