Repository navigation
fix: detect @angular/platform-server to determine if Angular project uses SSR - #10430
Conversation
…uses SSR Previously, Angular's discover() always returned mayWantBackend: true, causing the SSR warning to appear even for SPA-only Angular projects. Now checks for the presence of @angular/platform-server in installed dependencies. Resolves #10362
There was a problem hiding this comment.
Code Review
This pull request updates the Angular framework discovery logic to correctly identify if a project uses Server-Side Rendering (SSR). It replaces the hardcoded mayWantBackend: true with a check for the @angular/platform-server dependency, which helps suppress unnecessary SSR warnings for non-SSR projects. Comprehensive unit tests were added to verify discovery behavior for various project configurations, including missing configuration files and projects with or without SSR. A review comment suggests also checking for @angular/ssr to support modern Angular versions and notes potential performance implications of multiple dependency lookups.
| const mayWantBackend = !!findDependency("@angular/platform-server", { | ||
| cwd: dir, | ||
| depth: 0, | ||
| omitDev: false, | ||
| }); |
There was a problem hiding this comment.
While @angular/platform-server is the traditional indicator for SSR in Angular, modern projects (v17+) often use @angular/ssr. Although @angular/ssr depends on @angular/platform-server, it is safer to check for both to ensure robust detection in all project configurations.
Additionally, note that calling findDependency multiple times (here and inside getAngularVersion) can be slow as it may spawn multiple npm list processes. If performance becomes an issue, consider a more unified way to check for multiple dependencies in a single pass.
| const mayWantBackend = !!findDependency("@angular/platform-server", { | |
| cwd: dir, | |
| depth: 0, | |
| omitDev: false, | |
| }); | |
| const mayWantBackend = !!(findDependency("@angular/platform-server", { | |
| cwd: dir, | |
| depth: 0, | |
| omitDev: false, | |
| }) || findDependency("@angular/ssr", { | |
| cwd: dir, | |
| depth: 0, | |
| omitDev: false, | |
| })); |
…uses SSR (#10430) * fix: detect @angular/platform-server to determine if Angular project uses SSR Previously, Angular's discover() always returned mayWantBackend: true, causing the SSR warning to appear even for SPA-only Angular projects. Now checks for the presence of @angular/platform-server in installed dependencies. Resolves #10362 * changelog * add more tests --------- Co-authored-by: Sam Severance <[email protected]>
Duplicate of #10364 to allow merging the PR as it was created from a fork.
Quoting @swseverance: