-
Notifications
You must be signed in to change notification settings - Fork 159
feat: add rspack 2 types and dual-major test infrastructure #1398
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dannyhw
wants to merge
4
commits into
feat/rspack-2-node-guard
Choose a base branch
from
feat/rspack-2-types-test-infra
base: feat/rspack-2-node-guard
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
af1af71
feat: compile against rspack 2 and add dual-major test infrastructure
dannyhw 0b642c8
fix: resolve [projectRoot^N] paths reaching the filesystem root on Wi…
dannyhw de30460
fix: reset both legacy and top-level rspack cache locations
dannyhw 18e54f4
fix: keep resolveProjectPath inside project root on duplicate separators
dannyhw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| const { TestEnvironment: NodeEnvironment } = require('jest-environment-node'); | ||
|
|
||
| /** | ||
| * @rspack/core v2 is published as a pure ESM package, which Jest's sandboxed | ||
| * CJS module runtime cannot load (even `createRequire` inside the sandbox is | ||
| * wrapped by Jest and loops back into the module registry). | ||
| * | ||
| * Test environments are loaded outside the Jest sandbox with Node's real | ||
| * module system, where loading ESM through `require()`/`import()` is | ||
| * supported. Load @rspack/core here and expose it to the sandbox via a | ||
| * global - see jest.rspack-core-bridge.js for the consuming side. | ||
| * | ||
| * The environment is parameterized on RSPACK_MAJOR (default 2) so the suite | ||
| * can run against both supported Rspack majors: | ||
| * - v2: `await import('@rspack/core')` (ESM-only package), | ||
| * - v1: plain `require` of the aliased `@rspack/core-v1` devDependency - the | ||
| * package is CJS, and requiring it directly sidesteps any reliance on | ||
| * cjs-module-lexer named-export synthesis. | ||
| * `__RSPACK_MAJOR__` is exposed alongside so tests can gate major-specific | ||
| * assertions. | ||
| */ | ||
| class RspackCoreEnvironment extends NodeEnvironment { | ||
| async setup() { | ||
| await super.setup(); | ||
| const major = Number(process.env.RSPACK_MAJOR ?? '2'); | ||
| this.global.__RSPACK_CORE__ = | ||
| major === 1 ? require('@rspack/core-v1') : await import('@rspack/core'); | ||
| this.global.__RSPACK_MAJOR__ = major; | ||
| } | ||
| } | ||
|
|
||
| module.exports = RspackCoreEnvironment; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| // @rspack/core v2 is published as a pure ESM package, which Jest's sandboxed | ||
| // CJS module runtime cannot load. The real module is loaded natively by the | ||
| // custom test environment (jest.environment.js) and exposed via a global; | ||
| // this bridge maps `require('@rspack/core')` inside tests onto it. | ||
| // | ||
| // The `__esModule` marker keeps Babel's import interop treating this as an | ||
| // ESM-like namespace, so named imports (`import { rspack } from '@rspack/core'`) | ||
| // keep working. | ||
| const core = globalThis.__RSPACK_CORE__; | ||
|
|
||
| if (!core) { | ||
| throw new Error( | ||
| '@rspack/core was not preloaded by the test environment - ' + | ||
| 'make sure jest.environment.js is set as the testEnvironment' | ||
| ); | ||
| } | ||
|
|
||
| module.exports = { __esModule: true, ...core, default: core.default ?? core }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import { rspackVersion } from '@rspack/core'; | ||
|
|
||
| // Guards the dual-major test wiring itself: the custom Jest environment | ||
| // (jest.environment.js) loads @rspack/core v2 by default and the aliased | ||
| // @rspack/core-v1 under RSPACK_MAJOR=1. If the env var stops being honored, | ||
| // the "v1 lane" silently tests v2 twice - this catches that. | ||
| test('the loaded @rspack/core major matches the requested RSPACK_MAJOR lane', () => { | ||
| const requested = Number(process.env.RSPACK_MAJOR ?? '2'); | ||
| expect(Number(rspackVersion.split('.')[0])).toBe(requested); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.