mirror of
https://github.com/Quad4-Software/MeshChatX.git
synced 2026-08-18 09:49:09 -04:00
feat(electron): add patch script for electron-installer-common to improve glob handling
This commit is contained in:
parent
3dc7db5ffb
commit
0df55bd698
2 changed files with 68 additions and 1 deletions
|
|
@ -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 && node scripts/patch-electron-builder-fs.cjs",
|
||||
"electron-postinstall": "electron-builder install-app-deps && node scripts/ensure-micron-parser-package.js && node scripts/patch-electron-builder-fs.cjs && node scripts/patch-electron-installer-common.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",
|
||||
|
|
|
|||
67
scripts/patch-electron-installer-common.cjs
Normal file
67
scripts/patch-electron-installer-common.cjs
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
const fs = require("node:fs");
|
||||
const path = require("node:path");
|
||||
|
||||
const root = path.join(__dirname, "..");
|
||||
const nodeModules = path.join(root, "node_modules");
|
||||
|
||||
const needle = "const glob = promisify(require('glob'))";
|
||||
const globShim = `const __ebGlobModule = require('glob')
|
||||
const glob = typeof __ebGlobModule === 'function'
|
||||
? promisify(__ebGlobModule)
|
||||
: __ebGlobModule.glob.bind(__ebGlobModule)`;
|
||||
|
||||
function patchGlobPromisify(source) {
|
||||
if (!source.includes(needle) || source.includes("__ebGlobModule")) {
|
||||
return source;
|
||||
}
|
||||
return source.replace(needle, globShim);
|
||||
}
|
||||
|
||||
function walkJsFiles(dir, out = []) {
|
||||
if (!fs.existsSync(dir)) {
|
||||
return out;
|
||||
}
|
||||
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
||||
const full = path.join(dir, entry.name);
|
||||
if (entry.isDirectory()) {
|
||||
if (entry.name === ".git") {
|
||||
continue;
|
||||
}
|
||||
walkJsFiles(full, out);
|
||||
continue;
|
||||
}
|
||||
if (entry.isFile() && entry.name.endsWith(".js")) {
|
||||
out.push(full);
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
const targetRoots = [
|
||||
path.join(nodeModules, "electron-installer-common"),
|
||||
path.join(nodeModules, "@electron", "asar"),
|
||||
path.join(nodeModules, "asar"),
|
||||
];
|
||||
|
||||
let patched = 0;
|
||||
for (const targetRoot of targetRoots) {
|
||||
for (const file of walkJsFiles(targetRoot)) {
|
||||
const original = fs.readFileSync(file, "utf8");
|
||||
if (!original.includes(needle)) {
|
||||
continue;
|
||||
}
|
||||
const next = patchGlobPromisify(original);
|
||||
if (next === original) {
|
||||
continue;
|
||||
}
|
||||
fs.writeFileSync(file, next);
|
||||
patched += 1;
|
||||
console.log(`patched ${path.relative(root, file)}`);
|
||||
}
|
||||
}
|
||||
|
||||
if (patched === 0) {
|
||||
console.log("electron-installer glob shim already applied or not needed");
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue