@codedrifters/constructs 0.0.84 → 0.0.85
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.js +18 -2
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +23 -3
- package/lib/index.mjs.map +1 -1
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -435,11 +435,27 @@ var StaticContent = class extends import_constructs.Construct {
|
|
|
435
435
|
const bucket = import_aws_s32.Bucket.fromBucketArn(this, "bucket", bucketArn);
|
|
436
436
|
const isTestEnv = process.env.VITEST === "true";
|
|
437
437
|
const sources = isTestEnv ? [] : [import_aws_s3_deployment.Source.asset(contentSourceDirectory)];
|
|
438
|
-
|
|
438
|
+
const destinationKeyPrefix = `${keyPrefix}${contentDestinationDirectory}`;
|
|
439
|
+
new import_aws_s3_deployment.BucketDeployment(this, "deploy-assets", {
|
|
439
440
|
sources,
|
|
440
441
|
destinationBucket: bucket,
|
|
442
|
+
destinationKeyPrefix,
|
|
441
443
|
retainOnDelete: false,
|
|
442
|
-
|
|
444
|
+
prune: false,
|
|
445
|
+
exclude: ["*"],
|
|
446
|
+
include: ["assets/*"],
|
|
447
|
+
cacheControl: [
|
|
448
|
+
import_aws_s3_deployment.CacheControl.fromString("public, max-age=31536000, immutable")
|
|
449
|
+
]
|
|
450
|
+
});
|
|
451
|
+
new import_aws_s3_deployment.BucketDeployment(this, "deploy-root", {
|
|
452
|
+
sources,
|
|
453
|
+
destinationBucket: bucket,
|
|
454
|
+
destinationKeyPrefix,
|
|
455
|
+
retainOnDelete: false,
|
|
456
|
+
prune: false,
|
|
457
|
+
exclude: ["assets/*"],
|
|
458
|
+
cacheControl: [import_aws_s3_deployment.CacheControl.fromString("no-cache")]
|
|
443
459
|
});
|
|
444
460
|
}
|
|
445
461
|
};
|
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/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 ICommandHooks,\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 * Build an `ICommandHooks` implementation that copies an\n * entry-adjacent `.npmrc` into the bundling input directory before\n * `pnpm install` runs. Composes with any caller-supplied hooks so\n * existing `beforeBundling` / `beforeInstall` / `afterBundling`\n * commands are preserved.\n *\n * Exported for unit testing; the construct wires this automatically.\n */\nexport const buildNpmrcCopyCommandHooks = (params: {\n readonly npmrcPath: string;\n readonly existingHooks?: ICommandHooks;\n}): ICommandHooks => {\n const { npmrcPath, existingHooks } = params;\n return {\n beforeBundling(inputDir: string, outputDir: string): string[] {\n return existingHooks?.beforeBundling(inputDir, outputDir) ?? [];\n },\n beforeInstall(inputDir: string, outputDir: string): string[] {\n const callerCommands =\n existingHooks?.beforeInstall(inputDir, outputDir) ?? [];\n const copyCommand = `cp ${npmrcPath} ${inputDir}/.npmrc`;\n return [...callerCommands, copyCommand];\n },\n afterBundling(inputDir: string, outputDir: string): string[] {\n return existingHooks?.afterBundling(inputDir, outputDir) ?? [];\n },\n };\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. CDK does **not** copy arbitrary entry-adjacent\n * files into the bundling input directory, so the construct also\n * wires a `bundling.commandHooks.beforeInstall` hook that copies the\n * rendered `.npmrc` into the bundling input directory immediately\n * before `pnpm install` runs. Caller-supplied `commandHooks` are\n * preserved — the copy command is appended to whatever the caller\n * already returns from `beforeInstall`.\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 let mirrorResult: MirrorPnpmWorkspacePolicyResult | undefined;\n if (!props.disablePnpmPolicyMirror && props.entry) {\n mirrorResult = 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\n // Wire the beforeInstall hook only when the mirror produced (or\n // confirmed) an .npmrc file on disk. Other skippedReason values\n // (`missing-entry`, `missing-workspace-file`, `empty-policy`) mean\n // there is nothing to copy; falling through to plain NodejsFunction\n // behavior is correct in those cases.\n const npmrcPath = mirrorResult?.npmrcPath;\n const shouldWireHook = npmrcPath !== undefined && fs.existsSync(npmrcPath);\n\n const propsWithHook: NodejsFunctionProps = shouldWireHook\n ? {\n ...rest,\n bundling: {\n ...rest.bundling,\n commandHooks: buildNpmrcCopyCommandHooks({\n npmrcPath,\n existingHooks: rest.bundling?.commandHooks,\n }),\n },\n }\n : rest;\n\n super(scope, id, propsWithHook);\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 { CfnOutput } from \"aws-cdk-lib\";\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 new CfnOutput(this, \"StaticContentEndpoint\", {\n value: `https://${keyPrefix}`,\n description: \"Branch-specific HTTPS endpoint serving this content\",\n });\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,WAAW,QAAQ,EACnB,OAAO,QAAQ,EACf,OAAO,KAAK,EACZ,UAAU,GAAG,UAAU;IAC5B;AANa,IAAAC,SAAA,aAAU;AAchB,QAAM,mBAAmB,CAAC,aAAqB,cAAqB;AACzE,aAAO,YAAY,SAAS,YACxB,cACA,YAAY,UAAU,GAAG,SAAS;IACxC;AAJa,IAAAA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ports","findGitBranch","exports","exports","exports","fs","path","import_aws_cdk_lib","import_aws_s3","fs","path","import_aws_cdk_lib","import_aws_lambda_nodejs","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 ICommandHooks,\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 * Build an `ICommandHooks` implementation that copies an\n * entry-adjacent `.npmrc` into the bundling input directory before\n * `pnpm install` runs. Composes with any caller-supplied hooks so\n * existing `beforeBundling` / `beforeInstall` / `afterBundling`\n * commands are preserved.\n *\n * Exported for unit testing; the construct wires this automatically.\n */\nexport const buildNpmrcCopyCommandHooks = (params: {\n readonly npmrcPath: string;\n readonly existingHooks?: ICommandHooks;\n}): ICommandHooks => {\n const { npmrcPath, existingHooks } = params;\n return {\n beforeBundling(inputDir: string, outputDir: string): string[] {\n return existingHooks?.beforeBundling(inputDir, outputDir) ?? [];\n },\n beforeInstall(inputDir: string, outputDir: string): string[] {\n const callerCommands =\n existingHooks?.beforeInstall(inputDir, outputDir) ?? [];\n const copyCommand = `cp ${npmrcPath} ${inputDir}/.npmrc`;\n return [...callerCommands, copyCommand];\n },\n afterBundling(inputDir: string, outputDir: string): string[] {\n return existingHooks?.afterBundling(inputDir, outputDir) ?? [];\n },\n };\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. CDK does **not** copy arbitrary entry-adjacent\n * files into the bundling input directory, so the construct also\n * wires a `bundling.commandHooks.beforeInstall` hook that copies the\n * rendered `.npmrc` into the bundling input directory immediately\n * before `pnpm install` runs. Caller-supplied `commandHooks` are\n * preserved — the copy command is appended to whatever the caller\n * already returns from `beforeInstall`.\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 let mirrorResult: MirrorPnpmWorkspacePolicyResult | undefined;\n if (!props.disablePnpmPolicyMirror && props.entry) {\n mirrorResult = 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\n // Wire the beforeInstall hook only when the mirror produced (or\n // confirmed) an .npmrc file on disk. Other skippedReason values\n // (`missing-entry`, `missing-workspace-file`, `empty-policy`) mean\n // there is nothing to copy; falling through to plain NodejsFunction\n // behavior is correct in those cases.\n const npmrcPath = mirrorResult?.npmrcPath;\n const shouldWireHook = npmrcPath !== undefined && fs.existsSync(npmrcPath);\n\n const propsWithHook: NodejsFunctionProps = shouldWireHook\n ? {\n ...rest,\n bundling: {\n ...rest.bundling,\n commandHooks: buildNpmrcCopyCommandHooks({\n npmrcPath,\n existingHooks: rest.bundling?.commandHooks,\n }),\n },\n }\n : rest;\n\n super(scope, id, propsWithHook);\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 { CfnOutput } from \"aws-cdk-lib\";\nimport { Bucket } from \"aws-cdk-lib/aws-s3\";\nimport {\n BucketDeployment,\n CacheControl,\n Source,\n} 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 new CfnOutput(this, \"StaticContentEndpoint\", {\n value: `https://${keyPrefix}`,\n description: \"Branch-specific HTTPS endpoint serving this content\",\n });\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 const destinationKeyPrefix = `${keyPrefix}${contentDestinationDirectory}`;\n\n /***************************************************************************\n *\n * Deploy in two passes with different cache headers. Build tools (e.g.\n * Vite) emit content-hashed filenames under `assets/`, so those are\n * immutable and safe to cache forever. The unhashed entry document\n * (`index.html`) must be revalidated on every load — otherwise browsers\n * heuristically cache it and keep requesting stale (old-hash) bundles\n * until the user does a hard refresh.\n *\n * `prune: false` on both so neither pass deletes the other's objects (and\n * so previous hashed bundles linger briefly for clients mid-session).\n *\n **************************************************************************/\n\n new BucketDeployment(this, \"deploy-assets\", {\n sources,\n destinationBucket: bucket,\n destinationKeyPrefix,\n retainOnDelete: false,\n prune: false,\n exclude: [\"*\"],\n include: [\"assets/*\"],\n cacheControl: [\n CacheControl.fromString(\"public, max-age=31536000, immutable\"),\n ],\n });\n\n new BucketDeployment(this, \"deploy-root\", {\n sources,\n destinationBucket: bucket,\n destinationKeyPrefix,\n retainOnDelete: false,\n prune: false,\n exclude: [\"assets/*\"],\n cacheControl: [CacheControl.fromString(\"no-cache\")],\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,SAA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A,CAAC;AAAA,MAEL,iBAAiB;AAAA,QACf;AAAA,QACA,sBAAsB,2CAAqB;AAAA,QAC3C;AAAA,QACA,gBAAgB,qCAAe;AAAA,QAC/B,aAAa;AAAA,UACX;AAAA,YACE,iBAAiB,QAAQ;AAAA,YACzB,WAAW,0CAAoB;AAAA,UACjC;AAAA,QACF;AAAA,MACF;AAAA,MACA,mBAAmB;AAAA,IACrB,CAAC;AAKD,SAAK,aACH,eAAe,aAAa,aAAa,aAAa;AAUxD,QAAI,MAAM;AACR,UAAI,2BAAQ,MAAM,kBAAkB;AAAA,QAClC;AAAA,QACA,YAAY,aAAa,aAAa;AAAA,QACtC,QAAQ,gCAAa,UAAU,IAAI,4CAAiB,YAAY,CAAC;AAAA,MACnE,CAAC;AAED,UAAI,2BAAQ,MAAM,gBAAgB;AAAA,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_cdk_lib","import_aws_s3","fs","path","import_aws_cdk_lib","import_aws_lambda_nodejs","import_aws_ssm","import_constructs"]}
|
package/lib/index.mjs
CHANGED
|
@@ -368,7 +368,11 @@ var PrivateBucket = class extends Bucket {
|
|
|
368
368
|
var import_utils = __toESM(require_lib());
|
|
369
369
|
import { CfnOutput } from "aws-cdk-lib";
|
|
370
370
|
import { Bucket as Bucket2 } from "aws-cdk-lib/aws-s3";
|
|
371
|
-
import {
|
|
371
|
+
import {
|
|
372
|
+
BucketDeployment,
|
|
373
|
+
CacheControl,
|
|
374
|
+
Source
|
|
375
|
+
} from "aws-cdk-lib/aws-s3-deployment";
|
|
372
376
|
import { StringParameter } from "aws-cdk-lib/aws-ssm";
|
|
373
377
|
import { paramCase } from "change-case";
|
|
374
378
|
import { Construct } from "constructs";
|
|
@@ -398,11 +402,27 @@ var StaticContent = class extends Construct {
|
|
|
398
402
|
const bucket = Bucket2.fromBucketArn(this, "bucket", bucketArn);
|
|
399
403
|
const isTestEnv = process.env.VITEST === "true";
|
|
400
404
|
const sources = isTestEnv ? [] : [Source.asset(contentSourceDirectory)];
|
|
401
|
-
|
|
405
|
+
const destinationKeyPrefix = `${keyPrefix}${contentDestinationDirectory}`;
|
|
406
|
+
new BucketDeployment(this, "deploy-assets", {
|
|
407
|
+
sources,
|
|
408
|
+
destinationBucket: bucket,
|
|
409
|
+
destinationKeyPrefix,
|
|
410
|
+
retainOnDelete: false,
|
|
411
|
+
prune: false,
|
|
412
|
+
exclude: ["*"],
|
|
413
|
+
include: ["assets/*"],
|
|
414
|
+
cacheControl: [
|
|
415
|
+
CacheControl.fromString("public, max-age=31536000, immutable")
|
|
416
|
+
]
|
|
417
|
+
});
|
|
418
|
+
new BucketDeployment(this, "deploy-root", {
|
|
402
419
|
sources,
|
|
403
420
|
destinationBucket: bucket,
|
|
421
|
+
destinationKeyPrefix,
|
|
404
422
|
retainOnDelete: false,
|
|
405
|
-
|
|
423
|
+
prune: false,
|
|
424
|
+
exclude: ["assets/*"],
|
|
425
|
+
cacheControl: [CacheControl.fromString("no-cache")]
|
|
406
426
|
});
|
|
407
427
|
}
|
|
408
428
|
};
|
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/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 ICommandHooks,\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 * Build an `ICommandHooks` implementation that copies an\n * entry-adjacent `.npmrc` into the bundling input directory before\n * `pnpm install` runs. Composes with any caller-supplied hooks so\n * existing `beforeBundling` / `beforeInstall` / `afterBundling`\n * commands are preserved.\n *\n * Exported for unit testing; the construct wires this automatically.\n */\nexport const buildNpmrcCopyCommandHooks = (params: {\n readonly npmrcPath: string;\n readonly existingHooks?: ICommandHooks;\n}): ICommandHooks => {\n const { npmrcPath, existingHooks } = params;\n return {\n beforeBundling(inputDir: string, outputDir: string): string[] {\n return existingHooks?.beforeBundling(inputDir, outputDir) ?? [];\n },\n beforeInstall(inputDir: string, outputDir: string): string[] {\n const callerCommands =\n existingHooks?.beforeInstall(inputDir, outputDir) ?? [];\n const copyCommand = `cp ${npmrcPath} ${inputDir}/.npmrc`;\n return [...callerCommands, copyCommand];\n },\n afterBundling(inputDir: string, outputDir: string): string[] {\n return existingHooks?.afterBundling(inputDir, outputDir) ?? [];\n },\n };\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. CDK does **not** copy arbitrary entry-adjacent\n * files into the bundling input directory, so the construct also\n * wires a `bundling.commandHooks.beforeInstall` hook that copies the\n * rendered `.npmrc` into the bundling input directory immediately\n * before `pnpm install` runs. Caller-supplied `commandHooks` are\n * preserved — the copy command is appended to whatever the caller\n * already returns from `beforeInstall`.\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 let mirrorResult: MirrorPnpmWorkspacePolicyResult | undefined;\n if (!props.disablePnpmPolicyMirror && props.entry) {\n mirrorResult = 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\n // Wire the beforeInstall hook only when the mirror produced (or\n // confirmed) an .npmrc file on disk. Other skippedReason values\n // (`missing-entry`, `missing-workspace-file`, `empty-policy`) mean\n // there is nothing to copy; falling through to plain NodejsFunction\n // behavior is correct in those cases.\n const npmrcPath = mirrorResult?.npmrcPath;\n const shouldWireHook = npmrcPath !== undefined && fs.existsSync(npmrcPath);\n\n const propsWithHook: NodejsFunctionProps = shouldWireHook\n ? {\n ...rest,\n bundling: {\n ...rest.bundling,\n commandHooks: buildNpmrcCopyCommandHooks({\n npmrcPath,\n existingHooks: rest.bundling?.commandHooks,\n }),\n },\n }\n : rest;\n\n super(scope, id, propsWithHook);\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 { CfnOutput } from \"aws-cdk-lib\";\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 new CfnOutput(this, \"StaticContentEndpoint\", {\n value: `https://${keyPrefix}`,\n description: \"Branch-specific HTTPS endpoint serving this content\",\n });\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,iBAAiB;;;;MAI5B,KAAK;;;;MAKL,OAAO;;;;MAKP,MAAM;;AAYK,YAAA,yBAAyB;;;;;MAKpC,SAAS;;;;;MAKT,WAAW;;AAcA,YAAA,uBAAuB,QAAA;;;;;;;;;;ACvDpC,QAAA,uBAAA,UAAA,eAAA;AAQO,QAAMA,iBAAgB,MAAa;AACxC,cAAO,GAAA,qBAAA,UAAS,iCAAiC,EAC9C,SAAS,MAAM,EACf,QAAQ,cAAc,EAAE;IAC7B;AAJa,YAAA,gBAAaA;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,YAAA,kBAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACd5B,QAAA,SAAA,aAAA,UAAA,QAAA,CAAA;AAQO,QAAM,aAAa,CAAC,UAAkB,aAAqB,QAAO;AACvE,aAAO,OACJ,WAAW,QAAQ,EACnB,OAAO,QAAQ,EACf,OAAO,KAAK,EACZ,UAAU,GAAG,UAAU;IAC5B;AANa,YAAA,aAAU;AAchB,QAAM,mBAAmB,CAAC,aAAqB,cAAqB;AACzE,aAAO,YAAY,SAAS,YACxB,cACA,YAAY,UAAU,GAAG,SAAS;IACxC;AAJa,YAAA,mBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;ACtB7B,iBAAA,qBAAA,OAAA;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gB,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"]}
|
|
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 ICommandHooks,\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 * Build an `ICommandHooks` implementation that copies an\n * entry-adjacent `.npmrc` into the bundling input directory before\n * `pnpm install` runs. Composes with any caller-supplied hooks so\n * existing `beforeBundling` / `beforeInstall` / `afterBundling`\n * commands are preserved.\n *\n * Exported for unit testing; the construct wires this automatically.\n */\nexport const buildNpmrcCopyCommandHooks = (params: {\n readonly npmrcPath: string;\n readonly existingHooks?: ICommandHooks;\n}): ICommandHooks => {\n const { npmrcPath, existingHooks } = params;\n return {\n beforeBundling(inputDir: string, outputDir: string): string[] {\n return existingHooks?.beforeBundling(inputDir, outputDir) ?? [];\n },\n beforeInstall(inputDir: string, outputDir: string): string[] {\n const callerCommands =\n existingHooks?.beforeInstall(inputDir, outputDir) ?? [];\n const copyCommand = `cp ${npmrcPath} ${inputDir}/.npmrc`;\n return [...callerCommands, copyCommand];\n },\n afterBundling(inputDir: string, outputDir: string): string[] {\n return existingHooks?.afterBundling(inputDir, outputDir) ?? [];\n },\n };\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. CDK does **not** copy arbitrary entry-adjacent\n * files into the bundling input directory, so the construct also\n * wires a `bundling.commandHooks.beforeInstall` hook that copies the\n * rendered `.npmrc` into the bundling input directory immediately\n * before `pnpm install` runs. Caller-supplied `commandHooks` are\n * preserved — the copy command is appended to whatever the caller\n * already returns from `beforeInstall`.\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 let mirrorResult: MirrorPnpmWorkspacePolicyResult | undefined;\n if (!props.disablePnpmPolicyMirror && props.entry) {\n mirrorResult = 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\n // Wire the beforeInstall hook only when the mirror produced (or\n // confirmed) an .npmrc file on disk. Other skippedReason values\n // (`missing-entry`, `missing-workspace-file`, `empty-policy`) mean\n // there is nothing to copy; falling through to plain NodejsFunction\n // behavior is correct in those cases.\n const npmrcPath = mirrorResult?.npmrcPath;\n const shouldWireHook = npmrcPath !== undefined && fs.existsSync(npmrcPath);\n\n const propsWithHook: NodejsFunctionProps = shouldWireHook\n ? {\n ...rest,\n bundling: {\n ...rest.bundling,\n commandHooks: buildNpmrcCopyCommandHooks({\n npmrcPath,\n existingHooks: rest.bundling?.commandHooks,\n }),\n },\n }\n : rest;\n\n super(scope, id, propsWithHook);\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 { CfnOutput } from \"aws-cdk-lib\";\nimport { Bucket } from \"aws-cdk-lib/aws-s3\";\nimport {\n BucketDeployment,\n CacheControl,\n Source,\n} 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 new CfnOutput(this, \"StaticContentEndpoint\", {\n value: `https://${keyPrefix}`,\n description: \"Branch-specific HTTPS endpoint serving this content\",\n });\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 const destinationKeyPrefix = `${keyPrefix}${contentDestinationDirectory}`;\n\n /***************************************************************************\n *\n * Deploy in two passes with different cache headers. Build tools (e.g.\n * Vite) emit content-hashed filenames under `assets/`, so those are\n * immutable and safe to cache forever. The unhashed entry document\n * (`index.html`) must be revalidated on every load — otherwise browsers\n * heuristically cache it and keep requesting stale (old-hash) bundles\n * until the user does a hard refresh.\n *\n * `prune: false` on both so neither pass deletes the other's objects (and\n * so previous hashed bundles linger briefly for clients mid-session).\n *\n **************************************************************************/\n\n new BucketDeployment(this, \"deploy-assets\", {\n sources,\n destinationBucket: bucket,\n destinationKeyPrefix,\n retainOnDelete: false,\n prune: false,\n exclude: [\"*\"],\n include: [\"assets/*\"],\n cacheControl: [\n CacheControl.fromString(\"public, max-age=31536000, immutable\"),\n ],\n });\n\n new BucketDeployment(this, \"deploy-root\", {\n sources,\n destinationBucket: bucket,\n destinationKeyPrefix,\n retainOnDelete: false,\n prune: false,\n exclude: [\"assets/*\"],\n cacheControl: [CacheControl.fromString(\"no-cache\")],\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,iBAAiB;;;;MAI5B,KAAK;;;;MAKL,OAAO;;;;MAKP,MAAM;;AAYK,YAAA,yBAAyB;;;;;MAKpC,SAAS;;;;;MAKT,WAAW;;AAcA,YAAA,uBAAuB,QAAA;;;;;;;;;;ACvDpC,QAAA,uBAAA,UAAA,eAAA;AAQO,QAAMA,iBAAgB,MAAa;AACxC,cAAO,GAAA,qBAAA,UAAS,iCAAiC,EAC9C,SAAS,MAAM,EACf,QAAQ,cAAc,EAAE;IAC7B;AAJa,YAAA,gBAAaA;AAMnB,QA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AAAA,IACtB,CAAC;AAAA,EACH;AACF;","names":["findGitBranch","fs","path","Bucket","fs","path","NodejsFunction","StringParameter","Construct","Construct","NodejsFunction","StringParameter"]}
|
package/package.json
CHANGED