sst 2.22.5 → 2.22.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.
- package/package.json +1 -1
- package/runtime/handlers/node.js +31 -12
- package/sst.mjs +35 -19
package/package.json
CHANGED
package/runtime/handlers/node.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import os from "os";
|
|
1
2
|
import path from "path";
|
|
2
3
|
import fs from "fs/promises";
|
|
3
4
|
import { exec } from "child_process";
|
|
@@ -11,12 +12,13 @@ import { useRuntimeWorkers } from "../workers.js";
|
|
|
11
12
|
import { Context } from "../../context/context.js";
|
|
12
13
|
import { VisibleError } from "../../error.js";
|
|
13
14
|
import { Colors } from "../../cli/colors.js";
|
|
15
|
+
import { Logger } from "../../logger.js";
|
|
14
16
|
export const useNodeHandler = Context.memo(async () => {
|
|
15
17
|
const workers = await useRuntimeWorkers();
|
|
16
18
|
const handlers = useRuntimeHandlers();
|
|
17
|
-
const
|
|
19
|
+
const rebuildCache = {};
|
|
18
20
|
process.on("exit", () => {
|
|
19
|
-
for (const { ctx } of Object.values(
|
|
21
|
+
for (const { ctx } of Object.values(rebuildCache)) {
|
|
20
22
|
ctx.dispose();
|
|
21
23
|
}
|
|
22
24
|
});
|
|
@@ -24,14 +26,14 @@ export const useNodeHandler = Context.memo(async () => {
|
|
|
24
26
|
const threads = new Map();
|
|
25
27
|
handlers.register({
|
|
26
28
|
shouldBuild: (input) => {
|
|
27
|
-
const
|
|
28
|
-
if (!
|
|
29
|
+
const cache = rebuildCache[input.functionID];
|
|
30
|
+
if (!cache)
|
|
29
31
|
return false;
|
|
30
32
|
const relative = path
|
|
31
33
|
.relative(project.paths.root, input.file)
|
|
32
34
|
.split(path.sep)
|
|
33
35
|
.join(path.posix.sep);
|
|
34
|
-
return Boolean(result.
|
|
36
|
+
return Boolean(cache.result.metafile?.inputs[relative]);
|
|
35
37
|
},
|
|
36
38
|
canHandle: (input) => input.startsWith("nodejs"),
|
|
37
39
|
startWorker: async (input) => {
|
|
@@ -62,7 +64,6 @@ export const useNodeHandler = Context.memo(async () => {
|
|
|
62
64
|
await worker?.terminate();
|
|
63
65
|
},
|
|
64
66
|
build: async (input) => {
|
|
65
|
-
const exists = cache[input.functionID];
|
|
66
67
|
const parsed = path.parse(input.props.handler);
|
|
67
68
|
const file = [
|
|
68
69
|
".ts",
|
|
@@ -94,11 +95,13 @@ export const useNodeHandler = Context.memo(async () => {
|
|
|
94
95
|
.relative(input.out, target.replace(extension, parsed.ext))
|
|
95
96
|
.split(path.sep)
|
|
96
97
|
.join(path.posix.sep);
|
|
98
|
+
// Rebuilt using existing esbuild context
|
|
99
|
+
const exists = rebuildCache[input.functionID];
|
|
97
100
|
if (exists) {
|
|
98
101
|
const result = await exists.ctx.rebuild();
|
|
99
|
-
|
|
102
|
+
rebuildCache[input.functionID] = {
|
|
100
103
|
ctx: exists.ctx,
|
|
101
|
-
|
|
104
|
+
result,
|
|
102
105
|
};
|
|
103
106
|
return {
|
|
104
107
|
type: "success",
|
|
@@ -211,10 +214,11 @@ export const useNodeHandler = Context.memo(async () => {
|
|
|
211
214
|
}
|
|
212
215
|
catch { }
|
|
213
216
|
}
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
}
|
|
217
|
+
// Cache esbuild result and context for rebuild
|
|
218
|
+
if (input.mode === "start") {
|
|
219
|
+
rebuildCache[input.functionID] = { ctx, result };
|
|
220
|
+
}
|
|
221
|
+
logMemoryUsage(input.functionID, input.props.handler);
|
|
218
222
|
return {
|
|
219
223
|
type: "success",
|
|
220
224
|
handler,
|
|
@@ -240,3 +244,18 @@ export const useNodeHandler = Context.memo(async () => {
|
|
|
240
244
|
},
|
|
241
245
|
});
|
|
242
246
|
});
|
|
247
|
+
function logMemoryUsage(functionID, handler) {
|
|
248
|
+
const printInMB = (bytes) => `${Math.round(bytes / 1024 / 1024)} MB`;
|
|
249
|
+
const used = process.memoryUsage();
|
|
250
|
+
for (const key in used) {
|
|
251
|
+
// @ts-ignore
|
|
252
|
+
used[key] = printInMB(used[key]);
|
|
253
|
+
}
|
|
254
|
+
Logger.debug({
|
|
255
|
+
functionID,
|
|
256
|
+
handler,
|
|
257
|
+
freeMemory: printInMB(os.freemem()),
|
|
258
|
+
totalMemory: printInMB(os.totalmem()),
|
|
259
|
+
...used,
|
|
260
|
+
});
|
|
261
|
+
}
|
package/sst.mjs
CHANGED
|
@@ -5336,6 +5336,7 @@ var node_exports = {};
|
|
|
5336
5336
|
__export(node_exports, {
|
|
5337
5337
|
useNodeHandler: () => useNodeHandler
|
|
5338
5338
|
});
|
|
5339
|
+
import os4 from "os";
|
|
5339
5340
|
import path10 from "path";
|
|
5340
5341
|
import fs9 from "fs/promises";
|
|
5341
5342
|
import { exec as exec2 } from "child_process";
|
|
@@ -5343,6 +5344,20 @@ import fsSync2 from "fs";
|
|
|
5343
5344
|
import esbuild2 from "esbuild";
|
|
5344
5345
|
import url4 from "url";
|
|
5345
5346
|
import { Worker } from "worker_threads";
|
|
5347
|
+
function logMemoryUsage(functionID, handler) {
|
|
5348
|
+
const printInMB = (bytes) => `${Math.round(bytes / 1024 / 1024)} MB`;
|
|
5349
|
+
const used = process.memoryUsage();
|
|
5350
|
+
for (const key in used) {
|
|
5351
|
+
used[key] = printInMB(used[key]);
|
|
5352
|
+
}
|
|
5353
|
+
Logger.debug({
|
|
5354
|
+
functionID,
|
|
5355
|
+
handler,
|
|
5356
|
+
freeMemory: printInMB(os4.freemem()),
|
|
5357
|
+
totalMemory: printInMB(os4.totalmem()),
|
|
5358
|
+
...used
|
|
5359
|
+
});
|
|
5360
|
+
}
|
|
5346
5361
|
var useNodeHandler;
|
|
5347
5362
|
var init_node = __esm({
|
|
5348
5363
|
"src/runtime/handlers/node.ts"() {
|
|
@@ -5353,12 +5368,13 @@ var init_node = __esm({
|
|
|
5353
5368
|
init_context();
|
|
5354
5369
|
init_error();
|
|
5355
5370
|
init_colors();
|
|
5371
|
+
init_logger();
|
|
5356
5372
|
useNodeHandler = Context.memo(async () => {
|
|
5357
5373
|
const workers = await useRuntimeWorkers();
|
|
5358
5374
|
const handlers = useRuntimeHandlers();
|
|
5359
|
-
const
|
|
5375
|
+
const rebuildCache = {};
|
|
5360
5376
|
process.on("exit", () => {
|
|
5361
|
-
for (const { ctx } of Object.values(
|
|
5377
|
+
for (const { ctx } of Object.values(rebuildCache)) {
|
|
5362
5378
|
ctx.dispose();
|
|
5363
5379
|
}
|
|
5364
5380
|
});
|
|
@@ -5366,11 +5382,11 @@ var init_node = __esm({
|
|
|
5366
5382
|
const threads = /* @__PURE__ */ new Map();
|
|
5367
5383
|
handlers.register({
|
|
5368
5384
|
shouldBuild: (input) => {
|
|
5369
|
-
const
|
|
5370
|
-
if (!
|
|
5385
|
+
const cache = rebuildCache[input.functionID];
|
|
5386
|
+
if (!cache)
|
|
5371
5387
|
return false;
|
|
5372
5388
|
const relative = path10.relative(project.paths.root, input.file).split(path10.sep).join(path10.posix.sep);
|
|
5373
|
-
return Boolean(result.
|
|
5389
|
+
return Boolean(cache.result.metafile?.inputs[relative]);
|
|
5374
5390
|
},
|
|
5375
5391
|
canHandle: (input) => input.startsWith("nodejs"),
|
|
5376
5392
|
startWorker: async (input) => {
|
|
@@ -5406,7 +5422,6 @@ var init_node = __esm({
|
|
|
5406
5422
|
await worker?.terminate();
|
|
5407
5423
|
},
|
|
5408
5424
|
build: async (input) => {
|
|
5409
|
-
const exists = cache[input.functionID];
|
|
5410
5425
|
const parsed = path10.parse(input.props.handler);
|
|
5411
5426
|
const file = [
|
|
5412
5427
|
".ts",
|
|
@@ -5438,11 +5453,12 @@ var init_node = __esm({
|
|
|
5438
5453
|
parsed.name + extension
|
|
5439
5454
|
);
|
|
5440
5455
|
const handler = path10.relative(input.out, target.replace(extension, parsed.ext)).split(path10.sep).join(path10.posix.sep);
|
|
5456
|
+
const exists = rebuildCache[input.functionID];
|
|
5441
5457
|
if (exists) {
|
|
5442
5458
|
const result = await exists.ctx.rebuild();
|
|
5443
|
-
|
|
5459
|
+
rebuildCache[input.functionID] = {
|
|
5444
5460
|
ctx: exists.ctx,
|
|
5445
|
-
|
|
5461
|
+
result
|
|
5446
5462
|
};
|
|
5447
5463
|
return {
|
|
5448
5464
|
type: "success",
|
|
@@ -5562,10 +5578,10 @@ var init_node = __esm({
|
|
|
5562
5578
|
} catch {
|
|
5563
5579
|
}
|
|
5564
5580
|
}
|
|
5565
|
-
|
|
5566
|
-
ctx,
|
|
5567
|
-
|
|
5568
|
-
|
|
5581
|
+
if (input.mode === "start") {
|
|
5582
|
+
rebuildCache[input.functionID] = { ctx, result };
|
|
5583
|
+
}
|
|
5584
|
+
logMemoryUsage(input.functionID, input.props.handler);
|
|
5569
5585
|
return {
|
|
5570
5586
|
type: "success",
|
|
5571
5587
|
handler
|
|
@@ -5600,7 +5616,7 @@ __export(go_exports, {
|
|
|
5600
5616
|
});
|
|
5601
5617
|
import path11 from "path";
|
|
5602
5618
|
import fs10 from "fs/promises";
|
|
5603
|
-
import
|
|
5619
|
+
import os5 from "os";
|
|
5604
5620
|
import { spawn as spawn2 } from "child_process";
|
|
5605
5621
|
async function find(dir, target) {
|
|
5606
5622
|
if (dir === "/")
|
|
@@ -5671,7 +5687,7 @@ var init_go = __esm({
|
|
|
5671
5687
|
if (input.mode === "start") {
|
|
5672
5688
|
try {
|
|
5673
5689
|
const target = path11.join(input.out, handlerName);
|
|
5674
|
-
const srcPath =
|
|
5690
|
+
const srcPath = os5.platform() === "win32" ? src.replaceAll("\\", "\\\\") : src;
|
|
5675
5691
|
const result = await execAsync(
|
|
5676
5692
|
[
|
|
5677
5693
|
"go",
|
|
@@ -5698,7 +5714,7 @@ var init_go = __esm({
|
|
|
5698
5714
|
if (input.mode === "deploy") {
|
|
5699
5715
|
try {
|
|
5700
5716
|
const target = path11.join(input.out, "bootstrap");
|
|
5701
|
-
const srcPath =
|
|
5717
|
+
const srcPath = os5.platform() === "win32" ? src.replaceAll("\\", "\\\\") : src;
|
|
5702
5718
|
await execAsync(
|
|
5703
5719
|
[
|
|
5704
5720
|
"go",
|
|
@@ -6208,7 +6224,7 @@ import path14 from "path";
|
|
|
6208
6224
|
import { exec as exec5, spawn as spawn5 } from "child_process";
|
|
6209
6225
|
import { promisify as promisify3 } from "util";
|
|
6210
6226
|
import { Runtime } from "aws-cdk-lib/aws-lambda";
|
|
6211
|
-
import
|
|
6227
|
+
import os6 from "os";
|
|
6212
6228
|
import url6 from "url";
|
|
6213
6229
|
var execAsync3, RUNTIME_MAP, usePythonHandler;
|
|
6214
6230
|
var init_python = __esm({
|
|
@@ -6258,7 +6274,7 @@ var init_python = __esm({
|
|
|
6258
6274
|
const parsed = path14.parse(path14.relative(src, input.handler));
|
|
6259
6275
|
const target = [...parsed.dir.split(path14.sep), parsed.name].join(".");
|
|
6260
6276
|
const proc = spawn5(
|
|
6261
|
-
|
|
6277
|
+
os6.platform() === "win32" ? "python.exe" : "python3",
|
|
6262
6278
|
[
|
|
6263
6279
|
"-u",
|
|
6264
6280
|
url6.fileURLToPath(
|
|
@@ -6333,7 +6349,7 @@ __export(java_exports, {
|
|
|
6333
6349
|
});
|
|
6334
6350
|
import path15 from "path";
|
|
6335
6351
|
import fs13 from "fs/promises";
|
|
6336
|
-
import
|
|
6352
|
+
import os7 from "os";
|
|
6337
6353
|
import { spawn as spawn6 } from "child_process";
|
|
6338
6354
|
import url7 from "url";
|
|
6339
6355
|
import AdmZip from "adm-zip";
|
|
@@ -6378,7 +6394,7 @@ var init_java = __esm({
|
|
|
6378
6394
|
url7.fileURLToPath(
|
|
6379
6395
|
new URL("../../support/java-runtime/release/*", import.meta.url)
|
|
6380
6396
|
)
|
|
6381
|
-
].join(
|
|
6397
|
+
].join(os7.platform() === "win32" ? ";" : ":"),
|
|
6382
6398
|
"com.amazonaws.services.lambda.runtime.api.client.AWSLambda",
|
|
6383
6399
|
input.handler
|
|
6384
6400
|
],
|