Skip to content

Commit 00a93e2

Browse files
committed
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
1 parent e28281f commit 00a93e2

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

src/frameworks/angular/index.spec.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { expect } from "chai";
22
import * as sinon from "sinon";
33
import * as fsExtra from "fs-extra";
44

5+
import * as frameworkUtils from "../utils";
56
import { discover } from ".";
67

78
describe("Angular", () => {
@@ -17,12 +18,27 @@ describe("Angular", () => {
1718
sandbox.restore();
1819
});
1920

20-
it("should find an Angular app", async () => {
21+
it("should find an Angular app with SSR", async () => {
2122
sandbox.stub(fsExtra, "pathExists").resolves(true);
23+
sandbox.stub(frameworkUtils, "findDependency").callsFake((name) => {
24+
if (name === "@angular/platform-server") {
25+
return { version: "17.0.0", resolved: "", overridden: false };
26+
}
27+
return undefined;
28+
});
2229
expect(await discover(cwd)).to.deep.equal({
2330
mayWantBackend: true,
2431
version: undefined,
2532
});
2633
});
34+
35+
it("should find an Angular app without SSR", async () => {
36+
sandbox.stub(fsExtra, "pathExists").resolves(true);
37+
sandbox.stub(frameworkUtils, "findDependency").returns(undefined);
38+
expect(await discover(cwd)).to.deep.equal({
39+
mayWantBackend: false,
40+
version: undefined,
41+
});
42+
});
2743
});
2844
});

src/frameworks/angular/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,12 @@ export async function discover(dir: string): Promise<Discovery | undefined> {
4242
if (!(await pathExists(join(dir, "package.json")))) return;
4343
if (!(await pathExists(join(dir, "angular.json")))) return;
4444
const version = getAngularVersion(dir);
45-
return { mayWantBackend: true, version };
45+
const mayWantBackend = !!findDependency("@angular/platform-server", {
46+
cwd: dir,
47+
depth: 0,
48+
omitDev: false,
49+
});
50+
return { mayWantBackend, version };
4651
}
4752

4853
export function init(setup: any, config: any) {

0 commit comments

Comments
 (0)