mirror of
https://github.com/Quad4-Software/MeshChatX.git
synced 2026-08-18 09:49:09 -04:00
feat(electron): update post-install script to include patching for electron-builder file system constants
This commit is contained in:
parent
251df141b8
commit
bd0eef6ac9
3 changed files with 51 additions and 2 deletions
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
|
|
@ -116,7 +116,7 @@ jobs:
|
|||
pnpm exec vitest run --config vitest.electron.config.js
|
||||
;;
|
||||
backend-tests)
|
||||
uv run python -m pytest tests/backend -n auto \
|
||||
MESHCHAT_SKIP_STORAGE_LOCK=1 uv run python -m pytest tests/backend -n auto \
|
||||
--cov=meshchatx/src/backend
|
||||
;;
|
||||
lang-tests)
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@
|
|||
"test:e2e": "playwright test",
|
||||
"test:e2e:ui": "playwright test --ui",
|
||||
"test:e2e:install": "playwright install chromium",
|
||||
"electron-postinstall": "electron-builder install-app-deps && node scripts/ensure-micron-parser-package.js",
|
||||
"electron-postinstall": "electron-builder install-app-deps && node scripts/ensure-micron-parser-package.js && node scripts/patch-electron-builder-fs.cjs",
|
||||
"electron": "pnpm run electron-postinstall && pnpm run build && electron .",
|
||||
"dist": "pnpm run electron-postinstall && pnpm run build && electron-builder --publish=never",
|
||||
"dist:linux": "pnpm run electron-postinstall && cross-env PLATFORM=linux pnpm run build && electron-builder --linux AppImage deb --publish=never",
|
||||
|
|
|
|||
49
scripts/patch-electron-builder-fs.cjs
Normal file
49
scripts/patch-electron-builder-fs.cjs
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
const fs = require("node:fs");
|
||||
const path = require("node:path");
|
||||
|
||||
const root = path.join(__dirname, "..");
|
||||
const targets = [path.join(root, "node_modules", "app-builder-lib", "out", "binDownload.js")];
|
||||
|
||||
const preamble = `const __ebFsConstants = (() => {
|
||||
try {
|
||||
const c = require("fs").constants;
|
||||
if (c && c.R_OK != null) {
|
||||
return c;
|
||||
}
|
||||
} catch (_) {}
|
||||
try {
|
||||
const c = require("node:fs").constants;
|
||||
if (c && c.R_OK != null) {
|
||||
return c;
|
||||
}
|
||||
} catch (_) {}
|
||||
return { R_OK: 4, W_OK: 2, X_OK: 1 };
|
||||
})();
|
||||
|
||||
`;
|
||||
|
||||
function patchBinDownload(source) {
|
||||
if (source.includes("__ebFsConstants")) {
|
||||
return source;
|
||||
}
|
||||
let next = preamble + source;
|
||||
next = next.replace(/fs_1\.constants\.R_OK/g, "__ebFsConstants.R_OK");
|
||||
next = next.replace(/fs_1\.constants\.W_OK/g, "__ebFsConstants.W_OK");
|
||||
next = next.replace(/fs\.constants\.R_OK/g, "__ebFsConstants.R_OK");
|
||||
next = next.replace(/fs\.constants\.W_OK/g, "__ebFsConstants.W_OK");
|
||||
return next;
|
||||
}
|
||||
|
||||
for (const target of targets) {
|
||||
if (!fs.existsSync(target)) {
|
||||
continue;
|
||||
}
|
||||
const original = fs.readFileSync(target, "utf8");
|
||||
const patched = patchBinDownload(original);
|
||||
if (patched !== original) {
|
||||
fs.writeFileSync(target, patched);
|
||||
console.log(`patched ${path.relative(root, target)}`);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue