From a5faa4b2255693d5db6709bf577fde1029cd33b0 Mon Sep 17 00:00:00 2001 From: Tanmay Shinde <62463484+tanmay4u02@users.noreply.github.com> Date: Sat, 5 Oct 2024 19:57:17 +0530 Subject: [PATCH] refactor: removed fs-rmsync extra func used for node <14 (#5159) --- extra/download-dist.js | 11 ++++++----- extra/fs-rmSync.js | 23 ----------------------- extra/update-language-files/index.js | 11 ++++++++--- package.json | 3 +-- test/prepare-test-server.js | 4 ++-- 5 files changed, 17 insertions(+), 35 deletions(-) delete mode 100644 extra/fs-rmSync.js diff --git a/extra/download-dist.js b/extra/download-dist.js index b8be5eb8a..b339ac930 100644 --- a/extra/download-dist.js +++ b/extra/download-dist.js @@ -4,7 +4,6 @@ const tar = require("tar"); const packageJSON = require("../package.json"); const fs = require("fs"); -const rmSync = require("./fs-rmSync.js"); const version = packageJSON.version; const filename = "dist.tar.gz"; @@ -29,8 +28,9 @@ function download(url) { if (fs.existsSync("./dist")) { if (fs.existsSync("./dist-backup")) { - rmSync("./dist-backup", { - recursive: true + fs.rmSync("./dist-backup", { + recursive: true, + force: true, }); } @@ -43,8 +43,9 @@ function download(url) { tarStream.on("close", () => { if (fs.existsSync("./dist-backup")) { - rmSync("./dist-backup", { - recursive: true + fs.rmSync("./dist-backup", { + recursive: true, + force: true, }); } console.log("Done"); diff --git a/extra/fs-rmSync.js b/extra/fs-rmSync.js deleted file mode 100644 index a42e30a68..000000000 --- a/extra/fs-rmSync.js +++ /dev/null @@ -1,23 +0,0 @@ -const fs = require("fs"); -/** - * Detect if `fs.rmSync` is available - * to avoid the runtime deprecation warning triggered for using `fs.rmdirSync` with `{ recursive: true }` in Node.js v16, - * or the `recursive` property removing completely in the future Node.js version. - * See the link below. - * @todo Once we drop the support for Node.js v14 (or at least versions before v14.14.0), we can safely replace this function with `fs.rmSync`, since `fs.rmSync` was add in Node.js v14.14.0 and currently we supports all the Node.js v14 versions that include the versions before the v14.14.0, and this function have almost the same signature with `fs.rmSync`. - * @link https://nodejs.org/docs/latest-v16.x/api/deprecations.html#dep0147-fsrmdirpath--recursive-true- the deprecation information of `fs.rmdirSync` - * @link https://nodejs.org/docs/latest-v16.x/api/fs.html#fsrmsyncpath-options the document of `fs.rmSync` - * @param {fs.PathLike} path Valid types for path values in "fs". - * @param {fs.RmDirOptions} options options for `fs.rmdirSync`, if `fs.rmSync` is available and property `recursive` is true, it will automatically have property `force` with value `true`. - * @returns {void} - */ -const rmSync = (path, options) => { - if (typeof fs.rmSync === "function") { - if (options.recursive) { - options.force = true; - } - return fs.rmSync(path, options); - } - return fs.rmdirSync(path, options); -}; -module.exports = rmSync; diff --git a/extra/update-language-files/index.js b/extra/update-language-files/index.js index 5b748a98e..acb6bd467 100644 --- a/extra/update-language-files/index.js +++ b/extra/update-language-files/index.js @@ -2,7 +2,6 @@ import fs from "fs"; import util from "util"; -import rmSync from "../fs-rmSync.js"; /** * Copy across the required language files @@ -16,7 +15,10 @@ import rmSync from "../fs-rmSync.js"; */ function copyFiles(langCode, baseLang) { if (fs.existsSync("./languages")) { - rmSync("./languages", { recursive: true }); + fs.rmSync("./languages", { + recursive: true, + force: true, + }); } fs.mkdirSync("./languages"); @@ -93,6 +95,9 @@ console.log("Updating: " + langCode); copyFiles(langCode, baseLangCode); await updateLanguage(langCode, baseLangCode); -rmSync("./languages", { recursive: true }); +fs.rmSync("./languages", { + recursive: true, + force: true, +}); console.log("Done. Fixing formatting by ESLint..."); diff --git a/package.json b/package.json index cf6348cbd..0d51984c7 100644 --- a/package.json +++ b/package.json @@ -68,8 +68,7 @@ "sort-contributors": "node extra/sort-contributors.js", "quick-run-nightly": "docker run --rm --env NODE_ENV=development -p 3001:3001 louislam/uptime-kuma:nightly2", "start-dev-container": "cd docker && docker-compose -f docker-compose-dev.yml up --force-recreate", - "rebase-pr-to-1.23.X": "node extra/rebase-pr.js 1.23.X", - "start-server-node14-win": "private\\node14\\node.exe server/server.js" + "rebase-pr-to-1.23.X": "node extra/rebase-pr.js 1.23.X" }, "dependencies": { "@grpc/grpc-js": "~1.8.22", diff --git a/test/prepare-test-server.js b/test/prepare-test-server.js index 1a9b04df1..1e0ed5cc4 100644 --- a/test/prepare-test-server.js +++ b/test/prepare-test-server.js @@ -1,10 +1,10 @@ const fs = require("fs"); -const rmSync = require("../extra/fs-rmSync.js"); const path = "./data/test"; if (fs.existsSync(path)) { - rmSync(path, { + fs.rmSync(path, { recursive: true, + force: true, }); }