Skip to content

Commit

Permalink
Use graceful-fs (#108)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisblossom authored and sindresorhus committed Aug 22, 2019
1 parent f509a89 commit 1299747
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
21 changes: 19 additions & 2 deletions index.js
Expand Up @@ -2,13 +2,30 @@
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');
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.');
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -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",
Expand Down

0 comments on commit 1299747

Please sign in to comment.