Skip to content

Commit eb322fc

Browse files
committed
Format with prettier
1 parent 963e5bd commit eb322fc

34 files changed

Lines changed: 1245 additions & 857 deletions

.github/copilot-instructions.md

Lines changed: 46 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,38 @@
33
Always reference these instructions first and fallback to search or bash commands only when you encounter unexpected information that does not match the info here.
44

55
## Project Overview
6+
67
AMQP client.js is a TypeScript library providing AMQP 0-9-1 client functionality for both Node.js (TCP Socket) and browsers (WebSocket). The library has zero runtime dependencies and is designed for high performance messaging.
78

89
## Working Effectively
910

1011
### Prerequisites and Setup
12+
1113
- Requires Node.js >= 16.0.0 (verified working with Node.js 20.x)
1214
- Docker and Docker Compose for RabbitMQ testing server
1315
- For browser testing: Playwright (optional, may not work in all environments)
1416

1517
### Bootstrap and Build Process
18+
1619
Run these commands in sequence:
1720

1821
1. **Install dependencies**:
22+
1923
```bash
2024
npm install
2125
```
26+
2227
- Takes ~16 seconds
2328
- Automatically runs the build process via `prepare` script
2429
- NEVER CANCEL: Set timeout to 30+ minutes for initial install
2530

2631
2. **Manual build** (if needed):
32+
2733
```bash
2834
npm run build
2935
```
30-
- Takes ~5.4 seconds
36+
37+
- Takes ~5.4 seconds
3138
- NEVER CANCEL: Set timeout to 10+ minutes
3239
- Creates three output formats:
3340
- ES modules in `lib/mjs/`
@@ -36,9 +43,11 @@ Run these commands in sequence:
3643
- Browser bundle in `dist/`
3744

3845
3. **Start RabbitMQ services**:
46+
3947
```bash
4048
docker compose up -d
4149
```
50+
4251
- Takes ~11 seconds for first startup
4352
- NEVER CANCEL: Set timeout to 15+ minutes for Docker image pulls
4453
- Starts RabbitMQ server on ports 5671 (TLS) and 5672 (plain)
@@ -47,42 +56,51 @@ Run these commands in sequence:
4756
### Testing
4857

4958
#### Node.js Tests
59+
5060
```bash
5161
npm test
5262
```
63+
5364
- Takes ~15 seconds
5465
- NEVER CANCEL: Set timeout to 30+ minutes
5566
- Runs Node.js tests with coverage using Vitest
5667
- **EXPECTED**: 2 TLS-related tests may fail if certificates are not set up (normal in development)
5768
- All other tests should pass when RabbitMQ is running
5869

59-
#### Browser Tests
70+
#### Browser Tests
71+
6072
```bash
6173
npx playwright install --with-deps chromium
6274
npm run test-browser
6375
```
76+
6477
- **WARNING**: Playwright installation often fails in CI environments
6578
- Browser tests require WebSocket functionality
6679
- NEVER CANCEL: Playwright install can take 30+ minutes
6780
- Only attempt browser tests if Playwright installs successfully
6881

6982
#### Linting
83+
7084
```bash
7185
npm run lint
7286
```
87+
7388
- Takes ~1.8 seconds
7489
- Uses ESLint with TypeScript support
7590
- Must pass before committing (CI requirement)
7691

7792
#### Documentation Generation
93+
7894
```bash
79-
npm run docs
95+
npm run docs
8096
```
97+
8198
- Takes ~3.4 seconds
8299
- Generates API documentation in `docs/` directory
83100
- Uses TypeDoc
84101

85102
### Validation Scenarios
103+
86104
After making changes, always run this validation sequence:
87105

88106
1. **Build validation**: `npm run build` - ensure TypeScript compilation succeeds
@@ -91,89 +109,101 @@ After making changes, always run this validation sequence:
91109
4. **Functionality validation**: Test actual AMQP operations (see examples below)
92110

93111
### Manual Functional Testing
112+
94113
Always test functionality manually when making changes to core AMQP logic:
95114

96115
```javascript
97-
import { AMQPClient } from './lib/mjs/index.js';
116+
import { AMQPClient } from "./lib/mjs/index.js"
98117

99118
// Basic publish/consume test
100-
const amqp = new AMQPClient("amqp://localhost");
101-
const conn = await amqp.connect();
102-
const ch = await conn.channel();
103-
const q = await ch.queue("test-queue");
104-
await q.publish("test message");
105-
const consumer = await q.subscribe({noAck: true}, (msg) => {
106-
console.log("Received:", msg.bodyString());
107-
});
119+
const amqp = new AMQPClient("amqp://localhost")
120+
const conn = await amqp.connect()
121+
const ch = await conn.channel()
122+
const q = await ch.queue("test-queue")
123+
await q.publish("test message")
124+
const consumer = await q.subscribe({ noAck: true }, (msg) => {
125+
console.log("Received:", msg.bodyString())
126+
})
108127
// Clean up: consumer.cancel(), q.delete(), conn.close()
109128
```
110129

111130
## Important Files and Structure
112131

113132
### Source Code (`src/`)
133+
114134
- `amqp-socket-client.ts` - Node.js TCP client implementation
115-
- `amqp-websocket-client.ts` - Browser WebSocket client implementation
135+
- `amqp-websocket-client.ts` - Browser WebSocket client implementation
116136
- `amqp-channel.ts` - AMQP channel implementation
117137
- `amqp-queue.ts` - Queue operations
118138
- `amqp-message.ts` - Message handling
119139
- `index.ts` - Main exports
120140

121141
### Tests (`test/`)
142+
122143
- `test.ts` - Main Node.js test suite
123144
- `tls.ts` - TLS connection tests (may fail without certificates)
124145

125146
### Browser Tests (`test-browser/`)
147+
126148
- `websocket.ts` - WebSocket client tests
127149

128150
### Configuration Files
151+
129152
- `package.json` - Build scripts and dependencies
130153
- `tsconfig.json` - TypeScript configuration
131154
- `vitest.config.ts` - Node.js test configuration
132155
- `vitest.config.browser.ts` - Browser test configuration
133156
- `docker-compose.yml` - RabbitMQ test environment
134157

135158
### Build Output
159+
136160
- `lib/mjs/` - ES module builds
137-
- `lib/cjs/` - CommonJS builds
161+
- `lib/cjs/` - CommonJS builds
138162
- `types/` - TypeScript declarations
139163
- `dist/` - Browser-ready bundles
140164

141165
## Common Issues and Solutions
142166

143167
### RabbitMQ Connection Issues
168+
144169
- Ensure `docker compose up -d` has been run
145170
- Check containers are healthy: `docker compose ps`
146171
- RabbitMQ takes ~20 seconds to fully start
147172

148173
### Build Failures
174+
149175
- Run `npm run prebuild` to clean build directories
150176
- Ensure TypeScript has no compilation errors
151177
- Check Node.js version is >= 16.0.0
152178

153179
### Test Failures
180+
154181
- TLS tests failing: Expected if mkcert certificates not installed
155182
- Connection errors: Ensure RabbitMQ is running via Docker
156183
- WebSocket tests failing: Expected if Playwright not installed
157184

158185
### Browser Testing Limitations
186+
159187
- WebSocket client requires browser environment or WebSocket polyfill
160188
- Playwright installation may fail in some CI environments
161189
- Browser bundle available in `dist/amqp-websocket-client.mjs`
162190

163191
## Performance Notes
192+
164193
- Library has zero runtime dependencies
165194
- Supports high-throughput messaging (300k+ msgs/sec publish, 512k+ msgs/sec consume)
166195
- Uses DataView for binary protocol parsing (browser compatibility)
167196
- Optimized frame buffering for WebSocket connections
168197

169198
## Development Workflow
199+
170200
1. Start RabbitMQ: `docker compose up -d`
171-
2. Install dependencies: `npm install`
201+
2. Install dependencies: `npm install`
172202
3. Make changes to `src/` files
173203
4. Build: `npm run build`
174204
5. Test: `npm test`
175205
6. Lint: `npm run lint`
176206
7. Manual validation with real AMQP operations
177207
8. Clean up: `docker compose down`
178208

179-
Always run the full validation sequence before committing changes. The CI pipeline (.github/workflows/ci.yml) will run all these steps and must pass for merge approval.
209+
Always run the full validation sequence before committing changes. The CI pipeline (.github/workflows/ci.yml) will run all these steps and must pass for merge approval.

.github/workflows/ci.yml

Lines changed: 55 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ name: CI
22

33
on:
44
push:
5-
branches: [ main ]
5+
branches: [main]
66
pull_request:
7-
branches: [ main ]
7+
branches: [main]
88
workflow_dispatch:
99

1010
jobs:
@@ -17,61 +17,63 @@ jobs:
1717
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
1818

