Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: sindresorhus/del
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v5.1.0
Choose a base ref
...
head repository: sindresorhus/del
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v6.0.0
Choose a head ref
  • 8 commits
  • 6 files changed
  • 3 contributors

Commits on Aug 28, 2019

  1. Fix benchmark

    sindresorhus committed Aug 28, 2019

    Verified

    This commit was signed with the committer’s verified signature.
    AtofStryker Bill Glesias
    Copy the full SHA
    728cb7c View commit details

Commits on Sep 9, 2019

  1. Verified

    This commit was signed with the committer’s verified signature.
    AtofStryker Bill Glesias
    Copy the full SHA
    892ce2a View commit details

Commits on Oct 30, 2019

  1. Tidelift tasks

    sindresorhus committed Oct 30, 2019
    Copy the full SHA
    1e0d705 View commit details

Commits on Dec 16, 2019

  1. Copy the full SHA
    1a0c36c View commit details

Commits on Feb 24, 2020

  1. Add tip about deleting subdirectories (#116)

    Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
    deadcoder0904 and sindresorhus authored Feb 24, 2020
    Copy the full SHA
    4acd962 View commit details

Commits on Jul 5, 2020

  1. Readme tweaks

    sindresorhus committed Jul 5, 2020
    Copy the full SHA
    1df5280 View commit details

Commits on Sep 26, 2020

  1. Require Node.js 10

    sindresorhus committed Sep 26, 2020
    Copy the full SHA
    6c99805 View commit details
  2. 6.0.0

    sindresorhus committed Sep 26, 2020
    Copy the full SHA
    cd0543e View commit details
Showing with 60 additions and 64 deletions.
  1. +1 −1 .travis.yml
  2. +7 −8 benchmark.js
  3. +16 −16 index.d.ts
  4. +1 −1 license
  5. +14 −13 package.json
  6. +21 −25 readme.md
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -4,6 +4,6 @@ os:
- windows
language: node_js
node_js:
- '14'
- '12'
- '10'
- '8'
15 changes: 7 additions & 8 deletions benchmark.js
Original file line number Diff line number Diff line change
@@ -7,15 +7,15 @@ const del = require('.');

const suite = new Benchmark.Suite('concurrency');

const tempDir = tempy.directory();
const temporaryDir = tempy.directory();

const fixtures = Array.from({length: 2000}, (_, index) => {
return path.resolve(tempDir, (index + 1).toString());
return path.resolve(temporaryDir, (index + 1).toString());
});

function createFixtures() {
for (const fixture of fixtures) {
makeDir.sync(path.resolve(tempDir, fixture));
makeDir.sync(path.resolve(temporaryDir, fixture));
}
}

@@ -42,26 +42,25 @@ for (const concurrency of concurrencies) {
suite.add({
name,
defer: true,
setup() {}, // This line breaks async await
async fn(deferred) {
// Can't use `setup()` because it isn't called after every
// defer and it breaks using `async` keyword here.
// https://github.com/bestiejs/benchmark.js/issues/136
createFixtures();

const removedFiles = await del(['**/*'], {
cwd: tempDir,
cwd: temporaryDir,
concurrency
});

if (removedFiles.length !== fixtures.length) {
const error = new Error(
`"${name}": files removed: ${removedFiles.length}, expected: ${fixtures.length}`,
`"${name}": files removed: ${removedFiles.length}, expected: ${fixtures.length}`
);

console.error(error);

del.sync(tempDir, {cwd: tempDir, force: true});
del.sync(temporaryDir, {cwd: temporaryDir, force: true});

// eslint-disable-next-line unicorn/no-process-exit
process.exit(1);
@@ -79,6 +78,6 @@ suite
.on('complete', function () {
console.log(`Fastest is ${this.filter('fastest').map('name')}`);

del.sync(tempDir, {cwd: tempDir, force: true});
del.sync(temporaryDir, {cwd: temporaryDir, force: true});
})
.run({async: true});
32 changes: 16 additions & 16 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -37,6 +37,22 @@ declare namespace del {
}

declare const del: {
/**
Synchronously delete files and directories using glob patterns.
Note that glob patterns can only contain forward-slashes, not backward-slashes. Windows file paths can use backward-slashes as long as the path does not contain any glob-like characters, otherwise use `path.posix.join()` instead of `path.join()`.
@param patterns - See the supported [glob patterns](https://github.com/sindresorhus/globby#globbing-patterns).
- [Pattern examples with expected matches](https://github.com/sindresorhus/multimatch/blob/master/test/test.js)
- [Quick globbing pattern overview](https://github.com/sindresorhus/multimatch#globbing-patterns)
@param options - You can specify any of the [`globby` options](https://github.com/sindresorhus/globby#options) in addition to the `del` options. In contrast to the `globby` defaults, `expandDirectories`, `onlyFiles`, and `followSymbolicLinks` are `false` by default.
@returns The deleted paths.
*/
sync: (
patterns: string | readonly string[],
options?: del.Options
) => string[];

/**
Delete files and directories using glob patterns.
@@ -63,22 +79,6 @@ declare const del: {
patterns: string | readonly string[],
options?: del.Options
): Promise<string[]>;

/**
Synchronously delete files and directories using glob patterns.
Note that glob patterns can only contain forward-slashes, not backward-slashes. Windows file paths can use backward-slashes as long as the path does not contain any glob-like characters, otherwise use `path.posix.join()` instead of `path.join()`.
@param patterns - See the supported [glob patterns](https://github.com/sindresorhus/globby#globbing-patterns).
- [Pattern examples with expected matches](https://github.com/sindresorhus/multimatch/blob/master/test/test.js)
- [Quick globbing pattern overview](https://github.com/sindresorhus/multimatch#globbing-patterns)
@param options - You can specify any of the [`globby` options](https://github.com/sindresorhus/globby#options) in addition to the `del` options. In contrast to the `globby` defaults, `expandDirectories`, `onlyFiles`, and `followSymbolicLinks` are `false` by default.
@returns The deleted paths.
*/
sync(
patterns: string | readonly string[],
options?: del.Options
): string[];
};

export = del;
2 changes: 1 addition & 1 deletion license
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://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:

27 changes: 14 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
{
"name": "del",
"version": "5.1.0",
"version": "6.0.0",
"description": "Delete files and directories",
"license": "MIT",
"repository": "sindresorhus/del",
"funding": "https://github.com/sponsors/sindresorhus",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
"url": "https://sindresorhus.com"
},
"engines": {
"node": ">=8"
"node": ">=10"
},
"scripts": {
"test": "xo && ava && tsd",
@@ -45,21 +46,21 @@
"filesystem"
],
"dependencies": {
"globby": "^10.0.1",
"graceful-fs": "^4.2.2",
"globby": "^11.0.1",
"graceful-fs": "^4.2.4",
"is-glob": "^4.0.1",
"is-path-cwd": "^2.2.0",
"is-path-inside": "^3.0.1",
"p-map": "^3.0.0",
"rimraf": "^3.0.0",
"is-path-inside": "^3.0.2",
"p-map": "^4.0.0",
"rimraf": "^3.0.2",
"slash": "^3.0.0"
},
"devDependencies": {
"ava": "^2.3.0",
"ava": "^2.4.0",
"benchmark": "^2.1.4",
"make-dir": "^3.0.0",
"tempy": "^0.3.0",
"tsd": "^0.7.4",
"xo": "^0.24.0"
"make-dir": "^3.1.0",
"tempy": "^0.7.0",
"tsd": "^0.13.1",
"xo": "^0.33.1"
}
}
46 changes: 21 additions & 25 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
# 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/xojs/xo)
# del [![Build Status](https://travis-ci.com/sindresorhus/del.svg?branch=master)](https://travis-ci.com/github/sindresorhus/del) [![XO code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg)](https://github.com/xojs/xo)

> Delete files and directories using [globs](https://github.com/sindresorhus/globby#globbing-patterns)
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.


## Install

```
$ npm install del
```


## Usage

```js
const del = require('del');

(async () => {
const deletedPaths = await del(['temp/*.js', '!temp/unicorn.js']);
const deletedFilePaths = await del(['temp/*.js', '!temp/unicorn.js']);
const deletedDirectoryPaths = await del(['temp', 'public']);

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

## Beware
The glob pattern `**` matches all children and *the parent*.
@@ -41,8 +41,13 @@ You have to explicitly ignore the parent directories too:
del.sync(['public/assets/**', '!public/assets', '!public/assets/goat.png']);
```

Suggestions on how to improve this welcome!
To delete all subdirectories inside `public/`, you can do:

```js
del.sync(['public/*/']);
```

Suggestions on how to improve this welcome!

## API

@@ -73,14 +78,14 @@ You can specify any of the [`globby` options](https://github.com/sindresorhus/gl

##### force

Type: `boolean`<br>
Type: `boolean`\
Default: `false`

Allow deleting the current working directory and outside.

##### dryRun

Type: `boolean`<br>
Type: `boolean`\
Default: `false`

See what would be deleted.
@@ -97,32 +102,23 @@ const del = require('del');

##### concurrency

Type: `number`<br>
Default: `Infinity`<br>
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.

## del for enterprise

Available as part of the Tidelift Subscription.

The maintainers of del and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. [Learn more.](https://tidelift.com/subscription/pkg/npm-del?utm_source=npm-del&utm_medium=referral&utm_campaign=enterprise&utm_term=repo)

## 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


---

<div align="center">
<b>
<a href="https://tidelift.com/subscription/pkg/npm-del?utm_source=npm-del&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
</b>
<br>
<sub>
Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
</sub>
</div>