From 4c9486918e94d030d222e6a526e8afd6f4d01d67 Mon Sep 17 00:00:00 2001 From: Leonardo Ortiz Date: Fri, 23 Jun 2023 19:01:33 -0300 Subject: [PATCH] check whether `firebase/app` can be imported --- src/index.ts | 4 +++- src/utils.ts | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 src/utils.ts diff --git a/src/index.ts b/src/index.ts index 323ef8e3..e3b2e996 100644 --- a/src/index.ts +++ b/src/index.ts @@ -15,8 +15,10 @@ type Server = typeof import('./angular/index.js') | import type { Request } from 'firebase-functions/v2/https'; import type { Response } from 'express'; +import { isUsingFirebaseJsSdk } from './utils.js' + const dirname = process.env.__FIREBASE_FRAMEWORKS_ENTRY__; -const usingFirebaseJsSdk = !!process.env.__FIREBASE_DEFAULTS__; +const usingFirebaseJsSdk = await isUsingFirebaseJsSdk(); const basename = usingFirebaseJsSdk ? 'firebase-aware' : 'index'; // .env isn't parsed for Cloud Functions discovery during deploy, handle undefined diff --git a/src/utils.ts b/src/utils.ts new file mode 100644 index 00000000..7067e73a --- /dev/null +++ b/src/utils.ts @@ -0,0 +1,11 @@ +export async function isUsingFirebaseJsSdk() { + if(!process.env.__FIREBASE_DEFAULTS__) return false; + + try { + await import('firebase/app'); + + return true + } catch (e) { + return false; + } +} \ No newline at end of file