Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider replacing del with its dependency rimraf #2952

Closed
live627 opened this issue Jan 23, 2022 · 3 comments
Closed

Consider replacing del with its dependency rimraf #2952

live627 opened this issue Jan 23, 2022 · 3 comments
Labels

Comments

@live627
Copy link
Contributor

live627 commented Jan 23, 2022

The current version of rimraf supports globs, so one could just add an asterisk to the end of the folder, like so:

diff --git a/lib/cli.js b/lib/cli.js
index 3f9974732..d50f08624 100644
--- a/lib/cli.js
+++ b/lib/cli.js
@@ -5,7 +5,7 @@ import process from 'node:process';
 
 import arrify from 'arrify';
 import ciParallelVars from 'ci-parallel-vars';
-import del from 'del';
+import rimraf from 'rimraf';
 import figures from 'figures';
 import yargs from 'yargs';
 import {hideBin} from 'yargs/helpers'; // eslint-disable-line node/file-extension-in-import
@@ -253,7 +253,7 @@ export default async function loadCli() { // eslint-disable-line complexity
 		const cacheDir = path.join(projectDir, 'node_modules', '.cache', 'ava');
 
 		try {
-			const deletedFilePaths = await del('*', {cwd: cacheDir});
+			const deletedFilePaths = rimraf(path.join(cacheDir, '*'));
 
 			if (deletedFilePaths.length === 0) {
 				console.log(`\n${chalk.green(figures.tick)} No cache files to remove`);

--- a/test-tap/api.js
+++ b/test-tap/api.js
@@ -3,7 +3,7 @@ import path from 'node:path';
 import {fileURLToPath} from 'node:url';
 
 import ciInfo from 'ci-info';
-import del from 'del';
+import rimraf from 'rimraf';
 import {test} from 'tap';
 
 import Api from '../lib/api.js';
@@ -400,7 +400,7 @@ for (const opt of options) {
 	});
 
 	test(`caching can be disabled - workerThreads: ${opt.workerThreads}`, async t => {
-		del.sync(path.join(__dirname, 'fixture/caching/node_modules'));
+		rimraf.sync(path.join(__dirname, 'fixture/caching/node_modules'));
 
 		const api = await apiCreator({
 			...opt,

Could this be simplified?

del@6.0.0 (44 deps, 809.26kb, 342 files)
├─┬ globby@11.1.0 (23 deps, 576.5kb, 238 files)
│ ├── array-union@2.1.0 (3.09kb, 5 files)
│ ├─┬ dir-glob@3.0.1 (1 dep, 10.57kb, 9 files)
│ │ ╰── path-type@4.0.0 (5.28kb, 5 files)
│ ├─┬ fast-glob@3.2.11 (17 deps, 490.43kb, 206 files)
│ │ ├── @nodelib/fs.stat@2.0.5 (11.57kb, 15 files)
│ │ ├─┬ @nodelib/fs.walk@1.2.8 (6 deps, 120.09kb, 96 files)
│ │ │ ├─┬ @nodelib/fs.scandir@2.1.5 (3 deps, 47.78kb, 47 files)
│ │ │ │ ├── @nodelib/fs.stat@2.0.5 (🔗, 11.57kb, 15 files)
│ │ │ │ ╰─┬ run-parallel@1.2.0 (1 dep, 14.58kb, 9 files)
│ │ │ │   ╰── queue-microtask@1.2.3 (8.17kb, 5 files)
│ │ │ ╰─┬ fastq@1.13.0 (1 dep, 46.54kb, 24 files)
│ │ │   ╰── reusify@1.0.4 (9.22kb, 10 files)
│ │ ├─┬ glob-parent@5.1.2 (2 deps, 31.21kb, 13 files)
│ │ │ ╰── is-glob@4.0.3 (🔗, 1 dep, 19.36kb, 8 files)
│ │ ├── merge2@1.4.1 (🔗, 8.69kb, 4 files)
│ │ ╰─┬ micromatch@4.0.4 (5 deps, 243.77kb, 38 files)
│ │   ├─┬ braces@3.0.2 (3 deps, 95.84kb, 23 files)
│ │   │ ╰─┬ fill-range@7.0.1 (2 deps, 47.76kb, 12 files)
│ │   │   ╰─┬ to-regex-range@5.0.1 (1 dep, 31.79kb, 8 files)
│ │   │     ╰── is-number@7.0.0 (9.39kb, 4 files)
│ │   ╰── picomatch@2.3.1 (87.84kb, 10 files)
│ ├── ignore@5.2.0 (47.72kb, 6 files)
│ ├── merge2@1.4.1 (8.69kb, 4 files)
│ ╰── slash@3.0.0 (🔗, 3.42kb, 5 files)
├── graceful-fs@4.2.9 (30.86kb, 7 files)
├─┬ is-glob@4.0.3 (1 dep, 19.36kb, 8 files)
│ ╰── is-extglob@2.1.1 (6.07kb, 4 files)
├── is-path-cwd@2.2.0 (2.7kb, 5 files)
├── is-path-inside@3.0.3 (4.02kb, 5 files)
├─┬ p-map@4.0.0 (3 deps, 24.69kb, 20 files)
│ ╰─┬ aggregate-error@3.1.0 (2 deps, 16.21kb, 15 files)
│   ├── clean-stack@2.2.0 (5.38kb, 5 files)
│   ╰── indent-string@4.0.0 (4.29kb, 5 files)
├─┬ rimraf@3.0.2 (12 deps, 158.96kb, 62 files)
│ ╰─┬ glob@7.2.0 (11 deps, 142.04kb, 56 files)
│   ├── fs.realpath@1.0.0 (13.12kb, 5 files)
│   ├─┬ inflight@1.0.6 (3 deps, 13.41kb, 16 files)
│   │ ├── once@1.4.0 (🔗, 1 dep, 6.84kb, 8 files)
│   │ ╰── wrappy@1.0.2 (2.89kb, 4 files)
│   ├── inherits@2.0.4 (3.87kb, 5 files)
│   ├─┬ minimatch@3.0.4 (3 deps, 54.66kb, 20 files)
│   │ ╰─┬ brace-expansion@1.1.11 (2 deps, 22.32kb, 16 files)
│   │   ├── balanced-match@1.0.2 (6.78kb, 5 files)
│   │   ╰── concat-map@0.0.1 (4.75kb, 7 files)
│   ├─┬ once@1.4.0 (1 dep, 6.84kb, 8 files)
│   │ ╰── wrappy@1.0.2 (2.89kb, 4 files)
│   ╰── path-is-absolute@1.0.1 (3.53kb, 4 files)
╰── slash@3.0.0 (3.42kb, 5 files)

I already have a commit lined up.

@live627
Copy link
Contributor Author

live627 commented Jan 23, 2022

From https://stackoverflow.com/a/57866165/4710434

recursive rmdir uses rimraf internally as can be seen in pull request nodejs/node/pull/29168

fs.rm(dir, { recursive: true, force: true });

Added in: v14.14.0

@sindresorhus
Copy link
Member

I think it's better to just wait until AVA can target Node.js 14 and use the native fs.rm method with recursive option.

@novemberborn
Copy link
Member

That'll be in a few months time actually.

We don't tend to keep issues open for this purpose though so I'll close for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants