Skip to content
This repository was archived by the owner on Sep 2, 2025. It is now read-only.

Commit 883da46

Browse files
committed
Default to index handler file if no "." in handler config value
1 parent c1e0d41 commit 883da46

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

__tests__/fixtures/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('./foo');

__tests__/include-dependencies.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,12 @@ test('processFunction should include individually', t => {
267267
]);
268268
});
269269

270+
test('getHandlerFilename should default to index where there is no . in the handler name', t => {
271+
const instance = createTestInstance();
272+
273+
t.deepEqual(instance.getHandlerFilename('https'), path.join(__dirname, 'fixtures', 'index.js'));
274+
});
275+
270276
test('getHandlerFilename should handle a simple handler expression', t => {
271277
const instance = createTestInstance();
272278

include-dependencies.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ module.exports = class IncludeDependencies {
130130
}
131131

132132
getHandlerFilename(handler) {
133-
const handlerPath = handler.slice(0, handler.lastIndexOf('.'));
133+
const lastDotIndex = handler.lastIndexOf('.');
134+
const handlerPath = lastDotIndex !== -1 ? handler.slice(0, lastDotIndex) : 'index';
134135
return require.resolve((path.join(this.serverless.config.servicePath, handlerPath)));
135136
}
136137

0 commit comments

Comments
 (0)