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: 3a97a5ba131055fbf7eb39f5ed47db86a2fd4497
Choose a base ref
...
head repository: sindresorhus/del
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 51344d2ec4efece380768c44f3cc74f2b2c06590
Choose a head ref

Commits on Oct 26, 2016

  1. add XO badge

    sindresorhus authored Oct 26, 2016
    Copy the full SHA
    d3c64eb View commit details
  2. pin XO

    sindresorhus committed Oct 26, 2016
    Copy the full SHA
    b33ee97 View commit details

Commits on Apr 5, 2017

  1. Copy the full SHA
    6e84fee View commit details
  2. Copy the full SHA
    614368b View commit details

Commits on May 9, 2017

  1. Copy the full SHA
    f181a1f View commit details

Commits on May 11, 2017

  1. Meta tweaks

    sindresorhus committed May 11, 2017
    Copy the full SHA
    22a9ab5 View commit details

Commits on Jun 9, 2017

  1. Add concurrency option

    sindresorhus committed Jun 9, 2017
    Copy the full SHA
    b242094 View commit details
  2. Meta tweaks

    sindresorhus committed Jun 9, 2017
    Copy the full SHA
    d70b81d View commit details
  3. 3.0.0

    sindresorhus committed Jun 9, 2017
    Copy the full SHA
    255ab75 View commit details

Commits on Jan 11, 2018

  1. Update link in readme (#66)

    luftywiranda13 authored and SamVerschueren committed Jan 11, 2018
    Copy the full SHA
    072362b View commit details

Commits on Feb 14, 2018

  1. Update URL to XO

    sindresorhus committed Feb 14, 2018
    Copy the full SHA
    cdd9c76 View commit details

Commits on Nov 26, 2018

  1. Require Node.js 6

    Fixes #74
    sindresorhus committed Nov 26, 2018
    Copy the full SHA
    434c9f6 View commit details

Commits on Jan 24, 2019

  1. Fix readme typo (#78)

    vladshcherbin authored and sindresorhus committed Jan 24, 2019
    Copy the full SHA
    2b3ee82 View commit details

Commits on Feb 27, 2019

  1. Fix typo in error message (#80)

    chrisblossom authored and sindresorhus committed Feb 27, 2019
    Copy the full SHA
    e73cc8a View commit details

Commits on Mar 3, 2019

  1. Copy the full SHA
    34c771e View commit details
  2. 4.0.0

    sindresorhus committed Mar 3, 2019
    Copy the full SHA
    49e955b View commit details

Commits on Apr 1, 2019

  1. Copy the full SHA
    3f0d604 View commit details
  2. 4.1.0

    sindresorhus committed Apr 1, 2019
    Copy the full SHA
    c1ffcfb View commit details

Commits on Apr 26, 2019

  1. Add Node.js 12 to testing (#87)

    coreyfarrell authored and sindresorhus committed Apr 26, 2019
    Copy the full SHA
    f30ca85 View commit details

Commits on Apr 28, 2019

  1. Fix missing TypeScript import

    Fixes #83
    sindresorhus committed Apr 28, 2019
    Copy the full SHA
    0361dcc View commit details
  2. 4.1.1

    sindresorhus committed Apr 28, 2019
    Copy the full SHA
    31be0e7 View commit details

Commits on May 27, 2019

  1. Copy the full SHA
    535d775 View commit details
  2. Require Node.js 8

    sindresorhus committed May 27, 2019
    Copy the full SHA
    42e67a8 View commit details

Commits on May 31, 2019

  1. Tidelift tasks

    sindresorhus committed May 31, 2019
    Copy the full SHA
    6e23f6a View commit details

Commits on Jul 2, 2019

  1. Copy the full SHA
    6f96d2d View commit details
  2. Meta tweaks

    sindresorhus committed Jul 2, 2019
    Copy the full SHA
    a73462c View commit details
  3. 5.0.0

    sindresorhus committed Jul 2, 2019
    Copy the full SHA
    c071180 View commit details

Commits on Jul 5, 2019

  1. Add note about backward-slashes

    Fixes #93
    sindresorhus committed Jul 5, 2019
    Copy the full SHA
    9e7550b View commit details

Commits on Jul 12, 2019

  1. Copy the full SHA
    8efdbcd View commit details
  2. Fix the cwd option (#96)

    chrisblossom authored and sindresorhus committed Jul 12, 2019
    Copy the full SHA
    ffbf4c4 View commit details
  3. Meta tweaks

    sindresorhus committed Jul 12, 2019
    Copy the full SHA
    902b594 View commit details

Commits on Jul 13, 2019

  1. Copy the full SHA
    51662ac View commit details

Commits on Jul 16, 2019

  1. Sort removed files (#102)

    chrisblossom authored and sindresorhus committed Jul 16, 2019
    Copy the full SHA
    ca05c65 View commit details

Commits on Aug 22, 2019

  1. Update dependencies (#109)

    chrisblossom authored and sindresorhus committed Aug 22, 2019
    Copy the full SHA
    f509a89 View commit details
  2. Use graceful-fs (#108)

    chrisblossom authored and sindresorhus committed Aug 22, 2019
    Copy the full SHA
    1299747 View commit details

Commits on Aug 23, 2019

  1. Add benchmarks (#101)

    chrisblossom authored and sindresorhus committed Aug 23, 2019
    Copy the full SHA
    9c72270 View commit details
  2. Allow non-glob patterns with backslash on Windows (#100)

    This reverts commit 60e9d54
    chrisblossom authored and sindresorhus committed Aug 23, 2019
    Copy the full SHA
    01da91f View commit details
  3. Meta tweaks

    sindresorhus committed Aug 23, 2019
    Copy the full SHA
    12c443d View commit details
  4. 5.1.0

    sindresorhus committed Aug 23, 2019
    Copy the full SHA
    557c1fa View commit details

Commits on Aug 28, 2019

  1. Fix benchmark

    sindresorhus committed Aug 28, 2019
    Copy the full SHA
    728cb7c View commit details

Commits on Sep 9, 2019

  1. 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

Commits on Sep 27, 2020

  1. Fix readme typo (#129)

    SimenB authored Sep 27, 2020
    Copy the full SHA
    72007d7 View commit details

Commits on Jan 2, 2021

  1. Copy the full SHA
    d0030ba View commit details

Commits on Jan 24, 2021

  1. Copy the full SHA
    7c756b3 View commit details
Showing with 863 additions and 204 deletions.
  1. +1 −4 .editorconfig
  2. +1 −1 .gitattributes
  3. +3 −0 .github/security.md
  4. +26 −0 .github/workflows/main.yml
  5. +1 −0 .gitignore
  6. +1 −0 .npmrc
  7. +0 −7 .travis.yml
  8. +81 −0 benchmark.js
  9. +113 −0 index.d.ts
  10. +97 −49 index.js
  11. +25 −0 index.test-d.ts
  12. +5 −17 license
  13. +71 −59 package.json
  14. +103 −38 readme.md
  15. +335 −29 test.js
5 changes: 1 addition & 4 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -7,9 +7,6 @@ charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[{package.json,*.yml}]
[*.yml]
indent_style = space
indent_size = 2

[*.md]
trim_trailing_whitespace = false
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* text=auto
* text=auto eol=lf
3 changes: 3 additions & 0 deletions .github/security.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Security Policy

To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure.
26 changes: 26 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: CI
on:
- push
- pull_request
jobs:
test:
name: Node.js ${{ matrix.node-version }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
node-version:
- 22
- 20
- 18
os:
- ubuntu-latest
- macos-latest
- windows-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm test
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
7 changes: 0 additions & 7 deletions .travis.yml

This file was deleted.

81 changes: 81 additions & 0 deletions benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import fs from 'node:fs';
import path from 'node:path';
import process from 'node:process';
import Benchmark from 'benchmark';
import {temporaryDirectory} from 'tempy';
import {deleteAsync, deleteSync} from './index.js';

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

const temporaryDirectoryPath = temporaryDirectory();

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

function createFixtures() {
for (const fixture of fixtures) {
fs.mkdirSync(path.resolve(temporaryDirectoryPath, fixture), {recursive: true});
}
}

const concurrencies = [
1,
3,
5,
10,
15,
20,
50,
100,
200,
300,
400,
500,
1000,
Number.POSITIVE_INFINITY,
];

for (const concurrency of concurrencies) {
const name = `concurrency: ${concurrency.toString()}`;

suite.add({
name,
defer: true,
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 deleteAsync(['**/*'], {
cwd: temporaryDirectoryPath,
concurrency,
});

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

console.error(error);

deleteSync(temporaryDirectoryPath, {cwd: temporaryDirectoryPath, force: true});

// eslint-disable-next-line unicorn/no-process-exit
process.exit(1);
}

deferred.resolve();
},
});
}

suite
.on('cycle', event => {
console.log(String(event.target));
})
.on('complete', function () {
console.log(`Fastest is ${this.filter('fastest').map('name')}`);

deleteSync(temporaryDirectoryPath, {cwd: temporaryDirectoryPath, force: true});
})
.run({async: true});
113 changes: 113 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import {type Options as GlobbyOptions} from 'globby';

export type ProgressData = {
/**
Deleted files and directories count.
*/
readonly deletedCount: number;

/**
Total files and directories count.
*/
readonly totalCount: number;

/**
Completed percentage. A value between `0` and `1`.
*/
readonly percent: number;

/**
The absolute path of the deleted file or directory.
It will not be present if nothing was deleted.
*/
readonly path?: string;
};

export type Options = {
/**
Allow deleting the current working directory and outside.
@default false
*/
readonly force?: boolean;

/**
See what would be deleted.
@default false
@example
```
import {deleteAsync} from 'del';
const deletedPaths = await deleteAsync(['temp/*.js'], {dryRun: true});
console.log('Files and directories that would be deleted:\n', deletedPaths.join('\n'));
```
*/
readonly dryRun?: boolean;

/**
Concurrency limit. Minimum: `1`.
@default Infinity
*/
readonly concurrency?: number;

/**
Called after each file or directory is deleted.
@example
```
import {deleteAsync} from 'del';
await deleteAsync(patterns, {
onProgress: progress => {
// …
}});
```
*/
readonly onProgress?: (progress: ProgressData) => void;
} & GlobbyOptions;

/**
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/main/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.
@example
```
import {deleteAsync} from 'del';
const deletedPaths = await deleteAsync(['temp/*.js', '!temp/unicorn.js']);
console.log('Deleted files and directories:\n', deletedPaths.join('\n'));
```
*/
export function deleteAsync(
patterns: string | readonly string[],
options?: 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/main/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.
*/
export function deleteSync(
patterns: string | readonly string[],
options?: Options
): string[];
Loading