Skip to content

Commit

Permalink
Replace mkdirp with builtin recursive flag
Browse files Browse the repository at this point in the history
In node 10.12 mkdir got new recursive flag which provides the same
functionality as mkdirp.

See here https://nodejs.org/api/fs.html#fs_fs_mkdir_path_options_callback

Also node 10 got builtin promisified `fs` utilities.

See here https://nodejs.org/api/fs.html#fs_fs_promises_api
  • Loading branch information
TrySound committed Nov 6, 2020
1 parent ee6c7a9 commit 3a9bfa5
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
1 change: 0 additions & 1 deletion package.json
Expand Up @@ -44,7 +44,6 @@
"filesize": "^6.1.0",
"gzip-size": "^5.1.1",
"lodash": "^4.17.20",
"mkdirp": "^1.0.4",
"opener": "^1.5.2",
"ws": "^7.3.1"
},
Expand Down
4 changes: 2 additions & 2 deletions src/BundleAnalyzerPlugin.js
@@ -1,6 +1,6 @@
const fs = reqiore('fs');
const bfj = require('bfj');
const path = require('path');
const mkdir = require('mkdirp');
const {bold} = require('chalk');

const Logger = require('./Logger');
Expand Down Expand Up @@ -80,7 +80,7 @@ class BundleAnalyzerPlugin {

async generateStatsFile(stats) {
const statsFilepath = path.resolve(this.compiler.outputPath, this.opts.statsFilename);
mkdir.sync(path.dirname(statsFilepath));
await fs.promises.mkdir(path.dirname(statsFilepath), { recursive: true });

try {
await bfj.write(statsFilepath, stats, {
Expand Down
7 changes: 3 additions & 4 deletions src/viewer.js
Expand Up @@ -6,7 +6,6 @@ const WebSocket = require('ws');
const _ = require('lodash');
const express = require('express');
const ejs = require('ejs');
const mkdir = require('mkdirp');
const {bold} = require('chalk');

const Logger = require('./Logger');
Expand Down Expand Up @@ -163,7 +162,7 @@ async function generateReport(bundleStats, opts) {

const reportFilepath = path.resolve(bundleDir || process.cwd(), reportFilename);

mkdir.sync(path.dirname(reportFilepath));
fs.mkdirSync(path.dirname(reportFilepath), { recursive: true });
fs.writeFileSync(reportFilepath, reportHtml);

logger.info(`${bold('Webpack Bundle Analyzer')} saved report to ${bold(reportFilepath)}`);
Expand All @@ -187,8 +186,8 @@ async function generateJSONReport(bundleStats, opts) {

if (!chartData) return;

mkdir.sync(path.dirname(reportFilename));
fs.writeFileSync(reportFilename, JSON.stringify(chartData));
await fs.promises.mkdir(path.dirname(reportFilename), { recursive: true });
await fs.promises.writeFileSync(reportFilename, JSON.stringify(chartData));

logger.info(`${bold('Webpack Bundle Analyzer')} saved JSON report to ${bold(reportFilename)}`);
}
Expand Down

0 comments on commit 3a9bfa5

Please sign in to comment.