Skip to content

🐛 fix(desktop): 修复 Lark SDK 导致 sidecar bundle 可重定位性自检失败 (dev 无法启动) - #40

Merged
CavinHuang merged 1 commit into
mainfrom
worktree-fix-sidecar-lark-relocatable
Aug 10, 2026
Merged

🐛 fix(desktop): 修复 Lark SDK 导致 sidecar bundle 可重定位性自检失败 (dev 无法启动)#40
CavinHuang merged 1 commit into
mainfrom
worktree-fix-sidecar-lark-relocatable

Conversation

@CavinHuang

Copy link
Copy Markdown
Owner

问题

bun run dev 启动失败:

[sidecar-bundle] main still contains the build workspace path
Exited with code 1

根因

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 版本号,无功能影响;
  • bundle 里 SDK 的 package.json 本就不会随包发布,原绝对路径在新机器上同样解析不到。
+ const larkSdkDirnamePattern = /^  var __dirname = ".*node_modules.*larksuiteoapi.*node-sdk.*lib";\r?\n/m;
+ if (!larkSdkDirnamePattern.test(bundleSrc)) {
+   console.error("[sidecar-bundle] main: Lark SDK __dirname pattern not found");
+   process.exit(1);
+ }
+ bundleSrc = bundleSrc.replace(larkSdkDirnamePattern, '  var __dirname = ".";');

验证

在基于 origin/main 的 fresh worktree 端到端验证:

  • 修复前:构建 exit 1main still contains the build workspace path
  • 修复后:构建 exit 0,可重定位性自检通过 + 全流程(jsdom 样式表 / XHR worker / 原生包复制)完成 ✓

🤖 Generated with Claude Code

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>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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 = ".";',

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

@CavinHuang
CavinHuang merged commit 254424d into main Aug 10, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants