Skip to content

Commit 2560578

Browse files
docs: add comprehensive PUBLISH.md documentation
- Document multi-version publishing workflow for PostgreSQL versions 13-17 - Cover parser package version preparation using prepare-versions.ts - Cover deparser package template-based generation using generate-version-packages.ts - Include yarn && yarn build prerequisites - Provide step-by-step publishing procedures for both individual and Lerna workflows - Add troubleshooting section for common publishing issues Co-Authored-By: Dan Lynch <[email protected]>
1 parent a0f6c30 commit 2560578

File tree

1 file changed

+261
-0
lines changed

1 file changed

+261
-0
lines changed

PUBLISH.md

Lines changed: 261 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,261 @@
1+
# Publishing Guide
2+
3+
This guide covers the multi-version publishing workflow for the pgsql-parser monorepo, which supports PostgreSQL versions 13-17 with version-specific npm tags.
4+
5+
## Prerequisites
6+
7+
Before publishing any packages, you must build the entire monorepo:
8+
9+
```bash
10+
yarn && yarn build
11+
```
12+
13+
This installs all dependencies and builds all packages in the correct order using Lerna.
14+
15+
## Multi-Version Publishing Overview
16+
17+
The pgsql-parser project uses a sophisticated multi-version publishing system to support different PostgreSQL versions. Each PostgreSQL version has its own:
18+
19+
- **Version numbers** for each package (parser, deparser, types)
20+
- **npm tag** for publishing (pg13, pg14, pg15, pg16, pg17)
21+
- **libpg-query dependency** version
22+
23+
All version mappings are centrally managed in `config/versions.json`:
24+
25+
```json
26+
{
27+
"versions": {
28+
"13": {
29+
"libpg-query": "13.5.7",
30+
"pgsql-parser": "13.18.0",
31+
"pgsql-deparser": "13.17.0",
32+
"@pgsql/types": "13.11.1",
33+
"npmTag": "pg13"
34+
},
35+
"17": {
36+
"libpg-query": "17.5.5",
37+
"pgsql-parser": "17.7.5",
38+
"pgsql-deparser": "17.8.3",
39+
"@pgsql/types": "17.6.1",
40+
"npmTag": "pg17"
41+
}
42+
}
43+
}
44+
```
45+
46+
## Package Publishing Workflows
47+
48+
### 1. Parser Package (`pgsql-parser`)
49+
50+
The parser package uses a version preparation script to generate multiple version-specific packages.
51+
52+
#### Prepare Versions
53+
```bash
54+
cd packages/parser
55+
npm run prepare-versions
56+
```
57+
58+
This script (`scripts/prepare-versions.ts`):
59+
- Reads version configuration from `config/versions.json`
60+
- Creates version-specific directories in `packages/parser/versions/`
61+
- Generates `package.json`, `tsconfig.json`, and source files for each PostgreSQL version
62+
- Each version gets its own libpg-query dependency and npm tag
63+
64+
#### Build and Publish Individual Versions
65+
```bash
66+
# Navigate to a specific version directory
67+
cd packages/parser/versions/17
68+
69+
# Build the package
70+
npm run build
71+
72+
# Publish with the correct tag
73+
npm publish --tag pg17
74+
```
75+
76+
#### Publish All Parser Versions
77+
```bash
78+
cd packages/parser
79+
80+
# Prepare all versions
81+
npm run prepare-versions
82+
83+
# Build and publish each version
84+
for version in versions/*/; do
85+
cd "$version"
86+
npm run build
87+
npm run publish:pkg # Uses the npmTag from config
88+
cd ..
89+
done
90+
```
91+
92+
### 2. Deparser Package (`pgsql-deparser`)
93+
94+
The deparser package uses a template-based approach for multi-version publishing.
95+
96+
#### Prepare Versions
97+
```bash
98+
cd packages/deparser
99+
npm run prepare-versions
100+
```
101+
102+
This runs a complete preparation pipeline:
103+
1. `strip-transformer-types` - Clean up transformer types
104+
2. `strip-direct-transformer-types` - Clean up direct transformer types
105+
3. `strip-deparser-types` - Clean up deparser types
106+
4. `organize-transformers` - Organize transformers by version
107+
5. `generate-version-deparsers` - Generate version-specific deparsers
108+
6. `generate-packages` - Generate package.json files for each version
109+
110+
The `generate-packages` script (`scripts/generate-version-packages.ts`):
111+
- Uses the template from `config/deparser-versions.json`
112+
- Creates version-specific packages in `packages/deparser/versions/`
113+
- Sets up proper dependencies and npm tags for each PostgreSQL version
114+
115+
#### Build and Publish Individual Versions
116+
```bash
117+
# Navigate to a specific version directory
118+
cd packages/deparser/versions/17
119+
120+
# Build the package
121+
npm run build
122+
123+
# Publish with the correct tag
124+
npm publish --tag pg17
125+
```
126+
127+
#### Publish All Deparser Versions
128+
```bash
129+
cd packages/deparser
130+
131+
# Prepare all versions
132+
npm run prepare-versions
133+
134+
# Build and publish each version
135+
for version in versions/*/; do
136+
cd "$version"
137+
npm run build
138+
npm run publish:pkg # Uses the npmTag from config
139+
cd ..
140+
done
141+
```
142+
143+
### 3. Other Packages
144+
145+
For packages without multi-version publishing (utils, traverse, cli, etc.):
146+
147+
```bash
148+
cd packages/{package-name}
149+
npm run build
150+
npm publish
151+
```
152+
153+
## Lerna Publishing
154+
155+
For coordinated publishing across the entire monorepo:
156+
157+
```bash
158+
# Publish all packages that have changed
159+
lerna publish
160+
161+
# Publish with a specific version bump
162+
lerna publish major|minor|patch
163+
164+
# Publish from a specific branch (main only by default)
165+
lerna publish --allow-branch main
166+
```
167+
168+
The Lerna configuration (`lerna.json`) is set up with:
169+
- Independent versioning for each package
170+
- Conventional commits for automatic changelog generation
171+
- Restricted to publishing from the `main` branch
172+
173+
## Complete Publishing Procedure
174+
175+
### For a New Release
176+
177+
1. **Update version configuration** in `config/versions.json` if needed
178+
2. **Build the monorepo**:
179+
```bash
180+
yarn && yarn build
181+
```
182+
183+
3. **Prepare multi-version packages**:
184+
```bash
185+
# Parser versions
186+
cd packages/parser && npm run prepare-versions && cd ../..
187+
188+
# Deparser versions
189+
cd packages/deparser && npm run prepare-versions && cd ../..
190+
```
191+
192+
4. **Publish packages** (choose one approach):
193+
194+
**Option A: Individual package publishing**
195+
```bash
196+
# Publish parser versions
197+
cd packages/parser
198+
for version in versions/*/; do
199+
cd "$version" && npm run build && npm run publish:pkg && cd ..
200+
done
201+
cd ../..
202+
203+
# Publish deparser versions
204+
cd packages/deparser
205+
for version in versions/*/; do
206+
cd "$version" && npm run build && npm run publish:pkg && cd ..
207+
done
208+
cd ../..
209+
210+
# Publish other packages
211+
cd packages/utils && npm run build && npm publish && cd ../..
212+
cd packages/traverse && npm run build && npm publish && cd ../..
213+
# ... repeat for other packages
214+
```
215+
216+
**Option B: Lerna coordinated publishing**
217+
```bash
218+
lerna publish
219+
```
220+
221+
### For Emergency Patches
222+
223+
1. **Create a patch branch** from the target version
224+
2. **Apply fixes** to the relevant packages
225+
3. **Update version numbers** in `config/versions.json`
226+
4. **Follow the complete publishing procedure** above
227+
228+
## Troubleshooting
229+
230+
### Common Issues
231+
232+
**Build failures**: Ensure you've run `yarn && yarn build` in the root directory first.
233+
234+
**Version conflicts**: Check that `config/versions.json` has consistent version numbers across all packages.
235+
236+
**npm tag issues**: Verify that the npmTag in the configuration matches what you're publishing with.
237+
238+
**Permission errors**: Ensure you're logged into npm with an account that has publish permissions for the `@pgsql` scope and `pgsql-*` packages.
239+
240+
### Verification
241+
242+
After publishing, verify the packages are available:
243+
244+
```bash
245+
# Check latest versions
246+
npm view pgsql-parser dist-tags
247+
npm view pgsql-deparser dist-tags
248+
249+
# Check specific version tags
250+
npm view pgsql-parser@pg17
251+
npm view pgsql-deparser@pg17
252+
```
253+
254+
## Package Dependencies
255+
256+
The multi-version system maintains these relationships:
257+
- `pgsql-parser` depends on `libpg-query`, `pgsql-deparser`, and `@pgsql/types`
258+
- `pgsql-deparser` depends only on `@pgsql/types`
259+
- All versions must be compatible within the same PostgreSQL version
260+
261+
When updating versions, ensure all related packages are updated together to maintain compatibility.

0 commit comments

Comments
 (0)