-
Notifications
You must be signed in to change notification settings - Fork 184
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 LABjs string from source #846
Conversation
I guess we could pre-build two copies (normal and debug) and select among them with an option... 🤔 That would actually let us turn on debugging at run-time which could be useful. |
🤔 iiuc, we're just checking in the source of lab.js to react server core, but is that really where it belongs? Maybe it makes sense to make it a separate npm package? Maybe it even makes sense to make it into an npm package that lives outside of the react server repo, maybe something like https://npmjs.com/package/labjs? It's under and MIT license, and it doesn't really seem like its something react server specific... We could also add a git dependency to react-server/package.json |
Actually, looks like there's plans to put it on npm |
Oh, good thought. I'm going to make some modifications for its use in React Server, so if anything it would probably have to be |
Makes sense. I vote we pry it out into |
We already can't. We would need getify/LABjs#81 to land for non-debug. |
But anyway once this (or whatever this turns into) lands I've got another PR coming on its heels that starts really hacking it up. 😈 |
const path = require("path"); | ||
const {readFileSync} = require("fs"); | ||
|
||
var lab = readFileSync(path.join(__dirname, "LAB.src.js"), "utf-8"); |
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.
Doesn't this mean that this module can't be used on the client side?
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.
Yep, this module is only used in the render middleware. Its output is a string of JS that is put into an inline script tag.
lab = lab.replace(/\/\*!START_DEBUG(?:.|[\n\r])*?END_DEBUG\*\//g, ""); | ||
|
||
// After the debug code is removed just uglify. | ||
lab = require("uglify-js").minify(lab, {fromString: true}).code; |
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 already run this whole package through Babel with Gulp, why not uglify it there and save the uglified version in target/(client|server)/util/LABString.js
? What am I missing?
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 am I missing?
The full extent of my laziness. 👹
As I think about it more I like @doug-wade's idea of pulling this out into a separate package. Going to manage it inside the React Server repo for now just for convenience. We'll be able to pull it out later using lerna export
if we want to.
Future LABjs
The debug code gets totally removed in the minified build.
I've updated this PR to put LAB into a dedicated package and move the minification to build time. 🍻 |
Hard to believe |
@@ -0,0 +1,9 @@ | |||
console.log( | |||
'module.exports = '+ | |||
require("fs").readFileSync("/dev/stdin", "utf-8") |
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 feel like I should know this, but... do we officially support windows? Seems like /dev/stdin
wouldn't work there?
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.
Ugh... this is only at build time. Do we need to support windows even for that? 😩
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 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.
Ignore the mockery
stuff. The memory-stream
package allows you to pass a stream object to a library and then call .toString()
on what was written to the stream.
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.
Okay, got rid of the use of |
While you're involved in this, it probably is a good idea to look into getify/LABjs#113. It might address #77 and #253 without much work from this end. Whoops... @doug-wade was on it and already mentioned this! |
Oh, nice. Thanks for the link. |
|
||
This is based on the awesome [LABjs](https://github.com/getify/LABjs) package. | ||
|
||
TODO: Flesh out this README. :grin: |
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.
😆
@@ -0,0 +1,39 @@ | |||
{ | |||
"name": "flab", |
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.
😆
"loader" | ||
], | ||
"author": "Bo Borgerson", | ||
"license": "MIT", |
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.
Apache 2?
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.
LABjs is MIT. Can MIT be converted to Apache 2?
"bugs": { | ||
"url": "https://github.com/redfin/react-server/issues" | ||
}, | ||
"homepage": "https://github.com/redfin/react-server#readme", |
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.
out-of-scope: should we update all of the modules to point to react-server.io as their homepage?
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.
Oh, maybe... 🤔
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 dig it. Thanks @gigabo 🎉
Onward! 👉 |
I'm going to start making substantive changes to the LABjs code we put at the top of every page. I want to have useful diffs and commit history for those changes, so as a baseline this PR replaces the pre-minified source string with the (mostly) vanilla source file.
A few benefits:
DEBUG_LAB=true react-server start
A few drawbacks:
Could minify during build to avoid those, but we'd lose the debug-ability which is really nice.