|
2 | 2 | const {promisify} = require('util'); |
3 | 3 | const path = require('path'); |
4 | 4 | const globby = require('globby'); |
| 5 | +const gracefulFs = require('graceful-fs'); |
5 | 6 | const isPathCwd = require('is-path-cwd'); |
6 | 7 | const isPathInside = require('is-path-inside'); |
7 | 8 | const rimraf = require('rimraf'); |
8 | 9 | const pMap = require('p-map'); |
9 | 10 |
|
10 | 11 | const rimrafP = promisify(rimraf); |
11 | 12 |
|
| 13 | +const rimrafOptions = { |
| 14 | + glob: false, |
| 15 | + unlink: gracefulFs.unlink, |
| 16 | + unlinkSync: gracefulFs.unlinkSync, |
| 17 | + chmod: gracefulFs.chmod, |
| 18 | + chmodSync: gracefulFs.chmodSync, |
| 19 | + stat: gracefulFs.stat, |
| 20 | + statSync: gracefulFs.statSync, |
| 21 | + lstat: gracefulFs.lstat, |
| 22 | + lstatSync: gracefulFs.lstatSync, |
| 23 | + rmdir: gracefulFs.rmdir, |
| 24 | + rmdirSync: gracefulFs.rmdirSync, |
| 25 | + readdir: gracefulFs.readdir, |
| 26 | + readdirSync: gracefulFs.readdirSync |
| 27 | +}; |
| 28 | + |
12 | 29 | function safeCheck(file, cwd) { |
13 | 30 | if (isPathCwd(file)) { |
14 | 31 | 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 |
39 | 56 | } |
40 | 57 |
|
41 | 58 | if (!dryRun) { |
42 | | - await rimrafP(file, {glob: false}); |
| 59 | + await rimrafP(file, rimrafOptions); |
43 | 60 | } |
44 | 61 |
|
45 | 62 | return file; |
@@ -72,7 +89,7 @@ module.exports.sync = (patterns, {force, dryRun, cwd = process.cwd(), ...options |
72 | 89 | } |
73 | 90 |
|
74 | 91 | if (!dryRun) { |
75 | | - rimraf.sync(file, {glob: false}); |
| 92 | + rimraf.sync(file, rimrafOptions); |
76 | 93 | } |
77 | 94 |
|
78 | 95 | return file; |
|
0 commit comments