Skip to content

Commit

Permalink
Merge pull request #129 from ryan953/stream-json-stringify
Browse files Browse the repository at this point in the history
Output large json stats objects
  • Loading branch information
th0r committed Jan 18, 2018
2 parents 350ddce + b5254aa commit 5cb03ba
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 10 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -34,6 +34,7 @@
],
"dependencies": {
"acorn": "^5.1.1",
"bfj-node4": "^4.2.4",
"chalk": "^1.1.3",
"commander": "^2.9.0",
"ejs": "^2.5.6",
Expand Down
28 changes: 18 additions & 10 deletions src/BundleAnalyzerPlugin.js
@@ -1,4 +1,4 @@
const fs = require('fs');
const bfj = require('bfj-node4');
const path = require('path');
const mkdir = require('mkdirp');
const { bold } = require('chalk');
Expand Down Expand Up @@ -61,19 +61,27 @@ class BundleAnalyzerPlugin {
});
}

generateStatsFile(stats) {
async generateStatsFile(stats) {
const statsFilepath = path.resolve(this.compiler.outputPath, this.opts.statsFilename);

mkdir.sync(path.dirname(statsFilepath));

fs.writeFileSync(
statsFilepath,
JSON.stringify(stats, null, 2)
);
try {
await bfj.write(statsFilepath, stats, {
promises: 'ignore',
buffers: 'ignore',
maps: 'ignore',
iterables: 'ignore',
circular: 'ignore'
});

this.logger.info(
`${bold('Webpack Bundle Analyzer')} saved stats file to ${bold(statsFilepath)}`
);
this.logger.info(
`${bold('Webpack Bundle Analyzer')} saved stats file to ${bold(statsFilepath)}`
);
} catch (error) {
this.logger.error(
`${bold('Webpack Bundle Analyzer')} error saving stats file to ${bold(statsFilepath)}: ${error}`
);
}
}

async startAnalyzerServer(stats) {
Expand Down
15 changes: 15 additions & 0 deletions yarn.lock
Expand Up @@ -759,6 +759,13 @@ beeper@^1.0.0:
version "1.1.1"
resolved "https://registry.npmjs.org/beeper/-/beeper-1.1.1.tgz#e6d5ea8c5dad001304a70b22638447f69cb2f809"

bfj-node4@^4.2.4:
version "4.2.4"
resolved "https://registry.yarnpkg.com/bfj-node4/-/bfj-node4-4.2.4.tgz#8484fe2ec73ea195906f3fd26ebd309be233e91a"
dependencies:
check-types "^7.3.0"
tryer "^1.0.0"

big.js@^3.1.3:
version "3.1.3"
resolved "https://registry.npmjs.org/big.js/-/big.js-3.1.3.tgz#4cada2193652eb3ca9ec8e55c9015669c9806978"
Expand Down Expand Up @@ -967,6 +974,10 @@ chalk@^1.0.0, chalk@^1.1.0, chalk@^1.1.1, chalk@^1.1.3:
strip-ansi "^3.0.0"
supports-color "^2.0.0"

check-types@^7.3.0:
version "7.3.0"
resolved "https://registry.yarnpkg.com/check-types/-/check-types-7.3.0.tgz#468f571a4435c24248f5fd0cb0e8d87c3c341e7d"

chokidar@^1.4.3, chokidar@^1.6.0, chokidar@^1.6.1:
version "1.7.0"
resolved "https://registry.npmjs.org/chokidar/-/chokidar-1.7.0.tgz#798e689778151c8076b4b360e5edd28cda2bb468"
Expand Down Expand Up @@ -4890,6 +4901,10 @@ trim-right@^1.0.1:
version "1.0.1"
resolved "https://registry.npmjs.org/trim-right/-/trim-right-1.0.1.tgz#cb2e1203067e0c8de1f614094b9fe45704ea6003"

tryer@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/tryer/-/tryer-1.0.0.tgz#027b69fa823225e551cace3ef03b11f6ab37c1d7"

tryit@^1.0.1:
version "1.0.3"
resolved "https://registry.npmjs.org/tryit/-/tryit-1.0.3.tgz#393be730a9446fd1ead6da59a014308f36c289cb"
Expand Down

0 comments on commit 5cb03ba

Please sign in to comment.