Repository navigation
fix: do not inline the package version when bundling - #16422
Conversation
Webpack inlined `require('../package.json')` into each bundle. Releases
build first and bump `package.json` afterwards, so the shipped bundles
carried the previous version: `jest --version` printed 30.5.0 on 30.5.1,
and `jest-haste-map`/`@jest/transform` built their cache keys from a
stale version too. `webpackIgnore` does not apply to CommonJS `require`,
so mark the request external instead - the bundle is emitted to
`<packageDir>/build`, one level under the file it needs.
Regressed in jestjs#12348, which moved the build to webpack.
β Deploy Preview for jestjs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
π’ Approval recommended
The change is narrowly scoped to webpack externals handling for package.json and aligns with the stated release/build behavior without introducing API or runtime behavior beyond correcting version resolution.
Pull request overview
This PR fixes a regression introduced by webpack bundling where require('../package.json') gets inlined into package bundles, causing jest --version, --debug, and cache key versioning (e.g. in jest-haste-map and @jest/transform) to report the previous release version after Lerna bumps package.json post-build.
Changes:
- Updates the webpack build config to treat each packageβs
package.jsonas a CommonJS external (restoring a runtimerequire). - Adds a changelog entry documenting the fix across the affected packages.
File summaries
| File | Description |
|---|---|
| scripts/buildUtils.mjs | Adds a webpack externals handler to keep <packageDir>/package.json runtime-required instead of bundled/inlined. |
| CHANGELOG.md | Documents the fix under ## main for jest-core, jest-haste-map, and jest-transform. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 0
- Review effort level: Lite
π‘ Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
babel-jest
babel-plugin-jest-hoist
babel-preset-jest
create-jest
@jest/diff-sequences
expect
@jest/expect-utils
jest
jest-changed-files
jest-circus
jest-cli
jest-config
@jest/console
@jest/core
@jest/create-cache-key-function
jest-diff
jest-docblock
jest-each
@jest/environment
jest-environment-jsdom
@jest/environment-jsdom-abstract
jest-environment-node
@jest/expect
@jest/fake-timers
@jest/get-type
@jest/globals
jest-haste-map
jest-jasmine2
jest-leak-detector
jest-matcher-utils
jest-message-util
jest-mock
@jest/pattern
jest-phabricator
jest-regex-util
@jest/reporters
jest-resolve
jest-resolve-dependencies
jest-runner
jest-runtime
@jest/schemas
jest-snapshot
@jest/snapshot-utils
@jest/source-map
@jest/test-result
@jest/test-sequencer
@jest/transform
@jest/types
jest-util
jest-validate
jest-watcher
jest-worker
pretty-format
commit: |
|
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Summary
Fixes #16420.
Webpack inlines
require('../package.json')into each bundle. A release builds first and lets Lerna bump everypackage.jsonafterwards, so the published bundles carry the version from before the bump β@jest/core@30.5.1ships"version":"30.5.0"in itsbuild/index.js, and30.2.0ships30.1.3.jest --versionand--debugprint that stale value.jest-haste-mapand@jest/transformread the same constant into their cache keys, so those are labelled one release behind too.29.7.0 was unaffected: that build emitted one file per module with a real runtime
require. It regressed in #12348, which moved the build to webpack.Marking the request external restores the runtime
require.webpackIgnoreis not an option β webpack honours it onimport()andnew URL(), not on CommonJSrequire; with the magic comment in place the output still reads__webpack_require__(/* webpackIgnore: true */"./package.json")and the JSON is still emitted as a module.The external path is relative to the bundle rather than to the importing source file, so
logDebugMessages.tsasking for../../package.jsonfromsrc/liblands in the same place asversion.tsasking for../package.json. No source changes needed.Test plan
After
yarn build:js, no"version":"30.x.y"literal is left in thejest-core,jest-transformorjest-haste-mapbundles, and each containsmodule.exports = require("../package.json").Editing
packages/jest-core/package.jsonto99.9.9after building, then runningnode packages/jest-cli/bin/jest.js --version, prints99.9.9-devβ the built output reads the file at run time.grep -rln 'require("../package.json")' packages/*/build/matches only the three flatbuild/index.jsfiles. The external assumes a chunk atbuild/*.js; the one nested entry in the build,jest-jasmine2'sjasmine/jasmineLight.js, does not touchpackage.json.