feat: Upgrade @rspack/core to v2 and fix breaking changes#419
Draft
yoannmoinet wants to merge 1 commit into
Draft
feat: Upgrade @rspack/core to v2 and fix breaking changes#419yoannmoinet wants to merge 1 commit into
yoannmoinet wants to merge 1 commit into
Conversation
Fixes #418 - widen rspack peer dependency to support v2. Breaking changes addressed: - Remove `experiments.css: true` from bundler config (removed in rspack v2; CSS processing is now always available) - Add explicit CSS module rule `{ test: /\.css$/, type: 'css' }` required in rspack v2 for CSS imports to work Jest ESM compatibility fix: - @rspack/core v2 is pure ESM ("type": "module"), which causes Jest's CJS runtime to throw ERR_REQUIRE_ESM when --experimental-vm-modules is active - Add a custom Jest resolver (rspack-jest-resolver.cjs) that maps @rspack/core to a .cjs shim file - The .cjs shim uses createRequire() (Node's native, non-Jest-intercepted loader) to load the real rspack, bypassing Jest's module interception while preserving Node 20.17+'s require(esm) support Changes: - packages/tests/package.json: @rspack/core 1.4.9 -> 2.0.8 - packages/tools/package.json: @rspack/core 1.4.9 -> 2.0.8 - packages/tools/src/bundlers.ts: remove experiments.css, add CSS rule - packages/published/rspack-plugin/package.json: peerDep 1.x -> 1.x || 2.x - packages/tests/jest.config.ts: add custom resolver for @rspack/core - packages/tests/src/_jest/rspack-jest-resolver.cjs: custom Jest resolver - packages/tests/src/_jest/rspack-cjs-shim.cjs: CJS shim for rspack v2
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What and why?
Fixes #418.
@datadog/rspack-pluginpeer dependency from"1.x"to"1.x || 2.x"so users on rspack v2 are no longer blocked.@rspack/coredev/test dependency from1.4.9→2.0.8.How?
Rspack v2 breaking changes addressed:
experiments.cssremoved — rspack v2 dropped this option (CSS support is now always on). Removed it fromconfigXpack()inpackages/tools/src/bundlers.ts; leaving it in caused rspack to throw on unknown config.{ test: /\.css$/, type: 'css' }inmodule.rulesfor CSS imports to be processed. Added it alongside the existingts-loaderrule so theeasy_project_with_cssfixture tests continue to work.Jest ESM compatibility:
@rspack/corev2 ships as a pure ESM package ("type": "module"). The test suite runs Jest with--experimental-vm-modules, which causes Jest'sshouldLoadAsEsm()to returntruefor any package with"type": "module"— makingrequire('@rspack/core')throwERR_REQUIRE_ESMbefore the transformer ever runs.Fix: added a custom Jest resolver (
rspack-jest-resolver.cjs) that interceptsrequire('@rspack/core')and redirects it to a.cjsshim (rspack-cjs-shim.cjs). Two properties make this work:.cjsextension causesshouldLoadAsEsm()to returnfalseunconditionally, bypassing Jest's ESM guard.createRequire()fromnode:moduleis used instead of the module's ownrequire.createRequire()is not patched by Jest and uses Node's native loader, which supportsrequire(esm)natively on Node ≥ 20.17.No test logic was changed; all pre-existing failures (macOS
fsmonitor--daemon.ipcsocket-copy errors in git integration tests) are unrelated to this PR and reproduce identically with the webpack bundler.