fix: stop publishing the package's Babel config to consumers - #835
Open
PsukheDelos wants to merge 1 commit into
Open
fix: stop publishing the package's Babel config to consumers#835PsukheDelos wants to merge 1 commit into
PsukheDelos wants to merge 1 commit into
Conversation
`package.json#babel` is a file-relative Babel config that only exists to compile this repo's own sources for `jest`. Because `package.json` is always included in the npm tarball, that config ships to every consumer and is picked up by their Babel/Metro resolution — under Expo/EAS it clashes with `babel-preset-expo` and fails the build with a config conflict. Move it to `babel.config.js`, which is not in the `files` whitelist and so is never published. Test behaviour is unchanged (the presets and plugins are moved verbatim); consumers now get only the project's own Babel config.
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.
Problem
package.jsoncarries ababelkey:That config exists purely to compile this repo's own
src/forjest -i. It has no purpose for consumers — the package publishes untranspiled source ("main": "src/index.js"), so consumers compile it with their own Babel setup.But
package.jsonis always included in the npm tarball, so this file-relative Babel config ships to every install and lands atnode_modules/react-native-nfc-manager/package.json, where consumer tooling can pick it up. In Expo/EAS builds it collides withbabel-preset-expoand the build fails with a Babel config conflict.Downstream projects are currently working around this with
patch-package— stripping thebabelkey from the installedpackage.json. We've been carrying such a patch for a while, and it seemed better to fix it at the source than to keep re-cutting the patch on every release.Fix
Move the config verbatim into
babel.config.js.babel.config.jsisn't in thefileswhitelist, so it's never published — confirmed withnpm pack --dry-run:package.json(withbabelkey)babelkeybabel.config.jsPresets and plugins are unchanged, so the local build/test behaviour is identical.
babel.config.jsis a root config rather than a file-relative one, which is the correct form for "compile this project" and is whatbabel-jestresolves from the repo root.Verification
Run against
mainbefore and after:npx jest -i— 3 suites, 20 tests, passing both before and after.npx eslint .— clean.npm pack --dry-run—babel.config.jsabsent from the tarball, as above.Note (not included here)
@babel/plugin-proposal-class-propertieshas been deprecated in favour of@babel/plugin-transform-class-propertiessince Babel 7.22, and@babel/preset-envhas bundled the class-fields transform since 7.14 — so the explicit plugin is likely redundant now. I left it alone deliberately: renaming or dropping it means regeneratingpackage-lock.json, and against a lockfile this age that produces a few hundred lines of unrelated transitive drift. Happy to send that as a separate PR if you'd like it.