Skip to content

Commit

Permalink
refactor(del): use rimraf directly
Browse files Browse the repository at this point in the history
  • Loading branch information
luftywiranda13 committed Jan 16, 2018
1 parent 1a5eb8c commit 705ac6e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
17 changes: 12 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
'use strict';

const { resolve } = require('path');
const del = require('del');
const execa = require('execa');
const globby = require('globby');
const pify = require('pify');
const pMap = require('p-map');
const rimraf = require('rimraf');

const rimrafP = pify(rimraf);

const DEFAULTS = { nodir: false, force: true };

const gitForceRemove = (file, options) =>
execa('git', ['rm', '-rf', file], options)
.then(() => resolve(options.cwd || '', file))
.catch(() => del(file, options));
const gitForceRemove = (file, options) => {
const resolvedFile = resolve(options.cwd || '', file);

return execa('git', ['rm', '-rf', resolvedFile], options)
.then(() => resolvedFile)
.catch(() => rimrafP(resolvedFile, { glob: false }))
.then(() => resolvedFile);
};

const forceDel = (patterns, options) => {
const opts = Object.assign({}, DEFAULTS, options);
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
"index.js"
],
"dependencies": {
"del": "^3.0.0",
"execa": "^0.9.0",
"globby": "^7.1.1",
"p-map": "^1.2.0"
"p-map": "^1.2.0",
"rimraf": "^2.6.2"
},
"devDependencies": {
"async-to-gen": "^1.3.3",
Expand Down
10 changes: 1 addition & 9 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ If the matching files or folders are managed by `git`, theyʼll be deleted and m

* Filters the files that should be deleted by using [globby](https://github.com/sindresorhus/globby)
* Maps those _one-by-one_ to be included in `git rm -f` command
* Use [del](https://github.com/sindresorhus/del) if the matching item isnʼt managed by `git`
* Use [rimraf](https://github.com/isaacs/rimraf) if the matching item isnʼt managed by `git`
* These processes run concurrently

## Installation
Expand Down Expand Up @@ -67,19 +67,11 @@ Default: `false`

From [node-glob](https://github.com/isaacs/node-glob#options). Set to `true` to match files only.

##### force

Type: `boolean`<br />
Default: `true`

From [del](https://github.com/sindresorhus/del#force). Allow deleting the current working directory and outside. This option only affects matching paths that are not managed by `git`.

Other options are derived from the defaults of these libraries:

* [globby](https://github.com/sindresorhus/globby#options)
* [node-glob](https://github.com/isaacs/node-glob#options)
* [execa](https://github.com/sindresorhus/execa/#options)
* [del](https://github.com/sindresorhus/del#options)

## Related

Expand Down

0 comments on commit 705ac6e

Please sign in to comment.