Skip to content

feat: add Rspack 2 runtime foundations and dual-major test infrastructure - #1397

Open
dannyhw wants to merge 5 commits into
dannyhw/rspack-2-supportfrom
feat/rspack-2-node-guard
Open

feat: add Rspack 2 runtime foundations and dual-major test infrastructure#1397
dannyhw wants to merge 5 commits into
dannyhw/rspack-2-supportfrom
feat/rspack-2-node-guard

Conversation

@dannyhw

@dannyhw dannyhw commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

Summary

Combines the remaining Rspack 2 runtime foundations into one review unit:

This PR targets dannyhw/rspack-2-support, where #1394 has already landed. It is the next prerequisite for the config, cache, and React Refresh work.

What changed

  • Fail clearly on unsupported Node versions before importing the ESM-only Rspack 2 core.
  • Load start and bundle commands lazily and route profiling through the shared version helper.
  • Compile Re.Pack against Rspack 2 types while preserving Rspack 1 runtime compatibility.
  • Add honest Rspack 1 and Rspack 2 Jest lanes with a major-version guard.
  • Add Rspack 1 and Windows CI coverage.
  • Fix resolveProjectPath behavior at the Windows filesystem root.

Detailed review history for the absorbed test-infrastructure slice remains in #1398.

References

Validation

The component branches previously passed:

  • pnpm turbo run typecheck test --force — 17/17 tasks
  • Re.Pack unit tests under Rspack 1 and Rspack 2
  • pnpm lint:ci

The combined branch will run the same GitHub checks before merging into the feature branch.

@vercel

vercel Bot commented Jul 6, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
repack-website Ready Ready Preview, Comment Jul 26, 2026 8:45pm

Request Review

@changeset-bot

changeset-bot Bot commented Jul 6, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 7554f51

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 6 packages
Name Type
@callstack/repack Patch
@callstack/repack-plugin-expo-modules Patch
@callstack/repack-plugin-nativewind Patch
@callstack/repack-plugin-reanimated Patch
@callstack/repack-dev-server Patch
@callstack/repack-init Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Comment thread packages/repack/src/commands/rspack/ensureNodeCompat.ts
Base automatically changed from feat/rspack-2-foundations to dannyhw/rspack-2-support July 26, 2026 20:29
@dannyhw dannyhw changed the title feat: add node compatibility guard and lazy command loading for rspack feat: add Rspack 2 runtime foundations and dual-major test infrastructure Jul 26, 2026
dannyhw added 5 commits July 26, 2026 21:43
Bump @callstack/repack's @rspack/core devDependency to ^2.1.2 (the
workspace catalog stays on v1) and absorb the type-level fallout with
zero runtime behavior change for Rspack 1 / webpack users:

- SwcLoaderOptions became a union discriminated on detectSyntax in v2 -
  introduce a local non-union SwcConfig alias and split builtin:swc-loader
  only options off before calling the raw swc transformSync (also more
  correct at runtime)
- narrow devServer before reading .hot in RepackTargetPlugin (the key can
  be false in v2 types)
- rest-destructure devServer off the config in the bundle command instead
  of delete (not assignable to v2's bundled DevServer type, and unused
  for bundling)
- one documented cast in the start command: Re.Pack's devServer type
  augmentation and Rspack 2's bundled DevServer type are incompatible
  solely because each pulls proxy types from a different copy of
  http-proxy-middleware, and devServer cannot be stripped there because
  the dev server flow reads it back from compiler.options
- getRspackCacheConfig accessor reading the persistent cache config from
  both the Rspack 1 (experiments.cache) and Rspack 2 (top-level cache)
  locations, with derived cache types extended for the legacy location

@rspack/core v2 is ESM-only which Jest's sandboxed CJS runtime cannot
load, so tests now run through a custom test environment that loads the
real core outside the sandbox and bridges it back via moduleNameMapper.
The environment is parameterized on RSPACK_MAJOR (v2 via import(), v1
via require of the aliased @rspack/core-v1 devDependency), exposes
__RSPACK_MAJOR__ for major-gated assertions, and a permanent lane-guard
test asserts the loaded major matches the requested lane.

CI gains a Rspack 1 unit-suite lane, a Windows lane running the suite
under both majors (the require(esm) loading path is Windows-sensitive),
and the main-branch Node 18/20 matrix lanes run with RSPACK_MAJOR=1
since Rspack 2 requires Node ^20.19.0 || >=22.12.0. HermesBytecodePlugin
test expectations are made platform-agnostic for the Windows lane.
getRspackCacheConfig preferred experiments.cache over the top-level
cache option, but a merged or dual-major config can carry both keys
(e.g. the experimental cache defaults set experiments.cache while a
user config sets top-level cache). Which location is active depends on
the installed Rspack major, so --reset-cache now collects both
locations instead of picking one.
- unit-test ensureNodeSupportsRspack against mocked rspack/node versions,
  including the ^20.19.0 || >=22.12.0 range boundaries
- assert the rspack commands module registers without loading @rspack/core
  (a throwing @rspack/core mock fails the suite on any eager load)
- assert lazy bundle/start run the guard before importing the command
  modules and skip them entirely when the guard throws
- lower dynamic import() to require() in the jest babel env only;
  published output keeps import() as-is
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.

1 participant