serverless-offline 13.7.0 → 13.8.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.
package/README.md CHANGED
@@ -1,5 +1,27 @@
1
1
  # Serverless Offline
2
2
 
3
+ <div align="center">
4
+ <p>
5
+ <sup>
6
+ <a href="https://github.com/sponsors/dherault">Serverless-offline is supported by the community.</a>
7
+ </sup>
8
+ </p>
9
+ <sup>
10
+ Special thanks to:
11
+ </sup>
12
+ <a href="https://arccode.dev?ref=so">
13
+ <div>
14
+ <img src="https://arccode.dev/images/logotype.png" height="64" alt="Arccode">
15
+ </div>
16
+ <b>
17
+ The first role-playing game for developers
18
+ </b>
19
+ <div>
20
+ XP, level ups and guilds. All while you work.
21
+ </div>
22
+ </a>
23
+ </div>
24
+ &nbsp;
3
25
  <p>
4
26
  <a href="https://www.serverless.com">
5
27
  <img src="http://public.serverless.com/badges/v3.svg">
@@ -243,6 +265,11 @@ Default: 600 (10 minutes)
243
265
  WebSocket port to listen on.<br />
244
266
  Default: 3001
245
267
 
268
+ #### preLoadModules
269
+
270
+ Pre-load specified modules in the main thread to avoid crashes when importing in worker threads. Provide module names as a comma-separated list (e.g., "sharp,canvas").<br />
271
+ Default: ''
272
+
246
273
  Any of the CLI options can be added to your `serverless.yml`. For example:
247
274
 
248
275
  ```yml
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "serverless-offline",
3
- "version": "13.7.0",
3
+ "version": "13.8.0",
4
4
  "description": "Emulate AWS λ and API Gateway locally when developing your Serverless project",
5
5
  "license": "MIT",
6
6
  "exports": {
@@ -65,6 +65,8 @@ export default class ServerlessOffline {
65
65
  async start() {
66
66
  this.#mergeOptions()
67
67
 
68
+ this.#preLoadModules()
69
+
68
70
  if (this.#cliOptions.noSponsor) {
69
71
  log.notice()
70
72
  } else {
@@ -423,6 +425,20 @@ export default class ServerlessOffline {
423
425
  }
424
426
  }
425
427
 
428
+ #preLoadModules() {
429
+ const modules = this.#options.preLoadModules.split(",")
430
+
431
+ modules.forEach((module) => {
432
+ if (!module) return
433
+
434
+ try {
435
+ import(module)
436
+ } catch (error) {
437
+ log.error(`Error importing module ${module}: ${error}`)
438
+ }
439
+ })
440
+ }
441
+
426
442
  // TODO FIXME
427
443
  // TEMP quick fix to expose for testing, look for better solution
428
444
  internals() {
@@ -446,6 +462,10 @@ export default class ServerlessOffline {
446
462
  mergeOptions: () => {
447
463
  this.#mergeOptions()
448
464
  },
465
+
466
+ preLoadModules: () => {
467
+ this.#preLoadModules()
468
+ },
449
469
  }
450
470
  }
451
471
  }
@@ -104,6 +104,10 @@ export default {
104
104
  usage:
105
105
  "Adds a prefix to every path, to send your requests to http://localhost:3000/prefix/[your_path] instead.",
106
106
  },
107
+ preLoadModules: {
108
+ type: "string",
109
+ usage: "A comma separated list of modules to preload on the main thread",
110
+ },
107
111
  reloadHandler: {
108
112
  type: "boolean",
109
113
  usage: "Reloads handler with each request.",
@@ -20,6 +20,7 @@ export default {
20
20
  noPrependStageInUrl: false,
21
21
  noTimeout: false,
22
22
  prefix: "",
23
+ preLoadModules: "",
23
24
  reloadHandler: false,
24
25
  resourceRoutes: false,
25
26
  terminateIdleLambdaTime: 60,
@@ -104,8 +104,6 @@ export default class PythonRunner {
104
104
  })
105
105
 
106
106
  const onErr = (data) => {
107
- // TODO
108
-
109
107
  log.notice(data.toString())
110
108
  }
111
109
 
@@ -104,7 +104,7 @@ if __name__ == '__main__':
104
104
  '__offline_payload__': result
105
105
  }
106
106
 
107
- if isinstance(result['body'], bytes):
107
+ if hasattr(result, 'body') and isinstance(result['body'], bytes):
108
108
  data['__offline_payload__']['body'] = base64.b64encode(result['body']).decode('utf-8')
109
109
  data['isBase64Encoded'] = True
110
110