Skip to content
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

Merged
merged 5 commits into from
Jan 31, 2017
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
516 changes: 516 additions & 0 deletions packages/flab/LAB.src.js

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions packages/flab/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Future Loading and Blocking JS

This is based on the awesome [LABjs](https://github.com/getify/LABjs) package.

TODO: Flesh out this README. :grin:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😆

4 changes: 4 additions & 0 deletions packages/flab/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
src: require("./string/src"),
min: require("./string/min"),
}
12 changes: 12 additions & 0 deletions packages/flab/minify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
console.log(
"\n"+
"/*! LAB.js (LABjs :: Loading And Blocking JavaScript)\n"+
" v2.0.3 (c) Kyle Simpson\n"+
" MIT License\n"+
"*/\n"+
require("uglify-js").minify(
require("fs").readFileSync("/dev/stdin", "utf-8")
.replace(/\/\*!START_DEBUG(?:.|[\n\r])*?END_DEBUG\*\//g, ""),
{fromString: true}
).code
);
38 changes: 38 additions & 0 deletions packages/flab/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"name": "flab",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😆

"version": "0.0.1",
"description": "Future Loading and Blocking JS",
"main": "index.js",
"files": [
"index.js",
"string"
],
"scripts": {
"prepublish": "mkdir -p string && npm run build-src && npm run build-min",
"build-src": "node stringify.js < LAB.src.js > string/src.js",
"build-min": "node minify.js < LAB.src.js | node stringify.js > string/min.js",
"clean": "rimraf string",
"test": "echo \"No tests yet...\""
},
"repository": {
"type": "git",
"url": "git+https://github.com/redfin/react-server.git"
},
"keywords": [
"loading",
"blocking",
"js",
"asynchronous",
"loader"
],
"author": "Bo Borgerson",
"license": "MIT",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apache 2?

Copy link
Contributor Author

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",
Copy link
Collaborator

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, maybe... 🤔

"devDependencies": {
"rimraf": "^2.5.4",
"uglify-js": "^2.7.5"
}
}
9 changes: 9 additions & 0 deletions packages/flab/stringify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
console.log(
'module.exports = '+
require("fs").readFileSync("/dev/stdin", "utf-8")
Copy link
Member

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?

Copy link
Contributor Author

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? 😩

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh cool thanks @drewpc.

I'm tempted to use get-stdin, which is a bit more targeted to what this little one-liner needs to do.

.replace(/\\/g, '\\\\')
.replace(/"/g, '\\"')
.replace(/^/gm, '"')
.replace(/$/gm, '\\n"+')+
'"";'
);
4 changes: 2 additions & 2 deletions packages/react-server/core/renderMiddleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var logger = require('./logging').getLogger(__LOGGER__),
RequestContext = require('./context/RequestContext'),
RequestLocalStorage = require('./util/RequestLocalStorage'),
RLS = RequestLocalStorage.getNamespace(),
LABString = require('./util/LABString'),
flab = require('flab'),
Q = require('q'),
config = require('./config'),
ExpressServerRequest = require("./ExpressServerRequest"),
Expand Down Expand Up @@ -484,7 +484,7 @@ function renderScriptsAsync(scripts, res) {
if (!RLS().didLoadLAB){

// This is the full implementation of LABjs.
res.write(LABString);
res.write(flab.min);

// We always want scripts to be executed in order.
res.write("$LAB.setGlobalDefaults({AlwaysPreserveOrder:true});");
Expand Down
11 changes: 0 additions & 11 deletions packages/react-server/core/util/LABString.js

This file was deleted.

1 change: 1 addition & 0 deletions packages/react-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"cookie-parser": "1.4.3",
"eventemitter3": "^2.0.2",
"express-state": "^1.4.0",
"flab": "^0.0.1",
"lodash": "^4.16.4",
"mobile-detect": "^1.3.5",
"q": "1.4.1",
Expand Down