Skip to content

Commit

Permalink
Frameworks: Call "next build" from command line instead of import (#6066
Browse files Browse the repository at this point in the history
)
  • Loading branch information
hsubox76 committed Jul 5, 2023
1 parent 57dd7fe commit e091b2a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 16 deletions.
4 changes: 2 additions & 2 deletions firebase-vscode/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 4 additions & 7 deletions firebase-vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand All @@ -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": {
Expand Down Expand Up @@ -133,8 +133,5 @@
"webpack": "^5.75.0",
"webpack-cli": "^5.0.1",
"webpack-merge": "^5.8.0"
},
"extensionDependencies": [
"google.monospace"
]
}
}
21 changes: 14 additions & 7 deletions src/frameworks/next/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
relativeRequire,
findDependency,
validateLocales,
getNodeModuleBin,
} from "../utils";
import { BuildResult, FrameworkType, SupportLevel } from "../interfaces";

Expand Down Expand Up @@ -101,8 +102,6 @@ export async function discover(dir: string) {
* Build a next.js application.
*/
export async function build(dir: string): Promise<BuildResult> {
const { default: nextBuild } = relativeRequire(dir, "next/dist/build");

await warnIfCustomBuildScript(dir, name, DEFAULT_BUILD_SCRIPT);

const reactVersion = getReactVersion(dir);
Expand All @@ -111,12 +110,20 @@ export async function build(dir: string): Promise<BuildResult> {
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);
Expand Down

0 comments on commit e091b2a

Please sign in to comment.