mirror of
https://github.com/YuJunZhiXue/dsh-purge.git
synced 2026-11-28 07:30:22 +08:00
fix: 发布 1.1.22,官方桌面 app.asar 还在时应用不再 ENOENT
归档还在时改写真实 resources/app;没有归档时仍用 node:fs。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
4538da436d
commit
58c950ae65
10 files changed
+153
-50
No files matched your search
+11
-10
@@ -3,6 +3,7 @@ import { pathToFileURL } from "node:url";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import path from "node:path";
|
||||
import { isAsarSealedPath } from "./desktop.js";
|
||||
import { diskFs, fsFor } from "./extract-asar.js";
|
||||
|
||||
const MARK = "__dshPurgeHideConsole";
|
||||
const IMPORT_MARK = "dsh-purge-hide-console";
|
||||
@@ -167,15 +168,15 @@ if (process.platform === "win32" && cp && !cp[MARK]) {
|
||||
`;
|
||||
}
|
||||
|
||||
function requireFs() {
|
||||
return createRequire(import.meta.url)("node:fs");
|
||||
}
|
||||
function requirePath() {
|
||||
return createRequire(import.meta.url)("node:path");
|
||||
}
|
||||
|
||||
function ioFor(explicit, targetPath) {
|
||||
return explicit ?? fsFor(targetPath);
|
||||
}
|
||||
|
||||
export function resolveDshBinRoot(hint, { fs, path: nodePath } = {}) {
|
||||
const nodeFs = fs ?? requireFs();
|
||||
const p = nodePath ?? requirePath();
|
||||
const tries = [];
|
||||
const push = (x) => {
|
||||
@@ -199,7 +200,7 @@ export function resolveDshBinRoot(hint, { fs, path: nodePath } = {}) {
|
||||
try {
|
||||
const binJs = p.join(root, "lib", "bin.js");
|
||||
if (isAsarSealedPath(root) || isAsarSealedPath(binJs)) continue;
|
||||
if (nodeFs.existsSync(binJs)) return p.normalize(root);
|
||||
if (ioFor(fs, binJs).existsSync(binJs)) return p.normalize(root);
|
||||
} catch {}
|
||||
}
|
||||
return null;
|
||||
@@ -209,16 +210,16 @@ const IMPORT_LINE = `import "./${IMPORT_MARK}.js"; // [dsh-purge] hide-console`;
|
||||
|
||||
export function installHideConsoleIntoBin(aiBase, { fs, path: nodePath } = {}) {
|
||||
if (process.platform !== "win32") return "skipped_not_win32";
|
||||
const nodeFs = fs ?? requireFs();
|
||||
const p = nodePath ?? requirePath();
|
||||
const root = resolveDshBinRoot(aiBase, { fs: nodeFs, path: p });
|
||||
const root = resolveDshBinRoot(aiBase, { fs, path: p });
|
||||
if (!root) return "missing_bin";
|
||||
const nodeFs = ioFor(fs, root);
|
||||
const binJs = p.join(root, "lib", "bin.js");
|
||||
const side = p.join(root, "lib", `${IMPORT_MARK}.js`);
|
||||
const facadeSide = p.join(root, "lib", "dsh-purge-child-process-hide.mjs");
|
||||
if (isAsarSealedPath(root) || isAsarSealedPath(binJs)) return "sealed_asar";
|
||||
|
||||
const facadeSrc = nodeFs.readFileSync(
|
||||
const facadeSrc = diskFs().readFileSync(
|
||||
fileURLToPath(new URL("./child-process-hide.mjs", import.meta.url)),
|
||||
"utf8",
|
||||
);
|
||||
@@ -244,10 +245,10 @@ export function installHideConsoleIntoBin(aiBase, { fs, path: nodePath } = {}) {
|
||||
}
|
||||
|
||||
export function revertHideConsoleFromBin(aiBase, { fs, path: nodePath } = {}) {
|
||||
const nodeFs = fs ?? requireFs();
|
||||
const p = nodePath ?? requirePath();
|
||||
const root = resolveDshBinRoot(aiBase, { fs: nodeFs, path: p });
|
||||
const root = resolveDshBinRoot(aiBase, { fs, path: p });
|
||||
if (!root) return "missing_bin";
|
||||
const nodeFs = ioFor(fs, root);
|
||||
const binJs = p.join(root, "lib", "bin.js");
|
||||
const side = p.join(root, "lib", `${IMPORT_MARK}.js`);
|
||||
const facadeSide = p.join(root, "lib", "dsh-purge-child-process-hide.mjs");
|
||||
|
||||
Reference in new issue
Block a user