Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Suppress SSR warning for non-SSR Angular projects on init hosting (#10364)
53 changes: 50 additions & 3 deletions src/frameworks/angular/index.spec.ts
Original file line number Diff line number Diff line change
@@ -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;
});
Comment thread
swseverance marked this conversation as resolved.
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",
});
});
});
});
7 changes: 6 additions & 1 deletion src/frameworks/angular/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@ export async function discover(dir: string): Promise<Discovery | undefined> {
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) {
Expand Down