diff --git a/CHANGELOG.md b/CHANGELOG.md index e69de29bb2d..f7345e2b405 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -0,0 +1 @@ +- Suppress SSR warning for non-SSR Angular projects on init hosting (#10364) diff --git a/src/frameworks/angular/index.spec.ts b/src/frameworks/angular/index.spec.ts index f3de64863fe..0e9b10f231d 100644 --- a/src/frameworks/angular/index.spec.ts +++ b/src/frameworks/angular/index.spec.ts @@ -1,28 +1,75 @@ import { expect } from "chai"; import * as sinon from "sinon"; import * as fsExtra from "fs-extra"; +import { join } from "path"; +import * as frameworkUtils from "../utils"; import { discover } from "."; describe("Angular", () => { describe("discovery", () => { - const cwd = Math.random().toString(36).split(".")[1]; + const cwd = "."; let sandbox: sinon.SinonSandbox; + let pathExistsStub: sinon.SinonStub; beforeEach(() => { sandbox = sinon.createSandbox(); + pathExistsStub = sandbox.stub(fsExtra, "pathExists"); }); afterEach(() => { sandbox.restore(); }); - it("should find an Angular app", async () => { - sandbox.stub(fsExtra, "pathExists").resolves(true); + it("should not discover if package.json is missing", async () => { + pathExistsStub.resolves(false); + expect(await discover(cwd)).to.be.undefined; + }); + + it("should not discover if angular.json is missing", async () => { + pathExistsStub.withArgs(join(cwd, "package.json")).resolves(true); + pathExistsStub.resolves(false); + expect(await discover(cwd)).to.be.undefined; + }); + + it("should find an Angular app with SSR", async () => { + pathExistsStub.resolves(true); + sandbox.stub(frameworkUtils, "findDependency").callsFake((name) => { + if (name === "@angular/core") { + return { version: "17.0.0", resolved: "", overridden: false }; + } + if (name === "@angular/platform-server") { + return { version: "17.0.0", resolved: "", overridden: false }; + } + return undefined; + }); expect(await discover(cwd)).to.deep.equal({ mayWantBackend: true, + version: "17.0.0", + }); + }); + + it("should find an Angular app without SSR", async () => { + pathExistsStub.resolves(true); + sandbox.stub(frameworkUtils, "findDependency").returns(undefined); + expect(await discover(cwd)).to.deep.equal({ + mayWantBackend: false, version: undefined, }); }); + + it("should propagate the @angular/core version", async () => { + pathExistsStub.resolves(true); + sandbox.stub(frameworkUtils, "findDependency").callsFake((name) => { + if (name === "@angular/core") { + return { version: "18.2.1", resolved: "", overridden: false }; + } + return undefined; + }); + expect(await discover(cwd)).to.deep.equal({ + mayWantBackend: false, + version: "18.2.1", + }); + }); }); }); diff --git a/src/frameworks/angular/index.ts b/src/frameworks/angular/index.ts index 9921119f7d0..60d5ba532cd 100644 --- a/src/frameworks/angular/index.ts +++ b/src/frameworks/angular/index.ts @@ -42,7 +42,12 @@ export async function discover(dir: string): Promise { if (!(await pathExists(join(dir, "package.json")))) return; if (!(await pathExists(join(dir, "angular.json")))) return; const version = getAngularVersion(dir); - return { mayWantBackend: true, version }; + const mayWantBackend = !!findDependency("@angular/platform-server", { + cwd: dir, + depth: 0, + omitDev: false, + }); + return { mayWantBackend, version }; } export function init(setup: any, config: any) {