@codedrifters/constructs 0.0.72 → 0.0.73

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.
package/lib/index.d.mts CHANGED
@@ -1,10 +1,122 @@
1
- import { Bucket, BucketProps } from 'aws-cdk-lib/aws-s3';
1
+ import { NodejsFunction, NodejsFunctionProps } from 'aws-cdk-lib/aws-lambda-nodejs';
2
2
  import { Construct } from 'constructs';
3
+ import { Bucket, BucketProps } from 'aws-cdk-lib/aws-s3';
3
4
  import { StackProps } from 'aws-cdk-lib';
4
5
  import { HostedZoneAttributes } from 'aws-cdk-lib/aws-route53';
5
6
  import { HostingMode } from './static-hosting.viewer-request-handler.mjs';
6
7
  import 'aws-lambda';
7
8
 
9
+ /**
10
+ * Props for `PnpmWorkspaceNodejsFunction`. Extends
11
+ * `NodejsFunctionProps` so the wrapper is a drop-in for any existing
12
+ * `NodejsFunction` call site.
13
+ */
14
+ interface PnpmWorkspaceNodejsFunctionProps extends NodejsFunctionProps {
15
+ /**
16
+ * Directory to begin the upward search for `pnpm-workspace.yaml`.
17
+ * Defaults to the directory of the resolved entry path.
18
+ */
19
+ readonly workspaceSearchFrom?: string;
20
+ /**
21
+ * Skip the policy-mirror step entirely. Useful for tests or when the
22
+ * caller wants the pure `NodejsFunction` behavior.
23
+ *
24
+ * @default false
25
+ */
26
+ readonly disablePnpmPolicyMirror?: boolean;
27
+ }
28
+ /**
29
+ * Result of `mirrorPnpmWorkspacePolicy` — describes what the policy
30
+ * mirror did for one entry.
31
+ */
32
+ interface MirrorPnpmWorkspacePolicyResult {
33
+ /** Resolved `.npmrc` path if a write happened, otherwise undefined. */
34
+ readonly npmrcPath?: string;
35
+ /** Reason the mirror was a no-op, if it was. */
36
+ readonly skippedReason?: "missing-entry" | "missing-workspace-file" | "empty-policy" | "no-change";
37
+ }
38
+ /**
39
+ * Mirror the workspace pnpm policy into an `.npmrc` adjacent to the
40
+ * Lambda entry. Pure side-effect helper used by
41
+ * `PnpmWorkspaceNodejsFunction`; exported so consumers can drive it
42
+ * from other call sites if desired.
43
+ */
44
+ declare const mirrorPnpmWorkspacePolicy: (params: {
45
+ readonly entry: string;
46
+ readonly workspaceSearchFrom?: string;
47
+ }) => MirrorPnpmWorkspacePolicyResult;
48
+ /**
49
+ * A `NodejsFunction` wrapper that mirrors the workspace's pnpm policy
50
+ * (currently `minimumReleaseAge` and `minimumReleaseAgeExclude`) into
51
+ * an `.npmrc` adjacent to the Lambda entry before bundling.
52
+ *
53
+ * CDK's bundler runs `pnpm install` in an isolated temp directory
54
+ * outside the workspace, which means `pnpm-workspace.yaml` settings
55
+ * do not apply there. Mirroring the policy into an entry-adjacent
56
+ * `.npmrc` (which CDK copies into the bundling input directory)
57
+ * lets the inner `pnpm install` honour the same freshness rules.
58
+ *
59
+ * See the `pnpm-workspace-nodejs-function` documentation page for
60
+ * full details on what gets mirrored, merge behaviour against an
61
+ * existing `.npmrc`, and when to disable the mirror.
62
+ */
63
+ declare class PnpmWorkspaceNodejsFunction extends NodejsFunction {
64
+ constructor(scope: Construct, id: string, props: PnpmWorkspaceNodejsFunctionProps);
65
+ }
66
+
67
+ /**
68
+ * Subset of `pnpm-workspace.yaml` fields that map to `.npmrc` keys
69
+ * pnpm honours when running install in a non-workspace directory.
70
+ */
71
+ interface PnpmWorkspacePolicy {
72
+ /** `minimumReleaseAge` (minutes) — equivalent to `.npmrc` `minimum-release-age`. */
73
+ readonly minimumReleaseAge?: number;
74
+ /**
75
+ * `minimumReleaseAgeExclude` — equivalent to `.npmrc`
76
+ * `minimum-release-age-exclude` (comma-separated when serialised).
77
+ */
78
+ readonly minimumReleaseAgeExclude?: ReadonlyArray<string>;
79
+ }
80
+ /**
81
+ * Walk up from `startDir` until a `pnpm-workspace.yaml` file is found
82
+ * and return its absolute path. Returns `undefined` when the filesystem
83
+ * root is reached without finding one.
84
+ */
85
+ declare const findPnpmWorkspaceFile: (startDir: string) => string | undefined;
86
+ /**
87
+ * Read the policy subset (`minimumReleaseAge` and
88
+ * `minimumReleaseAgeExclude`) from a `pnpm-workspace.yaml` file.
89
+ *
90
+ * Returns an empty object when the file is missing, unreadable, or
91
+ * contains neither key. Throws when the file is present but YAML
92
+ * parsing fails — the caller is expected to surface a clear error.
93
+ */
94
+ declare const readPnpmWorkspacePolicy: (workspaceFile: string) => PnpmWorkspacePolicy;
95
+ /**
96
+ * Render an `.npmrc` body that pnpm will honour when installing in
97
+ * a directory outside the workspace tree. The keys emitted here are
98
+ * the `.npmrc` equivalents of the `pnpm-workspace.yaml` fields in
99
+ * {@link PnpmWorkspacePolicy} — pnpm reads `minimum-release-age` and
100
+ * `minimum-release-age-exclude` from `.npmrc`, not from the workspace
101
+ * file, when the install runs outside the workspace.
102
+ *
103
+ * Returns an empty string when the policy carries no relevant fields.
104
+ */
105
+ declare const renderNpmrcLines: (policy: PnpmWorkspacePolicy) => ReadonlyArray<string>;
106
+ /**
107
+ * Parse the body of an existing `.npmrc` file into a map of trimmed
108
+ * key/value pairs. Lines that are blank or start with `#` are dropped.
109
+ * Lines without an `=` are dropped.
110
+ */
111
+ declare const parseNpmrc: (body: string) => Map<string, string>;
112
+ /**
113
+ * Merge a set of policy-derived `.npmrc` lines into an existing
114
+ * `.npmrc` body. Our keys overwrite matching keys in the existing
115
+ * body; all other keys are preserved. Returns the new `.npmrc` body
116
+ * (always terminated by a trailing newline when non-empty).
117
+ */
118
+ declare const mergeNpmrc: (existing: string | undefined, ourLines: ReadonlyArray<string>) => string;
119
+
8
120
  interface PrivateBucketProps extends BucketProps {
9
121
  }
10
122
  declare class PrivateBucket extends Bucket {
@@ -123,4 +235,4 @@ declare class StaticHosting extends Construct {
123
235
  constructor(scope: Construct, id: string, props?: StaticHostingProps);
124
236
  }
125
237
 
126
- export { PrivateBucket, type PrivateBucketProps, StaticContent, type StaticContentProps, type StaticDomainProps, StaticHosting, type StaticHostingProps };
238
+ export { type MirrorPnpmWorkspacePolicyResult, PnpmWorkspaceNodejsFunction, type PnpmWorkspaceNodejsFunctionProps, type PnpmWorkspacePolicy, PrivateBucket, type PrivateBucketProps, StaticContent, type StaticContentProps, type StaticDomainProps, StaticHosting, type StaticHostingProps, findPnpmWorkspaceFile, mergeNpmrc, mirrorPnpmWorkspacePolicy, parseNpmrc, readPnpmWorkspacePolicy, renderNpmrcLines };
package/lib/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- import { Bucket, BucketProps } from 'aws-cdk-lib/aws-s3';
1
+ import { NodejsFunction, NodejsFunctionProps } from 'aws-cdk-lib/aws-lambda-nodejs';
2
2
  import { Construct } from 'constructs';
3
+ import { Bucket, BucketProps } from 'aws-cdk-lib/aws-s3';
3
4
  import { StackProps } from 'aws-cdk-lib';
4
5
  import { HostedZoneAttributes } from 'aws-cdk-lib/aws-route53';
5
6
 
@@ -15,6 +16,117 @@ import { HostedZoneAttributes } from 'aws-cdk-lib/aws-route53';
15
16
  */
16
17
  type HostingMode = "spa" | "static";
17
18
 
19
+ /**
20
+ * Props for `PnpmWorkspaceNodejsFunction`. Extends
21
+ * `NodejsFunctionProps` so the wrapper is a drop-in for any existing
22
+ * `NodejsFunction` call site.
23
+ */
24
+ interface PnpmWorkspaceNodejsFunctionProps extends NodejsFunctionProps {
25
+ /**
26
+ * Directory to begin the upward search for `pnpm-workspace.yaml`.
27
+ * Defaults to the directory of the resolved entry path.
28
+ */
29
+ readonly workspaceSearchFrom?: string;
30
+ /**
31
+ * Skip the policy-mirror step entirely. Useful for tests or when the
32
+ * caller wants the pure `NodejsFunction` behavior.
33
+ *
34
+ * @default false
35
+ */
36
+ readonly disablePnpmPolicyMirror?: boolean;
37
+ }
38
+ /**
39
+ * Result of `mirrorPnpmWorkspacePolicy` — describes what the policy
40
+ * mirror did for one entry.
41
+ */
42
+ interface MirrorPnpmWorkspacePolicyResult {
43
+ /** Resolved `.npmrc` path if a write happened, otherwise undefined. */
44
+ readonly npmrcPath?: string;
45
+ /** Reason the mirror was a no-op, if it was. */
46
+ readonly skippedReason?: "missing-entry" | "missing-workspace-file" | "empty-policy" | "no-change";
47
+ }
48
+ /**
49
+ * Mirror the workspace pnpm policy into an `.npmrc` adjacent to the
50
+ * Lambda entry. Pure side-effect helper used by
51
+ * `PnpmWorkspaceNodejsFunction`; exported so consumers can drive it
52
+ * from other call sites if desired.
53
+ */
54
+ declare const mirrorPnpmWorkspacePolicy: (params: {
55
+ readonly entry: string;
56
+ readonly workspaceSearchFrom?: string;
57
+ }) => MirrorPnpmWorkspacePolicyResult;
58
+ /**
59
+ * A `NodejsFunction` wrapper that mirrors the workspace's pnpm policy
60
+ * (currently `minimumReleaseAge` and `minimumReleaseAgeExclude`) into
61
+ * an `.npmrc` adjacent to the Lambda entry before bundling.
62
+ *
63
+ * CDK's bundler runs `pnpm install` in an isolated temp directory
64
+ * outside the workspace, which means `pnpm-workspace.yaml` settings
65
+ * do not apply there. Mirroring the policy into an entry-adjacent
66
+ * `.npmrc` (which CDK copies into the bundling input directory)
67
+ * lets the inner `pnpm install` honour the same freshness rules.
68
+ *
69
+ * See the `pnpm-workspace-nodejs-function` documentation page for
70
+ * full details on what gets mirrored, merge behaviour against an
71
+ * existing `.npmrc`, and when to disable the mirror.
72
+ */
73
+ declare class PnpmWorkspaceNodejsFunction extends NodejsFunction {
74
+ constructor(scope: Construct, id: string, props: PnpmWorkspaceNodejsFunctionProps);
75
+ }
76
+
77
+ /**
78
+ * Subset of `pnpm-workspace.yaml` fields that map to `.npmrc` keys
79
+ * pnpm honours when running install in a non-workspace directory.
80
+ */
81
+ interface PnpmWorkspacePolicy {
82
+ /** `minimumReleaseAge` (minutes) — equivalent to `.npmrc` `minimum-release-age`. */
83
+ readonly minimumReleaseAge?: number;
84
+ /**
85
+ * `minimumReleaseAgeExclude` — equivalent to `.npmrc`
86
+ * `minimum-release-age-exclude` (comma-separated when serialised).
87
+ */
88
+ readonly minimumReleaseAgeExclude?: ReadonlyArray<string>;
89
+ }
90
+ /**
91
+ * Walk up from `startDir` until a `pnpm-workspace.yaml` file is found
92
+ * and return its absolute path. Returns `undefined` when the filesystem
93
+ * root is reached without finding one.
94
+ */
95
+ declare const findPnpmWorkspaceFile: (startDir: string) => string | undefined;
96
+ /**
97
+ * Read the policy subset (`minimumReleaseAge` and
98
+ * `minimumReleaseAgeExclude`) from a `pnpm-workspace.yaml` file.
99
+ *
100
+ * Returns an empty object when the file is missing, unreadable, or
101
+ * contains neither key. Throws when the file is present but YAML
102
+ * parsing fails — the caller is expected to surface a clear error.
103
+ */
104
+ declare const readPnpmWorkspacePolicy: (workspaceFile: string) => PnpmWorkspacePolicy;
105
+ /**
106
+ * Render an `.npmrc` body that pnpm will honour when installing in
107
+ * a directory outside the workspace tree. The keys emitted here are
108
+ * the `.npmrc` equivalents of the `pnpm-workspace.yaml` fields in
109
+ * {@link PnpmWorkspacePolicy} — pnpm reads `minimum-release-age` and
110
+ * `minimum-release-age-exclude` from `.npmrc`, not from the workspace
111
+ * file, when the install runs outside the workspace.
112
+ *
113
+ * Returns an empty string when the policy carries no relevant fields.
114
+ */
115
+ declare const renderNpmrcLines: (policy: PnpmWorkspacePolicy) => ReadonlyArray<string>;
116
+ /**
117
+ * Parse the body of an existing `.npmrc` file into a map of trimmed
118
+ * key/value pairs. Lines that are blank or start with `#` are dropped.
119
+ * Lines without an `=` are dropped.
120
+ */
121
+ declare const parseNpmrc: (body: string) => Map<string, string>;
122
+ /**
123
+ * Merge a set of policy-derived `.npmrc` lines into an existing
124
+ * `.npmrc` body. Our keys overwrite matching keys in the existing
125
+ * body; all other keys are preserved. Returns the new `.npmrc` body
126
+ * (always terminated by a trailing newline when non-empty).
127
+ */
128
+ declare const mergeNpmrc: (existing: string | undefined, ourLines: ReadonlyArray<string>) => string;
129
+
18
130
  interface PrivateBucketProps extends BucketProps {
19
131
  }
20
132
  declare class PrivateBucket extends Bucket {
@@ -133,5 +245,5 @@ declare class StaticHosting extends Construct {
133
245
  constructor(scope: Construct, id: string, props?: StaticHostingProps);
134
246
  }
135
247
 
136
- export { PrivateBucket, StaticContent, StaticHosting };
137
- export type { PrivateBucketProps, StaticContentProps, StaticDomainProps, StaticHostingProps };
248
+ export { PnpmWorkspaceNodejsFunction, PrivateBucket, StaticContent, StaticHosting, findPnpmWorkspaceFile, mergeNpmrc, mirrorPnpmWorkspacePolicy, parseNpmrc, readPnpmWorkspacePolicy, renderNpmrcLines };
249
+ export type { MirrorPnpmWorkspacePolicyResult, PnpmWorkspaceNodejsFunctionProps, PnpmWorkspacePolicy, PrivateBucketProps, StaticContentProps, StaticDomainProps, StaticHostingProps };
package/lib/index.js CHANGED
@@ -175,12 +175,183 @@ var require_lib = __commonJS({
175
175
  // src/index.ts
176
176
  var src_exports = {};
177
177
  __export(src_exports, {
178
+ PnpmWorkspaceNodejsFunction: () => PnpmWorkspaceNodejsFunction,
178
179
  PrivateBucket: () => PrivateBucket,
179
180
  StaticContent: () => StaticContent,
180
- StaticHosting: () => StaticHosting
181
+ StaticHosting: () => StaticHosting,
182
+ findPnpmWorkspaceFile: () => findPnpmWorkspaceFile,
183
+ mergeNpmrc: () => mergeNpmrc,
184
+ mirrorPnpmWorkspacePolicy: () => mirrorPnpmWorkspacePolicy,
185
+ parseNpmrc: () => parseNpmrc,
186
+ readPnpmWorkspacePolicy: () => readPnpmWorkspacePolicy,
187
+ renderNpmrcLines: () => renderNpmrcLines
181
188
  });
182
189
  module.exports = __toCommonJS(src_exports);
183
190
 
191
+ // src/lambda/pnpm-workspace-nodejs-function.ts
192
+ var fs2 = __toESM(require("fs"));
193
+ var path2 = __toESM(require("path"));
194
+ var import_aws_lambda_nodejs = require("aws-cdk-lib/aws-lambda-nodejs");
195
+
196
+ // src/lambda/pnpm-workspace-parser.ts
197
+ var fs = __toESM(require("fs"));
198
+ var path = __toESM(require("path"));
199
+ var yaml = __toESM(require("js-yaml"));
200
+ var findPnpmWorkspaceFile = (startDir) => {
201
+ let current = path.resolve(startDir);
202
+ while (true) {
203
+ const candidate = path.join(current, "pnpm-workspace.yaml");
204
+ if (fs.existsSync(candidate)) {
205
+ return candidate;
206
+ }
207
+ const parent = path.dirname(current);
208
+ if (parent === current) {
209
+ return void 0;
210
+ }
211
+ current = parent;
212
+ }
213
+ };
214
+ var readPnpmWorkspacePolicy = (workspaceFile) => {
215
+ if (!fs.existsSync(workspaceFile)) {
216
+ return {};
217
+ }
218
+ const raw = fs.readFileSync(workspaceFile, "utf8");
219
+ const parsed = yaml.load(raw);
220
+ if (!parsed || typeof parsed !== "object") {
221
+ return {};
222
+ }
223
+ const obj = parsed;
224
+ const policy = {};
225
+ const age = obj.minimumReleaseAge;
226
+ if (typeof age === "number" && Number.isFinite(age)) {
227
+ policy.minimumReleaseAge = age;
228
+ }
229
+ const exclude = obj.minimumReleaseAgeExclude;
230
+ if (Array.isArray(exclude)) {
231
+ const cleaned = exclude.filter(
232
+ (entry) => typeof entry === "string" && entry.length > 0
233
+ );
234
+ if (cleaned.length > 0) {
235
+ policy.minimumReleaseAgeExclude = cleaned;
236
+ }
237
+ }
238
+ return policy;
239
+ };
240
+ var renderNpmrcLines = (policy) => {
241
+ const lines = [];
242
+ if (typeof policy.minimumReleaseAge === "number") {
243
+ lines.push(`minimum-release-age=${policy.minimumReleaseAge}`);
244
+ }
245
+ const exclude = policy.minimumReleaseAgeExclude ?? [];
246
+ if (exclude.length > 0) {
247
+ lines.push(`minimum-release-age-exclude=${exclude.join(",")}`);
248
+ }
249
+ return lines;
250
+ };
251
+ var parseNpmrc = (body) => {
252
+ const map = /* @__PURE__ */ new Map();
253
+ for (const rawLine of body.split(/\r?\n/)) {
254
+ const line = rawLine.trim();
255
+ if (line.length === 0 || line.startsWith("#")) {
256
+ continue;
257
+ }
258
+ const eq = line.indexOf("=");
259
+ if (eq < 0) {
260
+ continue;
261
+ }
262
+ const key = line.slice(0, eq).trim();
263
+ const value = line.slice(eq + 1).trim();
264
+ if (key.length > 0) {
265
+ map.set(key, value);
266
+ }
267
+ }
268
+ return map;
269
+ };
270
+ var mergeNpmrc = (existing, ourLines) => {
271
+ if (ourLines.length === 0) {
272
+ return existing ?? "";
273
+ }
274
+ const ourMap = /* @__PURE__ */ new Map();
275
+ for (const line of ourLines) {
276
+ const eq = line.indexOf("=");
277
+ if (eq < 0) {
278
+ continue;
279
+ }
280
+ ourMap.set(line.slice(0, eq).trim(), line.slice(eq + 1).trim());
281
+ }
282
+ const existingMap = parseNpmrc(existing ?? "");
283
+ for (const [key, value] of ourMap) {
284
+ existingMap.set(key, value);
285
+ }
286
+ const orderedKeys = [];
287
+ const seen = /* @__PURE__ */ new Set();
288
+ for (const rawLine of (existing ?? "").split(/\r?\n/)) {
289
+ const line = rawLine.trim();
290
+ if (line.length === 0 || line.startsWith("#")) {
291
+ continue;
292
+ }
293
+ const eq = line.indexOf("=");
294
+ if (eq < 0) {
295
+ continue;
296
+ }
297
+ const key = line.slice(0, eq).trim();
298
+ if (key.length > 0 && existingMap.has(key) && !seen.has(key)) {
299
+ orderedKeys.push(key);
300
+ seen.add(key);
301
+ }
302
+ }
303
+ for (const key of ourMap.keys()) {
304
+ if (!seen.has(key)) {
305
+ orderedKeys.push(key);
306
+ seen.add(key);
307
+ }
308
+ }
309
+ const body = orderedKeys.map((key) => `${key}=${existingMap.get(key)}`).join("\n");
310
+ return body.length === 0 ? "" : `${body}
311
+ `;
312
+ };
313
+
314
+ // src/lambda/pnpm-workspace-nodejs-function.ts
315
+ var mirrorPnpmWorkspacePolicy = (params) => {
316
+ const { entry, workspaceSearchFrom } = params;
317
+ if (!fs2.existsSync(entry)) {
318
+ return { skippedReason: "missing-entry" };
319
+ }
320
+ const entryDir = path2.dirname(path2.resolve(entry));
321
+ const searchFrom = workspaceSearchFrom ? path2.resolve(workspaceSearchFrom) : entryDir;
322
+ const workspaceFile = findPnpmWorkspaceFile(searchFrom);
323
+ if (!workspaceFile) {
324
+ return { skippedReason: "missing-workspace-file" };
325
+ }
326
+ const policy = readPnpmWorkspacePolicy(workspaceFile);
327
+ const lines = renderNpmrcLines(policy);
328
+ if (lines.length === 0) {
329
+ return { skippedReason: "empty-policy" };
330
+ }
331
+ const npmrcPath = path2.join(entryDir, ".npmrc");
332
+ const existing = fs2.existsSync(npmrcPath) ? fs2.readFileSync(npmrcPath, "utf8") : void 0;
333
+ const merged = mergeNpmrc(existing, lines);
334
+ if (merged === existing) {
335
+ return { npmrcPath, skippedReason: "no-change" };
336
+ }
337
+ fs2.writeFileSync(npmrcPath, merged);
338
+ return { npmrcPath };
339
+ };
340
+ var PnpmWorkspaceNodejsFunction = class extends import_aws_lambda_nodejs.NodejsFunction {
341
+ constructor(scope, id, props) {
342
+ if (!props.disablePnpmPolicyMirror && props.entry) {
343
+ mirrorPnpmWorkspacePolicy({
344
+ entry: props.entry,
345
+ workspaceSearchFrom: props.workspaceSearchFrom
346
+ });
347
+ }
348
+ const { disablePnpmPolicyMirror, workspaceSearchFrom, ...rest } = props;
349
+ void disablePnpmPolicyMirror;
350
+ void workspaceSearchFrom;
351
+ super(scope, id, rest);
352
+ }
353
+ };
354
+
184
355
  // src/s3/private-bucket.ts
185
356
  var import_aws_cdk_lib = require("aws-cdk-lib");
186
357
  var import_aws_s3 = require("aws-cdk-lib/aws-s3");
@@ -239,14 +410,14 @@ var StaticContent = class extends import_constructs.Construct {
239
410
  };
240
411
 
241
412
  // src/static-hosting/static-hosting.ts
242
- var fs = __toESM(require("fs"));
243
- var path = __toESM(require("path"));
413
+ var fs3 = __toESM(require("fs"));
414
+ var path3 = __toESM(require("path"));
244
415
  var import_aws_cdk_lib2 = require("aws-cdk-lib");
245
416
  var import_aws_certificatemanager = require("aws-cdk-lib/aws-certificatemanager");
246
417
  var import_aws_cloudfront = require("aws-cdk-lib/aws-cloudfront");
247
418
  var import_aws_cloudfront_origins = require("aws-cdk-lib/aws-cloudfront-origins");
248
419
  var import_aws_lambda = require("aws-cdk-lib/aws-lambda");
249
- var import_aws_lambda_nodejs = require("aws-cdk-lib/aws-lambda-nodejs");
420
+ var import_aws_lambda_nodejs2 = require("aws-cdk-lib/aws-lambda-nodejs");
250
421
  var import_aws_logs = require("aws-cdk-lib/aws-logs");
251
422
  var import_aws_route53 = require("aws-cdk-lib/aws-route53");
252
423
  var import_aws_route53_targets = require("aws-cdk-lib/aws-route53-targets");
@@ -292,16 +463,16 @@ var StaticHosting = class extends import_constructs2.Construct {
292
463
  })
293
464
  });
294
465
  }
295
- const handlerJs = path.join(
466
+ const handlerJs = path3.join(
296
467
  __dirname,
297
468
  "static-hosting.viewer-request-handler.js"
298
469
  );
299
- const handlerTs = path.join(
470
+ const handlerTs = path3.join(
300
471
  __dirname,
301
472
  "static-hosting.viewer-request-handler.ts"
302
473
  );
303
- const handlerEntry = fs.existsSync(handlerJs) ? handlerJs : handlerTs;
304
- const handler = new import_aws_lambda_nodejs.NodejsFunction(this, "viewer-request-handler", {
474
+ const handlerEntry = fs3.existsSync(handlerJs) ? handlerJs : handlerTs;
475
+ const handler = new import_aws_lambda_nodejs2.NodejsFunction(this, "viewer-request-handler", {
305
476
  entry: handlerEntry,
306
477
  handler: hostingMode === "static" ? "staticHandler" : "spaHandler",
307
478
  memorySize: 128,
@@ -383,8 +554,15 @@ var StaticHosting = class extends import_constructs2.Construct {
383
554
  };
384
555
  // Annotate the CommonJS export names for ESM import in node:
385
556
  0 && (module.exports = {
557
+ PnpmWorkspaceNodejsFunction,
386
558
  PrivateBucket,
387
559
  StaticContent,
388
- StaticHosting
560
+ StaticHosting,
561
+ findPnpmWorkspaceFile,
562
+ mergeNpmrc,
563
+ mirrorPnpmWorkspacePolicy,
564
+ parseNpmrc,
565
+ readPnpmWorkspacePolicy,
566
+ renderNpmrcLines
389
567
  });
390
568
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../../utils/src/aws/aws-types.ts","../../utils/src/git/git-utils.ts","../../utils/src/string/string-utils.ts","../../utils/src/index.ts","../src/index.ts","../src/s3/private-bucket.ts","../src/static-hosting/static-content.ts","../src/static-hosting/static-hosting.ts"],"sourcesContent":["/**\n * Stage Types\n *\n * What stage of deployment is this? Dev, staging, or prod?\n */\nexport const AWS_STAGE_TYPE = {\n /**\n * Development environment, typically used for testing and development.\n */\n DEV: \"dev\",\n\n /**\n * Staging environment, used for pre-production testing.\n */\n STAGE: \"stage\",\n\n /**\n * Production environment, used for live deployments.\n */\n PROD: \"prod\",\n} as const;\n\n/**\n * Above const as a type.\n */\nexport type AwsStageType = (typeof AWS_STAGE_TYPE)[keyof typeof AWS_STAGE_TYPE];\n\n/**\n * Deployment target role: whether an (account, region) is the primary or\n * secondary deployment target (e.g. primary vs replica region).\n */\nexport const DEPLOYMENT_TARGET_ROLE = {\n /**\n * Account and region that represents the primary region for this service.\n * For example, the base DynamoDB Region for global tables.\n */\n PRIMARY: \"primary\",\n /**\n * Account and region that represents a secondary region for this service.\n * For example, a replica region for a global DynamoDB table.\n */\n SECONDARY: \"secondary\",\n} as const;\n\n/**\n * Type for deployment target role values.\n */\nexport type DeploymentTargetRoleType =\n (typeof DEPLOYMENT_TARGET_ROLE)[keyof typeof DEPLOYMENT_TARGET_ROLE];\n\n/**\n * Environment types (primary/secondary).\n *\n * @deprecated Use {@link DEPLOYMENT_TARGET_ROLE} instead. This constant is maintained for backward compatibility.\n */\nexport const AWS_ENVIRONMENT_TYPE = DEPLOYMENT_TARGET_ROLE;\n\n/**\n * Type for environment type values.\n *\n * @deprecated Use {@link DeploymentTargetRoleType} instead. This type is maintained for backward compatibility.\n */\nexport type AwsEnvironmentType = DeploymentTargetRoleType;\n","import { execSync } from \"node:child_process\";\n\n/**\n * Returns the current full git branch name\n *\n * ie: feature/1234 returns feature/1234\n *\n */\nexport const findGitBranch = (): string => {\n return execSync(\"git rev-parse --abbrev-ref HEAD\")\n .toString(\"utf8\")\n .replace(/[\\n\\r\\s]+$/, \"\");\n};\n\nexport const findGitRepoName = (): string => {\n /**\n * When running in github actions this will be populated.\n */\n if (process.env.GITHUB_REPOSITORY) {\n return process.env.GITHUB_REPOSITORY;\n }\n\n /**\n * locally, we need to extract the repo name from the git config.\n */\n const remote = execSync(\"git config --get remote.origin.url\")\n .toString(\"utf8\")\n .replace(/[\\n\\r\\s]+$/, \"\")\n .trim();\n\n const match = remote.match(/[:\\/]([^/]+\\/[^/]+?)(?:\\.git)?$/);\n const repoName = match ? match[1] : \"error-repo-name\";\n\n return repoName;\n};\n","import * as crypto from \"node:crypto\";\n\n/**\n *\n * @param inString - string to hash\n * @param trimLength - trim to this length (defaults to 999 chars)\n * @returns Hex-encoded sha256 digest, truncated to `trimLength` characters.\n */\nexport const hashString = (inString: string, trimLength: number = 999) => {\n return crypto\n .createHash(\"sha256\")\n .update(inString)\n .digest(\"hex\")\n .substring(0, trimLength);\n};\n\n/**\n *\n * @param inputString - string to truncate\n * @param maxLength - max length of this string\n * @returns trimmed string\n */\nexport const trimStringLength = (inputString: string, maxLength: number) => {\n return inputString.length < maxLength\n ? inputString\n : inputString.substring(0, maxLength);\n};\n","export * from \"./aws/aws-types\";\nexport * from \"./git/git-utils\";\nexport * from \"./string/string-utils\";\n","export * from \"./s3\";\nexport * from \"./static-hosting\";\n","import { RemovalPolicy } from \"aws-cdk-lib\";\nimport {\n BlockPublicAccess,\n Bucket,\n BucketProps,\n ObjectOwnership,\n} from \"aws-cdk-lib/aws-s3\";\nimport { Construct } from \"constructs\";\n\nexport interface PrivateBucketProps extends BucketProps {}\n\nexport class PrivateBucket extends Bucket {\n constructor(scope: Construct, id: string, props: PrivateBucketProps = {}) {\n const defaultProps = {\n removalPolicy: props.removalPolicy ?? RemovalPolicy.RETAIN,\n autoDeleteObjects: props.removalPolicy === RemovalPolicy.DESTROY,\n };\n\n const requiredProps = {\n publicReadAccess: false,\n blockPublicAccess: BlockPublicAccess.BLOCK_ALL,\n enforceSSL: true,\n objectOwnership: ObjectOwnership.BUCKET_OWNER_ENFORCED,\n };\n\n super(scope, id, { ...defaultProps, ...props, ...requiredProps });\n }\n}\n","// eslint-disable-next-line import/no-extraneous-dependencies\nimport { findGitBranch } from \"@codedrifters/utils\";\nimport { Bucket } from \"aws-cdk-lib/aws-s3\";\nimport { BucketDeployment, Source } from \"aws-cdk-lib/aws-s3-deployment\";\nimport { StringParameter } from \"aws-cdk-lib/aws-ssm\";\nimport { paramCase } from \"change-case\";\nimport { Construct } from \"constructs\";\n\n/*******************************************************************************\n *\n * STATIC CONTENT UPLOADER\n *\n * This construct uploads a directory of content from a local location into S3.\n *\n * To support PR and branch specific builds, each S3 bucket can store content\n * for multiple domains and builds, using the following format:\n *\n * S3-bucket/domain/*\n *\n * A bucket used to store content for stage.openhi.org might have the\n * following directory structure (all in the same bucket).\n *\n * `/stage.openhi.org/*` serves content to stage.openhi.org\n * `/feature-7.stage.openhi.org/*` serves content to feature-7.stage.openhi.org\n * `/pr-123.stage.openhi.org/*` serves content to pr-123.stage.openhi.org\n *\n ******************************************************************************/\n\nexport interface StaticContentProps {\n /**\n * Parameter name to use when storing the static hosting bucket's ARN.\n * This is needed in other later steps when deploying hosted content to S3.\n */\n readonly bucketArnParamName?: string;\n\n /**\n * Absolute path to directory containing content for the website.\n */\n readonly contentSourceDirectory: string;\n\n /**\n * Directory to place content into. Should start with a slash.\n * Example: '/widget'\n */\n readonly contentDestinationDirectory: string;\n\n /**\n * The sub domain prefix (ie: images)\n *\n * @default git branch name\n */\n readonly subDomain?: string;\n\n /**\n * The full domain (ie: staging.codedrifters.com)\n */\n readonly fullDomain: string;\n}\n\nexport class StaticContent extends Construct {\n constructor(scope: Construct, id: string, props: StaticContentProps) {\n super(scope, id);\n\n /***************************************************************************\n *\n * Initial Setup\n *\n * Set some defaults, build domain information.\n *\n **************************************************************************/\n\n const {\n bucketArnParamName,\n contentSourceDirectory,\n contentDestinationDirectory,\n subDomain,\n fullDomain,\n } = {\n bucketArnParamName: \"/STATIC_WEBSITE/BUCKET_ARN\",\n subDomain: findGitBranch(),\n ...props,\n };\n\n /***************************************************************************\n *\n * Import and build some values from Param Store during deployment.\n *\n **************************************************************************/\n\n const keyPrefix = [paramCase(subDomain), fullDomain].join(\".\");\n\n const bucketArn = StringParameter.valueForStringParameter(\n this,\n bucketArnParamName,\n );\n const bucket = Bucket.fromBucketArn(this, \"bucket\", bucketArn);\n\n /***************************************************************************\n *\n * Gather the sources we'll be deploying. We need to have an empty source\n * for tests since it will change all the time and bork up the test\n * snapshots if we don't.\n *\n **************************************************************************/\n\n const isTestEnv = process.env.VITEST === \"true\";\n const sources = isTestEnv ? [] : [Source.asset(contentSourceDirectory)];\n\n new BucketDeployment(this, \"deploy\", {\n sources,\n destinationBucket: bucket,\n retainOnDelete: false,\n destinationKeyPrefix: `${keyPrefix}${contentDestinationDirectory}`,\n });\n }\n}\n","import * as fs from \"fs\";\nimport * as path from \"path\";\nimport { Duration, StackProps } from \"aws-cdk-lib\";\nimport {\n Certificate,\n CertificateValidation,\n} from \"aws-cdk-lib/aws-certificatemanager\";\nimport {\n AccessLevel,\n AllowedMethods,\n CacheCookieBehavior,\n CacheHeaderBehavior,\n CachePolicy,\n CacheQueryStringBehavior,\n Distribution,\n LambdaEdgeEventType,\n S3OriginAccessControl,\n Signing,\n ViewerProtocolPolicy,\n} from \"aws-cdk-lib/aws-cloudfront\";\nimport { S3BucketOrigin } from \"aws-cdk-lib/aws-cloudfront-origins\";\nimport { Runtime } from \"aws-cdk-lib/aws-lambda\";\nimport { NodejsFunction } from \"aws-cdk-lib/aws-lambda-nodejs\";\nimport { LogGroup, RetentionDays } from \"aws-cdk-lib/aws-logs\";\nimport {\n ARecord,\n HostedZone,\n HostedZoneAttributes,\n IHostedZone,\n RecordTarget,\n} from \"aws-cdk-lib/aws-route53\";\nimport { CloudFrontTarget } from \"aws-cdk-lib/aws-route53-targets\";\nimport { StringParameter } from \"aws-cdk-lib/aws-ssm\";\nimport { Construct } from \"constructs\";\nimport type { HostingMode } from \"./static-hosting.viewer-request-handler\";\nimport { PrivateBucket, PrivateBucketProps } from \"../s3/private-bucket\";\n\nexport interface StaticDomainProps {\n /**\n * The base domain (ie: codedrifters.com)\n */\n readonly baseDomain: string;\n\n /**\n * Hosted zone ID for the base domain.\n */\n readonly hostedZoneAttributes: HostedZoneAttributes;\n}\n\nexport interface StaticHostingProps extends StackProps {\n /**\n * Short description used in various places for traceability.\n */\n readonly description?: string;\n\n /**\n * Values used to connect a domain name to the cloudfront distribution. If not\n * supplied, cloudfront doesn't use a custom domain.\n */\n readonly staticDomainProps?: StaticDomainProps;\n\n /**\n * Parameter name to use when storing the static hosting bucket's ARN.\n * This is needed in other later steps when deploying hosted content to S3.\n */\n readonly bucketArnParamName?: string;\n\n /**\n * Parameter name to use when storing the CloudFront Distribution Domain Name.\n */\n readonly distributionDomainParamName?: string;\n\n /**\n * Parameter name to use when storing the CloudFront Distribution ID.\n */\n readonly distributionIDParamName?: string;\n\n /**\n * Props to pass to the private S3 bucket.\n */\n readonly privateBucketProps?: PrivateBucketProps;\n\n /**\n * Selects how path-like URIs are rewritten by the viewer-request\n * `Lambda@Edge` handler.\n *\n * - `spa` (default): path-like URIs rewrite to `/index.html` so a\n * single-page app can serve its one root index and let the client-side\n * router handle the path.\n * - `static`: path-like URIs append `/index.html` (e.g. `/docs` →\n * `/docs/index.html`) so multi-page static sites can serve distinct\n * HTML per path.\n *\n * Multi-tenant domain-folder prepending runs after the rewrite in both\n * modes and is unaffected by this prop.\n *\n * @default \"spa\"\n */\n readonly hostingMode?: HostingMode;\n}\n\nexport class StaticHosting extends Construct {\n /**\n * Full domain name used as basis for hosting.\n */\n public readonly fullDomain: string;\n\n constructor(scope: Construct, id: string, props: StaticHostingProps = {}) {\n super(scope, id);\n\n /***************************************************************************\n *\n * Initial Setup\n *\n * Set some defaults, build domain information.\n *\n **************************************************************************/\n\n const {\n bucketArnParamName,\n distributionDomainParamName,\n distributionIDParamName,\n staticDomainProps,\n privateBucketProps,\n hostingMode,\n } = {\n bucketArnParamName: \"/STATIC_WEBSITE/BUCKET_ARN\",\n distributionDomainParamName: \"/STATIC_WEBSITE/DISTRIBUTION_DOMAIN\",\n distributionIDParamName: \"/STATIC_WEBSITE/DISTRIBUTION_ID\",\n hostingMode: \"spa\" as HostingMode,\n ...props,\n };\n\n const { baseDomain, hostedZoneAttributes } = staticDomainProps ?? {};\n\n /***************************************************************************\n *\n * PRIVATE BUCKET\n *\n * A bucket to store the files within.\n * Save ARN for later deploys.\n *\n **************************************************************************/\n\n const bucket = new PrivateBucket(\n this,\n \"static-hosting-bucket\",\n privateBucketProps,\n );\n\n /***************************************************************************\n *\n * DNS & Wildcard Certificate\n *\n * If a zone Id as passed in, find the hosted zone and create a wildcard\n * certificate for the domain.\n *\n **************************************************************************/\n\n let zone: IHostedZone | undefined;\n let certificate: Certificate | undefined;\n\n if (hostedZoneAttributes && baseDomain) {\n zone = HostedZone.fromHostedZoneAttributes(\n this,\n \"zone\",\n hostedZoneAttributes,\n );\n certificate = new Certificate(this, \"wildcard-certificate\", {\n domainName: `*.${baseDomain}`,\n subjectAlternativeNames: [baseDomain],\n validation: CertificateValidation.fromDnsMultiZone({\n [`*.${baseDomain}`]: zone,\n [baseDomain]: zone,\n }),\n });\n }\n\n /******************************************************************************\n *\n * `LAMBDA@EDGE` FUNCTION\n *\n * This handles rewriting the path from domain name.\n *\n *****************************************************************************/\n\n // Explicit entry required: when omitted, NodejsFunction infers the path from the\n // call site (the built lib/index.js), so it looks for index.viewer-request-handler.js\n // in the package. That file is only emitted if we add it as a separate tsup entry.\n // Use .js when present (built package); fall back to .ts for tests running from source.\n const handlerJs = path.join(\n __dirname,\n \"static-hosting.viewer-request-handler.js\",\n );\n const handlerTs = path.join(\n __dirname,\n \"static-hosting.viewer-request-handler.ts\",\n );\n const handlerEntry = fs.existsSync(handlerJs) ? handlerJs : handlerTs;\n\n const handler = new NodejsFunction(this, \"viewer-request-handler\", {\n entry: handlerEntry,\n handler: hostingMode === \"static\" ? \"staticHandler\" : \"spaHandler\",\n memorySize: 128,\n runtime: Runtime.NODEJS_24_X,\n logGroup: new LogGroup(this, \"viewer-request-handler-log-group\", {\n retention: RetentionDays.ONE_MONTH,\n }),\n });\n\n /******************************************************************************\n *\n * CLOUDFRONT CONFIG\n *\n * Setup a CloudFront Distribution for the bucket.\n *\n *****************************************************************************/\n\n const cachePolicy = new CachePolicy(this, \"cloudfront-policy\", {\n comment: \"Relatively conservative TTL policy.\",\n maxTtl: Duration.seconds(300),\n minTtl: Duration.seconds(0),\n defaultTtl: Duration.seconds(60),\n headerBehavior: CacheHeaderBehavior.none(),\n queryStringBehavior: CacheQueryStringBehavior.none(),\n cookieBehavior: CacheCookieBehavior.none(),\n enableAcceptEncodingGzip: true,\n enableAcceptEncodingBrotli: true,\n });\n\n const oac = new S3OriginAccessControl(this, \"MyOAC\", {\n signing: Signing.SIGV4_NO_OVERRIDE,\n });\n const origin = S3BucketOrigin.withOriginAccessControl(bucket, {\n originAccessControl: oac,\n originAccessLevels: [AccessLevel.READ],\n });\n\n const distribution = new Distribution(this, \"cloudfront-distribution\", {\n comment: `Distribution for ${props.description ?? id}`,\n\n /**\n * Only if domain was supplied\n */\n ...(certificate && baseDomain\n ? {\n certificate,\n domainNames: [baseDomain, `*.${baseDomain}`],\n }\n : {}),\n\n defaultBehavior: {\n origin,\n viewerProtocolPolicy: ViewerProtocolPolicy.REDIRECT_TO_HTTPS,\n cachePolicy,\n allowedMethods: AllowedMethods.ALLOW_GET_HEAD_OPTIONS,\n edgeLambdas: [\n {\n functionVersion: handler.currentVersion,\n eventType: LambdaEdgeEventType.VIEWER_REQUEST,\n },\n ],\n },\n defaultRootObject: \"index.html\",\n });\n\n /**\n * We finally have enough information to set the full domain.\n */\n this.fullDomain =\n certificate && baseDomain ? baseDomain : distribution.domainName;\n\n /***************************************************************************\n *\n * DNS ENTRY\n *\n * Link cloudfront to both the root fulldomain and all possible subdomains.\n *\n **************************************************************************/\n\n if (zone) {\n new ARecord(this, \"root-dns-entry\", {\n zone,\n recordName: baseDomain ? baseDomain : \"\",\n target: RecordTarget.fromAlias(new CloudFrontTarget(distribution)),\n });\n\n new ARecord(this, \"wc-dns-entry\", {\n zone,\n recordName: baseDomain ? `*.${baseDomain}` : \"*\",\n target: RecordTarget.fromAlias(new CloudFrontTarget(distribution)),\n });\n }\n\n /***************************************************************************\n *\n * EXPORTS\n *\n * Used by content uploader later.\n *\n **************************************************************************/\n\n new StringParameter(this, \"dist-domain\", {\n description: `GENERATED DO NOT CHANGE - CloudFront Distribution Details (${props.description ?? id}).`,\n parameterName: distributionDomainParamName,\n stringValue: distribution.domainName,\n });\n\n new StringParameter(this, \"dist-id\", {\n description: `GENERATED DO NOT CHANGE - CloudFront Distribution Details (${props.description ?? id}).`,\n parameterName: distributionIDParamName,\n stringValue: distribution.distributionId,\n });\n\n new StringParameter(this, \"bucket-arn\", {\n description: `GENERATED DO NOT CHANGE - S3 Bucket ARN for (${props.description ?? id}).`,\n parameterName: bucketArnParamName,\n stringValue: bucket.bucketArn,\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKa,IAAAA,SAAA,iBAAiB;;;;MAI5B,KAAK;;;;MAKL,OAAO;;;;MAKP,MAAM;;AAYK,IAAAA,SAAA,yBAAyB;;;;;MAKpC,SAAS;;;;;MAKT,WAAW;;AAcA,IAAAA,SAAA,uBAAuBA,SAAA;;;;;;;;;;ACvDpC,QAAA,uBAAA,QAAA,eAAA;AAQO,QAAMC,iBAAgB,MAAa;AACxC,cAAO,GAAA,qBAAA,UAAS,iCAAiC,EAC9C,SAAS,MAAM,EACf,QAAQ,cAAc,EAAE;IAC7B;AAJa,IAAAC,SAAA,gBAAaD;AAMnB,QAAM,kBAAkB,MAAa;AAI1C,UAAI,QAAQ,IAAI,mBAAmB;AACjC,eAAO,QAAQ,IAAI;MACrB;AAKA,YAAM,UAAS,GAAA,qBAAA,UAAS,oCAAoC,EACzD,SAAS,MAAM,EACf,QAAQ,cAAc,EAAE,EACxB,KAAI;AAEP,YAAM,QAAQ,OAAO,MAAM,iCAAiC;AAC5D,YAAM,WAAW,QAAQ,MAAM,CAAC,IAAI;AAEpC,aAAO;IACT;AApBa,IAAAC,SAAA,k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;AAED,QAAI,gCAAgB,MAAM,cAAc;AAAA,MACtC,aAAa,gDAAgD,MAAM,eAAe,EAAE;AAAA,MACpF,eAAe;AAAA,MACf,aAAa,OAAO;AAAA,IACtB,CAAC;AAAA,EACH;AACF;","names":["exports","findGitBranch","exports","exports","exports","import_aws_s3","import_aws_cdk_lib","import_aws_ssm","import_constructs"]}
1
+ {"version":3,"sources":["../../utils/src/aws/aws-types.ts","../../utils/src/git/git-utils.ts","../../utils/src/string/string-utils.ts","../../utils/src/index.ts","../src/index.ts","../src/lambda/pnpm-workspace-nodejs-function.ts","../src/lambda/pnpm-workspace-parser.ts","../src/s3/private-bucket.ts","../src/static-hosting/static-content.ts","../src/static-hosting/static-hosting.ts"],"sourcesContent":["/**\n * Stage Types\n *\n * What stage of deployment is this? Dev, staging, or prod?\n */\nexport const AWS_STAGE_TYPE = {\n /**\n * Development environment, typically used for testing and development.\n */\n DEV: \"dev\",\n\n /**\n * Staging environment, used for pre-production testing.\n */\n STAGE: \"stage\",\n\n /**\n * Production environment, used for live deployments.\n */\n PROD: \"prod\",\n} as const;\n\n/**\n * Above const as a type.\n */\nexport type AwsStageType = (typeof AWS_STAGE_TYPE)[keyof typeof AWS_STAGE_TYPE];\n\n/**\n * Deployment target role: whether an (account, region) is the primary or\n * secondary deployment target (e.g. primary vs replica region).\n */\nexport const DEPLOYMENT_TARGET_ROLE = {\n /**\n * Account and region that represents the primary region for this service.\n * For example, the base DynamoDB Region for global tables.\n */\n PRIMARY: \"primary\",\n /**\n * Account and region that represents a secondary region for this service.\n * For example, a replica region for a global DynamoDB table.\n */\n SECONDARY: \"secondary\",\n} as const;\n\n/**\n * Type for deployment target role values.\n */\nexport type DeploymentTargetRoleType =\n (typeof DEPLOYMENT_TARGET_ROLE)[keyof typeof DEPLOYMENT_TARGET_ROLE];\n\n/**\n * Environment types (primary/secondary).\n *\n * @deprecated Use {@link DEPLOYMENT_TARGET_ROLE} instead. This constant is maintained for backward compatibility.\n */\nexport const AWS_ENVIRONMENT_TYPE = DEPLOYMENT_TARGET_ROLE;\n\n/**\n * Type for environment type values.\n *\n * @deprecated Use {@link DeploymentTargetRoleType} instead. This type is maintained for backward compatibility.\n */\nexport type AwsEnvironmentType = DeploymentTargetRoleType;\n","import { execSync } from \"node:child_process\";\n\n/**\n * Returns the current full git branch name\n *\n * ie: feature/1234 returns feature/1234\n *\n */\nexport const findGitBranch = (): string => {\n return execSync(\"git rev-parse --abbrev-ref HEAD\")\n .toString(\"utf8\")\n .replace(/[\\n\\r\\s]+$/, \"\");\n};\n\nexport const findGitRepoName = (): string => {\n /**\n * When running in github actions this will be populated.\n */\n if (process.env.GITHUB_REPOSITORY) {\n return process.env.GITHUB_REPOSITORY;\n }\n\n /**\n * locally, we need to extract the repo name from the git config.\n */\n const remote = execSync(\"git config --get remote.origin.url\")\n .toString(\"utf8\")\n .replace(/[\\n\\r\\s]+$/, \"\")\n .trim();\n\n const match = remote.match(/[:\\/]([^/]+\\/[^/]+?)(?:\\.git)?$/);\n const repoName = match ? match[1] : \"error-repo-name\";\n\n return repoName;\n};\n","import * as crypto from \"node:crypto\";\n\n/**\n *\n * @param inString - string to hash\n * @param trimLength - trim to this length (defaults to 999 chars)\n * @returns Hex-encoded sha256 digest, truncated to `trimLength` characters.\n */\nexport const hashString = (inString: string, trimLength: number = 999) => {\n return crypto\n .createHash(\"sha256\")\n .update(inString)\n .digest(\"hex\")\n .substring(0, trimLength);\n};\n\n/**\n *\n * @param inputString - string to truncate\n * @param maxLength - max length of this string\n * @returns trimmed string\n */\nexport const trimStringLength = (inputString: string, maxLength: number) => {\n return inputString.length < maxLength\n ? inputString\n : inputString.substring(0, maxLength);\n};\n","export * from \"./aws/aws-types\";\nexport * from \"./git/git-utils\";\nexport * from \"./string/string-utils\";\n","export * from \"./lambda\";\nexport * from \"./s3\";\nexport * from \"./static-hosting\";\n","import * as fs from \"node:fs\";\nimport * as path from \"node:path\";\nimport {\n NodejsFunction,\n NodejsFunctionProps,\n} from \"aws-cdk-lib/aws-lambda-nodejs\";\nimport { Construct } from \"constructs\";\nimport {\n findPnpmWorkspaceFile,\n mergeNpmrc,\n readPnpmWorkspacePolicy,\n renderNpmrcLines,\n} from \"./pnpm-workspace-parser\";\n\n/**\n * Props for `PnpmWorkspaceNodejsFunction`. Extends\n * `NodejsFunctionProps` so the wrapper is a drop-in for any existing\n * `NodejsFunction` call site.\n */\nexport interface PnpmWorkspaceNodejsFunctionProps extends NodejsFunctionProps {\n /**\n * Directory to begin the upward search for `pnpm-workspace.yaml`.\n * Defaults to the directory of the resolved entry path.\n */\n readonly workspaceSearchFrom?: string;\n\n /**\n * Skip the policy-mirror step entirely. Useful for tests or when the\n * caller wants the pure `NodejsFunction` behavior.\n *\n * @default false\n */\n readonly disablePnpmPolicyMirror?: boolean;\n}\n\n/**\n * Result of `mirrorPnpmWorkspacePolicy` — describes what the policy\n * mirror did for one entry.\n */\nexport interface MirrorPnpmWorkspacePolicyResult {\n /** Resolved `.npmrc` path if a write happened, otherwise undefined. */\n readonly npmrcPath?: string;\n /** Reason the mirror was a no-op, if it was. */\n readonly skippedReason?:\n | \"missing-entry\"\n | \"missing-workspace-file\"\n | \"empty-policy\"\n | \"no-change\";\n}\n\n/**\n * Mirror the workspace pnpm policy into an `.npmrc` adjacent to the\n * Lambda entry. Pure side-effect helper used by\n * `PnpmWorkspaceNodejsFunction`; exported so consumers can drive it\n * from other call sites if desired.\n */\nexport const mirrorPnpmWorkspacePolicy = (params: {\n readonly entry: string;\n readonly workspaceSearchFrom?: string;\n}): MirrorPnpmWorkspacePolicyResult => {\n const { entry, workspaceSearchFrom } = params;\n if (!fs.existsSync(entry)) {\n return { skippedReason: \"missing-entry\" };\n }\n\n const entryDir = path.dirname(path.resolve(entry));\n const searchFrom = workspaceSearchFrom\n ? path.resolve(workspaceSearchFrom)\n : entryDir;\n\n const workspaceFile = findPnpmWorkspaceFile(searchFrom);\n if (!workspaceFile) {\n return { skippedReason: \"missing-workspace-file\" };\n }\n\n const policy = readPnpmWorkspacePolicy(workspaceFile);\n const lines = renderNpmrcLines(policy);\n if (lines.length === 0) {\n return { skippedReason: \"empty-policy\" };\n }\n\n const npmrcPath = path.join(entryDir, \".npmrc\");\n const existing = fs.existsSync(npmrcPath)\n ? fs.readFileSync(npmrcPath, \"utf8\")\n : undefined;\n const merged = mergeNpmrc(existing, lines);\n\n if (merged === existing) {\n return { npmrcPath, skippedReason: \"no-change\" };\n }\n\n fs.writeFileSync(npmrcPath, merged);\n return { npmrcPath };\n};\n\n/**\n * A `NodejsFunction` wrapper that mirrors the workspace's pnpm policy\n * (currently `minimumReleaseAge` and `minimumReleaseAgeExclude`) into\n * an `.npmrc` adjacent to the Lambda entry before bundling.\n *\n * CDK's bundler runs `pnpm install` in an isolated temp directory\n * outside the workspace, which means `pnpm-workspace.yaml` settings\n * do not apply there. Mirroring the policy into an entry-adjacent\n * `.npmrc` (which CDK copies into the bundling input directory)\n * lets the inner `pnpm install` honour the same freshness rules.\n *\n * See the `pnpm-workspace-nodejs-function` documentation page for\n * full details on what gets mirrored, merge behaviour against an\n * existing `.npmrc`, and when to disable the mirror.\n */\nexport class PnpmWorkspaceNodejsFunction extends NodejsFunction {\n constructor(\n scope: Construct,\n id: string,\n props: PnpmWorkspaceNodejsFunctionProps,\n ) {\n if (!props.disablePnpmPolicyMirror && props.entry) {\n mirrorPnpmWorkspacePolicy({\n entry: props.entry,\n workspaceSearchFrom: props.workspaceSearchFrom,\n });\n }\n\n const { disablePnpmPolicyMirror, workspaceSearchFrom, ...rest } = props;\n void disablePnpmPolicyMirror;\n void workspaceSearchFrom;\n super(scope, id, rest);\n }\n}\n","import * as fs from \"node:fs\";\nimport * as path from \"node:path\";\nimport * as yaml from \"js-yaml\";\n\n/**\n * Subset of `pnpm-workspace.yaml` fields that map to `.npmrc` keys\n * pnpm honours when running install in a non-workspace directory.\n */\nexport interface PnpmWorkspacePolicy {\n /** `minimumReleaseAge` (minutes) — equivalent to `.npmrc` `minimum-release-age`. */\n readonly minimumReleaseAge?: number;\n /**\n * `minimumReleaseAgeExclude` — equivalent to `.npmrc`\n * `minimum-release-age-exclude` (comma-separated when serialised).\n */\n readonly minimumReleaseAgeExclude?: ReadonlyArray<string>;\n}\n\n/**\n * Walk up from `startDir` until a `pnpm-workspace.yaml` file is found\n * and return its absolute path. Returns `undefined` when the filesystem\n * root is reached without finding one.\n */\nexport const findPnpmWorkspaceFile = (startDir: string): string | undefined => {\n let current = path.resolve(startDir);\n while (true) {\n const candidate = path.join(current, \"pnpm-workspace.yaml\");\n if (fs.existsSync(candidate)) {\n return candidate;\n }\n const parent = path.dirname(current);\n if (parent === current) {\n return undefined;\n }\n current = parent;\n }\n};\n\n/**\n * Read the policy subset (`minimumReleaseAge` and\n * `minimumReleaseAgeExclude`) from a `pnpm-workspace.yaml` file.\n *\n * Returns an empty object when the file is missing, unreadable, or\n * contains neither key. Throws when the file is present but YAML\n * parsing fails — the caller is expected to surface a clear error.\n */\nexport const readPnpmWorkspacePolicy = (\n workspaceFile: string,\n): PnpmWorkspacePolicy => {\n if (!fs.existsSync(workspaceFile)) {\n return {};\n }\n\n const raw = fs.readFileSync(workspaceFile, \"utf8\");\n const parsed = yaml.load(raw);\n\n if (!parsed || typeof parsed !== \"object\") {\n return {};\n }\n\n const obj = parsed as Record<string, unknown>;\n const policy: {\n -readonly [K in keyof PnpmWorkspacePolicy]: PnpmWorkspacePolicy[K];\n } = {};\n\n const age = obj.minimumReleaseAge;\n if (typeof age === \"number\" && Number.isFinite(age)) {\n policy.minimumReleaseAge = age;\n }\n\n const exclude = obj.minimumReleaseAgeExclude;\n if (Array.isArray(exclude)) {\n const cleaned = exclude.filter(\n (entry): entry is string => typeof entry === \"string\" && entry.length > 0,\n );\n if (cleaned.length > 0) {\n policy.minimumReleaseAgeExclude = cleaned;\n }\n }\n\n return policy;\n};\n\n/**\n * Render an `.npmrc` body that pnpm will honour when installing in\n * a directory outside the workspace tree. The keys emitted here are\n * the `.npmrc` equivalents of the `pnpm-workspace.yaml` fields in\n * {@link PnpmWorkspacePolicy} — pnpm reads `minimum-release-age` and\n * `minimum-release-age-exclude` from `.npmrc`, not from the workspace\n * file, when the install runs outside the workspace.\n *\n * Returns an empty string when the policy carries no relevant fields.\n */\nexport const renderNpmrcLines = (\n policy: PnpmWorkspacePolicy,\n): ReadonlyArray<string> => {\n const lines: Array<string> = [];\n\n if (typeof policy.minimumReleaseAge === \"number\") {\n lines.push(`minimum-release-age=${policy.minimumReleaseAge}`);\n }\n\n const exclude = policy.minimumReleaseAgeExclude ?? [];\n if (exclude.length > 0) {\n lines.push(`minimum-release-age-exclude=${exclude.join(\",\")}`);\n }\n\n return lines;\n};\n\n/**\n * Parse the body of an existing `.npmrc` file into a map of trimmed\n * key/value pairs. Lines that are blank or start with `#` are dropped.\n * Lines without an `=` are dropped.\n */\nexport const parseNpmrc = (body: string): Map<string, string> => {\n const map = new Map<string, string>();\n for (const rawLine of body.split(/\\r?\\n/)) {\n const line = rawLine.trim();\n if (line.length === 0 || line.startsWith(\"#\")) {\n continue;\n }\n const eq = line.indexOf(\"=\");\n if (eq < 0) {\n continue;\n }\n const key = line.slice(0, eq).trim();\n const value = line.slice(eq + 1).trim();\n if (key.length > 0) {\n map.set(key, value);\n }\n }\n return map;\n};\n\n/**\n * Merge a set of policy-derived `.npmrc` lines into an existing\n * `.npmrc` body. Our keys overwrite matching keys in the existing\n * body; all other keys are preserved. Returns the new `.npmrc` body\n * (always terminated by a trailing newline when non-empty).\n */\nexport const mergeNpmrc = (\n existing: string | undefined,\n ourLines: ReadonlyArray<string>,\n): string => {\n if (ourLines.length === 0) {\n return existing ?? \"\";\n }\n\n const ourMap = new Map<string, string>();\n for (const line of ourLines) {\n const eq = line.indexOf(\"=\");\n if (eq < 0) {\n continue;\n }\n ourMap.set(line.slice(0, eq).trim(), line.slice(eq + 1).trim());\n }\n\n const existingMap = parseNpmrc(existing ?? \"\");\n for (const [key, value] of ourMap) {\n existingMap.set(key, value);\n }\n\n const orderedKeys: Array<string> = [];\n const seen = new Set<string>();\n\n // Preserve the original line order for any pre-existing keys.\n for (const rawLine of (existing ?? \"\").split(/\\r?\\n/)) {\n const line = rawLine.trim();\n if (line.length === 0 || line.startsWith(\"#\")) {\n continue;\n }\n const eq = line.indexOf(\"=\");\n if (eq < 0) {\n continue;\n }\n const key = line.slice(0, eq).trim();\n if (key.length > 0 && existingMap.has(key) && !seen.has(key)) {\n orderedKeys.push(key);\n seen.add(key);\n }\n }\n\n // Append any keys we added that weren't already present.\n for (const key of ourMap.keys()) {\n if (!seen.has(key)) {\n orderedKeys.push(key);\n seen.add(key);\n }\n }\n\n const body = orderedKeys\n .map((key) => `${key}=${existingMap.get(key)}`)\n .join(\"\\n\");\n\n return body.length === 0 ? \"\" : `${body}\\n`;\n};\n","import { RemovalPolicy } from \"aws-cdk-lib\";\nimport {\n BlockPublicAccess,\n Bucket,\n BucketProps,\n ObjectOwnership,\n} from \"aws-cdk-lib/aws-s3\";\nimport { Construct } from \"constructs\";\n\nexport interface PrivateBucketProps extends BucketProps {}\n\nexport class PrivateBucket extends Bucket {\n constructor(scope: Construct, id: string, props: PrivateBucketProps = {}) {\n const defaultProps = {\n removalPolicy: props.removalPolicy ?? RemovalPolicy.RETAIN,\n autoDeleteObjects: props.removalPolicy === RemovalPolicy.DESTROY,\n };\n\n const requiredProps = {\n publicReadAccess: false,\n blockPublicAccess: BlockPublicAccess.BLOCK_ALL,\n enforceSSL: true,\n objectOwnership: ObjectOwnership.BUCKET_OWNER_ENFORCED,\n };\n\n super(scope, id, { ...defaultProps, ...props, ...requiredProps });\n }\n}\n","// eslint-disable-next-line import/no-extraneous-dependencies\nimport { findGitBranch } from \"@codedrifters/utils\";\nimport { Bucket } from \"aws-cdk-lib/aws-s3\";\nimport { BucketDeployment, Source } from \"aws-cdk-lib/aws-s3-deployment\";\nimport { StringParameter } from \"aws-cdk-lib/aws-ssm\";\nimport { paramCase } from \"change-case\";\nimport { Construct } from \"constructs\";\n\n/*******************************************************************************\n *\n * STATIC CONTENT UPLOADER\n *\n * This construct uploads a directory of content from a local location into S3.\n *\n * To support PR and branch specific builds, each S3 bucket can store content\n * for multiple domains and builds, using the following format:\n *\n * S3-bucket/domain/*\n *\n * A bucket used to store content for stage.openhi.org might have the\n * following directory structure (all in the same bucket).\n *\n * `/stage.openhi.org/*` serves content to stage.openhi.org\n * `/feature-7.stage.openhi.org/*` serves content to feature-7.stage.openhi.org\n * `/pr-123.stage.openhi.org/*` serves content to pr-123.stage.openhi.org\n *\n ******************************************************************************/\n\nexport interface StaticContentProps {\n /**\n * Parameter name to use when storing the static hosting bucket's ARN.\n * This is needed in other later steps when deploying hosted content to S3.\n */\n readonly bucketArnParamName?: string;\n\n /**\n * Absolute path to directory containing content for the website.\n */\n readonly contentSourceDirectory: string;\n\n /**\n * Directory to place content into. Should start with a slash.\n * Example: '/widget'\n */\n readonly contentDestinationDirectory: string;\n\n /**\n * The sub domain prefix (ie: images)\n *\n * @default git branch name\n */\n readonly subDomain?: string;\n\n /**\n * The full domain (ie: staging.codedrifters.com)\n */\n readonly fullDomain: string;\n}\n\nexport class StaticContent extends Construct {\n constructor(scope: Construct, id: string, props: StaticContentProps) {\n super(scope, id);\n\n /***************************************************************************\n *\n * Initial Setup\n *\n * Set some defaults, build domain information.\n *\n **************************************************************************/\n\n const {\n bucketArnParamName,\n contentSourceDirectory,\n contentDestinationDirectory,\n subDomain,\n fullDomain,\n } = {\n bucketArnParamName: \"/STATIC_WEBSITE/BUCKET_ARN\",\n subDomain: findGitBranch(),\n ...props,\n };\n\n /***************************************************************************\n *\n * Import and build some values from Param Store during deployment.\n *\n **************************************************************************/\n\n const keyPrefix = [paramCase(subDomain), fullDomain].join(\".\");\n\n const bucketArn = StringParameter.valueForStringParameter(\n this,\n bucketArnParamName,\n );\n const bucket = Bucket.fromBucketArn(this, \"bucket\", bucketArn);\n\n /***************************************************************************\n *\n * Gather the sources we'll be deploying. We need to have an empty source\n * for tests since it will change all the time and bork up the test\n * snapshots if we don't.\n *\n **************************************************************************/\n\n const isTestEnv = process.env.VITEST === \"true\";\n const sources = isTestEnv ? [] : [Source.asset(contentSourceDirectory)];\n\n new BucketDeployment(this, \"deploy\", {\n sources,\n destinationBucket: bucket,\n retainOnDelete: false,\n destinationKeyPrefix: `${keyPrefix}${contentDestinationDirectory}`,\n });\n }\n}\n","import * as fs from \"node:fs\";\nimport * as path from \"node:path\";\nimport { Duration, StackProps } from \"aws-cdk-lib\";\nimport {\n Certificate,\n CertificateValidation,\n} from \"aws-cdk-lib/aws-certificatemanager\";\nimport {\n AccessLevel,\n AllowedMethods,\n CacheCookieBehavior,\n CacheHeaderBehavior,\n CachePolicy,\n CacheQueryStringBehavior,\n Distribution,\n LambdaEdgeEventType,\n S3OriginAccessControl,\n Signing,\n ViewerProtocolPolicy,\n} from \"aws-cdk-lib/aws-cloudfront\";\nimport { S3BucketOrigin } from \"aws-cdk-lib/aws-cloudfront-origins\";\nimport { Runtime } from \"aws-cdk-lib/aws-lambda\";\nimport { NodejsFunction } from \"aws-cdk-lib/aws-lambda-nodejs\";\nimport { LogGroup, RetentionDays } from \"aws-cdk-lib/aws-logs\";\nimport {\n ARecord,\n HostedZone,\n HostedZoneAttributes,\n IHostedZone,\n RecordTarget,\n} from \"aws-cdk-lib/aws-route53\";\nimport { CloudFrontTarget } from \"aws-cdk-lib/aws-route53-targets\";\nimport { StringParameter } from \"aws-cdk-lib/aws-ssm\";\nimport { Construct } from \"constructs\";\nimport type { HostingMode } from \"./static-hosting.viewer-request-handler\";\nimport { PrivateBucket, PrivateBucketProps } from \"../s3/private-bucket\";\n\nexport interface StaticDomainProps {\n /**\n * The base domain (ie: codedrifters.com)\n */\n readonly baseDomain: string;\n\n /**\n * Hosted zone ID for the base domain.\n */\n readonly hostedZoneAttributes: HostedZoneAttributes;\n}\n\nexport interface StaticHostingProps extends StackProps {\n /**\n * Short description used in various places for traceability.\n */\n readonly description?: string;\n\n /**\n * Values used to connect a domain name to the cloudfront distribution. If not\n * supplied, cloudfront doesn't use a custom domain.\n */\n readonly staticDomainProps?: StaticDomainProps;\n\n /**\n * Parameter name to use when storing the static hosting bucket's ARN.\n * This is needed in other later steps when deploying hosted content to S3.\n */\n readonly bucketArnParamName?: string;\n\n /**\n * Parameter name to use when storing the CloudFront Distribution Domain Name.\n */\n readonly distributionDomainParamName?: string;\n\n /**\n * Parameter name to use when storing the CloudFront Distribution ID.\n */\n readonly distributionIDParamName?: string;\n\n /**\n * Props to pass to the private S3 bucket.\n */\n readonly privateBucketProps?: PrivateBucketProps;\n\n /**\n * Selects how path-like URIs are rewritten by the viewer-request\n * `Lambda@Edge` handler.\n *\n * - `spa` (default): path-like URIs rewrite to `/index.html` so a\n * single-page app can serve its one root index and let the client-side\n * router handle the path.\n * - `static`: path-like URIs append `/index.html` (e.g. `/docs` →\n * `/docs/index.html`) so multi-page static sites can serve distinct\n * HTML per path.\n *\n * Multi-tenant domain-folder prepending runs after the rewrite in both\n * modes and is unaffected by this prop.\n *\n * @default \"spa\"\n */\n readonly hostingMode?: HostingMode;\n}\n\nexport class StaticHosting extends Construct {\n /**\n * Full domain name used as basis for hosting.\n */\n public readonly fullDomain: string;\n\n constructor(scope: Construct, id: string, props: StaticHostingProps = {}) {\n super(scope, id);\n\n /***************************************************************************\n *\n * Initial Setup\n *\n * Set some defaults, build domain information.\n *\n **************************************************************************/\n\n const {\n bucketArnParamName,\n distributionDomainParamName,\n distributionIDParamName,\n staticDomainProps,\n privateBucketProps,\n hostingMode,\n } = {\n bucketArnParamName: \"/STATIC_WEBSITE/BUCKET_ARN\",\n distributionDomainParamName: \"/STATIC_WEBSITE/DISTRIBUTION_DOMAIN\",\n distributionIDParamName: \"/STATIC_WEBSITE/DISTRIBUTION_ID\",\n hostingMode: \"spa\" as HostingMode,\n ...props,\n };\n\n const { baseDomain, hostedZoneAttributes } = staticDomainProps ?? {};\n\n /***************************************************************************\n *\n * PRIVATE BUCKET\n *\n * A bucket to store the files within.\n * Save ARN for later deploys.\n *\n **************************************************************************/\n\n const bucket = new PrivateBucket(\n this,\n \"static-hosting-bucket\",\n privateBucketProps,\n );\n\n /***************************************************************************\n *\n * DNS & Wildcard Certificate\n *\n * If a zone Id as passed in, find the hosted zone and create a wildcard\n * certificate for the domain.\n *\n **************************************************************************/\n\n let zone: IHostedZone | undefined;\n let certificate: Certificate | undefined;\n\n if (hostedZoneAttributes && baseDomain) {\n zone = HostedZone.fromHostedZoneAttributes(\n this,\n \"zone\",\n hostedZoneAttributes,\n );\n certificate = new Certificate(this, \"wildcard-certificate\", {\n domainName: `*.${baseDomain}`,\n subjectAlternativeNames: [baseDomain],\n validation: CertificateValidation.fromDnsMultiZone({\n [`*.${baseDomain}`]: zone,\n [baseDomain]: zone,\n }),\n });\n }\n\n /******************************************************************************\n *\n * `LAMBDA@EDGE` FUNCTION\n *\n * This handles rewriting the path from domain name.\n *\n *****************************************************************************/\n\n // Explicit entry required: when omitted, NodejsFunction infers the path from the\n // call site (the built lib/index.js), so it looks for index.viewer-request-handler.js\n // in the package. That file is only emitted if we add it as a separate tsup entry.\n // Use .js when present (built package); fall back to .ts for tests running from source.\n const handlerJs = path.join(\n __dirname,\n \"static-hosting.viewer-request-handler.js\",\n );\n const handlerTs = path.join(\n __dirname,\n \"static-hosting.viewer-request-handler.ts\",\n );\n const handlerEntry = fs.existsSync(handlerJs) ? handlerJs : handlerTs;\n\n const handler = new NodejsFunction(this, \"viewer-request-handler\", {\n entry: handlerEntry,\n handler: hostingMode === \"static\" ? \"staticHandler\" : \"spaHandler\",\n memorySize: 128,\n runtime: Runtime.NODEJS_24_X,\n logGroup: new LogGroup(this, \"viewer-request-handler-log-group\", {\n retention: RetentionDays.ONE_MONTH,\n }),\n });\n\n /******************************************************************************\n *\n * CLOUDFRONT CONFIG\n *\n * Setup a CloudFront Distribution for the bucket.\n *\n *****************************************************************************/\n\n const cachePolicy = new CachePolicy(this, \"cloudfront-policy\", {\n comment: \"Relatively conservative TTL policy.\",\n maxTtl: Duration.seconds(300),\n minTtl: Duration.seconds(0),\n defaultTtl: Duration.seconds(60),\n headerBehavior: CacheHeaderBehavior.none(),\n queryStringBehavior: CacheQueryStringBehavior.none(),\n cookieBehavior: CacheCookieBehavior.none(),\n enableAcceptEncodingGzip: true,\n enableAcceptEncodingBrotli: true,\n });\n\n const oac = new S3OriginAccessControl(this, \"MyOAC\", {\n signing: Signing.SIGV4_NO_OVERRIDE,\n });\n const origin = S3BucketOrigin.withOriginAccessControl(bucket, {\n originAccessControl: oac,\n originAccessLevels: [AccessLevel.READ],\n });\n\n const distribution = new Distribution(this, \"cloudfront-distribution\", {\n comment: `Distribution for ${props.description ?? id}`,\n\n /**\n * Only if domain was supplied\n */\n ...(certificate && baseDomain\n ? {\n certificate,\n domainNames: [baseDomain, `*.${baseDomain}`],\n }\n : {}),\n\n defaultBehavior: {\n origin,\n viewerProtocolPolicy: ViewerProtocolPolicy.REDIRECT_TO_HTTPS,\n cachePolicy,\n allowedMethods: AllowedMethods.ALLOW_GET_HEAD_OPTIONS,\n edgeLambdas: [\n {\n functionVersion: handler.currentVersion,\n eventType: LambdaEdgeEventType.VIEWER_REQUEST,\n },\n ],\n },\n defaultRootObject: \"index.html\",\n });\n\n /**\n * We finally have enough information to set the full domain.\n */\n this.fullDomain =\n certificate && baseDomain ? baseDomain : distribution.domainName;\n\n /***************************************************************************\n *\n * DNS ENTRY\n *\n * Link cloudfront to both the root fulldomain and all possible subdomains.\n *\n **************************************************************************/\n\n if (zone) {\n new ARecord(this, \"root-dns-entry\", {\n zone,\n recordName: baseDomain ? baseDomain : \"\",\n target: RecordTarget.fromAlias(new CloudFrontTarget(distribution)),\n });\n\n new ARecord(this, \"wc-dns-entry\", {\n zone,\n recordName: baseDomain ? `*.${baseDomain}` : \"*\",\n target: RecordTarget.fromAlias(new CloudFrontTarget(distribution)),\n });\n }\n\n /***************************************************************************\n *\n * EXPORTS\n *\n * Used by content uploader later.\n *\n **************************************************************************/\n\n new StringParameter(this, \"dist-domain\", {\n description: `GENERATED DO NOT CHANGE - CloudFront Distribution Details (${props.description ?? id}).`,\n parameterName: distributionDomainParamName,\n stringValue: distribution.domainName,\n });\n\n new StringParameter(this, \"dist-id\", {\n description: `GENERATED DO NOT CHANGE - CloudFront Distribution Details (${props.description ?? id}).`,\n parameterName: distributionIDParamName,\n stringValue: distribution.distributionId,\n });\n\n new StringParameter(this, \"bucket-arn\", {\n description: `GENERATED DO NOT CHANGE - S3 Bucket ARN for (${props.description ?? id}).`,\n parameterName: bucketArnParamName,\n stringValue: bucket.bucketArn,\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKa,IAAAA,SAAA,iBAAiB;;;;MAI5B,KAAK;;;;MAKL,OAAO;;;;MAKP,MAAM;;AAYK,IAAAA,SAAA,yBAAyB;;;;;MAKpC,SAAS;;;;;MAKT,WAAW;;AAcA,IAAAA,SAAA,uBAAuBA,SAAA;;;;;;;;;;ACvDpC,QAAA,uBAAA,QAAA,eAAA;AAQO,QAAMC,iBAAgB,MAAa;AACxC,cAAO,GAAA,qBAAA,UAAS,iCAAiC,EAC9C,SAAS,MAAM,EACf,QAAQ,cAAc,EAAE;IAC7B;AAJa,IAAAC,SAAA,gBAAaD;AAMnB,QAAM,kBAAkB,MAAa;AAI1C,UAAI,QAAQ,IAAI,mBAAmB;AACjC,eAAO,QAAQ,IAAI;MACrB;AAKA,YAAM,UAAS,GAAA,qBAAA,UAAS,oCAAoC,EACzD,SAAS,MAAM,EACf,QAAQ,cAAc,EAAE,EACxB,KAAI;AAEP,YAAM,QAAQ,OAAO,MAAM,iCAAiC;AAC5D,YAAM,WAAW,QAAQ,MAAM,CAAC,IAAI;AAEpC,aAAO;IACT;AApBa,IAAAC,SAAA,kBAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACd5B,QAAA,SAAA,aAAA,QAAA,QAAA,CAAA;AAQO,QAAM,aAAa,CAAC,UAAkB,aAAqB,QAAO;AACvE,aAAO,OACJ,WAA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A,QAChC;AAAA,QACA,YAAY,aAAa,KAAK,UAAU,KAAK;AAAA,QAC7C,QAAQ,gCAAa,UAAU,IAAI,4CAAiB,YAAY,CAAC;AAAA,MACnE,CAAC;AAAA,IACH;AAUA,QAAI,gCAAgB,MAAM,eAAe;AAAA,MACvC,aAAa,8DAA8D,MAAM,eAAe,EAAE;AAAA,MAClG,eAAe;AAAA,MACf,aAAa,aAAa;AAAA,IAC5B,CAAC;AAED,QAAI,gCAAgB,MAAM,WAAW;AAAA,MACnC,aAAa,8DAA8D,MAAM,eAAe,EAAE;AAAA,MAClG,eAAe;AAAA,MACf,aAAa,aAAa;AAAA,IAC5B,CAAC;AAED,QAAI,gCAAgB,MAAM,cAAc;AAAA,MACtC,aAAa,gDAAgD,MAAM,eAAe,EAAE;AAAA,MACpF,eAAe;AAAA,MACf,aAAa,OAAO;AAAA,IACtB,CAAC;AAAA,EACH;AACF;","names":["exports","findGitBranch","exports","exports","exports","fs","path","import_aws_s3","fs","path","import_aws_cdk_lib","import_aws_lambda_nodejs","import_aws_ssm","import_constructs"]}
package/lib/index.mjs CHANGED
@@ -146,6 +146,172 @@ var require_lib = __commonJS({
146
146
  }
147
147
  });
148
148
 
149
+ // src/lambda/pnpm-workspace-nodejs-function.ts
150
+ import * as fs2 from "fs";
151
+ import * as path2 from "path";
152
+ import {
153
+ NodejsFunction
154
+ } from "aws-cdk-lib/aws-lambda-nodejs";
155
+
156
+ // src/lambda/pnpm-workspace-parser.ts
157
+ import * as fs from "fs";
158
+ import * as path from "path";
159
+ import * as yaml from "js-yaml";
160
+ var findPnpmWorkspaceFile = (startDir) => {
161
+ let current = path.resolve(startDir);
162
+ while (true) {
163
+ const candidate = path.join(current, "pnpm-workspace.yaml");
164
+ if (fs.existsSync(candidate)) {
165
+ return candidate;
166
+ }
167
+ const parent = path.dirname(current);
168
+ if (parent === current) {
169
+ return void 0;
170
+ }
171
+ current = parent;
172
+ }
173
+ };
174
+ var readPnpmWorkspacePolicy = (workspaceFile) => {
175
+ if (!fs.existsSync(workspaceFile)) {
176
+ return {};
177
+ }
178
+ const raw = fs.readFileSync(workspaceFile, "utf8");
179
+ const parsed = yaml.load(raw);
180
+ if (!parsed || typeof parsed !== "object") {
181
+ return {};
182
+ }
183
+ const obj = parsed;
184
+ const policy = {};
185
+ const age = obj.minimumReleaseAge;
186
+ if (typeof age === "number" && Number.isFinite(age)) {
187
+ policy.minimumReleaseAge = age;
188
+ }
189
+ const exclude = obj.minimumReleaseAgeExclude;
190
+ if (Array.isArray(exclude)) {
191
+ const cleaned = exclude.filter(
192
+ (entry) => typeof entry === "string" && entry.length > 0
193
+ );
194
+ if (cleaned.length > 0) {
195
+ policy.minimumReleaseAgeExclude = cleaned;
196
+ }
197
+ }
198
+ return policy;
199
+ };
200
+ var renderNpmrcLines = (policy) => {
201
+ const lines = [];
202
+ if (typeof policy.minimumReleaseAge === "number") {
203
+ lines.push(`minimum-release-age=${policy.minimumReleaseAge}`);
204
+ }
205
+ const exclude = policy.minimumReleaseAgeExclude ?? [];
206
+ if (exclude.length > 0) {
207
+ lines.push(`minimum-release-age-exclude=${exclude.join(",")}`);
208
+ }
209
+ return lines;
210
+ };
211
+ var parseNpmrc = (body) => {
212
+ const map = /* @__PURE__ */ new Map();
213
+ for (const rawLine of body.split(/\r?\n/)) {
214
+ const line = rawLine.trim();
215
+ if (line.length === 0 || line.startsWith("#")) {
216
+ continue;
217
+ }
218
+ const eq = line.indexOf("=");
219
+ if (eq < 0) {
220
+ continue;
221
+ }
222
+ const key = line.slice(0, eq).trim();
223
+ const value = line.slice(eq + 1).trim();
224
+ if (key.length > 0) {
225
+ map.set(key, value);
226
+ }
227
+ }
228
+ return map;
229
+ };
230
+ var mergeNpmrc = (existing, ourLines) => {
231
+ if (ourLines.length === 0) {
232
+ return existing ?? "";
233
+ }
234
+ const ourMap = /* @__PURE__ */ new Map();
235
+ for (const line of ourLines) {
236
+ const eq = line.indexOf("=");
237
+ if (eq < 0) {
238
+ continue;
239
+ }
240
+ ourMap.set(line.slice(0, eq).trim(), line.slice(eq + 1).trim());
241
+ }
242
+ const existingMap = parseNpmrc(existing ?? "");
243
+ for (const [key, value] of ourMap) {
244
+ existingMap.set(key, value);
245
+ }
246
+ const orderedKeys = [];
247
+ const seen = /* @__PURE__ */ new Set();
248
+ for (const rawLine of (existing ?? "").split(/\r?\n/)) {
249
+ const line = rawLine.trim();
250
+ if (line.length === 0 || line.startsWith("#")) {
251
+ continue;
252
+ }
253
+ const eq = line.indexOf("=");
254
+ if (eq < 0) {
255
+ continue;
256
+ }
257
+ const key = line.slice(0, eq).trim();
258
+ if (key.length > 0 && existingMap.has(key) && !seen.has(key)) {
259
+ orderedKeys.push(key);
260
+ seen.add(key);
261
+ }
262
+ }
263
+ for (const key of ourMap.keys()) {
264
+ if (!seen.has(key)) {
265
+ orderedKeys.push(key);
266
+ seen.add(key);
267
+ }
268
+ }
269
+ const body = orderedKeys.map((key) => `${key}=${existingMap.get(key)}`).join("\n");
270
+ return body.length === 0 ? "" : `${body}
271
+ `;
272
+ };
273
+
274
+ // src/lambda/pnpm-workspace-nodejs-function.ts
275
+ var mirrorPnpmWorkspacePolicy = (params) => {
276
+ const { entry, workspaceSearchFrom } = params;
277
+ if (!fs2.existsSync(entry)) {
278
+ return { skippedReason: "missing-entry" };
279
+ }
280
+ const entryDir = path2.dirname(path2.resolve(entry));
281
+ const searchFrom = workspaceSearchFrom ? path2.resolve(workspaceSearchFrom) : entryDir;
282
+ const workspaceFile = findPnpmWorkspaceFile(searchFrom);
283
+ if (!workspaceFile) {
284
+ return { skippedReason: "missing-workspace-file" };
285
+ }
286
+ const policy = readPnpmWorkspacePolicy(workspaceFile);
287
+ const lines = renderNpmrcLines(policy);
288
+ if (lines.length === 0) {
289
+ return { skippedReason: "empty-policy" };
290
+ }
291
+ const npmrcPath = path2.join(entryDir, ".npmrc");
292
+ const existing = fs2.existsSync(npmrcPath) ? fs2.readFileSync(npmrcPath, "utf8") : void 0;
293
+ const merged = mergeNpmrc(existing, lines);
294
+ if (merged === existing) {
295
+ return { npmrcPath, skippedReason: "no-change" };
296
+ }
297
+ fs2.writeFileSync(npmrcPath, merged);
298
+ return { npmrcPath };
299
+ };
300
+ var PnpmWorkspaceNodejsFunction = class extends NodejsFunction {
301
+ constructor(scope, id, props) {
302
+ if (!props.disablePnpmPolicyMirror && props.entry) {
303
+ mirrorPnpmWorkspacePolicy({
304
+ entry: props.entry,
305
+ workspaceSearchFrom: props.workspaceSearchFrom
306
+ });
307
+ }
308
+ const { disablePnpmPolicyMirror, workspaceSearchFrom, ...rest } = props;
309
+ void disablePnpmPolicyMirror;
310
+ void workspaceSearchFrom;
311
+ super(scope, id, rest);
312
+ }
313
+ };
314
+
149
315
  // src/s3/private-bucket.ts
150
316
  import { RemovalPolicy } from "aws-cdk-lib";
151
317
  import {
@@ -208,8 +374,8 @@ var StaticContent = class extends Construct {
208
374
  };
209
375
 
210
376
  // src/static-hosting/static-hosting.ts
211
- import * as fs from "fs";
212
- import * as path from "path";
377
+ import * as fs3 from "fs";
378
+ import * as path3 from "path";
213
379
  import { Duration } from "aws-cdk-lib";
214
380
  import {
215
381
  Certificate,
@@ -230,7 +396,7 @@ import {
230
396
  } from "aws-cdk-lib/aws-cloudfront";
231
397
  import { S3BucketOrigin } from "aws-cdk-lib/aws-cloudfront-origins";
232
398
  import { Runtime } from "aws-cdk-lib/aws-lambda";
233
- import { NodejsFunction } from "aws-cdk-lib/aws-lambda-nodejs";
399
+ import { NodejsFunction as NodejsFunction2 } from "aws-cdk-lib/aws-lambda-nodejs";
234
400
  import { LogGroup, RetentionDays } from "aws-cdk-lib/aws-logs";
235
401
  import {
236
402
  ARecord,
@@ -280,16 +446,16 @@ var StaticHosting = class extends Construct2 {
280
446
  })
281
447
  });
282
448
  }
283
- const handlerJs = path.join(
449
+ const handlerJs = path3.join(
284
450
  __dirname,
285
451
  "static-hosting.viewer-request-handler.js"
286
452
  );
287
- const handlerTs = path.join(
453
+ const handlerTs = path3.join(
288
454
  __dirname,
289
455
  "static-hosting.viewer-request-handler.ts"
290
456
  );
291
- const handlerEntry = fs.existsSync(handlerJs) ? handlerJs : handlerTs;
292
- const handler = new NodejsFunction(this, "viewer-request-handler", {
457
+ const handlerEntry = fs3.existsSync(handlerJs) ? handlerJs : handlerTs;
458
+ const handler = new NodejsFunction2(this, "viewer-request-handler", {
293
459
  entry: handlerEntry,
294
460
  handler: hostingMode === "static" ? "staticHandler" : "spaHandler",
295
461
  memorySize: 128,
@@ -370,8 +536,15 @@ var StaticHosting = class extends Construct2 {
370
536
  }
371
537
  };
372
538
  export {
539
+ PnpmWorkspaceNodejsFunction,
373
540
  PrivateBucket,
374
541
  StaticContent,
375
- StaticHosting
542
+ StaticHosting,
543
+ findPnpmWorkspaceFile,
544
+ mergeNpmrc,
545
+ mirrorPnpmWorkspacePolicy,
546
+ parseNpmrc,
547
+ readPnpmWorkspacePolicy,
548
+ renderNpmrcLines
376
549
  };
377
550
  //# sourceMappingURL=index.mjs.map
package/lib/index.mjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../../utils/src/aws/aws-types.ts","../../utils/src/git/git-utils.ts","../../utils/src/string/string-utils.ts","../../utils/src/index.ts","../src/s3/private-bucket.ts","../src/static-hosting/static-content.ts","../src/static-hosting/static-hosting.ts"],"sourcesContent":["/**\n * Stage Types\n *\n * What stage of deployment is this? Dev, staging, or prod?\n */\nexport const AWS_STAGE_TYPE = {\n /**\n * Development environment, typically used for testing and development.\n */\n DEV: \"dev\",\n\n /**\n * Staging environment, used for pre-production testing.\n */\n STAGE: \"stage\",\n\n /**\n * Production environment, used for live deployments.\n */\n PROD: \"prod\",\n} as const;\n\n/**\n * Above const as a type.\n */\nexport type AwsStageType = (typeof AWS_STAGE_TYPE)[keyof typeof AWS_STAGE_TYPE];\n\n/**\n * Deployment target role: whether an (account, region) is the primary or\n * secondary deployment target (e.g. primary vs replica region).\n */\nexport const DEPLOYMENT_TARGET_ROLE = {\n /**\n * Account and region that represents the primary region for this service.\n * For example, the base DynamoDB Region for global tables.\n */\n PRIMARY: \"primary\",\n /**\n * Account and region that represents a secondary region for this service.\n * For example, a replica region for a global DynamoDB table.\n */\n SECONDARY: \"secondary\",\n} as const;\n\n/**\n * Type for deployment target role values.\n */\nexport type DeploymentTargetRoleType =\n (typeof DEPLOYMENT_TARGET_ROLE)[keyof typeof DEPLOYMENT_TARGET_ROLE];\n\n/**\n * Environment types (primary/secondary).\n *\n * @deprecated Use {@link DEPLOYMENT_TARGET_ROLE} instead. This constant is maintained for backward compatibility.\n */\nexport const AWS_ENVIRONMENT_TYPE = DEPLOYMENT_TARGET_ROLE;\n\n/**\n * Type for environment type values.\n *\n * @deprecated Use {@link DeploymentTargetRoleType} instead. This type is maintained for backward compatibility.\n */\nexport type AwsEnvironmentType = DeploymentTargetRoleType;\n","import { execSync } from \"node:child_process\";\n\n/**\n * Returns the current full git branch name\n *\n * ie: feature/1234 returns feature/1234\n *\n */\nexport const findGitBranch = (): string => {\n return execSync(\"git rev-parse --abbrev-ref HEAD\")\n .toString(\"utf8\")\n .replace(/[\\n\\r\\s]+$/, \"\");\n};\n\nexport const findGitRepoName = (): string => {\n /**\n * When running in github actions this will be populated.\n */\n if (process.env.GITHUB_REPOSITORY) {\n return process.env.GITHUB_REPOSITORY;\n }\n\n /**\n * locally, we need to extract the repo name from the git config.\n */\n const remote = execSync(\"git config --get remote.origin.url\")\n .toString(\"utf8\")\n .replace(/[\\n\\r\\s]+$/, \"\")\n .trim();\n\n const match = remote.match(/[:\\/]([^/]+\\/[^/]+?)(?:\\.git)?$/);\n const repoName = match ? match[1] : \"error-repo-name\";\n\n return repoName;\n};\n","import * as crypto from \"node:crypto\";\n\n/**\n *\n * @param inString - string to hash\n * @param trimLength - trim to this length (defaults to 999 chars)\n * @returns Hex-encoded sha256 digest, truncated to `trimLength` characters.\n */\nexport const hashString = (inString: string, trimLength: number = 999) => {\n return crypto\n .createHash(\"sha256\")\n .update(inString)\n .digest(\"hex\")\n .substring(0, trimLength);\n};\n\n/**\n *\n * @param inputString - string to truncate\n * @param maxLength - max length of this string\n * @returns trimmed string\n */\nexport const trimStringLength = (inputString: string, maxLength: number) => {\n return inputString.length < maxLength\n ? inputString\n : inputString.substring(0, maxLength);\n};\n","export * from \"./aws/aws-types\";\nexport * from \"./git/git-utils\";\nexport * from \"./string/string-utils\";\n","import { RemovalPolicy } from \"aws-cdk-lib\";\nimport {\n BlockPublicAccess,\n Bucket,\n BucketProps,\n ObjectOwnership,\n} from \"aws-cdk-lib/aws-s3\";\nimport { Construct } from \"constructs\";\n\nexport interface PrivateBucketProps extends BucketProps {}\n\nexport class PrivateBucket extends Bucket {\n constructor(scope: Construct, id: string, props: PrivateBucketProps = {}) {\n const defaultProps = {\n removalPolicy: props.removalPolicy ?? RemovalPolicy.RETAIN,\n autoDeleteObjects: props.removalPolicy === RemovalPolicy.DESTROY,\n };\n\n const requiredProps = {\n publicReadAccess: false,\n blockPublicAccess: BlockPublicAccess.BLOCK_ALL,\n enforceSSL: true,\n objectOwnership: ObjectOwnership.BUCKET_OWNER_ENFORCED,\n };\n\n super(scope, id, { ...defaultProps, ...props, ...requiredProps });\n }\n}\n","// eslint-disable-next-line import/no-extraneous-dependencies\nimport { findGitBranch } from \"@codedrifters/utils\";\nimport { Bucket } from \"aws-cdk-lib/aws-s3\";\nimport { BucketDeployment, Source } from \"aws-cdk-lib/aws-s3-deployment\";\nimport { StringParameter } from \"aws-cdk-lib/aws-ssm\";\nimport { paramCase } from \"change-case\";\nimport { Construct } from \"constructs\";\n\n/*******************************************************************************\n *\n * STATIC CONTENT UPLOADER\n *\n * This construct uploads a directory of content from a local location into S3.\n *\n * To support PR and branch specific builds, each S3 bucket can store content\n * for multiple domains and builds, using the following format:\n *\n * S3-bucket/domain/*\n *\n * A bucket used to store content for stage.openhi.org might have the\n * following directory structure (all in the same bucket).\n *\n * `/stage.openhi.org/*` serves content to stage.openhi.org\n * `/feature-7.stage.openhi.org/*` serves content to feature-7.stage.openhi.org\n * `/pr-123.stage.openhi.org/*` serves content to pr-123.stage.openhi.org\n *\n ******************************************************************************/\n\nexport interface StaticContentProps {\n /**\n * Parameter name to use when storing the static hosting bucket's ARN.\n * This is needed in other later steps when deploying hosted content to S3.\n */\n readonly bucketArnParamName?: string;\n\n /**\n * Absolute path to directory containing content for the website.\n */\n readonly contentSourceDirectory: string;\n\n /**\n * Directory to place content into. Should start with a slash.\n * Example: '/widget'\n */\n readonly contentDestinationDirectory: string;\n\n /**\n * The sub domain prefix (ie: images)\n *\n * @default git branch name\n */\n readonly subDomain?: string;\n\n /**\n * The full domain (ie: staging.codedrifters.com)\n */\n readonly fullDomain: string;\n}\n\nexport class StaticContent extends Construct {\n constructor(scope: Construct, id: string, props: StaticContentProps) {\n super(scope, id);\n\n /***************************************************************************\n *\n * Initial Setup\n *\n * Set some defaults, build domain information.\n *\n **************************************************************************/\n\n const {\n bucketArnParamName,\n contentSourceDirectory,\n contentDestinationDirectory,\n subDomain,\n fullDomain,\n } = {\n bucketArnParamName: \"/STATIC_WEBSITE/BUCKET_ARN\",\n subDomain: findGitBranch(),\n ...props,\n };\n\n /***************************************************************************\n *\n * Import and build some values from Param Store during deployment.\n *\n **************************************************************************/\n\n const keyPrefix = [paramCase(subDomain), fullDomain].join(\".\");\n\n const bucketArn = StringParameter.valueForStringParameter(\n this,\n bucketArnParamName,\n );\n const bucket = Bucket.fromBucketArn(this, \"bucket\", bucketArn);\n\n /***************************************************************************\n *\n * Gather the sources we'll be deploying. We need to have an empty source\n * for tests since it will change all the time and bork up the test\n * snapshots if we don't.\n *\n **************************************************************************/\n\n const isTestEnv = process.env.VITEST === \"true\";\n const sources = isTestEnv ? [] : [Source.asset(contentSourceDirectory)];\n\n new BucketDeployment(this, \"deploy\", {\n sources,\n destinationBucket: bucket,\n retainOnDelete: false,\n destinationKeyPrefix: `${keyPrefix}${contentDestinationDirectory}`,\n });\n }\n}\n","import * as fs from \"fs\";\nimport * as path from \"path\";\nimport { Duration, StackProps } from \"aws-cdk-lib\";\nimport {\n Certificate,\n CertificateValidation,\n} from \"aws-cdk-lib/aws-certificatemanager\";\nimport {\n AccessLevel,\n AllowedMethods,\n CacheCookieBehavior,\n CacheHeaderBehavior,\n CachePolicy,\n CacheQueryStringBehavior,\n Distribution,\n LambdaEdgeEventType,\n S3OriginAccessControl,\n Signing,\n ViewerProtocolPolicy,\n} from \"aws-cdk-lib/aws-cloudfront\";\nimport { S3BucketOrigin } from \"aws-cdk-lib/aws-cloudfront-origins\";\nimport { Runtime } from \"aws-cdk-lib/aws-lambda\";\nimport { NodejsFunction } from \"aws-cdk-lib/aws-lambda-nodejs\";\nimport { LogGroup, RetentionDays } from \"aws-cdk-lib/aws-logs\";\nimport {\n ARecord,\n HostedZone,\n HostedZoneAttributes,\n IHostedZone,\n RecordTarget,\n} from \"aws-cdk-lib/aws-route53\";\nimport { CloudFrontTarget } from \"aws-cdk-lib/aws-route53-targets\";\nimport { StringParameter } from \"aws-cdk-lib/aws-ssm\";\nimport { Construct } from \"constructs\";\nimport type { HostingMode } from \"./static-hosting.viewer-request-handler\";\nimport { PrivateBucket, PrivateBucketProps } from \"../s3/private-bucket\";\n\nexport interface StaticDomainProps {\n /**\n * The base domain (ie: codedrifters.com)\n */\n readonly baseDomain: string;\n\n /**\n * Hosted zone ID for the base domain.\n */\n readonly hostedZoneAttributes: HostedZoneAttributes;\n}\n\nexport interface StaticHostingProps extends StackProps {\n /**\n * Short description used in various places for traceability.\n */\n readonly description?: string;\n\n /**\n * Values used to connect a domain name to the cloudfront distribution. If not\n * supplied, cloudfront doesn't use a custom domain.\n */\n readonly staticDomainProps?: StaticDomainProps;\n\n /**\n * Parameter name to use when storing the static hosting bucket's ARN.\n * This is needed in other later steps when deploying hosted content to S3.\n */\n readonly bucketArnParamName?: string;\n\n /**\n * Parameter name to use when storing the CloudFront Distribution Domain Name.\n */\n readonly distributionDomainParamName?: string;\n\n /**\n * Parameter name to use when storing the CloudFront Distribution ID.\n */\n readonly distributionIDParamName?: string;\n\n /**\n * Props to pass to the private S3 bucket.\n */\n readonly privateBucketProps?: PrivateBucketProps;\n\n /**\n * Selects how path-like URIs are rewritten by the viewer-request\n * `Lambda@Edge` handler.\n *\n * - `spa` (default): path-like URIs rewrite to `/index.html` so a\n * single-page app can serve its one root index and let the client-side\n * router handle the path.\n * - `static`: path-like URIs append `/index.html` (e.g. `/docs` →\n * `/docs/index.html`) so multi-page static sites can serve distinct\n * HTML per path.\n *\n * Multi-tenant domain-folder prepending runs after the rewrite in both\n * modes and is unaffected by this prop.\n *\n * @default \"spa\"\n */\n readonly hostingMode?: HostingMode;\n}\n\nexport class StaticHosting extends Construct {\n /**\n * Full domain name used as basis for hosting.\n */\n public readonly fullDomain: string;\n\n constructor(scope: Construct, id: string, props: StaticHostingProps = {}) {\n super(scope, id);\n\n /***************************************************************************\n *\n * Initial Setup\n *\n * Set some defaults, build domain information.\n *\n **************************************************************************/\n\n const {\n bucketArnParamName,\n distributionDomainParamName,\n distributionIDParamName,\n staticDomainProps,\n privateBucketProps,\n hostingMode,\n } = {\n bucketArnParamName: \"/STATIC_WEBSITE/BUCKET_ARN\",\n distributionDomainParamName: \"/STATIC_WEBSITE/DISTRIBUTION_DOMAIN\",\n distributionIDParamName: \"/STATIC_WEBSITE/DISTRIBUTION_ID\",\n hostingMode: \"spa\" as HostingMode,\n ...props,\n };\n\n const { baseDomain, hostedZoneAttributes } = staticDomainProps ?? {};\n\n /***************************************************************************\n *\n * PRIVATE BUCKET\n *\n * A bucket to store the files within.\n * Save ARN for later deploys.\n *\n **************************************************************************/\n\n const bucket = new PrivateBucket(\n this,\n \"static-hosting-bucket\",\n privateBucketProps,\n );\n\n /***************************************************************************\n *\n * DNS & Wildcard Certificate\n *\n * If a zone Id as passed in, find the hosted zone and create a wildcard\n * certificate for the domain.\n *\n **************************************************************************/\n\n let zone: IHostedZone | undefined;\n let certificate: Certificate | undefined;\n\n if (hostedZoneAttributes && baseDomain) {\n zone = HostedZone.fromHostedZoneAttributes(\n this,\n \"zone\",\n hostedZoneAttributes,\n );\n certificate = new Certificate(this, \"wildcard-certificate\", {\n domainName: `*.${baseDomain}`,\n subjectAlternativeNames: [baseDomain],\n validation: CertificateValidation.fromDnsMultiZone({\n [`*.${baseDomain}`]: zone,\n [baseDomain]: zone,\n }),\n });\n }\n\n /******************************************************************************\n *\n * `LAMBDA@EDGE` FUNCTION\n *\n * This handles rewriting the path from domain name.\n *\n *****************************************************************************/\n\n // Explicit entry required: when omitted, NodejsFunction infers the path from the\n // call site (the built lib/index.js), so it looks for index.viewer-request-handler.js\n // in the package. That file is only emitted if we add it as a separate tsup entry.\n // Use .js when present (built package); fall back to .ts for tests running from source.\n const handlerJs = path.join(\n __dirname,\n \"static-hosting.viewer-request-handler.js\",\n );\n const handlerTs = path.join(\n __dirname,\n \"static-hosting.viewer-request-handler.ts\",\n );\n const handlerEntry = fs.existsSync(handlerJs) ? handlerJs : handlerTs;\n\n const handler = new NodejsFunction(this, \"viewer-request-handler\", {\n entry: handlerEntry,\n handler: hostingMode === \"static\" ? \"staticHandler\" : \"spaHandler\",\n memorySize: 128,\n runtime: Runtime.NODEJS_24_X,\n logGroup: new LogGroup(this, \"viewer-request-handler-log-group\", {\n retention: RetentionDays.ONE_MONTH,\n }),\n });\n\n /******************************************************************************\n *\n * CLOUDFRONT CONFIG\n *\n * Setup a CloudFront Distribution for the bucket.\n *\n *****************************************************************************/\n\n const cachePolicy = new CachePolicy(this, \"cloudfront-policy\", {\n comment: \"Relatively conservative TTL policy.\",\n maxTtl: Duration.seconds(300),\n minTtl: Duration.seconds(0),\n defaultTtl: Duration.seconds(60),\n headerBehavior: CacheHeaderBehavior.none(),\n queryStringBehavior: CacheQueryStringBehavior.none(),\n cookieBehavior: CacheCookieBehavior.none(),\n enableAcceptEncodingGzip: true,\n enableAcceptEncodingBrotli: true,\n });\n\n const oac = new S3OriginAccessControl(this, \"MyOAC\", {\n signing: Signing.SIGV4_NO_OVERRIDE,\n });\n const origin = S3BucketOrigin.withOriginAccessControl(bucket, {\n originAccessControl: oac,\n originAccessLevels: [AccessLevel.READ],\n });\n\n const distribution = new Distribution(this, \"cloudfront-distribution\", {\n comment: `Distribution for ${props.description ?? id}`,\n\n /**\n * Only if domain was supplied\n */\n ...(certificate && baseDomain\n ? {\n certificate,\n domainNames: [baseDomain, `*.${baseDomain}`],\n }\n : {}),\n\n defaultBehavior: {\n origin,\n viewerProtocolPolicy: ViewerProtocolPolicy.REDIRECT_TO_HTTPS,\n cachePolicy,\n allowedMethods: AllowedMethods.ALLOW_GET_HEAD_OPTIONS,\n edgeLambdas: [\n {\n functionVersion: handler.currentVersion,\n eventType: LambdaEdgeEventType.VIEWER_REQUEST,\n },\n ],\n },\n defaultRootObject: \"index.html\",\n });\n\n /**\n * We finally have enough information to set the full domain.\n */\n this.fullDomain =\n certificate && baseDomain ? baseDomain : distribution.domainName;\n\n /***************************************************************************\n *\n * DNS ENTRY\n *\n * Link cloudfront to both the root fulldomain and all possible subdomains.\n *\n **************************************************************************/\n\n if (zone) {\n new ARecord(this, \"root-dns-entry\", {\n zone,\n recordName: baseDomain ? baseDomain : \"\",\n target: RecordTarget.fromAlias(new CloudFrontTarget(distribution)),\n });\n\n new ARecord(this, \"wc-dns-entry\", {\n zone,\n recordName: baseDomain ? `*.${baseDomain}` : \"*\",\n target: RecordTarget.fromAlias(new CloudFrontTarget(distribution)),\n });\n }\n\n /***************************************************************************\n *\n * EXPORTS\n *\n * Used by content uploader later.\n *\n **************************************************************************/\n\n new StringParameter(this, \"dist-domain\", {\n description: `GENERATED DO NOT CHANGE - CloudFront Distribution Details (${props.description ?? id}).`,\n parameterName: distributionDomainParamName,\n stringValue: distribution.domainName,\n });\n\n new StringParameter(this, \"dist-id\", {\n description: `GENERATED DO NOT CHANGE - CloudFront Distribution Details (${props.description ?? id}).`,\n parameterName: distributionIDParamName,\n stringValue: distribution.distributionId,\n });\n\n new StringParameter(this, \"bucket-arn\", {\n description: `GENERATED DO NOT CHANGE - S3 Bucket ARN for (${props.description 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YAAY,KAAK,UAAU,EAAE;AAAA,MAC7C,IACA,CAAC;AAAA,MAEL,iBAAiB;AAAA,QACf;AAAA,QACA,sBAAsB,qBAAqB;AAAA,QAC3C;AAAA,QACA,gBAAgB,eAAe;AAAA,QAC/B,aAAa;AAAA,UACX;AAAA,YACE,iBAAiB,QAAQ;AAAA,YACzB,WAAW,oBAAoB;AAAA,UACjC;AAAA,QACF;AAAA,MACF;AAAA,MACA,mBAAmB;AAAA,IACrB,CAAC;AAKD,SAAK,aACH,eAAe,aAAa,aAAa,aAAa;AAUxD,QAAI,MAAM;AACR,UAAI,QAAQ,MAAM,kBAAkB;AAAA,QAClC;AAAA,QACA,YAAY,aAAa,aAAa;AAAA,QACtC,QAAQ,aAAa,UAAU,IAAI,iBAAiB,YAAY,CAAC;AAAA,MACnE,CAAC;AAED,UAAI,QAAQ,MAAM,gBAAgB;AAAA,QAChC;AAAA,QACA,YAAY,aAAa,KAAK,UAAU,KAAK;AAAA,QAC7C,QAAQ,aAAa,UAAU,IAAI,iBAAiB,YAAY,CAAC;AAAA,MACnE,CAAC;AAAA,IACH;AAUA,QAAIC,iBAAgB,MAAM,eAAe;AAAA,MACvC,aAAa,8DAA8D,MAAM,eAAe,EAAE;AAAA,MAClG,eAAe;AAAA,MACf,aAAa,aAAa;AAAA,IAC5B,CAAC;AAED,QAAIA,iBAAgB,MAAM,WAAW;AAAA,MACnC,aAAa,8DAA8D,MAAM,eAAe,EAAE;AAAA,MAClG,eAAe;AAAA,MACf,aAAa,aAAa;AAAA,IAC5B,CAAC;AAED,QAAIA,iBAAgB,MAAM,cAAc;AAAA,MACtC,aAAa,gDAAgD,MAAM,eAAe,EAAE;AAAA,MACpF,eAAe;AAAA,MACf,aAAa,OAAO;AAAA,IACtB,CAAC;AAAA,EACH;AACF;","names":["findGitBranch","Bucket","StringParameter","Construct","Construct","StringParameter"]}
1
+ {"version":3,"sources":["../../utils/src/aws/aws-types.ts","../../utils/src/git/git-utils.ts","../../utils/src/string/string-utils.ts","../../utils/src/index.ts","../src/lambda/pnpm-workspace-nodejs-function.ts","../src/lambda/pnpm-workspace-parser.ts","../src/s3/private-bucket.ts","../src/static-hosting/static-content.ts","../src/static-hosting/static-hosting.ts"],"sourcesContent":["/**\n * Stage Types\n *\n * What stage of deployment is this? Dev, staging, or prod?\n */\nexport const AWS_STAGE_TYPE = {\n /**\n * Development environment, typically used for testing and development.\n */\n DEV: \"dev\",\n\n /**\n * Staging environment, used for pre-production testing.\n */\n STAGE: \"stage\",\n\n /**\n * Production environment, used for live deployments.\n */\n PROD: \"prod\",\n} as const;\n\n/**\n * Above const as a type.\n */\nexport type AwsStageType = (typeof AWS_STAGE_TYPE)[keyof typeof AWS_STAGE_TYPE];\n\n/**\n * Deployment target role: whether an (account, region) is the primary or\n * secondary deployment target (e.g. primary vs replica region).\n */\nexport const DEPLOYMENT_TARGET_ROLE = {\n /**\n * Account and region that represents the primary region for this service.\n * For example, the base DynamoDB Region for global tables.\n */\n PRIMARY: \"primary\",\n /**\n * Account and region that represents a secondary region for this service.\n * For example, a replica region for a global DynamoDB table.\n */\n SECONDARY: \"secondary\",\n} as const;\n\n/**\n * Type for deployment target role values.\n */\nexport type DeploymentTargetRoleType =\n (typeof DEPLOYMENT_TARGET_ROLE)[keyof typeof DEPLOYMENT_TARGET_ROLE];\n\n/**\n * Environment types (primary/secondary).\n *\n * @deprecated Use {@link DEPLOYMENT_TARGET_ROLE} instead. This constant is maintained for backward compatibility.\n */\nexport const AWS_ENVIRONMENT_TYPE = DEPLOYMENT_TARGET_ROLE;\n\n/**\n * Type for environment type values.\n *\n * @deprecated Use {@link DeploymentTargetRoleType} instead. This type is maintained for backward compatibility.\n */\nexport type AwsEnvironmentType = DeploymentTargetRoleType;\n","import { execSync } from \"node:child_process\";\n\n/**\n * Returns the current full git branch name\n *\n * ie: feature/1234 returns feature/1234\n *\n */\nexport const findGitBranch = (): string => {\n return execSync(\"git rev-parse --abbrev-ref HEAD\")\n .toString(\"utf8\")\n .replace(/[\\n\\r\\s]+$/, \"\");\n};\n\nexport const findGitRepoName = (): string => {\n /**\n * When running in github actions this will be populated.\n */\n if (process.env.GITHUB_REPOSITORY) {\n return process.env.GITHUB_REPOSITORY;\n }\n\n /**\n * locally, we need to extract the repo name from the git config.\n */\n const remote = execSync(\"git config --get remote.origin.url\")\n .toString(\"utf8\")\n .replace(/[\\n\\r\\s]+$/, \"\")\n .trim();\n\n const match = remote.match(/[:\\/]([^/]+\\/[^/]+?)(?:\\.git)?$/);\n const repoName = match ? match[1] : \"error-repo-name\";\n\n return repoName;\n};\n","import * as crypto from \"node:crypto\";\n\n/**\n *\n * @param inString - string to hash\n * @param trimLength - trim to this length (defaults to 999 chars)\n * @returns Hex-encoded sha256 digest, truncated to `trimLength` characters.\n */\nexport const hashString = (inString: string, trimLength: number = 999) => {\n return crypto\n .createHash(\"sha256\")\n .update(inString)\n .digest(\"hex\")\n .substring(0, trimLength);\n};\n\n/**\n *\n * @param inputString - string to truncate\n * @param maxLength - max length of this string\n * @returns trimmed string\n */\nexport const trimStringLength = (inputString: string, maxLength: number) => {\n return inputString.length < maxLength\n ? inputString\n : inputString.substring(0, maxLength);\n};\n","export * from \"./aws/aws-types\";\nexport * from \"./git/git-utils\";\nexport * from \"./string/string-utils\";\n","import * as fs from \"node:fs\";\nimport * as path from \"node:path\";\nimport {\n NodejsFunction,\n NodejsFunctionProps,\n} from \"aws-cdk-lib/aws-lambda-nodejs\";\nimport { Construct } from \"constructs\";\nimport {\n findPnpmWorkspaceFile,\n mergeNpmrc,\n readPnpmWorkspacePolicy,\n renderNpmrcLines,\n} from \"./pnpm-workspace-parser\";\n\n/**\n * Props for `PnpmWorkspaceNodejsFunction`. Extends\n * `NodejsFunctionProps` so the wrapper is a drop-in for any existing\n * `NodejsFunction` call site.\n */\nexport interface PnpmWorkspaceNodejsFunctionProps extends NodejsFunctionProps {\n /**\n * Directory to begin the upward search for `pnpm-workspace.yaml`.\n * Defaults to the directory of the resolved entry path.\n */\n readonly workspaceSearchFrom?: string;\n\n /**\n * Skip the policy-mirror step entirely. Useful for tests or when the\n * caller wants the pure `NodejsFunction` behavior.\n *\n * @default false\n */\n readonly disablePnpmPolicyMirror?: boolean;\n}\n\n/**\n * Result of `mirrorPnpmWorkspacePolicy` — describes what the policy\n * mirror did for one entry.\n */\nexport interface MirrorPnpmWorkspacePolicyResult {\n /** Resolved `.npmrc` path if a write happened, otherwise undefined. */\n readonly npmrcPath?: string;\n /** Reason the mirror was a no-op, if it was. */\n readonly skippedReason?:\n | \"missing-entry\"\n | \"missing-workspace-file\"\n | \"empty-policy\"\n | \"no-change\";\n}\n\n/**\n * Mirror the workspace pnpm policy into an `.npmrc` adjacent to the\n * Lambda entry. Pure side-effect helper used by\n * `PnpmWorkspaceNodejsFunction`; exported so consumers can drive it\n * from other call sites if desired.\n */\nexport const mirrorPnpmWorkspacePolicy = (params: {\n readonly entry: string;\n readonly workspaceSearchFrom?: string;\n}): MirrorPnpmWorkspacePolicyResult => {\n const { entry, workspaceSearchFrom } = params;\n if (!fs.existsSync(entry)) {\n return { skippedReason: \"missing-entry\" };\n }\n\n const entryDir = path.dirname(path.resolve(entry));\n const searchFrom = workspaceSearchFrom\n ? path.resolve(workspaceSearchFrom)\n : entryDir;\n\n const workspaceFile = findPnpmWorkspaceFile(searchFrom);\n if (!workspaceFile) {\n return { skippedReason: \"missing-workspace-file\" };\n }\n\n const policy = readPnpmWorkspacePolicy(workspaceFile);\n const lines = renderNpmrcLines(policy);\n if (lines.length === 0) {\n return { skippedReason: \"empty-policy\" };\n }\n\n const npmrcPath = path.join(entryDir, \".npmrc\");\n const existing = fs.existsSync(npmrcPath)\n ? fs.readFileSync(npmrcPath, \"utf8\")\n : undefined;\n const merged = mergeNpmrc(existing, lines);\n\n if (merged === existing) {\n return { npmrcPath, skippedReason: \"no-change\" };\n }\n\n fs.writeFileSync(npmrcPath, merged);\n return { npmrcPath };\n};\n\n/**\n * A `NodejsFunction` wrapper that mirrors the workspace's pnpm policy\n * (currently `minimumReleaseAge` and `minimumReleaseAgeExclude`) into\n * an `.npmrc` adjacent to the Lambda entry before bundling.\n *\n * CDK's bundler runs `pnpm install` in an isolated temp directory\n * outside the workspace, which means `pnpm-workspace.yaml` settings\n * do not apply there. Mirroring the policy into an entry-adjacent\n * `.npmrc` (which CDK copies into the bundling input directory)\n * lets the inner `pnpm install` honour the same freshness rules.\n *\n * See the `pnpm-workspace-nodejs-function` documentation page for\n * full details on what gets mirrored, merge behaviour against an\n * existing `.npmrc`, and when to disable the mirror.\n */\nexport class PnpmWorkspaceNodejsFunction extends NodejsFunction {\n constructor(\n scope: Construct,\n id: string,\n props: PnpmWorkspaceNodejsFunctionProps,\n ) {\n if (!props.disablePnpmPolicyMirror && props.entry) {\n mirrorPnpmWorkspacePolicy({\n entry: props.entry,\n workspaceSearchFrom: props.workspaceSearchFrom,\n });\n }\n\n const { disablePnpmPolicyMirror, workspaceSearchFrom, ...rest } = props;\n void disablePnpmPolicyMirror;\n void workspaceSearchFrom;\n super(scope, id, rest);\n }\n}\n","import * as fs from \"node:fs\";\nimport * as path from \"node:path\";\nimport * as yaml from \"js-yaml\";\n\n/**\n * Subset of `pnpm-workspace.yaml` fields that map to `.npmrc` keys\n * pnpm honours when running install in a non-workspace directory.\n */\nexport interface PnpmWorkspacePolicy {\n /** `minimumReleaseAge` (minutes) — equivalent to `.npmrc` `minimum-release-age`. */\n readonly minimumReleaseAge?: number;\n /**\n * `minimumReleaseAgeExclude` — equivalent to `.npmrc`\n * `minimum-release-age-exclude` (comma-separated when serialised).\n */\n readonly minimumReleaseAgeExclude?: ReadonlyArray<string>;\n}\n\n/**\n * Walk up from `startDir` until a `pnpm-workspace.yaml` file is found\n * and return its absolute path. Returns `undefined` when the filesystem\n * root is reached without finding one.\n */\nexport const findPnpmWorkspaceFile = (startDir: string): string | undefined => {\n let current = path.resolve(startDir);\n while (true) {\n const candidate = path.join(current, \"pnpm-workspace.yaml\");\n if (fs.existsSync(candidate)) {\n return candidate;\n }\n const parent = path.dirname(current);\n if (parent === current) {\n return undefined;\n }\n current = parent;\n }\n};\n\n/**\n * Read the policy subset (`minimumReleaseAge` and\n * `minimumReleaseAgeExclude`) from a `pnpm-workspace.yaml` file.\n *\n * Returns an empty object when the file is missing, unreadable, or\n * contains neither key. Throws when the file is present but YAML\n * parsing fails — the caller is expected to surface a clear error.\n */\nexport const readPnpmWorkspacePolicy = (\n workspaceFile: string,\n): PnpmWorkspacePolicy => {\n if (!fs.existsSync(workspaceFile)) {\n return {};\n }\n\n const raw = fs.readFileSync(workspaceFile, \"utf8\");\n const parsed = yaml.load(raw);\n\n if (!parsed || typeof parsed !== \"object\") {\n return {};\n }\n\n const obj = parsed as Record<string, unknown>;\n const policy: {\n -readonly [K in keyof PnpmWorkspacePolicy]: PnpmWorkspacePolicy[K];\n } = {};\n\n const age = obj.minimumReleaseAge;\n if (typeof age === \"number\" && Number.isFinite(age)) {\n policy.minimumReleaseAge = age;\n }\n\n const exclude = obj.minimumReleaseAgeExclude;\n if (Array.isArray(exclude)) {\n const cleaned = exclude.filter(\n (entry): entry is string => typeof entry === \"string\" && entry.length > 0,\n );\n if (cleaned.length > 0) {\n policy.minimumReleaseAgeExclude = cleaned;\n }\n }\n\n return policy;\n};\n\n/**\n * Render an `.npmrc` body that pnpm will honour when installing in\n * a directory outside the workspace tree. The keys emitted here are\n * the `.npmrc` equivalents of the `pnpm-workspace.yaml` fields in\n * {@link PnpmWorkspacePolicy} — pnpm reads `minimum-release-age` and\n * `minimum-release-age-exclude` from `.npmrc`, not from the workspace\n * file, when the install runs outside the workspace.\n *\n * Returns an empty string when the policy carries no relevant fields.\n */\nexport const renderNpmrcLines = (\n policy: PnpmWorkspacePolicy,\n): ReadonlyArray<string> => {\n const lines: Array<string> = [];\n\n if (typeof policy.minimumReleaseAge === \"number\") {\n lines.push(`minimum-release-age=${policy.minimumReleaseAge}`);\n }\n\n const exclude = policy.minimumReleaseAgeExclude ?? [];\n if (exclude.length > 0) {\n lines.push(`minimum-release-age-exclude=${exclude.join(\",\")}`);\n }\n\n return lines;\n};\n\n/**\n * Parse the body of an existing `.npmrc` file into a map of trimmed\n * key/value pairs. Lines that are blank or start with `#` are dropped.\n * Lines without an `=` are dropped.\n */\nexport const parseNpmrc = (body: string): Map<string, string> => {\n const map = new Map<string, string>();\n for (const rawLine of body.split(/\\r?\\n/)) {\n const line = rawLine.trim();\n if (line.length === 0 || line.startsWith(\"#\")) {\n continue;\n }\n const eq = line.indexOf(\"=\");\n if (eq < 0) {\n continue;\n }\n const key = line.slice(0, eq).trim();\n const value = line.slice(eq + 1).trim();\n if (key.length > 0) {\n map.set(key, value);\n }\n }\n return map;\n};\n\n/**\n * Merge a set of policy-derived `.npmrc` lines into an existing\n * `.npmrc` body. Our keys overwrite matching keys in the existing\n * body; all other keys are preserved. Returns the new `.npmrc` body\n * (always terminated by a trailing newline when non-empty).\n */\nexport const mergeNpmrc = (\n existing: string | undefined,\n ourLines: ReadonlyArray<string>,\n): string => {\n if (ourLines.length === 0) {\n return existing ?? \"\";\n }\n\n const ourMap = new Map<string, string>();\n for (const line of ourLines) {\n const eq = line.indexOf(\"=\");\n if (eq < 0) {\n continue;\n }\n ourMap.set(line.slice(0, eq).trim(), line.slice(eq + 1).trim());\n }\n\n const existingMap = parseNpmrc(existing ?? \"\");\n for (const [key, value] of ourMap) {\n existingMap.set(key, value);\n }\n\n const orderedKeys: Array<string> = [];\n const seen = new Set<string>();\n\n // Preserve the original line order for any pre-existing keys.\n for (const rawLine of (existing ?? \"\").split(/\\r?\\n/)) {\n const line = rawLine.trim();\n if (line.length === 0 || line.startsWith(\"#\")) {\n continue;\n }\n const eq = line.indexOf(\"=\");\n if (eq < 0) {\n continue;\n }\n const key = line.slice(0, eq).trim();\n if (key.length > 0 && existingMap.has(key) && !seen.has(key)) {\n orderedKeys.push(key);\n seen.add(key);\n }\n }\n\n // Append any keys we added that weren't already present.\n for (const key of ourMap.keys()) {\n if (!seen.has(key)) {\n orderedKeys.push(key);\n seen.add(key);\n }\n }\n\n const body = orderedKeys\n .map((key) => `${key}=${existingMap.get(key)}`)\n .join(\"\\n\");\n\n return body.length === 0 ? \"\" : `${body}\\n`;\n};\n","import { RemovalPolicy } from \"aws-cdk-lib\";\nimport {\n BlockPublicAccess,\n Bucket,\n BucketProps,\n ObjectOwnership,\n} from \"aws-cdk-lib/aws-s3\";\nimport { Construct } from \"constructs\";\n\nexport interface PrivateBucketProps extends BucketProps {}\n\nexport class PrivateBucket extends Bucket {\n constructor(scope: Construct, id: string, props: PrivateBucketProps = {}) {\n const defaultProps = {\n removalPolicy: props.removalPolicy ?? RemovalPolicy.RETAIN,\n autoDeleteObjects: props.removalPolicy === RemovalPolicy.DESTROY,\n };\n\n const requiredProps = {\n publicReadAccess: false,\n blockPublicAccess: BlockPublicAccess.BLOCK_ALL,\n enforceSSL: true,\n objectOwnership: ObjectOwnership.BUCKET_OWNER_ENFORCED,\n };\n\n super(scope, id, { ...defaultProps, ...props, ...requiredProps });\n }\n}\n","// eslint-disable-next-line import/no-extraneous-dependencies\nimport { findGitBranch } from \"@codedrifters/utils\";\nimport { Bucket } from \"aws-cdk-lib/aws-s3\";\nimport { BucketDeployment, Source } from \"aws-cdk-lib/aws-s3-deployment\";\nimport { StringParameter } from \"aws-cdk-lib/aws-ssm\";\nimport { paramCase } from \"change-case\";\nimport { Construct } from \"constructs\";\n\n/*******************************************************************************\n *\n * STATIC CONTENT UPLOADER\n *\n * This construct uploads a directory of content from a local location into S3.\n *\n * To support PR and branch specific builds, each S3 bucket can store content\n * for multiple domains and builds, using the following format:\n *\n * S3-bucket/domain/*\n *\n * A bucket used to store content for stage.openhi.org might have the\n * following directory structure (all in the same bucket).\n *\n * `/stage.openhi.org/*` serves content to stage.openhi.org\n * `/feature-7.stage.openhi.org/*` serves content to feature-7.stage.openhi.org\n * `/pr-123.stage.openhi.org/*` serves content to pr-123.stage.openhi.org\n *\n ******************************************************************************/\n\nexport interface StaticContentProps {\n /**\n * Parameter name to use when storing the static hosting bucket's ARN.\n * This is needed in other later steps when deploying hosted content to S3.\n */\n readonly bucketArnParamName?: string;\n\n /**\n * Absolute path to directory containing content for the website.\n */\n readonly contentSourceDirectory: string;\n\n /**\n * Directory to place content into. Should start with a slash.\n * Example: '/widget'\n */\n readonly contentDestinationDirectory: string;\n\n /**\n * The sub domain prefix (ie: images)\n *\n * @default git branch name\n */\n readonly subDomain?: string;\n\n /**\n * The full domain (ie: staging.codedrifters.com)\n */\n readonly fullDomain: string;\n}\n\nexport class StaticContent extends Construct {\n constructor(scope: Construct, id: string, props: StaticContentProps) {\n super(scope, id);\n\n /***************************************************************************\n *\n * Initial Setup\n *\n * Set some defaults, build domain information.\n *\n **************************************************************************/\n\n const {\n bucketArnParamName,\n contentSourceDirectory,\n contentDestinationDirectory,\n subDomain,\n fullDomain,\n } = {\n bucketArnParamName: \"/STATIC_WEBSITE/BUCKET_ARN\",\n subDomain: findGitBranch(),\n ...props,\n };\n\n /***************************************************************************\n *\n * Import and build some values from Param Store during deployment.\n *\n **************************************************************************/\n\n const keyPrefix = [paramCase(subDomain), fullDomain].join(\".\");\n\n const bucketArn = StringParameter.valueForStringParameter(\n this,\n bucketArnParamName,\n );\n const bucket = Bucket.fromBucketArn(this, \"bucket\", bucketArn);\n\n /***************************************************************************\n *\n * Gather the sources we'll be deploying. We need to have an empty source\n * for tests since it will change all the time and bork up the test\n * snapshots if we don't.\n *\n **************************************************************************/\n\n const isTestEnv = process.env.VITEST === \"true\";\n const sources = isTestEnv ? [] : [Source.asset(contentSourceDirectory)];\n\n new BucketDeployment(this, \"deploy\", {\n sources,\n destinationBucket: bucket,\n retainOnDelete: false,\n destinationKeyPrefix: `${keyPrefix}${contentDestinationDirectory}`,\n });\n }\n}\n","import * as fs from \"node:fs\";\nimport * as path from \"node:path\";\nimport { Duration, StackProps } from \"aws-cdk-lib\";\nimport {\n Certificate,\n CertificateValidation,\n} from \"aws-cdk-lib/aws-certificatemanager\";\nimport {\n AccessLevel,\n AllowedMethods,\n CacheCookieBehavior,\n CacheHeaderBehavior,\n CachePolicy,\n CacheQueryStringBehavior,\n Distribution,\n LambdaEdgeEventType,\n S3OriginAccessControl,\n Signing,\n ViewerProtocolPolicy,\n} from \"aws-cdk-lib/aws-cloudfront\";\nimport { S3BucketOrigin } from \"aws-cdk-lib/aws-cloudfront-origins\";\nimport { Runtime } from \"aws-cdk-lib/aws-lambda\";\nimport { NodejsFunction } from \"aws-cdk-lib/aws-lambda-nodejs\";\nimport { LogGroup, RetentionDays } from \"aws-cdk-lib/aws-logs\";\nimport {\n ARecord,\n HostedZone,\n HostedZoneAttributes,\n IHostedZone,\n RecordTarget,\n} from \"aws-cdk-lib/aws-route53\";\nimport { CloudFrontTarget } from \"aws-cdk-lib/aws-route53-targets\";\nimport { StringParameter } from \"aws-cdk-lib/aws-ssm\";\nimport { Construct } from \"constructs\";\nimport type { HostingMode } from \"./static-hosting.viewer-request-handler\";\nimport { PrivateBucket, PrivateBucketProps } from \"../s3/private-bucket\";\n\nexport interface StaticDomainProps {\n /**\n * The base domain (ie: codedrifters.com)\n */\n readonly baseDomain: string;\n\n /**\n * Hosted zone ID for the base domain.\n */\n readonly hostedZoneAttributes: HostedZoneAttributes;\n}\n\nexport interface StaticHostingProps extends StackProps {\n /**\n * Short description used in various places for traceability.\n */\n readonly description?: string;\n\n /**\n * Values used to connect a domain name to the cloudfront distribution. If not\n * supplied, cloudfront doesn't use a custom domain.\n */\n readonly staticDomainProps?: StaticDomainProps;\n\n /**\n * Parameter name to use when storing the static hosting bucket's ARN.\n * This is needed in other later steps when deploying hosted content to S3.\n */\n readonly bucketArnParamName?: string;\n\n /**\n * Parameter name to use when storing the CloudFront Distribution Domain Name.\n */\n readonly distributionDomainParamName?: string;\n\n /**\n * Parameter name to use when storing the CloudFront Distribution ID.\n */\n readonly distributionIDParamName?: string;\n\n /**\n * Props to pass to the private S3 bucket.\n */\n readonly privateBucketProps?: PrivateBucketProps;\n\n /**\n * Selects how path-like URIs are rewritten by the viewer-request\n * `Lambda@Edge` handler.\n *\n * - `spa` (default): path-like URIs rewrite to `/index.html` so a\n * single-page app can serve its one root index and let the client-side\n * router handle the path.\n * - `static`: path-like URIs append `/index.html` (e.g. `/docs` →\n * `/docs/index.html`) so multi-page static sites can serve distinct\n * HTML per path.\n *\n * Multi-tenant domain-folder prepending runs after the rewrite in both\n * modes and is unaffected by this prop.\n *\n * @default \"spa\"\n */\n readonly hostingMode?: HostingMode;\n}\n\nexport class StaticHosting extends Construct {\n /**\n * Full domain name used as basis for hosting.\n */\n public readonly fullDomain: string;\n\n constructor(scope: Construct, id: string, props: StaticHostingProps = {}) {\n super(scope, id);\n\n /***************************************************************************\n *\n * Initial Setup\n *\n * Set some defaults, build domain information.\n *\n **************************************************************************/\n\n const {\n bucketArnParamName,\n distributionDomainParamName,\n distributionIDParamName,\n staticDomainProps,\n privateBucketProps,\n hostingMode,\n } = {\n bucketArnParamName: \"/STATIC_WEBSITE/BUCKET_ARN\",\n distributionDomainParamName: \"/STATIC_WEBSITE/DISTRIBUTION_DOMAIN\",\n distributionIDParamName: \"/STATIC_WEBSITE/DISTRIBUTION_ID\",\n hostingMode: \"spa\" as HostingMode,\n ...props,\n };\n\n const { baseDomain, hostedZoneAttributes } = staticDomainProps ?? {};\n\n /***************************************************************************\n *\n * PRIVATE BUCKET\n *\n * A bucket to store the files within.\n * Save ARN for later deploys.\n *\n **************************************************************************/\n\n const bucket = new PrivateBucket(\n this,\n \"static-hosting-bucket\",\n privateBucketProps,\n );\n\n /***************************************************************************\n *\n * DNS & Wildcard Certificate\n *\n * If a zone Id as passed in, find the hosted zone and create a wildcard\n * certificate for the domain.\n *\n **************************************************************************/\n\n let zone: IHostedZone | undefined;\n let certificate: Certificate | undefined;\n\n if (hostedZoneAttributes && baseDomain) {\n zone = HostedZone.fromHostedZoneAttributes(\n this,\n \"zone\",\n hostedZoneAttributes,\n );\n certificate = new Certificate(this, \"wildcard-certificate\", {\n domainName: `*.${baseDomain}`,\n subjectAlternativeNames: [baseDomain],\n validation: CertificateValidation.fromDnsMultiZone({\n [`*.${baseDomain}`]: zone,\n [baseDomain]: zone,\n }),\n });\n }\n\n /******************************************************************************\n *\n * `LAMBDA@EDGE` FUNCTION\n *\n * This handles rewriting the path from domain name.\n *\n *****************************************************************************/\n\n // Explicit entry required: when omitted, NodejsFunction infers the path from the\n // call site (the built lib/index.js), so it looks for index.viewer-request-handler.js\n // in the package. That file is only emitted if we add it as a separate tsup entry.\n // Use .js when present (built package); fall back to .ts for tests running from source.\n const handlerJs = path.join(\n __dirname,\n \"static-hosting.viewer-request-handler.js\",\n );\n const handlerTs = path.join(\n __dirname,\n \"static-hosting.viewer-request-handler.ts\",\n );\n const handlerEntry = fs.existsSync(handlerJs) ? handlerJs : handlerTs;\n\n const handler = new NodejsFunction(this, \"viewer-request-handler\", {\n entry: handlerEntry,\n handler: hostingMode === \"static\" ? \"staticHandler\" : \"spaHandler\",\n memorySize: 128,\n runtime: Runtime.NODEJS_24_X,\n logGroup: new LogGroup(this, \"viewer-request-handler-log-group\", {\n retention: RetentionDays.ONE_MONTH,\n }),\n });\n\n /******************************************************************************\n *\n * CLOUDFRONT CONFIG\n *\n * Setup a CloudFront Distribution for the bucket.\n *\n *****************************************************************************/\n\n const cachePolicy = new CachePolicy(this, \"cloudfront-policy\", {\n comment: \"Relatively conservative TTL policy.\",\n maxTtl: Duration.seconds(300),\n minTtl: Duration.seconds(0),\n defaultTtl: Duration.seconds(60),\n headerBehavior: CacheHeaderBehavior.none(),\n queryStringBehavior: CacheQueryStringBehavior.none(),\n cookieBehavior: CacheCookieBehavior.none(),\n enableAcceptEncodingGzip: true,\n enableAcceptEncodingBrotli: true,\n });\n\n const oac = new S3OriginAccessControl(this, \"MyOAC\", {\n signing: Signing.SIGV4_NO_OVERRIDE,\n });\n const origin = S3BucketOrigin.withOriginAccessControl(bucket, {\n originAccessControl: oac,\n originAccessLevels: [AccessLevel.READ],\n });\n\n const distribution = new Distribution(this, \"cloudfront-distribution\", {\n comment: `Distribution for ${props.description ?? id}`,\n\n /**\n * Only if domain was supplied\n */\n ...(certificate && baseDomain\n ? {\n certificate,\n domainNames: [baseDomain, `*.${baseDomain}`],\n }\n : {}),\n\n defaultBehavior: {\n origin,\n viewerProtocolPolicy: ViewerProtocolPolicy.REDIRECT_TO_HTTPS,\n cachePolicy,\n allowedMethods: AllowedMethods.ALLOW_GET_HEAD_OPTIONS,\n edgeLambdas: [\n {\n functionVersion: handler.currentVersion,\n eventType: LambdaEdgeEventType.VIEWER_REQUEST,\n },\n ],\n },\n defaultRootObject: \"index.html\",\n });\n\n /**\n * We finally have enough information to set the full domain.\n */\n this.fullDomain =\n certificate && baseDomain ? baseDomain : distribution.domainName;\n\n /***************************************************************************\n *\n * DNS ENTRY\n *\n * Link cloudfront to both the root fulldomain and all possible subdomains.\n *\n **************************************************************************/\n\n if (zone) {\n new ARecord(this, \"root-dns-entry\", {\n zone,\n recordName: baseDomain ? baseDomain : \"\",\n target: RecordTarget.fromAlias(new CloudFrontTarget(distribution)),\n });\n\n new ARecord(this, \"wc-dns-entry\", {\n zone,\n recordName: baseDomain ? `*.${baseDomain}` : \"*\",\n target: RecordTarget.fromAlias(new CloudFrontTarget(distribution)),\n });\n }\n\n /***************************************************************************\n *\n * EXPORTS\n *\n * Used by content uploader later.\n *\n **************************************************************************/\n\n new StringParameter(this, \"dist-domain\", {\n description: `GENERATED DO NOT CHANGE - CloudFront Distribution Details (${props.description ?? id}).`,\n parameterName: distributionDomainParamName,\n stringValue: distribution.domainName,\n });\n\n new StringParameter(this, \"dist-id\", {\n description: `GENERATED DO NOT CHANGE - CloudFront Distribution Details (${props.description ?? id}).`,\n parameterName: distributionIDParamName,\n stringValue: distribution.distributionId,\n });\n\n new StringParameter(this, \"bucket-arn\", {\n description: `GENERATED DO NOT CHANGE - S3 Bucket ARN for (${props.description ?? id}).`,\n parameterName: bucketArnParamName,\n stringValue: bucket.bucketArn,\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;AAKa,YAAA,iB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,eAAe;AAAA,MACf,aAAa,aAAa;AAAA,IAC5B,CAAC;AAED,QAAIA,iBAAgB,MAAM,WAAW;AAAA,MACnC,aAAa,8DAA8D,MAAM,eAAe,EAAE;AAAA,MAClG,eAAe;AAAA,MACf,aAAa,aAAa;AAAA,IAC5B,CAAC;AAED,QAAIA,iBAAgB,MAAM,cAAc;AAAA,MACtC,aAAa,gDAAgD,MAAM,eAAe,EAAE;AAAA,MACpF,eAAe;AAAA,MACf,aAAa,OAAO;AAAA,IACtB,CAAC;AAAA,EACH;AACF;","names":["findGitBranch","fs","path","Bucket","fs","path","NodejsFunction","StringParameter","Construct","Construct","NodejsFunction","StringParameter"]}
package/package.json CHANGED
@@ -11,6 +11,7 @@
11
11
  },
12
12
  "devDependencies": {
13
13
  "@microsoft/api-extractor": "7.58.7",
14
+ "@types/js-yaml": "^4.0.9",
14
15
  "@types/node": "25.8.0",
15
16
  "@typescript-eslint/eslint-plugin": "^8",
16
17
  "@typescript-eslint/parser": "^8",
@@ -40,7 +41,8 @@
40
41
  "dependencies": {
41
42
  "@types/aws-lambda": "^8.10.161",
42
43
  "change-case": "^4.0",
43
- "esbuild": "^0.28.0"
44
+ "esbuild": "^0.28.0",
45
+ "js-yaml": "^4.1.0"
44
46
  },
45
47
  "devEngines": {
46
48
  "packageManager": {
@@ -51,7 +53,7 @@
51
53
  },
52
54
  "main": "lib/index.js",
53
55
  "license": "MIT",
54
- "version": "0.0.72",
56
+ "version": "0.0.73",
55
57
  "types": "lib/index.d.ts",
56
58
  "//": "~~ Generated by projen. To modify, edit .projenrc.js and run \"pnpm exec projen\".",
57
59
  "scripts": {