🐛 fix(desktop): 修复 Lark SDK 导致 sidecar bundle 可重定位性自检失败 (dev 无法启动) - #40
Conversation
PR#34 引入 @larksuiteoapi/node-sdk,其 getSdkVersion() 的 __dirname 被 bun 固化为构建机绝对路径,触发 build-sidecar-bundle.mjs 可重定位性自检,导致 bun run dev 启动失败(exit 1: main still contains the build workspace path)。照 sql.js 既有范式新增 larkSdkDirnamePattern,将该 __dirname 替换为相对路径。getSdkVersion() 解析失败走 SDK 自带 try/catch 返回 unknown,仅影响 User-Agent 版本号,无功能影响。 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9ea54b916f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| } | ||
| bundleSrc = bundleSrc.replace( | ||
| larkSdkDirnamePattern, | ||
| ' var __dirname = ".";', |
There was a problem hiding this comment.
Avoid resolving Lark's version from css-tree metadata
When the desktop launches the sidecar, createUtilityProcessSidecarForkConfig sets its cwd to the bundle directory (apps/desktop/src/sidecar-process.ts:171), so replacing the SDK's lib directory with "." makes its ../package.json lookup target resources/package.json. The build explicitly places css-tree's manifest there (scripts/build-sidecar-bundle.mjs:223), meaning the lookup succeeds with css-tree's 3.2.1 version instead of taking the claimed unknown fallback; Feishu requests consequently advertise an incorrect SDK version. Use a guaranteed-missing path to preserve the fallback or inline the actual Lark SDK version.
Useful? React with 👍 / 👎.
问题
bun run dev启动失败:根因
PR#34(飞书/钉钉/企微 IM 集成)引入
@larksuiteoapi/node-sdk@1.72.0。该 CJS SDK 的getSdkVersion()用__dirname读自身package.json取版本号拼 User-Agent,bun 打包时把__dirname固化为构建机绝对路径(index.mjs唯一路径残留),触发build-sidecar-bundle.mjs的可重定位性自检 →exit(1)→ dev 起不来。现有
makeRelocatable正则只覆盖 jsdom / undici / sql.js / transformers,漏了 Lark SDK。修复
照
sql.js既有范式新增larkSdkDirnamePattern,将该__dirname绝对路径替换为".":getSdkVersion()解析失败走 SDK 自带try/catch兜底返回'unknown',仅影响 User-Agent 版本号,无功能影响;package.json本就不会随包发布,原绝对路径在新机器上同样解析不到。+ const larkSdkDirnamePattern = /^ var __dirname = ".*node_modules.*larksuiteoapi.*node-sdk.*lib";\r?\n/m;验证
在基于
origin/main的 fresh worktree 端到端验证:exit 1,main still contains the build workspace path✗exit 0,可重定位性自检通过 + 全流程(jsdom 样式表 / XHR worker / 原生包复制)完成 ✓🤖 Generated with Claude Code