sst 2.0.0-rc.9 → 2.0.0

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.
Files changed (242) hide show
  1. package/bootstrap.d.ts +2 -4
  2. package/bootstrap.js +208 -61
  3. package/bus.d.ts +3 -3
  4. package/bus.js +1 -1
  5. package/cache.js +1 -1
  6. package/cdk/cloudformation-deployments-wrapper.d.ts +3 -0
  7. package/cdk/cloudformation-deployments-wrapper.js +117 -0
  8. package/cdk/cloudformation-deployments.d.ts +19 -4
  9. package/cdk/deploy-stack.d.ts +17 -2
  10. package/cdk/deploy-stack.js +6 -1
  11. package/cli/colors.d.ts +28 -0
  12. package/cli/colors.js +27 -0
  13. package/cli/commands/bind.d.ts +4 -0
  14. package/cli/commands/bind.js +10 -7
  15. package/cli/commands/bootstrap.d.ts +13 -0
  16. package/cli/commands/bootstrap.js +11 -0
  17. package/cli/commands/build.d.ts +6 -2
  18. package/cli/commands/build.js +13 -8
  19. package/cli/commands/console.d.ts +5 -1
  20. package/cli/commands/console.js +8 -6
  21. package/cli/commands/deploy.d.ts +4 -2
  22. package/cli/commands/deploy.js +69 -29
  23. package/cli/commands/dev.d.ts +5 -1
  24. package/cli/commands/dev.js +157 -79
  25. package/cli/commands/diff.d.ts +15 -0
  26. package/cli/commands/diff.js +61 -0
  27. package/cli/commands/env.d.ts +5 -1
  28. package/cli/commands/env.js +14 -15
  29. package/cli/commands/plugins/kysely.js +13 -5
  30. package/cli/commands/plugins/pothos.js +9 -4
  31. package/cli/commands/remove.d.ts +4 -0
  32. package/cli/commands/remove.js +26 -18
  33. package/cli/commands/secrets/get.d.ts +7 -3
  34. package/cli/commands/secrets/get.js +11 -24
  35. package/cli/commands/secrets/list.d.ts +6 -2
  36. package/cli/commands/secrets/list.js +15 -7
  37. package/cli/commands/secrets/remove.d.ts +8 -4
  38. package/cli/commands/secrets/remove.js +18 -16
  39. package/cli/commands/secrets/secrets.js +3 -3
  40. package/cli/commands/secrets/set.d.ts +8 -6
  41. package/cli/commands/secrets/set.js +16 -33
  42. package/cli/commands/telemetry.d.ts +15 -0
  43. package/cli/commands/telemetry.js +17 -0
  44. package/cli/commands/transform.d.ts +15 -0
  45. package/cli/commands/transform.js +55 -0
  46. package/cli/commands/update.d.ts +6 -2
  47. package/cli/commands/update.js +41 -33
  48. package/cli/commands/version.d.ts +13 -0
  49. package/cli/commands/version.js +7 -0
  50. package/cli/local/router.d.ts +6 -6
  51. package/cli/local/router.js +3 -3
  52. package/cli/local/server.d.ts +5 -3
  53. package/cli/local/server.js +21 -14
  54. package/cli/program.d.ts +5 -1
  55. package/cli/program.js +29 -5
  56. package/cli/spinner.js +2 -0
  57. package/cli/sst.js +35 -23
  58. package/cli/telemetry/environment.d.ts +1 -1
  59. package/cli/telemetry/environment.js +1 -1
  60. package/cli/terminal.d.ts +1 -0
  61. package/cli/terminal.js +8 -0
  62. package/cli/ui/deploy.d.ts +3 -2
  63. package/cli/ui/deploy.js +106 -106
  64. package/cli/ui/functions.d.ts +2 -0
  65. package/cli/ui/functions.js +132 -0
  66. package/cli/ui/header.d.ts +5 -0
  67. package/cli/ui/header.js +16 -0
  68. package/cli/ui/stack.d.ts +1 -0
  69. package/cli/ui/stack.js +6 -0
  70. package/config.d.ts +1 -1
  71. package/config.js +8 -8
  72. package/constructs/Api.d.ts +3 -71
  73. package/constructs/Api.js +3 -42
  74. package/constructs/ApiGatewayV1Api.d.ts +3 -3
  75. package/constructs/ApiGatewayV1Api.js +4 -3
  76. package/constructs/App.d.ts +2 -22
  77. package/constructs/App.js +12 -25
  78. package/constructs/AppSyncApi.d.ts +4 -5
  79. package/constructs/AppSyncApi.js +8 -5
  80. package/constructs/AstroSite.d.ts +2 -3
  81. package/constructs/AstroSite.js +43 -53
  82. package/constructs/Auth.js +27 -16
  83. package/constructs/BaseSite.d.ts +10 -10
  84. package/constructs/BaseSite.js +2 -2
  85. package/constructs/Cognito.js +28 -28
  86. package/constructs/EdgeFunction.d.ts +6 -4
  87. package/constructs/EdgeFunction.js +56 -59
  88. package/constructs/EventBus.js +1 -1
  89. package/constructs/Function.d.ts +4 -44
  90. package/constructs/Function.js +14 -50
  91. package/constructs/FunctionalStack.d.ts +2 -2
  92. package/constructs/Job.d.ts +23 -63
  93. package/constructs/Job.js +11 -32
  94. package/constructs/Metadata.d.ts +18 -20
  95. package/constructs/NextjsSite.d.ts +21 -5
  96. package/constructs/NextjsSite.js +67 -101
  97. package/constructs/Queue.js +10 -10
  98. package/constructs/RDS.d.ts +1 -1
  99. package/constructs/RDS.js +1 -1
  100. package/constructs/RemixSite.d.ts +0 -2
  101. package/constructs/RemixSite.js +20 -20
  102. package/constructs/Script.js +1 -1
  103. package/constructs/Secret.js +5 -3
  104. package/constructs/SolidStartSite.d.ts +2 -3
  105. package/constructs/SolidStartSite.js +42 -52
  106. package/constructs/SsrFunction.d.ts +22 -0
  107. package/constructs/SsrFunction.js +113 -0
  108. package/constructs/SsrSite.d.ts +104 -104
  109. package/constructs/SsrSite.js +196 -217
  110. package/constructs/Stack.d.ts +1 -20
  111. package/constructs/Stack.js +3 -65
  112. package/constructs/StaticSite.d.ts +33 -53
  113. package/constructs/StaticSite.js +92 -118
  114. package/constructs/Table.d.ts +1 -1
  115. package/constructs/Table.js +4 -4
  116. package/constructs/Topic.js +1 -1
  117. package/constructs/cdk/certificate-base.d.ts +18 -0
  118. package/constructs/cdk/certificate-base.js +26 -0
  119. package/constructs/cdk/dns-validated-certificate.d.ts +77 -0
  120. package/constructs/cdk/dns-validated-certificate.js +125 -0
  121. package/constructs/cdk/website-redirect.d.ts +53 -0
  122. package/constructs/cdk/website-redirect.js +77 -0
  123. package/constructs/deferred_task.d.ts +1 -1
  124. package/constructs/deprecated/NextjsSite.js +8 -6
  125. package/constructs/index.d.ts +0 -6
  126. package/constructs/index.js +0 -6
  127. package/constructs/util/apiGatewayV1AccessLog.d.ts +1 -1
  128. package/constructs/util/apiGatewayV2AccessLog.js +4 -4
  129. package/constructs/util/apiGatewayV2Domain.js +9 -2
  130. package/constructs/util/appSyncApiDomain.d.ts +1 -1
  131. package/constructs/util/appSyncApiDomain.js +9 -15
  132. package/constructs/util/duration.d.ts +1 -1
  133. package/constructs/util/functionBinding.js +1 -1
  134. package/constructs/util/permission.d.ts +3 -3
  135. package/constructs/util/permission.js +16 -18
  136. package/constructs/util/size.d.ts +1 -1
  137. package/constructs/util/warning.js +2 -2
  138. package/context/context.d.ts +2 -2
  139. package/context/context.js +4 -4
  140. package/context/handler.d.ts +1 -1
  141. package/credentials.d.ts +1 -1
  142. package/credentials.js +42 -6
  143. package/index.d.ts +1 -0
  144. package/index.js +1 -0
  145. package/iot.js +6 -2
  146. package/logger.js +3 -1
  147. package/node/api/index.d.ts +2 -3
  148. package/node/api/index.js +8 -2
  149. package/node/auth/adapter/adapter.d.ts +1 -1
  150. package/node/auth/adapter/facebook.js +1 -1
  151. package/node/auth/adapter/github.js +4 -4
  152. package/node/auth/adapter/google.d.ts +1 -1
  153. package/node/auth/adapter/google.js +2 -2
  154. package/node/auth/adapter/twitch.js +1 -1
  155. package/node/auth/session.d.ts +1 -1
  156. package/node/config/index.d.ts +2 -2
  157. package/node/config/index.js +3 -8
  158. package/node/job/index.d.ts +2 -2
  159. package/node/site/index.js +3 -5
  160. package/package.json +26 -21
  161. package/pothos.js +1 -0
  162. package/project.d.ts +47 -0
  163. package/{app.js → project.js} +60 -53
  164. package/runtime/handlers/dotnet.d.ts +1 -1
  165. package/runtime/handlers/dotnet.js +4 -4
  166. package/runtime/handlers/go.d.ts +1 -1
  167. package/runtime/handlers/go.js +3 -3
  168. package/runtime/handlers/java.d.ts +1 -1
  169. package/runtime/handlers/java.js +4 -4
  170. package/runtime/handlers/node.d.ts +1 -1
  171. package/runtime/handlers/node.js +60 -39
  172. package/runtime/handlers/python.d.ts +1 -1
  173. package/runtime/handlers/python.js +3 -3
  174. package/runtime/handlers.js +15 -12
  175. package/runtime/iot.js +3 -0
  176. package/runtime/runtime.d.ts +4 -0
  177. package/runtime/server.d.ts +3 -3
  178. package/runtime/server.js +11 -5
  179. package/runtime/workers.d.ts +4 -2
  180. package/runtime/workers.js +13 -3
  181. package/site-env.js +2 -1
  182. package/sst.mjs +6357 -20848
  183. package/stacks/app-metadata.d.ts +7 -0
  184. package/stacks/app-metadata.js +78 -0
  185. package/stacks/assembly.d.ts +1 -0
  186. package/stacks/assembly.js +4 -0
  187. package/stacks/build.d.ts +1 -1
  188. package/stacks/build.js +41 -48
  189. package/stacks/deploy.d.ts +1 -0
  190. package/stacks/deploy.js +128 -7
  191. package/stacks/diff.d.ts +8 -0
  192. package/stacks/diff.js +62 -0
  193. package/stacks/index.d.ts +3 -0
  194. package/stacks/index.js +3 -0
  195. package/stacks/metadata.d.ts +2 -0
  196. package/stacks/metadata.js +14 -12
  197. package/stacks/monitor.d.ts +8 -3
  198. package/stacks/monitor.js +38 -4
  199. package/stacks/remove.js +0 -4
  200. package/stacks/synth.d.ts +1 -0
  201. package/stacks/synth.js +27 -13
  202. package/support/base-site-archiver.mjs +1 -1
  203. package/support/bootstrap-metadata-function/index.mjs +68740 -0
  204. package/support/bridge/bridge.mjs +28 -28
  205. package/support/certificate-requestor/index.js +549 -0
  206. package/support/custom-resources/index.mjs +3824 -26567
  207. package/support/dotnet6-bootstrap/release/dotnet-bootstrap.deps.json +1 -1
  208. package/support/dotnet6-bootstrap/release/dotnet-bootstrap.runtimeconfig.json +1 -1
  209. package/support/edge-function/edge-lambda.mjs +2 -2
  210. package/support/job-invoker/index.mjs +26 -0
  211. package/support/nodejs-runtime/index.mjs +75 -72
  212. package/support/rds-migrator/index.mjs +22 -23
  213. package/support/remix-site-function/edge-server.js +1 -1
  214. package/support/script-function/index.mjs +30485 -0
  215. package/support/{edge-function-code-replacer → sls-nextjs-site-function-code-replacer}/lambda-code-updater.py +0 -0
  216. package/support/ssr-site-function-archiver.mjs +96 -0
  217. package/watcher.js +1 -1
  218. package/app.d.ts +0 -36
  219. package/constructs/DebugApp.d.ts +0 -49
  220. package/constructs/DebugApp.js +0 -63
  221. package/constructs/DebugStack.d.ts +0 -34
  222. package/constructs/DebugStack.js +0 -132
  223. package/constructs/GraphQLApi.d.ts +0 -98
  224. package/constructs/GraphQLApi.js +0 -80
  225. package/constructs/ReactStaticSite.d.ts +0 -20
  226. package/constructs/ReactStaticSite.js +0 -54
  227. package/constructs/Script/cfn-response.d.ts +0 -19
  228. package/constructs/Script/cfn-response.js +0 -77
  229. package/constructs/Script/index.d.ts +0 -1
  230. package/constructs/Script/index.js +0 -78
  231. package/constructs/Script/outbound.d.ts +0 -10
  232. package/constructs/Script/outbound.js +0 -42
  233. package/constructs/Script/util.d.ts +0 -2
  234. package/constructs/Script/util.js +0 -11
  235. package/constructs/ViteStaticSite.d.ts +0 -32
  236. package/constructs/ViteStaticSite.js +0 -66
  237. package/support/astro-site-html-stub/index.html +0 -99
  238. package/support/base-site-archiver.cjs +0 -116
  239. package/support/nextjs-site-html-stub/index.html +0 -99
  240. package/support/remix-site-html-stub/index.html +0 -99
  241. package/support/solid-start-site-html-stub/index.html +0 -99
  242. package/support/static-site-stub/index.html +0 -90
