Skip to content

fix(galacean): remove browser field from package.json#3058

Merged
GuoLei1990 merged 3 commits into
galacean:dev/2.0from
luo2430:fix/galacean
Jul 24, 2026
Merged

fix(galacean): remove browser field from package.json#3058
GuoLei1990 merged 3 commits into
galacean:dev/2.0from
luo2430:fix/galacean

Conversation

@luo2430

@luo2430 luo2430 commented Jul 1, 2026

Copy link
Copy Markdown
  • The commit message follows our guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

主要用于适配在一个utils包中包装部分功能并且 export * from "@galacean/engine"; 以方便其它库使用的情况。

Summary by CodeRabbit

  • New Features

    • Improved package entry-point mappings for module, type, and CDN-based browser usage.
    • CDN references now use minified browser builds where available.
  • Bug Fixes

    • Corrected browser package resolution by removing ambiguous browser metadata.
  • Tests

    • Added automated validation to verify package entry points and browser bundling compatibility during builds.

@coderabbitai

coderabbitai Bot commented Jul 1, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

Package manifests now use conditional exports or explicit CDN mappings instead of selected top-level browser fields. A new Rollup-based checker validates browser targets and module resolution across workspace packages, and build scripts run it before type generation.

Changes

Package Entry Contract Updates

Layer / File(s) Summary
Package manifest entry updates
packages/galacean/package.json, packages/math/package.json, packages/physics-physx/package.json, packages/shader-compiler/..., packages/shader/package.json, packages/ui/package.json, packages/xr...
Replaces browser fields with unpkg and jsdelivr mappings where applicable, and adds conditional exports["."] entries for the galacean package.
Entry contract checker
scripts/check-package-entry-contracts.js
Discovers package manifests, rejects UMD browser targets, and verifies module resolution through temporary Rollup bundles.
Build validation wiring
package.json
Adds check:package-entries and invokes it in build and b:all before type generation.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Suggested reviewers: guolei1990, luzhuang

Poem

A rabbit checks each package door,
Finds browser paths that work as before,
Rollup hops through imports bright,
While builds validate entries right. 🐇📦

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title matches a real and important part of the change: removing the browser field from the Galacean package manifest.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Jul 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.99%. Comparing base (721b42a) to head (5130903).
⚠️ Report is 9 commits behind head on dev/2.0.

Additional details and impacted files
@@             Coverage Diff             @@
##           dev/2.0    #3058      +/-   ##
===========================================
+ Coverage    79.37%   79.99%   +0.61%     
===========================================
  Files          903      906       +3     
  Lines       100632   101370     +738     
  Branches     11260    11600     +340     
===========================================
+ Hits         79879    81090    +1211     
+ Misses       20569    20097     -472     
+ Partials       184      183       -1     
Flag Coverage Δ
unittests 79.99% <ø> (+0.61%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
packages/galacean/package.json (1)

17-24: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick win

Missing "./package.json" subpath export.

Once "exports" is defined, only listed subpaths remain accessible — tools that read the dependency's own package.json (bundlers, React Native/Metro, require.resolve('galacean/package.json'), etc.) will fail with ERR_PACKAGE_PATH_NOT_EXPORTED. This is a well-known gotcha (see nodejs/node#33460, react-native-community/cli#1168) that has broken several popular packages after adopting exports.

🔧 Suggested addition
   "exports": {
     ".": {
       "types": "./types/index.d.ts",
       "import": "./dist/module.js",
       "browser": "./dist/browser.js",
       "default": "./dist/main.js"
-    }
+    },
+    "./package.json": "./package.json"
   },
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/galacean/package.json` around lines 17 - 24, The package exports map
in the package.json currently omits the package’s own package.json subpath,
which breaks consumers that resolve it directly. Update the exports block in the
package manifest to include the "./package.json" subpath alongside the existing
"." entry so tools like bundlers, Metro, and require.resolve can access it. Keep
the fix localized to the package.json exports definition and preserve the
current main/browser/module/type entries.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/galacean/package.json`:
- Around line 17-24: The package exports map in the galacean package is ordered
incorrectly, causing resolvers that match both conditions to select the import
target before the browser build. Update the object in the exports entry so the
browser condition is listed before import, keeping the types entry unchanged and
preserving the existing default fallback.

---

Nitpick comments:
In `@packages/galacean/package.json`:
- Around line 17-24: The package exports map in the package.json currently omits
the package’s own package.json subpath, which breaks consumers that resolve it
directly. Update the exports block in the package manifest to include the
"./package.json" subpath alongside the existing "." entry so tools like
bundlers, Metro, and require.resolve can access it. Keep the fix localized to
the package.json exports definition and preserve the current
main/browser/module/type entries.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: f2285e36-c5e1-4739-9a7c-dfcab3783759

📥 Commits

Reviewing files that changed from the base of the PR and between 721b42a and 48abd80.

📒 Files selected for processing (3)
  • packages/galacean/package.json
  • packages/galacean/src/ShaderPool.ts
  • packages/galacean/src/index.ts

