Skip to content

fix(core): resolve require.resolve from source module#1322

Merged
9aoy merged 6 commits into
mainfrom
9aoy/fix-require-resolve-origin
May 29, 2026
Merged

fix(core): resolve require.resolve from source module#1322
9aoy merged 6 commits into
mainfrom
9aoy/fix-require-resolve-origin

Conversation

@9aoy

@9aoy 9aoy commented May 26, 2026

Copy link
Copy Markdown
Collaborator

Summary

This PR wires Rstest to Rspack's injectRequireResolveOrigin support so require.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 native paths option, and adds unit plus e2e coverage.

Related Links

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

@github-actions

github-actions Bot commented May 26, 2026

Copy link
Copy Markdown

Rsdoctor Bundle Diff Analysis

Found 13 projects in monorepo, 1 project with changes.

📊 Quick Summary
Project Total Size Change
adapter-rsbuild 3.7 KB 0
adapter-rslib 24.7 KB 0
adapter-rspack 7.8 KB 0
browser 2.0 MB 0
browser-react 3.7 KB 0
browser-ui 810.0 KB 0
coverage-istanbul 14.5 KB 0
coverage-v8 16.3 KB 0
core/browser 971.9 KB 0
core/loaders 869.0 B 0
core/main 1.7 MB +2.3 KB (0.1%)
vscode/extension 27.0 MB 0
vscode/worker 14.5 KB 0
📋 Detailed Reports (Click to expand)

📁 core/main

Path: packages/core/.rsdoctor/main/rsdoctor-data.json

📌 Baseline Commit: 7bd281f648 | PR: #1303

Metric Current Baseline Change
📊 Total Size 1.7 MB 1.7 MB +2.3 KB (0.1%)
📄 JavaScript 1.6 MB 1.6 MB +2.3 KB (0.1%)
🎨 CSS 0 B 0 B 0
🌐 HTML 0 B 0 B 0
📁 Other Assets 81.6 KB 81.6 KB 0

📦 Download Diff Report: core/main Bundle Diff

Generated by Rsdoctor GitHub Action

@cloudflare-workers-and-pages

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

Copy link
Copy Markdown

Deploying rstest with  Cloudflare Pages  Cloudflare Pages

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

View logs

@github-actions

github-actions Bot commented May 28, 2026

Copy link
Copy Markdown

📝 Rstest Ecosystem CI: Open

suite result
examples ✅ success
rspress ✅ success
rslib ✅ success
modernjs ✅ success
rsdoctor ✅ success
rsbuild ✅ success

@9aoy 9aoy marked this pull request as ready for review May 28, 2026 11:22
@9aoy 9aoy requested a review from Copilot May 28, 2026 11:22

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 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.resolve runtime 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 injectRequireResolveOrigin in the rspack RstestPlugin configuration 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.

Comment thread packages/core/tests/runner/requireResolveOrigin.test.ts
@9aoy

9aoy commented May 29, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

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

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

Comment thread packages/core/src/runtime/worker/loadModule.ts Outdated

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

Comment thread packages/core/src/runtime/worker/loadModule.ts Outdated
@9aoy 9aoy merged commit 9b77a98 into main May 29, 2026
14 checks passed
@9aoy 9aoy deleted the 9aoy/fix-require-resolve-origin branch May 29, 2026 05:53
@9aoy 9aoy restored the 9aoy/fix-require-resolve-origin branch May 29, 2026 06:25
@9aoy 9aoy deleted the 9aoy/fix-require-resolve-origin branch May 29, 2026 06:55
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.

[Bug]: require.resolve error

2 participants