fix(core): resolve require.resolve from source module#1322
Conversation
Rsdoctor Bundle Diff AnalysisFound 13 projects in monorepo, 1 project with changes. 📊 Quick Summary
📋 Detailed Reports (Click to expand)📁 core/mainPath:
📦 Download Diff Report: core/main Bundle Diff Generated by Rsdoctor GitHub Action |
Deploying rstest with
|
| Latest commit: |
7b00d41
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://9882d69d.rstest.pages.dev |
| Branch Preview URL: | https://9aoy-fix-require-resolve-ori.rstest.pages.dev |
There was a problem hiding this comment.
Pull request overview
This PR integrates rspack’s injectRequireResolveOrigin support into Rstest so require.resolve() calls inside bundled modules resolve relative specifiers against the originating source module (rather than the test entry), while preserving the native paths option. It adds runtime helpers for both CJS and ESM execution and introduces unit + e2e coverage for the new behavior.
Changes:
- Add a CJS
require.resolveruntime wrapper plus a VM-global__rstest_require_resolve__helper for rewritten call sites. - Add an ESM
import.meta.__rstest_require_resolve__helper for rewritten call sites in module output mode. - Enable
injectRequireResolveOriginin the rspackRstestPluginconfiguration and add unit/e2e tests.
Reviewed changes
Copilot reviewed 8 out of 9 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| packages/core/src/runtime/worker/loadModule.ts | Adds the CJS require.resolve wrapper and exposes __rstest_require_resolve__ in the VM context. |
| packages/core/src/runtime/worker/loadEsModule.ts | Adds the ESM import.meta.__rstest_require_resolve__ helper via initializeImportMeta. |
| packages/core/src/core/plugins/basic.ts | Enables rspack injectRequireResolveOrigin and selects helper function name based on output mode. |
| packages/core/tests/runner/requireResolveOrigin.test.ts | Adds unit tests for origin-aware resolution and options passthrough (CJS + ESM helper attachment). |
| packages/core/tests/core/snapshots/rsbuild.test.ts.snap | Updates snapshots to reflect the new rspack plugin option wiring. |
| e2e/externals/requireResolveOrigin.test.ts | Adds e2e coverage for resolving relative specifiers and preserving paths. |
| e2e/externals/require-resolve-origin/index.js | Adds an externals fixture that calls require.resolve() from a different directory than the test entry. |
| e2e/externals/require-resolve-origin/index.d.ts | Adds typings for the new externals fixture exports. |
| e2e/externals/require-resolve-origin/exportHelper.js | Adds a small helper file used by the externals fixture. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 75ab3c939d
ℹ️ 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".
Summary
This PR wires Rstest to Rspack's
injectRequireResolveOriginsupport sorequire.resolve()in bundled modules resolves relative specifiers from the source module that produced the call instead of the test entry. It adds CJS and ESM runtime helpers, preserves the nativepathsoption, and adds unit plus e2e coverage.Related Links
Checklist