@@ -7,76 +7,83 @@ import { Logger } from "./logger.js";
7
7
  import { Context } from "./context/context.js";
8
8
  import { VisibleError } from "./error.js";
9
9
  import { blue } from "colorette";
10
- import { dynamicImport } from "./util/module.js";
11
10
  import dotenv from "dotenv";
11
+ import { load } from "./stacks/build.js";
12
12
  const DEFAULTS = {
13
- main: "stacks/index.ts",
14
13
  stage: undefined,
15
14
  ssmPrefix: undefined,
16
15
  };
17
- export const ProjectContext = Context.create();
16
+ export const ProjectContext = Context.create("Project");
18
17
  export function useProject() {
19
18
  return ProjectContext.use();
20
19
  }
21
- const CONFIG_EXTENSIONS = [".config.cjs", ".config.mjs", ".config.js", ".json"];
20
+ const CONFIG_EXTENSIONS = [
21
+ ".config.ts",
22
+ ".config.mts",
23
+ ".config.cts",
24
+ ".config.cjs",
25
+ ".config.mjs",
26
+ ".config.js",
27
+ ];
22
28
  export async function initProject(globals) {
23
29
  const root = globals.root || (await findRoot());
24
30
  const out = path.join(root, ".sst");
25
31
  await fs.mkdir(out, {
26
32
  recursive: true,
27
33
  });
28
- async function load() {
29
- const base = await (async function () {
30
- for (const ext of CONFIG_EXTENSIONS) {
31
- const file = path.join(root, "sst" + ext);
32
- try {
33
- await fs.access(file);
34
- }
35
- catch {
36
- continue;
37
- }
38
- if (file.endsWith("js")) {
39
- const fn = await dynamicImport(file);
40
- return await fn.default(globals);
41
- }
42
- if (file.endsWith(".json")) {
43
- const data = await fs.readFile(file);
44
- return Object.assign(DEFAULTS, JSON.parse(data.toString("utf8")));
45
- }
46
- }
47
- throw new VisibleError("Could not found a configuration file", "Make sure one of the following exists", " - sst.config.cjs", " - sst.config.mjs", " - sst.config.js", " - sst.json");
48
- })();
49
- return {
50
- ...DEFAULTS,
51
- ...base,
52
- stage: base.stage ||
53
- globals.stage ||
54
- (await usePersonalStage(out)) ||
55
- (await promptPersonalStage(out)),
56
- profile: base.profile || globals.profile,
57
- region: base.region || globals.region,
58
- };
59
- }
60
- const project = await load();
61
- project.ssmPrefix =
62
- project.ssmPrefix || `/sst/${project.name}/${project.stage}/`;
63
- project.paths = {
64
- root,
65
- out,
66
- artifacts: path.join(out, "artifacts"),
34
+ let file;
35
+ const [metafile, sstConfig] = await (async function () {
36
+ for (const ext of CONFIG_EXTENSIONS) {
37
+ file = path.join(root, "sst" + ext);
38
+ if (!fsSync.existsSync(file))
39
+ continue;
40
+ const [metafile, config] = await load(file);
41
+ return [metafile, config];
42
+ }
43
+ throw new VisibleError("Could not found a configuration file", "Make sure one of the following exists", ...CONFIG_EXTENSIONS.map((x) => ` - sst${x}`));
44
+ })();
45
+ const config = await Promise.resolve(sstConfig.config(globals));
46
+ const stage = globals.stage ||
47
+ config.stage ||
48
+ (await usePersonalStage(out)) ||
49
+ (await promptPersonalStage(out));
50
+ const [version, cdkVersion] = await (async () => {
51
+ try {
52
+ const packageJson = JSON.parse(await fs
53
+ .readFile(url.fileURLToPath(new URL("./package.json", import.meta.url)))
54
+ .then((x) => x.toString()));
55
+ return [packageJson.version, packageJson.dependencies["aws-cdk-lib"]];
56
+ }
57
+ catch {
58
+ return ["unknown", "unknown"];
59
+ }
60
+ })();
61
+ const project = {
62
+ version,
63
+ cdkVersion,
64
+ config: {
65
+ ...config,
66
+ stage,
67
+ profile: process.env.AWS_ACCESS_KEY_ID && process.env.AWS_SECRET_ACCESS_KEY
68
+ ? undefined
69
+ : globals.profile || config.profile,
70
+ region: globals.region || config.region,
71
+ role: globals.role || config.role,
72
+ ssmPrefix: config.ssmPrefix || `/sst/${config.name}/${stage}/`,
73
+ },
74
+ stacks: sstConfig.stacks,
75
+ metafile,
76
+ paths: {
77
+ config: file,
78
+ root,
79
+ out,
80
+ artifacts: path.join(out, "artifacts"),
81
+ },
67
82
  };
68
- try {
69
- const packageJson = JSON.parse(await fs
70
- .readFile(url.fileURLToPath(new URL("./package.json", import.meta.url)))
71
- .then((x) => x.toString()));
72
- project.version = packageJson.version;
73
- }
74
- catch {
75
- project.version = "unknown";
76
- }
77
83
  ProjectContext.provide(project);
78
84
  dotenv.config({
79
- path: path.join(project.paths.root, `.env.${project.stage}`),
85
+ path: path.join(project.paths.root, `.env.${project.config.stage}`),
86
+ override: true,
80
87
  });
81
88
  Logger.debug("Config loaded", project);
82
89
  }
@@ -1 +1 @@
1
- export declare const useDotnetHandler: () => void;
1
+ export declare const useDotnetHandler: () => Promise<void>;
@@ -4,7 +4,7 @@ import { Context } from "../../context/context.js";
4
4
  import { spawn } from "child_process";
5
5
  import { useRuntimeServerConfig } from "../server.js";
6
6
  import { findBelow, isChild } from "../../util/fs.js";
7
- import { useProject } from "../../app.js";
7
+ import { useProject } from "../../project.js";
8
8
  import { execAsync } from "../../util/process.js";
9
9
  import url from "url";
10
10
  const FRAMEWORK_MAP = {
@@ -21,10 +21,10 @@ const BOOTSTRAP_MAP = {
21
21
  "dotnetcore3.1": "dotnet31-bootstrap",
22
22
  dotnet6: "dotnet6-bootstrap",
23
23
  };
24
- export const useDotnetHandler = Context.memo(() => {
25
- const workers = useRuntimeWorkers();
24
+ export const useDotnetHandler = Context.memo(async () => {
25
+ const workers = await useRuntimeWorkers();
26
+ const server = await useRuntimeServerConfig();
26
27
  const handlers = useRuntimeHandlers();
27
- const server = useRuntimeServerConfig();
28
28
  const processes = new Map();
29
29
  const sources = new Map();
30
30
  const handlerName = process.platform === "win32" ? `handler.exe` : `handler`;
@@ -1 +1 @@
1
- export declare const useGoHandler: () => void;
1
+ export declare const useGoHandler: () => Promise<void>;
@@ -9,10 +9,10 @@ import { promisify } from "util";
9
9
  import { useRuntimeServerConfig } from "../server.js";
10
10
  import { isChild } from "../../util/fs.js";
11
11
  const execAsync = promisify(exec);
12
- export const useGoHandler = Context.memo(() => {
13
- const workers = useRuntimeWorkers();
12
+ export const useGoHandler = Context.memo(async () => {
13
+ const workers = await useRuntimeWorkers();
14
+ const server = await useRuntimeServerConfig();
14
15
  const handlers = useRuntimeHandlers();
15
- const server = useRuntimeServerConfig();
16
16
  const processes = new Map();
17
17
  const sources = new Map();
18
18
  const handlerName = process.platform === "win32" ? `handler.exe` : `handler`;
@@ -1 +1 @@
1
- export declare const useJavaHandler: () => void;
1
+ export declare const useJavaHandler: () => Promise<void>;
@@ -8,13 +8,13 @@ import zipLocal from "zip-local";
8
8
  import { spawn } from "child_process";
9
9
  import { useRuntimeServerConfig } from "../server.js";
10
10
  import { existsAsync, findBelow, isChild } from "../../util/fs.js";
11
- import { useProject } from "../../app.js";
11
+ import { useProject } from "../../project.js";
12
12
  import { execAsync } from "../../util/process.js";
13
13
  import url from "url";
14
- export const useJavaHandler = Context.memo(() => {
15
- const workers = useRuntimeWorkers();
14
+ export const useJavaHandler = Context.memo(async () => {
15
+ const workers = await useRuntimeWorkers();
16
+ const server = await useRuntimeServerConfig();
16
17
  const handlers = useRuntimeHandlers();
17
- const server = useRuntimeServerConfig();
18
18
  const processes = new Map();
19
19
  const sources = new Map();
20
20
  const handlerName = process.platform === "win32" ? `handler.exe` : `handler`;
@@ -1 +1 @@
1
- export declare const useNodeHandler: () => void;
1
+ export declare const useNodeHandler: () => Promise<void>;
@@ -2,7 +2,7 @@ import path from "path";
2
2
  import fs from "fs/promises";
3
3
  import { exec } from "child_process";
4
4
  import fsSync from "fs";
5
- import { useProject } from "../../app.js";
5
+ import { useProject } from "../../project.js";
6
6
  import esbuild from "esbuild";
7
7
  import url from "url";
8
8
  import { Worker } from "worker_threads";
@@ -10,8 +10,9 @@ import { useRuntimeHandlers } from "../handlers.js";
10
10
  import { useRuntimeWorkers } from "../workers.js";
11
11
  import { Context } from "../../context/context.js";
12
12
  import { VisibleError } from "../../error.js";
13
- export const useNodeHandler = Context.memo(() => {
14
- const workers = useRuntimeWorkers();
13
+ import { Colors } from "../../cli/colors.js";
14
+ export const useNodeHandler = Context.memo(async () => {
15
+ const workers = await useRuntimeWorkers();
15
16
  const handlers = useRuntimeHandlers();
16
17
  const cache = {};
17
18
  const project = useProject();
@@ -79,7 +80,10 @@ export const useNodeHandler = Context.memo(() => {
79
80
  const target = path.join(input.out, !relative.startsWith("..") && !path.isAbsolute(relative)
80
81
  ? relative
81
82
  : "", parsed.name + extension);
82
- const handler = path.relative(input.out, target.replace(extension, parsed.ext));
83
+ const handler = path
84
+ .relative(input.out, target.replace(extension, parsed.ext))
85
+ .split(path.sep)
86
+ .join(path.posix.sep);
83
87
  if (exists?.rebuild) {
84
88
  const result = await exists.rebuild();
85
89
  cache[input.functionID] = result;
@@ -99,6 +103,7 @@ export const useNodeHandler = Context.memo(() => {
99
103
  ],
100
104
  keepNames: true,
101
105
  bundle: true,
106
+ logLevel: "silent",
102
107
  metafile: true,
103
108
  ...(isESM
104
109
  ? {
@@ -127,44 +132,60 @@ export const useNodeHandler = Context.memo(() => {
127
132
  minify: nodejs.minify,
128
133
  ...override,
129
134
  };
130
- const result = await esbuild.build(options);
131
- // Install node_modules
132
- if (options.external?.length) {
133
- async function find(dir, target) {
134
- if (dir === "/")
135
- throw new VisibleError("Could not find a package.json file");
136
- if (await fs
137
- .access(path.join(dir, target))
138
- .then(() => true)
139
- .catch(() => false))
140
- return dir;
141
- return find(path.join(dir, ".."), target);
142
- }
143
- if (input.mode === "deploy" && nodejs.install) {
144
- const src = await find(parsed.dir, "package.json");
145
- const json = JSON.parse(await fs
146
- .readFile(path.join(src, "package.json"))
147
- .then((x) => x.toString()));
148
- fs.writeFile(path.join(input.out, "package.json"), JSON.stringify({
149
- dependencies: Object.fromEntries(nodejs.install?.map((x) => [x, json.dependencies?.[x] || "*"])),
150
- }));
151
- await new Promise((resolve) => {
152
- const process = exec("npm install", {
153
- cwd: input.out,
135
+ try {
136
+ const result = await esbuild.build(options);
137
+ // Install node_modules
138
+ if (options.external?.length) {
139
+ async function find(dir, target) {
140
+ if (dir === "/")
141
+ throw new VisibleError("Could not find a package.json file");
142
+ if (await fs
143
+ .access(path.join(dir, target))
144
+ .then(() => true)
145
+ .catch(() => false))
146
+ return dir;
147
+ return find(path.join(dir, ".."), target);
148
+ }
149
+ if (input.mode === "deploy" && nodejs.install) {
150
+ const src = await find(parsed.dir, "package.json");
151
+ const json = JSON.parse(await fs
152
+ .readFile(path.join(src, "package.json"))
153
+ .then((x) => x.toString()));
154
+ fs.writeFile(path.join(input.out, "package.json"), JSON.stringify({
155
+ dependencies: Object.fromEntries(nodejs.install?.map((x) => [x, json.dependencies?.[x] || "*"])),
156
+ }));
157
+ await new Promise((resolve) => {
158
+ const process = exec("npm install", {
159
+ cwd: input.out,
160
+ });
161
+ process.on("exit", () => resolve());
154
162
  });
155
- process.on("exit", () => resolve());
156
- });
157
- }
158
- if (input.mode === "start") {
159
- const dir = path.join(await find(parsed.dir, "package.json"), "node_modules");
160
- await fs.symlink(path.resolve(dir), path.resolve(path.join(input.out, "node_modules")), "dir");
163
+ }
164
+ if (input.mode === "start") {
165
+ const dir = path.join(await find(parsed.dir, "package.json"), "node_modules");
166
+ try {
167
+ await fs.symlink(path.resolve(dir), path.resolve(path.join(input.out, "node_modules")), "dir");
168
+ }
169
+ catch { }
170
+ }
161
171
  }
172
+ cache[input.functionID] = result;
173
+ return {
174
+ type: "success",
175
+ handler,
176
+ };
177
+ }
178
+ catch (ex) {
179
+ const result = ex;
180
+ return {
181
+ type: "error",
182
+ errors: result.errors.flatMap((x) => [
183
+ Colors.bold(x.text),
184
+ x.location?.file || "",
185
+ Colors.dim(x.location?.line, "│", x.location?.lineText),
186
+ ]),
187
+ };
162
188
  }
163
- cache[input.functionID] = result;
164
- return {
165
- type: "success",
166
- handler,
167
- };
168
189
  },
169
190
  });
170
191
  });
@@ -1 +1 @@
1
- export declare const usePythonHandler: () => void;
1
+ export declare const usePythonHandler: () => Promise<void>;
@@ -18,10 +18,10 @@ const RUNTIME_MAP = {
18
18
  "python3.8": Runtime.PYTHON_3_8,
19
19
  "python3.9": Runtime.PYTHON_3_9,
20
20
  };
21
- export const usePythonHandler = Context.memo(() => {
22
- const workers = useRuntimeWorkers();
21
+ export const usePythonHandler = Context.memo(async () => {
22
+ const workers = await useRuntimeWorkers();
23
+ const server = await useRuntimeServerConfig();
23
24
  const handlers = useRuntimeHandlers();
24
- const server = useRuntimeServerConfig();
25
25
  const processes = new Map();
26
26
  const sources = new Map();
27
27
  handlers.register({
@@ -4,7 +4,7 @@ import path from "path";
4
4
  import fs from "fs/promises";
5
5
  import { useWatcher } from "../watcher.js";
6
6
  import { useBus } from "../bus.js";
7
- import { useProject } from "../app.js";
7
+ import { useProject } from "../project.js";
8
8
  import { useFunctions } from "../constructs/Function.js";
9
9
  export const useRuntimeHandlers = Context.memo(() => {
10
10
  const handlers = [];
@@ -19,7 +19,7 @@ export const useRuntimeHandlers = Context.memo(() => {
19
19
  for: (runtime) => {
20
20
  const result = handlers.find((x) => x.canHandle(runtime));
21
21
  if (!result)
22
- throw new Error(`No handler found for runtime ${runtime}`);
22
+ throw new Error(`${runtime} runtime is unsupported`);
23
23
  return result;
24
24
  },
25
25
  async build(functionID, mode) {
@@ -101,17 +101,20 @@ export const useFunctionBuilder = Context.memo(() => {
101
101
  };
102
102
  const watcher = useWatcher();
103
103
  watcher.subscribe("file.changed", async (evt) => {
104
- const functions = useFunctions();
105
- for (const [functionID, props] of Object.entries(functions.all)) {
106
- const handler = handlers.for(props.runtime);
107
- if (!handler?.shouldBuild({
108
- functionID,
109
- file: evt.properties.file,
110
- }))
111
- continue;
112
- await result.build(functionID);
113
- Logger.debug("Rebuilt function", functionID);
104
+ try {
105
+ const functions = useFunctions();
106
+ for (const [functionID, props] of Object.entries(functions.all)) {
107
+ const handler = handlers.for(props.runtime);
108
+ if (!handler?.shouldBuild({
109
+ functionID,
110
+ file: evt.properties.file,
111
+ }))
112
+ continue;
113
+ await result.build(functionID);
114
+ Logger.debug("Rebuilt function", functionID);
115
+ }
114
116
  }
117
+ catch { }
115
118
  });
116
119
  return result;
117
120
  });
package/runtime/iot.js CHANGED
@@ -11,4 +11,7 @@ export const useIOTBridge = Context.memo(async () => {
11
11
  bus.subscribe("function.error", async (evt) => {
12
12
  iot.publish(topic, "function.error", evt.properties);
13
13
  });
14
+ bus.subscribe("function.ack", async (evt) => {
15
+ iot.publish(topic, "function.ack", evt.properties);
16
+ });
14
17
  });
@@ -1,6 +1,10 @@
1
1
  import "../bus.js";
2
2
  declare module "../bus.js" {
3
3
  interface Events {
4
+ "function.ack": {
5
+ workerID: string;
6
+ functionID: string;
7
+ };
4
8
  "function.invoked": {
5
9
  workerID: string;
6
10
  functionID: string;
@@ -1,6 +1,6 @@
1
- export declare const useRuntimeServerConfig: () => {
1
+ export declare const useRuntimeServerConfig: () => Promise<{
2
2
  API_VERSION: string;
3
- url: string;
4
3
  port: number;
5
- };
4
+ url: string;
5
+ }>;
6
6
  export declare const useRuntimeServer: () => Promise<void>;
package/runtime/server.js CHANGED
@@ -4,18 +4,22 @@ import { useBus } from "../bus.js";
4
4
  import { Logger } from "../logger.js";
5
5
  import { useRuntimeWorkers } from "./workers.js";
6
6
  import https from "https";
7
- export const useRuntimeServerConfig = Context.memo(() => {
7
+ import getPort from "get-port";
8
+ export const useRuntimeServerConfig = Context.memo(async () => {
9
+ const port = await getPort({
10
+ port: 12557,
11
+ });
8
12
  return {
9
13
  API_VERSION: "2018-06-01",
10
- url: "http://localhost:12557",
11
- port: 12557,
14
+ port,
15
+ url: `http://localhost:${port}`,
12
16
  };
13
17
  });
14
18
  export const useRuntimeServer = Context.memo(async () => {
15
19
  const bus = useBus();
16
20
  const app = express();
17
- const workers = useRuntimeWorkers();
18
- const cfg = useRuntimeServerConfig();
21
+ const workers = await useRuntimeWorkers();
22
+ const cfg = await useRuntimeServerConfig();
19
23
  const workersWaiting = new Map();
20
24
  const invocationsQueued = new Map();
21
25
  function next(workerID) {
@@ -54,6 +58,8 @@ export const useRuntimeServer = Context.memo(async () => {
54
58
  }), async (req, res) => {
55
59
  const worker = workers.fromID(req.params.workerID);
56
60
  bus.publish("function.error", {
61
+ requestID: workers.getCurrentRequestID(worker.workerID),
62
+ workerID: worker.workerID,
57
63
  functionID: worker.functionID,
58
64
  ...req.body,
59
65
  });
@@ -24,13 +24,15 @@ interface Worker {
24
24
  workerID: string;
25
25
  functionID: string;
26
26
  }
27
- export declare const useRuntimeWorkers: () => {
27
+ export declare const useRuntimeWorkers: () => Promise<{
28
28
  fromID(workerID: string): Worker;
29
+ getCurrentRequestID(workerID: string): string | undefined;
30
+ setCurrentRequestID(workerID: string, requestID: string): void;
29
31
  stdout(workerID: string, message: string): void;
30
32
  exited(workerID: string): void;
31
33
  subscribe: <Type extends "worker.started" | "worker.stopped" | "worker.exited" | "worker.stdout">(type: Type, cb: (payload: import("../bus.js").EventPayload<Type>) => void) => {
32
34
  type: keyof import("../bus.js").Events;
33
35
  cb: (payload: any) => void;
34
36
  };
35
- };
37
+ }>;
36
38
  export {};
@@ -3,12 +3,12 @@ import { useBus } from "../bus.js";
3
3
  import { useFunctionBuilder, useRuntimeHandlers } from "./handlers.js";
4
4
  import { useRuntimeServerConfig } from "./server.js";
5
5
  import { useFunctions } from "../constructs/Function.js";
6
- export const useRuntimeWorkers = Context.memo(() => {
6
+ export const useRuntimeWorkers = Context.memo(async () => {
7
7
  const workers = new Map();
8
8
  const bus = useBus();
9
9
  const handlers = useRuntimeHandlers();
10
10
  const builder = useFunctionBuilder();
11
- const server = useRuntimeServerConfig();
11
+ const server = await useRuntimeServerConfig();
12
12
  handlers.subscribe("function.build.success", async (evt) => {
13
13
  for (const [_, worker] of workers) {
14
14
  if (worker.functionID === evt.properties.functionID) {
@@ -21,8 +21,11 @@ export const useRuntimeWorkers = Context.memo(() => {
21
21
  });
22
22
  const lastRequestId = new Map();
23
23
  bus.subscribe("function.invoked", async (evt) => {
24
+ bus.publish("function.ack", {
25
+ functionID: evt.properties.functionID,
26
+ workerID: evt.properties.workerID,
27
+ });
24
28
  let worker = workers.get(evt.properties.workerID);
25
- lastRequestId.set(evt.properties.workerID, evt.properties.context.awsRequestId);
26
29
  if (worker)
27
30
  return;
28
31
  const props = useFunctions().fromID(evt.properties.functionID);
@@ -32,6 +35,7 @@ export const useRuntimeWorkers = Context.memo(() => {
32
35
  const build = await builder.artifact(evt.properties.functionID);
33
36
  if (!build)
34
37
  return;
38
+ lastRequestId.set(evt.properties.workerID, evt.properties.requestID);
35
39
  await handler.startWorker({
36
40
  ...build,
37
41
  workerID: evt.properties.workerID,
@@ -51,6 +55,12 @@ export const useRuntimeWorkers = Context.memo(() => {
51
55
  fromID(workerID) {
52
56
  return workers.get(workerID);
53
57
  },
58
+ getCurrentRequestID(workerID) {
59
+ return lastRequestId.get(workerID);
60
+ },
61
+ setCurrentRequestID(workerID, requestID) {
62
+ lastRequestId.set(workerID, requestID);
63
+ },
54
64
  stdout(workerID, message) {
55
65
  const worker = workers.get(workerID);
56
66
  bus.publish("worker.stdout", {
package/site-env.js CHANGED
@@ -1,7 +1,7 @@
1
1
  export * as SiteEnv from "./site-env.js";
2
2
  import fs from "fs";
3
3
  import path from "path";
4
- import { useProject } from "./app.js";
4
+ import { useProject } from "./project.js";
5
5
  function keysFile() {
6
6
  return path.join(useProject().paths.out, "site-environment-keys.jsonl");
7
7
  }
@@ -37,6 +37,7 @@ export async function writeValues(input) {
37
37
  await fs.promises.writeFile(file, JSON.stringify(input));
38
38
  }
39
39
  export function append(input) {
40
+ input.path = path.resolve(useProject().paths.root, input.path);
40
41
  fs.appendFileSync(keysFile(), JSON.stringify(input) + "\n");
41
42
  }
42
43
  export function reset() {