sst 2.28.3 → 2.28.5

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.
@@ -1,4 +1,3 @@
1
- import { lazy } from "../../util/lazy.js";
2
1
  export const dev = (program) => program.command(["dev", "start"], "Work on your app locally", (yargs) => yargs.option("increase-timeout", {
3
2
  type: "boolean",
4
3
  description: "Increase function timeout",
@@ -19,6 +18,8 @@ export const dev = (program) => program.command(["dev", "start"], "Work on your
19
18
  const { useProject } = await import("../../project.js");
20
19
  const { clear } = await import("../terminal.js");
21
20
  const { getCiInfo } = await import("../ci-info.js");
21
+ const { useMetadataCache } = await import("../../stacks/metadata.js");
22
+ const { lazy } = await import("../../util/lazy.js");
22
23
  try {
23
24
  if (args._[0] === "start") {
24
25
  console.log(yellow(`Warning: ${bold(`sst start`)} has been renamed to ${bold(`sst dev`)}`));
@@ -320,6 +321,7 @@ export const dev = (program) => program.command(["dev", "start"], "Work on your
320
321
  await printHeader({ console: true, hint: "ready!" });
321
322
  await Promise.all([
322
323
  useStackBuilder(),
324
+ useMetadataCache(),
323
325
  useDisconnector(),
324
326
  import("../../runtime/workers.js").then((mod) => mod.useRuntimeWorkers()),
325
327
  import("../../runtime/iot.js").then((mod) => mod.useIOTBridge()),
@@ -99,6 +99,7 @@ type NextjsSiteNormalizedProps = NextjsSiteProps & SsrSiteNormalizedProps;
99
99
  */
100
100
  export declare class NextjsSite extends SsrSite {
101
101
  props: NextjsSiteNormalizedProps;
102
+ private buildId?;
102
103
  constructor(scope: Construct, id: string, props?: NextjsSiteProps);
103
104
  protected plan(bucket: Bucket): {
104
105
  cloudFrontFunctions?: {
@@ -189,7 +190,9 @@ export declare class NextjsSite extends SsrSite {
189
190
  private createRevalidationQueue;
190
191
  private createRevalidationTable;
191
192
  getConstructMetadata(): {
193
+ type: "NextjsSite";
192
194
  data: {
195
+ routes: any[];
193
196
  mode: "placeholder" | "deployed";
194
197
  path: string;
195
198
  runtime: "nodejs14.x" | "nodejs16.x" | "nodejs18.x";
@@ -199,7 +202,9 @@ export declare class NextjsSite extends SsrSite {
199
202
  server: string;
200
203
  secrets: string[];
201
204
  };
202
- type: "NextjsSite";
203
205
  };
206
+ private wrapHandler;
207
+ private getRoutes;
208
+ private useBuildId;
204
209
  }
205
210
  export {};
@@ -11,6 +11,7 @@ import { SsrSite } from "./SsrSite.js";
11
11
  import { toCdkSize } from "./util/size.js";
12
12
  import { PolicyStatement } from "aws-cdk-lib/aws-iam";
13
13
  import { RetentionDays } from "aws-cdk-lib/aws-logs";
14
+ import { VisibleError } from "../error.js";
14
15
  /**
15
16
  * The `NextjsSite` construct is a higher level CDK construct that makes it easy to create a Next.js app.
16
17
  * @example
@@ -23,6 +24,7 @@ import { RetentionDays } from "aws-cdk-lib/aws-logs";
23
24
  * ```
24
25
  */
25
26
  export class NextjsSite extends SsrSite {
27
+ buildId;
26
28
  constructor(scope, id, props) {
27
29
  const { streaming, disableDynamoDBCache, disableIncrementalCache } = {
28
30
  streaming: false,
@@ -32,7 +34,7 @@ export class NextjsSite extends SsrSite {
32
34
  };
33
35
  super(scope, id, {
34
36
  buildCommand: [
35
- "npx --yes open-next@2.2.1 build",
37
+ "npx --yes open-next@2.2.3 build",
36
38
  ...(streaming ? ["--streaming"] : []),
37
39
  ...(disableDynamoDBCache
38
40
  ? ["--dangerously-disable-dynamodb-cache"]
@@ -55,7 +57,7 @@ export class NextjsSite extends SsrSite {
55
57
  const serverConfig = {
56
58
  description: "Next.js server",
57
59
  bundle: path.join(sitePath, ".open-next", "server-function"),
58
- handler: "index.handler",
60
+ handler: this.wrapHandler(),
59
61
  environment: {
60
62
  CACHE_BUCKET_NAME: bucket.bucketName,
61
63
  CACHE_BUCKET_KEY_PREFIX: "_cache",
@@ -189,9 +191,7 @@ export class NextjsSite extends SsrSite {
189
191
  "next-router-state-tree",
190
192
  "next-url",
191
193
  ],
192
- buildId: fs
193
- .readFileSync(path.join(sitePath, ".next/BUILD_ID"))
194
- .toString(),
194
+ buildId: this.useBuildId(),
195
195
  warmerConfig: {
196
196
  function: path.join(sitePath, ".open-next", "warmer-function"),
197
197
  },
@@ -276,9 +276,53 @@ export class NextjsSite extends SsrSite {
276
276
  }
277
277
  }
278
278
  getConstructMetadata() {
279
+ const metadata = this.getConstructMetadataBase();
279
280
  return {
281
+ ...metadata,
280
282
  type: "NextjsSite",
281
- ...this.getConstructMetadataBase(),
283
+ data: {
284
+ ...metadata.data,
285
+ routes: this.getRoutes(),
286
+ },
282
287
  };
283
288
  }
289
+ wrapHandler() {
290
+ const { path: sitePath } = this.props;
291
+ const wrapperName = "nextjssite-index";
292
+ const serverPath = path.join(sitePath, ".open-next", "server-function");
293
+ fs.writeFileSync(path.join(serverPath, `${wrapperName}.mjs`), [
294
+ `import { handler as rawHandler } from "./index.mjs";`,
295
+ `export const handler = (event, context) => {`,
296
+ ` return rawHandler(event, context);`,
297
+ `};`,
298
+ ].join("\n"));
299
+ return `${wrapperName}.handler`;
300
+ }
301
+ getRoutes() {
302
+ const id = this.node.id;
303
+ const { path: sitePath } = this.props;
304
+ try {
305
+ const content = JSON.parse(fs
306
+ .readFileSync(path.join(sitePath, ".next/routes-manifest.json"))
307
+ .toString());
308
+ return [
309
+ ...[...content.dynamicRoutes, ...content.staticRoutes].map(({ page }) => ({
310
+ route: page,
311
+ })),
312
+ ...(content.dataRoutes || []).map(({ page }) => ({
313
+ route: page.endsWith("/")
314
+ ? `/_next/data/${this.useBuildId()}${page}index.json`
315
+ : `/_next/data/${this.useBuildId()}${page}.json`,
316
+ })),
317
+ ];
318
+ }
319
+ catch (e) {
320
+ console.error(e);
321
+ throw new VisibleError(`Failed to read routes data from ".next/routes-manifest.json" for the "${id}" site.`);
322
+ }
323
+ }
324
+ useBuildId() {
325
+ const { path: sitePath } = this.props;
326
+ return fs.readFileSync(path.join(sitePath, ".next/BUILD_ID")).toString();
327
+ }
284
328
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "sideEffects": false,
3
3
  "name": "sst",
4
- "version": "2.28.3",
4
+ "version": "2.28.5",
5
5
  "bin": {
6
6
  "sst": "cli/sst.js"
7
7
  },
@@ -119,7 +119,7 @@
119
119
  "@types/ws": "^8.5.3",
120
120
  "@types/yargs": "^17.0.13",
121
121
  "archiver": "^5.3.1",
122
- "astro-sst": "2.28.3",
122
+ "astro-sst": "2.28.5",
123
123
  "tsx": "^3.12.1",
124
124
  "typescript": "^5.2.2",
125
125
  "vitest": "^0.33.0"