sst 2.18.0 → 2.18.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.
@@ -291,6 +291,7 @@ export const dev = (program) => program.command(["dev", "start"], "Work on your
291
291
  }
292
292
  clear();
293
293
  await printHeader({ console: true, hint: "ready!" });
294
+ await useStackBuilder();
294
295
  await Promise.all([
295
296
  useDisconnector(),
296
297
  useRuntimeWorkers(),
@@ -301,6 +302,5 @@ export const dev = (program) => program.command(["dev", "start"], "Work on your
301
302
  useKyselyTypeGenerator(),
302
303
  useRDSWarmer(),
303
304
  useFunctionLogger(),
304
- useStackBuilder(),
305
305
  ]);
306
306
  });
@@ -63,7 +63,6 @@ export declare class NextjsSite extends SsrSite {
63
63
  protected createCloudFrontDistributionForRegional(): Distribution;
64
64
  protected createCloudFrontDistributionForEdge(): Distribution;
65
65
  private buildImageBehavior;
66
- private buildStaticFileBehavior;
67
66
  protected generateBuildId(): string;
68
67
  getConstructMetadata(): {
69
68
  data: {
@@ -4,7 +4,7 @@ import { Fn, Duration as CdkDuration, RemovalPolicy, CustomResource, } from "aws
4
4
  import { Effect, Policy, PolicyStatement } from "aws-cdk-lib/aws-iam";
5
5
  import { RetentionDays } from "aws-cdk-lib/aws-logs";
6
6
  import { Code, Runtime, Architecture, Function as CdkFunction, FunctionUrlAuthType, } from "aws-cdk-lib/aws-lambda";
7
- import { Distribution, ViewerProtocolPolicy, AllowedMethods, CachedMethods, CachePolicy, } from "aws-cdk-lib/aws-cloudfront";
7
+ import { Distribution, ViewerProtocolPolicy, AllowedMethods, CachedMethods, } from "aws-cdk-lib/aws-cloudfront";
8
8
  import { S3Origin, HttpOrigin } from "aws-cdk-lib/aws-cloudfront-origins";
9
9
  import { Rule, Schedule } from "aws-cdk-lib/aws-events";
10
10
  import { LambdaFunction } from "aws-cdk-lib/aws-events-targets";
@@ -254,9 +254,6 @@ export class NextjsSite extends SsrSite {
254
254
  */
255
255
  const { cdk } = this.props;
256
256
  const cfDistributionProps = cdk?.distribution || {};
257
- const s3Origin = new S3Origin(this.cdk.bucket, {
258
- originPath: "/" + this.buildConfig.clientBuildS3KeyPrefix,
259
- });
260
257
  const cachePolicy = cdk?.serverCachePolicy ??
261
258
  this.buildServerCachePolicy([
262
259
  "accept",
@@ -278,8 +275,6 @@ export class NextjsSite extends SsrSite {
278
275
  "api/*": serverBehavior,
279
276
  "_next/data/*": serverBehavior,
280
277
  "_next/image*": this.buildImageBehavior(cachePolicy),
281
- "_next/*": this.buildStaticFileBehavior(s3Origin),
282
- ...this.buildStaticFileBehaviors(s3Origin),
283
278
  ...(cfDistributionProps.additionalBehaviors || {}),
284
279
  },
285
280
  });
@@ -311,8 +306,6 @@ export class NextjsSite extends SsrSite {
311
306
  "api/*": serverBehavior,
312
307
  "_next/data/*": serverBehavior,
313
308
  "_next/image*": this.buildImageBehavior(cachePolicy),
314
- "_next/*": this.buildStaticFileBehavior(s3Origin),
315
- ...this.buildStaticFileBehaviors(s3Origin),
316
309
  ...(cfDistributionProps.additionalBehaviors || {}),
317
310
  },
318
311
  });
@@ -333,18 +326,6 @@ export class NextjsSite extends SsrSite {
333
326
  responseHeadersPolicy: cdk?.responseHeadersPolicy,
334
327
  };
335
328
  }
336
- buildStaticFileBehavior(s3Origin) {
337
- const { cdk } = this.props;
338
- return {
339
- origin: s3Origin,
340
- viewerProtocolPolicy: ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
341
- allowedMethods: AllowedMethods.ALLOW_GET_HEAD_OPTIONS,
342
- cachedMethods: CachedMethods.CACHE_GET_HEAD_OPTIONS,
343
- compress: true,
344
- cachePolicy: CachePolicy.CACHING_OPTIMIZED,
345
- responseHeadersPolicy: cdk?.responseHeadersPolicy,
346
- };
347
- }
348
329
  generateBuildId() {
349
330
  const filePath = path.join(this.props.path, ".next/BUILD_ID");
350
331
  return fs.readFileSync(filePath).toString();
@@ -13,7 +13,7 @@ export interface RDSProps {
13
13
  /**
14
14
  * Database engine of the cluster. Cannot be changed once set.
15
15
  */
16
- engine: "mysql5.6" | "mysql5.7" | "postgresql10.14" | "postgresql11.13" | "postgresql11.16" | "postgresql13.9";
16
+ engine: "mysql5.6" | "mysql5.7" | "postgresql11.13" | "postgresql11.16" | "postgresql13.9";
17
17
  /**
18
18
  * Name of a database which is automatically created inside the cluster.
19
19
  */
@@ -191,7 +191,7 @@ export declare class RDS extends Construct implements SSTConstruct {
191
191
  getConstructMetadata(): {
192
192
  type: "RDS";
193
193
  data: {
194
- engine: "mysql5.6" | "mysql5.7" | "postgresql10.14" | "postgresql11.13" | "postgresql11.16" | "postgresql13.9";
194
+ engine: "mysql5.6" | "mysql5.7" | "postgresql11.13" | "postgresql11.16" | "postgresql13.9";
195
195
  secretArn: string;
196
196
  types: RDSTypes | undefined;
197
197
  clusterArn: string;
package/constructs/RDS.js CHANGED
@@ -202,11 +202,6 @@ export class RDS extends Construct {
202
202
  version: AuroraMysqlEngineVersion.VER_2_07_1,
203
203
  });
204
204
  }
205
- else if (engine === "postgresql10.14") {
206
- return DatabaseClusterEngine.auroraPostgres({
207
- version: AuroraPostgresEngineVersion.VER_10_14,
208
- });
209
- }
210
205
  else if (engine === "postgresql11.13") {
211
206
  return DatabaseClusterEngine.auroraPostgres({
212
207
  version: AuroraPostgresEngineVersion.VER_11_13,
@@ -1,6 +1,6 @@
1
1
  import { Construct } from "constructs";
2
2
  import { Bucket, BucketProps, IBucket } from "aws-cdk-lib/aws-s3";
3
- import { Function as CdkFunction, IFunction as ICdkFunction, FunctionProps } from "aws-cdk-lib/aws-lambda";
3
+ import { IFunction as ICdkFunction, FunctionProps } from "aws-cdk-lib/aws-lambda";
4
4
  import { IHostedZone } from "aws-cdk-lib/aws-route53";
5
5
  import { Distribution, ICachePolicy, IResponseHeadersPolicy, BehaviorOptions, CachePolicy, Function as CfFunction, FunctionEventType as CfFunctionEventType } from "aws-cdk-lib/aws-cloudfront";
6
6
  import { ICertificate } from "aws-cdk-lib/aws-certificatemanager";
@@ -282,7 +282,7 @@ export declare abstract class SsrSite extends Construct implements SSTConstruct
282
282
  private createS3Deployment;
283
283
  protected createFunctionForRegional(): SsrFunction;
284
284
  protected createFunctionForEdge(): EdgeFunction;
285
- protected createFunctionForDev(): CdkFunction;
285
+ protected createFunctionForDev(): SsrFunction;
286
286
  private grantServerS3Permissions;
287
287
  private grantServerCloudFrontPermissions;
288
288
  private validateCloudFrontDistributionSettings;
@@ -296,7 +296,7 @@ export declare abstract class SsrSite extends Construct implements SSTConstruct
296
296
  eventType: CfFunctionEventType;
297
297
  function: CfFunction;
298
298
  }[];
299
- protected buildStaticFileBehaviors(origin: S3Origin): Record<string, BehaviorOptions>;
299
+ protected addStaticFileBehaviors(): void;
300
300
  protected buildServerCachePolicy(allowedHeaders?: string[]): CachePolicy;
301
301
  protected buildServerOriginRequestPolicy(): import("aws-cdk-lib/aws-cloudfront").IOriginRequestPolicy;
302
302
  private createCloudFrontInvalidation;
@@ -122,6 +122,8 @@ export class SsrSite extends Construct {
122
122
  const assetFileOptions = this.createS3AssetFileOptions();
123
123
  const s3deployCR = this.createS3Deployment(cliLayer, assets, assetFileOptions);
124
124
  this.distribution.node.addDependency(s3deployCR);
125
+ // Add static file behaviors
126
+ this.addStaticFileBehaviors();
125
127
  // Invalidate CloudFront
126
128
  this.createCloudFrontInvalidation();
127
129
  for (const task of this.deferredTaskCallbacks) {
@@ -353,7 +355,7 @@ export class SsrSite extends Construct {
353
355
  if (item === this.buildConfig.clientBuildVersionedSubDir) {
354
356
  fileOptions.push({
355
357
  exclude: "*",
356
- include: `${this.buildConfig.clientBuildVersionedSubDir}/*`,
358
+ include: path.posix.join(this.buildConfig.clientBuildS3KeyPrefix ?? "", this.buildConfig.clientBuildVersionedSubDir, "*"),
357
359
  cacheControl: "public,max-age=31536000,immutable",
358
360
  });
359
361
  }
@@ -464,7 +466,10 @@ export class SsrSite extends Construct {
464
466
  permissions,
465
467
  // note: do not need to set vpc settings b/c this function is not being used
466
468
  });
467
- return ssrFn.function;
469
+ useDeferredTasks().add(async () => {
470
+ await ssrFn.build();
471
+ });
472
+ return ssrFn;
468
473
  }
469
474
  grantServerS3Permissions() {
470
475
  const server = this.serverLambdaCdkFunctionForEdge || this.serverLambdaForRegional;
@@ -511,7 +516,6 @@ function handler(event) {
511
516
  createCloudFrontDistributionForRegional() {
512
517
  const { cdk } = this.props;
513
518
  const cfDistributionProps = cdk?.distribution || {};
514
- const s3Origin = new S3Origin(this.bucket);
515
519
  const cachePolicy = cdk?.serverCachePolicy ?? this.buildServerCachePolicy();
516
520
  return new Distribution(this, "Distribution", {
517
521
  // these values can be overwritten by cfDistributionProps
@@ -523,7 +527,6 @@ function handler(event) {
523
527
  certificate: this.certificate,
524
528
  defaultBehavior: this.buildDefaultBehaviorForRegional(cachePolicy),
525
529
  additionalBehaviors: {
526
- ...this.buildStaticFileBehaviors(s3Origin),
527
530
  ...(cfDistributionProps.additionalBehaviors || {}),
528
531
  },
529
532
  });
@@ -543,7 +546,6 @@ function handler(event) {
543
546
  certificate: this.certificate,
544
547
  defaultBehavior: this.buildDefaultBehaviorForEdge(s3Origin, cachePolicy),
545
548
  additionalBehaviors: {
546
- ...this.buildStaticFileBehaviors(s3Origin),
547
549
  ...(cfDistributionProps.additionalBehaviors || {}),
548
550
  },
549
551
  });
@@ -628,29 +630,23 @@ function handler(event) {
628
630
  },
629
631
  ];
630
632
  }
631
- buildStaticFileBehaviors(origin) {
633
+ addStaticFileBehaviors() {
632
634
  const { cdk } = this.props;
633
- // Create additional behaviours for statics
634
- const staticBehaviourOptions = {
635
- viewerProtocolPolicy: ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
636
- origin,
637
- allowedMethods: AllowedMethods.ALLOW_GET_HEAD_OPTIONS,
638
- cachedMethods: CachedMethods.CACHE_GET_HEAD_OPTIONS,
639
- compress: true,
640
- cachePolicy: CachePolicy.CACHING_OPTIMIZED,
641
- };
642
- // Add behaviour for public folder statics (excluding build)
643
- const staticsBehaviours = {};
635
+ // Create a template for statics behaviours
644
636
  const publicDir = path.join(this.props.path, this.buildConfig.clientBuildOutputDir);
645
637
  for (const item of fs.readdirSync(publicDir)) {
646
- if (fs.statSync(path.join(publicDir, item)).isDirectory()) {
647
- staticsBehaviours[`${item}/*`] = staticBehaviourOptions;
648
- }
649
- else {
650
- staticsBehaviours[item] = staticBehaviourOptions;
651
- }
638
+ const isDir = fs.statSync(path.join(publicDir, item)).isDirectory();
639
+ this.distribution.addBehavior(isDir ? `${item}/*` : item, new S3Origin(this.bucket, {
640
+ originPath: "/" + (this.buildConfig.clientBuildS3KeyPrefix ?? ""),
641
+ }), {
642
+ viewerProtocolPolicy: ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
643
+ allowedMethods: AllowedMethods.ALLOW_GET_HEAD_OPTIONS,
644
+ cachedMethods: CachedMethods.CACHE_GET_HEAD_OPTIONS,
645
+ compress: true,
646
+ cachePolicy: CachePolicy.CACHING_OPTIMIZED,
647
+ responseHeadersPolicy: cdk?.responseHeadersPolicy,
648
+ });
652
649
  }
653
- return staticsBehaviours;
654
650
  }
655
651
  buildServerCachePolicy(allowedHeaders) {
656
652
  return new CachePolicy(this, "ServerCache", {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "sideEffects": false,
3
3
  "name": "sst",
4
- "version": "2.18.0",
4
+ "version": "2.18.2",
5
5
  "bin": {
6
6
  "sst": "cli/sst.js"
7
7
  },
package/sst.mjs CHANGED
@@ -7339,6 +7339,7 @@ Are you sure you want to run this stage in dev mode? [y/N] `,
7339
7339
  }
7340
7340
  clear2();
7341
7341
  await printHeader2({ console: true, hint: "ready!" });
7342
+ await useStackBuilder();
7342
7343
  await Promise.all([
7343
7344
  useDisconnector(),
7344
7345
  useRuntimeWorkers2(),
@@ -7348,8 +7349,7 @@ Are you sure you want to run this stage in dev mode? [y/N] `,
7348
7349
  useMetadata2(),
7349
7350
  useKyselyTypeGenerator2(),
7350
7351
  useRDSWarmer2(),
7351
- useFunctionLogger(),
7352
- useStackBuilder()
7352
+ useFunctionLogger()
7353
7353
  ]);
7354
7354
  }
7355
7355
  );