Skip to content

fix(bds-tools): isMainModule 破坏 recovery.js shim(LSP 回归) - #43

Merged
Tanya7z merged 1 commit into
mainfrom
cursor/bc-93e0f3a7-4599-4b0b-80a6-20b00d6bce33-2f80
Jul 23, 2026
Merged

fix(bds-tools): isMainModule 破坏 recovery.js shim(LSP 回归)#43
Tanya7z merged 1 commit into
mainfrom
cursor/bc-93e0f3a7-4599-4b0b-80a6-20b00d6bce33-2f80

Conversation

@cursor

@cursor cursor Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

背景

main@8bb9337 将 require.main === module / endsWith(...) 收敛为 isMainModule(import.meta.url) 严格路径相等。

审查结论(DRY / OCP / DIP / LSP / Demeter)

BLOCKER — LSP

node recovery.js(根目录 shim → dist/recovery.js)时 process.argv[1]import.meta.url 路径不同,isMain() 恒为 false,CLI 不再执行。历史 endsWith("recovery.js") 契约被破坏。

BLOCKER — ESM 加载

recovery.js 仍用 createRequire 加载 ESM dist/,在 "type":"module" 下不可靠;改为动态 import()

MAJOR — LSP 对称性

check-updateSFMC_SERVICE==="update" 兜底,bds-manager 缺失;补齐 manager

正向(DRY)

抽取 is-main.ts 本身正确,保留并加固该唯一入口判定来源。

修复

  • isMainModule:realpath + 同 stem shim 兼容(对齐历史契约)
  • recovery.js:动态 import(dist)
  • bds-managerSFMC_SERVICE==="manager"
  • is-main.test.mjs:直接入口 / 同名 shim / 异名 import 三场景

验证

npm run build -w @sfmc-bds/bds-tools
npm test -w @sfmc-bds/bds-tools   # 3/3 pass
node bds-tools/recovery.js        # 正常跑 CLI(无标记时 WARN 退出 0)

CI

触发 push 的 ootb run 29975803843 已 success;本 PR 修的是 ootb 未覆盖的 rollback shim 路径。

Open in Web View Automation 

8bb9337 将入口判断改为 argv 与 import.meta.url 严格路径相等后,
`node recovery.js`(根目录 shim → dist/recovery.js)不再触发 CLI。
恢复同 stem shim 契约,realpath 抗符号链接,recovery shim 改动态 import,
并为 manager 补齐 SFMC_SERVICE 对称判定;附 node:test 覆盖。

Co-authored-by: Shiroha <Tanya7z@users.noreply.github.com>
@Tanya7z
Tanya7z marked this pull request as ready for review July 23, 2026 03:07
@cursor

cursor Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor Author

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

@Tanya7z
Tanya7z merged commit 1e3928a into main Jul 23, 2026
1 check passed
@Tanya7z
Tanya7z deleted the cursor/bc-93e0f3a7-4599-4b0b-80a6-20b00d6bce33-2f80 branch July 23, 2026 03:19
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