serverless-offline 13.3.1 → 13.3.3
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 +17 -17
- package/package.json +14 -13
- package/src/ServerlessOffline.js +42 -42
- package/src/config/colors.js +9 -9
- package/src/config/commandOptions.js +61 -61
- package/src/config/constants.js +5 -5
- package/src/config/defaultOptions.js +6 -6
- package/src/config/index.js +4 -4
- package/src/config/supportedRuntimes.js +18 -18
- package/src/errors/index.js +1 -1
- package/src/events/alb/Alb.js +2 -2
- package/src/events/alb/AlbEventDefinition.js +2 -2
- package/src/events/alb/HttpServer.js +54 -54
- package/src/events/alb/index.js +1 -1
- package/src/events/alb/lambda-events/LambdaAlbRequestEvent.js +2 -2
- package/src/events/alb/lambda-events/index.js +1 -1
- package/src/events/authCanExecuteResource.js +3 -3
- package/src/events/authFunctionNameExtractor.js +9 -9
- package/src/events/authMatchPolicyResource.js +8 -8
- package/src/events/authValidateContext.js +11 -11
- package/src/events/http/Endpoint.js +26 -26
- package/src/events/http/Http.js +2 -2
- package/src/events/http/HttpEventDefinition.js +2 -2
- package/src/events/http/HttpServer.js +156 -156
- package/src/events/http/OfflineEndpoint.js +7 -7
- package/src/events/http/authJWTSettingsExtractor.js +2 -2
- package/src/events/http/createAuthScheme.js +29 -27
- package/src/events/http/createJWTAuthScheme.js +12 -12
- package/src/events/http/index.js +1 -1
- package/src/events/http/javaHelpers.js +2 -2
- package/src/events/http/lambda-events/LambdaIntegrationEvent.js +5 -5
- package/src/events/http/lambda-events/LambdaProxyIntegrationEvent.js +47 -47
- package/src/events/http/lambda-events/LambdaProxyIntegrationEventV2.js +27 -27
- package/src/events/http/lambda-events/VelocityContext.js +28 -32
- package/src/events/http/lambda-events/index.js +4 -4
- package/src/events/http/lambda-events/renderVelocityTemplateObject.js +13 -13
- package/src/events/http/parseResources.js +6 -6
- package/src/events/http/payloadSchemaValidator.js +2 -2
- package/src/events/schedule/Schedule.js +21 -21
- package/src/events/schedule/ScheduleEvent.js +7 -7
- package/src/events/schedule/ScheduleEventDefinition.js +1 -1
- package/src/events/schedule/index.js +1 -1
- package/src/events/websocket/HttpServer.js +9 -9
- package/src/events/websocket/WebSocket.js +4 -4
- package/src/events/websocket/WebSocketClients.js +29 -29
- package/src/events/websocket/WebSocketEventDefinition.js +1 -1
- package/src/events/websocket/WebSocketServer.js +9 -9
- package/src/events/websocket/http-routes/_catchAll/catchAllRoute.js +3 -3
- package/src/events/websocket/http-routes/_catchAll/index.js +1 -1
- package/src/events/websocket/http-routes/connections/ConnectionsController.js +1 -1
- package/src/events/websocket/http-routes/connections/connectionsRoutes.js +6 -6
- package/src/events/websocket/http-routes/connections/index.js +1 -1
- package/src/events/websocket/http-routes/index.js +2 -2
- package/src/events/websocket/index.js +1 -1
- package/src/events/websocket/lambda-events/WebSocketAuthorizerEvent.js +5 -5
- package/src/events/websocket/lambda-events/WebSocketConnectEvent.js +7 -6
- package/src/events/websocket/lambda-events/WebSocketDisconnectEvent.js +5 -5
- package/src/events/websocket/lambda-events/WebSocketEvent.js +2 -2
- package/src/events/websocket/lambda-events/WebSocketRequestContext.js +12 -11
- package/src/events/websocket/lambda-events/index.js +4 -4
- package/src/index.js +1 -1
- package/src/lambda/HttpServer.js +11 -11
- package/src/lambda/Lambda.js +2 -2
- package/src/lambda/LambdaContext.js +1 -1
- package/src/lambda/LambdaFunction.js +34 -34
- package/src/lambda/LambdaFunctionPool.js +3 -3
- package/src/lambda/handler-runner/HandlerRunner.js +12 -12
- package/src/lambda/handler-runner/docker-runner/DockerContainer.js +59 -59
- package/src/lambda/handler-runner/docker-runner/DockerImage.js +6 -6
- package/src/lambda/handler-runner/docker-runner/DockerRunner.js +2 -2
- package/src/lambda/handler-runner/docker-runner/index.js +1 -1
- package/src/lambda/handler-runner/go-runner/GoRunner.js +34 -34
- package/src/lambda/handler-runner/go-runner/index.js +1 -1
- package/src/lambda/handler-runner/in-process-runner/InProcessRunner.js +7 -7
- package/src/lambda/handler-runner/in-process-runner/aws-lambda-ric/UserFunction.js +52 -52
- package/src/lambda/handler-runner/in-process-runner/index.js +1 -1
- package/src/lambda/handler-runner/index.js +1 -1
- package/src/lambda/handler-runner/java-runner/JavaRunner.js +13 -13
- package/src/lambda/handler-runner/java-runner/index.js +1 -1
- package/src/lambda/handler-runner/python-runner/PythonRunner.js +21 -21
- package/src/lambda/handler-runner/python-runner/index.js +1 -1
- package/src/lambda/handler-runner/ruby-runner/RubyRunner.js +11 -11
- package/src/lambda/handler-runner/ruby-runner/index.js +1 -1
- package/src/lambda/handler-runner/worker-thread-runner/WorkerThreadRunner.js +6 -6
- package/src/lambda/handler-runner/worker-thread-runner/index.js +1 -1
- package/src/lambda/handler-runner/worker-thread-runner/workerThreadHelper.js +4 -4
- package/src/lambda/index.js +1 -1
- package/src/lambda/routes/index.js +2 -2
- package/src/lambda/routes/invocations/InvocationsController.js +11 -11
- package/src/lambda/routes/invocations/index.js +1 -1
- package/src/lambda/routes/invocations/invocationsRoute.js +15 -15
- package/src/lambda/routes/invoke-async/index.js +1 -1
- package/src/lambda/routes/invoke-async/invokeAsyncRoute.js +6 -6
- package/src/utils/checkDockerDaemon.js +8 -8
- package/src/utils/checkGoVersion.js +3 -3
- package/src/utils/createApiKey.js +2 -2
- package/src/utils/detectExecutable.js +2 -2
- package/src/utils/formatToClfTime.js +2 -2
- package/src/utils/generateHapiPath.js +8 -8
- package/src/utils/getApiKeysValues.js +10 -2
- package/src/utils/getHttpApiCorsConfig.js +11 -11
- package/src/utils/getRawQueryParams.js +2 -2
- package/src/utils/index.js +25 -26
- package/src/utils/jsonPath.js +1 -1
- package/src/utils/logRoutes.js +13 -13
- package/src/utils/parseHeaders.js +1 -1
- package/src/utils/parseMultiValueHeaders.js +1 -1
- package/src/utils/parseMultiValueQueryStringParameters.js +1 -1
- package/src/utils/parseQueryStringParameters.js +1 -1
- package/src/utils/parseQueryStringParametersForPayloadV2.js +1 -1
- package/src/utils/splitHandlerPathAndName.js +3 -3
- package/src/utils/createUniqueId.js +0 -5
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { mkdir, readFile, rm, rmdir, writeFile } from
|
|
2
|
-
import { EOL } from
|
|
3
|
-
import process, { chdir, cwd } from
|
|
4
|
-
import { parse as pathParse, resolve, sep } from
|
|
5
|
-
import { log } from
|
|
6
|
-
import { execa } from
|
|
7
|
-
import { splitHandlerPathAndName } from
|
|
1
|
+
import { mkdir, readFile, rm, rmdir, writeFile } from "node:fs/promises"
|
|
2
|
+
import { EOL } from "node:os"
|
|
3
|
+
import process, { chdir, cwd } from "node:process"
|
|
4
|
+
import { parse as pathParse, resolve, sep } from "node:path"
|
|
5
|
+
import { log } from "@serverless/utils/log.js"
|
|
6
|
+
import { execa } from "execa"
|
|
7
|
+
import { splitHandlerPathAndName } from "../../../utils/index.js"
|
|
8
8
|
|
|
9
9
|
const { parse, stringify } = JSON
|
|
10
10
|
|
|
11
11
|
export default class GoRunner {
|
|
12
|
-
static #payloadIdentifier =
|
|
12
|
+
static #payloadIdentifier = "offline_payload"
|
|
13
13
|
|
|
14
14
|
#codeDir = null
|
|
15
15
|
|
|
@@ -36,21 +36,21 @@ export default class GoRunner {
|
|
|
36
36
|
try {
|
|
37
37
|
// refresh go.mod
|
|
38
38
|
await rm(this.#tmpFile)
|
|
39
|
-
await execa(
|
|
39
|
+
await execa("go", ["mod", "tidy"])
|
|
40
40
|
|
|
41
41
|
if (this.workspace && this.#tmpPath) {
|
|
42
42
|
const workPath = `${this.#codeDir}/go.work`
|
|
43
|
-
const workFile = await readFile(workPath,
|
|
43
|
+
const workFile = await readFile(workPath, "utf8")
|
|
44
44
|
|
|
45
|
-
const out = workFile.replace(this.#tmpPath,
|
|
45
|
+
const out = workFile.replace(this.#tmpPath, "")
|
|
46
46
|
|
|
47
47
|
try {
|
|
48
|
-
await writeFile(workPath, out,
|
|
48
|
+
await writeFile(workPath, out, "utf8")
|
|
49
49
|
} catch {
|
|
50
50
|
// @ignore
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
await execa(
|
|
53
|
+
await execa("go", ["work", "sync"])
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
await rmdir(this.#tmpPath, {
|
|
@@ -97,10 +97,10 @@ export default class GoRunner {
|
|
|
97
97
|
async run(event, context) {
|
|
98
98
|
const { dir } = pathParse(this.#handlerPath)
|
|
99
99
|
const handlerCodeRoot = dir.split(sep).slice(0, -1).join(sep)
|
|
100
|
-
const handlerCode = await readFile(`${this.#handlerPath}.go`,
|
|
100
|
+
const handlerCode = await readFile(`${this.#handlerPath}.go`, "utf8")
|
|
101
101
|
|
|
102
|
-
this.#tmpPath = resolve(handlerCodeRoot,
|
|
103
|
-
this.#tmpFile = resolve(this.#tmpPath,
|
|
102
|
+
this.#tmpPath = resolve(handlerCodeRoot, "tmp")
|
|
103
|
+
this.#tmpFile = resolve(this.#tmpPath, "main.go")
|
|
104
104
|
|
|
105
105
|
const out = handlerCode.replace(
|
|
106
106
|
'"github.com/aws/aws-lambda-go/lambda"',
|
|
@@ -114,53 +114,53 @@ export default class GoRunner {
|
|
|
114
114
|
}
|
|
115
115
|
|
|
116
116
|
try {
|
|
117
|
-
await writeFile(this.#tmpFile, out,
|
|
117
|
+
await writeFile(this.#tmpFile, out, "utf8")
|
|
118
118
|
} catch {
|
|
119
119
|
// @ignore
|
|
120
120
|
}
|
|
121
121
|
|
|
122
122
|
// Get go env to run this locally
|
|
123
123
|
if (!this.#goEnv) {
|
|
124
|
-
const goEnvResponse = await execa(
|
|
125
|
-
encoding:
|
|
126
|
-
stdio:
|
|
124
|
+
const goEnvResponse = await execa("go", ["env"], {
|
|
125
|
+
encoding: "utf8",
|
|
126
|
+
stdio: "pipe",
|
|
127
127
|
})
|
|
128
128
|
|
|
129
129
|
const goEnvString = goEnvResponse.stdout || goEnvResponse.stderr
|
|
130
130
|
this.#goEnv = goEnvString.split(EOL).reduce((a, b) => {
|
|
131
131
|
const [k, v] = b.split('="')
|
|
132
132
|
// eslint-disable-next-line no-param-reassign
|
|
133
|
-
a[k] = v ? v.slice(0, -1) :
|
|
133
|
+
a[k] = v ? v.slice(0, -1) : ""
|
|
134
134
|
return a
|
|
135
135
|
}, {})
|
|
136
136
|
}
|
|
137
137
|
|
|
138
138
|
// Remove our root, since we want to invoke go relatively
|
|
139
|
-
const cwdPath = `${this.#tmpFile}`.replace(`${cwd()}${sep}`,
|
|
139
|
+
const cwdPath = `${this.#tmpFile}`.replace(`${cwd()}${sep}`, "")
|
|
140
140
|
|
|
141
141
|
try {
|
|
142
|
-
chdir(cwdPath.substring(0, cwdPath.indexOf(
|
|
142
|
+
chdir(cwdPath.substring(0, cwdPath.indexOf("main.go")))
|
|
143
143
|
|
|
144
144
|
if (this.workspace) {
|
|
145
145
|
/**
|
|
146
146
|
* We need to initialize the module, as in the case of a workspace it will not already exist
|
|
147
147
|
*/
|
|
148
|
-
await execa(
|
|
149
|
-
await execa(
|
|
148
|
+
await execa("go", ["mod", "init", "tmp"])
|
|
149
|
+
await execa("go", ["work", "use", this.#tmpPath])
|
|
150
150
|
}
|
|
151
151
|
|
|
152
152
|
// Make sure we have the mock-lambda runner
|
|
153
|
-
await execa(
|
|
154
|
-
|
|
155
|
-
|
|
153
|
+
await execa("go", [
|
|
154
|
+
"get",
|
|
155
|
+
"github.com/icarus-sullivan/mock-lambda@e065469",
|
|
156
156
|
])
|
|
157
|
-
await execa(
|
|
157
|
+
await execa("go", ["build"])
|
|
158
158
|
} catch {
|
|
159
159
|
// @ignore
|
|
160
160
|
}
|
|
161
161
|
|
|
162
162
|
const { stdout, stderr } = await execa(`./tmp`, {
|
|
163
|
-
encoding:
|
|
163
|
+
encoding: "utf8",
|
|
164
164
|
env: {
|
|
165
165
|
...this.#env,
|
|
166
166
|
...this.#goEnv,
|
|
@@ -170,15 +170,15 @@ export default class GoRunner {
|
|
|
170
170
|
AWS_LAMBDA_LOG_GROUP_NAME: context.logGroupName,
|
|
171
171
|
AWS_LAMBDA_LOG_STREAM_NAME: context.logStreamName,
|
|
172
172
|
IS_LAMBDA_AUTHORIZER:
|
|
173
|
-
event.type ===
|
|
174
|
-
IS_LAMBDA_REQUEST_AUTHORIZER: event.type ===
|
|
175
|
-
IS_LAMBDA_TOKEN_AUTHORIZER: event.type ===
|
|
173
|
+
event.type === "REQUEST" || event.type === "TOKEN",
|
|
174
|
+
IS_LAMBDA_REQUEST_AUTHORIZER: event.type === "REQUEST",
|
|
175
|
+
IS_LAMBDA_TOKEN_AUTHORIZER: event.type === "TOKEN",
|
|
176
176
|
LAMBDA_CONTEXT: stringify(context),
|
|
177
177
|
LAMBDA_EVENT: stringify(event),
|
|
178
178
|
LAMBDA_TEST_EVENT: `${event}`,
|
|
179
179
|
PATH: process.env.PATH,
|
|
180
180
|
},
|
|
181
|
-
stdio:
|
|
181
|
+
stdio: "pipe",
|
|
182
182
|
})
|
|
183
183
|
|
|
184
184
|
await this.cleanup()
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { default } from
|
|
1
|
+
export { default } from "./GoRunner.js"
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { join } from
|
|
2
|
-
import { performance } from
|
|
3
|
-
import process from
|
|
4
|
-
import { load } from
|
|
1
|
+
import { join } from "node:path"
|
|
2
|
+
import { performance } from "node:perf_hooks"
|
|
3
|
+
import process from "node:process"
|
|
4
|
+
import { load } from "./aws-lambda-ric/UserFunction.js"
|
|
5
5
|
|
|
6
6
|
const { floor } = Math
|
|
7
7
|
const { assign } = Object
|
|
@@ -47,8 +47,8 @@ export default class InProcessRunner {
|
|
|
47
47
|
|
|
48
48
|
const callbackWrapper = new Promise((res, rej) => {
|
|
49
49
|
callback = (err, data) => {
|
|
50
|
-
if (err ===
|
|
51
|
-
res(
|
|
50
|
+
if (err === "Unauthorized") {
|
|
51
|
+
res("Unauthorized")
|
|
52
52
|
return
|
|
53
53
|
}
|
|
54
54
|
if (err) {
|
|
@@ -89,7 +89,7 @@ export default class InProcessRunner {
|
|
|
89
89
|
const responses = [callbackWrapper]
|
|
90
90
|
|
|
91
91
|
// Promise was returned
|
|
92
|
-
if (result != null && typeof result.then ===
|
|
92
|
+
if (result != null && typeof result.then === "function") {
|
|
93
93
|
responses.push(result)
|
|
94
94
|
}
|
|
95
95
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict"
|
|
2
2
|
|
|
3
|
-
const { pathToFileURL } = require(
|
|
3
|
+
const { pathToFileURL } = require("node:url")
|
|
4
4
|
|
|
5
5
|
// node_modules/lambda-runtime/dist/node16/UserFunction.js
|
|
6
6
|
;(function () {
|
|
@@ -17,19 +17,19 @@ const { pathToFileURL } = require('node:url')
|
|
|
17
17
|
)
|
|
18
18
|
}
|
|
19
19
|
const require_Errors = __commonJS({
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
"Errors.js": function (exports2, module2) {
|
|
21
|
+
"use strict"
|
|
22
22
|
|
|
23
|
-
const util = require(
|
|
23
|
+
const util = require("util")
|
|
24
24
|
function _isError(obj) {
|
|
25
25
|
return (
|
|
26
26
|
obj &&
|
|
27
27
|
obj.name &&
|
|
28
28
|
obj.message &&
|
|
29
29
|
obj.stack &&
|
|
30
|
-
typeof obj.name ===
|
|
31
|
-
typeof obj.message ===
|
|
32
|
-
typeof obj.stack ===
|
|
30
|
+
typeof obj.name === "string" &&
|
|
31
|
+
typeof obj.message === "string" &&
|
|
32
|
+
typeof obj.stack === "string"
|
|
33
33
|
)
|
|
34
34
|
}
|
|
35
35
|
function intoError(err) {
|
|
@@ -45,7 +45,7 @@ const { pathToFileURL } = require('node:url')
|
|
|
45
45
|
return {
|
|
46
46
|
errorType: error.name,
|
|
47
47
|
errorMessage: error.message,
|
|
48
|
-
trace: error.stack.split(
|
|
48
|
+
trace: error.stack.split("\n"),
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
return {
|
|
@@ -55,9 +55,9 @@ const { pathToFileURL } = require('node:url')
|
|
|
55
55
|
}
|
|
56
56
|
} catch (_err) {
|
|
57
57
|
return {
|
|
58
|
-
errorType:
|
|
58
|
+
errorType: "handled",
|
|
59
59
|
errorMessage:
|
|
60
|
-
|
|
60
|
+
"callback called with Error argument, but there was a problem while retrieving one or more of its message, name, and stack",
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
}
|
|
@@ -79,8 +79,8 @@ const { pathToFileURL } = require('node:url')
|
|
|
79
79
|
code: error.code,
|
|
80
80
|
...error,
|
|
81
81
|
}
|
|
82
|
-
if (typeof error.stack ===
|
|
83
|
-
ret.stack = error.stack.split(
|
|
82
|
+
if (typeof error.stack === "string") {
|
|
83
|
+
ret.stack = error.stack.split("\n")
|
|
84
84
|
}
|
|
85
85
|
return ret
|
|
86
86
|
}
|
|
@@ -108,11 +108,11 @@ const { pathToFileURL } = require('node:url')
|
|
|
108
108
|
},
|
|
109
109
|
})
|
|
110
110
|
const require_VerboseLog = __commonJS({
|
|
111
|
-
|
|
112
|
-
|
|
111
|
+
"VerboseLog.js": function (exports2) {
|
|
112
|
+
"use strict"
|
|
113
113
|
|
|
114
|
-
const EnvVarName =
|
|
115
|
-
const Tag =
|
|
114
|
+
const EnvVarName = "AWS_LAMBDA_RUNTIME_VERBOSE"
|
|
115
|
+
const Tag = "RUNTIME"
|
|
116
116
|
const Verbosity = (() => {
|
|
117
117
|
if (!process.env[EnvVarName]) {
|
|
118
118
|
return 0
|
|
@@ -146,11 +146,11 @@ const { pathToFileURL } = require('node:url')
|
|
|
146
146
|
},
|
|
147
147
|
})
|
|
148
148
|
const require_HttpResponseStream = __commonJS({
|
|
149
|
-
|
|
150
|
-
|
|
149
|
+
"HttpResponseStream.js": function (exports2, module2) {
|
|
150
|
+
"use strict"
|
|
151
151
|
|
|
152
152
|
const METADATA_PRELUDE_CONTENT_TYPE =
|
|
153
|
-
|
|
153
|
+
"application/vnd.awslambda.http-integration-response"
|
|
154
154
|
const DELIMITER_LEN = 8
|
|
155
155
|
const HttpResponseStream2 = class {
|
|
156
156
|
static from(underlyingStream, prelude) {
|
|
@@ -166,23 +166,23 @@ const { pathToFileURL } = require('node:url')
|
|
|
166
166
|
module2.exports.HttpResponseStream = HttpResponseStream2
|
|
167
167
|
},
|
|
168
168
|
})
|
|
169
|
-
const path = require(
|
|
170
|
-
const fs = require(
|
|
169
|
+
const path = require("path")
|
|
170
|
+
const fs = require("fs")
|
|
171
171
|
const {
|
|
172
172
|
HandlerNotFound,
|
|
173
173
|
MalformedHandlerName,
|
|
174
174
|
ImportModuleError,
|
|
175
175
|
UserCodeSyntaxError,
|
|
176
176
|
} = require_Errors()
|
|
177
|
-
const { verbose } = require_VerboseLog().logger(
|
|
177
|
+
const { verbose } = require_VerboseLog().logger("LOADER")
|
|
178
178
|
const { HttpResponseStream } = require_HttpResponseStream()
|
|
179
179
|
const FUNCTION_EXPR = /^([^.]*)\.(.*)$/
|
|
180
|
-
const RELATIVE_PATH_SUBSTRING =
|
|
181
|
-
const HANDLER_STREAMING = Symbol.for(
|
|
182
|
-
const STREAM_RESPONSE =
|
|
180
|
+
const RELATIVE_PATH_SUBSTRING = ".."
|
|
181
|
+
const HANDLER_STREAMING = Symbol.for("aws.lambda.runtime.handler.streaming")
|
|
182
|
+
const STREAM_RESPONSE = "response"
|
|
183
183
|
const NoGlobalAwsLambda =
|
|
184
|
-
process.env.AWS_LAMBDA_NODEJS_NO_GLOBAL_AWSLAMBDA ===
|
|
185
|
-
process.env.AWS_LAMBDA_NODEJS_NO_GLOBAL_AWSLAMBDA ===
|
|
184
|
+
process.env.AWS_LAMBDA_NODEJS_NO_GLOBAL_AWSLAMBDA === "1" ||
|
|
185
|
+
process.env.AWS_LAMBDA_NODEJS_NO_GLOBAL_AWSLAMBDA === "true"
|
|
186
186
|
function _moduleRootAndHandler(fullHandlerString) {
|
|
187
187
|
const handlerString = path.basename(fullHandlerString)
|
|
188
188
|
const moduleRoot = fullHandlerString.substring(
|
|
@@ -194,38 +194,38 @@ const { pathToFileURL } = require('node:url')
|
|
|
194
194
|
function _splitHandlerString(handler) {
|
|
195
195
|
const match = handler.match(FUNCTION_EXPR)
|
|
196
196
|
if (!match || match.length != 3) {
|
|
197
|
-
throw new MalformedHandlerName(
|
|
197
|
+
throw new MalformedHandlerName("Bad handler")
|
|
198
198
|
}
|
|
199
199
|
return [match[1], match[2]]
|
|
200
200
|
}
|
|
201
201
|
function _resolveHandler(object, nestedProperty) {
|
|
202
|
-
return nestedProperty.split(
|
|
202
|
+
return nestedProperty.split(".").reduce((nested, key) => {
|
|
203
203
|
return nested && nested[key]
|
|
204
204
|
}, object)
|
|
205
205
|
}
|
|
206
206
|
function _tryRequireFile(file, extension) {
|
|
207
|
-
const path2 = file + (extension ||
|
|
208
|
-
verbose(
|
|
207
|
+
const path2 = file + (extension || "")
|
|
208
|
+
verbose("Try loading as commonjs:", path2)
|
|
209
209
|
return fs.existsSync(path2) ? require(path2) : void 0
|
|
210
210
|
}
|
|
211
211
|
async function _tryAwaitImport(file, extension) {
|
|
212
|
-
const path2 = file + (extension ||
|
|
213
|
-
verbose(
|
|
212
|
+
const path2 = file + (extension || "")
|
|
213
|
+
verbose("Try loading as esmodule:", path2)
|
|
214
214
|
if (fs.existsSync(path2)) {
|
|
215
215
|
return await import(pathToFileURL(path2).href)
|
|
216
216
|
}
|
|
217
217
|
return void 0
|
|
218
218
|
}
|
|
219
219
|
function _hasFolderPackageJsonTypeModule(folder) {
|
|
220
|
-
if (folder.endsWith(
|
|
220
|
+
if (folder.endsWith("/node_modules")) {
|
|
221
221
|
return false
|
|
222
222
|
}
|
|
223
|
-
const pj = path.join(folder,
|
|
223
|
+
const pj = path.join(folder, "/package.json")
|
|
224
224
|
if (fs.existsSync(pj)) {
|
|
225
225
|
try {
|
|
226
226
|
const pkg = JSON.parse(fs.readFileSync(pj))
|
|
227
227
|
if (pkg) {
|
|
228
|
-
if (pkg.type ===
|
|
228
|
+
if (pkg.type === "module") {
|
|
229
229
|
verbose(`'type: module' detected in ${pj}`)
|
|
230
230
|
return true
|
|
231
231
|
}
|
|
@@ -240,10 +240,10 @@ const { pathToFileURL } = require('node:url')
|
|
|
240
240
|
return false
|
|
241
241
|
}
|
|
242
242
|
}
|
|
243
|
-
if (folder ===
|
|
243
|
+
if (folder === "/") {
|
|
244
244
|
return false
|
|
245
245
|
}
|
|
246
|
-
return _hasFolderPackageJsonTypeModule(path.resolve(folder,
|
|
246
|
+
return _hasFolderPackageJsonTypeModule(path.resolve(folder, ".."))
|
|
247
247
|
}
|
|
248
248
|
function _hasPackageJsonTypeModule(file) {
|
|
249
249
|
const jsPath = `${file}.js`
|
|
@@ -253,9 +253,9 @@ const { pathToFileURL } = require('node:url')
|
|
|
253
253
|
}
|
|
254
254
|
async function _tryRequire(appRoot, moduleRoot, module2) {
|
|
255
255
|
verbose(
|
|
256
|
-
|
|
256
|
+
"Try loading as commonjs: ",
|
|
257
257
|
module2,
|
|
258
|
-
|
|
258
|
+
" with paths: ,",
|
|
259
259
|
appRoot,
|
|
260
260
|
moduleRoot,
|
|
261
261
|
)
|
|
@@ -266,22 +266,22 @@ const { pathToFileURL } = require('node:url')
|
|
|
266
266
|
}
|
|
267
267
|
const pjHasModule = _hasPackageJsonTypeModule(lambdaStylePath)
|
|
268
268
|
if (!pjHasModule) {
|
|
269
|
-
const loaded2 = _tryRequireFile(lambdaStylePath,
|
|
269
|
+
const loaded2 = _tryRequireFile(lambdaStylePath, ".js")
|
|
270
270
|
if (loaded2) {
|
|
271
271
|
return loaded2
|
|
272
272
|
}
|
|
273
273
|
}
|
|
274
274
|
const loaded =
|
|
275
|
-
(pjHasModule && (await _tryAwaitImport(lambdaStylePath,
|
|
276
|
-
(await _tryAwaitImport(lambdaStylePath,
|
|
277
|
-
_tryRequireFile(lambdaStylePath,
|
|
275
|
+
(pjHasModule && (await _tryAwaitImport(lambdaStylePath, ".js"))) ||
|
|
276
|
+
(await _tryAwaitImport(lambdaStylePath, ".mjs")) ||
|
|
277
|
+
_tryRequireFile(lambdaStylePath, ".cjs")
|
|
278
278
|
if (loaded) {
|
|
279
279
|
return loaded
|
|
280
280
|
}
|
|
281
281
|
verbose(
|
|
282
|
-
|
|
282
|
+
"Try loading as commonjs: ",
|
|
283
283
|
module2,
|
|
284
|
-
|
|
284
|
+
" with path(s): ",
|
|
285
285
|
appRoot,
|
|
286
286
|
moduleRoot,
|
|
287
287
|
)
|
|
@@ -305,8 +305,8 @@ const { pathToFileURL } = require('node:url')
|
|
|
305
305
|
} catch (e) {
|
|
306
306
|
if (e instanceof SyntaxError) {
|
|
307
307
|
throw new UserCodeSyntaxError(e)
|
|
308
|
-
} else if (e.code !== void 0 && e.code ===
|
|
309
|
-
verbose(
|
|
308
|
+
} else if (e.code !== void 0 && e.code === "MODULE_NOT_FOUND") {
|
|
309
|
+
verbose("globalPaths", JSON.stringify(require("module").globalPaths))
|
|
310
310
|
throw new ImportModuleError(e)
|
|
311
311
|
} else {
|
|
312
312
|
throw e
|
|
@@ -322,7 +322,7 @@ const { pathToFileURL } = require('node:url')
|
|
|
322
322
|
}
|
|
323
323
|
function _isHandlerStreaming(handler) {
|
|
324
324
|
if (
|
|
325
|
-
typeof handler[HANDLER_STREAMING] ===
|
|
325
|
+
typeof handler[HANDLER_STREAMING] === "undefined" ||
|
|
326
326
|
handler[HANDLER_STREAMING] === null ||
|
|
327
327
|
handler[HANDLER_STREAMING] === false
|
|
328
328
|
) {
|
|
@@ -331,7 +331,7 @@ const { pathToFileURL } = require('node:url')
|
|
|
331
331
|
if (handler[HANDLER_STREAMING] === STREAM_RESPONSE) {
|
|
332
332
|
return STREAM_RESPONSE
|
|
333
333
|
}
|
|
334
|
-
throw new MalformedStreamingHandler(
|
|
334
|
+
throw new MalformedStreamingHandler("Only response streaming is supported.")
|
|
335
335
|
}
|
|
336
336
|
module.exports.load = async function (appRoot, fullHandlerString) {
|
|
337
337
|
_throwIfInvalidHandler(fullHandlerString)
|
|
@@ -345,7 +345,7 @@ const { pathToFileURL } = require('node:url')
|
|
|
345
345
|
`${fullHandlerString} is undefined or not exported`,
|
|
346
346
|
)
|
|
347
347
|
}
|
|
348
|
-
if (typeof handlerFunc !==
|
|
348
|
+
if (typeof handlerFunc !== "function") {
|
|
349
349
|
throw new HandlerNotFound(`${fullHandlerString} is not a function`)
|
|
350
350
|
}
|
|
351
351
|
return handlerFunc
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { default } from
|
|
1
|
+
export { default } from "./InProcessRunner.js"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { default } from
|
|
1
|
+
export { default } from "./HandlerRunner.js"
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { EOL } from
|
|
2
|
-
import process from
|
|
3
|
-
import { log } from
|
|
4
|
-
import { invokeJavaLocal } from
|
|
1
|
+
import { EOL } from "node:os"
|
|
2
|
+
import process from "node:process"
|
|
3
|
+
import { log } from "@serverless/utils/log.js"
|
|
4
|
+
import { invokeJavaLocal } from "java-invoke-local"
|
|
5
5
|
|
|
6
6
|
const { parse, stringify } = JSON
|
|
7
7
|
const { hasOwn } = Object
|
|
8
8
|
|
|
9
9
|
export default class JavaRunner {
|
|
10
|
-
static #payloadIdentifier =
|
|
10
|
+
static #payloadIdentifier = "__offline_payload__"
|
|
11
11
|
|
|
12
12
|
#deployPackage = null
|
|
13
13
|
|
|
@@ -46,7 +46,7 @@ export default class JavaRunner {
|
|
|
46
46
|
// now let's see if we have a property __offline_payload__
|
|
47
47
|
if (
|
|
48
48
|
json &&
|
|
49
|
-
typeof json ===
|
|
49
|
+
typeof json === "object" &&
|
|
50
50
|
hasOwn(json, JavaRunner.#payloadIdentifier)
|
|
51
51
|
) {
|
|
52
52
|
return json[JavaRunner.#payloadIdentifier]
|
|
@@ -73,7 +73,7 @@ export default class JavaRunner {
|
|
|
73
73
|
|
|
74
74
|
const httpOptions = {
|
|
75
75
|
body: data,
|
|
76
|
-
method:
|
|
76
|
+
method: "POST",
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
const port = process.env.JAVA_OFFLINE_SERVER || 8080
|
|
@@ -95,16 +95,16 @@ export default class JavaRunner {
|
|
|
95
95
|
|
|
96
96
|
// Fallback invocation
|
|
97
97
|
const args = [
|
|
98
|
-
|
|
98
|
+
"-c",
|
|
99
99
|
this.#handler,
|
|
100
|
-
|
|
100
|
+
"-a",
|
|
101
101
|
this.#deployPackage,
|
|
102
|
-
|
|
102
|
+
"-f",
|
|
103
103
|
this.#functionName,
|
|
104
|
-
|
|
104
|
+
"-d",
|
|
105
105
|
input,
|
|
106
|
-
|
|
107
|
-
|
|
106
|
+
"--json-output",
|
|
107
|
+
"--serverless-offline",
|
|
108
108
|
]
|
|
109
109
|
result = invokeJavaLocal(args, this.#env)
|
|
110
110
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { default } from
|
|
1
|
+
export { default } from "./JavaRunner.js"
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { spawn } from
|
|
2
|
-
import { EOL, platform } from
|
|
3
|
-
import { delimiter, join as pathJoin, relative } from
|
|
4
|
-
import process, { cwd, nextTick } from
|
|
5
|
-
import { createInterface } from
|
|
6
|
-
import { log } from
|
|
7
|
-
import { join } from
|
|
8
|
-
import { splitHandlerPathAndName } from
|
|
1
|
+
import { spawn } from "node:child_process"
|
|
2
|
+
import { EOL, platform } from "node:os"
|
|
3
|
+
import { delimiter, join as pathJoin, relative } from "node:path"
|
|
4
|
+
import process, { cwd, nextTick } from "node:process"
|
|
5
|
+
import { createInterface } from "node:readline"
|
|
6
|
+
import { log } from "@serverless/utils/log.js"
|
|
7
|
+
import { join } from "desm"
|
|
8
|
+
import { splitHandlerPathAndName } from "../../../utils/index.js"
|
|
9
9
|
|
|
10
10
|
const { parse, stringify } = JSON
|
|
11
11
|
const { assign, hasOwn } = Object
|
|
12
12
|
|
|
13
13
|
export default class PythonRunner {
|
|
14
|
-
static #payloadIdentifier =
|
|
14
|
+
static #payloadIdentifier = "__offline_payload__"
|
|
15
15
|
|
|
16
16
|
#env = null
|
|
17
17
|
|
|
@@ -24,25 +24,25 @@ export default class PythonRunner {
|
|
|
24
24
|
const [handlerPath, handlerName] = splitHandlerPathAndName(handler)
|
|
25
25
|
|
|
26
26
|
this.#env = env
|
|
27
|
-
this.#runtime = platform() ===
|
|
27
|
+
this.#runtime = platform() === "win32" ? "python.exe" : runtime
|
|
28
28
|
|
|
29
29
|
if (process.env.VIRTUAL_ENV) {
|
|
30
|
-
const runtimeDir = platform() ===
|
|
30
|
+
const runtimeDir = platform() === "win32" ? "Scripts" : "bin"
|
|
31
31
|
|
|
32
32
|
process.env.PATH = [
|
|
33
33
|
pathJoin(process.env.VIRTUAL_ENV, runtimeDir),
|
|
34
34
|
delimiter,
|
|
35
35
|
process.env.PATH,
|
|
36
|
-
].join(
|
|
36
|
+
].join("")
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
const [pythonExecutable] = this.#runtime.split(
|
|
39
|
+
const [pythonExecutable] = this.#runtime.split(".")
|
|
40
40
|
|
|
41
41
|
this.#handlerProcess = spawn(
|
|
42
42
|
pythonExecutable,
|
|
43
43
|
[
|
|
44
|
-
|
|
45
|
-
join(import.meta.url,
|
|
44
|
+
"-u",
|
|
45
|
+
join(import.meta.url, "invoke.py"),
|
|
46
46
|
relative(cwd(), handlerPath),
|
|
47
47
|
handlerName,
|
|
48
48
|
],
|
|
@@ -79,7 +79,7 @@ export default class PythonRunner {
|
|
|
79
79
|
// now let's see if we have a property __offline_payload__
|
|
80
80
|
if (
|
|
81
81
|
json &&
|
|
82
|
-
typeof json ===
|
|
82
|
+
typeof json === "object" &&
|
|
83
83
|
hasOwn(json, PythonRunner.#payloadIdentifier)
|
|
84
84
|
) {
|
|
85
85
|
payload = json[PythonRunner.#payloadIdentifier]
|
|
@@ -113,8 +113,8 @@ export default class PythonRunner {
|
|
|
113
113
|
try {
|
|
114
114
|
const parsed = this.#parsePayload(line.toString())
|
|
115
115
|
if (parsed) {
|
|
116
|
-
this.#handlerProcess.stdout.readline.removeListener(
|
|
117
|
-
this.#handlerProcess.stderr.removeListener(
|
|
116
|
+
this.#handlerProcess.stdout.readline.removeListener("line", onLine)
|
|
117
|
+
this.#handlerProcess.stderr.removeListener("data", onErr)
|
|
118
118
|
res(parsed)
|
|
119
119
|
}
|
|
120
120
|
} catch (err) {
|
|
@@ -122,12 +122,12 @@ export default class PythonRunner {
|
|
|
122
122
|
}
|
|
123
123
|
}
|
|
124
124
|
|
|
125
|
-
this.#handlerProcess.stdout.readline.on(
|
|
126
|
-
this.#handlerProcess.stderr.on(
|
|
125
|
+
this.#handlerProcess.stdout.readline.on("line", onLine)
|
|
126
|
+
this.#handlerProcess.stderr.on("data", onErr)
|
|
127
127
|
|
|
128
128
|
nextTick(() => {
|
|
129
129
|
this.#handlerProcess.stdin.write(input)
|
|
130
|
-
this.#handlerProcess.stdin.write(
|
|
130
|
+
this.#handlerProcess.stdin.write("\n")
|
|
131
131
|
})
|
|
132
132
|
})
|
|
133
133
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { default } from
|
|
1
|
+
export { default } from "./PythonRunner.js"
|