fix(darwin): boot the packaged Harness without Node's internal loader - #146
Merged
Conversation
Every signed macOS launch failed profile boot at the same step:
DSH entry failed: failed to apply loader entry (@deepseek-ai/cordis-plugin-hmr):
--expose-internals is required for HMR service
Harness creates the full Cordis HMR service after boot whenever no `hmr`
service exists, and that service throws on construction without
`ctx.loader.internal`, taking the rest of boot with it — user patch-layer
watching included. A packaged Electron app cannot provide those internals:
the flag reaches the utility process's execArgv without reaching Node's
option parser, and the `node-addon-require-builtin` path the loader tries
next is built for plain Node and reports `Unsupported/no-realm` under
Electron.
A minimal Electron repro over the four combinations puts the boundary at
packaging, not at the TCC disclaim this branch was suspected of:
| build | disclaim | internal loader |
| dev run | false | available |
| dev run | true | available |
| signed | false | MODULE_NOT_FOUND |
| signed | true | MODULE_NOT_FOUND |
So the macOS TCC isolation stays as it is. What profile boot actually asks
of HMR is a file watcher and a callback — `watchUserPatches` only calls
`registerConfig` — and that needs no internals. This adds a desktop-owned
service supplying exactly that subset, and only where the internals are out
of reach: a host that has them keeps the real service, module-level hot
replacement included, so development runs and the bundled-Node platforms are
unchanged.
Verified on a signed --dir build: two consecutive cold starts both reach
`DSH entry loaded` with the endpoint answering 200 and no HMR error in the
log, where the same build without this change failed both. Editing the
profile's patch file leaves Harness serving.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
签名打包的 macOS 正式版每次启动都在 profile boot 的同一步失败(0.4.3 用户日志 8/8):
对应内部文档《DSH Desktop v0.4.3 macOS 正式版启动失败:Utility Process 与 HMR 集成问题》的第二个问题(第一个是插件残留,与本 PR 无关)。
根因
runProfile在 boot 之后发现没有hmr服务时会自己创建一个完整的 Cordis HMR(日志里那个随机 id 就是它),而该服务在缺少ctx.loader.internal时构造即抛,把 boot 的后半段一起带走——包括用户 patch 层的监听。打包版拿不到这个 internal loader,两条路都断:
--expose-internals进得了 utility process 的execArgv,但进不了 Node 的选项解析器;node-addon-require-builtin是按 plain Node 构建的,在 Electron 下直接报Unsupported/no-realm。补上文档建议 1 要求的最小复现(直接验证 internal loader 对象,而非只看
process.execArgv),四组组合结果如下:disclaimfalsetruefalseMODULE_NOT_FOUNDtrueMODULE_NOT_FOUND分水岭是打包,不是
disclaim。 这修正了文档"最可能的解释",也意味着 #107 的 macOS TCC 责任隔离不需要动。另外确认:在 profile 层把
hmr行disabled: true关掉没有用——那只会让runProfile换个 id 再创建一个,照样抛错。修复
watchUserPatches对 HMR 的全部要求就是registerConfig(filename, refresh)——一个文件监听加一个回调,不需要 internals。本 PR 新增一个桌面端自有的hmr服务,只提供这个子集,且仅在 internals 不可达时生效:变更点:
packages/dsh-desktop-hmr-fallback/(新包)、build/dsh-desktop.patch.yml(插入该行)、package.json(file: 依赖)。验证
在签名的
--dir构建上验证(文档建议 4 要求的正式打包态,非 dev build):DSH entry loaded,grep -c 'expose-internals'为 0;同一构建去掉本改动则两次都失败;cordis.patch.yml后 Harness 继续正常服务,监听未打挂;npm run typecheck通过;npm test36 文件 245 测试全绿(新增 4 条)。与 #145 的关系
不重叠。#145 修的是
buildPnpmEnvironment删掉ELECTRON_RUN_AS_NODE导致市场安装报 "pnpm completed, but dshmarket was not found"(issue #140);本 PR 修的是 Harness 启动本身。两者都只在 macOS 上出现,但根因和代码路径都不同。遗留