Skip to content

fix(plugin-babel): skip text import attributes in standalone rule - #8039

Merged
chenjiahan merged 1 commit into
mainfrom
chenjiahan/fix-babel-text-import-attributes
Jul 2, 2026
Merged

fix(plugin-babel): skip text import attributes in standalone rule#8039
chenjiahan merged 1 commit into
mainfrom
chenjiahan/fix-babel-text-import-attributes

Conversation

@chenjiahan

Copy link
Copy Markdown
Member

Summary

This PR fixes a @rsbuild/plugin-babel include/exclude mode compatibility issue where its standalone script rule could still transform script imports using with { type: 'text' }, causing the text import to export Babel-processed content instead of the original source text. The standalone Babel rule now skips type: 'text' import attributes, and a focused e2e case covers the .ts text-import path while keeping normal named imports working.

Related Links

Copilot AI review requested due to automatic review settings July 2, 2026 06:07
@coderabbitai

coderabbitai Bot commented Jul 2, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 16b33a2d-9446-4c78-ba93-d071a2cc9aaf

📥 Commits

Reviewing files that changed from the base of the PR and between a134672 and 0c2ee8b.

⛔ Files ignored due to path filters (1)
  • packages/plugin-babel/tests/__snapshots__/index.test.ts.snap is excluded by !**/*.snap
📒 Files selected for processing (4)
  • e2e/cases/plugin-babel/import-attributes-text-script/index.test.ts
  • e2e/cases/plugin-babel/import-attributes-text-script/src/index.js
  • e2e/cases/plugin-babel/import-attributes-text-script/src/text.ts
  • packages/plugin-babel/src/plugin.ts

📝 Walkthrough

Walkthrough

Changes

This change updates the Babel plugin's include/exclude rule to exclude modules with type 'text' from processing by adding a .with({ type: { not: 'text' } }) condition after the existing .test(SCRIPT_REGEX) check. A corresponding new E2E test case is added under plugin-babel/import-attributes-text-script, including a text fixture file exporting a string constant, an index module that imports the fixture both as raw text and as a value and exposes both on window, and a test that builds a preview and asserts the exposed values match the source file contents.

Related PRs: None specified.

Suggested labels: plugin-babel, e2e-test

Suggested reviewers: None specified.


🐰 A whisper of text, untouched by the loom,
No script shall claim it, no rule shall consume—
A fixture, a value, a window's soft glow,
Carrots for tests that make certain we know.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main change: skipping text import attributes in the standalone plugin-babel rule.
Description check ✅ Passed The description is directly related to the fix and the new e2e coverage for text imports.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 fixes an interaction between @rsbuild/plugin-babel’s include/exclude mode and Rsbuild’s “text import attributes” feature by ensuring the standalone Babel rule does not apply to import ... with { type: 'text' } requests, preserving the original source text.

Changes:

  • Update the plugin-babel standalone script rule (include/exclude mode) to skip with { type: 'text' } imports.
  • Update plugin-babel snapshot output to reflect the new rule condition.
  • Add an e2e case verifying TS text-imports remain untransformed while normal named imports still work with Babel include mode.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/plugin-babel/src/plugin.ts Excludes type: 'text' import attributes from the standalone Babel rule.
packages/plugin-babel/tests/snapshots/index.test.ts.snap Updates expected rule serialization to include the new with.type.not condition.
e2e/cases/plugin-babel/import-attributes-text-script/src/text.ts Adds a TS fixture used for both normal and text-attribute imports.
e2e/cases/plugin-babel/import-attributes-text-script/src/index.js Imports the TS fixture normally and via with { type: 'text' } and exposes results on window.
e2e/cases/plugin-babel/import-attributes-text-script/index.test.ts Verifies the text import equals the raw source file content and the named import still evaluates correctly.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 142 to 146
const loader = rule
.test(SCRIPT_REGEX)
.with({ type: { not: 'text' } })
.use(CHAIN_ID.USE.BABEL)
.loader(BABEL_LOADER_PATH)
@chenjiahan
chenjiahan merged commit 6b6df8b into main Jul 2, 2026
8 checks passed
@chenjiahan
chenjiahan deleted the chenjiahan/fix-babel-text-import-attributes branch July 2, 2026 06:24
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