feat(core): support environment scoped exposed APIs#7994
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe PR adds environment-scoped support for 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
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. Comment |
|
@codex review |
|
Codex Review: Didn't find any major issues. Breezy! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 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 `@website/docs/en/plugins/dev/core.mdx`:
- Around line 758-761: Update the plugin API example to use api.expose instead
of rsbuild.expose so it matches the documented method and does not suggest the
environment-scoped option is only available on the instance API. Locate the
snippet in the core.mdx docs section around the api.expose documentation and
replace both rsbuild.expose calls with the corresponding api.expose calls while
keeping the same arguments.
In `@website/docs/zh/plugins/dev/core.mdx`:
- Around line 759-760: The plugin API example currently uses rsbuild.expose,
which conflicts with the surrounding api.expose documentation. Update the
example in the core plugin API section to use api.expose for both calls, and
keep the same arguments and environment values so the example matches the API
being described.
🪄 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: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 0c6deb72-5e81-41fa-b2cc-a773c05f79e3
📒 Files selected for processing (7)
e2e/cases/plugin-api/plugin-expose/index.test.tspackages/core/src/initPlugins.tspackages/core/src/types/plugin.tswebsite/docs/en/api/javascript-api/instance.mdxwebsite/docs/en/plugins/dev/core.mdxwebsite/docs/zh/api/javascript-api/instance.mdxwebsite/docs/zh/plugins/dev/core.mdx
There was a problem hiding this comment.
Pull request overview
This PR extends Rsbuild’s exposed plugin APIs to support environment-scoped registration and resolution, enabling integrations (e.g. Rstest) to expose different APIs per config.environments entry without leaking across environments. useExposed now prefers an API exposed for the current plugin environment and falls back to a global exposed API, while expose remains backward-compatible unless an environment option is provided.
Changes:
- Extend
exposeto accept an optional{ environment?: string }and store multiple exposed APIs per id (global + per-environment). - Update
useExposedresolution to prefer same-environment API and fall back to global. - Add e2e coverage and update both English/Chinese docs for the new behavior.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| website/docs/zh/plugins/dev/core.mdx | Documents api.expose options and environment-scoped resolution behavior. |
| website/docs/zh/api/javascript-api/instance.mdx | Adds environment-scoped rsbuild.expose usage example and behavior description. |
| website/docs/en/plugins/dev/core.mdx | Documents api.expose options and environment-scoped resolution behavior. |
| website/docs/en/api/javascript-api/instance.mdx | Adds environment-scoped rsbuild.expose usage example and behavior description. |
| packages/core/src/types/plugin.ts | Adds ExposeOptions and updates RsbuildPluginAPI.expose signature + useExposed behavior note. |
| packages/core/src/initPlugins.ts | Implements environment-scoped exposed API storage and environment-aware useExposed. |
| e2e/cases/plugin-api/plugin-expose/index.test.ts | Adds e2e tests for environment scoping, fallback to global, and non-leakage to global plugins. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Summary
This PR adds environment-scoped
expose/useExposedsupport so integrations such as Rstest can expose per-environment APIs without leaking configuration changes across projects.useExposednow prefers an API registered for the current plugin environment and falls back to the global exposed API, whileexposeremains backward-compatible and only scopes APIs when anenvironmentoption is provided.Usage Example
In this example,
project1Pluginresolves therstestAPI exposed forproject1. It does not receive the API exposed forproject2, and will fall back to a global exposed API only when no matching environment API exists.Related Links
https://github.com/web-infra-dev/rsbuild/blob/main/packages/core/src/pluginManager.ts