Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

feat(nuxt)!: only scan top level composables/ and support glob #6025

Merged
merged 6 commits into from
Jul 21, 2022

Conversation

antfu
Copy link
Member

@antfu antfu commented Jul 21, 2022

πŸ”— Linked issue

unjs/unimport#86 (comment)

Unimport upgraded from 0.4.x to 0.6.x in #6032

❓ Type of change

  • πŸ“– Documentation (updates to the documentation or readme)
  • 🐞 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)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

This PR changes auto-imports' behavior to exclude nested folders from auto-imports.

To get auto imports for nested modules, you can re-export them from composables/index.ts (see alternative below)

// composables/index.ts
export { usebar } from './utils/bar.ts'

πŸ‘‰ Migration

⚠️ Breaking change: composables/*/index.ts is no longer being scanned and you need to reexport. In order to preserve previous behavior, please configure autoImports.dirs:

export default defineConfig({
  // ...
  autoImports: {
    dirs: [
      'composables', // top-level modules
      'composables/*/index.{ts,js,mjs,mts}' // one level directories's index.js,
      //'composables/**', // Scan all nested directories
    ]
  }
})

πŸ“ Checklist

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

@antfu antfu requested review from danielroe and pi0 July 21, 2022 08:36
@netlify
Copy link

netlify bot commented Jul 21, 2022

βœ… Deploy Preview for nuxt3-docs ready!

Name Link
πŸ”¨ Latest commit c49fcd8
πŸ” Latest deploy log https://app.netlify.com/sites/nuxt3-docs/deploys/62d95c915021970009c0b934
😎 Deploy Preview https://deploy-preview-6025--nuxt3-docs.netlify.app
πŸ“± Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

Copy link
Member

@danielroe danielroe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

@pi0
Copy link
Member

pi0 commented Jul 21, 2022

Seems a good defaults change to simplify scanning with top level only. Can you please:

  • Update PR description for breaking change and migration guide (to link from release notes)
  • Split the nested composables example from simple one to the end of docs page
  • Suggest composables/index.ts for reexports
  • Swap two options for nested to prefer top-level file over configuration

@danielroe
Copy link
Member

Updated migration guide whilst @pi0 was reviewing. One thought: we should also update logic for other scanned directories, likely in same PR to reduce breaking change.

@pi0
Copy link
Member

pi0 commented Jul 21, 2022

surely we need to make scanned directories to a closer behavior. But let's keep changes splitted. @danielroe What other dirs are you thinking?

@danielroe
Copy link
Member

Plugins currently have this /index behaviour. Middleware and layouts are also scanned at a single level with no way to configure it. (Which might be okay, but see also #5842.)

@pi0
Copy link
Member

pi0 commented Jul 21, 2022

Strict behavior of middleware/layouts makes sense. We can add option later without breaking changes. (breaking) Change for plugins makes sense with same next release πŸ‘πŸΌ

@pi0
Copy link
Member

pi0 commented Jul 21, 2022

PR description: I would suggest to add top level index.ts reexport (convention over configuration) as recommended migration path.

@antfu
Copy link
Member Author

antfu commented Jul 21, 2022

Migration guide updated. Let me know if you have any other suggestion, or update it directly :)

@pi0
Copy link
Member

pi0 commented Jul 21, 2022

(upgraded mistakenly merged via previous #6032 PR). Latest edge release contains the changes via merge commit of this.

@pi0 pi0 changed the title feat(auto-import)!: support glob in dirs and change scanning logic feat(auto-import)!: support glob in composables/ and only scan top level Jul 21, 2022
@pi0 pi0 changed the title feat(auto-import)!: support glob in composables/ and only scan top level feat(nuxt)!: only scan top level composables/ and support glob Jul 21, 2022
@pi0 pi0 merged commit 45c2a61 into main Jul 21, 2022
@pi0 pi0 deleted the feat/unimport-dir-scan branch July 21, 2022 14:04
@pi0 pi0 mentioned this pull request Aug 5, 2022
@antfu antfu mentioned this pull request Aug 8, 2022
4 tasks
HomWang added a commit to HomWang/framework that referenced this pull request Aug 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants