-
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
feat(gatsby-plugin-utils): save validation resulting value to plugin options #27381
feat(gatsby-plugin-utils): save validation resulting value to plugin options #27381
Conversation
…nd us extends to extend Joi types, feat: save validation results back into plugin 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.
Some comments on the code and questions.
// All plugins have "plugins: []"" added to their options in load.ts, even if they | ||
// do not have subplugins. We add plugins to the schema if it does not exist already | ||
// to make sure they pass validation. | ||
if (typeof plugin.pluginOptions === `undefined`) { |
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.
for some reason pluginOptions
can be undefined, so I've handled that case (thanks ts).
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.
Do you have a repro cause it shouldn't
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.
Not specifically. But type script believed it could be. I'm guessing TS is wrong but I didn't try and hunt down where that was coming from. I can try and figure that out and let you know.
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.
that means our gatsby types are wrong I guess ^^
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.
@mxstbr this can be done in a follow-up PR but I would like to see where this comes from cause it means something in our types are wrong
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.
gatsby/packages/gatsby/src/bootstrap/load-plugins/types.ts
Lines 22 to 24 in 10d3451
/** Options passed to the plugin */ | |
pluginOptions?: IPluginInfoOptions | |
} |
"peerDependencies": { | ||
"gatsby": "^2.24.73" | ||
}, |
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.
sweet, this is better 👍
Note: after shipping this we're going to have to bump the minimum supported |
Note: I had to re-add gatsby as a devDependency in 52118ee as we rely on importing some types from it, which otherwise didn't exist when only specified as a peerDep as far as I can tell! |
@mxstbr I've lost track on what needs to be done. Are you waiting on me for anything? |
@moonmeister no, I went ahead and cleaned everything up! This just needs another code review 😊 |
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 good, One small follow up request.
// All plugins have "plugins: []"" added to their options in load.ts, even if they | ||
// do not have subplugins. We add plugins to the schema if it does not exist already | ||
// to make sure they pass validation. | ||
if (typeof plugin.pluginOptions === `undefined`) { |
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.
@mxstbr this can be done in a follow-up PR but I would like to see where this comes from cause it means something in our types are wrong
@@ -26,6 +26,8 @@ export { | |||
withAssetPrefix, | |||
} from "gatsby-link" | |||
|
|||
export { IPluginInfoOptions } from "./src/bootstrap/load-plugins/types" | |||
|
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.
This line broke TypeScript types as the src folder is not included in the distribution, so you get...
node_modules/gatsby/index.d.ts:29:36 - error TS2307: Cannot find module './src/bootstrap/load-plugins/types' or its corresponding type declarations.
29 export { IPluginInfoOptions } from "./src/bootstrap/load-plugins/types"
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.
Could you open a new issue for this please? 🙏
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.
…options (gatsbyjs#27381) * misc: fix various validation issues in plugin-utils, uncopy typings and us extends to extend Joi types, feat: save validation results back into plugin options. * fix: add missing comment * fix: add missing comment * fix: move gatsby to peer dep * Undo Joi change * Add test for this * Update tests that are failing with new functionality * Add gatsby as a devDep to gatsby-plugin-utils as we need the types * Maybe fix type import Co-authored-by: Max Stoiber <[email protected]>
Description
Some cleanup but more importantly saving results of Joi validation back to pluginOptions.
Documentation
I think @mxstbr is working on this but happy to add anything that's needed.