Skip to content

Commit

Permalink
Replace 'del' dependency by built-in recursive fs.rm (#3198)
Browse files Browse the repository at this point in the history
Co-authored-by: Mark Wubben <mark@novemberborn.net>
  • Loading branch information
craigahobbs and novemberborn committed May 24, 2023
1 parent d7c6120 commit faa9654
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
19 changes: 15 additions & 4 deletions lib/cli.js
Expand Up @@ -5,7 +5,6 @@ import process from 'node:process';

import arrify from 'arrify';
import ciParallelVars from 'ci-parallel-vars';
import {deleteAsync} from 'del';
import figures from 'figures';
import yargs from 'yargs';
import {hideBin} from 'yargs/helpers'; // eslint-disable-line n/file-extension-in-import
Expand Down Expand Up @@ -261,11 +260,23 @@ export default async function loadCli() { // eslint-disable-line complexity
const {nonSemVerExperiments: experiments, projectDir} = conf;
if (resetCache) {
const cacheDir = path.join(projectDir, 'node_modules', '.cache', 'ava');

try {
const deletedFilePaths = await deleteAsync('*', {cwd: cacheDir});
let entries;
try {
entries = fs.readdirSync(cacheDir);
} catch (error) {
if (error.code === 'ENOENT') {
entries = [];
} else {
throw error;
}
}

for (const entry of entries) {
fs.rmSync(path.join(cacheDir, entry), {recursive: true, force: true});
}

if (deletedFilePaths.length === 0) {
if (entries.length === 0) {
console.log(`\n${chalk.green(figures.tick)} No cache files to remove`);
} else {
console.log(`\n${chalk.green(figures.tick)} Removed AVA cache files in ${cacheDir}`);
Expand Down
1 change: 0 additions & 1 deletion package.json
Expand Up @@ -100,7 +100,6 @@
"concordance": "^5.0.4",
"currently-unhandled": "^0.4.1",
"debug": "^4.3.4",
"del": "^7.0.0",
"emittery": "^1.0.1",
"figures": "^5.0.0",
"globby": "^13.1.3",
Expand Down
5 changes: 2 additions & 3 deletions test-tap/api.js
Expand Up @@ -3,7 +3,6 @@ import path from 'node:path';
import {fileURLToPath} from 'node:url';

import ciInfo from 'ci-info';
import {deleteSync} from 'del';
import {test} from 'tap';

import Api from '../lib/api.js';
Expand Down Expand Up @@ -380,7 +379,7 @@ for (const opt of options) {
});

test(`caching is enabled by default - workerThreads: ${opt.workerThreads}`, async t => {
deleteSync(path.join(__dirname, 'fixture/caching/node_modules'));
fs.rmSync(path.join(__dirname, 'fixture/caching/node_modules'), {recursive: true, force: true});

const api = await apiCreator({
...opt,
Expand All @@ -400,7 +399,7 @@ for (const opt of options) {
});

test(`caching can be disabled - workerThreads: ${opt.workerThreads}`, async t => {
deleteSync(path.join(__dirname, 'fixture/caching/node_modules'));
fs.rmSync(path.join(__dirname, 'fixture/caching/node_modules'), {recursive: true, force: true});

const api = await apiCreator({
...opt,
Expand Down

0 comments on commit faa9654

Please sign in to comment.