Skip to content

refactor: migrate lib.autoExternal to output.autoExternal to leverage Rsbuild's capability#1641

Open
elecmonkey wants to merge 3 commits into
mainfrom
refactor/migrate-auto-external-to-rsbuild
Open

refactor: migrate lib.autoExternal to output.autoExternal to leverage Rsbuild's capability#1641
elecmonkey wants to merge 3 commits into
mainfrom
refactor/migrate-auto-external-to-rsbuild

Conversation

@elecmonkey
Copy link
Copy Markdown
Member

@elecmonkey elecmonkey commented May 12, 2026

Migrated lib.autoExternal to reuse Rsbuild's native output.autoExternal (available since Rsbuild 2.0.7).

The deprecated lib.autoExternal field is preserved that maps to output.autoExternal with a deprecation warning.

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented May 13, 2026

Deploying rslib with  Cloudflare Pages  Cloudflare Pages

Latest commit: 1a5b36f
Status: ✅  Deploy successful!
Preview URL: https://d9ac31c0.rslib.pages.dev
Branch Preview URL: https://refactor-migrate-auto-extern.rslib.pages.dev

View logs

Leverage Rsbuild 2.0.7's native output.autoExternal instead of
maintaining custom externalization logic. The deprecated lib.autoExternal
is kept as a thin shim with a logger warning.

- Remove composeAutoExternalConfig, composeExternalsWarnConfig,
  composeModuleImportWarn, handleMatchedExternal, getAutoExternalDefaultValue
- Set autoExternal default in composeFormatConfig (ESM/CJS bundle → true)
- Add exeExternalOverride to disable autoExternal for exe mode
- CLI writes to output.autoExternal instead of lib.autoExternal
- Add autoExternal field to RslibOutputConfig type
- Add output.autoExternal section to Rsbuild output docs (en/zh)
- Add deprecation warning banner to lib.autoExternal docs (en/zh)
- Update output.externals description to reference output.autoExternal
@elecmonkey elecmonkey force-pushed the refactor/migrate-auto-external-to-rsbuild branch from b2e6446 to 1a5b36f Compare May 21, 2026 06:09
@elecmonkey elecmonkey marked this pull request as ready for review May 21, 2026 06:09
Copilot AI review requested due to automatic review settings May 21, 2026 06:09
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR migrates Rslib’s dependency auto-externalization behavior from the legacy lib.autoExternal option to Rsbuild’s output.autoExternal, aligning implementation with Rsbuild’s built-in capability while keeping backward compatibility via a deprecation shim.

Changes:

  • Add output.autoExternal documentation (EN/ZH) and mark lib.autoExternal as deprecated in docs and public config typings.
  • Refactor core config composition to rely on output.autoExternal (and remove the previous custom composeAutoExternalConfig implementation and its unit tests).
  • Update CLI option wiring and test expectations/snapshots to reflect the new configuration location.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
website/docs/zh/config/rsbuild/output.mdx Add output.autoExternal docs and update output.externals wording to reference it.
website/docs/zh/config/lib/auto-external.mdx Add deprecation warning pointing to output.autoExternal.
website/docs/en/config/rsbuild/output.mdx Add output.autoExternal docs and update output.externals wording to reference it.
website/docs/en/config/lib/auto-external.mdx Add deprecation warning pointing to output.autoExternal.
tests/integration/externals/index.test.ts Remove the module-import warning integration test that depended on the old warning logic.
tests/integration/auto-external/index.test.ts Remove the module-import warning integration test and simplify imports accordingly.
packages/core/tests/external.test.ts Remove unit tests for the deleted composeAutoExternalConfig.
packages/core/tests/config.test.ts Update CLI snapshot expectations for new output.autoExternal location.
packages/core/tests/cli.test.ts Assert CLI populates lib.output.autoExternal instead of lib.autoExternal.
packages/core/tests/snapshots/config.test.ts.snap Update snapshots to reflect externals ordering and output.autoExternal presence.
packages/core/src/types/config.ts Deprecate lib.autoExternal in typings and add output.autoExternal override typing/docs.
packages/core/src/config.ts Remove custom auto-externalization + warning logic; set defaults via output.autoExternal; add deprecation shim.
packages/core/src/cli/init.ts Wire --auto-external CLI flag to lib.output.autoExternal.
Comments suppressed due to low confidence (2)

website/docs/en/config/lib/auto-external.mdx:15

  • The page frontmatter/intro still describes lib.autoExternal as an active configuration, but the option is now deprecated. Update the page description/intro to clearly state it’s kept for backward compatibility and point readers to output.autoExternal as the canonical option.
# lib.autoExternal

:::warning
`lib.autoExternal` is deprecated. Please use [output.autoExternal](/config/rsbuild/output#outputautoexternal) instead.
:::

:::info

`autoExternal` is a specific configuration for bundle mode. It will not take effect in bundleless mode (set [lib.bundle](/config/lib/bundle) to `false`) since deps will not be bundled in bundleless mode.

website/docs/zh/config/lib/auto-external.mdx:15

  • 当前页面的描述仍然把 lib.autoExternal 当作主要配置项,但这里已标记为废弃。建议同步更新页面的描述/开头说明,明确这是兼容性保留配置,并引导用户迁移到 output.autoExternal
# lib.autoExternal

:::warning
`lib.autoExternal` 已废弃,请使用 [output.autoExternal](/config/rsbuild/output#outputautoexternal) 代替。
:::

:::info

`autoExternal` 是 bundle 模式的特定配置。在 bundleless 模式(将 [lib.bundle](/config/lib/bundle) 设置为 `false`)下不会生效,因为 bundleless 模式下依赖不会被打包。

Comment thread packages/core/src/config.ts Outdated
Comment thread packages/core/src/config.ts
Comment thread website/docs/en/config/rsbuild/output.mdx
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@elecmonkey elecmonkey requested a review from Timeless0911 May 21, 2026 06:25
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.

2 participants