diff --git a/index.js b/index.js index f9637f0..cbdde5a 100644 --- a/index.js +++ b/index.js @@ -2,6 +2,7 @@ const {promisify} = require('util'); const path = require('path'); const globby = require('globby'); +const gracefulFs = require('graceful-fs'); const isPathCwd = require('is-path-cwd'); const isPathInside = require('is-path-inside'); const rimraf = require('rimraf'); @@ -9,6 +10,22 @@ const pMap = require('p-map'); const rimrafP = promisify(rimraf); +const rimrafOptions = { + glob: false, + unlink: gracefulFs.unlink, + unlinkSync: gracefulFs.unlinkSync, + chmod: gracefulFs.chmod, + chmodSync: gracefulFs.chmodSync, + stat: gracefulFs.stat, + statSync: gracefulFs.statSync, + lstat: gracefulFs.lstat, + lstatSync: gracefulFs.lstatSync, + rmdir: gracefulFs.rmdir, + rmdirSync: gracefulFs.rmdirSync, + readdir: gracefulFs.readdir, + readdirSync: gracefulFs.readdirSync +}; + function safeCheck(file, cwd) { if (isPathCwd(file)) { throw new Error('Cannot delete the current working directory. Can be overridden with the `force` option.'); @@ -39,7 +56,7 @@ module.exports = async (patterns, {force, dryRun, cwd = process.cwd(), ...option } if (!dryRun) { - await rimrafP(file, {glob: false}); + await rimrafP(file, rimrafOptions); } return file; @@ -72,7 +89,7 @@ module.exports.sync = (patterns, {force, dryRun, cwd = process.cwd(), ...options } if (!dryRun) { - rimraf.sync(file, {glob: false}); + rimraf.sync(file, rimrafOptions); } return file; diff --git a/package.json b/package.json index fb2fb5e..6b4ac47 100644 --- a/package.json +++ b/package.json @@ -45,6 +45,7 @@ ], "dependencies": { "globby": "^10.0.0", + "graceful-fs": "^4.2.2", "is-path-cwd": "^2.0.0", "is-path-inside": "^3.0.1", "p-map": "^3.0.0",