Skip to content

Commit 5cb03ba

Browse files
authored
Merge pull request #129 from ryan953/stream-json-stringify
Output large json stats objects
2 parents 350ddce + b5254aa commit 5cb03ba

File tree

3 files changed

+34
-10
lines changed

3 files changed

+34
-10
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
],
3535
"dependencies": {
3636
"acorn": "^5.1.1",
37+
"bfj-node4": "^4.2.4",
3738
"chalk": "^1.1.3",
3839
"commander": "^2.9.0",
3940
"ejs": "^2.5.6",

src/BundleAnalyzerPlugin.js

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const fs = require('fs');
1+
const bfj = require('bfj-node4');
22
const path = require('path');
33
const mkdir = require('mkdirp');
44
const { bold } = require('chalk');
@@ -61,19 +61,27 @@ class BundleAnalyzerPlugin {
6161
});
6262
}
6363

64-
generateStatsFile(stats) {
64+
async generateStatsFile(stats) {
6565
const statsFilepath = path.resolve(this.compiler.outputPath, this.opts.statsFilename);
66-
6766
mkdir.sync(path.dirname(statsFilepath));
6867

69-
fs.writeFileSync(
70-
statsFilepath,
71-
JSON.stringify(stats, null, 2)
72-
);
68+
try {
69+
await bfj.write(statsFilepath, stats, {
70+
promises: 'ignore',
71+
buffers: 'ignore',
72+
maps: 'ignore',
73+
iterables: 'ignore',
74+
circular: 'ignore'
75+
});
7376

74-
this.logger.info(
75-
`${bold('Webpack Bundle Analyzer')} saved stats file to ${bold(statsFilepath)}`
76-
);
77+
this.logger.info(
78+
`${bold('Webpack Bundle Analyzer')} saved stats file to ${bold(statsFilepath)}`
79+
);
80+
} catch (error) {
81+
this.logger.error(
82+
`${bold('Webpack Bundle Analyzer')} error saving stats file to ${bold(statsFilepath)}: ${error}`
83+
);
84+
}
7785
}
7886

7987
async startAnalyzerServer(stats) {

yarn.lock

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,13 @@ beeper@^1.0.0:
759759
version "1.1.1"
760760
resolved "https://registry.npmjs.org/beeper/-/beeper-1.1.1.tgz#e6d5ea8c5dad001304a70b22638447f69cb2f809"
761761

762+
bfj-node4@^4.2.4:
763+
version "4.2.4"
764+
resolved "https://registry.yarnpkg.com/bfj-node4/-/bfj-node4-4.2.4.tgz#8484fe2ec73ea195906f3fd26ebd309be233e91a"
765+
dependencies:
766+
check-types "^7.3.0"
767+
tryer "^1.0.0"
768+
762769
big.js@^3.1.3:
763770
version "3.1.3"
764771
resolved "https://registry.npmjs.org/big.js/-/big.js-3.1.3.tgz#4cada2193652eb3ca9ec8e55c9015669c9806978"
@@ -967,6 +974,10 @@ chalk@^1.0.0, chalk@^1.1.0, chalk@^1.1.1, chalk@^1.1.3:
967974
strip-ansi "^3.0.0"
968975
supports-color "^2.0.0"
969976

977+
check-types@^7.3.0:
978+
version "7.3.0"
979+
resolved "https://registry.yarnpkg.com/check-types/-/check-types-7.3.0.tgz#468f571a4435c24248f5fd0cb0e8d87c3c341e7d"
980+
970981
chokidar@^1.4.3, chokidar@^1.6.0, chokidar@^1.6.1:
971982
version "1.7.0"
972983
resolved "https://registry.npmjs.org/chokidar/-/chokidar-1.7.0.tgz#798e689778151c8076b4b360e5edd28cda2bb468"
@@ -4890,6 +4901,10 @@ trim-right@^1.0.1:
48904901
version "1.0.1"
48914902
resolved "https://registry.npmjs.org/trim-right/-/trim-right-1.0.1.tgz#cb2e1203067e0c8de1f614094b9fe45704ea6003"
48924903

4904+
tryer@^1.0.0:
4905+
version "1.0.0"
4906+
resolved "https://registry.yarnpkg.com/tryer/-/tryer-1.0.0.tgz#027b69fa823225e551cace3ef03b11f6ab37c1d7"
4907+
48934908
tryit@^1.0.1:
48944909
version "1.0.3"
48954910
resolved "https://registry.npmjs.org/tryit/-/tryit-1.0.3.tgz#393be730a9446fd1ead6da59a014308f36c289cb"

0 commit comments

Comments
 (0)