From 434c9f6426f12df4085f96fbdc7cd40afe04d131 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Tue, 27 Nov 2018 01:14:14 +0700 Subject: [PATCH] Require Node.js 6 Fixes #74 --- .gitattributes | 3 +- .gitignore | 1 + .npmrc | 1 + .travis.yml | 2 +- index.js | 32 ++++++-------- package.json | 118 ++++++++++++++++++++++++------------------------- readme.md | 18 +++++--- test.js | 22 ++++----- 8 files changed, 99 insertions(+), 98 deletions(-) create mode 100644 .npmrc diff --git a/.gitattributes b/.gitattributes index 391f0a4..6313b56 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,2 +1 @@ -* text=auto -*.js text eol=lf +* text=auto eol=lf diff --git a/.gitignore b/.gitignore index 3c3629e..239ecff 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ node_modules +yarn.lock diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..43c97e7 --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +package-lock=false diff --git a/.travis.yml b/.travis.yml index 7d69d74..2ae9d62 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ language: node_js node_js: + - '10' - '8' - '6' - - '4' diff --git a/index.js b/index.js index 3b602af..6890cbf 100644 --- a/index.js +++ b/index.js @@ -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; @@ -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}); diff --git a/package.json b/package.json index 648da57..3b1c5a1 100644 --- a/package.json +++ b/package.json @@ -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" + } } diff --git a/readme.md b/readme.md index 1c9996e..f8e3c6b 100644 --- a/readme.md +++ b/readme.md @@ -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 ``` @@ -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')); +})(); ``` @@ -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). @@ -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 diff --git a/test.js b/test.js index f86e319..036cd32 100644 --- a/test.js +++ b/test.js @@ -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) { @@ -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 }); @@ -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 }); @@ -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 }); @@ -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 });