mirror of https://github.com/louislam/uptime-kuma
				
				
				
			Merge pull request #1348 from AnnAngela/master
Detect if `fs.rmSync` is available to avoid the runtime deprecation warningpull/1452/head
						commit
						87d3853b8e
					
				| 
						 | 
				
			
			@ -4,6 +4,7 @@ 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";
 | 
			
		||||
| 
						 | 
				
			
			@ -21,7 +22,7 @@ function download(url) {
 | 
			
		|||
            if (fs.existsSync("./dist")) {
 | 
			
		||||
 | 
			
		||||
                if (fs.existsSync("./dist-backup")) {
 | 
			
		||||
                    fs.rmdirSync("./dist-backup", {
 | 
			
		||||
                    rmSync("./dist-backup", {
 | 
			
		||||
                        recursive: true
 | 
			
		||||
                    });
 | 
			
		||||
                }
 | 
			
		||||
| 
						 | 
				
			
			@ -35,7 +36,7 @@ function download(url) {
 | 
			
		|||
 | 
			
		||||
            tarStream.on("close", () => {
 | 
			
		||||
                if (fs.existsSync("./dist-backup")) {
 | 
			
		||||
                    fs.rmdirSync("./dist-backup", {
 | 
			
		||||
                    rmSync("./dist-backup", {
 | 
			
		||||
                        recursive: true
 | 
			
		||||
                    });
 | 
			
		||||
                }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -0,0 +1,20 @@
 | 
			
		|||
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.
 | 
			
		||||
 * @link https://nodejs.org/docs/latest-v16.x/api/deprecations.html#dep0147-fsrmdirpath--recursive-true-
 | 
			
		||||
 * @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`.
 | 
			
		||||
 */
 | 
			
		||||
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;
 | 
			
		||||
| 
						 | 
				
			
			@ -3,6 +3,7 @@
 | 
			
		|||
import fs from "fs";
 | 
			
		||||
import path from "path";
 | 
			
		||||
import util from "util";
 | 
			
		||||
import rmSync from "../fs-rmSync.js";
 | 
			
		||||
 | 
			
		||||
// https://stackoverflow.com/questions/13786160/copy-folder-recursively-in-node-js
 | 
			
		||||
/**
 | 
			
		||||
| 
						 | 
				
			
			@ -30,7 +31,7 @@ console.log("Arguments:", process.argv);
 | 
			
		|||
const baseLangCode = process.argv[2] || "en";
 | 
			
		||||
console.log("Base Lang: " + baseLangCode);
 | 
			
		||||
if (fs.existsSync("./languages")) {
 | 
			
		||||
    fs.rmdirSync("./languages", { recursive: true });
 | 
			
		||||
    rmSync("./languages", { recursive: true });
 | 
			
		||||
}
 | 
			
		||||
copyRecursiveSync("../../src/languages", "./languages");
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -40,7 +41,7 @@ const files = fs.readdirSync("./languages");
 | 
			
		|||
console.log("Files:", files);
 | 
			
		||||
 | 
			
		||||
for (const file of files) {
 | 
			
		||||
    if (!file.endsWith(".js")) {
 | 
			
		||||
    if (! file.endsWith(".js")) {
 | 
			
		||||
        console.log("Skipping " + file);
 | 
			
		||||
        continue;
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -82,5 +83,5 @@ for (const file of files) {
 | 
			
		|||
    fs.writeFileSync(`../../src/languages/${file}`, code);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
fs.rmdirSync("./languages", { recursive: true });
 | 
			
		||||
rmSync("./languages", { recursive: true });
 | 
			
		||||
console.log("Done. Fixing formatting by ESLint...");
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,5 +1,6 @@
 | 
			
		|||
const pkg = require("../package.json");
 | 
			
		||||
const fs = require("fs");
 | 
			
		||||
const rmSync = require("./fs-rmSync.js");
 | 
			
		||||
const child_process = require("child_process");
 | 
			
		||||
const util = require("../src/util");
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -58,4 +59,3 @@ function tagExists(version) {
 | 
			
		|||
 | 
			
		||||
    return res.stdout.toString().trim() === version;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,9 +1,10 @@
 | 
			
		|||
const fs = require("fs");
 | 
			
		||||
const rmSync = require("../extra/fs-rmSync.js");
 | 
			
		||||
 | 
			
		||||
const path = "./data/test-chrome-profile";
 | 
			
		||||
 | 
			
		||||
if (fs.existsSync(path)) {
 | 
			
		||||
    fs.rmdirSync(path, {
 | 
			
		||||
    rmSync(path, {
 | 
			
		||||
        recursive: true,
 | 
			
		||||
    });
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,9 +1,10 @@
 | 
			
		|||
const fs = require("fs");
 | 
			
		||||
const rmSync = require("../extra/fs-rmSync.js");
 | 
			
		||||
 | 
			
		||||
const path = "./data/test";
 | 
			
		||||
 | 
			
		||||
if (fs.existsSync(path)) {
 | 
			
		||||
    fs.rmdirSync(path, {
 | 
			
		||||
    rmSync(path, {
 | 
			
		||||
        recursive: true,
 | 
			
		||||
    });
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue