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

Replace 'del' dependency by built-in recursive fs.rm #3198

Merged
merged 2 commits into from
May 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

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 @@
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;
}
}

Check warning on line 273 in lib/cli.js

View check run for this annotation

Codecov / codecov/patch

lib/cli.js#L268-L273

Added lines #L268 - L273 were not covered by tests

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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Loading