From 7a11801c791e2d5b806772c6a25c7ef68460d8a8 Mon Sep 17 00:00:00 2001 From: Bogdan Chadkin Date: Fri, 6 Nov 2020 19:43:20 +0300 Subject: [PATCH 1/4] 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 7877d05a..e9ba8f9c 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,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 e2bc2d34..7b67b3e4 100644 --- a/src/BundleAnalyzerPlugin.js +++ b/src/BundleAnalyzerPlugin.js @@ -1,5 +1,5 @@ +const fs = reqiore('fs'); 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 writeStats(stats, statsFilepath); 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)}`); } From 074398fa926079cdf4b653608c02db0ce58a047e Mon Sep 17 00:00:00 2001 From: Bogdan Chadkin Date: Fri, 6 Nov 2020 20:10:09 +0300 Subject: [PATCH 2/4] Fix typos --- src/BundleAnalyzerPlugin.js | 2 +- src/viewer.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/BundleAnalyzerPlugin.js b/src/BundleAnalyzerPlugin.js index 7b67b3e4..318dc3a2 100644 --- a/src/BundleAnalyzerPlugin.js +++ b/src/BundleAnalyzerPlugin.js @@ -1,4 +1,4 @@ -const fs = reqiore('fs'); +const fs = require('fs'); const path = require('path'); const {bold} = require('chalk'); diff --git a/src/viewer.js b/src/viewer.js index 28cd914f..5f4782e0 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -187,7 +187,7 @@ async function generateJSONReport(bundleStats, opts) { if (!chartData) return; await fs.promises.mkdir(path.dirname(reportFilename), { recursive: true }); - await fs.promises.writeFileSync(reportFilename, JSON.stringify(chartData)); + await fs.promises.writeFile(reportFilename, JSON.stringify(chartData)); logger.info(`${bold('Webpack Bundle Analyzer')} saved JSON report to ${bold(reportFilename)}`); } From a00e1bf616cdec2cfe869ba1848dd082b2653c6b Mon Sep 17 00:00:00 2001 From: Bogdan Chadkin Date: Sat, 7 Nov 2020 00:20:18 +0300 Subject: [PATCH 3/4] Update lockfile and fix lint --- package-lock.json | 5 ----- src/BundleAnalyzerPlugin.js | 2 +- src/viewer.js | 4 ++-- 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index 97167c00..68bfafd8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7280,11 +7280,6 @@ } } }, - "mkdirp": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz", - "integrity": "sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==" - }, "mobx": { "version": "5.15.7", "resolved": "https://registry.npmjs.org/mobx/-/mobx-5.15.7.tgz", diff --git a/src/BundleAnalyzerPlugin.js b/src/BundleAnalyzerPlugin.js index 318dc3a2..bc37f1de 100644 --- a/src/BundleAnalyzerPlugin.js +++ b/src/BundleAnalyzerPlugin.js @@ -80,7 +80,7 @@ class BundleAnalyzerPlugin { async generateStatsFile(stats) { const statsFilepath = path.resolve(this.compiler.outputPath, this.opts.statsFilename); - await fs.promises.mkdir(path.dirname(statsFilepath), { recursive: true }); + await fs.promises.mkdir(path.dirname(statsFilepath), {recursive: true}); try { await writeStats(stats, statsFilepath); diff --git a/src/viewer.js b/src/viewer.js index 5f4782e0..c259eede 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -162,7 +162,7 @@ async function generateReport(bundleStats, opts) { const reportFilepath = path.resolve(bundleDir || process.cwd(), reportFilename); - fs.mkdirSync(path.dirname(reportFilepath), { recursive: true }); + fs.mkdirSync(path.dirname(reportFilepath), {recursive: true}); fs.writeFileSync(reportFilepath, reportHtml); logger.info(`${bold('Webpack Bundle Analyzer')} saved report to ${bold(reportFilepath)}`); @@ -186,7 +186,7 @@ async function generateJSONReport(bundleStats, opts) { if (!chartData) return; - await fs.promises.mkdir(path.dirname(reportFilename), { recursive: true }); + await fs.promises.mkdir(path.dirname(reportFilename), {recursive: true}); await fs.promises.writeFile(reportFilename, JSON.stringify(chartData)); logger.info(`${bold('Webpack Bundle Analyzer')} saved JSON report to ${bold(reportFilename)}`); From 8509a61c6dd2553aaf1dc3b08f0323a949411030 Mon Sep 17 00:00:00 2001 From: Bogdan Chadkin Date: Sat, 7 Nov 2020 23:33:20 +0300 Subject: [PATCH 4/4] Trigger rebuild