Skip to content

Commit 2940a4b

Browse files
authored
Use process.env.PWD for finding .runtimeconfig.json (#634)
1 parent ff852c5 commit 2940a4b

File tree

4 files changed

+22
-9
lines changed

4 files changed

+22
-9
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
**IMPORTANT: Please update to this version of `firebase-functions` if you are using Node.js 10 functions, otherwise your functions will break in production.**
2+
3+
- Prevents deployment and runtime issues caused by upcoming changes to Cloud Functions infrastructure for Node.js 10 functions. (Issue #630)
4+
- Adds support for writing scheduled functions under handler namespace.

changelog.txt

Whitespace-only changes.

spec/config.spec.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ import * as mockRequire from 'mock-require';
2525
import { config, firebaseConfig } from '../src/config';
2626

2727
describe('config()', () => {
28+
before(() => {
29+
process.env.PWD = '/srv';
30+
});
31+
after(() => {
32+
delete process.env.PWD;
33+
});
2834
afterEach(() => {
2935
mockRequire.stopAll();
3036
delete config.singleton;
@@ -33,19 +39,19 @@ describe('config()', () => {
3339
});
3440

3541
it('loads config values from .runtimeconfig.json', () => {
36-
mockRequire('../../../.runtimeconfig.json', { foo: 'bar', firebase: {} });
42+
mockRequire('/srv/.runtimeconfig.json', { foo: 'bar', firebase: {} });
3743
const loaded = config();
3844
expect(loaded).to.not.have.property('firebase');
3945
expect(loaded).to.have.property('foo', 'bar');
4046
});
4147

4248
it('does not provide firebase config if .runtimeconfig.json not invalid', () => {
43-
mockRequire('../../../.runtimeconfig.json', 'does-not-exist');
49+
mockRequire('/srv/.runtimeconfig.json', 'does-not-exist');
4450
expect(firebaseConfig()).to.be.null;
4551
});
4652

4753
it('does not provide firebase config if .ruuntimeconfig.json has no firebase property', () => {
48-
mockRequire('../../../.runtimeconfig.json', {});
54+
mockRequire('/srv/.runtimeconfig.json', {});
4955
expect(firebaseConfig()).to.be.null;
5056
});
5157

src/config.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
// SOFTWARE.
2222

2323
import * as firebase from 'firebase-admin';
24+
import * as path from 'path';
2425

2526
export function config(): config.Config {
2627
if (typeof config.singleton === 'undefined') {
@@ -68,9 +69,10 @@ export function firebaseConfig(): firebase.AppOptions | null {
6869

6970
// Could have Runtime Config with Firebase in it as an ENV location or default.
7071
try {
71-
const path =
72-
process.env.CLOUD_RUNTIME_CONFIG || '../../../.runtimeconfig.json';
73-
const config = require(path);
72+
const configPath =
73+
process.env.CLOUD_RUNTIME_CONFIG ||
74+
path.join(process.env.PWD, '.runtimeconfig.json');
75+
const config = require(configPath);
7476
if (config.firebase) {
7577
return config.firebase;
7678
}
@@ -92,9 +94,10 @@ function init() {
9294
}
9395

9496
try {
95-
const path =
96-
process.env.CLOUD_RUNTIME_CONFIG || '../../../.runtimeconfig.json';
97-
const parsed = require(path);
97+
const configPath =
98+
process.env.CLOUD_RUNTIME_CONFIG ||
99+
path.join(process.env.PWD, '.runtimeconfig.json');
100+
const parsed = require(configPath);
98101
delete parsed.firebase;
99102
config.singleton = parsed;
100103
return;

0 commit comments

Comments
 (0)