Skip to content

Commit e08be85

Browse files
authored
Merge pull request #84 from leoortizz/firebase-aware-fix
Fix `usingFirebaseJsSdk`
2 parents a55de78 + 4c94869 commit e08be85

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ type Server = typeof import('./angular/index.js') |
1515
import type { Request } from 'firebase-functions/v2/https';
1616
import type { Response } from 'express';
1717

18+
import { isUsingFirebaseJsSdk } from './utils.js'
19+
1820
const dirname = process.env.__FIREBASE_FRAMEWORKS_ENTRY__;
19-
const usingFirebaseJsSdk = !!process.env.__FIREBASE_DEFAULTS__;
21+
const usingFirebaseJsSdk = await isUsingFirebaseJsSdk();
2022
const basename = usingFirebaseJsSdk ? 'firebase-aware' : 'index';
2123

2224
// .env isn't parsed for Cloud Functions discovery during deploy, handle undefined

src/utils.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export async function isUsingFirebaseJsSdk() {
2+
if(!process.env.__FIREBASE_DEFAULTS__) return false;
3+
4+
try {
5+
await import('firebase/app');
6+
7+
return true
8+
} catch (e) {
9+
return false;
10+
}
11+
}

0 commit comments

Comments
 (0)