From bde891f91d6aec2e837a960ad6e2de5ff0be4caf Mon Sep 17 00:00:00 2001 From: Craig Hobbs Date: Wed, 17 May 2023 15:27:31 -0700 Subject: [PATCH 1/2] Remove use of the "del" module. This reduces total dependencies by 11%. --- lib/cli.js | 12 +++++------- package.json | 1 - test-tap/api.js | 11 ++++++++--- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/lib/cli.js b/lib/cli.js index 20f2b67b7..4581af4fb 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -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 @@ -261,14 +260,13 @@ 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}); - - if (deletedFilePaths.length === 0) { - console.log(`\n${chalk.green(figures.tick)} No cache files to remove`); + if (fs.existsSync(cacheDir)) { + fs.rmSync(cacheDir, {recursive: true, force: true}); + fs.mkdirSync(cacheDir); + console.log(`\n${chalk.green(figures.tick)} Emptied AVA cache cache directory ${cacheDir}`); } else { - console.log(`\n${chalk.green(figures.tick)} Removed AVA cache files in ${cacheDir}`); + console.log(`\n${chalk.green(figures.tick)} No cache directory to remove`); } process.exit(0); // eslint-disable-line unicorn/no-process-exit diff --git a/package.json b/package.json index 3e5caa15c..9b1d34427 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/test-tap/api.js b/test-tap/api.js index 0d0c271e5..baf7d902b 100644 --- a/test-tap/api.js +++ b/test-tap/api.js @@ -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'; @@ -380,7 +379,10 @@ for (const opt of options) { }); test(`caching is enabled by default - workerThreads: ${opt.workerThreads}`, async t => { - deleteSync(path.join(__dirname, 'fixture/caching/node_modules')); + const nodeModulesPath = path.join(__dirname, 'fixture/caching/node_modules'); + if (fs.existsSync(nodeModulesPath)) { + fs.rmSync(nodeModulesPath, {recursive: true, force: true}); + } const api = await apiCreator({ ...opt, @@ -400,7 +402,10 @@ for (const opt of options) { }); test(`caching can be disabled - workerThreads: ${opt.workerThreads}`, async t => { - deleteSync(path.join(__dirname, 'fixture/caching/node_modules')); + const nodeModulesPath = path.join(__dirname, 'fixture/caching/node_modules'); + if (fs.existsSync(nodeModulesPath)) { + fs.rmSync(nodeModulesPath, {recursive: true, force: true}); + } const api = await apiCreator({ ...opt, From 9f2c8c6c1ba9726073e054a04345f36c741967e5 Mon Sep 17 00:00:00 2001 From: Mark Wubben Date: Sun, 21 May 2023 16:57:27 +0200 Subject: [PATCH 2/2] Remove unnecessary guards, match existing log output --- lib/cli.js | 23 ++++++++++++++++++----- test-tap/api.js | 10 ++-------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/lib/cli.js b/lib/cli.js index 4581af4fb..b613666c8 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -261,12 +261,25 @@ export default async function loadCli() { // eslint-disable-line complexity if (resetCache) { const cacheDir = path.join(projectDir, 'node_modules', '.cache', 'ava'); try { - if (fs.existsSync(cacheDir)) { - fs.rmSync(cacheDir, {recursive: true, force: true}); - fs.mkdirSync(cacheDir); - console.log(`\n${chalk.green(figures.tick)} Emptied AVA cache cache directory ${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 (entries.length === 0) { + console.log(`\n${chalk.green(figures.tick)} No cache files to remove`); } else { - console.log(`\n${chalk.green(figures.tick)} No cache directory to remove`); + console.log(`\n${chalk.green(figures.tick)} Removed AVA cache files in ${cacheDir}`); } process.exit(0); // eslint-disable-line unicorn/no-process-exit diff --git a/test-tap/api.js b/test-tap/api.js index baf7d902b..b395d81f8 100644 --- a/test-tap/api.js +++ b/test-tap/api.js @@ -379,10 +379,7 @@ for (const opt of options) { }); test(`caching is enabled by default - workerThreads: ${opt.workerThreads}`, async t => { - const nodeModulesPath = path.join(__dirname, 'fixture/caching/node_modules'); - if (fs.existsSync(nodeModulesPath)) { - fs.rmSync(nodeModulesPath, {recursive: true, force: true}); - } + fs.rmSync(path.join(__dirname, 'fixture/caching/node_modules'), {recursive: true, force: true}); const api = await apiCreator({ ...opt, @@ -402,10 +399,7 @@ for (const opt of options) { }); test(`caching can be disabled - workerThreads: ${opt.workerThreads}`, async t => { - const nodeModulesPath = path.join(__dirname, 'fixture/caching/node_modules'); - if (fs.existsSync(nodeModulesPath)) { - fs.rmSync(nodeModulesPath, {recursive: true, force: true}); - } + fs.rmSync(path.join(__dirname, 'fixture/caching/node_modules'), {recursive: true, force: true}); const api = await apiCreator({ ...opt,