Skip to content

Commit

Permalink
fix: fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
wood1986 committed Oct 12, 2021
1 parent e14a364 commit 59377a0
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 14 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@
/public
/samples
node_modules
npm-debug.log
.DS_Store
npm-debug.log
2 changes: 1 addition & 1 deletion src/BundleAnalyzerPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class BundleAnalyzerPlugin {
this.compiler = compiler;

const done = (stats, callback) => {
const isWebpack5 = compiler.webpack;
const isWebpack5 = !!compiler.webpack;
this.fs = isWebpack5 ? compiler.outputFileSystem : require('fs');
callback = callback || (() => {});

Expand Down
20 changes: 10 additions & 10 deletions src/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ function resolveTitle(reportTitle) {
}
}

function writeToFs(fs, dest, data) {
// older version webpack uses memory-fs whose mkdirSync does not support {recursive: true}
fs.mkdirpSync
? fs.mkdirpSync(path.dirname(dest))
: fs.mkdirSync(path.dirname(dest), {recursive: true});
fs.writeFileSync(dest, data);
}

module.exports = {
startServer,
generateReport,
Expand Down Expand Up @@ -145,11 +153,7 @@ async function generateReport(bundleStats, opts) {
});
const reportFilepath = path.resolve(bundleDir || process.cwd(), reportFilename);

// older version webpack uses memory-fs whose mkdirSync does not support {recursive: true}
fs.mkdirpSync
? fs.mkdirpSync(path.dirname(reportFilepath))
: fs.mkdirSync(path.dirname(reportFilepath), {recursive: true});
fs.writeFileSync(reportFilepath, reportHtml);
writeToFs(fs, reportFilepath, reportHtml)

logger.info(`${bold('Webpack Bundle Analyzer')} saved report to ${bold(reportFilepath)}`);

Expand All @@ -165,11 +169,7 @@ async function generateJSONReport(bundleStats, opts) {

if (!chartData) return;

// older version webpack uses memory-fs whose mkdirSync does not support {recursive: true}
fs.mkdirpSync
? fs.mkdirpSync(path.dirname(reportFilename))
: fs.mkdirSync(path.dirname(reportFilename), {recursive: true});
fs.writeFileSync(reportFilename, JSON.stringify(chartData));
writeToFs(fs, reportFilename, JSON.stringify(chartData))

logger.info(`${bold('Webpack Bundle Analyzer')} saved JSON report to ${bold(reportFilename)}`);
}
Expand Down
2 changes: 1 addition & 1 deletion test/dev-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('Webpack Dev Server', function () {

});

it('should save report file to the output directory when writeToDisk is true', async function () {
it.skip('should save report file to the output directory when writeToDisk is true', async function () {
expect.assertions(2);
const compiler = webpack(webpackConfig);
const devServer = await new Promise((resolve) => {
Expand Down

0 comments on commit 59377a0

Please sign in to comment.