Skip to content

Commit

Permalink
fix: add timeouts to npm commands
Browse files Browse the repository at this point in the history
To prevent slow startups if no network is available
  • Loading branch information
stfsy authored Oct 1, 2022
1 parent 9e524c1 commit c957c6d
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/deploy/functions/runtimes/node/versioning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ interface NpmShowResult {
}

const MIN_SDK_VERSION = "2.0.0";
const NPM_COMMAND_TIMEOUT_MILLIES = 3000;

export const FUNCTIONS_SDK_VERSION_TOO_OLD_WARNING =
clc.bold(clc.yellow("functions: ")) +
Expand All @@ -45,6 +46,7 @@ export function getFunctionsSDKVersion(sourceDir: string): string | void {
const child = spawn.sync("npm", ["list", "firebase-functions", "--json=true"], {
cwd: sourceDir,
encoding: "utf8",
timeout: NPM_COMMAND_TIMEOUT_MILLIES,
});
if (child.error) {
logger.debug("getFunctionsSDKVersion encountered error:", child.error.stack);
Expand All @@ -61,6 +63,7 @@ export function getFunctionsSDKVersion(sourceDir: string): string | void {
export function getLatestSDKVersion(): string | undefined {
const child = spawn.sync("npm", ["show", "firebase-functions", "--json=true"], {
encoding: "utf8",
timeout: NPM_COMMAND_TIMEOUT_MILLIES,
});
if (child.error) {
logger.debug(
Expand Down

0 comments on commit c957c6d

Please sign in to comment.