Comment thread packages/galacean/package.json Outdated
GuoLei1990

This comment was marked as outdated.

@luo2430 luo2430 changed the title feat(galacean): add conditional exports with browser field support | refactor(galacean): replace @ts-ignore with @ts-expect-error and modernize loop feat(galacean): add conditional exports Jul 1, 2026
@luo2430

luo2430 commented Jul 1, 2026

Copy link
Copy Markdown
Author

改好了,不会是还没睡吧

GuoLei1990

This comment was marked as outdated.

@luo2430

luo2430 commented Jul 8, 2026

Copy link
Copy Markdown
Author

@cptbtptpbcptdtptp 这个改动我觉得对于使用体验提升很有帮助

@luo2430

luo2430 commented Jul 18, 2026

Copy link
Copy Markdown
Author

@cptbtptpbcptdtptp 😭

@cptbtptpbcptdtptp

Copy link
Copy Markdown
Collaborator

@cptbtptpbcptdtptp 😭

我看看。

@cptbtptpbcptdtptp

Copy link
Copy Markdown
Collaborator

@cptbtptpbcptdtptp 这个改动我觉得对于使用体验提升很有帮助

Hi,麻烦描述一下你具体的使用场景,最好带上一个最简 Demo ,我们可以更快将这个 PR 审核掉。

@luo2430

luo2430 commented Jul 18, 2026

Copy link
Copy Markdown
Author

https://github.com/luo2430/galacean-project.git

@cptbtptpbcptdtptp 我做好了一个示例项目,但目前 pnpm dev 是不能正常运行的。设置 esModuleInterop 不能解决这个问题,所以我打了个patch。

GuoLei1990

This comment was marked as outdated.

@cptbtptpbcptdtptp cptbtptpbcptdtptp left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

已复核最终 HEAD e4cfc2d9e,无阻塞问题。使用作者提供的 demo 独立复现:发布版 2.0.0-alpha.38 因顶层 browser 入口解析到 UMD,export * 后浏览器报 named export 缺失;临时应用本 PR 的 types / import / default exports map 后,Vite dev 正常加载,Engine 初始化并创建 WebGL canvas。import 指向 ESM module.jsdefault 保留 CJS fallback,顶层 UMD/CDN 字段未受影响。

@cptbtptpbcptdtptp

Copy link
Copy Markdown
Collaborator

重新对比了 Three.js、Babylon.js、PlayCanvas、PixiJS、CesiumJS 的发布方式,并用你提供的 Demo 做了进一步验证。结论是:针对当前问题,不需要增加 exports,只删除顶层 "browser": "dist/browser.js" 更合适。

我在 @galacean/engine@2.0.0-alpha.38 上只移除 browser 字段、未添加 exports,重新运行 Demo 后:

  • export * from "@galacean/engine" 正常;
  • 不再出现 named export 缺失;
  • Engine 正常初始化并创建 WebGL canvas。

原因是 Vite 在没有 exports 时按 browser -> module 查找入口;删除 browser 后会自然选择真正的 ESM dist/module.jsdist/browser.js 仍可继续生成并用于 UMD/CDN,只是不再参与包入口解析。

相比之下,给已有包新增 exports 会封闭所有未声明的深层入口,包括 @galacean/engine/package.json,并改变 Node/打包器解析行为,属于额外的 package-format / breaking change,不是修复这个问题的必要条件。

建议本 PR 收敛为:

-  "browser": "dist/browser.js",

如果后续确实需要引入 exports,建议单独开 PR,先梳理公开子路径,并补齐 require、类型入口和打包兼容测试。

@luo2430 luo2430 changed the title feat(galacean): add conditional exports fix(galacean): remove browser field from package.json Jul 19, 2026
@luo2430

luo2430 commented Jul 19, 2026

Copy link
Copy Markdown
Author

@cptbtptpbcptdtptp @GuoLei1990 改好了

GuoLei1990

This comment was marked as outdated.

@luo2430

luo2430 commented Jul 21, 2026

Copy link
Copy Markdown
Author

@cptbtptpbcptdtptp 还有需要改的地方吗?

GuoLei1990

This comment was marked as outdated.

@luo2430

luo2430 commented Jul 23, 2026

Copy link
Copy Markdown
Author

@cptbtptpbcptdtptp 😭

@cptbtptpbcptdtptp

cptbtptpbcptdtptp commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

@cptbtptpbcptdtptp 😭

明天会合掉的,需要再讨论一下,合并了会再发个版本。

@luo2430

luo2430 commented Jul 23, 2026

Copy link
Copy Markdown
Author

@cptbtptpbcptdtptp 😭

明天会合掉的,需要再讨论一下,合并了会再发个版本。

😄

GuoLei1990

This comment was marked as outdated.

@GuoLei1990 GuoLei1990 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🫧 尘小沫

总结

这是相对上一份 2026-07-23T13:33:59Z 目标-HEAD review 的 steady-state 增量复核。PR HEAD 仍为 ea3d2687cef7675d50c7ebbbaa2731a9ca3f42e0;期间没有新增 commit、代码 diff、inline comment 或会话更新。最终改动仍是单文件、单 commit,净删 packages/galacean/package.json 顶层 "browser": "dist/browser.js"。无新问题,维持可合入结论。

