From c957c6dc7d0807d3318459f23da16fb11eb3eb3d Mon Sep 17 00:00:00 2001 From: Stefan Pfaffel Date: Sat, 1 Oct 2022 21:34:53 +0200 Subject: [PATCH] fix: add timeouts to npm commands To prevent slow startups if no network is available --- src/deploy/functions/runtimes/node/versioning.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/deploy/functions/runtimes/node/versioning.ts b/src/deploy/functions/runtimes/node/versioning.ts index 93630ed2d73e..c0898629b832 100644 --- a/src/deploy/functions/runtimes/node/versioning.ts +++ b/src/deploy/functions/runtimes/node/versioning.ts @@ -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: ")) + @@ -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); @@ -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(