serverless-offline 9.2.2 → 9.2.5

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
@@ -137,7 +137,7 @@ All CLI options are optional:
137
137
  --printOutput Turns on logging of your lambda outputs in the terminal.
138
138
  --reloadHandler Reloads handler with each request.
139
139
  --resourceRoutes Turns on loading of your HTTP proxy settings from serverless.yml
140
- --useChildProcesses Run handlers in a child process
140
+ --useChildProcesses [This option is deprecated] Run handlers in a child process.
141
141
  --useDocker Run handlers in a docker container.
142
142
  --useInProcess Run handlers in the same process as 'serverless-offline'.
143
143
  --webSocketHardTimeout Set WebSocket hard timeout in seconds to reproduce AWS limits (https://docs.aws.amazon.com/apigateway/latest/developerguide/limits.html#apigateway-execution-service-websocket-limits-table). Default: 7200 (2 hours)
@@ -188,7 +188,7 @@ Lambda handlers for the `node.js` runtime can run in different execution modes w
188
188
  - global state is being shared across lambda handlers as well as with `serverless` and `serverless-offline`
189
189
  - easy debugging
190
190
 
191
- #### child-processes
191
+ #### child-processes (this option is deprecated, please use the default worker-threads instead)
192
192
 
193
193
  - handlers run in a separate node.js instance
194
194
  - memory is not being shared between handlers, memory consumption is therefore higher
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "dedicatedTo": "Blue, a great migrating bird.",
3
3
  "name": "serverless-offline",
4
- "version": "9.2.2",
4
+ "version": "9.2.5",
5
5
  "description": "Emulate AWS λ and API Gateway locally when developing your Serverless project",
6
6
  "license": "MIT",
7
7
  "main": "./src/index.js",
@@ -1,12 +1,12 @@
1
1
  import process, { exit } from 'node:process'
2
2
  import { log } from '@serverless/utils/log.js'
3
- import chalk from 'chalk'
4
3
  import {
5
4
  commandOptions,
6
5
  CUSTOM_OPTION,
7
6
  defaultOptions,
8
7
  SERVER_SHUTDOWN_TIMEOUT,
9
8
  } from './config/index.js'
9
+ import { gray, orange } from './config/colors.js'
10
10
 
11
11
  export default class ServerlessOffline {
12
12
  #cliOptions = null
@@ -225,6 +225,14 @@ export default class ServerlessOffline {
225
225
  ...this.#cliOptions,
226
226
  }
227
227
 
228
+ if (this.#options.useChildProcesses) {
229
+ log.notice()
230
+ log.warning(
231
+ orange(`'--useChildProcesses' is deprecated and will be removed in the next major version. Worker threads, the current default, should provide the same if not an even better developer experience.
232
+ If you are experiencing any issues please let us know: https://github.com/dherault/serverless-offline/issues`),
233
+ )
234
+ }
235
+
228
236
  // Parse CORS options
229
237
  this.#options.corsAllowHeaders = this.#options.corsAllowHeaders
230
238
  .replace(/\s/g, '')
@@ -247,7 +255,7 @@ export default class ServerlessOffline {
247
255
  log.notice(
248
256
  `Starting Offline at stage ${
249
257
  this.#options.stage || provider.stage
250
- } ${chalk.gray(`(${this.#options.region || provider.region})`)}`,
258
+ } ${gray(`(${this.#options.region || provider.region})`)}`,
251
259
  )
252
260
  log.notice()
253
261
  log.debug('options:', this.#options)
@@ -0,0 +1,10 @@
1
+ import chalk from 'chalk'
2
+
3
+ export const dodgerblue = chalk.hex('#1e90ff')
4
+ export const gray = chalk.hex('#808080')
5
+ export const lime = chalk.hex('#00ff00')
6
+ export const orange = chalk.hex('#ffa500')
7
+ export const peachpuff = chalk.hex('#ffdab9')
8
+ export const plum = chalk.hex('#dda0dd')
9
+ export const red = chalk.hex('#ff0000')
10
+ export const yellow = chalk.hex('#ffff00')
@@ -132,7 +132,8 @@ export default {
132
132
  },
133
133
  useChildProcesses: {
134
134
  type: 'boolean',
135
- usage: 'Use separate node process to run handlers',
135
+ usage:
136
+ '[This option is deprecated] Use separate node process to run handlers.',
136
137
  },
137
138
  useDocker: {
138
139
  type: 'boolean',
@@ -10,11 +10,11 @@ const __dirname = dirname(fileURLToPath(import.meta.url))
10
10
 
11
11
  // velocity template defaults
12
12
  const defaultRequestTemplate = readFileSync(
13
- resolve(__dirname, './templates/offline-default.req.vm'),
13
+ resolve(__dirname, 'templates/offline-default.req.vm'),
14
14
  'utf8',
15
15
  )
16
16
  const defaultResponseTemplate = readFileSync(
17
- resolve(__dirname, './templates/offline-default.res.vm'),
17
+ resolve(__dirname, 'templates/offline-default.res.vm'),
18
18
  'utf8',
19
19
  )
20
20
 
@@ -788,12 +788,6 @@ export default class HttpServer {
788
788
  response.variety = 'buffer'
789
789
  } else if (typeof result === 'string') {
790
790
  response.source = stringify(result)
791
- } else if (result && result.body && typeof result.body !== 'string') {
792
- return this.#reply502(
793
- response,
794
- 'According to the API Gateway specs, the body content must be stringified. Check your Lambda response and make sure you are invoking JSON.stringify(YOUR_CONTENT) on your body object',
795
- {},
796
- )
797
791
  } else {
798
792
  response.source = result
799
793
  }
@@ -888,6 +882,7 @@ export default class HttpServer {
888
882
  response.variety = 'buffer'
889
883
  } else {
890
884
  if (result && result.body && typeof result.body !== 'string') {
885
+ // FIXME TODO we should probably just write to console instead of returning a payload
891
886
  return this.#reply502(
892
887
  response,
893
888
  'According to the API Gateway specs, the body content must be stringified. Check your Lambda response and make sure you are invoking JSON.stringify(YOUR_CONTENT) on your body object',
@@ -1,20 +1,24 @@
1
1
  import { log } from '@serverless/utils/log.js'
2
2
 
3
+ function buildFailureResult(warningMessage) {
4
+ log.warning(warningMessage)
5
+
6
+ return {
7
+ unsupportedAuth: true,
8
+ }
9
+ }
10
+
11
+ function buildSuccessResult(authorizerName) {
12
+ return {
13
+ authorizerName,
14
+ }
15
+ }
16
+
3
17
  export default function authJWTSettingsExtractor(
4
18
  endpoint,
5
19
  provider,
6
20
  ignoreJWTSignature,
7
21
  ) {
8
- const buildFailureResult = (warningMessage) => {
9
- log.warning(warningMessage)
10
-
11
- return {
12
- unsupportedAuth: true,
13
- }
14
- }
15
-
16
- const buildSuccessResult = (authorizerName) => ({ authorizerName })
17
-
18
22
  const { authorizer } = endpoint
19
23
 
20
24
  if (!authorizer) {
@@ -59,7 +59,7 @@ export default class ChildProcessRunner {
59
59
  rej(data.error)
60
60
  return
61
61
  }
62
- res(data)
62
+ res(data.result)
63
63
  })
64
64
  })
65
65
  } catch (err) {
@@ -41,5 +41,5 @@ process.on('message', async (messageData) => {
41
41
  const result = await inProcessRunner.run(event, context)
42
42
 
43
43
  // TODO check serializeability (contains function, symbol etc)
44
- process.send(result)
44
+ process.send({ result })
45
45
  })
@@ -3,7 +3,7 @@ import { fileURLToPath } from 'node:url'
3
3
  import { MessageChannel, Worker } from 'node:worker_threads'
4
4
 
5
5
  const __dirname = dirname(fileURLToPath(import.meta.url))
6
- const workerThreadHelperPath = resolve(__dirname, './workerThreadHelper.js')
6
+ const workerThreadHelperPath = resolve(__dirname, 'workerThreadHelper.js')
7
7
 
8
8
  export default class WorkerThreadRunner {
9
9
  #workerThread = null
@@ -1,17 +1,17 @@
1
1
  import boxen from 'boxen'
2
- import chalk from 'chalk'
2
+ import {
3
+ dodgerblue,
4
+ gray,
5
+ lime,
6
+ orange,
7
+ peachpuff,
8
+ plum,
9
+ red,
10
+ yellow,
11
+ } from '../config/colors.js'
3
12
 
4
13
  const { max } = Math
5
14
 
6
- const dodgerblue = chalk.hex('#1e90ff')
7
- const grey = chalk.hex('#808080')
8
- const lime = chalk.hex('#00ff00')
9
- const orange = chalk.hex('#ffa500')
10
- const peachpuff = chalk.hex('#ffdab9')
11
- const plum = chalk.hex('#dda0dd')
12
- const red = chalk.hex('#ff0000')
13
- const yellow = chalk.hex('#ffff00')
14
-
15
15
  const colorMethodMapping = new Map([
16
16
  ['DELETE', red],
17
17
  ['GET', dodgerblue],
@@ -28,9 +28,9 @@ function logRoute(method, server, path, maxLength, dimPath = false) {
28
28
  const methodColor = colorMethodMapping.get(method) ?? peachpuff
29
29
  const methodFormatted = method.padEnd(maxLength, ' ')
30
30
 
31
- return `${methodColor(methodFormatted)} ${yellow.dim('|')} ${grey.dim(
31
+ return `${methodColor(methodFormatted)} ${yellow.dim('|')} ${gray.dim(
32
32
  server,
33
- )}${dimPath ? grey.dim(path) : lime(path)}`
33
+ )}${dimPath ? gray.dim(path) : lime(path)}`
34
34
  }
35
35
 
36
36
  function getMaxHttpMethodNameLength(routeInfo) {
@@ -51,7 +51,7 @@ export default function logRoutes(routeInfo) {
51
51
  boxen(
52
52
  routeInfo
53
53
  .map(
54
- ({ method, path, server, invokePath }) =>
54
+ ({ invokePath, method, path, server }) =>
55
55
  // eslint-disable-next-line prefer-template
56
56
  logRoute(method, server, path, maxLength) +
57
57
  '\n' +