pax_global_header00006660000000000000000000000064131165314760014521gustar00rootroot0000000000000052 comment=255ab75f32c3a9188f261485f85ce1990d799f8c del-3.0.0/000077500000000000000000000000001311653147600122655ustar00rootroot00000000000000del-3.0.0/.editorconfig000066400000000000000000000002571311653147600147460ustar00rootroot00000000000000root = true [*] indent_style = tab end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [*.yml] indent_style = space indent_size = 2 del-3.0.0/.gitattributes000066400000000000000000000000351311653147600151560ustar00rootroot00000000000000* text=auto *.js text eol=lf del-3.0.0/.gitignore000066400000000000000000000000151311653147600142510ustar00rootroot00000000000000node_modules del-3.0.0/.travis.yml000066400000000000000000000000631311653147600143750ustar00rootroot00000000000000language: node_js node_js: - '8' - '6' - '4' del-3.0.0/index.js000066400000000000000000000027061311653147600137370ustar00rootroot00000000000000'use strict'; const path = require('path'); const globby = require('globby'); const isPathCwd = require('is-path-cwd'); const isPathInCwd = require('is-path-in-cwd'); const pify = require('pify'); const rimraf = require('rimraf'); const pMap = require('p-map'); const rimrafP = pify(rimraf); function safeCheck(file) { if (isPathCwd(file)) { throw new Error('Cannot delete the current working directory. Can be overriden with the `force` option.'); } if (!isPathInCwd(file)) { throw new Error('Cannot delete files/folders outside the current working directory. Can be overriden with the `force` option.'); } } module.exports = (patterns, opts) => { opts = Object.assign({}, opts); const force = opts.force; delete opts.force; const dryRun = opts.dryRun; delete opts.dryRun; const mapper = file => { if (!force) { safeCheck(file); } file = path.resolve(opts.cwd || '', file); if (dryRun) { return file; } return rimrafP(file, {glob: false}).then(() => file); }; return globby(patterns, opts).then(files => pMap(files, mapper, opts)); }; module.exports.sync = (patterns, opts) => { opts = Object.assign({}, opts); const force = opts.force; delete opts.force; const dryRun = opts.dryRun; delete opts.dryRun; return globby.sync(patterns, opts).map(file => { if (!force) { safeCheck(file); } file = path.resolve(opts.cwd || '', file); if (!dryRun) { rimraf.sync(file, {glob: false}); } return file; }); }; del-3.0.0/license000066400000000000000000000021251311653147600136320ustar00rootroot00000000000000MIT License Copyright (c) Sindre Sorhus (sindresorhus.com) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. del-3.0.0/package.json000066400000000000000000000017671311653147600145660ustar00rootroot00000000000000{ "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": "*" } } del-3.0.0/readme.md000066400000000000000000000060341311653147600140470ustar00rootroot00000000000000# del [![Build Status](https://travis-ci.org/sindresorhus/del.svg?branch=master)](https://travis-ci.org/sindresorhus/del) [![XO code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg)](https://github.com/sindresorhus/xo) > Delete files and folders using [globs](https://github.com/isaacs/minimatch#usage) Similar to [rimraf](https://github.com/isaacs/rimraf), but with a Promise API and support for multiple files and globbing. It also protects you against deleting the current working directory and above. ---

🐶

Support this project and improve your JavaScript skills with this great ES6 course by Wes Bos.
Try his free JavaScript 30 course for a taste of what to expect. You might also like his React and Sublime course.

