diff --git a/src/deploy/functions/release/index.ts b/src/deploy/functions/release/index.ts index e8082f97ef1..46bf286d24a 100644 --- a/src/deploy/functions/release/index.ts +++ b/src/deploy/functions/release/index.ts @@ -17,6 +17,7 @@ import { FirebaseError } from "../../../error"; import { getProjectNumber } from "../../../getProjectNumber"; import { release as extRelease } from "../../extensions"; import * as artifacts from "../../../functions/artifacts"; +import { runtimeIsLanguage } from "../runtimes/supported"; /** Releases new versions of functions and extensions to prod. */ export async function release( @@ -114,6 +115,17 @@ export async function release( const wantBackend = backend.merge(...Object.values(payload.functions).map((p) => p.wantBackend)); printTriggerUrls(wantBackend, projectNumber); + // TODO: Remove once the Firebase console has support. + if ( + backend.someEndpoint(wantBackend, (endpoint) => runtimeIsLanguage(endpoint.runtime, "dart")) + ) { + utils.logLabeledBullet( + "functions", + "Dart functions may not yet be visible in the Firebase Console. " + + `View them in the Cloud Console at https://console.cloud.google.com/run/services?project=${context.projectId}`, + ); + } + await setupArtifactCleanupPolicies( options, options.projectId!, diff --git a/src/deploy/functions/runtimes/supported/index.ts b/src/deploy/functions/runtimes/supported/index.ts index 21bef65beba..f5cbbb8fb3b 100644 --- a/src/deploy/functions/runtimes/supported/index.ts +++ b/src/deploy/functions/runtimes/supported/index.ts @@ -11,14 +11,9 @@ export function isRuntime(maybe: string): maybe is Runtime { /** Type deduction helper to narrow a runtime to a language. */ export function runtimeIsLanguage( - runtime: Runtime, + runtime: Runtime | undefined, language: L, ): runtime is Runtime & RuntimeOf { - return runtime.startsWith(language); -} - -/** Check if an optional runtime string belongs to a given language. */ -export function isLanguageRuntime(runtime: string | undefined, language: Language): boolean { return !!runtime && runtime.startsWith(language); } diff --git a/src/emulator/functionsEmulator.ts b/src/emulator/functionsEmulator.ts index 29271006ccd..c9bba89d2bd 100644 --- a/src/emulator/functionsEmulator.ts +++ b/src/emulator/functionsEmulator.ts @@ -60,7 +60,7 @@ import { BlockingFunctionsConfig } from "../gcp/identityPlatform"; import { resolveBackend } from "../deploy/functions/build"; import { getCredentialsEnvironment, setEnvVarsForEmulators } from "./env"; import { runWithVirtualEnv } from "../functions/python"; -import { isLanguageRuntime, Runtime } from "../deploy/functions/runtimes/supported"; +import { runtimeIsLanguage, Runtime } from "../deploy/functions/runtimes/supported"; import { DART_ENTRY_POINT } from "../deploy/functions/runtimes/dart"; import { ExtensionsEmulator } from "./extensionsEmulator"; @@ -424,7 +424,7 @@ export class FunctionsEmulator implements EmulatorInstance { // For Dart, include the function name in the path so the server can route // For other runtimes, use / as they use FUNCTION_TARGET env var - const isDart = isLanguageRuntime(record.backend.runtime, "dart"); + const isDart = runtimeIsLanguage(record.backend.runtime, "dart"); const path = isDart ? `/${trigger.entryPoint}` : `/`; return new Promise((resolve, reject) => { @@ -485,7 +485,7 @@ export class FunctionsEmulator implements EmulatorInstance { // First load triggers to discover the runtime type await this.loadTriggers(backend, /* force= */ true); - const isDart = isLanguageRuntime(backend.runtime, "dart"); + const isDart = runtimeIsLanguage(backend.runtime, "dart"); if (isDart) { // For Dart, build_runner watch handles source file watching and rebuilds @@ -1771,9 +1771,9 @@ export class FunctionsEmulator implements EmulatorInstance { const secretEnvs = await this.resolveSecretEnvs(backend, trigger); let runtime; - if (isLanguageRuntime(backend.runtime, "python")) { + if (runtimeIsLanguage(backend.runtime, "python")) { runtime = await this.startPython(backend, { ...runtimeEnv, ...secretEnvs }); - } else if (isLanguageRuntime(backend.runtime, "dart")) { + } else if (runtimeIsLanguage(backend.runtime, "dart")) { runtime = await this.startDart(backend, { ...runtimeEnv, ...secretEnvs }); } else { runtime = await this.startNode(backend, { ...runtimeEnv, ...secretEnvs }); @@ -1884,8 +1884,7 @@ export class FunctionsEmulator implements EmulatorInstance { // Use trigger.entryPoint (e.g. "helloworld") which is the actual function name // registered in the Dart server, not trigger_name which may include region prefix // (e.g. "us-central1-helloworld-0" from background function routes). - const isDart = isLanguageRuntime(record.backend.runtime, "dart"); - if (isDart) { + if (runtimeIsLanguage(record.backend.runtime, "dart")) { // Background trigger routes (e.g., /functions/projects/.../triggers/...) // leave a path artifact (/functions/projects/) after regex replacement. // Only append remaining path for HTTP trigger routes where the user may diff --git a/src/emulator/functionsRuntimeWorker.ts b/src/emulator/functionsRuntimeWorker.ts index 0593dc5a2a0..a8391d1ccd2 100644 --- a/src/emulator/functionsRuntimeWorker.ts +++ b/src/emulator/functionsRuntimeWorker.ts @@ -9,7 +9,7 @@ import { EmulatorLogger, ExtensionLogInfo } from "./emulatorLogger"; import { FirebaseError } from "../error"; import { Serializable } from "child_process"; import { getFunctionDiscoveryTimeout } from "../deploy/functions/runtimes/discovery"; -import { isLanguageRuntime } from "../deploy/functions/runtimes/supported"; +import { Runtime, runtimeIsLanguage } from "../deploy/functions/runtimes/supported"; type LogListener = (el: EmulatorLog) => any; @@ -297,13 +297,13 @@ export class RuntimeWorkerPool { constructor(private mode: FunctionsExecutionMode = FunctionsExecutionMode.AUTO) {} - getKey(triggerId: string | undefined, runtime?: string): string { + getKey(triggerId: string | undefined, runtime?: Runtime): string { if (this.mode === FunctionsExecutionMode.SEQUENTIAL) { return "~shared~"; } // For Dart, use a shared key so all functions in a codebase share the same worker process. // Dart loads all functions into a single process and routes based on request path. - if (isLanguageRuntime(runtime, "dart")) { + if (runtimeIsLanguage(runtime, "dart")) { return "~dart-shared~"; } return triggerId || "~diagnostic~"; @@ -350,7 +350,7 @@ export class RuntimeWorkerPool { * * @param triggerId */ - readyForWork(triggerId: string | undefined, runtime?: string): boolean { + readyForWork(triggerId: string | undefined, runtime?: Runtime): boolean { const idleWorker = this.getIdleWorker(triggerId, runtime); return !!idleWorker; } @@ -371,7 +371,7 @@ export class RuntimeWorkerPool { resp: http.ServerResponse, body: unknown, debug?: FunctionsRuntimeBundle["debug"], - runtime?: string, + runtime?: Runtime, ): Promise { this.log(`submitRequest(triggerId=${triggerId})`); const worker = this.getIdleWorker(triggerId, runtime); @@ -386,7 +386,7 @@ export class RuntimeWorkerPool { return worker.request(req, resp, body, !!debug); } - getIdleWorker(triggerId: string | undefined, runtime?: string): RuntimeWorker | undefined { + getIdleWorker(triggerId: string | undefined, runtime?: Runtime): RuntimeWorker | undefined { this.cleanUpWorkers(); const triggerWorkers = this.getTriggerWorkers(triggerId, runtime); if (!triggerWorkers.length) { @@ -412,7 +412,7 @@ export class RuntimeWorkerPool { trigger: EmulatedTriggerDefinition | undefined, runtime: FunctionsRuntimeInstance, extensionLogInfo: ExtensionLogInfo, - runtimeType?: string, + runtimeType?: Runtime, ): RuntimeWorker { const key = this.getKey(trigger?.id, runtimeType); this.log(`addWorker(${key})`); @@ -435,14 +435,14 @@ export class RuntimeWorkerPool { return worker; } - getTriggerWorkers(triggerId: string | undefined, runtime?: string): Array { + getTriggerWorkers(triggerId: string | undefined, runtime?: Runtime): Array { return this.workers.get(this.getKey(triggerId, runtime)) || []; } private setTriggerWorkers( triggerId: string | undefined, workers: Array, - runtime?: string, + runtime?: Runtime, ) { this.workers.set(this.getKey(triggerId, runtime), workers); }