Skip to content

Commit ca95831

Browse files
committed
fix(exportfunctions): backwards compatible with FUNCTION_NAME env var
The previous fix of #7 did not take into account that node 8 & 6 still use FUNCTION_NAME, which are accessible on GCP. This commit adresses that issue. fix #7
1 parent b8c8610 commit ca95831

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/default.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ const funcNameFromRelPath = (relpath: string): string => {
2121
return funcName.replace(/\//g, '-');
2222
};
2323

24+
function getEnvFuncName() {
25+
return process.env.FUNCTION_NAME || process.env.K_SERVICE;
26+
}
2427
/**
2528
* This function will search the given directory using provided glob matching pattern and
2629
* export firebase cloud functions for you automatically, without you having to require
@@ -56,7 +59,7 @@ export default function (__dirname: string, __filename: string, exports: any, di
5659
const relPath = absPath.substr(absFuncDir.length + 1); /* ? */
5760
const funcName = funcNameFromRelPath(relPath); /* ? */
5861
const propPath = funcName.replace(/-/g, '.'); /* ? */
59-
if (!process.env.K_SERVICE || process.env.K_SERVICE === funcName) {
62+
if (!getEnvFuncName() || getEnvFuncName() === funcName) {
6063
// eslint-disable-next-line import/no-dynamic-require, global-require, no-eval
6164
const module = eval('require')(resolve(__dirname, funcDir, relPath));
6265
if (!module.default) continue;

src/export-functions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ const disabledLogger = {
130130
},
131131
};
132132

133-
const getFunctionInstance = () => process.env.K_SERVICE;
133+
const getFunctionInstance = () => process.env.FUNCTION_NAME || process.env.K_SERVICE;
134134
const isDeployment = () => !getFunctionInstance();
135135
const funcNameMatchesInstance = (funcName: string) => funcName === getFunctionInstance();
136136
const getTriggerFromModule = (inputModule: any) => inputModule?.default;

0 commit comments

Comments
 (0)