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/bootstrap.js CHANGED
@@ -2,7 +2,7 @@ import { GetParametersCommand, SSMClient } from "@aws-sdk/client-ssm";
2
2
  import { Tags, Stack, RemovalPolicy, App } from "aws-cdk-lib";
3
3
  import { BlockPublicAccess, Bucket, BucketEncryption, } from "aws-cdk-lib/aws-s3";
4
4
  import { ParameterTier, StringParameter } from "aws-cdk-lib/aws-ssm";
5
- import { useProject } from "./app.js";
5
+ import { useProject } from "./project.js";
6
6
  import { createSpinner } from "./cli/spinner.js";
7
7
  import { Context } from "./context/context.js";
8
8
  import { useAWSClient } from "./credentials.js";
@@ -25,14 +25,14 @@ export const useBootstrap = Context.memo(async () => {
25
25
  const app = new App();
26
26
  const stack = new Stack(app, "SSTBootstrap", {
27
27
  env: {
28
- region: project.region,
28
+ region: project.config.region,
29
29
  },
30
30
  });
31
31
  const tags = {};
32
32
  for (const [key, value] of Object.entries(tags)) {
33
33
  Tags.of(app).add(key, value);
34
34
  }
35
- const bucket = new Bucket(stack, project.region, {
35
+ const bucket = new Bucket(stack, project.config.region, {
36
36
  encryption: BucketEncryption.S3_MANAGED,
37
37
  removalPolicy: RemovalPolicy.DESTROY,
38
38
  autoDeleteObjects: true,
package/bus.d.ts CHANGED
@@ -1,12 +1,12 @@
1
1
  export interface Events {
2
2
  }
3
- export declare type EventTypes = keyof Events;
4
- export declare type EventPayload<Type extends EventTypes = EventTypes> = {
3
+ export type EventTypes = keyof Events;
4
+ export type EventPayload<Type extends EventTypes = EventTypes> = {
5
5
  type: Type;
6
6
  sourceID: string;
7
7
  properties: Events[Type];
8
8
  };
9
- declare type Subscription = {
9
+ type Subscription = {
10
10
  type: EventTypes;
11
11
  cb: (payload: any) => void;
12
12
  };
package/cache.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import path from "path";
2
2
  import fs from "fs/promises";
3
- import { useProject } from "./app.js";
3
+ import { useProject } from "./project.js";
4
4
  import { Logger } from "./logger.js";
5
5
  import { Context } from "./context/context.js";
6
6
  export const useCache = Context.memo(async () => {
@@ -4,7 +4,7 @@ import { ISDK, SdkProvider } from "aws-cdk/lib/api/aws-auth/index.js";
4
4
  import { ToolkitInfo } from "aws-cdk/lib/api/toolkit-info.js";
5
5
  import { ResourcesToImport } from "aws-cdk/lib/api/util/cloudformation.js";
6
6
  import { StackActivityProgress } from "aws-cdk/lib/api/util/cloudformation/stack-activity-monitor.js";
7
- declare type TemplateBodyParameter = {
7
+ type TemplateBodyParameter = {
8
8
  TemplateBody?: string;
9
9
  TemplateURL?: string;
10
10
  };
@@ -166,7 +166,7 @@ export interface DeployStackOptions {
166
166
  */
167
167
  readonly assetParallelism?: boolean;
168
168
  }
169
- export declare type DeploymentMethod = DirectDeploymentMethod | ChangeSetDeploymentMethod;
169
+ export type DeploymentMethod = DirectDeploymentMethod | ChangeSetDeploymentMethod;
170
170
  export interface DirectDeploymentMethod {
171
171
  readonly method: "direct";
172
172
  }
@@ -10,7 +10,6 @@ import { contentHash } from "aws-cdk/lib/util/content-hash.js";
10
10
  import { CfnEvaluationException } from "aws-cdk/lib/api/evaluate-cloudformation-template.js";
11
11
  import { tryHotswapDeployment } from "aws-cdk/lib/api/hotswap-deployments.js";
12
12
  import { changeSetHasNoChanges, CloudFormationStack, TemplateParameters, waitForChangeSet, waitForStackDeploy, waitForStackDelete, } from "aws-cdk/lib/api/util/cloudformation.js";
13
- import { StackActivityMonitor, } from "aws-cdk/lib/api/util/cloudformation/stack-activity-monitor.js";
14
13
  import { blue } from "colorette";
15
14
  const LARGE_TEMPLATE_SIZE_KB = 50;
16
15
  export async function deployStack(options) {
@@ -261,14 +260,19 @@ class FullCloudFormationDeployment {
261
260
  }
262
261
  }
263
262
  async monitorDeployment(startTime, expectedChanges) {
264
- const monitor = this.options.quiet
265
- ? undefined
266
- : StackActivityMonitor.withDefaultPrinter(this.cfn, this.stackName, this.stackArtifact, {
267
- resourcesTotal: expectedChanges,
268
- progress: this.options.progress,
269
- changeSetCreationTime: startTime,
270
- ci: this.options.ci,
271
- }).start();
263
+ // const monitor = this.options.quiet
264
+ // ? undefined
265
+ // : StackActivityMonitor.withDefaultPrinter(
266
+ // this.cfn,
267
+ // this.stackName,
268
+ // this.stackArtifact,
269
+ // {
270
+ // resourcesTotal: expectedChanges,
271
+ // progress: this.options.progress,
272
+ // changeSetCreationTime: startTime,
273
+ // ci: this.options.ci,
274
+ // }
275
+ // ).start();
272
276
  let finalState = this.cloudFormationStack;
273
277
  try {
274
278
  const successStack = await waitForStackDeploy(this.cfn, this.stackName);
@@ -279,10 +283,10 @@ class FullCloudFormationDeployment {
279
283
  finalState = successStack;
280
284
  }
281
285
  catch (e) {
282
- throw new Error(suffixWithErrors(e.message, monitor?.errors));
286
+ throw new Error(suffixWithErrors(e.message /*, monitor?.errors*/));
283
287
  }
284
288
  finally {
285
- await monitor?.stop();
289
+ // await monitor?.stop();
286
290
  }
287
291
  debug("Stack %s has completed updating", this.stackName);
288
292
  return {
@@ -399,11 +403,13 @@ export async function destroyStack(options) {
399
403
  if (!currentStack.exists) {
400
404
  return;
401
405
  }
406
+ /*
402
407
  const monitor = options.quiet
403
- ? undefined
404
- : StackActivityMonitor.withDefaultPrinter(cfn, deployName, options.stack, {
405
- ci: options.ci,
408
+ ? undefined
409
+ : StackActivityMonitor.withDefaultPrinter(cfn, deployName, options.stack, {
410
+ ci: options.ci,
406
411
  }).start();
412
+ */
407
413
  try {
408
414
  await cfn
409
415
  .deleteStack({ StackName: deployName, RoleARN: options.roleArn })
@@ -415,12 +421,14 @@ export async function destroyStack(options) {
415
421
  }
416
422
  }
417
423
  catch (e) {
418
- throw new Error(suffixWithErrors(e.message, monitor?.errors));
424
+ throw new Error(suffixWithErrors(e.message /* , monitor?.errors */));
419
425
  }
420
426
  finally {
427
+ /*
421
428
  if (monitor) {
422
- await monitor.stop();
429
+ await monitor.stop();
423
430
  }
431
+ */
424
432
  }
425
433
  }
426
434
  /**
@@ -1,4 +1,4 @@
1
- import { useProject } from "../../app.js";
1
+ import { useProject } from "../../project.js";
2
2
  export const bind = (program) => program.command("bind <command>", "Binds blah", (yargs) => yargs.positional("command", {
3
3
  type: "string",
4
4
  describe: "Command to bind to",
@@ -16,7 +16,7 @@ export const bind = (program) => program.command("bind <command>", "Binds blah",
16
16
  AWS_ACCESS_KEY_ID: credentials.accessKeyId,
17
17
  AWS_SECRET_ACCESS_KEY: credentials.secretAccessKey,
18
18
  AWS_SESSION_TOKEN: credentials.sessionToken,
19
- AWS_REGION: project.region,
19
+ AWS_REGION: project.config.region,
20
20
  PATH: process.env.PATH,
21
21
  },
22
22
  stdio: "inherit",
@@ -1,11 +1,11 @@
1
+ import { useProject } from "../../project.js";
1
2
  import { createSpinner } from "../spinner.js";
2
- export const build = (program) => program.command("build", "Build stacks code", yargs => yargs.option("from", { type: "string" }), async () => {
3
+ export const build = (program) => program.command("build", "Build stacks code", (yargs) => yargs.option("from", { type: "string" }), async () => {
3
4
  const { Stacks } = await import("../../stacks/index.js");
4
5
  const spinner = createSpinner("Building stacks").start();
5
- const fn = await Stacks.build();
6
6
  await Stacks.synth({
7
- fn,
8
- mode: "deploy"
7
+ fn: useProject().stacks,
8
+ mode: "deploy",
9
9
  });
10
10
  spinner.succeed();
11
11
  process.exit(0);
@@ -1,4 +1,5 @@
1
1
  import { printDeploymentResults } from "../ui/deploy.js";
2
+ import { createSpinner } from "../spinner.js";
2
3
  export const deploy = (program) => program.command("deploy [filter]", "Work on your SST app locally", (yargs) => yargs
3
4
  .option("from", { type: "string" })
4
5
  .option("fullscreen", {
@@ -10,22 +11,24 @@ export const deploy = (program) => program.command("deploy [filter]", "Work on y
10
11
  const React = await import("react");
11
12
  const { CloudAssembly } = await import("aws-cdk-lib/cx-api");
12
13
  const { blue, bold } = await import("colorette");
13
- const { useProject } = await import("../../app.js");
14
+ const { useProject } = await import("../../project.js");
14
15
  const { Stacks } = await import("../../stacks/index.js");
15
16
  const { render } = await import("ink");
16
17
  const { DeploymentUI } = await import("../ui/deploy.js");
18
+ const project = useProject();
17
19
  const assembly = await (async function () {
18
20
  if (args.from) {
19
21
  const result = new CloudAssembly(args.from);
20
22
  return result;
21
23
  }
22
- const fn = await Stacks.build();
23
- return await Stacks.synth({
24
- fn,
24
+ const spinner = createSpinner("Building stacks");
25
+ const result = await Stacks.synth({
26
+ fn: project.stacks,
25
27
  mode: "deploy",
26
28
  });
29
+ spinner.succeed();
30
+ return result;
27
31
  })();
28
- const project = useProject();
29
32
  const target = assembly.stacks.filter((s) => !args.filter ||
30
33
  s.stackName.toLowerCase().includes(args.filter.toLowerCase()));
31
34
  if (!target.length) {
@@ -33,7 +36,7 @@ export const deploy = (program) => program.command("deploy [filter]", "Work on y
33
36
  process.exit(1);
34
37
  return;
35
38
  }
36
- console.log(`Deploying ${bold(target.length + " stacks")} for stage ${blue(project.stage)}...`);
39
+ console.log(`Deploying ${bold(target.length + " stacks")} for stage ${blue(project.config.stage)}...`);
37
40
  let component = undefined;
38
41
  if (args.fullscreen) {
39
42
  process.stdout.write("\x1b[?1049h");
@@ -44,5 +47,7 @@ export const deploy = (program) => program.command("deploy [filter]", "Work on y
44
47
  component.unmount();
45
48
  process.stdout.write("\x1b[?1049l");
46
49
  printDeploymentResults(results);
50
+ if (Object.values(results).some((stack) => Stacks.isFailed(stack.status)))
51
+ process.exit(1);
47
52
  process.exit(0);
48
53
  });
@@ -4,11 +4,11 @@ import crypto from "crypto";
4
4
  import { printDeploymentResults } from "../ui/deploy.js";
5
5
  import { useFunctions } from "../../constructs/Function.js";
6
6
  import { dim, gray, yellow } from "colorette";
7
- import { useProject } from "../../app.js";
8
7
  import { SiteEnv } from "../../site-env.js";
9
8
  import { usePothosBuilder } from "./plugins/pothos.js";
10
9
  import { useKyselyTypeGenerator } from "./plugins/kysely.js";
11
10
  import { useRDSWarmer } from "./plugins/warmer.js";
11
+ import { useProject } from "../../project.js";
12
12
  export const dev = (program) => program.command(["start", "dev"], "Work on your SST app locally", (yargs) => yargs.option("fullscreen", {
13
13
  type: "boolean",
14
14
  describe: "Disable full screen UI",
@@ -34,13 +34,13 @@ export const dev = (program) => program.command(["start", "dev"], "Work on your
34
34
  const useFunctionLogger = Context.memo(async () => {
35
35
  const bus = useBus();
36
36
  bus.subscribe("function.invoked", async (evt) => {
37
- console.log(bold(magenta(`Invoked `)), bold(useFunctions().fromID(evt.properties.functionID).handler));
37
+ console.log(bold(magenta(`Invoked `)), useFunctions().fromID(evt.properties.functionID).handler);
38
38
  });
39
39
  bus.subscribe("function.build.success", async (evt) => {
40
- console.log(bold(gray(`Built `)), bold(useFunctions().fromID(evt.properties.functionID).handler));
40
+ console.log(bold(gray(`Built `)), useFunctions().fromID(evt.properties.functionID).handler);
41
41
  });
42
42
  bus.subscribe("function.build.failed", async (evt) => {
43
- console.log(bold(red(`Build failed `)), bold(useFunctions().fromID(evt.properties.functionID).handler));
43
+ console.log(bold(red(`Build failed `)), useFunctions().fromID(evt.properties.functionID).handler);
44
44
  console.log(dim(evt.properties.errors.join("\n")));
45
45
  });
46
46
  bus.subscribe("worker.stdout", async (evt) => {
@@ -50,14 +50,14 @@ export const dev = (program) => program.command(["start", "dev"], "Work on your
50
50
  const line = lines[i];
51
51
  lines[i] = " " + line;
52
52
  }
53
- console.log(bold(blue(`Log `)), bold(useFunctions().fromID(evt.properties.functionID).handler));
53
+ console.log(bold(blue(`Log `)), useFunctions().fromID(evt.properties.functionID).handler);
54
54
  console.log(dim(lines.join("\n")));
55
55
  });
56
56
  bus.subscribe("function.success", async (evt) => {
57
- console.log(bold(green(`Success `)), bold(useFunctions().fromID(evt.properties.functionID).handler));
57
+ console.log(bold(green(`Success `)), useFunctions().fromID(evt.properties.functionID).handler);
58
58
  });
59
59
  bus.subscribe("function.error", async (evt) => {
60
- console.log(bold(red(`Error `)), bold(useFunctions().fromID(evt.properties.functionID).handler), evt.properties.errorMessage);
60
+ console.log(bold(red(`Error `)), useFunctions().fromID(evt.properties.functionID).handler, evt.properties.errorMessage);
61
61
  for (const line of evt.properties.trace || []) {
62
62
  console.log(` ${dim(line)}`);
63
63
  }
@@ -65,17 +65,19 @@ export const dev = (program) => program.command(["start", "dev"], "Work on your
65
65
  });
66
66
  const useStackBuilder = Context.memo(async () => {
67
67
  const watcher = useWatcher();
68
- const bus = useBus();
69
68
  const project = useProject();
69
+ const bus = useBus();
70
70
  let lastDeployed;
71
71
  let pending;
72
72
  let isDeploying = false;
73
73
  async function build() {
74
74
  const spinner = createSpinner("Building stacks").start();
75
75
  try {
76
- const fn = await Stacks.build();
76
+ const [metafile, sstConfig] = await Stacks.load(project.paths.config);
77
+ project.metafile = metafile;
78
+ project.stacks = sstConfig.stacks;
77
79
  const assembly = await Stacks.synth({
78
- fn,
80
+ fn: project.stacks,
79
81
  outDir: `.sst/cdk.out`,
80
82
  mode: "dev",
81
83
  });
@@ -151,14 +153,10 @@ export const dev = (program) => program.command(["start", "dev"], "Work on your
151
153
  .digest("hex");
152
154
  return hash;
153
155
  }
154
- let metafile;
155
- bus.subscribe("stack.built", async (evt) => {
156
- metafile = evt.properties.metafile;
157
- });
158
156
  watcher.subscribe("file.changed", async (evt) => {
159
- if (!metafile)
157
+ if (!project.metafile)
160
158
  return;
161
- if (!metafile.inputs[evt.properties.relative])
159
+ if (!project.metafile.inputs[evt.properties.relative])
162
160
  return;
163
161
  build();
164
162
  });
@@ -1,4 +1,4 @@
1
- import { useProject } from "../../app.js";
1
+ import { useProject } from "../../project.js";
2
2
  import { createSpinner } from "../spinner.js";
3
3
  import fs from "fs/promises";
4
4
  import path from "path";
@@ -10,17 +10,18 @@ export const env = (program) => program.command("env <command>", "description",
10
10
  demandOption: true,
11
11
  }), async (args) => {
12
12
  const project = useProject();
13
- const spinner = createSpinner("Waiting for SST to start").start();
13
+ let spinner;
14
14
  while (true) {
15
15
  const exists = await fs
16
16
  .access(SiteEnv.valuesFile())
17
17
  .then(() => true)
18
18
  .catch(() => false);
19
19
  if (!exists) {
20
+ spinner = createSpinner("Waiting for SST to start").start();
20
21
  await new Promise((resolve) => setTimeout(resolve, 1000));
21
22
  continue;
22
23
  }
23
- spinner.succeed();
24
+ spinner?.succeed();
24
25
  const sites = await SiteEnv.values();
25
26
  const current = path.relative(project.paths.root, process.cwd());
26
27
  const env = sites[current] || {};
@@ -5,7 +5,7 @@ import * as fs from "fs/promises";
5
5
  import { DatabaseMetadata, EnumCollection, PostgresDialect, Serializer, Transformer, } from "kysely-codegen";
6
6
  import { Context } from "../../../context/context.js";
7
7
  import { useBus } from "../../../bus.js";
8
- import { useProject } from "../../../app.js";
8
+ import { useProject } from "../../../project.js";
9
9
  export const useKyselyTypeGenerator = Context.memo(async () => {
10
10
  let databases = [];
11
11
  const bus = useBus();
@@ -21,7 +21,7 @@ export const useKyselyTypeGenerator = Context.memo(async () => {
21
21
  resourceArn: db.clusterArn,
22
22
  database: db.defaultDatabaseName,
23
23
  client: new RDSDataService({
24
- region: project.region,
24
+ region: project.config.region,
25
25
  }),
26
26
  },
27
27
  }),
@@ -5,7 +5,7 @@ export const remove = (program) => program.command("remove [filter]", "Remove al
5
5
  const React = await import("react");
6
6
  const { CloudAssembly } = await import("aws-cdk-lib/cx-api");
7
7
  const { blue, bold } = await import("colorette");
8
- const { useProject } = await import("../../app.js");
8
+ const { useProject } = await import("../../project.js");
9
9
  const { Stacks } = await import("../../stacks/index.js");
10
10
  const { render } = await import("ink");
11
11
  const { DeploymentUI } = await import("../ui/deploy.js");
@@ -14,9 +14,9 @@ export const remove = (program) => program.command("remove [filter]", "Remove al
14
14
  const result = new CloudAssembly(args.from);
15
15
  return result;
16
16
  }
17
- const fn = await Stacks.build();
17
+ const project = useProject();
18
18
  return await Stacks.synth({
19
- fn,
19
+ fn: project.stacks,
20
20
  mode: "remove",
21
21
  });
22
22
  })();
@@ -26,9 +26,8 @@ export const remove = (program) => program.command("remove [filter]", "Remove al
26
26
  if (!target.length) {
27
27
  console.log(`No stacks found matching ${blue(args.filter)}`);
28
28
  process.exit(1);
29
- return;
30
29
  }
31
- console.log(`Removing ${bold(target.length + " stacks")} for stage ${blue(project.stage)}...`);
30
+ console.log(`Removing ${bold(target.length + " stacks")} for stage ${blue(project.config.stage)}...`);
32
31
  process.stdout.write("\x1b[?1049h");
33
32
  const component = render(React.createElement(DeploymentUI, { stacks: target.map((s) => s.stackName) }));
34
33
  const results = await Stacks.removeMany(target);
@@ -1,17 +1,17 @@
1
1
  import { green, yellow } from "colorette";
2
2
  import fs from "fs/promises";
3
3
  import path from "path";
4
- const PACKAGE_MATCH = ["sst", "aws-cdk", "@aws-cdk"];
4
+ const PACKAGE_MATCH = ["sst", "aws-cdk", "@aws-cdk", "constructs"];
5
5
  const FIELDS = ["dependencies", "devDependencies"];
6
6
  export const update = (program) => program.command("update [ver]", "Update SST and CDK packages to another version", (yargs) => yargs.positional("ver", {
7
7
  type: "string",
8
8
  describe: "Optional SST version to update to",
9
9
  }), async (args) => {
10
10
  const { fetch } = await import("undici");
11
- const { useProject } = await import("../../app.js");
11
+ const { useProject } = await import("../../project.js");
12
12
  const project = useProject();
13
13
  const files = await find(project.paths.root);
14
- const metadata = await fetch(`https://registry.npmjs.org/sst/${args.ver || "rc"}`).then((resp) => resp.json());
14
+ const metadata = await fetch(`https://registry.npmjs.org/sst/${args.ver || "latest"}`).then((resp) => resp.json());
15
15
  const results = new Map();
16
16
  const tasks = files.map(async (file) => {
17
17
  const data = await fs
@@ -25,9 +25,15 @@ export const update = (program) => program.command("update [ver]", "Update SST a
25
25
  for (const [pkg, existing] of Object.entries(deps)) {
26
26
  if (!PACKAGE_MATCH.some((x) => pkg.startsWith(x)))
27
27
  continue;
28
- const desired = pkg === "sst"
29
- ? metadata.version
30
- : metadata.dependencies["aws-cdk-lib"];
28
+ const desired = (() => {
29
+ if (pkg === "sst")
30
+ return metadata.version;
31
+ if (pkg === "constructs")
32
+ return metadata.dependencies.constructs;
33
+ if (pkg.endsWith("alpha"))
34
+ return metadata.dependencies["@aws-cdk/aws-apigatewayv2-alpha"];
35
+ return metadata.dependencies["aws-cdk-lib"];
36
+ })();
31
37
  if (existing === desired)
32
38
  continue;
33
39
  let arr = results.get(file);
@@ -1,6 +1,6 @@
1
1
  import * as trpc from "@trpc/server";
2
2
  import { DendriformPatch } from "dendriform-immer-patch-optimiser";
3
- export declare type State = {
3
+ export type State = {
4
4
  app: string;
5
5
  stage: string;
6
6
  functions: Record<string, FunctionState>;
@@ -9,13 +9,13 @@ export declare type State = {
9
9
  status: any;
10
10
  };
11
11
  };
12
- export declare type FunctionState = {
12
+ export type FunctionState = {
13
13
  state: "idle" | "building" | "checking";
14
14
  invocations: Invocation[];
15
15
  issues: Record<string, any[]>;
16
16
  warm: boolean;
17
17
  };
18
- export declare type Invocation = {
18
+ export type Invocation = {
19
19
  id: string;
20
20
  request: any;
21
21
  response?: any;
@@ -28,15 +28,15 @@ export declare type Invocation = {
28
28
  timestamp: number;
29
29
  }[];
30
30
  };
31
- export declare type Context = {
31
+ export type Context = {
32
32
  state: State;
33
33
  };
34
34
  export declare const router: import("@trpc/server/dist/declarations/src/router.js").Router<Context, Context, Record<"getCredentials", import("@trpc/server/dist/declarations/src/internals/procedure.js").Procedure<Context, Context, undefined, undefined, {
35
- region: string;
35
+ region: string | undefined;
36
36
  credentials: {
37
37
  accessKeyId: string;
38
38
  secretAccessKey: string;
39
39
  sessionToken: string | undefined;
40
40
  };
41
41
  }>> & Record<"getState", import("@trpc/server/dist/declarations/src/internals/procedure.js").Procedure<Context, Context, undefined, undefined, State>>, Record<"deploy", import("@trpc/server/dist/declarations/src/internals/procedure.js").Procedure<Context, Context, undefined, undefined, void>>, Record<"onStateChange", import("@trpc/server/dist/declarations/src/internals/procedure.js").Procedure<Context, Context, undefined, undefined, trpc.Subscription<DendriformPatch[]>>>, trpc.DefaultErrorShape>;
42
- export declare type Router = typeof router;
42
+ export type Router = typeof router;
@@ -1,5 +1,5 @@
1
1
  import * as trpc from "@trpc/server";
2
- import { useProject } from "../../app.js";
2
+ import { useProject } from "../../project.js";
3
3
  import { useBus } from "../../bus.js";
4
4
  import { useAWSCredentials } from "../../credentials.js";
5
5
  export const router = trpc
@@ -9,7 +9,7 @@ export const router = trpc
9
9
  const project = useProject();
10
10
  const credentials = await useAWSCredentials();
11
11
  return {
12
- region: project.region,
12
+ region: project.config.region,
13
13
  credentials: {
14
14
  accessKeyId: credentials.accessKeyId,
15
15
  secretAccessKey: credentials.secretAccessKey,
@@ -24,7 +24,7 @@ export const router = trpc
24
24
  },
25
25
  })
26
26
  .mutation("deploy", {
27
- async resolve({ ctx }) {
27
+ async resolve() {
28
28
  return;
29
29
  },
30
30
  })
@@ -1,7 +1,7 @@
1
1
  import { FunctionState, State } from "./router.js";
2
2
  import { WritableDraft } from "immer/dist/internal.js";
3
3
  import { DendriformPatch } from "dendriform-immer-patch-optimiser";
4
- declare type Opts = {
4
+ type Opts = {
5
5
  port: number;
6
6
  key: any;
7
7
  cert: any;
@@ -9,13 +9,13 @@ import { applyWSSHandler } from "@trpc/server/adapters/ws/dist/trpc-server-adapt
9
9
  import { router } from "./router.js";
10
10
  import { optimise } from "dendriform-immer-patch-optimiser";
11
11
  import { sync } from "cross-spawn";
12
- import { useProject } from "../../app.js";
12
+ import { useProject } from "../../project.js";
13
13
  import { useBus } from "../../bus.js";
14
14
  export async function useLocalServer(opts) {
15
15
  const project = useProject();
16
16
  let state = {
17
- app: project.name,
18
- stage: project.stage,
17
+ app: project.config.name,
18
+ stage: project.config.stage,
19
19
  live: opts.live,
20
20
  stacks: {
21
21
  status: "idle",
@@ -23,17 +23,12 @@ export async function useLocalServer(opts) {
23
23
  functions: {},
24
24
  };
25
25
  const rest = express();
26
- /*
27
26
  rest.all(`/ping`, (req, res) => {
28
- res.header("Access-Control-Allow-Origin", "*");
29
- res.header("Access-Control-Allow-Methods", "GET, PUT, PATCH, POST, DELETE");
30
- res.header(
31
- "Access-Control-Allow-Headers",
32
- req.header("access-control-request-headers")
33
- );
34
- res.sendStatus(200);
27
+ res.header("Access-Control-Allow-Origin", "*");
28
+ res.header("Access-Control-Allow-Methods", "GET, PUT, PATCH, POST, DELETE");
29
+ res.header("Access-Control-Allow-Headers", req.header("access-control-request-headers"));
30
+ res.sendStatus(200);
35
31
  });
36
- */
37
32
  rest.all(`/proxy*`, express.raw({
38
33
  type: "*/*",
39
34
  limit: "1024mb",
package/cli/program.d.ts CHANGED
@@ -6,4 +6,4 @@ export declare const program: import("yargs").Argv<{
6
6
  } & {
7
7
  region: string | undefined;
8
8
  }>;
9
- export declare type Program = typeof program;
9
+ export type Program = typeof program;
package/cli/program.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import yargs from "yargs";
2
2
  import { hideBin } from "yargs/helpers";
3
- import { initProject } from "../app.js";
3
+ import { initProject } from "../project.js";
4
4
  import { trackCli } from "./telemetry/telemetry.js";
5
5
  export const program = yargs(hideBin(process.argv))
6
6
  .scriptName("sst")
@@ -1,5 +1,5 @@
1
1
  /// <reference types="node" resolution-mode="require"/>
2
- declare type EnvironmentData = {
2
+ type EnvironmentData = {
3
3
  systemPlatform: NodeJS.Platform;
4
4
  systemRelease: string;
5
5
  systemArchitecture: string;
@@ -1,6 +1,6 @@
1
1
  import os from "os";
2
2
  import ciInfo from "ci-info";
3
- import { useProject } from "../../app.js";
3
+ import { useProject } from "../../project.js";
4
4
  let data;
5
5
  export function getEnvironmentData() {
6
6
  if (data) {
package/cli/ui/deploy.js CHANGED
@@ -3,7 +3,7 @@ import { Box, Text } from "ink";
3
3
  import { useBus } from "../../bus.js";
4
4
  import { Stacks } from "../../stacks/index.js";
5
5
  import inkSpinner from "ink-spinner";
6
- import { useProject } from "../../app.js";
6
+ import { useProject } from "../../project.js";
7
7
  import { blue, bold, green, red } from "colorette";
8
8
  // @ts-ignore
9
9
  const { default: Spinner } = inkSpinner;
@@ -77,7 +77,7 @@ export const DeploymentUI = (props) => {
77
77
  "Deploying ",
78
78
  React.createElement(Text, { color: "bold" }, props.stacks.length),
79
79
  " stacks for stage ",
80
- React.createElement(Text, { color: "blue" }, useProject().stage)),
80
+ React.createElement(Text, { color: "blue" }, useProject().config.stage)),
81
81
  Object.entries(stacks).map(([stackID, status]) => {
82
82
  return (React.createElement(React.Fragment, { key: stackID },
83
83
  React.createElement(Text, null,