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

fix(schema): sync types of vite v3.x #7104

Merged
merged 2 commits into from
Aug 31, 2022
Merged

fix(schema): sync types of vite v3.x #7104

merged 2 commits into from
Aug 31, 2022

Conversation

brownsugar
Copy link
Sponsor Contributor

πŸ”— Linked issue

❓ 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

  1. globEager is deprecated
  2. add some types according to latest types
  3. glob will always exists in import.meta, I think there is no need to set it as an optional field here?
    If we try to use optional chain in the code, it will break this feature in Vite 3:
// Works in Vite 2 but not in Vite 3
const result = import.meta.glob?.('assets/images/svg/**/*.svg')
console.log(result) // `undefined` in Vite 3

// Works fine
const result = import.meta.glob('assets/images/svg/**/*.svg')
console.log(result) // { '.../...svg': () => import(...) }

πŸ“ Checklist

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

@netlify
Copy link

netlify bot commented Aug 31, 2022

βœ… Deploy Preview for nuxt3-docs canceled.

Name Link
πŸ”¨ Latest commit 4a1aa26
πŸ” Latest deploy log https://app.netlify.com/sites/nuxt3-docs/deploys/630f4f5e68897c000842a8eb


/** vite glob import utility - https://vitejs.dev/guide/features.html#glob-import */
globEager?(pattern: string, options?: ViteGlobOptions): Record<string, Record<string, any>>
glob (glob: string | string[], options?: ViteGlobOptions): Record<string, () => Promise<Record<string, any>>>
Copy link
Member

Choose a reason for hiding this comment

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

Tricky. This is meant to be optional as the declaration is also present in webpack builder.

It might be worth reconsidering whether we add these types within vite-builder rather than schema, so it can be more precisely targeted to both the vite version and the builder that is being used. wdyt @pi0?

Copy link
Member

Choose a reason for hiding this comment

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

I like the idea of moving types but that also makes a tricky question of how we tie vite versions to Nuxt releases (it uses caret). As you also mentioned, reason to have types here was that they are shared between different bundlers. I think we can revise this refactor later but you are right about being optional.

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
glob (glob: string | string[], options?: ViteGlobOptions): Record<string, () => Promise<Record<string, any>>>
glob?(glob: string | string[], options?: ViteGlobOptions): Record<string, () => Promise<Record<string, any>>>

Copy link
Member

@danielroe danielroe Aug 31, 2022

Choose a reason for hiding this comment

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

@brownsugar seemed to say that optional chaining would break the usage.

Copy link
Member

@pi0 pi0 Aug 31, 2022

Choose a reason for hiding this comment

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

It really seems a bug in vite to me with static replacement (import.meta by spec is an object while static replacement is not covering another valid syntax of optional chaining...)

Okay then let's keep it non optional until issue is fixed by either a refactor or upstream. Webpack is not that important for being optional (we might even polyfill import.meta.glob for webpack)

@pi0 pi0 changed the title feat(schema): sync types of vite v3.x fix(schema): sync types of vite v3.x Aug 31, 2022
@pi0 pi0 merged commit d50b01e into nuxt:main Aug 31, 2022
@pi0 pi0 mentioned this pull request Sep 1, 2022
@danielroe danielroe added the 3.x label Jan 19, 2023
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.

None yet

3 participants