From be1ca74e9e283f65865921fe29069404c8dde9a7 Mon Sep 17 00:00:00 2001 From: odilitime Date: Sun, 5 Jan 2025 17:43:57 +0000 Subject: [PATCH] support more debians distros --- packages/plugin-node/scripts/postinstall.js | 64 ++++++++++++++++++--- 1 file changed, 55 insertions(+), 9 deletions(-) diff --git a/packages/plugin-node/scripts/postinstall.js b/packages/plugin-node/scripts/postinstall.js index 9c3ccc3686..6a30ca9443 100644 --- a/packages/plugin-node/scripts/postinstall.js +++ b/packages/plugin-node/scripts/postinstall.js @@ -1,18 +1,64 @@ import os from "os"; +import fs from "fs"; +import { execSync } from "child_process"; + const platform = os.platform(); +const rel = os.release(); + +if (platform !== "linux") { + console.log("Skipping playwright installation: non-Linux platform detected:", platform); + process.exit(0); +} + +function getDistroName() { + try { + const osReleaseContent = fs.readFileSync("/etc/os-release", "utf8"); + const lines = osReleaseContent.split("\n"); + const info = {}; + for (const line of lines) { + const [key, value] = line.split("="); + if (key && value) { + info[key.toLowerCase()] = value.replace(/"/g, "").toLowerCase().trim(); + } + } + return info["id"] || info["id_like"] || null; + } catch (err) { + console.error("Error reading /etc/os-release:", err.message); + } + return null; +} -if ( - platform === "linux" && - !(os.release().includes("ubuntu") || os.release().includes("debian")) -) { - // DO NOT CHANGE THIS TO ELIZALOGGER, this file cannot depends on any workspace otherwise we can't build the workspace +const distro = getDistroName(); +console.log("Detected Linux distribution:", distro || "unknown"); + +const supportedDistros = [ + "ubuntu", + "debian", + "pve", + "raspbian", + "pop", + "zorin", + "linuxmint", + "elementary", + "pureos", + "kali" +]; + +if (!distro || !supportedDistros.some((name) => distro.includes(name))) { console.log( "Skipping playwright installation on unsupported platform:", - platform + platform, + rel, + distro || "unknown distro" ); -} else { - const { execSync } = await import("child_process"); + process.exit(0); +} + +try { execSync("npx playwright install-deps && npx playwright install", { - stdio: "inherit", + stdio: "inherit" }); +} catch (err) { + console.error("Failed to install Playwright dependencies:", err.message); + process.exit(1); }