Skip to content

Commit

Permalink
Various fixes and improvements. (#5139)
Browse files Browse the repository at this point in the history
* Make web frameworks public (#5136)

* We don't need no public dir (#5142)

* We don't need no public dir

* Add docs

* Add changelog

Co-authored-by: Thomas Bouldin <inlined@users.noreply.github.com>
  • Loading branch information
bkendall and inlined committed Oct 18, 2022
1 parent 31f9b00 commit 8079f7c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
@@ -0,0 +1 @@
Fix a bug where next.js applications would fail to deploy if they did not have a public dir (#5142)
4 changes: 3 additions & 1 deletion src/experiments.ts
Expand Up @@ -81,10 +81,12 @@ export const ALL_EXPERIMENTS = experiments({
shortDescription: "Native support for popular web frameworks",
fullDescription:
"Adds support for popular web frameworks such as Next.js " +
"Nuxt, Netlify, Angular, and Vite-compatible frameworks. Firebase is " +
"Angular, React, Svelte, and Vite-compatible frameworks. Firebase is " +
"committed to support these platforms long-term, but a manual migration " +
"may be required when the non-experimental support for these frameworks " +
"is released",
docsUri: "https://firebase.google.com/docs/hosting/frameworks-overview",
public: true,
},
pintags: {
shortDescription: "Adds the pinTag option to Run and Functions rewrites",
Expand Down
29 changes: 26 additions & 3 deletions src/frameworks/next/index.ts
Expand Up @@ -51,13 +51,19 @@ function getNextVersion(cwd: string) {
return findDependency("next", { cwd, depth: 0, omitDev: false })?.version;
}

/**
* Returns whether this codebase is a Next.js backend.
*/
export async function discover(dir: string) {
if (!(await pathExists(join(dir, "package.json")))) return;
if (!(await pathExists("next.config.js")) && !getNextVersion(dir)) return;
// TODO don't hardcode public dir
return { mayWantBackend: true, publicDirectory: join(dir, "public") };
}

/**
* Build a next.js application.
*/
export async function build(dir: string): Promise<BuildResult> {
const { default: nextBuild } = relativeRequire(dir, "next/dist/build");

Expand Down Expand Up @@ -133,6 +139,9 @@ export async function build(dir: string): Promise<BuildResult> {
return { wantsBackend, headers, redirects, rewrites };
}

/**
* Utility method used during project initialization.
*/
export async function init(setup: any) {
const language = await promptOnce({
type: "list",
Expand All @@ -148,6 +157,9 @@ export async function init(setup: any) {
);
}

/**
* Create a directory for SSG content.
*/
export async function ɵcodegenPublicDirectory(sourceDir: string, destDir: string) {
const { distDir } = await getConfig(sourceDir);
const exportDetailPath = join(sourceDir, distDir, "export-detail.json");
Expand All @@ -157,8 +169,11 @@ export async function ɵcodegenPublicDirectory(sourceDir: string, destDir: strin
if (exportDetailJson?.success) {
copy(exportDetailJson.outDirectory, destDir);
} else {
const publicPath = join(sourceDir, "public");
await mkdir(join(destDir, "_next", "static"), { recursive: true });
await copy(join(sourceDir, "public"), destDir);
if (await pathExists(publicPath)) {
await copy(publicPath, destDir);
}
await copy(join(sourceDir, distDir, "static"), join(destDir, "_next", "static"));

const serverPagesDir = join(sourceDir, distDir, "server", "pages");
Expand Down Expand Up @@ -202,6 +217,9 @@ export async function ɵcodegenPublicDirectory(sourceDir: string, destDir: strin
}
}

/**
* Create a directory for SSR content.
*/
export async function ɵcodegenFunctionsDirectory(sourceDir: string, destDir: string) {
const { distDir } = await getConfig(sourceDir);
const packageJsonBuffer = await readFile(join(sourceDir, "package.json"));
Expand All @@ -227,13 +245,18 @@ export async function ɵcodegenFunctionsDirectory(sourceDir: string, destDir: st
platform: "node",
});
}
await mkdir(join(destDir, "public"));
if (await pathExists(join(sourceDir, "public"))) {
await mkdir(join(destDir, "public"));
await copy(join(sourceDir, "public"), join(destDir, "public"));
}
await mkdirp(join(destDir, distDir));
await copy(join(sourceDir, "public"), join(destDir, "public"));
await copy(join(sourceDir, distDir), join(destDir, distDir));
return { packageJson, frameworksEntry: "next.js" };
}

/**
* Create a dev server.
*/
export async function getDevModeHandle(dir: string) {
const { default: next } = relativeRequire(dir, "next");
const nextApp = next({
Expand Down

0 comments on commit 8079f7c

Please sign in to comment.