Skip to content
This repository was archived by the owner on Apr 6, 2023. It is now read-only.
/frameworkPublic archive

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

Merged
pi0 merged 6 commits into
mainfrom
feat/unimport-dir-scan
Jul 21, 2022
Merged

feat(nuxt)!: only scan top level composables/ and support glob#6025
pi0 merged 6 commits into
mainfrom
feat/unimport-dir-scan

Conversation

@antfu

@antfuantfu commented Jul 21, 2022

Copy link
Copy Markdown
Member

🔗 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.tsexport{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:

exportdefaultdefineConfig({// ...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 pi0July 21, 2022 08:36
@netlify

netlifyBot commented Jul 21, 2022

Copy link
Copy Markdown

Deploy Preview for nuxt3-docs ready!

NameLink
🔨 Latest commitc49fcd8
🔍 Latest deploy loghttps://app.netlify.com/sites/nuxt3-docs/deploys/62d95c915021970009c0b934
😎 Deploy Previewhttps://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.

@danielroedanielroe left a comment

Copy link
Copy Markdown
Member

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

pi0 commented Jul 21, 2022

Copy link
Copy Markdown
Member

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
Copy Markdown
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

pi0 commented Jul 21, 2022

Copy link
Copy Markdown
Member

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
Copy Markdown
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

pi0 commented Jul 21, 2022

Copy link
Copy Markdown
Member

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

pi0 commented Jul 21, 2022

Copy link
Copy Markdown
Member

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

@antfu

Copy link
Copy Markdown
MemberAuthor

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

pi0
pi0 approved these changes Jul 21, 2022
@pi0

pi0 commented Jul 21, 2022

Copy link
Copy Markdown
Member

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

@pi0pi0 changed the title feat(auto-import)!: support glob in dirs and change scanning logicfeat(auto-import)!: support glob in composables/ and only scan top level Jul 21, 2022
@pi0pi0 changed the title feat(auto-import)!: support glob in composables/ and only scan top level feat(nuxt)!: only scan top level composables/ and support globJul 21, 2022
@pi0
pi0 merged commit 45c2a61 into mainJul 21, 2022
@pi0
pi0 deleted the feat/unimport-dir-scan branch July 21, 2022 14:04
@pi0pi0 mentioned this pull request Aug 5, 2022
@antfuantfu 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 freeto 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

@antfu@pi0@danielroe