已关闭问题清单

  • [P1] exports.browser 指向 UMD:整套 exports 方案已撤销;最终 commit ea3d2687c 只删除顶层 browser 字段,问题不再适用。
  • [P2] featrefactor 混装:最终标题、commit 与 diff 已收敛为纯 fix,已修复。
  • Object.entries / @ts-expect-error 重构:已退出最终 diff,不适用。
  • CodeRabbit 的 ./package.json subpath 与条件调序建议:均依赖已撤销的 exports 方案;旧 inline thread 已 outdated,不重复提出。

增量与架构治理复核

  • 增量事实:GitHub 三点 compare 仍以 721b42a8c 为 merge base,PR 相对当前 dev/2.0 为 ahead 1 / behind 6,唯一 PR 文件变化仍是删除该行;PR 为 MERGEABLE / CLEAN
  • 上游生产 ownerpackages/galacean/src/index.ts 是入口源;Rollup 的 module() 读取 pkgJson.module/main 分别生成 ESM dist/module.js 与 CJS dist/main.jsgetUMD() 只按保留的 pkgJson.umd 选择包并生成 dist/browser(.min).js。构建链不读取被删字段,因此 UMD 产物与发布文件集合不受影响。
  • 下游消费 owner:browser bundler 不再被冲突的 browser → UMD 映射截流,会机械落到真正的 ESM module.js;Node/CJS 仍由 main.js 负责。unpkg / jsdelivr 继续指向 dist/bundled.module.min.js。Editor preload 只读取独立 browserPath 配置,且 first-party 列表不含顶层 @galacean/engine
  • 同根因冗余扫描:历史 57515aac build: set galacean global name 已把 UMD 构建选择权从 pkgJson.browser 迁到 pkgJson.umd;遗留的顶层 browser 字段因此成为消费入口上的第二 owner。当前删除方向正确:保留 module/main 作为模块消费权威、保留 umd 作为 UMD 生产权威,不新增 wrapper 或同步层。直接链路内没有剩余的平行状态机、可推导持久状态、重复转换/校验或 compat 分支需要随本 PR 继续删除。
  • 当前 base 与验证:base 后续 6 个 commit 包含 alpha.38 / alpha.39 发版及其他功能演进;packages/galacean/package.json 只发生版本号更新,没有改变入口协议。目标 HEAD 的 12 项 checks 全部 success,包括三平台 build、4 组 e2e、lint 与 codecov。

问题

无 P0/P1/P2/P3 新问题。当前单行删除仍是必要充分的最小根修。本次按 AutoCR 边界提交 COMMENTED review,等待人工 Reviewer 完成合入门禁。

@coderabbitai coderabbitai 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.

🧹 Nitpick comments (1)
scripts/check-package-entry-contracts.js (1)

45-59: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Validate the new CDN entrypoints too.

Lines 48-55 only inspect packageJson.browser, so every new unpkg/jsdelivr value bypasses the build-time contract check. Validate that each CDN target matches the allowed browser UMD naming and resolves to an artifact after b:module; otherwise a typo can ship broken CDN imports while this command passes.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@scripts/check-package-entry-contracts.js` around lines 45 - 59, Update
validateBrowserEntries to also inspect each package’s unpkg and jsdelivr targets
alongside packageJson.browser. Apply the allowed UMD naming validation and
verify each CDN target resolves to an artifact after b:module, reporting
violations through the existing violations collection.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@scripts/check-package-entry-contracts.js`:
- Around line 45-59: Update validateBrowserEntries to also inspect each
package’s unpkg and jsdelivr targets alongside packageJson.browser. Apply the
allowed UMD naming validation and verify each CDN target resolves to an artifact
after b:module, reporting violations through the existing violations collection.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: fb634406-1bbb-49e9-82e0-0bcfad3daf84

📥 Commits

Reviewing files that changed from the base of the PR and between ea3d268 and 1a81249.

📒 Files selected for processing (10)
  • package.json
  • packages/math/package.json
  • packages/physics-physx/package.json
  • packages/shader-compiler/package.json
  • packages/shader-compiler/verbose/package.json
  • packages/shader/package.json
  • packages/ui/package.json
  • packages/xr-webxr/package.json
  • packages/xr/package.json
  • scripts/check-package-entry-contracts.js
💤 Files with no reviewable changes (1)
  • packages/math/package.json

@GuoLei1990
GuoLei1990 merged commit 5e1a338 into galacean:dev/2.0 Jul 24, 2026
12 checks passed
@luo2430
luo2430 deleted the fix/galacean branch July 24, 2026 11:56

Copy link
Copy Markdown
Member

已合并,并随 v2.0.0-alpha.41 发布了,感谢贡献!🎉

@luo2430

luo2430 commented Jul 24, 2026

Copy link
Copy Markdown
Author

已合并,并随 v2.0.0-alpha.41 发布了,感谢贡献!🎉

🤭

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.

3 participants