--- ## Install ``` $ npm install --save del ``` ## Usage ```js const del = require('del'); del(['tmp/*.js', '!tmp/unicorn.js']).then(paths => { console.log('Deleted files and folders:\n', paths.join('\n')); }); ``` ## Beware The glob pattern `**` matches all children and *the parent*. So this won't work: ```js del.sync(['public/assets/**', '!public/assets/goat.png']); ``` You have to explicitly ignore the parent directories too: ```js del.sync(['public/assets/**', '!public/assets', '!public/assets/goat.png']); ``` Suggestions on how to improve this welcome! ## API ### del(patterns, [options]) Returns a promise for an array of deleted paths. ### del.sync(patterns, [options]) Returns an array of deleted paths. #### patterns Type: `string` `Array` See supported minimatch [patterns](https://github.com/isaacs/minimatch#usage). - [Pattern examples with expected matches](https://github.com/sindresorhus/multimatch/blob/master/test.js) - [Quick globbing pattern overview](https://github.com/sindresorhus/multimatch#globbing-patterns) #### options Type: `Object` See the [`glob` options](https://github.com/isaacs/node-glob#options). ##### force Type: `boolean`
Default: `false` Allow deleting the current working directory and outside. ##### dryRun Type: `boolean`
Default: `false` See what would be deleted. ```js const del = require('del'); del(['tmp/*.js'], {dryRun: true}).then(paths => { console.log('Files and folders that would be deleted:\n', paths.join('\n')); }); ``` ##### concurrency Type: `number`
Default: `Infinity`
Minimum: `1` Concurrency limit. ## CLI See [del-cli](https://github.com/sindresorhus/del-cli) for a CLI for this module and [trash-cli](https://github.com/sindresorhus/trash-cli) for a safe version that is suitable for running by hand. ## Related - [make-dir](https://github.com/sindresorhus/make-dir) - Make a directory and its parents if needed - [globby](https://github.com/sindresorhus/globby) - User-friendly glob matching ## License MIT © [Sindre Sorhus](https://sindresorhus.com) del-3.0.0/test.js000066400000000000000000000045501311653147600136060ustar00rootroot00000000000000import path from 'path'; import fs from 'fs'; import test from 'ava'; import tempy from 'tempy'; import makeDir from 'make-dir'; import m from '.'; function exists(t, files) { for (const file of files) { t.true(fs.existsSync(path.join(t.context.tmp, file))); } } function notExists(t, files) { for (const file of files) { t.false(fs.existsSync(path.join(t.context.tmp, file))); } } const fixtures = [ '1.tmp', '2.tmp', '3.tmp', '4.tmp', '.dot.tmp' ]; test.beforeEach(t => { t.context.tmp = tempy.directory(); for (const fixture of fixtures) { makeDir.sync(path.join(t.context.tmp, fixture)); } }); test('delete files - async', async t => { await m(['*.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}); 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*'], { cwd: t.context.tmp, dot: true }); exists(t, ['1.tmp']); notExists(t, ['2.tmp', '3.tmp', '4.tmp', '.dot.tmp']); }); test('take options into account - sync', t => { m.sync(['*.tmp', '!1*'], { cwd: t.context.tmp, dot: true }); exists(t, ['1.tmp']); notExists(t, ['2.tmp', '3.tmp', '4.tmp', '.dot.tmp']); }); test.serial('return deleted files - async', async t => { t.deepEqual( await m('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}), [path.join(t.context.tmp, '1.tmp')] ); }); test(`don't delete files, but return them - async`, async t => { const deletedFiles = await m(['*.tmp', '!1*'], { cwd: t.context.tmp, dryRun: true }); exists(t, ['1.tmp', '2.tmp', '3.tmp', '4.tmp', '.dot.tmp']); t.deepEqual(deletedFiles, [ path.join(t.context.tmp, '2.tmp'), path.join(t.context.tmp, '3.tmp'), path.join(t.context.tmp, '4.tmp') ]); }); test(`don't delete files, but return them - sync`, t => { const deletedFiles = m.sync(['*.tmp', '!1*'], { cwd: t.context.tmp, dryRun: true }); exists(t, ['1.tmp', '2.tmp', '3.tmp', '4.tmp', '.dot.tmp']); t.deepEqual(deletedFiles, [ path.join(t.context.tmp, '2.tmp'), path.join(t.context.tmp, '3.tmp'), path.join(t.context.tmp, '4.tmp') ]); });