@intelligems/sst 2.49.6-ig.1 → 2.49.6-ig.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.
@@ -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
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "sideEffects": false,
3
3
  "name": "@intelligems/sst",
4
- "version": "2.49.6-ig.1",
4
+ "version": "2.49.6-ig.3",
5
5
  "bin": {
6
6
  "sst": "cli/sst.js"
7
7
  },
package/package.json.bak CHANGED
@@ -5,7 +5,7 @@
5
5
  },
6
6
  "sideEffects": false,
7
7
  "name": "@intelligems/sst",
8
- "version": "2.49.6-ig.1",
8
+ "version": "2.49.6-ig.3",
9
9
  "bin": {
10
10
  "sst": "cli/sst.js"
11
11
  },
@@ -61,6 +61,48 @@ 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
+ if (input.mode === "start" && monoBundleExists) {
69
+ Colors.line(Colors.prefix, Colors.dim.bold("MonoBundle"), Colors.dim(`mode=${input.mode}, exists=${monoBundleExists}, handler=${input.props.handler}`));
70
+ // Symlink node_modules to mono-bundle dir for external dependencies
71
+ // Only create if symlink doesn't exist or points to wrong location (avoid redundant I/O)
72
+ const handlerFunctionsDir = path.join(project.paths.root, "web/node-backend/src");
73
+ const root = await findAbove(handlerFunctionsDir, "package.json");
74
+ if (root) {
75
+ const sourceNodeModules = path.resolve(root, "node_modules");
76
+ const monoBundleNodeModules = path.join(monoBundleDir, "node_modules");
77
+ try {
78
+ const existingTarget = await fs.readlink(monoBundleNodeModules);
79
+ if (existingTarget === sourceNodeModules) {
80
+ // Symlink already correct, skip
81
+ }
82
+ else {
83
+ // Symlink points to wrong location, recreate
84
+ await fs.rm(monoBundleNodeModules, { recursive: true, force: true });
85
+ await fs.symlink(sourceNodeModules, monoBundleNodeModules, "dir");
86
+ Logger.debug("Symlinked node_modules for mono-bundle from:", sourceNodeModules);
87
+ }
88
+ }
89
+ catch {
90
+ // Symlink doesn't exist, create it
91
+ try {
92
+ await fs.symlink(sourceNodeModules, monoBundleNodeModules, "dir");
93
+ Logger.debug("Symlinked node_modules for mono-bundle from:", sourceNodeModules);
94
+ }
95
+ catch (err) {
96
+ Logger.debug("Failed to symlink node_modules for mono-bundle:", err);
97
+ }
98
+ }
99
+ }
100
+ return {
101
+ type: "success",
102
+ handler: "index.handler",
103
+ out: monoBundleDir,
104
+ };
105
+ }
64
106
  const parsed = path.parse(input.props.handler);
65
107
  const file = [
66
108
  ".ts",
@@ -108,7 +150,8 @@ export const useNodeHandler = () => {
108
150
  try {
109
151
  await fs.symlink(path.resolve(dir), path.resolve(path.join(input.out, "node_modules")), "dir");
110
152
  }
111
- catch { }
153
+ catch {
154
+ }
112
155
  }
113
156
  // Rebuilt using existing esbuild context
114
157
  let ctx = rebuildCache[input.functionID]?.ctx;
@@ -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 {
@@ -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 parsed = path.parse(input.handler);
11
- var file = [".js", ".jsx", ".mjs", ".cjs"].map((ext) => path.join(input.out, parsed.dir, parsed.name + ext)).find((file2) => {
12
- return fs.existsSync(file2);
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
- const handler = parsed.ext.substring(1);
48
- fn = mod[handler];
59
+ fn = mod[handlerName];
49
60
  if (!fn) {
50
61
  throw new Error(
51
- `Function "${handler}" not found in "${input.handler}". Found ${Object.keys(mod).join(", ")}`
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) {