diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ab5470c78f..b8b54f4af7f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1 +1,2 @@ -Adds (opt-out) experiment to disable cleaning up containers after a functions deploy (#6861) +- Adds (opt-out) experiment to disable cleaning up containers after a functions deploy (#6861) +- Fix Next.js image optimization check in app directory for Windows (#6930) diff --git a/src/frameworks/next/utils.ts b/src/frameworks/next/utils.ts index de61137a9e3..e8711c122fe 100644 --- a/src/frameworks/next/utils.ts +++ b/src/frameworks/next/utils.ts @@ -1,6 +1,6 @@ import { existsSync } from "fs"; import { pathExists } from "fs-extra"; -import { basename, extname, join, posix } from "path"; +import { basename, extname, join, posix, sep } from "path"; import { readFile } from "fs/promises"; import { sync as globSync } from "glob"; import type { PagesManifest } from "next/dist/build/webpack/plugins/pages-manifest-plugin"; @@ -31,6 +31,7 @@ import { WEBPACK_LAYERS, } from "./constants"; import { dirExistsSync, fileExistsSync } from "../../fsutils"; +import { IS_WINDOWS } from "../../utils"; export const I18N_SOURCE = /\/:nextInternalLocale(\([^\)]+\))?/; @@ -247,15 +248,21 @@ export async function isUsingNextImageInAppDirectory( projectDir: string, nextDir: string, ): Promise { + const nextImagePath = ["node_modules", "next", "dist", "client", "image"]; + const nextImageString = IS_WINDOWS + ? // Note: Windows requires double backslashes to match Next.js generated file + nextImagePath.join(sep + sep) + : join(...nextImagePath); + const files = globSync( join(projectDir, nextDir, "server", "**", "*client-reference-manifest.js"), ); for (const filepath of files) { - const fileContents = await readFile(filepath); + const fileContents = await readFile(filepath, "utf-8"); // Return true when the first file containing the next/image component is found - if (fileContents.includes("node_modules/next/dist/client/image")) { + if (fileContents.includes(nextImageString)) { return true; } } diff --git a/src/utils.ts b/src/utils.ts index b2b75ce2151..5fb40c9da52 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -21,7 +21,7 @@ import { FirebaseError } from "./error"; import { logger, LogLevel } from "./logger"; import { LogDataOrUndefined } from "./emulator/loggingEmulator"; -const IS_WINDOWS = process.platform === "win32"; +export const IS_WINDOWS = process.platform === "win32"; const SUCCESS_CHAR = IS_WINDOWS ? "+" : "✔"; const WARNING_CHAR = IS_WINDOWS ? "!" : "⚠"; const ERROR_CHAR = IS_WINDOWS ? "!!" : "⬢";