Skip to content

Commit

Permalink
moves esbuild to an optional dependency; requires node 16 for framewo…
Browse files Browse the repository at this point in the history
…rks (#5052)
  • Loading branch information
bkendall authored Sep 30, 2022
1 parent a7d1133 commit 4184ad7
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
6 changes: 5 additions & 1 deletion npm-shrinkwrap.json

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

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@
"cross-env": "^5.1.3",
"cross-spawn": "^7.0.3",
"csv-parse": "^5.0.4",
"esbuild": "^0.15.7",
"exegesis": "^4.1.0",
"exegesis-express": "^4.0.0",
"express": "^4.16.4",
Expand Down Expand Up @@ -235,5 +234,8 @@
"typescript": "^4.5.4",
"typescript-json-schema": "^0.50.1",
"vite": "^3.1.0"
},
"optionalDependencies": {
"esbuild": "^0.15.7"
}
}
11 changes: 11 additions & 0 deletions src/frameworks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { IncomingMessage, ServerResponse } from "http";
import { copyFile, readdir, rm, writeFile } from "fs/promises";
import { mkdirp, pathExists, stat } from "fs-extra";
import * as clc from "colorette";
import * as process from "node:process";
import * as semver from "semver";

import { needProjectId } from "../projectUtils";
import { normalizedHostingConfigs } from "../hosting/normalizedHostingConfigs";
Expand All @@ -18,6 +20,7 @@ import { getCredentialPathAsync } from "../defaultCredentials";
import { getProjectDefaultAccount } from "../auth";
import { formatHost } from "../emulator/functionsEmulatorShared";
import { Constants } from "../emulator/constants";
import { FirebaseError } from "../error";

// Use "true &&"" to keep typescript from compiling this file and rewriting
// the import statement into a require
Expand Down Expand Up @@ -227,6 +230,14 @@ export async function prepareFrameworks(
options: any,
emulators: EmulatorInfo[] = []
) {
// `firebase-frameworks` requires Node >= 16. We must check for this to avoid horrible errors.
const nodeVersion = process.version;
if (!semver.satisfies(nodeVersion, ">=16.0.0")) {
throw new FirebaseError(
`The frameworks awareness feature requires Node.JS >= 16 and npm >= 8 in order to work correctly, due to some of the downstream dependencies. Please upgrade your version of Node.JS, reinstall firebase-tools, and give it another go.`
);
}

const project = needProjectId(context);
const { projectRoot } = options;
const account = getProjectDefaultAccount(projectRoot);
Expand Down
13 changes: 12 additions & 1 deletion src/frameworks/next/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ import {
} from "..";
import { promptOnce } from "../../prompt";
import { gte } from "semver";
import esbuild from "esbuild";
import { IncomingMessage, ServerResponse } from "http";
import { logger } from "../../logger";
import { FirebaseError } from "../../error";

// Next.js's exposed interface is incomplete here
// TODO see if there's a better way to grab this
Expand Down Expand Up @@ -206,6 +207,16 @@ export async function ɵcodegenFunctionsDirectory(sourceDir: string, destDir: st
const packageJsonBuffer = await readFile(join(sourceDir, "package.json"));
const packageJson = JSON.parse(packageJsonBuffer.toString());
if (existsSync(join(sourceDir, "next.config.js"))) {
let esbuild;
try {
esbuild = await import("esbuild");
} catch (e: unknown) {
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
logger.debug(`Failed to load 'esbuild': ${e}`);
throw new FirebaseError(
`Unable to find 'esbuild'. Install it into your local dev dependencies with 'npm i --save-dev esbuild''`
);
}
await esbuild.build({
bundle: true,
external: Object.keys(packageJson.dependencies),
Expand Down

0 comments on commit 4184ad7

Please sign in to comment.