fix(deps): exclude @types/* packages from component peer dependencies#10186
fix(deps): exclude @types/* packages from component peer dependencies#10186davidfirst wants to merge 4 commits intomasterfrom
Conversation
When @types/* packages are listed as peers in env.jsonc, they should not be added to components' peer dependencies. The env is installed alongside the component and handles TypeScript compilation, so these type packages are already available without the component needing them directly.
There was a problem hiding this comment.
Pull request overview
This PR fixes an issue where @types/* packages listed as peer dependencies in env.jsonc were incorrectly being added to components' peer dependencies. Since these TypeScript type definition packages are only needed for compilation (handled by the environment), and the env is always installed alongside components, there's no need for components to declare them as their own dependencies.
Changes:
- Added logic to exclude
@types/*packages from component dependencies when they appear in env peer dependencies - Includes comprehensive inline documentation explaining the rationale
scopes/dependencies/dependencies/dependencies-loader/apply-overrides.ts
Outdated
Show resolved
Hide resolved
| // so they're always installed alongside the env. Since @types/* packages are only needed | ||
| // for TypeScript compilation (which the env handles), there's no need for components | ||
| // to have them in their own dependencies. | ||
| if (pkgName.startsWith('@types/')) { |
There was a problem hiding this comment.
The early return at line 654 prevents cleanup of @types/* packages from allDependencies arrays when they exist as component dependencies. This can occur when the iteration order processes 'devDependencies' or 'dependencies' before 'peerDependencies'.
For example, if an @types/* package appears in both env.jsonc devDependencies and peerDependencies:
- First iteration (devDependencies): package is added to allDependencies.devDependencies
- Second iteration (peerDependencies): handlePeerDependencyOverride deletes from allPackagesDependencies but returns early before reaching lines 657-666 which would filter it from allDependencies arrays
To fix this, move the @types/* package filtering logic from allDependencies.dependencies and allDependencies.devDependencies before the early return, similar to lines 657-666 but specifically for @types/* packages.
| if (pkgName.startsWith('@types/')) { | |
| if (pkgName.startsWith('@types/')) { | |
| // Ensure @types/* is removed from all component dependency arrays, even if it was | |
| // previously added as a dependency or devDependency before being seen as a peer. | |
| this.allDependencies.dependencies = this.allDependencies.dependencies.filter( | |
| (dep) => dep.packageName !== pkgName | |
| ); | |
| this.allDependencies.devDependencies = this.allDependencies.devDependencies.filter( | |
| (dep) => dep.packageName !== pkgName | |
| ); | |
| this.allDependencies.peerDependencies = this.allDependencies.peerDependencies.filter( | |
| (dep) => dep.packageName !== pkgName | |
| ); |
|



When
@types/*packages are listed as peers in env.jsonc, they were incorrectly being added to components' peer dependencies.The fix excludes
@types/*packages from component dependencies entirely when they're in the env's peers. This is correct because:@types/*packages are only needed for TypeScript compilation (handled by the env), components don't need them in their own dependencies