Skip to content

Conversation

cernymatej
Copy link
Contributor

@cernymatej cernymatej commented Aug 29, 2025

πŸ”— Linked issue

❓ Type of change

  • πŸ“– Documentation (updates to the documentation, readme or JSdoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to 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

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@sadeghbarati
Copy link
Collaborator

sadeghbarati commented Sep 2, 2025

Hi πŸ‘‹

simple way is just don't use shadcn-nuxt. right? cause the shadcn-nuxt goal is to auto-import the components in the ui directory

if you don't want auto-import for ui just don't use it

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 ui dir you can use

export default defineNuxtConfig({
  hooks: {
    'components:dirs'(dirs) {
      dirs.unshift({
        path: '@/components/ui',
        extensions: [],
      })
    },
  }
})

@cernymatej
Copy link
Contributor Author

Hmm, I guess yeah, since it currently doesn't do anything else πŸ˜„
But it's probably a good idea to await it, isn't it?

@sadeghbarati
Copy link
Collaborator

await what line of code can you point it?

@cernymatej
Copy link
Contributor Author

https://github.com/unovue/shadcn-vue/pull/1398/files#diff-e8b52a811377c3181637938504d1ac1400a62288c80a9a73aae897ac6fee3457R64

currently, there's just a foreach, and I think that in some cases, only some of the components will get registered for auto-imports

try {
readdirSync(componentsPath)
.forEach(async (dir) => {
try {
const filePath = await resolvePath(join(COMPONENT_DIR_PATH, dir, 'index'), { extensions: ['.ts', '.js'] })

(depending on how long other modules take to install)

@sadeghbarati
Copy link
Collaborator

sadeghbarati commented Sep 2, 2025

Right, await must be in the setup scope, could you remove autoImport code and replace this block of code, Thanks

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)
}

@cernymatej cernymatej changed the title feat: add support for disabling auto-imports of components fix: await component registration Sep 2, 2025
@sadeghbarati sadeghbarati changed the title fix: await component registration fix(module): await component registration Sep 2, 2025
@sadeghbarati sadeghbarati merged commit ecbc09a into unovue:dev Sep 2, 2025
@sadeghbarati
Copy link
Collaborator

Thank You

@cernymatej cernymatej deleted the feat-support-for-disabling-auto-imports branch September 2, 2025 07:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants