sst 2.0.0-rc.2 → 2.0.0-rc.21

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 (107) hide show
  1. package/bootstrap.js +3 -3
  2. package/bus.d.ts +3 -3
  3. package/cache.js +1 -1
  4. package/cdk/deploy-stack.d.ts +2 -2
  5. package/cdk/deploy-stack.js +24 -16
  6. package/cli/commands/bind.js +2 -2
  7. package/cli/commands/build.js +4 -4
  8. package/cli/commands/deploy.js +11 -6
  9. package/cli/commands/dev.js +14 -16
  10. package/cli/commands/env.js +4 -3
  11. package/cli/commands/plugins/kysely.js +2 -2
  12. package/cli/commands/remove.js +4 -5
  13. package/cli/commands/update.js +12 -6
  14. package/cli/local/router.d.ts +6 -6
  15. package/cli/local/router.js +3 -3
  16. package/cli/local/server.d.ts +1 -1
  17. package/cli/local/server.js +7 -12
  18. package/cli/program.d.ts +1 -1
  19. package/cli/program.js +1 -1
  20. package/cli/telemetry/environment.d.ts +1 -1
  21. package/cli/telemetry/environment.js +1 -1
  22. package/cli/ui/deploy.js +2 -2
  23. package/config.js +5 -5
  24. package/constructs/Api.d.ts +3 -3
  25. package/constructs/ApiGatewayV1Api.d.ts +2 -2
  26. package/constructs/App.d.ts +2 -2
  27. package/constructs/App.js +1 -1
  28. package/constructs/AppSyncApi.d.ts +1 -1
  29. package/constructs/AppSyncApi.js +1 -1
  30. package/constructs/Function.d.ts +4 -5
  31. package/constructs/Function.js +6 -14
  32. package/constructs/FunctionalStack.d.ts +2 -2
  33. package/constructs/Job.d.ts +1 -1
  34. package/constructs/Job.js +2 -2
  35. package/constructs/Metadata.d.ts +19 -19
  36. package/constructs/NextjsSite.d.ts +1 -1
  37. package/constructs/NextjsSite.js +21 -4
  38. package/constructs/RDS.d.ts +1 -1
  39. package/constructs/RDS.js +1 -1
  40. package/constructs/ReactStaticSite.d.ts +2 -2
  41. package/constructs/ReactStaticSite.js +2 -1
  42. package/constructs/Script.js +1 -1
  43. package/constructs/SsrSite.d.ts +11 -6
  44. package/constructs/SsrSite.js +56 -43
  45. package/constructs/Stack.d.ts +1 -1
  46. package/constructs/Stack.js +1 -1
  47. package/constructs/StaticSite.d.ts +3 -3
  48. package/constructs/StaticSite.js +9 -9
  49. package/constructs/Table.d.ts +1 -1
  50. package/constructs/ViteStaticSite.d.ts +1 -1
  51. package/constructs/ViteStaticSite.js +2 -1
  52. package/constructs/deferred_task.d.ts +1 -1
  53. package/constructs/deprecated/NextjsSite.js +1 -1
  54. package/constructs/util/apiGatewayV1AccessLog.d.ts +1 -1
  55. package/constructs/util/duration.d.ts +1 -1
  56. package/constructs/util/permission.d.ts +3 -3
  57. package/constructs/util/size.d.ts +1 -1
  58. package/context/handler.d.ts +1 -1
  59. package/credentials.d.ts +1 -1
  60. package/credentials.js +8 -6
  61. package/index.d.ts +1 -0
  62. package/index.js +1 -0
  63. package/iot.js +2 -2
  64. package/logger.js +1 -1
  65. package/node/api/index.d.ts +2 -0
  66. package/node/api/index.js +8 -0
  67. package/node/auth/adapter/adapter.d.ts +1 -1
  68. package/node/auth/adapter/github.js +4 -4
  69. package/node/auth/adapter/google.d.ts +1 -1
  70. package/node/auth/session.d.ts +1 -1
  71. package/node/config/index.d.ts +2 -2
  72. package/node/job/index.d.ts +2 -2
  73. package/package.json +8 -13
  74. package/project.d.ts +44 -0
  75. package/{app.js → project.js} +56 -51
  76. package/runtime/handlers/dotnet.js +1 -1
  77. package/runtime/handlers/java.js +1 -1
  78. package/runtime/handlers/node.js +6 -5
  79. package/runtime/handlers.js +14 -11
  80. package/runtime/runtime.d.ts +4 -0
  81. package/runtime/workers.js +4 -0
  82. package/site-env.js +1 -1
  83. package/sst.mjs +807 -16608
  84. package/stacks/build.d.ts +1 -1
  85. package/stacks/build.js +13 -21
  86. package/stacks/metadata.js +5 -5
  87. package/stacks/monitor.d.ts +1 -1
  88. package/stacks/synth.js +4 -4
  89. package/support/base-site-archiver.mjs +79 -0
  90. package/support/bridge/bridge.mjs +83 -22
  91. package/support/custom-resources/index.mjs +22 -1
  92. package/support/edge-function/edge-lambda.mjs +2 -2
  93. package/support/nodejs-runtime/index.mjs +79 -72
  94. package/support/rds-migrator/index.mjs +27 -23
  95. package/support/script-function/index.mjs +30485 -0
  96. package/support/ssr-site-function-archiver.mjs +96 -0
  97. package/watcher.js +1 -1
  98. package/app.d.ts +0 -36
  99. package/constructs/Script/cfn-response.d.ts +0 -19
  100. package/constructs/Script/cfn-response.js +0 -77
  101. package/constructs/Script/index.d.ts +0 -1
  102. package/constructs/Script/index.js +0 -78
  103. package/constructs/Script/outbound.d.ts +0 -10
  104. package/constructs/Script/outbound.js +0 -42
  105. package/constructs/Script/util.d.ts +0 -2
  106. package/constructs/Script/util.js +0 -11
  107. package/support/base-site-archiver.cjs +0 -116
package/project.d.ts ADDED
@@ -0,0 +1,44 @@
1
+ import { Metafile } from "esbuild";
2
+ import { App } from "./constructs/App.js";
3
+ export interface SSTConfig {
4
+ config: (globals: GlobalOptions) => Promise<ConfigOptions> | ConfigOptions;
5
+ stacks: (app: App) => Promise<void> | void;
6
+ }
7
+ export interface ConfigOptions {
8
+ name: string;
9
+ region?: string;
10
+ stage?: string;
11
+ profile?: string;
12
+ ssmPrefix?: string;
13
+ }
14
+ declare const DEFAULTS: {
15
+ readonly stage: undefined;
16
+ readonly ssmPrefix: undefined;
17
+ };
18
+ interface Project {
19
+ config: ConfigOptions & Required<{
20
+ [key in keyof typeof DEFAULTS]: Exclude<ConfigOptions[key], undefined>;
21
+ }>;
22
+ version: string;
23
+ paths: {
24
+ root: string;
25
+ config: string;
26
+ out: string;
27
+ artifacts: string;
28
+ };
29
+ metafile: Metafile;
30
+ stacks: SSTConfig["stacks"];
31
+ }
32
+ export declare const ProjectContext: {
33
+ use(): Project;
34
+ provide(value: Project): void;
35
+ };
36
+ export declare function useProject(): Project;
37
+ interface GlobalOptions {
38
+ profile?: string;
39
+ stage?: string;
40
+ root?: string;
41
+ region?: string;
42
+ }
43
+ export declare function initProject(globals: GlobalOptions): Promise<void>;
44
+ export {};
@@ -7,10 +7,9 @@ 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 { Stacks } from "./stacks/index.js";
12
12
  const DEFAULTS = {
13
- main: "stacks/index.ts",
14
13
  stage: undefined,
15
14
  ssmPrefix: undefined,
16
15
  };
@@ -18,65 +17,71 @@ export const ProjectContext = Context.create();
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
- }
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
+ try {
39
+ await fs.access(file);
46
40
  }
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"),
41
+ catch {
42
+ continue;
43
+ }
44
+ const [metafile, config] = await Stacks.load(file);
45
+ return [metafile, config];
46
+ }
47
+ throw new VisibleError("Could not found a configuration file", "Make sure one of the following exists", ...CONFIG_EXTENSIONS.map((x) => ` - sst${x}`));
48
+ })();
49
+ const config = await Promise.resolve(sstConfig.config(globals));
50
+ const stage = config.stage ||
51
+ globals.stage ||
52
+ (await usePersonalStage(out)) ||
53
+ (await promptPersonalStage(out));
54
+ const project = {
55
+ version: await (async () => {
56
+ try {
57
+ const packageJson = JSON.parse(await fs
58
+ .readFile(url.fileURLToPath(new URL("./package.json", import.meta.url)))
59
+ .then((x) => x.toString()));
60
+ return packageJson.version;
61
+ }
62
+ catch {
63
+ return "unknown";
64
+ }
65
+ })(),
66
+ config: {
67
+ ...config,
68
+ stage,
69
+ profile: config.profile || globals.profile,
70
+ region: config.region || globals.region,
71
+ ssmPrefix: config.ssmPrefix || `/sst/${config.name}/${stage}/`,
72
+ },
73
+ stacks: sstConfig.stacks,
74
+ metafile,
75
+ paths: {
76
+ config: file,
77
+ root,
78
+ out,
79
+ artifacts: path.join(out, "artifacts"),
80
+ },
67
81
  };
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
82
  ProjectContext.provide(project);
78
83
  dotenv.config({
79
- path: path.join(project.paths.root, `.env.${project.stage}`),
84
+ path: path.join(project.paths.root, `.env.${project.config.stage}`),
80
85
  });
81
86
  Logger.debug("Config loaded", project);
82
87
  }
@@ -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 = {
@@ -8,7 +8,7 @@ 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
14
  export const useJavaHandler = Context.memo(() => {
@@ -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";
@@ -93,9 +93,7 @@ export const useNodeHandler = Context.memo(() => {
93
93
  entryPoints: [file],
94
94
  platform: "node",
95
95
  external: [
96
- ...(nodejs.format === "esm" || input.props.runtime === "nodejs18.x"
97
- ? []
98
- : ["aws-sdk"]),
96
+ ...(isESM || input.props.runtime === "nodejs18.x" ? [] : ["aws-sdk"]),
99
97
  ...(nodejs.install || []),
100
98
  ...(external || []),
101
99
  ],
@@ -159,7 +157,10 @@ export const useNodeHandler = Context.memo(() => {
159
157
  }
160
158
  if (input.mode === "start") {
161
159
  const dir = path.join(await find(parsed.dir, "package.json"), "node_modules");
162
- await fs.symlink(path.resolve(dir), path.resolve(path.join(input.out, "node_modules")), "dir");
160
+ try {
161
+ await fs.symlink(path.resolve(dir), path.resolve(path.join(input.out, "node_modules")), "dir");
162
+ }
163
+ catch { }
163
164
  }
164
165
  }
165
166
  cache[input.functionID] = result;
@@ -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 = [];
@@ -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
  });
@@ -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;
@@ -21,6 +21,10 @@ 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
29
  lastRequestId.set(evt.properties.workerID, evt.properties.context.awsRequestId);
26
30
  if (worker)
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
  }