Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove public directory from hosting emulator for frameworks #6674

Merged
merged 10 commits into from
Jan 23, 2024
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
- Add force flag to delete backend (#6635).
- Use framework build target in Vite builds (#6643).
- Use framework build target in NODE_ENV for production Vite builds (#6644)
- Let framework handle public directory with emulator. (#6674)
2 changes: 1 addition & 1 deletion src/frameworks/angular/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,19 @@

export const supportedRange = "14 - 17";

export async function discover(dir: string): Promise<Discovery | undefined> {

Check warning on line 41 in src/frameworks/angular/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Missing JSDoc comment
if (!(await pathExists(join(dir, "package.json")))) return;
if (!(await pathExists(join(dir, "angular.json")))) return;
const version = getAngularVersion(dir);
return { mayWantBackend: true, publicDirectory: join(dir, "src", "assets"), version };
return { mayWantBackend: true, version };
}

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

Check warning on line 48 in src/frameworks/angular/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Missing return type on function

Check warning on line 48 in src/frameworks/angular/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Missing JSDoc comment

Check warning on line 48 in src/frameworks/angular/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type

Check warning on line 48 in src/frameworks/angular/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type
execSync(
`npx --yes -p @angular/cli@"${supportedRange}" ng new ${setup.projectId} --directory ${setup.hosting.source} --skip-git`,

Check warning on line 50 in src/frameworks/angular/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Invalid type "any" of template literal expression

Check warning on line 50 in src/frameworks/angular/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .projectId on an `any` value

Check warning on line 50 in src/frameworks/angular/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Invalid type "any" of template literal expression

Check warning on line 50 in src/frameworks/angular/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .hosting on an `any` value
{
stdio: "inherit",
cwd: config.projectDir,

Check warning on line 53 in src/frameworks/angular/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe assignment of an `any` value
}
);
return Promise.resolve();
Expand Down
3 changes: 1 addition & 2 deletions src/frameworks/astro/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ export async function discover(dir: string): Promise<Discovery | undefined> {
if (!existsSync(join(dir, "package.json"))) return;
const version = getAstroVersion(dir);
if (!version) return;
const { output, publicDir: publicDirectory } = await getConfig(dir);
const { output } = await getConfig(dir);
return {
mayWantBackend: output !== "static",
publicDirectory,
version,
};
}
Expand Down
2 changes: 1 addition & 1 deletion src/frameworks/flutter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export async function discover(dir: string): Promise<Discovery | undefined> {
const pubSpec = loadYaml(pubSpecBuffer.toString());
const usingFlutter = pubSpec.dependencies?.flutter;
if (!usingFlutter) return;
return { mayWantBackend: false, publicDirectory: join(dir, "web") };
return { mayWantBackend: false };
}

export function init(setup: any, config: any) {
Expand Down
5 changes: 2 additions & 3 deletions src/frameworks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ export async function prepareFrameworks(
)
);
}
const { framework, mayWantBackend, publicDirectory } = results;
const { framework, mayWantBackend } = results;
const {
build,
ɵcodegenPublicDirectory,
Expand Down Expand Up @@ -304,7 +304,6 @@ export async function prepareFrameworks(
getDevModeHandle &&
(await getDevModeHandle(getProjectPath(), frameworksBuildTarget, hostingEmulatorInfo));
if (devModeHandle) {
config.public = relative(projectRoot, publicDirectory);
// Attach the handle to options, it will be used when spinning up superstatic
options.frameworksDevModeHandle = devModeHandle;
// null is the dev-mode entry for firebase-framework-tools
Expand Down Expand Up @@ -339,10 +338,10 @@ export async function prepareFrameworks(
site,
});

config.public = relative(projectRoot, hostingDist);
if (wantsBackend && !omitCloudFunction)
codegenFunctionsDirectory = codegenProdModeFunctionsDirectory;
}
config.public = relative(projectRoot, hostingDist);
config.webFramework = `${framework}${codegenFunctionsDirectory ? "_ssr" : ""}`;
if (codegenFunctionsDirectory) {
if (firebaseDefaults) {
Expand Down
1 change: 0 additions & 1 deletion src/frameworks/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export const enum SupportLevel {

export interface Discovery {
mayWantBackend: boolean;
publicDirectory: string;
version?: string;
vite?: boolean;
}
Expand Down
7 changes: 2 additions & 5 deletions src/frameworks/nuxt/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,9 @@ export async function discover(dir: string) {
if (!anyConfigFileExists && !version) return;
if (version && lt(version, "3.0.0-0")) return;

const {
dir: { public: publicDirectory },
ssr: mayWantBackend,
} = await getConfig(dir);
const { ssr: mayWantBackend } = await getConfig(dir);

return { publicDirectory, mayWantBackend, version };
return { mayWantBackend, version };
}

export async function build(cwd: string) {
Expand Down
3 changes: 1 addition & 2 deletions src/frameworks/nuxt2/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ export async function discover(rootDir: string) {
if (!(await pathExists(join(rootDir, "package.json")))) return;
const version = getNuxtVersion(rootDir);
if (!version || (version && gte(version, "3.0.0-0"))) return;
const { app } = await getAndLoadNuxt({ rootDir, for: "build" });
return { mayWantBackend: true, publicDirectory: app.options.dir.static, version };
return { mayWantBackend: true, version };
}

/**
Expand Down
2 changes: 0 additions & 2 deletions src/test/frameworks/angular/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import * as sinon from "sinon";
import * as fsExtra from "fs-extra";

import { discover } from "../../../frameworks/angular";
import { join } from "path";

describe("Angular", () => {
describe("discovery", () => {
Expand All @@ -22,7 +21,6 @@ describe("Angular", () => {
sandbox.stub(fsExtra, "pathExists").resolves(true);
expect(await discover(cwd)).to.deep.equal({
mayWantBackend: true,
publicDirectory: join(cwd, "src", "assets"),
version: undefined,
});
});
Expand Down
2 changes: 0 additions & 2 deletions src/test/frameworks/astro/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ describe("Astro", () => {
});
expect(await discover(cwd)).to.deep.equal({
mayWantBackend: false,
publicDirectory: publicDir,
version: "2.2.2",
});
});
Expand Down Expand Up @@ -84,7 +83,6 @@ describe("Astro", () => {
});
expect(await discover(cwd)).to.deep.equal({
mayWantBackend: true,
publicDirectory: publicDir,
version: "2.2.2",
});
});
Expand Down
1 change: 0 additions & 1 deletion src/test/frameworks/flutter/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ describe("Flutter", () => {
);
expect(await discover(cwd)).to.deep.equal({
mayWantBackend: false,
publicDirectory: "web",
});
});

Expand Down
2 changes: 0 additions & 2 deletions src/test/frameworks/nuxt/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ describe("Nuxt 2 utils", () => {

expect(await discoverNuxt2(discoverNuxtDir)).to.deep.equal({
mayWantBackend: true,
publicDirectory: "static",
version: "2.15.8",
});
});
Expand Down Expand Up @@ -75,7 +74,6 @@ describe("Nuxt 2 utils", () => {

expect(await discoverNuxt3(discoverNuxtDir)).to.deep.equal({
mayWantBackend: true,
publicDirectory: "public",
version: "3.0.0",
});
});
Expand Down