serverless-offline 7.1.0 → 8.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/README.md +125 -112
  2. package/dist/ServerlessOffline.js +91 -24
  3. package/dist/config/constants.js +1 -1
  4. package/dist/config/supportedRuntimes.js +1 -1
  5. package/dist/events/http/Endpoint.js +27 -9
  6. package/dist/events/http/Http.js +3 -3
  7. package/dist/events/http/HttpServer.js +311 -76
  8. package/dist/events/http/authFunctionNameExtractor.js +14 -8
  9. package/dist/events/http/authJWTSettingsExtractor.js +14 -7
  10. package/dist/events/http/createAuthScheme.js +42 -8
  11. package/dist/events/http/createJWTAuthScheme.js +52 -13
  12. package/dist/events/http/lambda-events/LambdaIntegrationEvent.js +7 -6
  13. package/dist/events/http/lambda-events/LambdaProxyIntegrationEvent.js +18 -7
  14. package/dist/events/http/lambda-events/LambdaProxyIntegrationEventV2.js +17 -6
  15. package/dist/events/http/lambda-events/VelocityContext.js +4 -4
  16. package/dist/events/http/lambda-events/index.js +4 -4
  17. package/dist/events/http/lambda-events/renderVelocityTemplateObject.js +19 -7
  18. package/dist/events/schedule/Schedule.js +64 -20
  19. package/dist/events/websocket/HttpServer.js +24 -7
  20. package/dist/events/websocket/WebSocket.js +14 -6
  21. package/dist/events/websocket/WebSocketClients.js +65 -17
  22. package/dist/events/websocket/WebSocketServer.js +28 -6
  23. package/dist/events/websocket/http-routes/_catchAll/catchAllRoute.js +9 -2
  24. package/dist/events/websocket/http-routes/connections/ConnectionsController.js +1 -1
  25. package/dist/events/websocket/http-routes/connections/connectionsRoutes.js +28 -5
  26. package/dist/events/websocket/lambda-events/WebSocketConnectEvent.js +5 -5
  27. package/dist/events/websocket/lambda-events/WebSocketDisconnectEvent.js +1 -1
  28. package/dist/events/websocket/lambda-events/WebSocketEvent.js +3 -3
  29. package/dist/events/websocket/lambda-events/WebSocketRequestContext.js +4 -4
  30. package/dist/lambda/HttpServer.js +34 -10
  31. package/dist/lambda/Lambda.js +15 -7
  32. package/dist/lambda/LambdaContext.js +1 -1
  33. package/dist/lambda/LambdaFunction.js +40 -23
  34. package/dist/lambda/LambdaFunctionPool.js +9 -8
  35. package/dist/lambda/handler-runner/HandlerRunner.js +48 -15
  36. package/dist/lambda/handler-runner/child-process-runner/ChildProcessRunner.js +21 -8
  37. package/dist/lambda/handler-runner/child-process-runner/childProcessHelper.js +1 -10
  38. package/dist/lambda/handler-runner/docker-runner/DockerContainer.js +168 -69
  39. package/dist/lambda/handler-runner/docker-runner/DockerImage.js +21 -5
  40. package/dist/lambda/handler-runner/docker-runner/DockerRunner.js +4 -4
  41. package/dist/lambda/handler-runner/in-process-runner/InProcessRunner.js +9 -21
  42. package/dist/lambda/handler-runner/java-runner/JavaRunner.js +26 -14
  43. package/dist/lambda/handler-runner/python-runner/PythonRunner.js +20 -7
  44. package/dist/lambda/handler-runner/ruby-runner/RubyRunner.js +22 -24
  45. package/dist/lambda/handler-runner/worker-thread-runner/WorkerThreadRunner.js +2 -2
  46. package/dist/lambda/handler-runner/worker-thread-runner/workerThreadHelper.js +1 -11
  47. package/dist/lambda/routes/invocations/InvocationsController.js +37 -11
  48. package/dist/lambda/routes/invocations/invocationsRoute.js +2 -2
  49. package/dist/lambda/routes/invoke-async/InvokeAsyncController.js +2 -6
  50. package/dist/serverlessLog.js +1 -1
  51. package/dist/utils/getHttpApiCorsConfig.js +18 -5
  52. package/dist/utils/index.js +16 -16
  53. package/package.json +58 -37
@@ -21,14 +21,14 @@ var id = 0;
21
21
 
22
22
  function _classPrivateFieldLooseKey(name) { return "__private_" + id++ + "_" + name; }
23
23
 
24
- var _lambda = _classPrivateFieldLooseKey("lambda");
24
+ var _lambda = /*#__PURE__*/_classPrivateFieldLooseKey("lambda");
25
25
 
