You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'd like to be able to modify top-level declarations within a module to, for example, modify objects that are exported in a separate statement. Something like:
// currently, there's no magicast-native way of accessing this declarationconstmyConfig=defineConfig({/*...*/})exportdefaultmyConfig;
I'm using magicast in a script that's supposed to modify a user's vite.config.js and this quite common way of specifying a vite config unfortunately causes problems.
API proposal:
I'm thinking about something along these lines:
constoriginalCode=` const myConfig = defineConfig({/*...*/}) export default myConfig;`constmod=parseModule(originalCode);// example modificationmod.$declarations.myConfig=builders.raw(...)
Once we have a way of accessing/modifying declarations, we could for example adjust theaddVitePlugin helper to use the $declarations field to adjust the config object if it is not directly default-exported.
I'm happy to give this a try to implement but I'd like to hear your thoughts around this first.
This is somewhat related to #45 but I believe modifying/parsing existing declarations isn't discussed in this issue.
Limitations
I think we need to accept that we couldn't possibly handle all kinds of declarations or complex syntax within them but for starters, I believe handling object declarations or function calls (like defineConfig) might be enough.
Additional information
Would you be willing to help implement this feature?
The text was updated successfully, but these errors were encountered:
An alternative would be to directly link to the actual declaration in the mod.exports.default property. While more convenient, I'd argue it's quite a diversion from representing an AST data structure. Also not sure which of the two options would be easier to implement
Describe the feature
I'd like to be able to modify top-level declarations within a module to, for example, modify objects that are exported in a separate statement. Something like:
I'm using
magicast
in a script that's supposed to modify a user'svite.config.js
and this quite common way of specifying a vite config unfortunately causes problems.API proposal:
I'm thinking about something along these lines:
Once we have a way of accessing/modifying declarations, we could for example adjust the
addVitePlugin
helper to use the$declarations
field to adjust the config object if it is not directly default-exported.I'm happy to give this a try to implement but I'd like to hear your thoughts around this first.
This is somewhat related to #45 but I believe modifying/parsing existing declarations isn't discussed in this issue.
Limitations
I think we need to accept that we couldn't possibly handle all kinds of declarations or complex syntax within them but for starters, I believe handling object declarations or function calls (like
defineConfig
) might be enough.Additional information
The text was updated successfully, but these errors were encountered: