Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Align glob raw support syntax with future standards #7017

Closed
4 tasks done
patak-dev opened this issue Feb 21, 2022 · 3 comments
Closed
4 tasks done

Align glob raw support syntax with future standards #7017

patak-dev opened this issue Feb 21, 2022 · 3 comments
Labels
p4-important Violate documented behavior or significantly improves performance (priority)

Comments

@patak-dev
Copy link
Member

Clear and concise description of the problem

We added support for raw glob imports in Vite 2.8 (#5545), trying to align the syntax with the import assertions proposal:

const examples = import.meta.glob('./examples/*.html', { assert: { type: 'raw' }})

@lucacasonato is pointing out that the import reflection proposal should have been used instead.

We should avoid moving more suffix-based modifiers until it is more clear how these proposals will evolve. For the glob raw syntax, let's discuss if we should mark it as deprecated and prepare users to move to a more aligned syntax once we release Vite 3.0

Suggested solution

Deprecate { assert: { type: 'raw' }}, delay further changes in import modifiers

Alternative

No response

Additional context

See twitter thread

Validations

@patak-dev patak-dev added enhancement: pending triage p4-important Violate documented behavior or significantly improves performance (priority) and removed enhancement: pending triage labels Feb 21, 2022
@yyx990803
Copy link
Member

yyx990803 commented Feb 21, 2022

I saw the conversation on Twitter and it confirms my impression that import assertions should not affect module evaluation semantics. However, the import reflection proposal will likely take quite some time to go through (if it ever does). I do like the as syntax though.

Either way, we should stop leaning on import assertions as transform hints.

To align with the current import reflections spec, the glob import should be changed to:

const examples = import.meta.glob('./examples/*.html', { as: 'raw' })

We can deprecate the previous syntax and mark this one as experimental so that we can adjust it per spec. I think it's safe to do so because even if the spec changes, the required code change will likely be trivial and can be done automatically across the codebase. If the spec doesn't go through, I still think as: 'raw' is a nice API.

In the meanwhile, we should keep the current query-based hints until import reflections goes stage 3.

@patak-dev
Copy link
Member Author

We talked about this PR and we think we should add { as: 'raw' } for glob import marked as experimental in Vite 2.9 and deprecate the { assert: { type: 'raw' }} syntax. We can then remove the assert syntax in Vite 3.0 at the beginning of May.

brillout added a commit to brillout/vite that referenced this issue Mar 7, 2022
 vitejs#7017)

BREAKING CHANGE: Use `import.meta.globEager('/dir/*.js', { as: 'raw' })` instead of `import.meta.globEager('/dir/*.js', { assert: { type: 'raw' } })` (it will be deprecated in Vite 3.0).
brillout added a commit to brillout/vite that referenced this issue Mar 7, 2022
 vitejs#7017)

BREAKING CHANGE: Use `import.meta.globEager('/dir/*.js', { as: 'raw' })` instead of `import.meta.globEager('/dir/*.js', { assert: { type: 'raw' } })` (it will be deprecated in Vite 3.0).
@brillout
Copy link
Contributor

brillout commented Mar 7, 2022

We talked about this PR and we think we should add { as: 'raw' } for glob import marked as experimental in Vite 2.9 and deprecate the { assert: { type: 'raw' }} syntax. We can then remove the assert syntax in Vite 3.0 at the beginning of May.

PR implementing this: #7215.

brillout added a commit to brillout/vite that referenced this issue Mar 7, 2022
 vitejs#7017)

BREAKING CHANGE: Use `import.meta.globEager('/dir/*.js', { as: 'raw' })` instead of `import.meta.globEager('/dir/*.js', { assert: { type: 'raw' } })` (it will be deprecated in Vite 3.0).
@github-actions github-actions bot locked and limited conversation to collaborators Mar 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
p4-important Violate documented behavior or significantly improves performance (priority)
Projects
Archived in project
Development

No branches or pull requests

3 participants