Repository navigation
feat: dynamic data in defineRouteMeta - #3096
horvbalint wants to merge 4 commits into
Conversation
|
I had to add acorn as a dependency and use its parse method, because rollup's this.parse had some type mismatches with reality (start and end was not present in it). I am not sure however what the correct parse options would be. Other than that this appeats to be working fine. |
|
I'm very excited about this feature 😍. |
|
Hello guys, any updates on this feature? Would love to get my hands on this asap! |
|
Hi, Has there been any progress on this feature recently? |
|
Waiting for this feature to be added, this look really cool. Any progress or news on this? |
|
The PR is waiting on a review from Pooya, but it might not be merged at all, since it does not implement the feature in a way that was previously requested by him. I am also rooting for this feature, since I would use it a lot, but please don't leave comments with the intention to speed the process up, cause that will have an opposite effect. Pooya has many many stuff to work on (eg.: upcoming v3 release) and I am sure he will get to this PR once he has the time. If you want to show support, please simply leave a reaction :) |
|
Thanks for the PR and patience @horvbalint. We really need to keep supporting build-time evaluation for We might use either jiti or esbuild (or rolldown in the future), which are already deps to bundle (resolve imports, drop all side effects) then eval meta. Closing PR for clarity (tracker: #2974) if you could make a POC with above in implementations against |
|
@pi0 Thanks for the review. I would love to make this happen at build-time, but I have very little knowledge on how to do that. I suspected that jiti will be the solution and will try to poke around with it, but likely I will need some help on how to structure something like this. Is there a discrod or something where I can ask for some help if needed?
Edit: I seem to forget that defineRouteMeta is not only used for openApi stuff 😄 |
🔗 Linked issue
#2974
❓ Type of change
📚 Description
In this PR I tried to add a very basic implementation of dynamic data in defineRouteMeta. It does not evaluate the meta in build time so if an approach like this is not desired, feel free to close this PR :)
The basic idea is that since we are already creating a virtual file that exports the route meta object for every route, it would make sense to have the computation in these files as well. I am searching through the route file code until the macro invocation is found. Along the way relative imports are updated with their absolute path. If the macro is found, I discard the lines after it and replace it with a default export of its argument.
As an example this route:
is transformed into this virtual file:
Though this is a very simple idea, it is working surprisingly well, allowing us to do very nice things with it like:
The meta or parts of it can also come from imports, so we can create utilities, like:
Of course there is no shortage of drawbacks/todos either:
Relative imports can not be used in the macro📝 Checklist