-
Notifications
You must be signed in to change notification settings - Fork 10.3k
fix(gatsby-plugin-netlify-cms): exclude node_modules from cms #15191
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
Conversation
@erquhart Can you give some context, maybe the original issue or a explanation of the regression? I just ran into some issues while updating my site but was able to get it to build and deploy. It appears to be working. see #15190 for my troubles. P.S. I'm mostly just curious and want to understand...not saying you're incorrect. |
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.
Seems like I can't fix it from inside gatsby.
I inlined some of your replace functions, didn't seemed necessary to abstract it away. made it harder to read for me.
Awesome work! when everything is green let me merge and get this patched. Thank you for making gatsby better! 👍
@wardpeet thanks for the edits! I think I might see a couple of issues, let me give a quick look before you merge, I'll be at my machine soon. |
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.
@wardpeet I added a few comments - the gist is that, we should be using safe methods like lodash.get
and castArray
here. This plugin is coloring outside the lines of Gatsby's API, constructing a Webpack config from the raw received config, and there are no guarantees as to what that object will look like.
Performance is also not an issue as this whole thing runs more or less instantaneously, and only once per build.
@@ -33,6 +27,38 @@ function deepMap(obj, fn) { | |||
return obj | |||
} | |||
|
|||
function replaceRule(value) { | |||
// If `value` does not have a `test` property, it isn't a rule object. | |||
if (!value || !value.test) { |
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.
value
could be a string - we're recursing the entire received object, in which case !value.test
would throw. Rather than first making sure it's an object and risking some other unforeseen issue, we should just go bulletproof with lodash.get
.
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 test is a string it will give a falsy value (undefined) when value.test
is used. So no harm here, thanks for bringing it up to my attention.
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.
No, value
could be a string. This will throw for some users.
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.
@erquhart do you have an example?
var a = 'node_modules' // or var a = ''
if (!a || !a.test) {
// we will be in this block
}
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.
Hmm not sure why I was thinking that would throw as if value
is undefined. I know I ran into issues deep mapping the webpack config and needed safe getters, but you're right, this wouldn't be an issue at this line.
return { | ||
...value, | ||
exclude: new RegExp( | ||
[value.exclude.source, `node_modules|bower_components`].join(`|`) |
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.
We don't know for sure that the exclude
is and will continue to be a RegExp, it could easily be an array. castArray
is the safe route, its guaranteed not to fail, we always know what we're getting, and the output is equally compatible with Webpack.
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.
I'm checking that it's a regex now. If people have a custom js rule they should make sure to exclude node_modules themselves.
@moonmeister ah, your issue is exactly what this addresses, I'll comment there. |
@wardpeet sorry to bug! Any chance of getting this in before the weekend? Bit of a showstopper for affected users. |
[email protected] Build failure gatsbyjs/gatsby#15190 (comment) > gatsby-plugin-netlify-cms runs an independent Webpack build within > Gatsby's Webpack build (insert "yo dawg" reference here) using a > modified version of the Gatsby Webpack config. Gatsby 2.11.0 no longer > excludes node_modules, which causes the plugin's Webpack build to attempt > processing the Netlify CMS modules with Babel. The modules are massive > and also prebuilt, so it will (and should) crash your system. > The PR I raised fix(gatsby-plugin-netlify-cms): exclude node_modules from cms builds gatsbyjs/gatsby#15191 > just adds that exclusion back in to the plugin's Webpack config. > Please don't override your node max file size limit to fix this! feat(gatsby): enable babel-loader for all dependencies gatsbyjs/gatsby#14111
Will any additional changes be needed for a developer who uses the plugin & uses Yarn's PnP feature? |
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.
Updated PR, thanks @erquhart for bringing those thinks to my attention
@moonmeister, it's just an out of memory as the cms.js bundle is about 3mb if not mistaken and a bit much to store in memory it seems.
@@ -33,6 +27,38 @@ function deepMap(obj, fn) { | |||
return obj | |||
} | |||
|
|||
function replaceRule(value) { | |||
// If `value` does not have a `test` property, it isn't a rule object. | |||
if (!value || !value.test) { |
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 test is a string it will give a falsy value (undefined) when value.test
is used. So no harm here, thanks for bringing it up to my attention.
return { | ||
...value, | ||
exclude: new RegExp( | ||
[value.exclude.source, `node_modules|bower_components`].join(`|`) |
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.
I'm checking that it's a regex now. If people have a custom js rule they should make sure to exclude node_modules themselves.
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.
Thank you for getting this fixed @erquhart! ❤️
Took another look based on @DSchau's comment on the review, and you're right, |
@wardpeet @erquhart In case it helps figure any of this out, this repo that uses Netlify CMS is still broken under |
Description
#14111 caused a regression for
gatsby-plugin-netlify-cms
, which reuses a modified version of Gatsby's final webpack config and requires thatnode_modules
be excluded from all builds. This PR adds the exclusion directly to the plugin.Related to #15190