From 85e576dc1be4a69fc05b9bf4ec25c669992cb3b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rouven=20We=C3=9Fling?= Date: Sun, 25 Oct 2020 00:21:45 +0200 Subject: [PATCH] Replace mkdirp with make-dir make-dir gives a nice promise-based API and is a very lightweight package --- package-lock.json | 26 +++++++++++++++++--------- package.json | 2 +- src/type/copy.js | 16 ++-------------- 3 files changed, 20 insertions(+), 24 deletions(-) diff --git a/package-lock.json b/package-lock.json index 20cf65e..05cf17c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -940,6 +940,21 @@ "yallist": "^2.1.2" } }, + "make-dir": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-3.1.0.tgz", + "integrity": "sha512-g3FeP20LNwhALb/6Cz6Dd4F2ngze0jz7tbzrD2wAV+o9FeNHe4rL+yK2md0J/fiSf1sa1ADhXqi5+oVwOM/eGw==", + "requires": { + "semver": "^6.0.0" + }, + "dependencies": { + "semver": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", + "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==" + } + } + }, "mime": { "version": "2.3.1", "resolved": "https://registry.npmjs.org/mime/-/mime-2.3.1.tgz", @@ -962,15 +977,8 @@ "minimist": { "version": "0.0.8", "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", - "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=" - }, - "mkdirp": { - "version": "0.5.0", - "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.0.tgz", - "integrity": "sha1-HXMHam35hs2TROFecfzAWkyavxI=", - "requires": { - "minimist": "0.0.8" - } + "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=", + "dev": true }, "mocha": { "version": "5.2.0", diff --git a/package.json b/package.json index f84d20c..c2446c6 100644 --- a/package.json +++ b/package.json @@ -23,9 +23,9 @@ "node": ">=10" }, "dependencies": { + "make-dir": "3.1.0", "mime": "2.3.1", "minimatch": "3.0.4", - "mkdirp": "0.5.0", "xxhashjs": "0.2.1" }, "devDependencies": { diff --git a/src/type/copy.js b/src/type/copy.js index 5eb7bb0..f29c261 100644 --- a/src/type/copy.js +++ b/src/type/copy.js @@ -2,7 +2,7 @@ const path = require('path'); const fs = require('fs'); -const mkdirp = require('mkdirp'); +const makeDir = require('make-dir'); const calcHash = require('../lib/hash'); const paths = require('../lib/paths'); @@ -17,18 +17,6 @@ const getHashName = (file, options) => + calcHash(file.contents, options) + path.extname(file.path); -const createDirAsync = (dirPath) => { - return new Promise((resolve, reject) => { - mkdirp(dirPath, (err) => { - if (err) { - reject(err); - } - - resolve(); - }); - }); -}; - const writeFileAsync = (file, dest) => { return new Promise((resolve, reject) => { fs.writeFile(dest, file.contents, { flag: 'wx' }, (err) => { @@ -79,7 +67,7 @@ module.exports = function processCopy(asset, dir, options, decl, warn, result, a const newAssetPath = path.join(newAssetBaseDir, assetRelativePath); const newRelativeAssetPath = normalize(path.relative(targetDir, newAssetPath)); - return createDirAsync(path.dirname(newAssetPath)) + return makeDir(path.dirname(newAssetPath)) .then(() => writeFileAsync(file, newAssetPath)) .then(() => { addDependency(file.path);