sst 2.31.0 → 2.32.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.
@@ -55,18 +55,22 @@ export class SsrSite extends Construct {
55
55
  const props = {
56
56
  path: ".",
57
57
  typesPath: ".",
58
- waitForInvalidation: false,
59
58
  runtime: "nodejs18.x",
60
59
  timeout: "10 seconds",
61
60
  memorySize: "1024 MB",
62
61
  ...rawProps,
62
+ invalidation: {
63
+ wait: rawProps?.waitForInvalidation,
64
+ paths: "all",
65
+ ...rawProps?.invalidation,
66
+ },
63
67
  };
64
68
  this.id = id;
65
69
  this.props = props;
66
70
  const app = scope.node.root;
67
71
  const stack = Stack.of(this);
68
72
  const self = this;
69
- const { path: sitePath, typesPath, buildCommand, runtime, timeout, memorySize, edge, regional, dev, assets, nodejs, permissions, environment, bind, customDomain, waitForInvalidation, warm, cdk, } = props;
73
+ const { path: sitePath, typesPath, buildCommand, runtime, timeout, memorySize, edge, regional, dev, assets, nodejs, permissions, environment, bind, customDomain, invalidation, warm, cdk, } = props;
70
74
  this.doNotDeploy = !stack.isActive || (app.mode === "dev" && !dev?.deploy);
71
75
  validateSiteExists();
72
76
  validateTimeout();
@@ -259,7 +263,6 @@ export class SsrSite extends Construct {
259
263
  const distribution = new Distribution(self, "CDN", {
260
264
  scopeOverride: self,
261
265
  customDomain,
262
- waitForInvalidation,
263
266
  cdk: {
264
267
  distribution: {
265
268
  // these values can be overwritten
@@ -689,18 +692,7 @@ function handler(event) {
689
692
  return replaceValues;
690
693
  }
691
694
  function createDistributionInvalidation() {
692
- const cdnInvalidationStrategy = assets?.cdnInvalidationStrategy ?? "all";
693
- if (cdnInvalidationStrategy === "never")
694
- return;
695
- if (plan.buildId) {
696
- distribution.createInvalidation(plan.buildId);
697
- return;
698
- }
699
- if (cdnInvalidationStrategy === "always") {
700
- const buildId = Date.now().toString(16) + Math.random().toString(16).slice(2);
701
- distribution.createInvalidation(buildId);
702
- return;
703
- }
695
+ const paths = invalidation.paths;
704
696
  // We will generate a hash based on the contents of the S3 files with cache enabled.
705
697
  // This will be used to determine if we need to invalidate our CloudFront cache.
706
698
  const s3Origin = Object.values(plan.origins).find((origin) => origin.type === "s3");
@@ -711,46 +703,64 @@ function handler(event) {
711
703
  return;
712
704
  // Build invalidation paths
713
705
  const invalidationPaths = [];
714
- if (cdnInvalidationStrategy === "versioned") {
706
+ if (paths === "none") {
707
+ }
708
+ else if (paths === "all") {
709
+ invalidationPaths.push("/*");
710
+ }
711
+ else if (paths === "versioned") {
715
712
  cachedS3Files.forEach((item) => {
716
713
  if (!item.versionedSubDir)
717
714
  return;
718
715
  invalidationPaths.push(path.posix.join("/", item.to, item.versionedSubDir, "*"));
719
716
  });
720
717
  }
718
+ else {
719
+ invalidationPaths.push(...paths);
720
+ }
721
721
  if (invalidationPaths.length === 0)
722
- invalidationPaths.push("/*");
722
+ return;
723
723
  // Build build ID
724
- const hash = crypto.createHash("md5");
725
- cachedS3Files.forEach((item) => {
726
- // The below options are needed to support following symlinks when building zip files:
727
- // - nodir: This will prevent symlinks themselves from being copied into the zip.
728
- // - follow: This will follow symlinks and copy the files within.
729
- // For versioned files, use file path for digest since file version in name should change on content change
730
- if (item.versionedSubDir) {
731
- globSync("**", {
732
- dot: true,
733
- nodir: true,
734
- follow: true,
735
- cwd: path.resolve(sitePath, item.from, item.versionedSubDir),
736
- }).forEach((filePath) => hash.update(filePath));
737
- }
738
- // For non-versioned files, use file content for digest
739
- if (cdnInvalidationStrategy === "all") {
740
- globSync("**", {
741
- ignore: item.versionedSubDir
742
- ? [path.posix.join(item.versionedSubDir, "**")]
743
- : undefined,
744
- dot: true,
745
- nodir: true,
746
- follow: true,
747
- cwd: path.resolve(sitePath, item.from),
748
- }).forEach((filePath) => hash.update(fs.readFileSync(path.resolve(sitePath, item.from, filePath))));
749
- }
724
+ let invalidationBuildId;
725
+ if (plan.buildId) {
726
+ invalidationBuildId = plan.buildId;
727
+ }
728
+ else {
729
+ const hash = crypto.createHash("md5");
730
+ cachedS3Files.forEach((item) => {
731
+ // The below options are needed to support following symlinks when building zip files:
732
+ // - nodir: This will prevent symlinks themselves from being copied into the zip.
733
+ // - follow: This will follow symlinks and copy the files within.
734
+ // For versioned files, use file path for digest since file version in name should change on content change
735
+ if (item.versionedSubDir) {
736
+ globSync("**", {
737
+ dot: true,
738
+ nodir: true,
739
+ follow: true,
740
+ cwd: path.resolve(sitePath, item.from, item.versionedSubDir),
741
+ }).forEach((filePath) => hash.update(filePath));
742
+ }
743
+ // For non-versioned files, use file content for digest
744
+ if (paths !== "versioned") {
745
+ globSync("**", {
746
+ ignore: item.versionedSubDir
747
+ ? [path.posix.join(item.versionedSubDir, "**")]
748
+ : undefined,
749
+ dot: true,
750
+ nodir: true,
751
+ follow: true,
752
+ cwd: path.resolve(sitePath, item.from),
753
+ }).forEach((filePath) => hash.update(fs.readFileSync(path.resolve(sitePath, item.from, filePath))));
754
+ }
755
+ });
756
+ invalidationBuildId = hash.digest("hex");
757
+ Logger.debug(`Generated build ID ${invalidationBuildId}`);
758
+ }
759
+ distribution.createInvalidation({
760
+ version: invalidationBuildId,
761
+ paths: invalidationPaths,
762
+ wait: invalidation.wait,
750
763
  });
751
- const buildId = hash.digest("hex");
752
- Logger.debug(`Generated build ID ${buildId}`);
753
- distribution.createInvalidation(buildId, invalidationPaths);
754
764
  }
755
765
  }
756
766
  static buildDefaultServerCachePolicyProps(allowedHeaders) {
@@ -49,7 +49,6 @@ export class StaticSite extends Construct {
49
49
  this.id = id;
50
50
  this.props = {
51
51
  path: ".",
52
- waitForInvalidation: false,
53
52
  ...props,
54
53
  };
55
54
  this.doNotDeploy =
@@ -74,7 +73,9 @@ export class StaticSite extends Construct {
74
73
  const s3deployCR = this.createS3Deployment(assets, filenamesAsset);
75
74
  this.distribution.node.addDependency(s3deployCR);
76
75
  // Invalidate CloudFront
77
- this.distribution.createInvalidation(this.generateInvalidationId(assets));
76
+ this.distribution.createInvalidation({
77
+ version: this.generateInvalidationId(assets),
78
+ });
78
79
  });
79
80
  app.registerTypes(this);
80
81
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "sideEffects": false,
3
3
  "name": "sst",
4
- "version": "2.31.0",
4
+ "version": "2.32.0",
5
5
  "bin": {
6
6
  "sst": "cli/sst.js"
7
7
  },
@@ -120,7 +120,7 @@
120
120
  "@types/ws": "^8.5.3",
121
121
  "@types/yargs": "^17.0.13",
122
122
  "archiver": "^5.3.1",
123
- "astro-sst": "2.31.0",
123
+ "astro-sst": "2.32.0",
124
124
  "async": "^3.2.4",
125
125
  "tsx": "^3.12.1",
126
126
  "typescript": "^5.2.2",