Skip to content

Commit c8201c5

Browse files
Merge pull request #1503 from aligent/feature/static-hosting-test-fixes-and-peer-deps
feat: Add comprehensive test suite and optimize peer dependencies for static-hosting
2 parents 5a25b33 + 8533c30 commit c8201c5

File tree

15 files changed

+1611
-12
lines changed

15 files changed

+1611
-12
lines changed

.github/workflows/pull-request.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,35 @@ jobs:
5454

5555
env:
5656
PR_BASE_REF: ${{ github.event.pull_request.base.ref }}
57+
58+
test:
59+
name: 🧪 Run tests
60+
runs-on: ubuntu-latest
61+
steps:
62+
- name: Checkout Repository
63+
uses: actions/checkout@v4
64+
with:
65+
fetch-depth: 0
66+
67+
- name: Fetch target
68+
run: git fetch origin ${{ env.PR_BASE_REF }}
69+
70+
- name: Enable Corepack
71+
run: corepack enable
72+
73+
- uses: actions/setup-node@v4
74+
with:
75+
node-version-file: ".nvmrc"
76+
cache: "yarn"
77+
78+
- name: Install
79+
run: yarn install
80+
81+
- name: Build all packages
82+
run: yarn nx run-many -t build
83+
84+
- name: Test affected packages
85+
run: yarn nx affected:test --base=origin/${{ env.PR_BASE_REF }} --parallel --max-parallel=3
86+
87+
env:
88+
PR_BASE_REF: ${{ github.event.pull_request.base.ref }}

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,6 @@ cdk.out
7777

7878
# Used during the publish stage
7979
.npmignore
80+
81+
.cursor/rules/nx-rules.mdc
82+
.github/instructions/nx.instructions.md

CLAUDE.md

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Repository Overview
6+
7+
This is an Nx-based monorepo containing AWS CDK v2 construct packages. Each package provides reusable infrastructure components for common AWS patterns.
8+
9+
## Key Commands
10+
11+
### Development
12+
```bash
13+
# Install dependencies
14+
npm ci
15+
16+
# Build a specific package
17+
yarn nx build <package-name>
18+
19+
# Run tests for a package
20+
yarn nx test <package-name>
21+
22+
# Lint a package
23+
yarn nx lint <package-name>
24+
25+
# Run a single test file
26+
yarn nx test <package-name> --testFile=<test-file-name>
27+
```
28+
29+
### Local Testing
30+
```bash
31+
# After building, pack the package
32+
cd dist/<package-name> && npm pack
33+
34+
# Install in your target project
35+
npm i <path-to-tarball>
36+
```
37+
38+
### Publishing
39+
```bash
40+
# Publish with version and tag
41+
yarn nx publish <package-name> --ver=<version> --tag=<tag>
42+
```
43+
44+
## Architecture
45+
46+
### Package Structure
47+
All packages follow this pattern:
48+
```
49+
packages/<package-name>/
50+
├── src/
51+
│ ├── index.ts # Main exports
52+
│ └── lib/
53+
│ ├── <construct>.ts # Main CDK construct
54+
│ └── handlers/ # Lambda function code
55+
├── package.json
56+
├── project.json # Nx configuration
57+
├── tsconfig.json
58+
├── jest.config.ts
59+
└── README.md
60+
```
61+
62+
### Construct Pattern
63+
Each package exports CDK Constructs that:
64+
- Extend the base `Construct` class from AWS CDK
65+
- Accept a typed props interface (e.g., `StaticHostingProps`)
66+
- Create and configure AWS resources
67+
- May include Lambda functions bundled with esbuild
68+
69+
### Key Architectural Decisions
70+
1. **Independent Packages**: Each construct is independently versioned and can be used standalone
71+
2. **Lambda Bundling**: Uses `@aligent/cdk-esbuild` for efficient Lambda deployment
72+
3. **Peer Dependencies**: All packages require `aws-cdk-lib` and `constructs` as peer dependencies
73+
4. **TypeScript**: Entire codebase uses TypeScript with strict mode enabled
74+
75+
### Package Dependencies
76+
- Packages can compose together (e.g., WAF + CloudFront)
77+
- Lambda functions use AWS SDK v3 clients
78+
- Build process uses Nx task orchestration with dependency graph
79+
80+
## Testing Approach
81+
- Jest with ts-jest for all packages
82+
- 80% code coverage threshold
83+
- Mock AWS services in tests
84+
- Test files follow `*.test.ts` pattern
85+
86+
## Code Quality and Git Workflow
87+
88+
### Pre-commit Requirements
89+
**ALWAYS run linting before pushing code to git:**
90+
```bash
91+
# Run lint check for the package being modified
92+
yarn nx lint <package-name>
93+
94+
# Fix any linting issues automatically when possible
95+
yarn nx lint <package-name> --fix
96+
```
97+
98+
### Git Commit Process
99+
1. Make code changes
100+
2. **MANDATORY**: Run `yarn nx lint <package-name>` to check for linting issues
101+
3. Fix any linting errors or warnings
102+
4. Stage changes with `git add`
103+
5. Commit with descriptive message
104+
6. Push to remote
105+
106+
**Never push code that fails linting checks** - this will cause GitHub Actions to fail and block the PR.

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,26 @@ Make your changes in the package of choice then
3232

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

35+
### Testing
36+
37+
To run tests for the entire monorepo:
38+
39+
```bash
40+
yarn nx run-many -t test
41+
```
42+
43+
To run tests for a specific package:
44+
45+
```bash
46+
yarn nx test <package-name>
47+
```
48+
49+
To run a single test file:
50+
51+
```bash
52+
yarn nx test <package-name> --testFile=<test-file-name>
53+
```
54+
3555
### Merging
3656

3757
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

packages/static-hosting/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,26 @@ It has the following features that can optionally be enabled:
1717

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

20+
## Installation
21+
22+
```bash
23+
npm install @aligent/cdk-static-hosting aws-cdk-lib constructs
24+
```
25+
26+
Or with yarn:
27+
28+
```bash
29+
yarn add @aligent/cdk-static-hosting aws-cdk-lib constructs
30+
```
31+
32+
### Peer Dependencies
33+
34+
This package has peer dependencies on:
35+
- `aws-cdk-lib` (^2.120.0)
36+
- `constructs` (^10.0.0)
37+
38+
Make sure to install compatible versions of these packages in your CDK application.
39+
2040
## Usage and PrerenderFargateOptions
2141
### `domainName`(string)
2242
- 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
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/* eslint-disable */
22
export default {
3-
displayName: "basic-auth",
3+
displayName: "static-hosting",
44
preset: "../../jest.preset.js",
55
testEnvironment: "node",
66
transform: {
77
"^.+\\.[tj]s$": ["ts-jest", { tsconfig: "<rootDir>/tsconfig.spec.json" }],
88
},
99
moduleFileExtensions: ["ts", "js", "html"],
10-
coverageDirectory: "../../coverage/packages/basic-auth",
10+
coverageDirectory: "../../coverage/packages/static-hosting",
1111
};

0 commit comments

Comments
 (0)