-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
Allow plugins to return custom @babel/parser options in preprocessSource #6209
Conversation
Deploy preview for using-drupal ready! Built with commit f5186b8 |
Deploy preview for gatsbygram ready! Built with commit f5186b8 |
I feel like there should be seperate API for passing custom BABYLON_OPTIONS options. I didn't understand this change in isolation and needed to look on your other PR to get what this supposed. |
yeah I think ideally a plugin would use the babel options api for this or provide custom logic in the |
@pieh, @jquense I agree that ideally there would be a separate API. However I don't see the harm in going with this for the time being. Did you see the discussion here: #6174? @m-allanson, what are your thoughts? Also, looking way forward, perhaps the solution I outline in #6206 is the way to go in the long term. |
I think you currently can do this already via the babel api no? I f not i think it'd be more productive to add that API than extend this one :) |
The babel api is for configuring babel plugins, not the babel parser plugins. These are hard coded. In my estimation the benefits of implementing a new api for this is just not worth the trouble. Really the only reason I can see for wanting to change the default parser plugins is the case of typescript (the flow and the typescript plugins can't be enabled simultaneously). I'd say the choice is between the solution in this PR or the one in #6174, which is more complicated and less performant. Also note that the typescript plugin is broken until one of these gets merged. |
Any updates on this? |
Doing that isn't really difficult - You literally just add `apiRunner('') and add docs to , so only reason not to do that would be implications that this API should be stable - but this also true with modyfing already existing API. How about doing something like this: export function addBabylonConfig() {
return [
{
test: /\.tsx?$/,
options: PARSER_OPTIONS
}
]
} and then let gatsby pick proper parser options depending on extension and doing fallback to default if none of tests passed by plugins matched? |
I'm not sure i understand when these options would be used @pieh. From what i tell internal |
IMO, the question really boils down to if there is any broader use case for having to switch the PARSER_OPTIONS. If the only foreseeable use case is for typescript then maybe gatsby should just be swapping it out for TS files without the need for a public API? |
This PR is exactly about transforming TS to JS and then parsing that to ast , that it has unneeded steps that could be skipped - we just argued what's the best way :) My idea was to pick appropiate parserOptions to be used here
But I definitely get your point. Returning AST seems good - this does make sense in context of In any case, I won't oppose any solution here - my initial complaint now seems not productive and only blocked this from moving forward. |
I actually think maybe this is the best short term idea. I recently did this on another project (here) and it works nicely. My only concern here is that adding a sub optimal api for this is likely to lead us down a frustrating road as things get more complicated for other usecases, and so it'd be great to avoid it if possible. @pieh what do you think about just supporting Typescript "natively", since we effectively do that for flow now, there are only two real options in this space, and it's TS is the most popular anyway |
Very good point and I think it's best solution for now - we can always revisit it in the future without being tied to new or change APIs this way. @dennari What do You think? |
Both solutions, hardcoding another set of options for |
Since hardcoding the typescript support is the easier solution here, and if we're willing to do that, I'd probably choose that. I can create a new PR for that if we so agree. |
There is another place we have yet another config for parser options - gatsby/packages/gatsby/src/bootstrap/resolve-module-exports.js Lines 27 to 43 in 2acc8b9
Might be worth to consolidate those? |
yeah we need a "parse util" gatsby can export some plugins do this also, e.g. react-docgen |
👍 to hardcoding things. APIs are hard to do well and can be expensive to maintain (there's docs, support, bugs, etc). so we should avoid them when possible. |
Alright, created a new PR for this: #6335 |
No description provided.