feat(glob-import): deprecate as option - #14420
Conversation
|
|
|
I wonder if we should think whether we want to migrate to import attributes from queries. |
|
It's still unclear how import attributes will go forward, and I'm leaning towards how the spec enforces it before we start implementing our custom handling. For example, the spec mentions:
So what Vite has to do at the end of the day is convert it to queries again, which I think it's better to go to queries directly. |
|
That makes sense 👍 |
There was a problem hiding this comment.
It would be great if we can infer the types from query property but I guess it's difficult to do it.
There was a problem hiding this comment.
Ah yeah I didn't notice as brings special default typings too. I guess they can still type it manually if needed, so it's not a huge issue.
It might be possible to infer it, but it very likely involves some dark magic and sacrifices.
| // validate `import` option based on `query` option (`as` is already handled above) | ||
| if (!opts.as && opts.query) { | ||
| if (urlRE.test(opts.query)) { | ||
| errorIfImportIsNotDefault(opts.import, '?url', optsStartIndex) | ||
| opts.import = opts.import || 'default' | ||
| } | ||
| if (rawRE.test(opts.query)) { | ||
| errorIfImportIsNotDefault(opts.import, '?raw', optsStartIndex) | ||
| opts.import = opts.import || 'default' | ||
| } | ||
| } |
There was a problem hiding this comment.
I feel it a bit too magic to change the default of import option based on query option. To me, as feels it might transform the output, but query only changes the query when imported.
That said, I think it'd be handy with this.
There was a problem hiding this comment.
That's true. I didn't think too much about it 🤔 I would be fine removing this and have the migration guide request adding import: 'default' too, especially given that this isn't typed anymore. Would you prefer that too?
There was a problem hiding this comment.
I removed the default import: 'default' configuration. This should make it more predictable.
|
cc @antfu requesting your review since you authored glob imports before, and have a recent |
|
Regardless of spec, I tend to prefer the I guess I am a bit conservative in general and I tend to keep things as-is if there is no much maintenance effort or absolute reason to drop something. Meanwhile, I understand you are trying to push a lot on removing things, huge respect here :). Thus I don't have a very strong opinion on this, we could move forward if the rest of the team agrees. |
|
I'm kind of in the same boat as @antfu here. The |
|
The main issue for me is that I don't think import assertions/attributes is going to solve queries. They're not exactly the same thing, and queries tend to be more flexible, compact, and subjectively readable (e.g. vite-imagetools API). There isn't a spec that covers it nicely yet, and I feel like that will be a lot of Vite majors away. But I'll keep this fair, and if there's another opposition to hold off for now I'll close the PR 👍 |
|
I'll move this off 5.0 for now. It actually seems that this can be done non-breakingly but the deprecation would have to come in a minor if we do so. |
|
Note to self: There's a bit more perf improvements I found especially:
I'll do this once the PR is merged so it's easier to review. |
sapphi-red
left a comment
There was a problem hiding this comment.
Just one small nit, the rest LGTM 👍
Co-authored-by: 翠 / green <green@sapphi.red>
Description
Deprecate the glob
asoption in favour ofquery. In practice they do the same thing, butqueryis more flexible and reuses the existing knowledge of?url,?raw,?workerqueries.Additional context
The gist of the changes are:
loggerinstance around to log a warning.aserror handling toqueryto keep feature parity.queryas astring, toparseGlobOptions(newParsedGeneralImportGlobOptionstype)asusage toquery.What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123).