Skip to content

Commit

Permalink
Require Node.js 6
Browse files Browse the repository at this point in the history
Fixes #74
  • Loading branch information
sindresorhus committed Nov 26, 2018
1 parent cdd9c76 commit 434c9f6
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 98 deletions.
3 changes: 1 addition & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
* text=auto
*.js text eol=lf
* text=auto eol=lf
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
yarn.lock
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: node_js
node_js:
- '10'
- '8'
- '6'
- '4'
32 changes: 14 additions & 18 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,19 @@ function safeCheck(file) {
}
}

module.exports = (patterns, opts) => {
opts = Object.assign({}, opts);
module.exports = (patterns, options) => {
options = Object.assign({}, options);

const force = opts.force;
delete opts.force;

const dryRun = opts.dryRun;
delete opts.dryRun;
const {force, dryRun} = options;
delete options.force;
delete options.dryRun;

const mapper = file => {
if (!force) {
safeCheck(file);
}

file = path.resolve(opts.cwd || '', file);
file = path.resolve(options.cwd || '', file);

if (dryRun) {
return file;
Expand All @@ -42,24 +40,22 @@ module.exports = (patterns, opts) => {
return rimrafP(file, {glob: false}).then(() => file);
};

return globby(patterns, opts).then(files => pMap(files, mapper, opts));
return globby(patterns, options).then(files => pMap(files, mapper, options));
};

module.exports.sync = (patterns, opts) => {
opts = Object.assign({}, opts);

const force = opts.force;
delete opts.force;
module.exports.sync = (patterns, options) => {
options = Object.assign({}, options);

const dryRun = opts.dryRun;
delete opts.dryRun;
const {force, dryRun} = options;
delete options.force;
delete options.dryRun;

return globby.sync(patterns, opts).map(file => {
return globby.sync(patterns, options).map(file => {
if (!force) {
safeCheck(file);
}

file = path.resolve(opts.cwd || '', file);
file = path.resolve(options.cwd || '', file);

if (!dryRun) {
rimraf.sync(file, {glob: false});
Expand Down
118 changes: 59 additions & 59 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,61 +1,61 @@
{
"name": "del",
"version": "3.0.0",
"description": "Delete files and folders",
"license": "MIT",
"repository": "sindresorhus/del",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"engines": {
"node": ">=4"
},
"scripts": {
"test": "xo && ava"
},
"files": [
"index.js"
],
"keywords": [
"delete",
"files",
"folders",
"directories",
"del",
"remove",
"destroy",
"trash",
"unlink",
"clean",
"cleaning",
"cleanup",
"rm",
"rmrf",
"rimraf",
"rmdir",
"glob",
"gulpfriendly",
"file",
"folder",
"directory",
"dir",
"fs",
"filesystem"
],
"dependencies": {
"globby": "^6.1.0",
"is-path-cwd": "^1.0.0",
"is-path-in-cwd": "^1.0.0",
"p-map": "^1.1.1",
"pify": "^3.0.0",
"rimraf": "^2.2.8"
},
"devDependencies": {
"ava": "*",
"make-dir": "^1.0.0",
"tempy": "^0.1.0",
"xo": "*"
}
"name": "del",
"version": "3.0.0",
"description": "Delete files and folders",
"license": "MIT",
"repository": "sindresorhus/del",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"engines": {
"node": ">=6"
},
"scripts": {
"test": "xo && ava"
},
"files": [
"index.js"
],
"keywords": [
"delete",
"files",
"folders",
"directories",
"del",
"remove",
"destroy",
"trash",
"unlink",
"clean",
"cleaning",
"cleanup",
"rm",
"rmrf",
"rimraf",
"rmdir",
"glob",
"gulpfriendly",
"file",
"folder",
"directory",
"dir",
"fs",
"filesystem"
],
"dependencies": {
"globby": "^6.1.0",
"is-path-cwd": "^2.0.0",
"is-path-in-cwd": "^2.0.0",
"p-map": "^2.0.0",
"pify": "^4.0.1",
"rimraf": "^2.6.2"
},
"devDependencies": {
"ava": "^0.25.0",
"make-dir": "^1.3.0",
"tempy": "^0.2.1",
"xo": "^0.23.0"
}
}
18 changes: 11 additions & 7 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Similar to [rimraf](https://github.com/isaacs/rimraf), but with a Promise API an
## Install

```
$ npm install --save del
$ npm install del
```


Expand All @@ -24,9 +24,11 @@ $ npm install --save del
```js
const del = require('del');

del(['tmp/*.js', '!tmp/unicorn.js']).then(paths => {
console.log('Deleted files and folders:\n', paths.join('\n'));
});
(async () => {
const deletedPaths = await del(['tmp/*.js', '!tmp/unicorn.js']);

console.log('Deleted files and folders:\n', deletedPaths.join('\n'));
})();
```


Expand Down Expand Up @@ -61,7 +63,7 @@ Returns an array of deleted paths.

#### patterns

Type: `string` `Array`
Type: `string` `string[]`

See supported minimatch [patterns](https://github.com/isaacs/minimatch#usage).

Expand Down Expand Up @@ -91,9 +93,11 @@ See what would be deleted.
```js
const del = require('del');

del(['tmp/*.js'], {dryRun: true}).then(paths => {
(async () => {
const deletedPaths = await del(['tmp/*.js'], {dryRun: true});

console.log('Files and folders that would be deleted:\n', paths.join('\n'));
});
})();
```

##### concurrency
Expand Down
22 changes: 11 additions & 11 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import fs from 'fs';
import test from 'ava';
import tempy from 'tempy';
import makeDir from 'make-dir';
import m from '.';
import del from '.';

function exists(t, files) {
for (const file of files) {
Expand Down Expand Up @@ -34,21 +34,21 @@ test.beforeEach(t => {
});

test('delete files - async', async t => {
await m(['*.tmp', '!1*'], {cwd: t.context.tmp});
await del(['*.tmp', '!1*'], {cwd: t.context.tmp});

exists(t, ['1.tmp', '.dot.tmp']);
notExists(t, ['2.tmp', '3.tmp', '4.tmp']);
});

test('delete files - sync', t => {
m.sync(['*.tmp', '!1*'], {cwd: t.context.tmp});
del.sync(['*.tmp', '!1*'], {cwd: t.context.tmp});

exists(t, ['1.tmp', '.dot.tmp']);
notExists(t, ['2.tmp', '3.tmp', '4.tmp']);
});

test('take options into account - async', async t => {
await m(['*.tmp', '!1*'], {
await del(['*.tmp', '!1*'], {
cwd: t.context.tmp,
dot: true
});
Expand All @@ -58,7 +58,7 @@ test('take options into account - async', async t => {
});

test('take options into account - sync', t => {
m.sync(['*.tmp', '!1*'], {
del.sync(['*.tmp', '!1*'], {
cwd: t.context.tmp,
dot: true
});
Expand All @@ -69,20 +69,20 @@ test('take options into account - sync', t => {

test.serial('return deleted files - async', async t => {
t.deepEqual(
await m('1.tmp', {cwd: t.context.tmp}),
await del('1.tmp', {cwd: t.context.tmp}),
[path.join(t.context.tmp, '1.tmp')]
);
});

test('return deleted files - sync', t => {
t.deepEqual(
m.sync('1.tmp', {cwd: t.context.tmp}),
del.sync('1.tmp', {cwd: t.context.tmp}),
[path.join(t.context.tmp, '1.tmp')]
);
});

test(`don't delete files, but return them - async`, async t => {
const deletedFiles = await m(['*.tmp', '!1*'], {
test('don\'t delete files, but return them - async', async t => {
const deletedFiles = await del(['*.tmp', '!1*'], {
cwd: t.context.tmp,
dryRun: true
});
Expand All @@ -94,8 +94,8 @@ test(`don't delete files, but return them - async`, async t => {
]);
});

test(`don't delete files, but return them - sync`, t => {
const deletedFiles = m.sync(['*.tmp', '!1*'], {
test('don\'t delete files, but return them - sync', t => {
const deletedFiles = del.sync(['*.tmp', '!1*'], {
cwd: t.context.tmp,
dryRun: true
});
Expand Down

0 comments on commit 434c9f6

Please sign in to comment.