Skip to content

Commit c05e7fb

Browse files
committed
fix!: remove default fallback when target function does not exist
This is a breaking change. Functions framework will no longer load a default function named 'function' if one is exported and the configured target can not be found.
1 parent d8ce21c commit c05e7fb

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

Diff for: src/loader.ts

+5-11
Original file line numberDiff line numberDiff line change
@@ -131,18 +131,12 @@ export async function getUserFunction(
131131
}
132132
}, functionModule);
133133

134-
// TODO: do we want 'function' fallback?
135134
if (typeof userFunction === 'undefined') {
136-
// eslint-disable-next-line no-prototype-builtins
137-
if (functionModule.hasOwnProperty('function')) {
138-
userFunction = functionModule['function'];
139-
} else {
140-
console.error(
141-
`Function '${functionTarget}' is not defined in the provided ` +
142-
'module.\nDid you specify the correct target function to execute?'
143-
);
144-
return null;
145-
}
135+
console.error(
136+
`Function '${functionTarget}' is not defined in the provided ` +
137+
'module.\nDid you specify the correct target function to execute?'
138+
);
139+
return null;
146140
}
147141

148142
if (typeof userFunction !== 'function') {

Diff for: test/loader.ts

+14
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,20 @@ describe('loading function', () => {
9393
}
9494
}
9595

96+
it('fails to load a function that does not exist', async () => {
97+
FunctionRegistry.http('function', () => {
98+
return 'PASS';
99+
});
100+
101+
const loadedFunction = await loader.getUserFunction(
102+
process.cwd() + '/test/data/with_main',
103+
'functionDoesNotExist',
104+
'http'
105+
);
106+
107+
assert.strictEqual(loadedFunction, null);
108+
});
109+
96110
it('loads a declaratively registered function', async () => {
97111
FunctionRegistry.http('registeredFunction', () => {
98112
return 'PASS';

0 commit comments

Comments
 (0)