From e091b2af7f9c7e0120bbe673a753609d896c3a38 Mon Sep 17 00:00:00 2001 From: Christina Holland Date: Wed, 5 Jul 2023 10:12:58 -0700 Subject: [PATCH] Frameworks: Call "next build" from command line instead of import (#6066) --- firebase-vscode/package-lock.json | 4 ++-- firebase-vscode/package.json | 11 ++++------- src/frameworks/next/index.ts | 21 ++++++++++++++------- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/firebase-vscode/package-lock.json b/firebase-vscode/package-lock.json index ef2240a2da3..ccbdb5e7b61 100644 --- a/firebase-vscode/package-lock.json +++ b/firebase-vscode/package-lock.json @@ -1,12 +1,12 @@ { "name": "firebase-vscode", - "version": "0.0.23-alpha.1", + "version": "0.0.23-alpha.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "firebase-vscode", - "version": "0.0.23-alpha.1", + "version": "0.0.23-alpha.2", "dependencies": { "@vscode/codicons": "0.0.30", "@vscode/webview-ui-toolkit": "^1.2.1", diff --git a/firebase-vscode/package.json b/firebase-vscode/package.json index 1eae05edc62..e18acd3939c 100644 --- a/firebase-vscode/package.json +++ b/firebase-vscode/package.json @@ -3,7 +3,7 @@ "displayName": "firebase-vscode", "publisher": "firebase", "description": "VSCode Extension for Firebase", - "version": "0.0.23-alpha.1", + "version": "0.0.23-alpha.2", "engines": { "vscode": "^1.69.0" }, @@ -22,12 +22,12 @@ "properties": { "firebase.debug": { "type": "boolean", - "default": true, + "default": false, "description": "Enable writing debug-level messages to the file provided in firebase.debugLogPath (requires restart)" }, "firebase.debugLogPath": { "type": "string", - "default": "/tmp/firebase-plugin.log", + "default": "", "description": "If firebase.debug is true, appends debug-level messages to the provided file (requires restart)" }, "firebase.npmPath": { @@ -133,8 +133,5 @@ "webpack": "^5.75.0", "webpack-cli": "^5.0.1", "webpack-merge": "^5.8.0" - }, - "extensionDependencies": [ - "google.monospace" - ] + } } \ No newline at end of file diff --git a/src/frameworks/next/index.ts b/src/frameworks/next/index.ts index e64ae4865d1..df3fb97f9de 100644 --- a/src/frameworks/next/index.ts +++ b/src/frameworks/next/index.ts @@ -28,6 +28,7 @@ import { relativeRequire, findDependency, validateLocales, + getNodeModuleBin, } from "../utils"; import { BuildResult, FrameworkType, SupportLevel } from "../interfaces"; @@ -101,8 +102,6 @@ export async function discover(dir: string) { * Build a next.js application. */ export async function build(dir: string): Promise { - const { default: nextBuild } = relativeRequire(dir, "next/dist/build"); - await warnIfCustomBuildScript(dir, name, DEFAULT_BUILD_SCRIPT); const reactVersion = getReactVersion(dir); @@ -111,12 +110,20 @@ export async function build(dir: string): Promise { process.env.__NEXT_REACT_ROOT = "true"; } - await nextBuild(dir, null, false, false, true).catch((e) => { - // Err on the side of displaying this error, since this is likely a bug in - // the developer's code that we want to display immediately - console.error(e.message); - throw e; + const cli = getNodeModuleBin("next", dir); + + const nextBuild = new Promise((resolve, reject) => { + const buildProcess = spawn(cli, ["build"], { cwd: dir }); + buildProcess.stdout?.on("data", (data) => logger.info(data.toString())); + buildProcess.stderr?.on("data", (data) => logger.info(data.toString())); + buildProcess.on("error", (err) => { + reject(new FirebaseError(`Unable to build your Next.js app: ${err}`)); + }); + buildProcess.on("exit", (code) => { + resolve(code); + }); }); + await nextBuild; const reasonsForBackend = new Set(); const { distDir, trailingSlash, basePath: baseUrl } = await getConfig(dir);