-
-
Notifications
You must be signed in to change notification settings - Fork 533
fix(module): await component registration #1398
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(module): await component registration #1398
Conversation
Hi π simple way is just don't use if you don't want auto-import for or if you want to disabled auto-import fully use export default defineNuxtConfig({
imports: {
autoImport: false,
scan: false,
}
}) or if you want to disable auto-import only for export default defineNuxtConfig({
hooks: {
'components:dirs'(dirs) {
dirs.unshift({
path: '@/components/ui',
extensions: [],
})
},
}
}) |
Hmm, I guess yeah, since it currently doesn't do anything else π |
await what line of code can you point it? |
currently, there's just a foreach, and I think that in some cases, only some of the components will get registered for auto-imports shadcn-vue/packages/module/src/module.ts Lines 56 to 60 in d90434f
(depending on how long other modules take to install) |
Right, await must be in the setup scope, could you remove Details
try {
const componentPromises = readdirSync(componentsPath)
.map(async (dir) => {
try {
const filePath = await resolvePath(join(COMPONENT_DIR_PATH, dir, 'index'), { extensions: ['.ts', '.js'] })
const content = readFileSync(filePath, { encoding: 'utf8' })
const ast = parseSync(filePath, content, {
sourceType: 'module',
})
const exportedKeys: string[] = ast.program.body
.filter(node => node.type === 'ExportNamedDeclaration')
// @ts-expect-error parse return any
.flatMap(node => node.specifiers?.map(specifier => specifier.exported?.name) || [])
.filter((key: string) => /^[A-Z]/.test(key))
exportedKeys.forEach((key) => {
addComponent({
name: `${prefix}${key}`, // name of the component to be used in vue templates
export: key, // (optional) if the component is a named (rather than default) export
filePath: resolve(filePath),
priority: 1,
})
})
}
catch (err) {
if (err instanceof Error)
console.warn('Module error: ', err.message)
}
})
await Promise.all(componentPromises)
}
catch (err) {
if (err instanceof Error)
console.warn(err.message)
} |
Thank You |
π Linked issue
β Type of change
π Description
Since the promises in the component registration were not being awaited, it could cause some components to not be registered for auto-imports.
πΈ Screenshots (if appropriate)
π Checklist