@intelligems/sst 2.49.6-ig.1 → 2.49.6-ig.2
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/cli/commands/dev.js +3 -2
- package/package.json +1 -1
- package/package.json.bak +1 -1
- package/runtime/handlers/node.js +32 -0
- package/runtime/handlers.d.ts +4 -2
- package/runtime/handlers.js +20 -0
- package/support/nodejs-runtime/index.mjs +18 -7
package/cli/commands/dev.js
CHANGED
|
@@ -92,9 +92,10 @@ export const dev = (program) => program.command(["dev", "start"], "Work on your
|
|
|
92
92
|
return;
|
|
93
93
|
if (info.enableLiveDev === false)
|
|
94
94
|
return;
|
|
95
|
+
const buildType = evt.properties.monoBundle ? "(mono-bundle)" : "(individual)";
|
|
95
96
|
Colors.line(info.runtime === "container"
|
|
96
|
-
? Colors.dim(Colors.prefix, "Built", info.handler, "container")
|
|
97
|
-
: Colors.dim(Colors.prefix, "Built", info.handler));
|
|
97
|
+
? Colors.dim(Colors.prefix, "Built", info.handler, "container", buildType)
|
|
98
|
+
: Colors.dim(Colors.prefix, "Built", info.handler, buildType));
|
|
98
99
|
});
|
|
99
100
|
bus.subscribe("function.build.failed", async (evt) => {
|
|
100
101
|
const info = useFunctions().fromID(evt.properties.functionID);
|
package/package.json
CHANGED
package/package.json.bak
CHANGED
package/runtime/handlers/node.js
CHANGED
|
@@ -61,6 +61,38 @@ export const useNodeHandler = () => {
|
|
|
61
61
|
await worker?.terminate();
|
|
62
62
|
},
|
|
63
63
|
build: async (input) => {
|
|
64
|
+
// Check for dev mode mono-bundle: if .mono-build/index.mjs exists, skip individual builds
|
|
65
|
+
const monoBundleDir = path.join(project.paths.root, ".mono-build");
|
|
66
|
+
const monoBundlePath = path.join(monoBundleDir, "index.mjs");
|
|
67
|
+
const monoBundleExists = fsSync.existsSync(monoBundlePath);
|
|
68
|
+
console.log(`[MONO-BUNDLE] mode=${input.mode}, exists=${monoBundleExists}, handler=${input.props.handler}`);
|
|
69
|
+
if (input.mode === "start" && monoBundleExists) {
|
|
70
|
+
console.log(`[MONO-BUNDLE] Using mono-bundle for: ${input.props.handler}`);
|
|
71
|
+
Logger.debug("Using mono-bundle for dev mode:", monoBundlePath);
|
|
72
|
+
// Symlink node_modules to mono-bundle dir for external dependencies
|
|
73
|
+
// Use the same approach as individual builds: find nearest package.json above the handler
|
|
74
|
+
// handler-functions.ts lives in web/node-backend/src/, so start from there
|
|
75
|
+
const handlerFunctionsDir = path.join(project.paths.root, "web/node-backend/src");
|
|
76
|
+
const root = await findAbove(handlerFunctionsDir, "package.json");
|
|
77
|
+
if (root) {
|
|
78
|
+
const sourceNodeModules = path.join(root, "node_modules");
|
|
79
|
+
const monoBundleNodeModules = path.join(monoBundleDir, "node_modules");
|
|
80
|
+
try {
|
|
81
|
+
// Remove existing node_modules in mono-build (might be stale from deploy build)
|
|
82
|
+
await fs.rm(monoBundleNodeModules, { recursive: true, force: true });
|
|
83
|
+
await fs.symlink(path.resolve(sourceNodeModules), monoBundleNodeModules, "dir");
|
|
84
|
+
Logger.debug("Symlinked node_modules for mono-bundle from:", sourceNodeModules);
|
|
85
|
+
}
|
|
86
|
+
catch (err) {
|
|
87
|
+
Logger.debug("Failed to symlink node_modules for mono-bundle:", err);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return {
|
|
91
|
+
type: "success",
|
|
92
|
+
handler: "index.handler",
|
|
93
|
+
out: monoBundleDir,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
64
96
|
const parsed = path.parse(input.props.handler);
|
|
65
97
|
const file = [
|
|
66
98
|
".ts",
|
package/runtime/handlers.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ declare module "../bus.js" {
|
|
|
6
6
|
};
|
|
7
7
|
"function.build.success": {
|
|
8
8
|
functionID: string;
|
|
9
|
+
monoBundle?: boolean;
|
|
9
10
|
};
|
|
10
11
|
"function.build.failed": {
|
|
11
12
|
functionID: string;
|
|
@@ -41,6 +42,7 @@ export interface RuntimeHandler {
|
|
|
41
42
|
type: "success";
|
|
42
43
|
handler: string;
|
|
43
44
|
sourcemap?: string;
|
|
45
|
+
out?: string;
|
|
44
46
|
} | {
|
|
45
47
|
type: "error";
|
|
46
48
|
errors: string[];
|
|
@@ -57,10 +59,10 @@ export declare const useRuntimeHandlers: () => {
|
|
|
57
59
|
type: "error";
|
|
58
60
|
errors: string[];
|
|
59
61
|
} | {
|
|
60
|
-
out: string;
|
|
61
|
-
sourcemap: string | undefined;
|
|
62
62
|
type: "success";
|
|
63
63
|
handler: string;
|
|
64
|
+
out: string;
|
|
65
|
+
sourcemap: string | undefined;
|
|
64
66
|
}>;
|
|
65
67
|
};
|
|
66
68
|
interface Artifact {
|
package/runtime/handlers.js
CHANGED
|
@@ -48,6 +48,26 @@ export const useRuntimeHandlers = lazy(() => {
|
|
|
48
48
|
};
|
|
49
49
|
const handler = result.for(func.runtime);
|
|
50
50
|
const out = path.join(project.paths.artifacts, functionID);
|
|
51
|
+
// Check for mono-bundle mode by doing a preliminary build call
|
|
52
|
+
// In mono-bundle mode, handler returns its own out path immediately without building
|
|
53
|
+
const monoBundleCheck = await handler.build({
|
|
54
|
+
functionID,
|
|
55
|
+
out,
|
|
56
|
+
mode,
|
|
57
|
+
props: func,
|
|
58
|
+
});
|
|
59
|
+
// If mono-bundle detected (handler returned custom out), skip all artifact work
|
|
60
|
+
if (monoBundleCheck.type === "success" && monoBundleCheck.out) {
|
|
61
|
+
bus.publish("function.build.started", { functionID });
|
|
62
|
+
bus.publish("function.build.success", { functionID, monoBundle: true });
|
|
63
|
+
return {
|
|
64
|
+
type: "success",
|
|
65
|
+
handler: monoBundleCheck.handler,
|
|
66
|
+
out: monoBundleCheck.out,
|
|
67
|
+
sourcemap: monoBundleCheck.sourcemap,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
// Non-mono-bundle: follow original flow
|
|
51
71
|
await fs.rm(out, { recursive: true, force: true });
|
|
52
72
|
await fs.mkdir(out, { recursive: true });
|
|
53
73
|
bus.publish("function.build.started", { functionID });
|
|
@@ -7,10 +7,22 @@ import fs from "fs";
|
|
|
7
7
|
import http from "http";
|
|
8
8
|
import url from "url";
|
|
9
9
|
var input = workerData;
|
|
10
|
-
var
|
|
11
|
-
var
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
var monoBundlePath = path.join(input.out, "index.mjs");
|
|
11
|
+
var useMonoBundle = input.handler === "index.handler" && fs.existsSync(monoBundlePath);
|
|
12
|
+
var file;
|
|
13
|
+
var handlerName;
|
|
14
|
+
if (useMonoBundle) {
|
|
15
|
+
file = monoBundlePath;
|
|
16
|
+
handlerName = "handler";
|
|
17
|
+
} else {
|
|
18
|
+
const parsed = path.parse(input.handler);
|
|
19
|
+
const foundFile = [".js", ".jsx", ".mjs", ".cjs"].map((ext) => path.join(input.out, parsed.dir, parsed.name + ext)).find((f) => fs.existsSync(f));
|
|
20
|
+
if (!foundFile) {
|
|
21
|
+
throw new Error(`Could not find handler file for "${input.handler}"`);
|
|
22
|
+
}
|
|
23
|
+
file = foundFile;
|
|
24
|
+
handlerName = parsed.ext.substring(1);
|
|
25
|
+
}
|
|
14
26
|
var fn;
|
|
15
27
|
function fetch(req) {
|
|
16
28
|
return new Promise((resolve, reject) => {
|
|
@@ -44,11 +56,10 @@ function fetch(req) {
|
|
|
44
56
|
try {
|
|
45
57
|
const { href } = url.pathToFileURL(file);
|
|
46
58
|
const mod = await import(href);
|
|
47
|
-
|
|
48
|
-
fn = mod[handler];
|
|
59
|
+
fn = mod[handlerName];
|
|
49
60
|
if (!fn) {
|
|
50
61
|
throw new Error(
|
|
51
|
-
`Function "${
|
|
62
|
+
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(", ")}`
|
|
52
63
|
);
|
|
53
64
|
}
|
|
54
65
|
} catch (ex) {
|