Skip to content

Commit f83c02b

Browse files
committed
cleanup postinstall
1 parent f52116a commit f83c02b

File tree

1 file changed

+30
-27
lines changed

1 file changed

+30
-27
lines changed

packages/util/postinstall.js

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,43 +19,43 @@ const { writeFile, readFile } = require('node:fs/promises');
1919
const { pathToFileURL } = require('node:url');
2020
const { isAbsolute, join } = require('node:path');
2121

22-
function getConfigFromEnv() {
22+
new Promise(resolve => {
2323
if (!process.env.FIREBASE_WEBAPP_CONFIG) {
24-
return Promise.resolve(undefined);
24+
return resolve(undefined);
2525
}
2626

2727
// Like FIREBASE_CONFIG (admin autoinit) FIREBASE_WEBAPP_CONFIG can be
2828
// either a JSON representation of FirebaseOptions or the path to a filename
2929
if (process.env.FIREBASE_WEBAPP_CONFIG.startsWith('{"')) {
3030
try {
31-
return Promise.resolve(JSON.parse(process.env.FIREBASE_WEBAPP_CONFIG));
31+
return resolve(JSON.parse(process.env.FIREBASE_WEBAPP_CONFIG));
3232
} catch (e) {
3333
console.error('FIREBASE_WEBAPP_CONFIG could not be parsed.\n', e);
34-
return Promise.resolve(undefined);
34+
return resolve(undefined);
3535
}
3636
}
3737

3838
const fileName = process.env.FIREBASE_WEBAPP_CONFIG;
3939
const fileURL = pathToFileURL(
4040
isAbsolute(fileName) ? fileName : join(process.cwd(), fileName)
4141
);
42-
return readFile(fileURL, 'utf-8').then(
43-
fileContents => {
44-
try {
45-
return JSON.parse(fileContents);
46-
} catch (e) {
42+
resolve(
43+
readFile(fileURL, 'utf-8').then(
44+
fileContents => {
45+
try {
46+
return JSON.parse(fileContents);
47+
} catch (e) {
48+
console.error(`Contents of "${fileName}" could not be parsed.\n`, e);
49+
return undefined;
50+
}
51+
},
52+
e => {
4753
console.error(`Contents of "${fileName}" could not be parsed.\n`, e);
4854
return undefined;
4955
}
50-
},
51-
e => {
52-
console.error(`Contents of "${fileName}" could not be parsed.\n`, e);
53-
return undefined;
54-
}
56+
)
5557
);
56-
}
57-
58-
getConfigFromEnv()
58+
})
5959
.then(partialConfig => {
6060
if (!partialConfig) {
6161
return undefined;
@@ -78,18 +78,21 @@ getConfigFromEnv()
7878
return fetch(
7979
`https://firebase.googleapis.com/v1alpha/projects/${projectId}/apps/${appId}/webConfig`,
8080
{ headers: { 'x-goog-api-key': apiKey } }
81-
).then(response => {
82-
if (!response.ok) {
83-
console.error(
84-
`Unable to fetch Firebase config, API returned ${response.statusText} (${response.status})`
85-
);
81+
).then(
82+
response => {
83+
if (!response.ok) {
84+
console.error(
85+
`Unable to fetch Firebase config, API returned ${response.statusText} (${response.status})`
86+
);
87+
return undefined;
88+
}
89+
return response.json().then(json => ({ ...json, apiKey }));
90+
},
91+
e => {
92+
console.error(`Unable to fetch Firebase config\n${e.cause}`);
8693
return undefined;
8794
}
88-
return response.json().then(json => ({ ...json, apiKey }));
89-
}, (e) => {
90-
console.error(`Unable to fetch Firebase config\n${e.cause}`);
91-
return undefined;
92-
});
95+
);
9396
})
9497
.then(config => {
9598
const emulatorHosts = Object.entries({

0 commit comments

Comments
 (0)