1919
steps:
20-
- name: Set up Homebrew
21-
uses: Homebrew/actions/setup-homebrew@master
22-
- name: Install github.com/FiloSottile/mkcert
23-
run: brew install mkcert
24-
- uses: actions/checkout@v4
25-
- name: Create local CA and certificate
26-
run: |
27-
mkdir -p .etc_rabbitmq
28-
CAROOT="$(pwd)/.etc_rabbitmq" $(brew --prefix)/bin/mkcert -install
29-
$(brew --prefix)/bin/mkcert -key-file ./.etc_rabbitmq/localhost-key.pem -cert-file ./.etc_rabbitmq/localhost.pem localhost
30-
chmod +r ./.etc_rabbitmq/localhost-key.pem
31-
- name: Create RabbitMQ config
32-
run: |
33-
tee ./.etc_rabbitmq/rabbitmq.conf <<'EOF'
34-
loopback_users = none
35-
listeners.ssl.default = 5671
36-
ssl_options.cacertfile = /etc/rabbitmq/rootCA.pem
37-
ssl_options.certfile = /etc/rabbitmq/localhost.pem
38-
ssl_options.keyfile = /etc/rabbitmq/localhost-key.pem
39-
EOF
40-
- name: Start Docker Compose
41-
run: docker compose up -d
42-
- name: Use Node.js ${{ matrix.node-version }}
43-
uses: actions/setup-node@v4
44-
with:
45-
node-version: ${{ matrix.node-version }}
46-
- run: npm install
47-
env:
48-
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: 1
49-
- run: npm test
50-
env:
51-
AMQPS_URL: amqps://localhost?insecure
52-
- run: npm run lint
20+
- name: Set up Homebrew
21+
uses: Homebrew/actions/setup-homebrew@master
22+
- name: Install github.com/FiloSottile/mkcert
23+
run: brew install mkcert
24+
- uses: actions/checkout@v4
25+
- name: Create local CA and certificate
26+
run: |
27+
mkdir -p .etc_rabbitmq
28+
CAROOT="$(pwd)/.etc_rabbitmq" $(brew --prefix)/bin/mkcert -install
29+
$(brew --prefix)/bin/mkcert -key-file ./.etc_rabbitmq/localhost-key.pem -cert-file ./.etc_rabbitmq/localhost.pem localhost
30+
chmod +r ./.etc_rabbitmq/localhost-key.pem
31+
- name: Create RabbitMQ config
32+
run: |
33+
tee ./.etc_rabbitmq/rabbitmq.conf <<'EOF'
34+
loopback_users = none
35+
listeners.ssl.default = 5671
36+
ssl_options.cacertfile = /etc/rabbitmq/rootCA.pem
37+
ssl_options.certfile = /etc/rabbitmq/localhost.pem
38+
ssl_options.keyfile = /etc/rabbitmq/localhost-key.pem
39+
EOF
40+
- name: Start Docker Compose
41+
run: docker compose up -d
42+
- name: Use Node.js ${{ matrix.node-version }}
43+
uses: actions/setup-node@v4
44+
with:
45+
node-version: ${{ matrix.node-version }}
46+
- run: npm install
47+
env:
48+
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: 1
49+
- run: npm test
50+
env:
51+
AMQPS_URL: amqps://localhost?insecure
52+
- run: npm run lint
53+
- run: npm run format:check
54+
- run: npm run typecheck
5355

5456
test-browser:
5557
runs-on: ubuntu-latest
5658
env:
5759
NODE_VERSION: 22.x
5860

5961
steps:
60-
- uses: actions/checkout@v4
61-
- name: Create RabbitMQ config
62-
run: |
63-
mkdir -p .etc_rabbitmq
64-
tee ./.etc_rabbitmq/rabbitmq.conf <<'EOF'
65-
loopback_users = none
66-
EOF
67-
- name: Start Docker Compose
68-
run: docker compose up -d
69-
- name: Use Node.js ${{ env.NODE_VERSION }}
70-
uses: actions/setup-node@v4
71-
with:
72-
node-version: ${{ env.NODE_VERSION }}
73-
- run: npm install
74-
env:
75-
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: 1
76-
- run: npx playwright install --with-deps chromium
77-
- run: npm run test-browser -- run --browser.headless
62+
- uses: actions/checkout@v4
63+
- name: Create RabbitMQ config
64+
run: |
65+
mkdir -p .etc_rabbitmq
66+
tee ./.etc_rabbitmq/rabbitmq.conf <<'EOF'
67+
loopback_users = none
68+
EOF
69+
- name: Start Docker Compose
70+
run: docker compose up -d
71+
- name: Use Node.js ${{ env.NODE_VERSION }}
72+
uses: actions/setup-node@v4
73+
with:
74+
node-version: ${{ env.NODE_VERSION }}
75+
- run: npm install
76+
env:
77+
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: 1
78+
- run: npx playwright install --with-deps chromium
79+
- run: npm run test-browser -- run --browser.headless

.github/workflows/docs.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ on:
66
branches:
77
- main
88
paths:
9-
- 'src/**'
10-
- 'README.md'
9+
- "src/**"
10+
- "README.md"
1111

1212
jobs:
1313
docs:

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Release NPM
33
on:
44
push:
55
tags:
6-
- 'v*'
6+
- "v*"
77

88
jobs:
99
release:

.prettierignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Ignore artifacts:
2+
dist
3+
lib
4+
types
5+
coverage
6+
7+
# ignore formatted config files
8+
tsconfig.json
9+
.vscode

.prettierrc.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"semi": false,
3+
"singleQuote": false,
4+
"printWidth": 120
5+
}

.vscode/extensions.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"recommendations": [
3-
"editorconfig.editorconfig"
3+
"editorconfig.editorconfig",
4+
"esbenp.prettier-vscode"
45
]
56
}

0 commit comments

Comments
 (0)