feat: add rspack version detection helpers#1394
Conversation
|
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
9b5229f to
89f3c09
Compare
89f3c09 to
7cbf8b8
Compare
Utilities for the upcoming dual rspack-major support (see agent_context/rspackv2-jul2026/): getRspackVersion / getRspackMajorVersion / isRspack2 resolve @rspack/core/package.json without importing the package - safe on any Node version (@rspack/core@2 is ESM-only and cannot be require()d on Node < 20.19) and safe when rspack is not installed (webpack-only projects). getRspackMajorVersionFromCompiler covers plugin contexts via compiler.webpack.rspackVersion. ConfigKeys additions (cache, experiments) describe config keys the commands already read. No behavior change; nothing consumes the helpers yet.
7cbf8b8 to
81936bb
Compare
dannyhw
left a comment
There was a problem hiding this comment.
codex review: Leaving one inline test-validity concern about the optional-peer-absent path.
| expect(getRspackVersion(rspack2Project)).toBe('2.3.4'); | ||
| }); | ||
|
|
||
| it('returns null when the version cannot be read', () => { |
There was a problem hiding this comment.
codex review: This still only covers the catch -> null branch through invalid package metadata, not the real optional-peer-absent path where require.resolve('@rspack/core/package.json', { paths: [project] }) throws MODULE_NOT_FOUND. Since optional-peer safety is part of this helper's contract, consider adding a child-process/raw Node test from a temp project with no @rspack/core installed; that avoids Jest's resolver fallback while locking down the actual absence case.
Summary
Second PR of the Rspack 2 support stack split out of #1393 (design doc in #1395). Deliberately minimal — pure utilities, nothing wired up yet:
helpers/rspackVersion.ts:getRspackVersion/getRspackMajorVersion/isRspack2resolve the installed@rspack/coreversion via itspackage.jsonwithout importing the package — safe on any Node version (@rspack/core@2is ESM-only and cannot berequire()d on Node < 20.19) and safe when rspack isn't installed (webpack-only projects).getRspackMajorVersionFromCompilercovers plugin contexts viacompiler.webpack.rspackVersion.ConfigKeysadditions (cache,experiments) incommands/types.ts— type-only; describes config keys the commands already read.No behavior change, no dependency changes, no changeset. Consumers arrive with the follow-up PRs:
ERR_REQUIRE_ESM)@rspack/core@^2devDep + type fallout + dual-major jest lane + CI lanes (Rspack 1 + Windows)Everything here was previously reviewed as part of #1393; the branch there stays as the reference implementation until the stack lands.
Verification
turbo run typecheck test --force— 17/17 tasks green (repack 280/280)biome check— clean