sst 2.39.10 → 2.39.12

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.
@@ -207,22 +207,9 @@ export class Function extends CDKFunction {
207
207
  ...props,
208
208
  ...(props.runtime === "container"
209
209
  ? {
210
- code: Code.fromAssetImage(props.handler, {
211
- ...(architecture?.dockerPlatform
212
- ? { platform: Platform.custom(architecture.dockerPlatform) }
213
- : {}),
214
- ...(props.container?.cmd ? { cmd: props.container.cmd } : {}),
215
- ...(props.container?.file
216
- ? { file: props.container.file }
217
- : {}),
218
- ...(props.container?.buildArgs
219
- ? { buildArgs: props.container.buildArgs }
220
- : {}),
221
- exclude: [".sst/dist", ".sst/artifacts"],
222
- ignoreMode: IgnoreMode.GLOB,
223
- }),
224
- handler: CDKHandler.FROM_IMAGE,
225
- runtime: CDKRuntime.FROM_IMAGE,
210
+ code: Code.fromInline("export function placeholder() {}"),
211
+ handler: "index.placeholder",
212
+ runtime: CDKRuntime.NODEJS_18_X,
226
213
  layers: undefined,
227
214
  }
228
215
  : {
@@ -244,7 +231,6 @@ export class Function extends CDKFunction {
244
231
  useDeferredTasks().add(async () => {
245
232
  if (props.runtime === "container")
246
233
  Colors.line(`➜ Building the container image for the "${this.node.id}" function...`);
247
- const project = useProject();
248
234
  // Build function
249
235
  const result = await useRuntimeHandlers().build(this.node.addr, "deploy");
250
236
  if (result.type === "error") {
@@ -253,9 +239,32 @@ export class Function extends CDKFunction {
253
239
  ...result.errors,
254
240
  ].join("\n"));
255
241
  }
256
- // No need to update code if runtime is container
257
- if (props.runtime === "container")
242
+ // Update function code for container
243
+ const cfnFunction = this.node.defaultChild;
244
+ if (props.runtime === "container") {
245
+ const code = Code.fromAssetImage(props.handler, {
246
+ ...(architecture?.dockerPlatform
247
+ ? { platform: Platform.custom(architecture.dockerPlatform) }
248
+ : {}),
249
+ ...(props.container?.cmd ? { cmd: props.container.cmd } : {}),
250
+ ...(props.container?.file ? { file: props.container.file } : {}),
251
+ ...(props.container?.buildArgs
252
+ ? { buildArgs: props.container.buildArgs }
253
+ : {}),
254
+ exclude: [".sst/dist", ".sst/artifacts"],
255
+ ignoreMode: IgnoreMode.GLOB,
256
+ });
257
+ const codeConfig = code.bind(this);
258
+ cfnFunction.packageType = "Image";
259
+ cfnFunction.code = {
260
+ imageUri: codeConfig.image?.imageUri,
261
+ };
262
+ delete cfnFunction.runtime;
263
+ delete cfnFunction.handler;
264
+ code.bindToResource(cfnFunction);
258
265
  return;
266
+ }
267
+ // Update function code for non-container
259
268
  if (result.sourcemap) {
260
269
  const data = await fs.readFile(result.sourcemap);
261
270
  await fs.writeFile(result.sourcemap, zlib.gzipSync(data));
@@ -270,7 +279,6 @@ export class Function extends CDKFunction {
270
279
  }
271
280
  this.missingSourcemap = !result.sourcemap;
272
281
  // Update code
273
- const cfnFunction = this.node.defaultChild;
274
282
  const code = AssetCode.fromAsset(result.out);
275
283
  const codeConfig = code.bind(this);
276
284
  cfnFunction.code = {
@@ -78,7 +78,7 @@ export class NextjsSite extends SsrSite {
78
78
  });
79
79
  this.handleMissingSourcemap();
80
80
  if (this.isPerRouteLoggingEnabled()) {
81
- this.disableDefaultLogging();
81
+ //this.disableDefaultLogging();
82
82
  this.uploadSourcemaps();
83
83
  }
84
84
  if (!props.experimental.disableIncrementalCache) {
@@ -359,36 +359,56 @@ export class NextjsSite extends SsrSite {
359
359
  if (this._routes)
360
360
  return this._routes;
361
361
  const routesManifest = this.useRoutesManifest();
362
+ const appPathRoutesManifest = this.useAppPathRoutesManifest();
363
+ const dynamicAndStaticRoutes = [
364
+ ...routesManifest.dynamicRoutes,
365
+ ...routesManifest.staticRoutes,
366
+ ].map(({ page, regex }) => {
367
+ const cwRoute = NextjsSite.buildCloudWatchRouteName(page);
368
+ const cwHash = NextjsSite.buildCloudWatchRouteHash(page);
369
+ const sourcemapPath = this.getSourcemapForAppRoute(page) ||
370
+ this.getSourcemapForPagesRoute(page);
371
+ return {
372
+ route: page,
373
+ regexMatch: regex,
374
+ logGroupPath: `/${cwHash}${cwRoute}`,
375
+ sourcemapPath: sourcemapPath,
376
+ sourcemapKey: cwHash,
377
+ };
378
+ });
379
+ // Some app routes are not in the routes manifest, so we need to add them
380
+ // ie. app/api/route.ts => IS NOT in the routes manifest
381
+ // app/items/[slug]/route.ts => IS in the routes manifest (dynamicRoutes)
382
+ const appRoutes = Object.values(appPathRoutesManifest)
383
+ .filter((page) => routesManifest.dynamicRoutes.every((route) => route.page !== page) &&
384
+ routesManifest.staticRoutes.every((route) => route.page !== page))
385
+ .map((page) => {
386
+ const cwRoute = NextjsSite.buildCloudWatchRouteName(page);
387
+ const cwHash = NextjsSite.buildCloudWatchRouteHash(page);
388
+ const sourcemapPath = this.getSourcemapForAppRoute(page);
389
+ return {
390
+ route: page,
391
+ prefixMatch: page,
392
+ logGroupPath: `/${cwHash}${cwRoute}`,
393
+ sourcemapPath: sourcemapPath,
394
+ sourcemapKey: cwHash,
395
+ };
396
+ });
397
+ const dataRoutes = (routesManifest.dataRoutes || []).map(({ page, dataRouteRegex }) => {
398
+ const routeDisplayName = page.endsWith("/")
399
+ ? `/_next/data/BUILD_ID${page}index.json`
400
+ : `/_next/data/BUILD_ID${page}.json`;
401
+ const cwRoute = NextjsSite.buildCloudWatchRouteName(routeDisplayName);
402
+ const cwHash = NextjsSite.buildCloudWatchRouteHash(page);
403
+ return {
404
+ route: routeDisplayName,
405
+ regexMatch: dataRouteRegex,
406
+ logGroupPath: `/${cwHash}${cwRoute}`,
407
+ };
408
+ });
362
409
  this._routes = [
363
- ...[...routesManifest.dynamicRoutes, ...routesManifest.staticRoutes]
364
- .map(({ page, regex }) => {
365
- const cwRoute = NextjsSite.buildCloudWatchRouteName(page);
366
- const cwHash = NextjsSite.buildCloudWatchRouteHash(page);
367
- const sourcemapPath = this.getSourcemapForAppRoute(page) ||
368
- this.getSourcemapForPagesRoute(page);
369
- return {
370
- route: page,
371
- regex,
372
- logGroupPath: `/${cwHash}${cwRoute}`,
373
- sourcemapPath: sourcemapPath,
374
- sourcemapKey: cwHash,
375
- };
376
- })
377
- .sort((a, b) => a.route.localeCompare(b.route)),
378
- ...(routesManifest.dataRoutes || [])
379
- .map(({ page, dataRouteRegex }) => {
380
- const routeDisplayName = page.endsWith("/")
381
- ? `/_next/data/BUILD_ID${page}index.json`
382
- : `/_next/data/BUILD_ID${page}.json`;
383
- const cwRoute = NextjsSite.buildCloudWatchRouteName(routeDisplayName);
384
- const cwHash = NextjsSite.buildCloudWatchRouteHash(page);
385
- return {
386
- route: routeDisplayName,
387
- regex: dataRouteRegex,
388
- logGroupPath: `/${cwHash}${cwRoute}`,
389
- };
390
- })
391
- .sort((a, b) => a.route.localeCompare(b.route)),
410
+ ...[...dynamicAndStaticRoutes, ...appRoutes].sort((a, b) => a.route.localeCompare(b.route)),
411
+ ...dataRoutes.sort((a, b) => a.route.localeCompare(b.route)),
392
412
  ];
393
413
  return this._routes;
394
414
  }
@@ -410,6 +430,15 @@ export class NextjsSite extends SsrSite {
410
430
  }
411
431
  }
412
432
  useAppPathRoutesManifest() {
433
+ // Example
434
+ // {
435
+ // "/_not-found": "/_not-found",
436
+ // "/page": "/",
437
+ // "/favicon.ico/route": "/favicon.ico",
438
+ // "/api/route": "/api", <- app/api/route.js
439
+ // "/api/sub/route": "/api/sub", <- app/api/sub/route.js
440
+ // "/items/[slug]/route": "/items/[slug]" <- app/items/[slug]/route.js
441
+ // }
413
442
  if (this.appPathRoutesManifest)
414
443
  return this.appPathRoutesManifest;
415
444
  const { path: sitePath } = this.props;
@@ -472,10 +501,17 @@ export class NextjsSite extends SsrSite {
472
501
  useServerFunctionPerRouteLoggingInjection() {
473
502
  return `
474
503
  if (event.rawPath) {
475
- const routeData = ${JSON.stringify(this.useRoutes().map(({ regex, logGroupPath }) => ({
476
- regex,
504
+ const routeData = ${JSON.stringify(
505
+ // @ts-expect-error
506
+ this.useRoutes().map(({ regexMatch, prefixMatch, logGroupPath }) => ({
507
+ regex: regexMatch,
508
+ prefix: prefixMatch,
477
509
  logGroupPath,
478
- })))}.find(({ regex }) => event.rawPath.match(new RegExp(regex)));
510
+ })))}.find(({ regex, prefix }) => {
511
+ if (regex) return event.rawPath.match(new RegExp(regex));
512
+ if (prefix) return event.rawPath === prefix || (event.rawPath === prefix + "/");
513
+ return false;
514
+ });
479
515
  if (routeData) {
480
516
  console.log("::sst::" + JSON.stringify({
481
517
  action:"log.split",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "sideEffects": false,
3
3
  "name": "sst",
4
- "version": "2.39.10",
4
+ "version": "2.39.12",
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.39.10",
123
+ "astro-sst": "2.39.12",
124
124
  "async": "^3.2.4",
125
125
  "tsx": "^3.12.1",
126
126
  "typescript": "^5.2.2",