Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion packages/galacean/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,16 @@
"types": "types/index.d.ts",
"main": "dist/main.js",
"module": "dist/module.js",
"browser": "dist/browser.js",
"unpkg": "dist/bundled.module.min.js",
"jsdelivr": "dist/bundled.module.min.js",
"exports": {
".": {
"types": "./types/index.d.ts",
"import": "./dist/module.js",
"browser": "./dist/browser.js",
"default": "./dist/main.js"
}
},
Comment on lines +18 to +24

@coderabbitai coderabbitai Bot Jul 1, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🌐 Web query:

What condition key order do Vite, Webpack 5, and Rollup use when resolving package.json "exports" for browser + ESM builds, and does key order in the exports object take priority over the resolver's condition list order?

💡 Result:

Vite, Webpack 5, and Rollup all adhere to the Node.js module resolution specification, which mandates that within the "exports" object of a package.json file, key order is significant [1][2][3]. During conditional export resolution, keys are checked in the order they appear in the object; the first matching condition found is the one that takes precedence [2][4][5]. Because the resolution process stops as soon as a match is found, the order of keys in the "exports" object effectively defines the priority of your conditions [2][4]. The standard practice is to list conditions from most specific to least specific (e.g., placing custom environment conditions before general fallbacks like "default") [5][3]. Regarding your question on priority: key order within the "exports" object takes absolute priority over the order in which you might list or "enable" conditions in a resolver's configuration [1][2]. While the bundler's configuration (such as Webpack's resolve.conditionNames or Vite/Rollup's export conditions) determines which conditions are currently "active" or available to be matched, the resolver will only select a condition if it exists in that active list AND appears earliest in the "exports" object's defined order [1][2][4]. Consequently, if you have both "import" and "require" active in your configuration, the one that appears first in your package.json "exports" object will be the one chosen [4].

Citations:


Place browser before import in the package exports map

exports resolution follows object key order, so with "import" first, browser ESM resolvers that enable both conditions will match ./dist/module.js before ./dist/browser.js. Move "browser" ahead of "import" to make the browser build selectable.

Suggested fix
   "exports": {
     ".": {
       "types": "./types/index.d.ts",
-      "import": "./dist/module.js",
       "browser": "./dist/browser.js",
+      "import": "./dist/module.js",
       "default": "./dist/main.js"
     }
   },
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"exports": {
".": {
"types": "./types/index.d.ts",
"import": "./dist/module.js",
"browser": "./dist/browser.js",
"default": "./dist/main.js"
}
},
"exports": {
".": {
"types": "./types/index.d.ts",
"browser": "./dist/browser.js",
"import": "./dist/module.js",
"default": "./dist/main.js"
}
},
🤖 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 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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

apply

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@luo2430 Got it, kicking off the change to reorder the exports map.

  • Reorder exports["."] in packages/galacean/package.json so browser precedes import, keeping types first and default last.

Failed to handle agent chat message. Please try again.

"files": [
"dist/**/*",
"types/**/*"
Expand Down
4 changes: 2 additions & 2 deletions packages/galacean/src/ShaderPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,15 @@ export class ShaderPool {
];

for (const source of sources) {
// @ts-ignore — `_createFromPrecompiled` is `Shader` @internal.
// @ts-expect-error — `_createFromPrecompiled` is `Shader` @internal.
Shader._createFromPrecompiled(source);
}

// Configure the particle feedback pass's transform-feedback varyings.
// The pass itself is later looked up via `Shader.find` inside
// `ParticleTransformFeedbackSimulator`, so no caching needed here.
const feedbackPass = Shader.find("Effect/ParticleFeedback").subShaders[0].passes[0];
// @ts-ignore — `_feedbackVaryings` is `ShaderPass` @internal.
// @ts-expect-error — `_feedbackVaryings` is `ShaderPass` @internal.
feedbackPass._feedbackVaryings = ["v_FeedbackPosition", "v_FeedbackVelocity"];
}
}
8 changes: 4 additions & 4 deletions packages/galacean/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as CoreObjects from "@galacean/engine-core";
import { Loader, Polyfill, SystemInfo } from "@galacean/engine-core";
import { ShaderPool } from "./ShaderPool";
//@ts-ignore

export const version = `__buildVersion`;

console.log(`Galacean Engine Version: ${version}`);
Expand All @@ -11,8 +11,8 @@ export * from "@galacean/engine-loader";
export * from "@galacean/engine-math";
export * from "@galacean/engine-rhi-webgl";

for (let key in CoreObjects) {
Loader.registerClass(key, CoreObjects[key]);
for (const [key, value] of Object.entries(CoreObjects)) {
Loader.registerClass(key, value);
}

// Bootstrap the Galacean engine flavor: browser polyfills first (must
Expand All @@ -26,7 +26,7 @@ for (let key in CoreObjects) {
// shader bundle dependency), which in turn lets the offline shader
// compiler import core's enums without dragging the full runtime closure.
Polyfill.registerPolyfill();
// @ts-ignore — `_initialize` is `SystemInfo` @internal.
// @ts-expect-error — `_initialize` is `SystemInfo` @internal.
SystemInfo._initialize();
ShaderPool.init();
ShaderPool.registerShaders();
Loading