fix(nuxt): augment GlobalComponents in multiple vue modules (#26541)

This commit is contained in:
Daniel Roe 2024-03-29 09:13:04 +00:00 committed by GitHub
parent 871404ae56
commit 22dfac7bd7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 31 additions and 6 deletions

View File

@ -109,12 +109,22 @@ export const componentsTypeTemplate = {
: c.filePath.replace(/(?<=\w)\.(?!vue)\w+$/g, ''), { wrapper: false })}['${c.export}']`
])
return `// Generated by components discovery
return `
interface _GlobalComponents {
${componentTypes.map(([pascalName, type]) => ` '${pascalName}': ${type}`).join('\n')}
${componentTypes.map(([pascalName, type]) => ` 'Lazy${pascalName}': ${type}`).join('\n')}
}
declare module '@vue/runtime-core' {
export interface GlobalComponents extends _GlobalComponents { }
}
declare module '@vue/runtime-dom' {
export interface GlobalComponents extends _GlobalComponents { }
}
declare module 'vue' {
export interface GlobalComponents {
${componentTypes.map(([pascalName, type]) => ` '${pascalName}': ${type}`).join('\n')}
${componentTypes.map(([pascalName, type]) => ` 'Lazy${pascalName}': ${type}`).join('\n')}
}
export interface GlobalComponents extends _GlobalComponents { }
}
${componentTypes.map(([pascalName, type]) => `export const ${pascalName}: ${type}`).join('\n')}

View File

@ -32,7 +32,22 @@ export default defineUntypedSchema({
*/
hoist: {
$resolve: (val) => {
const defaults = ['nitropack', 'defu', 'h3', '@unhead/vue', 'vue', 'vue-router', '@nuxt/schema', 'nuxt', 'consola', 'ofetch']
const defaults = [
// Nitro auto-imported/augmented dependencies
'nitropack',
'defu',
'h3',
'consola',
'ofetch',
// Key nuxt dependencies
'@unhead/vue',
'vue',
'@vue/runtime-core',
'@vue/runtime-dom',
'vue-router',
'@nuxt/schema',
'nuxt'
]
return val === false ? [] : (Array.isArray(val) ? val.concat(defaults) : defaults)
}
},