Remove the dependency of "del" (#55112)

Co-authored-by: Jake Bailey <5341706+jakebailey@users.noreply.github.com>
This commit is contained in:
Jimmy Wärting
2023-08-24 01:42:37 +02:00
committed by GitHub
parent 5fe88ea044
commit 3a22d3aded
5 changed files with 21 additions and 152 deletions

View File

@@ -2,7 +2,6 @@ import {
CancelError,
} from "@esfx/canceltoken";
import chalk from "chalk";
import del from "del";
import fs from "fs";
import os from "os";
import path from "path";
@@ -15,6 +14,7 @@ import cmdLineOptions from "./options.mjs";
import {
exec,
ExecError,
rimraf,
} from "./utils.mjs";
const mochaJs = path.resolve(findUpRoot(), "node_modules", "mocha", "bin", "_mocha");
@@ -48,16 +48,14 @@ export async function runConsoleTests(runJs, defaultReporter, runInParallel, opt
console.log(chalk.yellowBright(`[watch] cleaning test directories...`));
}
await cleanTestDirs();
await cleanCoverageDir();
await rimraf(coverageDir);
if (options.token?.signaled) {
return;
}
}
if (fs.existsSync(testConfigFile)) {
fs.unlinkSync(testConfigFile);
}
await rimraf(testConfigFile);
let workerCount, taskConfigsFolder;
if (runInParallel) {
@@ -158,8 +156,8 @@ export async function runConsoleTests(runJs, defaultReporter, runInParallel, opt
process.env.NODE_ENV = savedNodeEnv;
}
await del("test.config");
await deleteTemporaryProjectOutput();
await rimraf("test.config");
await rimraf(path.join(localBaseline, "projectOutput"));
if (error !== undefined) {
if (error instanceof CancelError) {
@@ -177,14 +175,10 @@ export async function runConsoleTests(runJs, defaultReporter, runInParallel, opt
}
export async function cleanTestDirs() {
await del([localBaseline]);
await rimraf(localBaseline);
await fs.promises.mkdir(localBaseline, { recursive: true });
}
async function cleanCoverageDir() {
await del([coverageDir]);
}
/**
* used to pass data from command line directly to run.js
* @param {string} tests
@@ -216,10 +210,6 @@ export function writeTestConfigFile(tests, runners, light, taskConfigsFolder, wo
fs.writeFileSync("test.config", testConfigContents);
}
function deleteTemporaryProjectOutput() {
return del(path.join(localBaseline, "projectOutput/"));
}
/**
* @param {string} text
*/

View File

@@ -232,3 +232,11 @@ export function memoize(fn) {
return value;
};
}
/**
* @param {fs.PathLike} p
*/
export function rimraf(p) {
// The rimraf package uses maxRetries=10 on Windows, but Node's fs.rm does not have that special case.
return fs.promises.rm(p, { recursive: true, force: true, maxRetries: process.platform === "win32" ? 10 : 0 });
}