-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Build: Add pragma check webpack plugin for server side rendering #1801
Conversation
Nice :) |
9171379
to
c03c9bf
Compare
/cc @mcsf for a pre-'Needs Review' review :) |
c03c9bf
to
ae0f329
Compare
It doesn't seem to adversely affect build perf. I ran a few tests vs master, and the build times were pretty similar — this PR being faster for some tests, slower for others… |
2d643e8
to
7a80f51
Compare
DevX concern -- if I screw up SSR and forget to restart Calypso, how will I know I messed up? Shouldn't there be some test that also fails? (In order to e.g. prevent merges via CircleCI.) |
The |
Noting that we'll only fail it here if, say, a dependency not marked as It doesn't do anything clever, so won't catch any SSR-incompatible code errors. Maybe we could check for stuff like |
|
||
module.dependencies.forEach( function( dep ) { | ||
// If the module is compiled through babel, we can be pretty sure it's our own module, not from npm. | ||
if ( dep.module && /babel-loader/.test( dep.module.request ) && |
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.
indexOf
instead of the RegEx 'cause it's probably faster? </nitpick>
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.
Sure :) lodash's includes
should be fast enough: https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L6707
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.
48ea69f
Looks good -- nitpicks aside :-) I don't really have a clue about webpack, but I was just wondering if we were duplicating module tree traversal (since I guess webpack needs to traverse the module tree for compilation anyway)? And if there was a way to just tack onto that on its way bottom-up, setting a per-module SSR flag, and check immediate child modules for the presence of that flag... Anyway, better to have a check soon than to spend too much time over-engineering. Feel free to merge 👍 |
if ( dep.module && /babel-loader/.test( dep.module.request ) && | ||
dep.module._source && | ||
dep.module._source._value.indexOf( SSR_READY ) === -1 ) { | ||
compilation.errors.push( PLUGIN_TITLE + ': ' + module.rawRequest + ', dependency ' + dep.module.rawRequest + ' is not ' + SSR_READY ); |
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 might want a brief explanation of the SSR acronym in the output.
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 might want a brief explanation of the SSR acronym in the output.
Ignore, I now see the next line of output 👍
Am I right in thinking that the scanning algorithm means we can be looking for the pragma in the same module over and over again if it happens to be often used as a dependency often? If so we could cache results, but that is probably unnecessary complexity at the moment. |
Yes, good point. I'll see what happens perf-wise when we have more pragmas. |
Looks good 👍 |
Removed test pragmas, and added a basic |
Add a webpack plugin that: - Scans module sources for the ssr-ready pragma - Scans non-npm dependencies of these modules, and checks that they also have the ssr-ready pragma. Adds a webpack compilation error if not. - Bails the process if errors are found(!)
85e21a8
to
9a25324
Compare
Readme looks fine, good to merge 👍 |
Build: Add pragma check webpack plugin for server side rendering
Closes #1594
Add a webpack plugin, for the client bundler, that:
Did look like this, now looks like #1801 (comment)
TODO:
To test:
make run
/** @ssr-ready **/
to a filemake run
doesn't error