Repository navigation
fix(npm): declare dependencies that were only available through hoisting - #12469
sebdanielsson wants to merge 1 commit into
Conversation
The published types of plugin-npm import react and @backstage/filter-predicates, but the package declares neither @types/react nor @backstage/filter-predicates. It also didn't forward the react-dom and react-router-dom peers that its Backstage dependencies require. Strict installs (pnpm, Yarn's pnpm linker, PnP) can't resolve undeclared packages. Also declare @types/react and @types/luxon as dev dependencies, since the source uses them. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01NZ521AzxwB3vLPS9t6fABT Signed-off-by: Sebastian Danielsson <[email protected]>
Changed Packages
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #12469 +/- ##
===========================================
- Coverage 85.92% 25.37% -60.55%
===========================================
Files 265 25 -240
Lines 9159 331 -8828
Branches 2239 90 -2149
===========================================
- Hits 7870 84 -7786
+ Misses 1279 247 -1032
+ Partials 10 0 -10
Continue to review full report in Codecov by Harness.
🚀 New features to boost your workflow:
|
|
Hi @sebdanielsson, thanks for this PR. It's a draft or should I take a look already? :) |
Hi! It's ready for review. It's a draft only because I reached my open PR limit for this repo. When you're happy with the PR, or if you have any feedback, feel free to ping me and I'll fix it. I can mark another PR as draft and mark this as ready for review as soon as you're happy to merge😃 |
| | Name | Location | Severity | | ||
| | :--------------------------- | :---------------- | :------- | | ||
| | @backstage/filter-predicates | package.json:54:6 | error | | ||
|
|
There was a problem hiding this comment.
Hmm, is there no other way? Because the npm plugin doesn't use FilterPredicate at all. It just appears in the transitive type definitions.. I'm just worried that the next person would remove the unused dependency then again... 🤔
There was a problem hiding this comment.
I don't think there's a way around it that works without hoisting😕 The plugin doesn't use FilterPredicate itself, but it's part of its public types: the cards come from EntityCardBlueprint, so the filter param and config in dist/alpha.d.ts import it from @backstage/filter-predicates. The published 1.30.0 already has that import without the dependency. With pnpm, or anything else that doesn't hoist, a package only sees what it declares, so for anyone using the plugin that import doesn't resolve and the types turn into any (or an error without skipLibCheck). Building the types in a strict layout fails too, with TS2742.
I also tried whether a re-export from @backstage/plugin-catalog-react would let TypeScript go through a dependency we already have. It does in a strict layout, but with the hoisted layout this repo builds with, TypeScript still writes the import from @backstage/filter-predicates.
You're right that nothing here stops someone from removing it again. Backstage has the same thing: plugins/app, core-compat-api and frontend-test-utils declare it only for their types, and it shows up as unused in their knip reports too. Knip only reads the source, not the generated types.
There was a problem hiding this comment.
Thanks for spending the time also to explain it's part of backstage. It's very cool that you spend time to apply this to many packages.
I'm fine to merge it but I'm really worried that this was "cleaned up" (for any plugin) again and again.
Is there an upstream issue to discuss this? Maybe it's a learning that extracting types doesn't work as good as expected?
There was a problem hiding this comment.
I also tried whether a re-export from @backstage/plugin-catalog-react would let TypeScript go through a dependency we already have. It does in a strict layout, but with the hoisted layout this repo builds with, TypeScript still writes the import from @backstage/filter-predicates.
That would be now my ask, couldn't a proper re-export resolve that issue. 🤔
Hey, I just made a Pull Request!
Strict installs (pnpm, Yarn PnP) only resolve declared dependencies, and
plugin-npmuses some it doesn't declare.@types/reactas an optional peer, since the published types importreact. Add thereact-domandreact-router-dompeers that@backstage/core-componentsneeds.@backstage/filter-predicates, whichdist/alpha.d.tsimports. Knip lists it as unused, since only the generated types use it.✔️ Checklist
Signed-off-byline in the message. (more info)🤖 Generated with Claude Code
https://claude.ai/code/session_01NZ5217H8AkdKkDBNzEiTik