-
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
chore(gatsby): convert babel-loader-helpers to typescript #25100
chore(gatsby): convert babel-loader-helpers to typescript #25100
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this. The typecheck tests are failing for this, largely because you'll need to update the babel tests to cast the Mock types. Make sure you run yarn typecheck to ensure it's all working.
@@ -16,13 +29,23 @@ const loadCachedConfig = () => { | |||
return pluginBabelConfig | |||
} | |||
|
|||
const getCustomOptions = stage => { | |||
export const getCustomOptions = (stage: string): IBabelStage["options"] => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a string enum Stage
which should be used for the argument here. You'll find it in commands/types.ts
const index = _.findIndex( | ||
items, | ||
i => i.file.resolved === itemToMerge.file.resolved | ||
i => i.file!.resolved === itemToMerge.file!.resolved |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use optional chaining rather than not-null assertion here and elsewhere, so avoid potential runtime errors
Thank you @ascorbic for the review. I updated the test types, the snapshots, and used the I added a 👍 on your comments to indicate I solved the issues. If you feel the feedback was addressed properly, feel free to resolve the conversations! |
pluginBabelConfig.stages[stage].plugins.forEach(plugin => { | ||
const reduxPlugins: PluginItem[] = [] | ||
const reduxPresets: PluginItem[] = [] | ||
pluginBabelConfig.stages[stage!].plugins.forEach(plugin => { | ||
reduxPlugins.push( | ||
babel.createConfigItem([resolve(plugin.name), plugin.options], { | ||
name: plugin.name, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this is an error. It seems it's correct that name
isn't a valid key. It accepts just dirname
and type
: https://babeljs.io/docs/en/babel-core#createconfigitem
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think would be the best option here? I'm not sure how it will affect prod to remove the name
key.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a few nits, though we'll need to check what's goign on with the name
prop, which seems to be an error.
const pluginBabelConfig = loadCachedConfig() | ||
return pluginBabelConfig.stages[stage].options | ||
} | ||
|
||
const prepareOptions = (babel, options = {}, resolve = require.resolve) => { | ||
let pluginBabelConfig = loadCachedConfig() | ||
type prepareOptionsType = ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than typing the whole function like this, can you just type the options object?
pluginBabelConfig.stages[stage].plugins.forEach(plugin => { | ||
const reduxPlugins: PluginItem[] = [] | ||
const reduxPresets: PluginItem[] = [] | ||
pluginBabelConfig.stages[stage!].plugins.forEach(plugin => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you've typed the options, and the stage key as optional you'll need a runtime null check for stage
rather than this assertion.
reduxPlugins.push( | ||
babel.createConfigItem([resolve(plugin.name), plugin.options], { | ||
name: plugin.name, | ||
type: `plugin`, | ||
}) | ||
) | ||
}) | ||
pluginBabelConfig.stages[stage].presets.forEach(preset => { | ||
pluginBabelConfig.stages[stage!].presets.forEach(preset => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same. If you've done a runtime check then this will have been narrowed to exclude null.
@@ -98,17 +122,34 @@ const prepareOptions = (babel, options = {}, resolve = require.resolve) => { | |||
] | |||
} | |||
|
|||
const mergeConfigItemOptions = ({ items, itemToMerge, type, babel }) => { | |||
type mergeConfigItemOptionsType = ({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As above, rather than typing the whole function like this, type the props object.
…atsby-babel-loader-helpers
Addressed the second wave of feedback, let me know your opinion about the |
Hey! Thanks so much for opening this pull request! Sadly this PR got stale and didn't have any activity for some time. We're trying to do better with PR reviews! To get a better overview of all actionable PRs we're going through all open PRs and triage them. Since we won't be able to do everything and adding new features always means added maintenance burden, we have to be more picky about what's beneficial for the average user and the project itself longterm. We think this is a great PR and would love to see it land in Gatsby. We're closing this PR for now but if you're able to rebase onto the latest We absolutely want to have you as a contributor and are sorry for any inconveniences we caused with replying too late to this PR. Thanks for submitting to Gatsby! 💜 |
Convert babel-loader-helpers to TS.
On line
101
and109
, I get a type error that I am not able to fix related to@babel/core
types not allowingcreateConfigItem
to have aname
key in its payload.I'm not sure why tests are failing, other than the imports, the types shouldn't have affected prod. Any insights on what is causing it? Switching back the
babel-loader
imports doesn't do anything.Related Issues
#21995