From 3a9bfa542219e9918e1b863bcb8a558cf8605feb Mon Sep 17 00:00:00 2001 From: Bogdan Chadkin Date: Fri, 6 Nov 2020 19:43:20 +0300 Subject: [PATCH] Replace mkdirp with builtin recursive flag 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 --- package.json | 1 - src/BundleAnalyzerPlugin.js | 4 ++-- src/viewer.js | 7 +++---- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index d134cc8a..86be8db4 100644 --- a/package.json +++ b/package.json @@ -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" }, diff --git a/src/BundleAnalyzerPlugin.js b/src/BundleAnalyzerPlugin.js index 6d294730..a01bc692 100644 --- a/src/BundleAnalyzerPlugin.js +++ b/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'); @@ -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, { diff --git a/src/viewer.js b/src/viewer.js index 6cb6d0b3..28cd914f 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -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'); @@ -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)}`); @@ -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)}`); }