@intelligems/sst 2.49.6-ig.4 → 2.49.6-ig.6

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.
@@ -6,9 +6,18 @@ import path from "path";
6
6
  import fs from "fs";
7
7
  import http from "http";
8
8
  import url from "url";
9
+ import os from "os";
10
+ try {
11
+ const mod = await import("node:module");
12
+ if (typeof mod.enableCompileCache === "function") {
13
+ const cacheDir = path.join(os.tmpdir(), "sst-compile-cache");
14
+ mod.enableCompileCache(cacheDir);
15
+ }
16
+ } catch {
17
+ }
9
18
  var input = workerData;
10
19
  var monoBundlePath = path.join(input.out, "index.mjs");
11
- var useMonoBundle = input.handler === "index.handler" && fs.existsSync(monoBundlePath);
20
+ var useMonoBundle = input.isMonoBuild ?? (input.handler === "index.handler" && fs.existsSync(monoBundlePath));
12
21
  var file;
13
22
  var handlerName;
14
23
  if (useMonoBundle) {
@@ -62,6 +71,9 @@ try {
62
71
  useMonoBundle ? `Mono-bundle handler "${handlerName}" not found in "${file}". Found: ${Object.keys(mod).join(", ")}` : `Function "${handlerName}" not found in "${input.handler}". Found: ${Object.keys(mod).join(", ")}`
63
72
  );
64
73
  }
74
+ if (useMonoBundle && mod.warmUp) {
75
+ await mod.warmUp();
76
+ }
65
77
  } catch (ex) {
66
78
  await fetch({
67
79
  path: `/runtime/init/error`,
@@ -128,9 +140,10 @@ while (true) {
128
140
  identity: JSON.parse(result.headers["lambda-runtime-cognito-identity"]) ?? void 0,
129
141
  // If clientContext is null, we want to mimick AWS behavior and return undefined
130
142
  clientContext: JSON.parse(result.headers["lambda-runtime-client-context"]) ?? void 0,
131
- functionName: process.env.AWS_LAMBDA_FUNCTION_NAME,
132
- functionVersion: process.env.AWS_LAMBDA_FUNCTION_VERSION,
133
- memoryLimitInMB: process.env.AWS_LAMBDA_FUNCTION_MEMORY_SIZE,
143
+ // Per-invocation function context from headers (essential for mono-build shared workers)
144
+ functionName: result.headers["lambda-runtime-function-name"] || process.env.AWS_LAMBDA_FUNCTION_NAME,
145
+ functionVersion: result.headers["lambda-runtime-function-version"] || process.env.AWS_LAMBDA_FUNCTION_VERSION,
146
+ memoryLimitInMB: result.headers["lambda-runtime-function-memory-size"] || process.env.AWS_LAMBDA_FUNCTION_MEMORY_SIZE,
134
147
  logGroupName: result.headers["lambda-runtime-log-group-name"],
135
148
  logStreamName: result.headers["lambda-runtime-log-stream-name"],
136
149
  callbackWaitsForEmptyEventLoop: {
@@ -130,33 +130,33 @@ if __name__ == '__main__':
130
130
  if hasattr(signal, 'SIGALRM'):
131
131
  signal.alarm(0)
132
132
 
133
- event = json.loads(r.read())
134
- context = Context(
135
- r.getheader('Lambda-Runtime-Invoked-Function-Arn'),
136
- r.getheader('Lambda-Runtime-Aws-Request-Id'),
137
- r.getheader('Lambda-Runtime-Deadline-Ms'),
138
- r.getheader('Lambda-Runtime-Cognito-Identity'),
139
- r.getheader('Lambda-Runtime-Client-Context'),
140
- r.getheader('Lambda-Runtime-Log-Group-Name'),
141
- r.getheader('Lambda-Runtime-Log-Stream-Name')
142
- )
133
+ event = json.loads(r.read())
134
+ context = Context(
135
+ r.getheader('Lambda-Runtime-Invoked-Function-Arn'),
136
+ r.getheader('Lambda-Runtime-Aws-Request-Id'),
137
+ r.getheader('Lambda-Runtime-Deadline-Ms'),
138
+ r.getheader('Lambda-Runtime-Cognito-Identity'),
139
+ r.getheader('Lambda-Runtime-Client-Context'),
140
+ r.getheader('Lambda-Runtime-Log-Group-Name'),
141
+ r.getheader('Lambda-Runtime-Log-Stream-Name')
142
+ )
143
143
 
144
144
  # Invoke handler
145
- try:
146
- result = handler(event, context)
147
- data = json.dumps(result, default=handleUnserializable).encode("utf-8")
145
+ try:
146
+ result = handler(event, context)
147
+ data = json.dumps(result, default=handleUnserializable).encode("utf-8")
148
148
  url_destination = '/response'
149
- except Exception as e:
149
+ except Exception as e:
150
150
  # Handler error - report but keep worker alive
151
- traceback.print_exc()
152
- ex_type, ex_value, ex_traceback = sys.exc_info()
151
+ traceback.print_exc()
152
+ ex_type, ex_value, ex_traceback = sys.exc_info()
153
153
  error_result = {
154
154
  "errorType": ex_type.__name__ if ex_type else "Error",
155
- "errorMessage": str(ex_value),
155
+ "errorMessage": str(ex_value),
156
156
  "trace": traceback.format_tb(ex_traceback) if ex_traceback else [],
157
- }
157
+ }
158
158
  data = json.dumps(error_result).encode("utf-8")
159
- url_destination = '/error'
159
+ url_destination = '/error'
160
160
 
161
161
  # Send response
162
162
  response_url = "http://{}/2018-06-01/runtime/invocation/{}{}".format(
@@ -165,7 +165,7 @@ if __name__ == '__main__':
165
165
  url_destination
166
166
  )
167
167
  req = request.Request(response_url, method="POST", data=data)
168
- req.add_header('Content-Type', 'application/json')
168
+ req.add_header('Content-Type', 'application/json')
169
169
 
170
170
  # Retry sending response (matching Node.js behavior)
171
171
  max_retries = 3