1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-19 06:38:07 +02:00

Remove the rimraf dependency in favor of the built-in Node.js fs.rmSync in the test folder

In Node.js 14.14.0 the `fs.rmSync` function was added that removes files
and directories. The `recursive` option is used to remove directories
and their contents, making it a drop-in replacement for the `rimraf`
dependency we use.

Given that PDF.js now requires Node.js 18+ we can be sure that this
option is available, so we can safely remove `rimraf` and reduce the
number of project dependencies in the test folder.

This commit also gets rid of the indirection via the `removeDirSync`
test helper function by simply calling `fs.rmSync` directly.

Co-authored-by: Wojciech Maj <kontakt@wojtekmaj.pl>
This commit is contained in:
Tim van der Meij 2024-04-14 16:33:16 +02:00
parent e08de772ff
commit a562c41e12
No known key found for this signature in database
GPG key ID: 8C3FD2925A5F2762
2 changed files with 7 additions and 20 deletions

View file

@ -15,7 +15,7 @@
*/ */
/* eslint-disable no-var */ /* eslint-disable no-var */
import { copySubtreeSync, ensureDirSync, removeDirSync } from "./testutils.mjs"; import { copySubtreeSync, ensureDirSync } from "./testutils.mjs";
import { import {
downloadManifestFiles, downloadManifestFiles,
verifyManifestFiles, verifyManifestFiles,
@ -25,14 +25,11 @@ import os from "os";
import path from "path"; import path from "path";
import puppeteer from "puppeteer"; import puppeteer from "puppeteer";
import readline from "readline"; import readline from "readline";
import rimraf from "rimraf";
import { translateFont } from "./font/ttxdriver.mjs"; import { translateFont } from "./font/ttxdriver.mjs";
import url from "url"; import url from "url";
import { WebServer } from "./webserver.mjs"; import { WebServer } from "./webserver.mjs";
import yargs from "yargs"; import yargs from "yargs";
const rimrafSync = rimraf.sync;
function parseOptions() { function parseOptions() {
const parsedArgs = yargs(process.argv) const parsedArgs = yargs(process.argv)
.usage("Usage: $0") .usage("Usage: $0")
@ -213,7 +210,7 @@ function updateRefImages() {
console.log(" Updating ref/ ... "); console.log(" Updating ref/ ... ");
copySubtreeSync(refsTmpDir, refsDir); copySubtreeSync(refsTmpDir, refsDir);
if (removeTmp) { if (removeTmp) {
removeDirSync(refsTmpDir); fs.rmSync(refsTmpDir, { recursive: true, force: true });
} }
console.log("done"); console.log("done");
} }
@ -324,7 +321,7 @@ async function startRefTest(masterMode, showRefImages) {
fs.unlinkSync(eqLog); fs.unlinkSync(eqLog);
} }
if (fs.existsSync(testResultDir)) { if (fs.existsSync(testResultDir)) {
removeDirSync(testResultDir); fs.rmSync(testResultDir, { recursive: true, force: true });
} }
startTime = Date.now(); startTime = Date.now();
@ -358,7 +355,7 @@ async function startRefTest(masterMode, showRefImages) {
function checkRefsTmp() { function checkRefsTmp() {
if (masterMode && fs.existsSync(refsTmpDir)) { if (masterMode && fs.existsSync(refsTmpDir)) {
if (options.noPrompts) { if (options.noPrompts) {
removeDirSync(refsTmpDir); fs.rmSync(refsTmpDir, { recursive: true, force: true });
setup(); setup();
return; return;
} }
@ -370,7 +367,7 @@ async function startRefTest(masterMode, showRefImages) {
"SHOULD THIS SCRIPT REMOVE tmp/? THINK CAREFULLY [yn] ", "SHOULD THIS SCRIPT REMOVE tmp/? THINK CAREFULLY [yn] ",
function (answer) { function (answer) {
if (answer.toLowerCase() === "y") { if (answer.toLowerCase() === "y") {
removeDirSync(refsTmpDir); fs.rmSync(refsTmpDir, { recursive: true, force: true });
} }
setup(); setup();
reader.close(); reader.close();
@ -1038,7 +1035,7 @@ async function closeSession(browser) {
}); });
if (allClosed) { if (allClosed) {
if (tempDir) { if (tempDir) {
rimrafSync(tempDir); fs.rmSync(tempDir, { recursive: true, force: true });
} }
onAllSessionsClosed?.(); onAllSessionsClosed?.();
} }

View file

@ -16,16 +16,6 @@
import fs from "fs"; import fs from "fs";
import path from "path"; import path from "path";
import rimraf from "rimraf";
const rimrafSync = rimraf.sync;
function removeDirSync(dir) {
fs.readdirSync(dir); // Will throw if dir is not a directory
rimrafSync(dir, {
disableGlob: true,
});
}
function copySubtreeSync(src, dest) { function copySubtreeSync(src, dest) {
const files = fs.readdirSync(src); const files = fs.readdirSync(src);
@ -63,4 +53,4 @@ function ensureDirSync(dir) {
} }
} }
export { copySubtreeSync, ensureDirSync, removeDirSync }; export { copySubtreeSync, ensureDirSync };