Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
2649358
feat(static-hosting): add comprehensive test suite for StaticHosting …
TheOrangePuff Jun 24, 2025
3174c87
feat(static-hosting): add PathRemapFunction test suite
TheOrangePuff Jun 24, 2025
2303b15
feat(static-hosting): add CSP Lambda functions test suite
TheOrangePuff Jun 24, 2025
dd45298
feat(static-hosting): add remap Lambda handler unit tests
TheOrangePuff Jun 24, 2025
4fad236
feat(static-hosting): add CSP origin request handler unit tests
TheOrangePuff Jun 24, 2025
4ad0cb1
feat(static-hosting): add placeholder for CSP origin response tests
TheOrangePuff Jun 24, 2025
2470d2a
fix(static-hosting): fix Jest and TypeScript configuration
TheOrangePuff Jun 24, 2025
e419721
feat(static-hosting): optimize peer dependencies configuration
TheOrangePuff Jun 24, 2025
7dc5bd2
docs(static-hosting): add installation instructions and peer dependen…
TheOrangePuff Jun 24, 2025
a465227
chore: update gitignore and yarn lock after test dependencies
TheOrangePuff Jun 24, 2025
0c67cde
docs: add CLAUDE.md with project context and testing commands
TheOrangePuff Jun 24, 2025
264618a
fix(static-hosting): update yarn.lock after peer dependency changes
TheOrangePuff Jun 24, 2025
201893b
fix: apply prettier formatting to origin-response.test.ts
TheOrangePuff Jun 24, 2025
8d78ad9
docs: add mandatory linting instructions to CLAUDE.md
TheOrangePuff Jun 24, 2025
5d8a17d
feat: add GitHub Actions test workflow and update README with test in…
TheOrangePuff Jun 24, 2025
8533c30
refactor: consolidate test workflow into pull-request.yml
TheOrangePuff Jun 24, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,35 @@ jobs:

env:
PR_BASE_REF: ${{ github.event.pull_request.base.ref }}

test:
name: 🧪 Run tests
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Fetch target
run: git fetch origin ${{ env.PR_BASE_REF }}

- name: Enable Corepack
run: corepack enable

- uses: actions/setup-node@v4
with:
node-version-file: ".nvmrc"
cache: "yarn"

- name: Install
run: yarn install

- name: Build all packages
run: yarn nx run-many -t build

- name: Test affected packages
run: yarn nx affected:test --base=origin/${{ env.PR_BASE_REF }} --parallel --max-parallel=3

env:
PR_BASE_REF: ${{ github.event.pull_request.base.ref }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,6 @@ cdk.out

# Used during the publish stage
.npmignore

.cursor/rules/nx-rules.mdc
.github/instructions/nx.instructions.md
106 changes: 106 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

## Repository Overview

This is an Nx-based monorepo containing AWS CDK v2 construct packages. Each package provides reusable infrastructure components for common AWS patterns.

## Key Commands

### Development
```bash
# Install dependencies
npm ci

# Build a specific package
yarn nx build <package-name>

# Run tests for a package
yarn nx test <package-name>

# Lint a package
yarn nx lint <package-name>

# Run a single test file
yarn nx test <package-name> --testFile=<test-file-name>
```

### Local Testing
```bash
# After building, pack the package
cd dist/<package-name> && npm pack

# Install in your target project
npm i <path-to-tarball>
```

### Publishing
```bash
# Publish with version and tag
yarn nx publish <package-name> --ver=<version> --tag=<tag>
```

## Architecture

### Package Structure
All packages follow this pattern:
```
packages/<package-name>/
├── src/
│ ├── index.ts # Main exports
│ └── lib/
│ ├── <construct>.ts # Main CDK construct
│ └── handlers/ # Lambda function code
├── package.json
├── project.json # Nx configuration
├── tsconfig.json
├── jest.config.ts
└── README.md
```

### Construct Pattern
Each package exports CDK Constructs that:
- Extend the base `Construct` class from AWS CDK
- Accept a typed props interface (e.g., `StaticHostingProps`)
- Create and configure AWS resources
- May include Lambda functions bundled with esbuild

### Key Architectural Decisions
1. **Independent Packages**: Each construct is independently versioned and can be used standalone
2. **Lambda Bundling**: Uses `@aligent/cdk-esbuild` for efficient Lambda deployment
3. **Peer Dependencies**: All packages require `aws-cdk-lib` and `constructs` as peer dependencies
4. **TypeScript**: Entire codebase uses TypeScript with strict mode enabled

### Package Dependencies
- Packages can compose together (e.g., WAF + CloudFront)
- Lambda functions use AWS SDK v3 clients
- Build process uses Nx task orchestration with dependency graph

## Testing Approach
- Jest with ts-jest for all packages
- 80% code coverage threshold
- Mock AWS services in tests
- Test files follow `*.test.ts` pattern

## Code Quality and Git Workflow

### Pre-commit Requirements
**ALWAYS run linting before pushing code to git:**
```bash
# Run lint check for the package being modified
yarn nx lint <package-name>

# Fix any linting issues automatically when possible
yarn nx lint <package-name> --fix
```

### Git Commit Process
1. Make code changes
2. **MANDATORY**: Run `yarn nx lint <package-name>` to check for linting issues
3. Fix any linting errors or warnings
4. Stage changes with `git add`
5. Commit with descriptive message
6. Push to remote

**Never push code that fails linting checks** - this will cause GitHub Actions to fail and block the PR.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,26 @@ Make your changes in the package of choice then

From here anytime you rerun the `npm pack` step your changes will be in sync.

### Testing

To run tests for the entire monorepo:

```bash
yarn nx run-many -t test
```

To run tests for a specific package:

```bash
yarn nx test <package-name>
```

To run a single test file:

```bash
yarn nx test <package-name> --testFile=<test-file-name>
```

### Merging

Once happy with the changes and there's no errors update the readme (if there's any functional changes) and [create a PR](https://github.com/aligent/cdk-constructs/compare) for your branch
Expand Down
20 changes: 20 additions & 0 deletions packages/static-hosting/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,26 @@ It has the following features that can optionally be enabled:

![static hosting diagram](docs/static_hosting.png)

## Installation

```bash
npm install @aligent/cdk-static-hosting aws-cdk-lib constructs
```

Or with yarn:

```bash
yarn add @aligent/cdk-static-hosting aws-cdk-lib constructs
```

### Peer Dependencies

This package has peer dependencies on:
- `aws-cdk-lib` (^2.120.0)
- `constructs` (^10.0.0)

Make sure to install compatible versions of these packages in your CDK application.

## Usage and PrerenderFargateOptions
### `domainName`(string)
- Domain name for the stack. Combined with the subDomainName it is used as the name for the S3 origin and an alternative domain name for the CloudFront distribution
Expand Down
4 changes: 2 additions & 2 deletions packages/static-hosting/jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/* eslint-disable */
export default {
displayName: "basic-auth",
displayName: "static-hosting",
preset: "../../jest.preset.js",
testEnvironment: "node",
transform: {
"^.+\\.[tj]s$": ["ts-jest", { tsconfig: "<rootDir>/tsconfig.spec.json" }],
},
moduleFileExtensions: ["ts", "js", "html"],
coverageDirectory: "../../coverage/packages/basic-auth",
coverageDirectory: "../../coverage/packages/static-hosting",
};
Loading