Repository: nuxt/nuxt
File: packages/nuxt/src/imports/module.ts (TypeScript)

Code before:
    const regenerateImports = async () => {
      await ctx.modifyDynamicImports(async (imports) => {
        // Clear old imports
        imports.length = 0

        // Scan for `composables/` and `utils/` directories
        if (options.scan) {
          const scannedImports = await scanDirExports(composablesDirs, {
            fileFilter: file => !isIgnored(file),
          })
          for (const i of scannedImports) {
            i.priority ||= priorities.find(([dir]) => i.from.startsWith(dir))?.[1]
          }
          imports.push(...scannedImports)
        }

        // Modules extending
        await nuxt.callHook('imports:extend', imports)

        const nuxtImportNames = new Set(
          await Promise.all(imports.map(
            async i => (NUXT_APP_RE.test(i.from) || (await resolvePath(i.from)).startsWith(distDir))
              ? i.name
              : null,
          )).then(r => r.filter(Boolean)),
        )

        for (const i of imports) {
          const value = i.as || i.name
          if (
            // import name is the same as a nuxt import
            (nuxtImportNames.has(value) || nuxtImportNamesFromPresets.has(value))
              // source is outside nuxt
              && !((await resolvePath(i.from)).startsWith(distDir))
              // isn't an intentional override (by a module, for example)
              && (!i.priority || i.priority >= 0 /* default priority */)
          ) {
            const relativePath = isAbsolute(i.from) ? `${resolveToAlias(i.from, nuxt)}` : i.from
            logger.error(`\`${value}\` is an auto-imported function that is in use by Nuxt. Overriding it will likely cause issues. Please consider renaming \`${value}\` in \`${relativePath}\`.`)
          }
        }

        return imports
      })

      await updateTemplates({
        filter: isImportsTemplate,
      })
    }

    await regenerateImports()

Review comment (performance):
we could probably get rid of this to avoid slowing down the import re-generation if there was a convention, that internal imports would be added only via `imports:sources`

Code after:
          for (const i of scannedImports) {
            i.priority ||= priorities.find(([dir]) => i.from.startsWith(dir))?.[1]
          }
          imports.push(...scannedImports)
        }

        // Modules extending
        await nuxt.callHook('imports:extend', imports)
        for (const i of imports) {
          if (!nuxtImportSources.has(i.from)) {
            const value = i.as || i.name
            if (nuxtImports.has(value) && (!i.priority || i.priority >= 0 /* default priority */)) {
              const relativePath = isAbsolute(i.from) ? `${resolveToAlias(i.from, nuxt)}` : i.from
              logger.error(`\`${value}\` is an auto-imported function that is in use by Nuxt. Overriding it will likely cause issues. Please consider renaming \`${value}\` in \`${relativePath}\`.`)
            }
          }
        }

        return imports
      })

      await updateTemplates({
        filter: isImportsTemplate,
      })
    }

    await regenerateImports()

    // Generate types
    addDeclarationTemplates(ctx, options)

    // Watch composables/ directory
    nuxt.hook('builder:watch', async (_, relativePath) => {
      const path = resolve(nuxt.options.srcDir, relativePath)
      if (options.scan && composablesDirs.some(dir => dir === path || path.startsWith(dir + '/'))) {
        await regenerateImports()
      }
    })

    // Watch for template generation
    nuxt.hook('app:templatesGenerated', async (_app, templates) => {
      // Only regenerate when non-imports templates are updated
      if (templates.some(t => !isImportsTemplate(t))) {
        await regenerateImports()
      }
    })
  },
})

function addDeclarationTemplates (ctx: Unimport, options: Partial<ImportsOptions>) {
  const nuxt = useNuxt()