sst 2.0.0-rc.55 → 2.0.0-rc.56

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.
@@ -17,7 +17,9 @@ export const usePothosBuilder = Context.memo(() => {
17
17
  });
18
18
  await fs.writeFile(route.output, schema);
19
19
  // bus.publish("pothos.extracted", { file: route.output });
20
- await Promise.all(route.commands.map((cmd) => execAsync(cmd)));
20
+ if (Array.isArray(route.commands) && route.commands.length > 0) {
21
+ await Promise.all(route.commands.map((cmd) => execAsync(cmd)));
22
+ }
21
23
  Colors.line(Colors.success(`✔`), " Pothos: Extracted pothos schema");
22
24
  }
23
25
  catch (ex) {
@@ -179,19 +179,21 @@ export interface StaticSiteProps {
179
179
  * ```
180
180
  */
181
181
  purgeFiles?: boolean;
182
- /**
183
- * When running `sst start`, a placeholder site is deployed. This is to ensure that the site content remains unchanged, and subsequent `sst start` can start up quickly.
184
- *
185
- * @default false
186
- *
187
- * @example
188
- * ```js
189
- * new StaticSite(stack, "frontend", {
190
- * disablePlaceholder: true
191
- * });
192
- * ```
193
- */
194
- disablePlaceholder?: boolean;
182
+ dev?: {
183
+ /**
184
+ * When running `sst dev, site is not deployed. This is to ensure `sst dev` can start up quickly.
185
+ * @default false
186
+ * @example
187
+ * ```js
188
+ * new StaticSite(stack, "frontend", {
189
+ * dev: {
190
+ * deploy: true
191
+ * }
192
+ * });
193
+ * ```
194
+ */
195
+ deploy?: boolean;
196
+ };
195
197
  vite?: {
196
198
  /**
197
199
  * The path where code-gen should place the type definition for environment variables
@@ -209,11 +211,11 @@ export interface StaticSiteProps {
209
211
  };
210
212
  /**
211
213
  * While deploying, SST waits for the CloudFront cache invalidation process to finish. This ensures that the new content will be served once the deploy command finishes. However, this process can sometimes take more than 5 mins. For non-prod environments it might make sense to pass in `false`. That'll skip waiting for the cache to invalidate and speed up the deploy process.
212
- * @default true
214
+ * @default false
213
215
  * @example
214
216
  * ```js
215
217
  * new StaticSite(stack, "frontend", {
216
- * waitForInvalidation: false
218
+ * waitForInvalidation: true
217
219
  * });
218
220
  * ```
219
221
  */
@@ -280,55 +282,33 @@ export interface StaticSiteCdkDistributionProps extends BaseSiteCdkDistributionP
280
282
  */
281
283
  export declare class StaticSite extends Construct implements SSTConstruct {
282
284
  readonly id: string;
283
- readonly cdk: {
284
- /**
285
- * The internally created CDK `Bucket` instance.
286
- */
287
- bucket: s3.Bucket;
288
- /**
289
- * The internally created CDK `Distribution` instance.
290
- */
291
- distribution: cloudfront.Distribution;
292
- /**
293
- * The Route 53 hosted zone for the custom domain.
294
- */
295
- hostedZone?: route53.IHostedZone;
296
- certificate?: acm.ICertificate;
297
- };
298
285
  private props;
299
- private isPlaceholder;
300
- private assets;
301
- private filenamesAsset?;
302
- private awsCliLayer;
286
+ private doNotDeploy;
287
+ private bucket;
288
+ private distribution;
289
+ private hostedZone?;
290
+ private certificate?;
303
291
  constructor(scope: Construct, id: string, props?: StaticSiteProps);
304
292
  /**
305
293
  * The CloudFront URL of the website.
306
294
  */
307
- get url(): string;
295
+ get url(): string | undefined;
308
296
  /**
309
297
  * If the custom domain is enabled, this is the URL of the website with the custom domain.
310
298
  */
311
299
  get customDomainUrl(): string | undefined;
312
300
  /**
313
- * The ARN of the internally created S3 Bucket.
301
+ * The internally created CDK resources.
314
302
  */
315
- get bucketArn(): string;
316
- /**
317
- * The name of the internally created S3 Bucket.
318
- */
319
- get bucketName(): string;
320
- /**
321
- * The ID of the internally created CloudFront Distribution.
322
- */
323
- get distributionId(): string;
324
- /**
325
- * The domain name of the internally created CloudFront Distribution.
326
- */
327
- get distributionDomain(): string;
303
+ get cdk(): {
304
+ bucket: s3.Bucket;
305
+ distribution: cloudfront.Distribution;
306
+ hostedZone: route53.IHostedZone | undefined;
307
+ certificate: acm.ICertificate | undefined;
308
+ };
328
309
  getConstructMetadata(): {
329
310
  type: "StaticSite";
330
311
  data: {
331
- distributionId: string;
332
312
  customDomainUrl: string | undefined;
333
313
  };
334
314
  };
@@ -23,6 +23,7 @@ import { ENVIRONMENT_PLACEHOLDER, getParameterPath, } from "./util/functionBindi
23
23
  import { gray } from "colorette";
24
24
  import { useProject } from "../project.js";
25
25
  import { SiteEnv } from "../site-env.js";
26
+ import { VisibleError } from "../error.js";
26
27
  const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
27
28
  /////////////////////
28
29
  // Construct
@@ -44,49 +45,53 @@ const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
44
45
  */
45
46
  export class StaticSite extends Construct {
46
47
  id;
47
- cdk;
48
48
  props;
49
- isPlaceholder;
50
- assets;
51
- filenamesAsset;
52
- awsCliLayer;
49
+ doNotDeploy;
50
+ bucket;
51
+ distribution;
52
+ hostedZone;
53
+ certificate;
53
54
  constructor(scope, id, props) {
54
55
  super(scope, props?.cdk?.id || id);
55
56
  const app = scope.node.root;
56
57
  this.id = id;
57
- this.props = { path: ".", ...props };
58
- this.cdk = {};
59
- // Local development or skip build => stub asset
60
- this.isPlaceholder =
61
- (app.local || app.skipBuild) && !this.props.disablePlaceholder;
58
+ this.props = {
59
+ path: ".",
60
+ waitForInvalidation: false,
61
+ ...props,
62
+ };
63
+ this.doNotDeploy = (app.local || app.skipBuild) && !this.props.dev?.deploy;
64
+ this.validateCustomDomainSettings();
65
+ this.registerSiteEnvironment();
66
+ this.generateViteTypes();
67
+ if (this.doNotDeploy) {
68
+ // @ts-ignore
69
+ this.bucket = this.distribution = null;
70
+ return;
71
+ }
72
+ const cliLayer = new AwsCliLayer(this, "AwsCliLayer");
73
+ // Build app
62
74
  const fileSizeLimit = app.isRunningSSTTest()
63
75
  ? // eslint-disable-next-line @typescript-eslint/ban-ts-comment
64
76
  // @ts-ignore: "sstTestFileSizeLimitOverride" not exposed in props
65
77
  this.props.sstTestFileSizeLimitOverride || 200
66
78
  : 200;
67
- this.awsCliLayer = new AwsCliLayer(this, "AwsCliLayer");
68
- this.registerSiteEnvironment();
69
- // Validate input
70
- this.validateCustomDomainSettings();
71
- // Generate Vite types
72
- this.generateViteTypes();
73
- // Build app
74
79
  this.buildApp();
75
- this.assets = this.bundleAssets(fileSizeLimit);
76
- this.filenamesAsset = this.bundleFilenamesAsset();
80
+ const assets = this.bundleAssets(fileSizeLimit);
81
+ const filenamesAsset = this.bundleFilenamesAsset();
77
82
  // Create Bucket
78
- this.cdk.bucket = this.createS3Bucket();
83
+ this.bucket = this.createS3Bucket();
79
84
  // Create Custom Domain
80
- this.cdk.hostedZone = this.lookupHostedZone();
81
- this.cdk.certificate = this.createCertificate();
85
+ this.hostedZone = this.lookupHostedZone();
86
+ this.certificate = this.createCertificate();
82
87
  // Create S3 Deployment
83
- const s3deployCR = this.createS3Deployment();
88
+ const s3deployCR = this.createS3Deployment(cliLayer, assets, filenamesAsset);
84
89
  // Create CloudFront
85
- this.cdk.distribution = this.createCfDistribution();
86
- this.cdk.distribution.node.addDependency(s3deployCR);
90
+ this.distribution = this.createCfDistribution();
91
+ this.distribution.node.addDependency(s3deployCR);
87
92
  // Invalidate CloudFront
88
- const invalidationCR = this.createCloudFrontInvalidation();
89
- invalidationCR.node.addDependency(this.cdk.distribution);
93
+ const invalidationCR = this.createCloudFrontInvalidation(cliLayer, assets);
94
+ invalidationCR.node.addDependency(this.distribution);
90
95
  // Connect Custom Domain to CloudFront Distribution
91
96
  this.createRoute53Records();
92
97
  }
@@ -94,12 +99,18 @@ export class StaticSite extends Construct {
94
99
  * The CloudFront URL of the website.
95
100
  */
96
101
  get url() {
97
- return `https://${this.cdk.distribution.distributionDomainName}`;
102
+ if (this.doNotDeploy) {
103
+ return;
104
+ }
105
+ return `https://${this.distribution.distributionDomainName}`;
98
106
  }
99
107
  /**
100
108
  * If the custom domain is enabled, this is the URL of the website with the custom domain.
101
109
  */
102
110
  get customDomainUrl() {
111
+ if (this.doNotDeploy) {
112
+ return;
113
+ }
103
114
  const { customDomain } = this.props;
104
115
  if (!customDomain) {
105
116
  return;
@@ -112,34 +123,23 @@ export class StaticSite extends Construct {
112
123
  }
113
124
  }
114
125
  /**
115
- * The ARN of the internally created S3 Bucket.
116
- */
117
- get bucketArn() {
118
- return this.cdk.bucket.bucketArn;
119
- }
120
- /**
121
- * The name of the internally created S3 Bucket.
126
+ * The internally created CDK resources.
122
127
  */
123
- get bucketName() {
124
- return this.cdk.bucket.bucketName;
125
- }
126
- /**
127
- * The ID of the internally created CloudFront Distribution.
128
- */
129
- get distributionId() {
130
- return this.cdk.distribution.distributionId;
131
- }
132
- /**
133
- * The domain name of the internally created CloudFront Distribution.
134
- */
135
- get distributionDomain() {
136
- return this.cdk.distribution.distributionDomainName;
128
+ get cdk() {
129
+ if (this.doNotDeploy) {
130
+ throw new VisibleError(`Cannot access CDK resources for the "${this.node.id}" site in dev mode`);
131
+ }
132
+ return {
133
+ bucket: this.bucket,
134
+ distribution: this.distribution,
135
+ hostedZone: this.hostedZone,
136
+ certificate: this.certificate,
137
+ };
137
138
  }
138
139
  getConstructMetadata() {
139
140
  return {
140
141
  type: "StaticSite",
141
142
  data: {
142
- distributionId: this.cdk.distribution.distributionId,
143
143
  customDomainUrl: this.customDomainUrl,
144
144
  },
145
145
  };
@@ -195,9 +195,6 @@ interface ImportMeta {
195
195
  fs.writeFileSync(filePath, content);
196
196
  }
197
197
  buildApp() {
198
- if (this.isPlaceholder) {
199
- return;
200
- }
201
198
  const { path: sitePath, buildCommand } = this.props;
202
199
  // validate site path exists
203
200
  if (!fs.existsSync(sitePath)) {
@@ -222,13 +219,6 @@ interface ImportMeta {
222
219
  }
223
220
  }
224
221
  bundleAssets(fileSizeLimit) {
225
- if (this.isPlaceholder) {
226
- return [
227
- new s3Assets.Asset(this, "Asset", {
228
- path: path.resolve(__dirname, "../support/static-site-stub"),
229
- }),
230
- ];
231
- }
232
222
  const { path: sitePath } = this.props;
233
223
  const buildOutput = this.props.buildOutput || ".";
234
224
  // validate buildOutput exists
@@ -268,9 +258,6 @@ interface ImportMeta {
268
258
  return assets;
269
259
  }
270
260
  bundleFilenamesAsset() {
271
- if (this.isPlaceholder) {
272
- return;
273
- }
274
261
  if (this.props.purgeFiles === false) {
275
262
  return;
276
263
  }
@@ -307,7 +294,7 @@ interface ImportMeta {
307
294
  });
308
295
  }
309
296
  }
310
- createS3Deployment() {
297
+ createS3Deployment(cliLayer, assets, filenamesAsset) {
311
298
  const fileOptions = this.props.fileOptions || [
312
299
  {
313
300
  exclude: "*",
@@ -323,18 +310,18 @@ interface ImportMeta {
323
310
  // Create a Lambda function that will be doing the uploading
324
311
  const uploader = new lambda.Function(this, "S3Uploader", {
325
312
  code: lambda.Code.fromAsset(path.join(__dirname, "../support/base-site-custom-resource")),
326
- layers: [this.awsCliLayer],
313
+ layers: [cliLayer],
327
314
  runtime: lambda.Runtime.PYTHON_3_7,
328
315
  handler: "s3-upload.handler",
329
316
  timeout: Duration.minutes(15),
330
317
  memorySize: 1024,
331
318
  });
332
- this.cdk.bucket.grantReadWrite(uploader);
333
- this.assets.forEach((asset) => asset.grantRead(uploader));
319
+ this.bucket.grantReadWrite(uploader);
320
+ assets.forEach((asset) => asset.grantRead(uploader));
334
321
  // Create the custom resource function
335
322
  const handler = new lambda.Function(this, "S3Handler", {
336
323
  code: lambda.Code.fromAsset(path.join(__dirname, "../support/base-site-custom-resource")),
337
- layers: [this.awsCliLayer],
324
+ layers: [cliLayer],
338
325
  runtime: lambda.Runtime.PYTHON_3_7,
339
326
  handler: "s3-handler.handler",
340
327
  timeout: Duration.minutes(15),
@@ -343,22 +330,22 @@ interface ImportMeta {
343
330
  UPLOADER_FUNCTION_NAME: uploader.functionName,
344
331
  },
345
332
  });
346
- this.cdk.bucket.grantReadWrite(handler);
347
- this.filenamesAsset?.grantRead(handler);
333
+ this.bucket.grantReadWrite(handler);
334
+ filenamesAsset?.grantRead(handler);
348
335
  uploader.grantInvoke(handler);
349
336
  // Create custom resource
350
337
  return new CustomResource(this, "S3Deployment", {
351
338
  serviceToken: handler.functionArn,
352
339
  resourceType: "Custom::SSTBucketDeployment",
353
340
  properties: {
354
- Sources: this.assets.map((asset) => ({
341
+ Sources: assets.map((asset) => ({
355
342
  BucketName: asset.s3BucketName,
356
343
  ObjectKey: asset.s3ObjectKey,
357
344
  })),
358
- DestinationBucketName: this.cdk.bucket.bucketName,
359
- Filenames: this.filenamesAsset && {
360
- BucketName: this.filenamesAsset.s3BucketName,
361
- ObjectKey: this.filenamesAsset.s3ObjectKey,
345
+ DestinationBucketName: this.bucket.bucketName,
346
+ Filenames: filenamesAsset && {
347
+ BucketName: filenamesAsset.s3BucketName,
348
+ ObjectKey: filenamesAsset.s3ObjectKey,
362
349
  },
363
350
  FileOptions: (fileOptions || []).map(({ exclude, include, cacheControl }) => {
364
351
  if (typeof exclude === "string") {
@@ -411,17 +398,9 @@ interface ImportMeta {
411
398
  }
412
399
  }
413
400
  // Build errorResponses
414
- let errorResponses;
415
- // case: sst start => showing stub site, and redirect all routes to the index page
416
- if (this.isPlaceholder) {
417
- errorResponses = buildErrorResponsesForRedirectToIndex(indexPage);
418
- }
419
- else {
420
- errorResponses =
421
- errorPage === "redirect_to_index_page" || errorPage === undefined
422
- ? buildErrorResponsesForRedirectToIndex(indexPage)
423
- : buildErrorResponsesFor404ErrorPage(errorPage);
424
- }
401
+ const errorResponses = errorPage === "redirect_to_index_page" || errorPage === undefined
402
+ ? buildErrorResponsesForRedirectToIndex(indexPage)
403
+ : buildErrorResponsesFor404ErrorPage(errorPage);
425
404
  // Create CloudFront distribution
426
405
  return new cloudfront.Distribution(this, "Distribution", {
427
406
  // these values can be overwritten by cfDistributionProps
@@ -430,19 +409,19 @@ interface ImportMeta {
430
409
  ...cdk?.distribution,
431
410
  // these values can NOT be overwritten by cfDistributionProps
432
411
  domainNames,
433
- certificate: this.cdk.certificate,
412
+ certificate: this.certificate,
434
413
  defaultBehavior: {
435
- origin: new cfOrigins.S3Origin(this.cdk.bucket),
414
+ origin: new cfOrigins.S3Origin(this.bucket),
436
415
  viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
437
416
  ...cdk?.distribution?.defaultBehavior,
438
417
  },
439
418
  });
440
419
  }
441
- createCloudFrontInvalidation() {
420
+ createCloudFrontInvalidation(cliLayer, assets) {
442
421
  // Create a Lambda function that will be doing the invalidation
443
422
  const invalidator = new lambda.Function(this, "CloudFrontInvalidator", {
444
423
  code: lambda.Code.fromAsset(path.join(__dirname, "../support/base-site-custom-resource")),
445
- layers: [this.awsCliLayer],
424
+ layers: [cliLayer],
446
425
  runtime: lambda.Runtime.PYTHON_3_7,
447
426
  handler: "cf-invalidate.handler",
448
427
  timeout: Duration.minutes(15),
@@ -460,22 +439,17 @@ interface ImportMeta {
460
439
  // Need the AssetHash field so the CR gets updated on each deploy
461
440
  const assetsHash = crypto
462
441
  .createHash("md5")
463
- .update(this.assets.map(({ assetHash }) => assetHash).join(""))
442
+ .update(assets.map(({ assetHash }) => assetHash).join(""))
464
443
  .digest("hex");
465
444
  // Create custom resource
466
- const waitForInvalidation = this.isPlaceholder
467
- ? false
468
- : this.props.waitForInvalidation === false
469
- ? false
470
- : true;
471
445
  return new CustomResource(this, "CloudFrontInvalidation", {
472
446
  serviceToken: invalidator.functionArn,
473
447
  resourceType: "Custom::SSTCloudFrontInvalidation",
474
448
  properties: {
475
449
  AssetsHash: assetsHash,
476
- DistributionId: this.cdk.distribution.distributionId,
450
+ DistributionId: this.distribution.distributionId,
477
451
  DistributionPaths: ["/*"],
478
- WaitForInvalidation: waitForInvalidation,
452
+ WaitForInvalidation: this.props.waitForInvalidation,
479
453
  },
480
454
  });
481
455
  }
@@ -543,11 +517,11 @@ interface ImportMeta {
543
517
  }
544
518
  let acmCertificate;
545
519
  // HostedZone is set for Route 53 domains
546
- if (this.cdk.hostedZone) {
520
+ if (this.hostedZone) {
547
521
  if (typeof customDomain === "string") {
548
522
  acmCertificate = new acm.DnsValidatedCertificate(this, "Certificate", {
549
523
  domainName: customDomain,
550
- hostedZone: this.cdk.hostedZone,
524
+ hostedZone: this.hostedZone,
551
525
  region: "us-east-1",
552
526
  });
553
527
  }
@@ -557,7 +531,7 @@ interface ImportMeta {
557
531
  else {
558
532
  acmCertificate = new acm.DnsValidatedCertificate(this, "Certificate", {
559
533
  domainName: customDomain.domainName,
560
- hostedZone: this.cdk.hostedZone,
534
+ hostedZone: this.hostedZone,
561
535
  region: "us-east-1",
562
536
  });
563
537
  }
@@ -572,7 +546,7 @@ interface ImportMeta {
572
546
  }
573
547
  createRoute53Records() {
574
548
  const { customDomain } = this.props;
575
- if (!customDomain || !this.cdk.hostedZone) {
549
+ if (!customDomain || !this.hostedZone) {
576
550
  return;
577
551
  }
578
552
  let recordName;
@@ -587,15 +561,15 @@ interface ImportMeta {
587
561
  // Create DNS record
588
562
  const recordProps = {
589
563
  recordName,
590
- zone: this.cdk.hostedZone,
591
- target: route53.RecordTarget.fromAlias(new route53Targets.CloudFrontTarget(this.cdk.distribution)),
564
+ zone: this.hostedZone,
565
+ target: route53.RecordTarget.fromAlias(new route53Targets.CloudFrontTarget(this.distribution)),
592
566
  };
593
567
  new route53.ARecord(this, "AliasRecord", recordProps);
594
568
  new route53.AaaaRecord(this, "AliasRecordAAAA", recordProps);
595
569
  // Create Alias redirect record
596
570
  if (domainAlias) {
597
571
  new route53Patterns.HttpsRedirect(this, "Redirect", {
598
- zone: this.cdk.hostedZone,
572
+ zone: this.hostedZone,
599
573
  recordNames: [domainAlias],
600
574
  targetDomain: recordName,
601
575
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sst",
3
- "version": "2.0.0-rc.55",
3
+ "version": "2.0.0-rc.56",
4
4
  "bin": {
5
5
  "sst": "cli/sst.js"
6
6
  },
package/sst.mjs CHANGED
@@ -5663,7 +5663,9 @@ var init_pothos2 = __esm({
5663
5663
  schema: route.schema
5664
5664
  });
5665
5665
  await fs15.writeFile(route.output, schema);
5666
- await Promise.all(route.commands.map((cmd) => execAsync4(cmd)));
5666
+ if (Array.isArray(route.commands) && route.commands.length > 0) {
5667
+ await Promise.all(route.commands.map((cmd) => execAsync4(cmd)));
5668
+ }
5667
5669
  Colors.line(Colors.success(`\u2714`), " Pothos: Extracted pothos schema");
5668
5670
  } catch (ex) {
5669
5671
  Colors.line(Colors.danger(`\u2716`), " Pothos: Failed to extract schema:");