From f713313326805d8baebbee38241979be8ae0387d Mon Sep 17 00:00:00 2001 From: Gaizka <1058674225@qq.com> Date: Thu, 10 Sep 2026 08:44:26 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20Electron=20=E5=AE=BF=E4=B8=BB(DSH=20Desk?= =?UTF-8?q?top)=E8=B7=B3=E8=BF=87=20child=5Fprocess=20ESM=20=E9=87=8D?= =?UTF-8?q?=E5=AE=9A=E5=90=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/hide-console.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/hide-console.js b/lib/hide-console.js index 7684c77..873ea60 100644 --- a/lib/hide-console.js +++ b/lib/hide-console.js @@ -73,6 +73,12 @@ function facadeUrl() { /** Redirect ESM/CJS resolution of child_process to the windowsHide facade. */ export function installChildProcessImportHook() { if (process.platform !== "win32") return { ok: true, skipped: "not_win32" }; + // DSH Desktop runs on Electron. Electron’s overrideChildProcess patches + // child_process by assigning properties (e.g. exec) onto the module object, + // which throws on a frozen ESM namespace. Skip the redirect on Electron hosts. + if (typeof process.versions !== "undefined" && process.versions.electron) { + return { ok: true, skipped: "electron_host" }; + } if (globalThis[HOOK_MARK]) return { ok: true, already: true }; const target = facadeUrl(); registerHooks({ @@ -119,7 +125,6 @@ export function hideConsoleEntrySource() { // The facade lives beside this file as dsh-purge-child-process-hide.mjs // (copied by installHideConsoleIntoBin). return `// ${IMPORT_MARK} — auto-installed by dsh-purge; do not edit -import { registerHooks } from "node:module"; import { pathToFileURL } from "node:url"; import { fileURLToPath } from "node:url"; @@ -127,7 +132,13 @@ const HOOK_MARK = "__dshPurgeChildProcessHook"; const MARK = ${JSON.stringify(MARK)}; const facade = pathToFileURL(fileURLToPath(new URL("./dsh-purge-child-process-hide.mjs", import.meta.url))).href; -if (process.platform === "win32" && !globalThis[HOOK_MARK]) { +// DSH Desktop (Electron) must NOT redirect child_process to the ESM facade: +// Electron’s overrideChildProcess assigns e.g. exec onto the module object, +// and a frozen ESM namespace throws TypeError. Only the safe wrapping below runs. +const isElectron = typeof process.versions !== "undefined" && !!process.versions.electron; + +if (process.platform === "win32" && !isElectron && !globalThis[HOOK_MARK]) { + const { registerHooks } = await import("node:module"); registerHooks({ resolve(specifier, context, nextResolve) { if (specifier === "node:child_process" || specifier === "child_process") { @@ -139,7 +150,7 @@ if (process.platform === "win32" && !globalThis[HOOK_MARK]) { Object.defineProperty(globalThis, HOOK_MARK, { value: true, enumerable: false }); } -const cp = process.getBuiltinModule("child_process"); +const cp = process.getBuiltinModule ? process.getBuiltinModule("child_process") : null; if (process.platform === "win32" && cp && !cp[MARK]) { const hide = (options) => { if (options == null) return { windowsHide: true };