sst 2.24.6 → 2.24.7

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.
@@ -24,6 +24,8 @@ import { StringParameter } from "aws-cdk-lib/aws-ssm";
24
24
  import { Platform } from "aws-cdk-lib/aws-ecr-assets";
25
25
  import { useBootstrap } from "../bootstrap.js";
26
26
  import { Colors } from "../cli/colors.js";
27
+ import { BucketDeployment, Source } from "aws-cdk-lib/aws-s3-deployment";
28
+ import { Bucket } from "aws-cdk-lib/aws-s3";
27
29
  const __dirname = url.fileURLToPath(new URL(".", import.meta.url));
28
30
  const supportedRuntimes = {
29
31
  container: CDKRuntime.FROM_IMAGE,
@@ -244,6 +246,15 @@ export class Function extends CDKFunction {
244
246
  const cfnFunction = this.node.defaultChild;
245
247
  const code = AssetCode.fromAsset(result.out);
246
248
  const codeConfig = code.bind(this);
249
+ const bootstrap = await useBootstrap();
250
+ if (result.sourcemap)
251
+ new BucketDeployment(this, "Sourcemap", {
252
+ sources: [Source.asset(result.sourcemap)],
253
+ contentEncoding: "gzip",
254
+ contentType: "application/json",
255
+ destinationBucket: Bucket.fromBucketName(this, "BootstrapBucket", bootstrap.bucket),
256
+ destinationKeyPrefix: `sourcemap/${app.name}/${app.stage}/${this.functionArn}/`,
257
+ });
247
258
  cfnFunction.code = {
248
259
  s3Bucket: codeConfig.s3Location?.bucketName,
249
260
  s3Key: codeConfig.s3Location?.objectKey,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "sideEffects": false,
3
3
  "name": "sst",
4
- "version": "2.24.6",
4
+ "version": "2.24.7",
5
5
  "bin": {
6
6
  "sst": "cli/sst.js"
7
7
  },
@@ -158,7 +158,7 @@ export const useNodeHandler = Context.memo(async () => {
158
158
  : undefined,
159
159
  }),
160
160
  outfile: target,
161
- sourcemap: input.mode === "start" ? "linked" : nodejs.sourcemap,
161
+ sourcemap: input.mode === "start" ? "linked" : true,
162
162
  minify: nodejs.minify,
163
163
  ...override,
164
164
  };
@@ -223,6 +223,9 @@ export const useNodeHandler = Context.memo(async () => {
223
223
  return {
224
224
  type: "success",
225
225
  handler,
226
+ sourcemap: !nodejs.sourcemap
227
+ ? Object.keys(result.metafile?.outputs || {}).find((item) => item.endsWith(".map"))
228
+ : undefined,
226
229
  };
227
230
  }
228
231
  catch (ex) {
@@ -40,6 +40,7 @@ export interface RuntimeHandler {
40
40
  build: (input: BuildInput) => Promise<{
41
41
  type: "success";
42
42
  handler: string;
43
+ sourcemap?: string;
43
44
  } | {
44
45
  type: "error";
45
46
  errors: string[];
@@ -57,6 +58,7 @@ export declare const useRuntimeHandlers: () => {
57
58
  errors: string[];
58
59
  } | {
59
60
  out: string;
61
+ sourcemap: string | undefined;
60
62
  type: "success";
61
63
  handler: string;
62
64
  }>;
@@ -1,9 +1,11 @@
1
1
  import { Context } from "../context/context.js";
2
2
  import { Logger } from "../logger.js";
3
3
  import path from "path";
4
+ import zlib from "zlib";
4
5
  import fs from "fs/promises";
5
6
  import { useWatcher } from "../watcher.js";
6
7
  import { useBus } from "../bus.js";
8
+ import crypto from "crypto";
7
9
  import { useProject } from "../project.js";
8
10
  import { useFunctions } from "../constructs/Function.js";
9
11
  export const useRuntimeHandlers = Context.memo(() => {
@@ -75,10 +77,21 @@ export const useRuntimeHandlers = Context.memo(() => {
75
77
  }
76
78
  if (func.hooks?.afterBuild)
77
79
  await func.hooks.afterBuild(func, out);
80
+ let sourcemap;
81
+ if (built.sourcemap) {
82
+ const data = await fs.readFile(built.sourcemap);
83
+ const hash = crypto.createHash("md5").update(data).digest("hex");
84
+ const dir = path.join(project.paths.artifacts, "sourcemaps", functionID);
85
+ await fs.rm(dir, { recursive: true, force: true });
86
+ await fs.mkdir(dir, { recursive: true });
87
+ sourcemap = dir;
88
+ await fs.writeFile(path.join(dir, `${hash}.map`), zlib.gzipSync(data));
89
+ }
78
90
  bus.publish("function.build.success", { functionID });
79
91
  return {
80
92
  ...built,
81
93
  out,
94
+ sourcemap,
82
95
  };
83
96
  }
84
97
  if (pendingBuilds.has(functionID)) {