1
0
Fork 0
mirror of https://gitlab.alpinelinux.org/alpine/aports.git synced 2025-07-13 11:19:50 +03:00
aports/community/zigbee2mqtt/dont-build-on-start.patch
2025-05-04 21:57:00 +00:00

114 lines
3.2 KiB
Diff

--- a/index.js
+++ b/index.js
@@ -1,9 +1,6 @@
const semver = require("semver");
const engines = require("./package.json").engines;
-const fs = require("node:fs");
-const os = require("node:os");
const path = require("node:path");
-const {exec} = require("node:child_process");
require("source-map-support").install();
let controller;
@@ -23,8 +20,6 @@
}
}
-const hashFile = path.join(__dirname, "dist", ".hash");
-
async function triggerWatchdog(code) {
const delay = watchdogDelays[watchdogCount];
watchdogCount += 1;
@@ -56,73 +51,8 @@
}
}
-async function currentHash() {
- return await new Promise((resolve) => {
- exec("git rev-parse --short=8 HEAD", (error, stdout) => {
- const commitHash = stdout.trim();
-
- if (error || commitHash === "") {
- resolve("unknown");
- } else {
- resolve(commitHash);
- }
- });
- });
-}
-
-async function writeHash() {
- const hash = await currentHash();
-
- fs.writeFileSync(hashFile, hash);
-}
-
-async function build(reason) {
- process.stdout.write(`Building Zigbee2MQTT... (${reason})`);
-
- return await new Promise((resolve, reject) => {
- const env = {...process.env};
- const mb600 = 629145600;
-
- if (mb600 > os.totalmem() && !env.NODE_OPTIONS) {
- // Prevent OOM on tsc compile for system with low memory
- // https://github.com/Koenkk/zigbee2mqtt/issues/12034
- env.NODE_OPTIONS = "--max_old_space_size=256";
- }
-
- // clean build, prevent failures due to tsc incremental building
- exec("pnpm run prepack", {env, cwd: __dirname}, (err) => {
- if (err) {
- process.stdout.write(", failed\n");
-
- if (err.code === 134) {
- process.stderr.write("\n\nBuild failed; ran out-of-memory, free some memory (RAM) and start again\n\n");
- }
-
- reject(err);
- } else {
- process.stdout.write(", finished\n");
- resolve();
- }
- });
- });
-}
-
-async function checkDist() {
- if (!fs.existsSync(hashFile)) {
- await build("initial build");
- }
-
- const distHash = fs.readFileSync(hashFile, "utf8");
- const hash = await currentHash();
-
- if (hash !== "unknown" && distHash !== hash) {
- await build("hash changed");
- }
-}
-
async function start() {
console.log(`Starting Zigbee2MQTT ${watchdog ? `with watchdog (${watchdogDelays})` : "without watchdog"}.`);
- await checkDist();
// gc
{
@@ -174,7 +104,8 @@
if (require.main === module || require.main.filename.endsWith(`${path.sep}cli.js`)) {
if (process.argv.length === 3 && process.argv[2] === "writehash") {
- writeHash();
+ console.log("writehash is ignored");
+ process.exit(0);
} else {
process.on("SIGINT", handleQuit);
process.on("SIGTERM", handleQuit);
--- a/package.json
+++ b/package.json
@@ -23,5 +23,5 @@
],
"scripts": {
- "build": "tsc && node index.js writehash",
+ "build": "tsc",
"build:watch": "tsc --watch",
"check": "biome check",