Skip to content

fix(npm): declare dependencies that were only available through hoisting - #12469

Open
sebdanielsson wants to merge 1 commit into
backstage:mainfrom
sebdanielsson:fix/npm-declare-deps
Open

sebdanielsson wants to merge 1 commit into
backstage:mainfrom
sebdanielsson:fix/npm-declare-deps

Conversation

@sebdanielsson

@sebdanielsson sebdanielsson commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Hey, I just made a Pull Request!

Strict installs (pnpm, Yarn PnP) only resolve declared dependencies, and plugin-npm uses some it doesn't declare.

  • Add @types/react as an optional peer, since the published types import react. Add the react-dom and react-router-dom peers that @backstage/core-components needs.
  • Add @backstage/filter-predicates, which dist/alpha.d.ts imports. Knip lists it as unused, since only the generated types use it.

✔️ Checklist

  • A changeset describing the change and affected packages. (more info)
  • Added or updated documentation
  • Tests for new functionality and regression tests for bug fixes
  • Screenshots attached (for UI changes)
  • All your commits have a Signed-off-by line in the message. (more info)

🤖 Generated with Claude Code

https://claude.ai/code/session_01NZ5217H8AkdKkDBNzEiTik

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]>
@backstage-goalie

Copy link
Copy Markdown
Contributor

Changed Packages

Package Name Package Path Changeset Bump Current Version
@backstage-community/plugin-npm workspaces/npm/plugins/npm patch v1.30.0

@codecov

codecov Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 25.37%. Comparing base (f30348d) to head (fb212b5).
⚠️ Report is 97 commits behind head on main.

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     
Flag Coverage Δ
3scale ?
bookmarks ?
keycloak ?
npm 25.37% <ø> (?)
pingidentity ?
rbac ?
scaffolder ?

Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cbd0db3...fb212b5. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@christoph-jerolimov

Copy link
Copy Markdown
Member

Hi @sebdanielsson, thanks for this PR. It's a draft or should I take a look already? :)

@sebdanielsson

Copy link
Copy Markdown
Contributor Author

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😃

@christoph-jerolimov christoph-jerolimov self-assigned this Dec 1, 2026
| Name | Location | Severity |
| :--------------------------- | :---------------- | :------- |
| @backstage/filter-predicates | package.json:54:6 | error |

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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... 🤔

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

/cc @awanlin @vinzscam @schultzp2020

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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. 🤔

@sebdanielsson
sebdanielsson marked this pull request as ready for review December 3, 2026 00:01
@sebdanielsson
sebdanielsson requested a review from 04kash December 3, 2026 00:01

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants