fix(packaging): mark entry-specific peers optional so subpath consumers are not forced to install them - #26
Merged
Merged
Conversation
…ot forced to install them npm 7+ auto-installs non-optional peerDependencies, so every package listed there ends up in each consumer's lockfile whether or not the consumer imports the entry point that needs it. A consumer that only uses the ./announcements subpath (react + lucide-react + react-markdown + remark-gfm) was still being handed the data-table and drag-and-drop stack, and its `npm ci` failed in CI with "Missing: @dnd-kit/core@6.3.1 from lock file" (and five more) whenever the lockfile had been generated on a machine with legacy-peer-deps=true, which skips peer auto-install. Move @dnd-kit/core, @dnd-kit/sortable, @dnd-kit/utilities, @tanstack/react-table and @tanstack/react-query into peerDependenciesMeta as optional, following the precedent already set for recharts (./analytics only). The peerDependencies entries stay, so the supported version ranges are still declared; only the auto-install obligation is dropped. react and react-dom remain required. @tanstack/react-query is included because no entry point imports it at all -- it is not reachable from any bundle, yet it was being installed into every consumer. The root-barrel consumers (sphere, sphere-dev-portal, sphere-backoffice) each already declare all four as their own direct dependencies, so nothing changes for them.
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
sphere-quest-frontendCI fails onnpm ci:Mechanism
npm 7+ auto-installs non-optional
peerDependencies. Everything listed there is therefore expected in every consumer's lockfile, whether or not that consumer imports the entry point that needs it. The lockfile in question was generated on a machine withlegacy-peer-deps=trueset globally, which skips peer auto-install; CI has no such setting, sonpm cifinds the tree out of sync and refuses.That app imports only
@unicitylabs/sphere-ui/announcements— the subpath added in 0.1.39, whose bundle imports nothing butreact,lucide-react,react-markdownandremark-gfm. Forcing it to declare a data-table and a drag-and-drop stack it never loads would defeat the purpose of that subpath existing.Fix
Move the entry-specific peers into
peerDependenciesMetaasoptional: true, following the precedent this library already sets forrecharts(needed only by./analytics):@tanstack/react-tableDataTable)@dnd-kit/core,@dnd-kit/sortable./hooks@dnd-kit/utilitiesMediaGallery)@tanstack/react-queryThe
peerDependenciesentries themselves are unchanged, so the supported version ranges are still declared; only the auto-install obligation is dropped.reactandreact-domstay required.@tanstack/react-queryIncluded, because it is not merely entry-specific — no entry point imports it at all.
git grep react-querymatches onlypackage.json, the tsupexternallist and the README; zero source files. It was nevertheless being installed into every consumer. The verification below shows npm pulling@tanstack/react-query@5.101.4and@tanstack/query-coreinto a consumer that wants neither. It did not appear in the reported error only becausesphere-quest-frontendhappens to declare react-query as a direct dependency itself.I left the
peerDependenciesentry in place rather than deleting it, so the ^5 range still documents what to pair with these components if an app uses both.Verification
Not just a green build here — a green build proves nothing about a consumer's install.
npm packed this branch and installed the tarball into a throwaway consumer whosepackage.jsonlists only the tarball,reactandreact-dom. Control = published0.1.39from the registry, identical steps.Control (published 0.1.39) —
npm install --legacy-peer-deps=falsedrags in 8 unwanted packages:and with the lockfile generated the way the dev machine does it (
--legacy-peer-deps=true),npm ci --dry-run --legacy-peer-deps=falsereproduces the reported CI failure exactly:This branch — same consumer, same commands:
npm install --legacy-peer-deps=false→ exit 0npm ci --dry-run --legacy-peer-deps=false→ exit 0node_modules/@dnd-kit→ absent,node_modules/@tanstack→ absent,recharts→ absent@dnd-kit/@tanstack→ 0 (the only textual mentions are this package's ownpeerDependencies/peerDependenciesMetametadata, which npm always mirrors into the lockfile)import('@unicitylabs/sphere-ui/announcements')resolves and returns all 11 exports with none of the optional peers installedAnd the actual failing CI scenario — lockfile built with
--legacy-peer-deps=true, thennpm ci --dry-run --legacy-peer-deps=false— now exits 0.npm run test:run(168 tests, 23 files),npm run typecheckandnpm run buildall pass.npm run lintis broken in this repo (eslint not installed, no config) — pre-existing, untouched.Impact on root-barrel consumers
sphere,sphere-dev-portalandsphere-backofficeimport from the package root, which genuinely needs the table and dnd packages. Checked eachpackage.json: all three already declare all four as their own direct dependencies, so dropping the auto-install changes nothing for them.@dnd-kit/core@dnd-kit/sortable@dnd-kit/utilities@tanstack/react-tablespheresphere-dev-portalsphere-backofficeThe trade-off is real but already paid for: an app that uses the root barrel without declaring these now gets a build error instead of a silent auto-install. None of the three is in that position.
Notes
workflow_dispatch.versionis left at0.1.39.sphere-quest-frontendis untouched; its lockfile gets regenerated once this is published.@dnd-kit/utilitiesandrecharts, listed the wrongsortablerange, and listedlucide-reactas a peer when it is a regular dependency).