-
-
Notifications
You must be signed in to change notification settings - Fork 401
feat(galacean): add conditional exports #3058
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
luo2430
wants to merge
5
commits into
galacean:dev/2.0
Choose a base branch
from
luo2430:fix/galacean
base: dev/2.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5014bbb
feat(galacean): add conditional exports with browser field support
luo2430 48abd80
refactor(galacean): replace @ts-ignore with @ts-expect-error and mode…
luo2430 ffa133f
Revert "refactor(galacean): replace @ts-ignore with @ts-expect-error …
luo2430 7bae7d5
Revert "feat(galacean): add conditional exports with browser field su…
luo2430 e4cfc2d
feat(galacean): add conditional exports
luo2430 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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:
package.jsonexports, conditional exports, and resolution algorithms across bundlers openjs-foundation/bundler-collab-space#7conditionNamesmatching webpack/enhanced-resolve#318node,browser,requireorimportconditions lukeed/resolve.exports#12Place
browserbeforeimportin the package exports mapexportsresolution follows object key order, so with"import"first, browser ESM resolvers that enable both conditions will match./dist/module.jsbefore./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
🤖 Prompt for AI Agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
apply
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@luo2430Got it, kicking off the change to reorder theexportsmap.exports["."]inpackages/galacean/package.jsonsobrowserprecedesimport, keepingtypesfirst anddefaultlast.Failed to handle agent chat message. Please try again.