-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
47 lines (35 loc) · 1.49 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
'use strict';
class ServerlessPluginLocalEnvironment {
constructor(serverless, options) {
this.serverless = serverless;
this.options = options;
this.hooks = {
'before:invoke:local:invoke': this.extendOptionsWithLocalEnvironment.bind(this)
};
}
extendOptionsWithLocalEnvironment(){
const functionObj = this.serverless.service.getFunction(this.options.function);
// const providerObj = this.serverless.getProvider();
this.extendWithLocalEnvironment(functionObj, functionObj && functionObj['local-environment'])
// this.extendWithLocalEnvironment(providerObj, providerObj && providerObj['local-environment'])
}
extendWithLocalEnvironment(obj, extension){
if(
extension &&
extension['LD_LIBRARY_PATH']
){
let ldPaths = [];
// from https://github.com/serverless/serverless/blob/4b71faf2128308894646940ce2fb64e826450972/lib/plugins/aws/invokeLocal/index.js#L95
const awsLibs = '/usr/local/lib64/node-v4.3.x/lib:/lib64:/usr/lib64:/var/runtime:/var/runtime/lib:/var/task:/var/task/lib';
ldPaths = ldPaths.concat(awsLibs.split(':'));
ldPaths = ldPaths.concat(extension['LD_LIBRARY_PATH'].split(':'));
extension['LD_LIBRARY_PATH'] = ldPaths.join(':');
}
if(!obj.environment){
obj.environment = {};
}
Object.assign(obj.environment, extension);
return Promise.resolve();
}
}
module.exports = ServerlessPluginLocalEnvironment;