Skip to content

refactor(build): align Rsbuild integration with official plugin patterns - #510

Merged
ScriptedAlchemy merged 3 commits into
mainfrom
refactor/build-official-plugin-patterns
Sep 4, 2026
Merged

refactor(build): align Rsbuild integration with official plugin patterns#510
ScriptedAlchemy merged 3 commits into
mainfrom
refactor/build-official-plugin-patterns

Conversation

@ScriptedAlchemy

@ScriptedAlchemy ScriptedAlchemy commented Sep 4, 2026

Copy link
Copy Markdown
Owner

Source-reading pass over the official/community plugins evaluated in #509 (rsbuild-plugin-publint, rsbuild-plugin-arethetypeswrong, @rsbuild/plugin-type-check, @rsbuild/plugin-check-syntax, rsbuild-plugin-source-build, @rsbuild/plugin-react, rsbuild-plugin-virtual-module) plus Rsbuild core's built-in plugins, looking for patterns that make an existing path in packages/agent-bundle/src/build/** or the two package rslib.config.ts files shorter or clearer with identical output. Scope kept to that; no new abstraction, plugin layer, or option. Each change below is one commit-sized item the maintainer can judge separately.

Changes

# Path Before → after (code lines, comments excluded) Pattern borrowed from Behavior
1 packages/agent-bundle/rslib.config.ts — the __filename/__dirname ESM shim 17 → 15; nesting 5 → 3 levels; drops the Rspack/rspack type imports and the engine parameter api.processAssets({ stage: 'additions' }, ({ assets, compilation, sources }) => …) — how Rsbuild's built-in rsbuild:inline-chunk and rsbuild:appIcon plugins hang asset rewrites, instead of a hand-written Rspack plugin class (apply → thisCompilation.tap → processAssets.tap({ stage: PROCESS_ASSETS_STAGE_ADDITIONS })) appended via tools.rspack. Rsbuild's implementation of the hook is the same thisCompilation + processAssets.tapPromise({ stage }) tap. dist/** byte-identical (warm and cold cache): diff -rq before/after clean; dist/1178.js still carries the shim.

That is the only change that met the bar. pluginPublint was already registered the official way, and both composeEntryLibConfig and composeMcpAppsRsbuildConfig already use @rsbuild/plugin-react.

Considered and left alone (with the reason)

  • Post-build checks onto onAfterBuild / afterEmit (assertNoResidualReservedImports, assertSelfContainedViews; publint/attw use api.onAfterBuild, check-syntax uses compiler.hooks.afterEmit over compilation.getAssets()): the framework's checks deliberately read the published on-disk bytes after rslib.build() resolves and after close(), and wrapping them in a plugin would be a new plugin layer, not a shorter path.
  • Logging through @rsbuild/core's logger (publint/attw/type-check pattern): src/build/** prints nothing itself — every failure is a thrown Error/DiagnosticError that the CLI's diagnostics layer renders, and builds run at logLevel: 'silent'/'error'. Nothing to move.
  • Option validation: the official plugins validate nothing beyond TypeScript types; the framework's tools shape checks (AB4720–4723) live in config/validate.ts, outside this scope, and are the diagnostics the docs promise.
  • pluginReact({ fastRefresh: false }) in rslib.ts: the plugin only enables refresh in dev mode, so the option is redundant for build(), but the file is owned by perf(build): one Rslib instance per target for every agent-host surface (xref row 12) #503 right now (see below) and the explicit false documents intent.
  • Multi-environment handling: composeMcpAppsRsbuildConfig already uses one Rsbuild instance with one environment per view, the shape type-check's checkedTsconfig-per-environment logic assumes.

For the xref-build-orchestration worker (#503 touches rslib.ts; not edited here)

  1. virtualModulesPluginConstructor is duplicated verbatim in src/build/rslib.ts (Rslib's engine) and src/build/mcp-apps.ts (workspace @rsbuild/core), differing only in the message text. One helper taking (rspack, engineName, purpose) would drop ~10 lines; both call sites keep their own engine object, so the dual-engine rule holds.
  2. enforceInvariants in rslib.ts grows a DefinePlugin and a VirtualModulesPlugin through config.plugins = [...(config.plugins ?? []), …] twice; a single append at the end of the mutator is one statement.

Verification

  • pnpm typecheck, pnpm lint: clean.
  • packages/agent-bundle/dist before vs after: diff -rq reports no differences, with the default warm Rspack cache and with a fresh AGENT_BUNDLE_RSLIB_CACHE_DIRECTORY.
  • artifact/** for examples/audiobook-curator and examples/host-test: unchanged by construction — no src/build/** file changes in this PR and the package dist they build with is byte-identical.

Review status

Codex reviewed 5a3cb01 (PR opened). One thread, addressed in-branch rather than by reply (this PR posts no comments):

  • .changeset/build-official-plugin-patterns.md — "implementation-only summary": agreed; there is no user-facing change to describe (byte-identical dist/**, no command, export, or config key). The changeset is removed and the PR carries the skip-changeset label, the AGENTS.md escape hatch for genuinely no-op changes.

Last Codex-reviewed head: 5a3cb01. Unreviewed heads (no re-review arrived after the pushes; this PR posts no comments): the changeset-number commit, the rebase over #507, and the changeset removal — current head 76877346d. Merged on green CI per the AGENTS.md fallback; any thread opened afterwards is answered in a follow-up PR.

@changeset-bot

changeset-bot Bot commented Sep 4, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 7687734

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 4, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-04T02:27:15.827186Z 5a3cb01 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@ScriptedAlchemy
ScriptedAlchemy force-pushed the refactor/build-official-plugin-patterns branch from 9f60224 to fc1d717 Compare September 4, 2026 02:26

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5a3cb01fcf

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

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".

'agent-bundle': patch
---

Register the package build's `__filename`/`__dirname` ESM shim through Rsbuild's `processAssets` plugin hook instead of a hand-rolled Rspack plugin class inside `tools.rspack`, matching how Rsbuild's own asset plugins hang post-build rewrites. The emitted `dist/**` is byte-identical; no artifact, config key, or CLI output changes. (#PR)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Replace the implementation-only changeset summary

When the next Version Packages release consumes this changeset, this paragraph becomes user-facing release prose, but it only documents the internal processAssets/Rspack refactor and explicitly says behavior is unchanged; it also names no public command, export, or config key. Replace it with the required user-facing imperative summary rather than publishing internal build mechanics.

AGENTS.md reference: AGENTS.md:L104-L105

Useful? React with 👍 / 👎.

@pkg-pr-new

pkg-pr-new Bot commented Sep 4, 2026

Copy link
Copy Markdown
npm i https://pkg.pr.new/ScriptedAlchemy/agent-bundle@510
npm i https://pkg.pr.new/ScriptedAlchemy/agent-bundle/create-agent-bundle@510
npm i https://pkg.pr.new/ScriptedAlchemy/agent-bundle/@agent-bundle/runtime@510

commit: 7687734

@ScriptedAlchemy ScriptedAlchemy added the skip-changeset PR changes a publishable package but ships no observable change; changeset not required label Sep 4, 2026
@ScriptedAlchemy
ScriptedAlchemy merged commit e4a5ad6 into main Sep 4, 2026
13 of 14 checks passed
@ScriptedAlchemy
ScriptedAlchemy deleted the refactor/build-official-plugin-patterns branch September 4, 2026 03:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip-changeset PR changes a publishable package but ships no observable change; changeset not required

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant