Skip to content

Commit

Permalink
Merge pull request #1875 from odilitime/fix-postinstall-script
Browse files Browse the repository at this point in the history
chore: support more debians distros
  • Loading branch information
shakkernerd authored Jan 5, 2025
2 parents 2724555 + 9689bc2 commit 09517c5
Showing 1 changed file with 55 additions and 9 deletions.
64 changes: 55 additions & 9 deletions packages/plugin-node/scripts/postinstall.js
Original file line number Diff line number Diff line change
@@ -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);
}

0 comments on commit 09517c5

Please sign in to comment.