Skip to content

Commit 5dc5d5c

Browse files
committed
remove the unnecessary build target
1 parent 034dff4 commit 5dc5d5c

File tree

5 files changed

+45
-73
lines changed

5 files changed

+45
-73
lines changed

packages/app/src/firebaseNamespaceCore.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,6 @@ export function createFirebaseNamespaceCore(
7070
}
7171
};
7272

73-
// setting version on CONSTANTS, so @firebase/database can get the version from
74-
// @firebase/util instead of @firebase/app. So we can provide a special build target
75-
// for @firebase/database that has no dependency on @firebase/app. The special build target will
76-
// be used by firebase-admin. It is to solve a version conflict (@firebase/app) that could happen
77-
// when firebase and firebase-admin are used in the same project.
78-
// https://github.com/firebase/firebase-js-sdk/issues/1696#issuecomment-501546596
79-
CONSTANTS.SDK_VERSION = version;
80-
8173
// Inject a circular default export to allow Babel users who were previously
8274
// using:
8375
//

packages/database/index.admin.ts

Lines changed: 0 additions & 50 deletions
This file was deleted.

packages/database/index.node.ts

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
* limitations under the License.
1616
*/
1717

18-
import firebase from '@firebase/app';
19-
import { FirebaseNamespace } from '@firebase/app-types';
18+
import { FirebaseNamespace, FirebaseApp } from '@firebase/app-types';
2019
import { _FirebaseNamespace } from '@firebase/app-types/private';
2120
import { Database } from './src/api/Database';
2221
import { DataSnapshot } from './src/api/DataSnapshot';
@@ -29,21 +28,50 @@ import * as TEST_ACCESS from './src/api/test_access';
2928
import './src/nodePatches';
3029
import * as types from '@firebase/database-types';
3130
import { setSDKVersion } from './src/core/version';
31+
import { CONSTANTS } from '@firebase/util';
32+
33+
34+
const ServerValue = Database.ServerValue;
3235

3336
/**
3437
* A one off register function which returns a database based on the app and
3538
* passed database URL.
3639
*
3740
* @param app A valid FirebaseApp-like object
3841
* @param url A valid Firebase databaseURL
42+
* @param version custom version e.g. firebase-admin version
3943
*/
44+
export function initStandalone(
45+
app: FirebaseApp,
46+
url: string,
47+
version: string
48+
) {
49+
/**
50+
* This should allow the firebase-admin package to provide a custom version
51+
* to the backend
52+
*/
53+
CONSTANTS.NODE_ADMIN = true;
54+
setSDKVersion(version);
4055

41-
const ServerValue = Database.ServerValue;
56+
return {
57+
instance: RepoManager.getInstance().databaseFromApp(app, url),
58+
namespace: {
59+
Reference,
60+
Query,
61+
Database,
62+
DataSnapshot,
63+
enableLogging,
64+
INTERNAL,
65+
ServerValue,
66+
TEST_ACCESS
67+
}
68+
};
69+
}
4270

4371
export function registerDatabase(instance: FirebaseNamespace) {
4472

4573
// set SDK_VERSION
46-
setSDKVersion(firebase.SDK_VERSION);
74+
setSDKVersion(instance.SDK_VERSION);
4775

4876
// Register the Database Service with the 'firebase' namespace.
4977
(instance as _FirebaseNamespace).INTERNAL.registerService(
@@ -65,7 +93,18 @@ export function registerDatabase(instance: FirebaseNamespace) {
6593
);
6694
}
6795

68-
registerDatabase(firebase);
96+
try {
97+
// If @firebase/app is not present, skip registering database.
98+
// It could happen when this package is used in firebase-admin which doesn't depend on @firebase/app.
99+
// Previously firebase-admin depends on @firebase/app, which causes version conflict on
100+
// @firebase/app when used together with the js sdk. More detail:
101+
// https://github.com/firebase/firebase-js-sdk/issues/1696#issuecomment-501546596
102+
const firebase = require('@firebase/app');
103+
registerDatabase(firebase);
104+
} catch(err) {
105+
106+
}
107+
69108

70109
// Types to export for the admin SDK
71110
export { Database, Query, Reference, enableLogging, ServerValue };

packages/database/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const ServerValue = Database.ServerValue;
3535
export function registerDatabase(instance: FirebaseNamespace) {
3636

3737
// set SDK_VERSION
38-
setSDKVersion(firebase.SDK_VERSION);
38+
setSDKVersion(instance.SDK_VERSION);
3939

4040
// Register the Database Service with the 'firebase' namespace.
4141
const namespace = (instance as _FirebaseNamespace).INTERNAL.registerService(

packages/database/rollup.config.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,6 @@ const es5Builds = [
4242
plugins: es5BuildPlugins,
4343
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
4444
},
45-
/**
46-
* Node.js Build for firebase-admin (no dep on @firebase/app)
47-
*/
48-
{
49-
input: 'index.admin.ts',
50-
output: [{ file: pkg['main-admin'], format: 'cjs', sourcemap: true }],
51-
plugins: es5BuildPlugins,
52-
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
53-
},
5445
/**
5546
* Browser Builds
5647
*/

0 commit comments

Comments
 (0)