Skip to content
This repository was archived by the owner on Dec 9, 2024. It is now read-only.

Commit c9b2fa2

Browse files
authored
Merge pull request #66 from herzog31/issue/65
Optimize path extraction of action handlers
2 parents 3eee7c4 + 9d0fe99 commit c9b2fa2

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

compile/functions/runtimes/base.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,11 @@ class BaseRuntime {
5151
}
5252

5353
convertHandlerToPath(functionHandler) {
54-
return functionHandler.replace(/\..*$/, this.extension)
54+
const lastDot = functionHandler.lastIndexOf('.');
55+
if (lastDot === -1) {
56+
return functionHandler;
57+
}
58+
return functionHandler.substring(0, lastDot) + this.extension;
5559
}
5660

5761
generateActionPackage(functionObject) {

compile/functions/tests/index.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,29 @@ require('chai').use(chaiAsPromised);
77

88
const sinon = require('sinon');
99
const OpenWhiskCompileFunctions = require('../index');
10+
const BaseRuntime = require('../runtimes/base.js');
11+
12+
describe('BaseRuntime', () => {
13+
describe('#convertHandlerToPath', () => {
14+
const base = new BaseRuntime();
15+
base.extension = '.js';
16+
17+
it('should extract the path for a given file handler', () => {
18+
const result = base.convertHandlerToPath('index.main');
19+
expect(result).to.equal('index.js');
20+
});
21+
22+
it('should return the input for a given file handler without exported function', () => {
23+
const result = base.convertHandlerToPath('index');
24+
expect(result).to.equal('index');
25+
});
26+
27+
it('should extract the path for a given path handler', () => {
28+
const result = base.convertHandlerToPath('[email protected]/index.main');
29+
expect(result).to.equal('[email protected]/index.js');
30+
});
31+
});
32+
});
1033

1134
describe('OpenWhiskCompileFunctions', () => {
1235
let serverless;

0 commit comments

Comments
 (0)