Skip to content

Commit 5cd1a55

Browse files
committed
Add back JSON string
1 parent 89dfe97 commit 5cd1a55

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

packages/util/src/defaults.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,36 @@ const getDefaultsFromGlobal = (): FirebaseDefaults | undefined =>
3838
getGlobal().__FIREBASE_DEFAULTS__;
3939

4040
/**
41-
* Attempt to read defaults from a JSON file whose path is in
41+
* Attempt to read defaults from a JSON string provided to
42+
* process.env.__FIREBASE_DEFAULTS__ or a JSON file whose path is in
4243
* process.env.__FIREBASE_DEFAULTS_PATH__
4344
*/
4445
const getDefaultsFromEnvVariable = (): FirebaseDefaults | undefined => {
4546
if (typeof process === 'undefined') {
4647
return;
4748
}
48-
const jsonPath = process.env.__FIREBASE_DEFAULTS_PATH__;
49-
if (jsonPath && typeof require !== 'undefined') {
49+
const defaultsJsonString = process.env.__FIREBASE_DEFAULTS__;
50+
const defaultsJsonPath = process.env.__FIREBASE_DEFAULTS_PATH__;
51+
if (defaultsJsonString) {
52+
if (defaultsJsonPath) {
53+
console.warn(
54+
`Values were provided for both __FIREBASE_DEFAULTS__ ` +
55+
`and __FIREBASE_DEFAULTS_PATH__. __FIREBASE_DEFAULTS_PATH__ ` +
56+
`will be ignored.`
57+
);
58+
}
59+
return JSON.parse(defaultsJsonString);
60+
}
61+
if (defaultsJsonPath && typeof require !== 'undefined') {
5062
try {
5163
// eslint-disable-next-line @typescript-eslint/no-require-imports
52-
const json = require(jsonPath);
64+
const json = require(defaultsJsonPath);
5365
return json;
5466
} catch (e) {
55-
console.warn(`Unable to read defaults from file: ${jsonPath}.`);
67+
console.warn(
68+
`Unable to read defaults from file provided to ` +
69+
`__FIREBASE_DEFAULTS_PATH__: ${defaultsJsonPath}`
70+
);
5671
}
5772
}
5873
};

0 commit comments

Comments
 (0)