Skip to content

perf(build): add a code hook filter to the replace plugin - #4946

Merged
pi0 merged 1 commit into
mainfrom
perf/code-filter
Oct 27, 2026
Merged

pi0 merged 1 commit into
mainfrom
perf/code-filter

Conversation

@pi0x

@pi0x pi0x commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

Resolves #4945.

The replace plugin's transform now has a code filter built from the escaped replacement keys, so modules that contain none of them are skipped (natively by Rolldown, before the handler by Rollup). Output is unchanged since such modules can't be modified by the plugin. The plugin setup moved to src/build/plugins/replace.ts with a unit test.

🤖 Generated with AI assistant

Modules without any of the replaced keys are skipped (natively by Rolldown). Resolves #4945.
@pi0x
pi0x requested a review from pi0 as a code owner October 27, 2026 17:21
@vercel

vercel Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
nitro.build Ready Ready Preview Oct 27, 2026 5:22pm UTC

Request Review

@coderabbitai

coderabbitai Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Caution

Review failed

The pull request is closed.

Walkthrough

The build now uses a local replacement plugin. It applies replacements while filtering transform calls to code that contains a configured replacement key. Tests cover the filter, raw-module exclusion, and related plugin behavior.

Changes: Replacement filtering

Layer / File(s) Summary
Configure and test replacement filtering
src/build/plugins/replace.ts, test/unit/build-replace.test.ts
The local plugin configures replacement values and assignment protection. When replacement keys exist, its transform hook filters code using escaped keys. Tests cover matching and non-matching code, raw modules, empty keys, and the absence of renderChunk.
Register the local replacement plugin
src/build/plugins.ts
baseBuildPlugins now registers the local plugin with base.replacements.

Priority: Not assessed

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Refactor

Possibly related PRs

  • nitrojs/nitro#4934: Adds nitro.options.envName to the replacement map consumed by the plugin changed here.

Suggested labels: v3

Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@pkg-pr-new

pkg-pr-new Bot commented Oct 27, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/nitro@4946

commit: 721e6e6

@pi0
pi0 merged commit 20a8850 into main Oct 27, 2026
15 of 16 checks passed
@pi0
pi0 deleted the perf/code-filter branch October 27, 2026 17:25

This branch was successfully deployed

1 active deployment
Preview — 721e6e6f Deployed Oct 27, 2026 by vercel[bot]
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.

build: add a code hook filter to the replace plugin

2 participants