Skip to content

Commit 1299747

Browse files
chrisblossomsindresorhus
authored andcommitted
Use graceful-fs (#108)
1 parent f509a89 commit 1299747

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

index.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,30 @@
22
const {promisify} = require('util');
33
const path = require('path');
44
const globby = require('globby');
5+
const gracefulFs = require('graceful-fs');
56
const isPathCwd = require('is-path-cwd');
67
const isPathInside = require('is-path-inside');
78
const rimraf = require('rimraf');
89
const pMap = require('p-map');
910

1011
const rimrafP = promisify(rimraf);
1112

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+
1229
function safeCheck(file, cwd) {
1330
if (isPathCwd(file)) {
1431
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
3956
}
4057

4158
if (!dryRun) {
42-
await rimrafP(file, {glob: false});
59+
await rimrafP(file, rimrafOptions);
4360
}
4461

4562
return file;
@@ -72,7 +89,7 @@ module.exports.sync = (patterns, {force, dryRun, cwd = process.cwd(), ...options
7289
}
7390

7491
if (!dryRun) {
75-
rimraf.sync(file, {glob: false});
92+
rimraf.sync(file, rimrafOptions);
7693
}
7794

7895
return file;

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
],
4646
"dependencies": {
4747
"globby": "^10.0.0",
48+
"graceful-fs": "^4.2.2",
4849
"is-path-cwd": "^2.0.0",
4950
"is-path-inside": "^3.0.1",
5051
"p-map": "^3.0.0",

0 commit comments

Comments
 (0)