Skip to content

Commit

Permalink
Stream JSON output (--json)
Browse files Browse the repository at this point in the history
This fixes webpack#4629

JSON.stringify can fail with `RangeError: Invalid string length`
when it runs out of memory. See nodejs/node-v0.x-archivei#14170.
With this fix, I was able to write out the profile JSON without
errors.
  • Loading branch information
simonflk committed Apr 3, 2017
1 parent 584f4da commit 4869904
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
5 changes: 4 additions & 1 deletion bin/webpack.js
Expand Up @@ -334,7 +334,10 @@ function processOptions(options) {
process.exit(1); // eslint-disable-line
}
if(outputOptions.json) {
process.stdout.write(JSON.stringify(stats.toJson(outputOptions), null, 2) + "\n");
var stringify = require('JSONStream').stringify('', '', '');
stringify.pipe(process.stdout);
stringify.write(stats.toJson(outputOptions));
stringify.end();
} else if(stats.hash !== lastHash) {
lastHash = stats.hash;
process.stdout.write(stats.toString(outputOptions) + "\n");
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -4,6 +4,7 @@
"author": "Tobias Koppers @sokra",
"description": "Packs CommonJs/AMD modules for the browser. Allows to split your codebase into multiple bundles, which can be loaded on demand. Support loaders to preprocess files, i.e. json, jsx, es7, css, less, ... and your custom stuff.",
"dependencies": {
"JSONStream": "^1.3.1",
"acorn": "^5.0.0",
"acorn-dynamic-import": "^2.0.0",
"ajv": "^4.7.0",
Expand Down

0 comments on commit 4869904

Please sign in to comment.