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

Commit 6f33da6

Browse files
committed
Merge branch 'master' of github.com:serverless/serverless-openwhisk
2 parents caf5173 + 251e7c4 commit 6f33da6

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

compile/functions/runtimes/node.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,21 @@ class Node extends BaseRuntime {
1717
zip.file("package.json", JSON.stringify({main: handlerFile}))
1818
return zip
1919
}
20+
21+
//We're handling a special case here which is that if TypeScript is being used
22+
//we won't actually have a ".js" file (this.extension), instead we'll have a "ts"
23+
//which should still be considered safe enough, or at least shouldn't
24+
//completely stop the deployment process
25+
isValidFile(handlerFile) {
26+
return super.isValidFile(handlerFile) || this.isValidTypeScriptFile(handlerFile);
27+
}
28+
29+
//Check for TypeScript version of handler file
30+
isValidTypeScriptFile(handlerFile) {
31+
//replaces the last occurance of `.js` with `.ts`, case insensitive
32+
const typescriptHandlerFile = handlerFile.replace(/\.js$/gi, ".ts");
33+
return super.isValidFile(typescriptHandlerFile);
34+
}
2035
}
2136

2237
module.exports = Node

compile/functions/runtimes/tests/node.js

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

88
const sinon = require('sinon');
99
const Node = require('../node');
10+
const BaseRuntime = require('../base');
1011
const JSZip = require("jszip");
1112
const fs = require('fs-extra');
1213

@@ -96,6 +97,28 @@ describe('Node', () => {
9697
})
9798
});
9899

100+
describe('#isValidTypeScriptFile()', () => {
101+
it('should report valid file path when a js path is passed that has a ts file instead', () => {
102+
//We need to mock the node's `super` call, which is why we're using BaseRuntime
103+
sandbox.stub(BaseRuntime.prototype, 'isValidFile', (path) => {
104+
expect(path).to.equal('valid_typescript_handler_wrong_extension.ts');
105+
return true;
106+
});
107+
expect(node.isValidTypeScriptFile('valid_typescript_handler_wrong_extension.js')).to.equal(true)
108+
});
109+
});
110+
111+
describe('#isValidFile()', () => {
112+
it('should still allow a js file to be used for handler', () => {
113+
//We need to mock the node's `super` call, which is why we're using BaseRuntime
114+
sandbox.stub(BaseRuntime.prototype, 'isValidFile', (path) => {
115+
expect(path).to.equal('valid_js_handler.js');
116+
return true;
117+
});
118+
expect(node.isValidFile('valid_js_handler.js')).to.equal(true)
119+
});
120+
});
121+
99122
describe('#generateActionPackage()', () => {
100123
it('should throw error for missing handler file', () => {
101124
expect(() => node.generateActionPackage({handler: 'does_not_exist.main'}))

0 commit comments

Comments
 (0)