mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-19 14:48:08 +02:00
Remove the rimraf
dependency in favor of the built-in Node.js fs.rmSync
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. Co-authored-by: Wojciech Maj <kontakt@wojtekmaj.pl>
This commit is contained in:
parent
0603d1ac18
commit
fad14321a8
3 changed files with 39 additions and 29 deletions
66
gulpfile.mjs
66
gulpfile.mjs
|
@ -35,7 +35,6 @@ import postcssNesting from "postcss-nesting";
|
|||
import { preprocess } from "./external/builder/builder.mjs";
|
||||
import rename from "gulp-rename";
|
||||
import replace from "gulp-replace";
|
||||
import rimraf from "rimraf";
|
||||
import stream from "stream";
|
||||
import streamqueue from "streamqueue";
|
||||
import TerserPlugin from "terser-webpack-plugin";
|
||||
|
@ -918,7 +917,7 @@ gulp.task("locale", function () {
|
|||
console.log();
|
||||
console.log("### Building localization files");
|
||||
|
||||
rimraf.sync(VIEWER_LOCALE_OUTPUT);
|
||||
fs.rmSync(VIEWER_LOCALE_OUTPUT, { recursive: true, force: true });
|
||||
fs.mkdirSync(VIEWER_LOCALE_OUTPUT, { recursive: true });
|
||||
|
||||
const subfolders = fs.readdirSync(L10N_DIR);
|
||||
|
@ -1020,7 +1019,7 @@ function preprocessHTML(source, defines) {
|
|||
}
|
||||
|
||||
function buildGeneric(defines, dir) {
|
||||
rimraf.sync(dir);
|
||||
fs.rmSync(dir, { recursive: true, force: true });
|
||||
|
||||
return merge([
|
||||
createMainBundle(defines).pipe(gulp.dest(dir + "build")),
|
||||
|
@ -1115,7 +1114,7 @@ gulp.task(
|
|||
);
|
||||
|
||||
function buildComponents(defines, dir) {
|
||||
rimraf.sync(dir);
|
||||
fs.rmSync(dir, { recursive: true, force: true });
|
||||
|
||||
const COMPONENTS_IMAGES = [
|
||||
"web/images/annotation-*.svg",
|
||||
|
@ -1201,7 +1200,7 @@ gulp.task(
|
|||
);
|
||||
|
||||
function buildMinified(defines, dir) {
|
||||
rimraf.sync(dir);
|
||||
fs.rmSync(dir, { recursive: true, force: true });
|
||||
|
||||
return merge([
|
||||
createMainBundle(defines).pipe(gulp.dest(dir + "build")),
|
||||
|
@ -1332,7 +1331,7 @@ gulp.task(
|
|||
};
|
||||
|
||||
// Clear out everything in the firefox extension build directory
|
||||
rimraf.sync(MOZCENTRAL_DIR);
|
||||
fs.rmSync(MOZCENTRAL_DIR, { recursive: true, force: true });
|
||||
|
||||
return merge([
|
||||
createMainBundle(defines).pipe(
|
||||
|
@ -1430,7 +1429,7 @@ gulp.task(
|
|||
];
|
||||
|
||||
// Clear out everything in the chrome extension build directory
|
||||
rimraf.sync(CHROME_BUILD_DIR);
|
||||
fs.rmSync(CHROME_BUILD_DIR, { recursive: true, force: true });
|
||||
|
||||
const version = getVersionJSON().version;
|
||||
|
||||
|
@ -1503,17 +1502,16 @@ gulp.task("jsdoc", function (done) {
|
|||
|
||||
const JSDOC_FILES = ["src/display/api.js"];
|
||||
|
||||
rimraf(JSDOC_BUILD_DIR, function () {
|
||||
fs.mkdirSync(JSDOC_BUILD_DIR, { recursive: true });
|
||||
fs.rmSync(JSDOC_BUILD_DIR, { recursive: true, force: true });
|
||||
fs.mkdirSync(JSDOC_BUILD_DIR, { recursive: true });
|
||||
|
||||
const command =
|
||||
'"node_modules/.bin/jsdoc" -d ' +
|
||||
JSDOC_BUILD_DIR +
|
||||
" " +
|
||||
JSDOC_FILES.join(" ");
|
||||
const command =
|
||||
'"node_modules/.bin/jsdoc" -d ' +
|
||||
JSDOC_BUILD_DIR +
|
||||
" " +
|
||||
JSDOC_FILES.join(" ");
|
||||
|
||||
exec(command, done);
|
||||
});
|
||||
exec(command, done);
|
||||
});
|
||||
|
||||
gulp.task("types", function (done) {
|
||||
|
@ -2013,7 +2011,7 @@ gulp.task(
|
|||
const defines = { ...DEFINES, GENERIC: true, TESTING: true };
|
||||
const sandboxDir = BUILD_DIR + "dev-sandbox/";
|
||||
|
||||
rimraf.sync(sandboxDir);
|
||||
fs.rmSync(sandboxDir, { recursive: true, force: true });
|
||||
|
||||
return createSandboxBundle(defines, {
|
||||
disableVersionInfo: true,
|
||||
|
@ -2059,7 +2057,8 @@ gulp.task("clean", function (done) {
|
|||
console.log();
|
||||
console.log("### Cleaning up project builds");
|
||||
|
||||
rimraf(BUILD_DIR, done);
|
||||
fs.rmSync(BUILD_DIR, { recursive: true, force: true });
|
||||
done();
|
||||
});
|
||||
|
||||
gulp.task("importl10n", async function () {
|
||||
|
@ -2078,7 +2077,7 @@ function ghPagesPrepare() {
|
|||
console.log();
|
||||
console.log("### Creating web site");
|
||||
|
||||
rimraf.sync(GH_PAGES_DIR);
|
||||
fs.rmSync(GH_PAGES_DIR, { recursive: true, force: true });
|
||||
|
||||
return merge([
|
||||
gulp
|
||||
|
@ -2192,13 +2191,20 @@ gulp.task(
|
|||
console.log();
|
||||
console.log("### Cloning baseline distribution");
|
||||
|
||||
rimraf.sync(DIST_DIR);
|
||||
fs.rmSync(DIST_DIR, { recursive: true, force: true });
|
||||
fs.mkdirSync(DIST_DIR, { recursive: true });
|
||||
safeSpawnSync("git", ["clone", "--depth", "1", DIST_REPO_URL, DIST_DIR]);
|
||||
|
||||
console.log();
|
||||
console.log("### Overwriting all files");
|
||||
rimraf.sync(path.join(DIST_DIR, "*"));
|
||||
|
||||
// Remove all files/folders, except for `.git` because it needs to be a
|
||||
// valid Git repository for the Git commands in the `dist` target to work.
|
||||
for (const entry of fs.readdirSync(DIST_DIR)) {
|
||||
if (entry !== ".git") {
|
||||
fs.rmSync(DIST_DIR + entry, { recursive: true, force: true });
|
||||
}
|
||||
}
|
||||
|
||||
return merge([
|
||||
packageJson().pipe(gulp.dest(DIST_DIR)),
|
||||
|
@ -2330,7 +2336,7 @@ gulp.task(
|
|||
console.log("### Creating mozcentral baseline environment");
|
||||
|
||||
// Create a mozcentral build.
|
||||
rimraf.sync(BASELINE_DIR + BUILD_DIR);
|
||||
fs.rmSync(BASELINE_DIR + BUILD_DIR, { recursive: true, force: true });
|
||||
|
||||
const workingDirectory = path.resolve(process.cwd(), BASELINE_DIR);
|
||||
safeSpawnSync("gulp", ["mozcentral"], {
|
||||
|
@ -2340,7 +2346,7 @@ gulp.task(
|
|||
});
|
||||
|
||||
// Copy the mozcentral build to the mozcentral baseline directory.
|
||||
rimraf.sync(MOZCENTRAL_BASELINE_DIR);
|
||||
fs.rmSync(MOZCENTRAL_BASELINE_DIR, { recursive: true, force: true });
|
||||
fs.mkdirSync(MOZCENTRAL_BASELINE_DIR, { recursive: true });
|
||||
|
||||
gulp
|
||||
|
@ -2369,10 +2375,16 @@ gulp.task(
|
|||
|
||||
// Create the diff between the current mozcentral build and the
|
||||
// baseline mozcentral build, which both exist at this point.
|
||||
// The mozcentral baseline directory is a Git repository, so we
|
||||
// remove all files and copy the current mozcentral build files
|
||||
// into it to create the diff.
|
||||
rimraf.sync(MOZCENTRAL_BASELINE_DIR + "*");
|
||||
// Remove all files/folders, except for `.git` because it needs to be a
|
||||
// valid Git repository for the Git commands below to work.
|
||||
for (const entry of fs.readdirSync(MOZCENTRAL_BASELINE_DIR)) {
|
||||
if (entry !== ".git") {
|
||||
fs.rmSync(MOZCENTRAL_BASELINE_DIR + entry, {
|
||||
recursive: true,
|
||||
force: true,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
gulp
|
||||
.src([BUILD_DIR + "mozcentral/**/*"])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue