1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-19 14:48:08 +02:00

Remove the mkdirp dependency in favor of the built-in Node.js fs.mkdirSync

In Node.js 10.12.0 the `recursive` option was added to `fs.mkdirSync`.
This option allows us to create a directory and all its parent
directories if they do not exist, making it a drop-in replacement for
the `mkdirp` 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 `mkdirp` and reduce the
number of project dependencies.

Co-authored-by: Wojciech Maj <kontakt@wojtekmaj.pl>
This commit is contained in:
Tim van der Meij 2024-04-12 14:30:06 +02:00
parent 2e94511330
commit 13afff48f8
No known key found for this signature in database
GPG key ID: 8C3FD2925A5F2762
3 changed files with 15 additions and 32 deletions

View file

@ -26,7 +26,6 @@ import { fileURLToPath } from "url";
import fs from "fs";
import gulp from "gulp";
import merge from "merge-stream";
import { mkdirp } from "mkdirp";
import path from "path";
import postcss from "gulp-postcss";
import postcssDarkThemeClass from "postcss-dark-theme-class";
@ -670,7 +669,7 @@ function replaceInFile(filePath, find, replacement) {
}
function getTempFile(prefix, suffix) {
mkdirp.sync(BUILD_DIR + "tmp/");
fs.mkdirSync(BUILD_DIR + "tmp/", { recursive: true });
const bytes = crypto.randomBytes(6).toString("hex");
const filePath = BUILD_DIR + "tmp/" + prefix + bytes + suffix;
fs.writeFileSync(filePath, "");
@ -926,7 +925,7 @@ gulp.task("locale", function () {
console.log("### Building localization files");
rimraf.sync(VIEWER_LOCALE_OUTPUT);
mkdirp.sync(VIEWER_LOCALE_OUTPUT);
fs.mkdirSync(VIEWER_LOCALE_OUTPUT, { recursive: true });
const subfolders = fs.readdirSync(L10N_DIR);
subfolders.sort();
@ -942,7 +941,7 @@ gulp.task("locale", function () {
continue;
}
mkdirp.sync(VIEWER_LOCALE_OUTPUT + "/" + locale);
fs.mkdirSync(VIEWER_LOCALE_OUTPUT + "/" + locale, { recursive: true });
locales.push(locale);
@ -1511,14 +1510,15 @@ gulp.task("jsdoc", function (done) {
const JSDOC_FILES = ["src/display/api.js"];
rimraf(JSDOC_BUILD_DIR, function () {
mkdirp(JSDOC_BUILD_DIR).then(function () {
const command =
'"node_modules/.bin/jsdoc" -d ' +
JSDOC_BUILD_DIR +
" " +
JSDOC_FILES.join(" ");
exec(command, done);
});
fs.mkdirSync(JSDOC_BUILD_DIR, { recursive: true });
const command =
'"node_modules/.bin/jsdoc" -d ' +
JSDOC_BUILD_DIR +
" " +
JSDOC_FILES.join(" ");
exec(command, done);
});
});
@ -1862,7 +1862,7 @@ function createBaseline(done) {
let initializeCommand = "git fetch origin";
if (!checkDir(BASELINE_DIR)) {
mkdirp.sync(BASELINE_DIR);
fs.mkdirSync(BASELINE_DIR, { recursive: true });
initializeCommand = "git clone ../../ .";
}
@ -2198,7 +2198,7 @@ gulp.task(
console.log("### Cloning baseline distribution");
rimraf.sync(DIST_DIR);
mkdirp.sync(DIST_DIR);
fs.mkdirSync(DIST_DIR, { recursive: true });
safeSpawnSync("git", ["clone", "--depth", "1", DIST_REPO_URL, DIST_DIR]);
console.log();
@ -2346,7 +2346,7 @@ gulp.task(
// Copy the mozcentral build to the mozcentral baseline directory.
rimraf.sync(MOZCENTRAL_BASELINE_DIR);
mkdirp.sync(MOZCENTRAL_BASELINE_DIR);
fs.mkdirSync(MOZCENTRAL_BASELINE_DIR, { recursive: true });
gulp
.src([BASELINE_DIR + BUILD_DIR + "mozcentral/**/*"])