26
- var _options = _classPrivateFieldLooseKey("options");
26
+ var _options = /*#__PURE__*/_classPrivateFieldLooseKey("options");
27
27
 
28
- var _server = _classPrivateFieldLooseKey("server");
28
+ var _server = /*#__PURE__*/_classPrivateFieldLooseKey("server");
29
29
 
30
30
  class HttpServer {
31
- constructor(options, lambda) {
31
+ constructor(options, lambda, v3Utils) {
32
32
  Object.defineProperty(this, _lambda, {
33
33
  writable: true,
34
34
  value: null
@@ -51,12 +51,20 @@ class HttpServer {
51
51
  host,
52
52
  port: lambdaPort
53
53
  };
54
+
55
+ if (v3Utils) {
56
+ this.log = v3Utils.log;
57
+ this.progress = v3Utils.progress;
58
+ this.writeText = v3Utils.writeText;
59
+ this.v3Utils = v3Utils;
60
+ }
61
+
54
62
  _classPrivateFieldLooseBase(this, _server)[_server] = new _hapi.Server(serverOptions);
55
63
  }
56
64
 
57
65
  async start() {
58
66
  // add routes
59
- const _invocationsRoute = (0, _index.invocationsRoute)(_classPrivateFieldLooseBase(this, _lambda)[_lambda], _classPrivateFieldLooseBase(this, _options)[_options]);
67
+ const _invocationsRoute = (0, _index.invocationsRoute)(_classPrivateFieldLooseBase(this, _lambda)[_lambda], _classPrivateFieldLooseBase(this, _options)[_options], this.v3Utils);
60
68
 
61
69
  const _invokeAsyncRoute = (0, _index.invokeAsyncRoute)(_classPrivateFieldLooseBase(this, _lambda)[_lambda], _classPrivateFieldLooseBase(this, _options)[_options]);
62
70
 
@@ -71,19 +79,35 @@ class HttpServer {
71
79
  try {
72
80
  await _classPrivateFieldLooseBase(this, _server)[_server].start();
73
81
  } catch (err) {
74
- console.error(`Unexpected error while starting serverless-offline lambda server on port ${lambdaPort}:`, err);
82
+ if (this.log) {
83
+ this.log.error(`Unexpected error while starting serverless-offline lambda server on port ${lambdaPort}:`, err);
84
+ } else {
85
+ console.error(`Unexpected error while starting serverless-offline lambda server on port ${lambdaPort}:`, err);
86
+ }
87
+
75
88
  process.exit(1);
76
89
  }
77
90
 
78
- (0, _serverlessLog.default)(`Offline [http for lambda] listening on http${httpsProtocol ? 's' : ''}://${host}:${lambdaPort}`); // Print all the invocation routes to debug
91
+ if (this.log) {
92
+ this.log.notice(`Offline [http for lambda] listening on http${httpsProtocol ? 's' : ''}://${host}:${lambdaPort}`);
93
+ } else {
94
+ (0, _serverlessLog.default)(`Offline [http for lambda] listening on http${httpsProtocol ? 's' : ''}://${host}:${lambdaPort}`);
95
+ } // Print all the invocation routes to debug
96
+
79
97
 
80
98
  const basePath = `http${httpsProtocol ? 's' : ''}://${host}:${lambdaPort}`;
81
99
 
82
100
  const funcNamePairs = _classPrivateFieldLooseBase(this, _lambda)[_lambda].listFunctionNamePairs();
83
101
 
84
- (0, _serverlessLog.default)([`Function names exposed for local invocation by aws-sdk:`, ..._classPrivateFieldLooseBase(this, _lambda)[_lambda].listFunctionNames().map(functionName => ` * ${funcNamePairs[functionName]}: ${functionName}`)].join('\n'));
85
- (0, _debugLog.default)([`Lambda Invocation Routes (for AWS SDK or AWS CLI):`, ..._classPrivateFieldLooseBase(this, _lambda)[_lambda].listFunctionNames().map(functionName => ` * ${_invocationsRoute.method} ${basePath}${_invocationsRoute.path.replace('{functionName}', functionName)}`)].join('\n'));
86
- (0, _debugLog.default)([`Lambda Async Invocation Routes (for AWS SDK or AWS CLI):`, ..._classPrivateFieldLooseBase(this, _lambda)[_lambda].listFunctionNames().map(functionName => ` * ${_invokeAsyncRoute.method} ${basePath}${_invokeAsyncRoute.path.replace('{functionName}', functionName)}`)].join('\n'));
102
+ if (this.log) {
103
+ this.log.notice([`Function names exposed for local invocation by aws-sdk:`, ..._classPrivateFieldLooseBase(this, _lambda)[_lambda].listFunctionNames().map(functionName => ` * ${funcNamePairs[functionName]}: ${functionName}`)].join('\n'));
104
+ this.log.debug([`Lambda Invocation Routes (for AWS SDK or AWS CLI):`, ..._classPrivateFieldLooseBase(this, _lambda)[_lambda].listFunctionNames().map(functionName => ` * ${_invocationsRoute.method} ${basePath}${_invocationsRoute.path.replace('{functionName}', functionName)}`)].join('\n'));
105
+ this.log.debug([`Lambda Async Invocation Routes (for AWS SDK or AWS CLI):`, ..._classPrivateFieldLooseBase(this, _lambda)[_lambda].listFunctionNames().map(functionName => ` * ${_invokeAsyncRoute.method} ${basePath}${_invokeAsyncRoute.path.replace('{functionName}', functionName)}`)].join('\n'));
106
+ } else {
107
+ (0, _serverlessLog.default)([`Function names exposed for local invocation by aws-sdk:`, ..._classPrivateFieldLooseBase(this, _lambda)[_lambda].listFunctionNames().map(functionName => ` * ${funcNamePairs[functionName]}: ${functionName}`)].join('\n'));
108
+ (0, _debugLog.default)([`Lambda Invocation Routes (for AWS SDK or AWS CLI):`, ..._classPrivateFieldLooseBase(this, _lambda)[_lambda].listFunctionNames().map(functionName => ` * ${_invocationsRoute.method} ${basePath}${_invocationsRoute.path.replace('{functionName}', functionName)}`)].join('\n'));
109
+ (0, _debugLog.default)([`Lambda Async Invocation Routes (for AWS SDK or AWS CLI):`, ..._classPrivateFieldLooseBase(this, _lambda)[_lambda].listFunctionNames().map(functionName => ` * ${_invokeAsyncRoute.method} ${basePath}${_invokeAsyncRoute.path.replace('{functionName}', functionName)}`)].join('\n'));
110
+ }
87
111
  } // stops the server
88
112
 
89
113
 
@@ -17,16 +17,16 @@ var id = 0;
17
17
 
18
18
  function _classPrivateFieldLooseKey(name) { return "__private_" + id++ + "_" + name; }
19
19
 
20
- var _httpServer = _classPrivateFieldLooseKey("httpServer");
20
+ var _httpServer = /*#__PURE__*/_classPrivateFieldLooseKey("httpServer");
21
21
 
22
- var _lambdas = _classPrivateFieldLooseKey("lambdas");
22
+ var _lambdas = /*#__PURE__*/_classPrivateFieldLooseKey("lambdas");
23
23
 
24
- var _lambdaFunctionNamesKeys = _classPrivateFieldLooseKey("lambdaFunctionNamesKeys");
24
+ var _lambdaFunctionNamesKeys = /*#__PURE__*/_classPrivateFieldLooseKey("lambdaFunctionNamesKeys");
25
25
 
26
- var _lambdaFunctionPool = _classPrivateFieldLooseKey("lambdaFunctionPool");
26
+ var _lambdaFunctionPool = /*#__PURE__*/_classPrivateFieldLooseKey("lambdaFunctionPool");
27
27
 
28
28
  class Lambda {
29
- constructor(serverless, options) {
29
+ constructor(serverless, options, v3Utils) {
30
30
  Object.defineProperty(this, _httpServer, {
31
31
  writable: true,
32
32
  value: null
@@ -43,8 +43,16 @@ class Lambda {
43
43
  writable: true,
44
44
  value: null
45
45
  });
46
- _classPrivateFieldLooseBase(this, _httpServer)[_httpServer] = new _HttpServer.default(options, this);
47
- _classPrivateFieldLooseBase(this, _lambdaFunctionPool)[_lambdaFunctionPool] = new _LambdaFunctionPool.default(serverless, options);
46
+
47
+ if (v3Utils) {
48
+ this.log = v3Utils.log;
49
+ this.progress = v3Utils.progress;
50
+ this.writeText = v3Utils.writeText;
51
+ this.v3Utils = v3Utils;
52
+ }
53
+
54
+ _classPrivateFieldLooseBase(this, _httpServer)[_httpServer] = new _HttpServer.default(options, this, v3Utils);
55
+ _classPrivateFieldLooseBase(this, _lambdaFunctionPool)[_lambdaFunctionPool] = new _LambdaFunctionPool.default(serverless, options, v3Utils);
48
56
  }
49
57
 
50
58
  _create(functionKey, functionDefinition) {
@@ -11,7 +11,7 @@ var id = 0;
11
11
 
12
12
  function _classPrivateFieldLooseKey(name) { return "__private_" + id++ + "_" + name; }
13
13
 
14
- var _context = _classPrivateFieldLooseKey("context");
14
+ var _context = /*#__PURE__*/_classPrivateFieldLooseKey("context");
15
15
 
16
16
  // class for creating a LambdaContext
17
17
  // http://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-context.html
@@ -40,43 +40,43 @@ const {
40
40
  ceil
41
41
  } = Math;
42
42
 
43
- var _artifact = _classPrivateFieldLooseKey("artifact");
43
+ var _artifact = /*#__PURE__*/_classPrivateFieldLooseKey("artifact");
44
44
 
45
- var _clientContext = _classPrivateFieldLooseKey("clientContext");
45
+ var _clientContext = /*#__PURE__*/_classPrivateFieldLooseKey("clientContext");
46
46
 
47
- var _codeDir = _classPrivateFieldLooseKey("codeDir");
47
+ var _codeDir = /*#__PURE__*/_classPrivateFieldLooseKey("codeDir");
48
48
 
49
- var _event = _classPrivateFieldLooseKey("event");
49
+ var _event = /*#__PURE__*/_classPrivateFieldLooseKey("event");
50
50
 
51
- var _executionTimeEnded = _classPrivateFieldLooseKey("executionTimeEnded");
51
+ var _executionTimeEnded = /*#__PURE__*/_classPrivateFieldLooseKey("executionTimeEnded");
52
52
 
53
- var _executionTimeStarted = _classPrivateFieldLooseKey("executionTimeStarted");
53
+ var _executionTimeStarted = /*#__PURE__*/_classPrivateFieldLooseKey("executionTimeStarted");
54
54
 
55
- var _functionKey = _classPrivateFieldLooseKey("functionKey");
55
+ var _functionKey = /*#__PURE__*/_classPrivateFieldLooseKey("functionKey");
56
56
 
57
- var _functionName = _classPrivateFieldLooseKey("functionName");
57
+ var _functionName = /*#__PURE__*/_classPrivateFieldLooseKey("functionName");
58
58
 
59
- var _handlerRunner = _classPrivateFieldLooseKey("handlerRunner");
59
+ var _handlerRunner = /*#__PURE__*/_classPrivateFieldLooseKey("handlerRunner");
60
60
 
61
- var _idleTimeStarted = _classPrivateFieldLooseKey("idleTimeStarted");
61
+ var _idleTimeStarted = /*#__PURE__*/_classPrivateFieldLooseKey("idleTimeStarted");
62
62
 
63
- var _initialized = _classPrivateFieldLooseKey("initialized");
63
+ var _initialized = /*#__PURE__*/_classPrivateFieldLooseKey("initialized");
64
64
 
65
- var _lambdaContext = _classPrivateFieldLooseKey("lambdaContext");
65
+ var _lambdaContext = /*#__PURE__*/_classPrivateFieldLooseKey("lambdaContext");
66
66
 
67
- var _lambdaDir = _classPrivateFieldLooseKey("lambdaDir");
67
+ var _lambdaDir = /*#__PURE__*/_classPrivateFieldLooseKey("lambdaDir");
68
68
 
69
- var _memorySize = _classPrivateFieldLooseKey("memorySize");
69
+ var _memorySize = /*#__PURE__*/_classPrivateFieldLooseKey("memorySize");
70
70
 
71
- var _region = _classPrivateFieldLooseKey("region");
71
+ var _region = /*#__PURE__*/_classPrivateFieldLooseKey("region");
72
72
 
73
- var _runtime = _classPrivateFieldLooseKey("runtime");
73
+ var _runtime = /*#__PURE__*/_classPrivateFieldLooseKey("runtime");
74
74
 
75
- var _timeout = _classPrivateFieldLooseKey("timeout");
75
+ var _timeout = /*#__PURE__*/_classPrivateFieldLooseKey("timeout");
76
76
 
77
77
  class LambdaFunction {
78
78
  // can be 'BUSY' or 'IDLE'
79
- constructor(functionKey, functionDefinition, serverless, options) {
79
+ constructor(functionKey, functionDefinition, serverless, options, v3Utils) {
80
80
  var _functionDefinition$p;
81
81
 
82
82
  Object.defineProperty(this, _artifact, {
@@ -158,10 +158,18 @@ class LambdaFunction {
158
158
  provider,
159
159
  package: servicePackage = {}
160
160
  }
161
- } = serverless; // TEMP options.location, for compatibility with serverless-webpack:
161
+ } = serverless;
162
+
163
+ if (v3Utils) {
164
+ this.log = v3Utils.log;
165
+ this.progress = v3Utils.progress;
166
+ this.writeText = v3Utils.writeText;
167
+ this.v3Utils = v3Utils;
168
+ } // TEMP options.location, for compatibility with serverless-webpack:
162
169
  // https://github.com/dherault/serverless-offline/issues/787
163
170
  // TODO FIXME look into better way to work with serverless-webpack
164
171
 
172
+
165
173
  const _servicePath = (0, _path.resolve)(servicePath, options.location || '');
166
174
 
167
175
  const {
@@ -216,7 +224,7 @@ class LambdaFunction {
216
224
  servicePackage: servicePackage.artifact ? (0, _path.resolve)(_servicePath, servicePackage.artifact) : undefined,
217
225
  functionPackage: functionPackage.artifact ? (0, _path.resolve)(_servicePath, functionPackage.artifact) : undefined
218
226
  };
219
- _classPrivateFieldLooseBase(this, _handlerRunner)[_handlerRunner] = new _index.default(funOptions, options, env);
227
+ _classPrivateFieldLooseBase(this, _handlerRunner)[_handlerRunner] = new _index.default(funOptions, options, env, v3Utils);
220
228
  _classPrivateFieldLooseBase(this, _lambdaContext)[_lambdaContext] = new _LambdaContext.default(name, memorySize);
221
229
  }
222
230
 
@@ -236,8 +244,13 @@ class LambdaFunction {
236
244
  // print message but keep working (don't error out or exit process)
237
245
  if (!_index2.supportedRuntimes.has(_classPrivateFieldLooseBase(this, _runtime)[_runtime])) {
238
246
  // this.printBlankLine(); // TODO
239
- console.log('');
240
- (0, _serverlessLog.default)(`Warning: found unsupported runtime '${_classPrivateFieldLooseBase(this, _runtime)[_runtime]}' for function '${_classPrivateFieldLooseBase(this, _functionKey)[_functionKey]}'`);
247
+ if (this.log) {
248
+ this.log.warning();
249
+ this.log.warning(`Warning: found unsupported runtime '${_classPrivateFieldLooseBase(this, _runtime)[_runtime]}' for function '${_classPrivateFieldLooseBase(this, _functionKey)[_functionKey]}'`);
250
+ } else {
251
+ console.log('');
252
+ (0, _serverlessLog.default)(`Warning: found unsupported runtime '${_classPrivateFieldLooseBase(this, _runtime)[_runtime]}' for function '${_classPrivateFieldLooseBase(this, _functionKey)[_functionKey]}'`);
253
+ }
241
254
  }
242
255
  } // based on:
243
256
  // https://github.com/serverless/serverless/blob/v1.50.0/lib/plugins/aws/invokeLocal/index.js#L108
@@ -358,7 +371,11 @@ class LambdaFunction {
358
371
 
359
372
 
360
373
  if (!_classPrivateFieldLooseBase(this, _handlerRunner)[_handlerRunner].isDockerRunner()) {
361
- (0, _serverlessLog.default)(`(λ: ${_classPrivateFieldLooseBase(this, _functionKey)[_functionKey]}) RequestId: ${requestId} Duration: ${this._executionTimeInMillis().toFixed(2)} ms Billed Duration: ${this._billedExecutionTimeInMillis()} ms`);
374
+ if (this.log) {
375
+ this.log.notice(`(λ: ${_classPrivateFieldLooseBase(this, _functionKey)[_functionKey]}) RequestId: ${requestId} Duration: ${this._executionTimeInMillis().toFixed(2)} ms Billed Duration: ${this._billedExecutionTimeInMillis()} ms`);
376
+ } else {
377
+ (0, _serverlessLog.default)(`(λ: ${_classPrivateFieldLooseBase(this, _functionKey)[_functionKey]}) RequestId: ${requestId} Duration: ${this._executionTimeInMillis().toFixed(2)} ms Billed Duration: ${this._billedExecutionTimeInMillis()} ms`);
378
+ }
362
379
  }
363
380
 
364
381
  this.status = 'IDLE';
@@ -15,16 +15,16 @@ var id = 0;
15
15
 
16
16
  function _classPrivateFieldLooseKey(name) { return "__private_" + id++ + "_" + name; }
17
17
 
18
- var _options = _classPrivateFieldLooseKey("options");
18
+ var _options = /*#__PURE__*/_classPrivateFieldLooseKey("options");
19
19
 
20
- var _pool = _classPrivateFieldLooseKey("pool");
20
+ var _pool = /*#__PURE__*/_classPrivateFieldLooseKey("pool");
21
21
 
22
- var _serverless = _classPrivateFieldLooseKey("serverless");
22
+ var _serverless = /*#__PURE__*/_classPrivateFieldLooseKey("serverless");
23
23
 
24
- var _timerRef = _classPrivateFieldLooseKey("timerRef");
24
+ var _timerRef = /*#__PURE__*/_classPrivateFieldLooseKey("timerRef");
25
25
 
26
26
  class LambdaFunctionPool {
27
- constructor(serverless, options) {
27
+ constructor(serverless, options, v3Utils) {
28
28
  Object.defineProperty(this, _options, {
29
29
  writable: true,
30
30
  value: null
@@ -42,7 +42,8 @@ class LambdaFunctionPool {
42
42
  value: null
43
43
  });
44
44
  _classPrivateFieldLooseBase(this, _options)[_options] = options;
45
- _classPrivateFieldLooseBase(this, _serverless)[_serverless] = serverless; // start cleaner
45
+ _classPrivateFieldLooseBase(this, _serverless)[_serverless] = serverless;
46
+ this.v3Utils = v3Utils; // start cleaner
46
47
 
47
48
  this._startCleanTimer();
48
49
  }
@@ -98,7 +99,7 @@ class LambdaFunctionPool {
98
99
  let lambdaFunction; // we don't have any instances
99
100
 
100
101
  if (lambdaFunctions == null) {
101
- lambdaFunction = new _LambdaFunction.default(functionKey, functionDefinition, _classPrivateFieldLooseBase(this, _serverless)[_serverless], _classPrivateFieldLooseBase(this, _options)[_options]);
102
+ lambdaFunction = new _LambdaFunction.default(functionKey, functionDefinition, _classPrivateFieldLooseBase(this, _serverless)[_serverless], _classPrivateFieldLooseBase(this, _options)[_options], this.v3Utils);
102
103
 
103
104
  _classPrivateFieldLooseBase(this, _pool)[_pool].set(functionKey, new Set([lambdaFunction]));
104
105
 
@@ -112,7 +113,7 @@ class LambdaFunctionPool {
112
113
  }) => status === 'IDLE'); // we don't have any IDLE instances
113
114
 
114
115
  if (lambdaFunction == null) {
115
- lambdaFunction = new _LambdaFunction.default(functionKey, functionDefinition, _classPrivateFieldLooseBase(this, _serverless)[_serverless], _classPrivateFieldLooseBase(this, _options)[_options]);
116
+ lambdaFunction = new _LambdaFunction.default(functionKey, functionDefinition, _classPrivateFieldLooseBase(this, _serverless)[_serverless], _classPrivateFieldLooseBase(this, _options)[_options], this.v3Utils);
116
117
  lambdaFunctions.add(lambdaFunction); // console.log(`${lambdaFunctions.size} lambdaFunctions`)
117
118
 
118
119
  return lambdaFunction;
@@ -15,9 +15,9 @@ var _index2 = require("../../utils/index.js");
15
15
 
16
16
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
17
 
18
- function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
18
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
19
19
 
20
- function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
20
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
21
21
 
22
22
  function _classPrivateFieldLooseBase(receiver, privateKey) { if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) { throw new TypeError("attempted to use private field on non-instance"); } return receiver; }
23
23
 
@@ -25,16 +25,16 @@ var id = 0;
25
25
 
26
26
  function _classPrivateFieldLooseKey(name) { return "__private_" + id++ + "_" + name; }
27
27
 
28
- var _env = _classPrivateFieldLooseKey("env");
28
+ var _env = /*#__PURE__*/_classPrivateFieldLooseKey("env");
29
29
 
30
- var _funOptions = _classPrivateFieldLooseKey("funOptions");
30
+ var _funOptions = /*#__PURE__*/_classPrivateFieldLooseKey("funOptions");
31
31
 
32
- var _options = _classPrivateFieldLooseKey("options");
32
+ var _options = /*#__PURE__*/_classPrivateFieldLooseKey("options");
33
33
 
34
- var _runner = _classPrivateFieldLooseKey("runner");
34
+ var _runner = /*#__PURE__*/_classPrivateFieldLooseKey("runner");
35
35
 
36
36
  class HandlerRunner {
37
- constructor(funOptions, options, env) {
37
+ constructor(funOptions, options, env, v3Utils) {
38
38
  Object.defineProperty(this, _env, {
39
39
  writable: true,
40
40
  value: null
@@ -54,6 +54,13 @@ class HandlerRunner {
54
54
  _classPrivateFieldLooseBase(this, _env)[_env] = env;
55
55
  _classPrivateFieldLooseBase(this, _funOptions)[_funOptions] = funOptions;
56
56
  _classPrivateFieldLooseBase(this, _options)[_options] = options;
57
+
58
+ if (v3Utils) {
59
+ this.log = v3Utils.log;
60
+ this.progress = v3Utils.progress;
61
+ this.writeText = v3Utils.writeText;
62
+ this.v3Utils = v3Utils;
63
+ }
57
64
  }
58
65
 
59
66
  async _loadRunner() {
@@ -72,12 +79,31 @@ class HandlerRunner {
72
79
  timeout
73
80
  } = _classPrivateFieldLooseBase(this, _funOptions)[_funOptions];
74
81
 
75
- (0, _debugLog.default)(`Loading handler... (${handlerPath})`);
82
+ if (this.log) {
83
+ this.log.debug(`Loading handler... (${handlerPath})`);
84
+ } else {
85
+ (0, _debugLog.default)(`Loading handler... (${handlerPath})`);
86
+ }
76
87
 
77
88
  if (useDocker) {
78
89
  // https://github.com/lambci/docker-lambda/issues/329
79
90
  if (runtime === 'nodejs14.x') {
80
- (0, _serverlessLog.logWarning)('"nodejs14.x" runtime is not supported with docker. See https://github.com/lambci/docker-lambda/issues/329');
91
+ if (this.log) {
92
+ this.log.warning('"nodejs14.x" runtime is not supported with docker. See https://github.com/lambci/docker-lambda/issues/329');
93
+ } else {
94
+ (0, _serverlessLog.logWarning)('"nodejs14.x" runtime is not supported with docker. See https://github.com/lambci/docker-lambda/issues/329');
95
+ }
96
+
97
+ throw new Error('Unsupported runtime');
98
+ }
99
+
100
+ if (runtime === 'python3.9') {
101
+ if (this.log) {
102
+ this.log.warning('"python3.9" runtime is not supported with docker.');
103
+ } else {
104
+ (0, _serverlessLog.logWarning)('"python3.9" runtime is not supported with docker.');
105
+ }
106
+
81
107
  throw new Error('Unsupported runtime');
82
108
  }
83
109
 
@@ -91,7 +117,7 @@ class HandlerRunner {
91
117
  const {
92
118
  default: DockerRunner
93
119
  } = await Promise.resolve().then(() => _interopRequireWildcard(require('./docker-runner/index.js')));
94
- return new DockerRunner(_classPrivateFieldLooseBase(this, _funOptions)[_funOptions], _classPrivateFieldLooseBase(this, _env)[_env], dockerOptions);
120
+ return new DockerRunner(_classPrivateFieldLooseBase(this, _funOptions)[_funOptions], _classPrivateFieldLooseBase(this, _env)[_env], dockerOptions, this.v3Utils);
95
121
  }
96
122
 
97
123
  if (_index.supportedNodejs.has(runtime)) {
@@ -99,7 +125,7 @@ class HandlerRunner {
99
125
  const {
100
126
  default: ChildProcessRunner
101
127
  } = await Promise.resolve().then(() => _interopRequireWildcard(require('./child-process-runner/index.js')));
102
- return new ChildProcessRunner(_classPrivateFieldLooseBase(this, _funOptions)[_funOptions], _classPrivateFieldLooseBase(this, _env)[_env], allowCache);
128
+ return new ChildProcessRunner(_classPrivateFieldLooseBase(this, _funOptions)[_funOptions], _classPrivateFieldLooseBase(this, _env)[_env], allowCache, this.v3Utils);
103
129
  }
104
130
 
105
131
  if (useWorkerThreads) {
@@ -122,21 +148,21 @@ class HandlerRunner {
122
148
  const {
123
149
  default: PythonRunner
124
150
  } = await Promise.resolve().then(() => _interopRequireWildcard(require('./python-runner/index.js')));
125
- return new PythonRunner(_classPrivateFieldLooseBase(this, _funOptions)[_funOptions], _classPrivateFieldLooseBase(this, _env)[_env], allowCache);
151
+ return new PythonRunner(_classPrivateFieldLooseBase(this, _funOptions)[_funOptions], _classPrivateFieldLooseBase(this, _env)[_env], allowCache, this.v3Utils);
126
152
  }
127
153
 
128
154
  if (_index.supportedRuby.has(runtime)) {
129
155
  const {
130
156
  default: RubyRunner
131
157
  } = await Promise.resolve().then(() => _interopRequireWildcard(require('./ruby-runner/index.js')));
132
- return new RubyRunner(_classPrivateFieldLooseBase(this, _funOptions)[_funOptions], _classPrivateFieldLooseBase(this, _env)[_env], allowCache);
158
+ return new RubyRunner(_classPrivateFieldLooseBase(this, _funOptions)[_funOptions], _classPrivateFieldLooseBase(this, _env)[_env], allowCache, this.v3Utils);
133
159
  }
134
160
 
135
161
  if (_index.supportedJava.has(runtime)) {
136
162
  const {
137
163
  default: JavaRunner
138
164
  } = await Promise.resolve().then(() => _interopRequireWildcard(require('./java-runner/index.js')));
139
- return new JavaRunner(_classPrivateFieldLooseBase(this, _funOptions)[_funOptions], _classPrivateFieldLooseBase(this, _env)[_env], allowCache);
165
+ return new JavaRunner(_classPrivateFieldLooseBase(this, _funOptions)[_funOptions], _classPrivateFieldLooseBase(this, _env)[_env], allowCache, this.v3Utils);
140
166
  } // TODO FIXME
141
167
 
142
168
 
@@ -151,9 +177,16 @@ class HandlerRunner {
151
177
  const versionIsSatisfied = (0, _index2.satisfiesVersionRange)(currentVersion, requiredVersionRange); // we're happy
152
178
 
153
179
  if (!versionIsSatisfied) {
154
- (0, _serverlessLog.logWarning)(`"worker threads" require node.js version ${requiredVersionRange}, but found version ${currentVersion}.
180
+ if (this.log) {
181
+ this.log.warning(`"worker threads" require node.js version ${requiredVersionRange}, but found version ${currentVersion}.
182
+ To use this feature you have to update node.js to a later version.
183
+ `);
184
+ } else {
185
+ (0, _serverlessLog.logWarning)(`"worker threads" require node.js version ${requiredVersionRange}, but found version ${currentVersion}.
155
186
  To use this feature you have to update node.js to a later version.
156
187
  `);
188
+ }
189
+
157
190
  throw new Error('"worker threads" are not supported with this node.js version');
158
191
  }
159
192
  } // TEMP TODO FIXME
@@ -19,20 +19,20 @@ function _classPrivateFieldLooseKey(name) { return "__private_" + id++ + "_" + n
19
19
 
20
20
  const childProcessHelperPath = _path.default.resolve(__dirname, 'childProcessHelper.js');
21
21
 
22
- var _env = _classPrivateFieldLooseKey("env");
22
+ var _env = /*#__PURE__*/_classPrivateFieldLooseKey("env");
23
23
 
24
- var _functionKey = _classPrivateFieldLooseKey("functionKey");
24
+ var _functionKey = /*#__PURE__*/_classPrivateFieldLooseKey("functionKey");
25
25
 
26
- var _handlerName = _classPrivateFieldLooseKey("handlerName");
26
+ var _handlerName = /*#__PURE__*/_classPrivateFieldLooseKey("handlerName");
27
27
 
28
- var _handlerPath = _classPrivateFieldLooseKey("handlerPath");
28
+ var _handlerPath = /*#__PURE__*/_classPrivateFieldLooseKey("handlerPath");
29
29
 
30
- var _timeout = _classPrivateFieldLooseKey("timeout");
30
+ var _timeout = /*#__PURE__*/_classPrivateFieldLooseKey("timeout");
31
31
 
32
- var _allowCache = _classPrivateFieldLooseKey("allowCache");
32
+ var _allowCache = /*#__PURE__*/_classPrivateFieldLooseKey("allowCache");
33
33
 
34
34
  class ChildProcessRunner {
35
- constructor(funOptions, env, allowCache) {
35
+ constructor(funOptions, env, allowCache, v3Utils) {
36
36
  Object.defineProperty(this, _env, {
37
37
  writable: true,
38
38
  value: null
@@ -63,6 +63,14 @@ class ChildProcessRunner {
63
63
  handlerPath,
64
64
  timeout
65
65
  } = funOptions;
66
+
67
+ if (v3Utils) {
68
+ this.log = v3Utils.log;
69
+ this.progress = v3Utils.progress;
70
+ this.writeText = v3Utils.writeText;
71
+ this.v3Utils = v3Utils;
72
+ }
73
+
66
74
  _classPrivateFieldLooseBase(this, _env)[_env] = env;
67
75
  _classPrivateFieldLooseBase(this, _functionKey)[_functionKey] = functionKey;
68
76
  _classPrivateFieldLooseBase(this, _handlerName)[_handlerName] = handlerName;
@@ -99,7 +107,12 @@ class ChildProcessRunner {
99
107
  result = await message;
100
108
  } catch (err) {
101
109
  // TODO
102
- console.log(err);
110
+ if (this.log) {
111
+ this.log.error(err);
112
+ } else {
113
+ console.log(err);
114
+ }
115
+
103
116
  throw err;
104
117
  }
105
118
 
@@ -34,16 +34,7 @@ process.on('message', async messageData => {
34
34
  } = messageData; // TODO we could probably cache this in the module scope?
35
35
 
36
36
  const inProcessRunner = new _index.default(functionKey, handlerPath, handlerName, process.env, timeout, allowCache);
37
- let result;
38
-
39
- try {
40
- result = await inProcessRunner.run(event, context);
41
- } catch (err) {
42
- // TODO logging
43
- console.log(err);
44
- throw err;
45
- } // TODO check serializeability (contains function, symbol etc)
46
-
37
+ const result = await inProcessRunner.run(event, context); // TODO check serializeability (contains function, symbol etc)
47
38
 
48
39
  process.send(result);
49
40
  });