|
| 1 | +# Publishing Guide for libpg-query |
| 2 | + |
| 3 | +This guide explains how to publish multiple PostgreSQL version packages under the unified "libpg-query" name using dist-tags. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +The repository contains multiple PostgreSQL version packages: |
| 8 | +- `@libpg-query/v13` → Published as `libpg-query@pg13` |
| 9 | +- `@libpg-query/v14` → Published as `libpg-query@pg14` |
| 10 | +- `@libpg-query/v15` → Published as `libpg-query@pg15` |
| 11 | +- `@libpg-query/v16` → Published as `libpg-query@pg16` |
| 12 | +- `@libpg-query/v17` → Published as `libpg-query@pg17` |
| 13 | + |
| 14 | +## Quick Start |
| 15 | + |
| 16 | +### Test Publishing (Dry Run) |
| 17 | +```bash |
| 18 | +# Test all versions |
| 19 | +pnpm publish:dry-run |
| 20 | + |
| 21 | +# Test specific version |
| 22 | +node scripts/publish-versions.js --dry-run --versions "17" |
| 23 | +``` |
| 24 | + |
| 25 | +### Publish All Versions |
| 26 | +```bash |
| 27 | +pnpm publish:versions |
| 28 | +``` |
| 29 | + |
| 30 | +### Publish Specific Version |
| 31 | +```bash |
| 32 | +# Publish PostgreSQL 17 version |
| 33 | +pnpm publish:specific 17 |
| 34 | + |
| 35 | +# Or directly with the script |
| 36 | +node scripts/publish-versions.js --versions "17" |
| 37 | +``` |
| 38 | + |
| 39 | +## Publishing Examples |
| 40 | + |
| 41 | +### Example 1: Publishing a Single Version with Default Versioning |
| 42 | +```bash |
| 43 | +# Publish PostgreSQL 17 version with default version (17.0.0) |
| 44 | +node scripts/publish-versions.js --versions "17" |
| 45 | +``` |
| 46 | + |
| 47 | +**What happens:** |
| 48 | +1. Script backs up `versions/17/package.json` |
| 49 | +2. Temporarily changes name from `@libpg-query/v17` to `libpg-query` |
| 50 | +3. Sets version to `17.0.0` |
| 51 | +4. Runs `pnpm build` in `versions/17/` |
| 52 | +5. Publishes with `pnpm publish --tag pg17` |
| 53 | +6. Restores original `package.json` |
| 54 | + |
| 55 | +**Result:** Users can install with `npm install libpg-query@pg17` |
| 56 | + |
| 57 | +### Example 2: Publishing with Custom Version |
| 58 | +```bash |
| 59 | +# Publish PostgreSQL 16 version with custom version 1.5.2 |
| 60 | +node scripts/publish-versions.js --versions "16" --set-version "1.5.2" |
| 61 | +``` |
| 62 | + |
| 63 | +**What happens:** |
| 64 | +1. Same process as Example 1, but sets version to `1.5.2` instead of `16.0.0` |
| 65 | +2. Published as `libpg-query@pg16` with version `1.5.2` |
| 66 | + |
| 67 | +**Result:** Users can install with `npm install libpg-query@pg16` and get version `1.5.2` |
| 68 | + |
| 69 | +### Example 3: Publishing Multiple Versions |
| 70 | +```bash |
| 71 | +# Publish PostgreSQL 16 and 17 versions |
| 72 | +node scripts/publish-versions.js --versions "16,17" --set-version "2.0.0" |
| 73 | +``` |
| 74 | + |
| 75 | +**What happens:** |
| 76 | +1. Processes both version 16 and 17 packages |
| 77 | +2. Both get published with version `2.0.0` |
| 78 | +3. Published as `libpg-query@pg16` and `libpg-query@pg17` |
| 79 | + |
| 80 | +### Example 4: Skip Build Step (Pre-built Packages) |
| 81 | +```bash |
| 82 | +# Publish without building (assumes already built) |
| 83 | +node scripts/publish-versions.js --versions "17" --skip-build |
| 84 | +``` |
| 85 | + |
| 86 | +**Use case:** When packages are already built and you just want to publish. |
| 87 | + |
| 88 | +## Version Management |
| 89 | + |
| 90 | +### Default Versioning |
| 91 | +- **Pattern:** `{major}.0.0` where major matches the PostgreSQL version |
| 92 | +- **Examples:** |
| 93 | + - PostgreSQL 13 → `13.0.0` |
| 94 | + - PostgreSQL 17 → `17.0.0` |
| 95 | + |
| 96 | +### Custom Versioning |
| 97 | +Use `--set-version` to specify exact version: |
| 98 | +```bash |
| 99 | +node scripts/publish-versions.js --versions "17" --set-version "1.2.3" |
| 100 | +``` |
| 101 | + |
| 102 | +### Dist-Tags |
| 103 | +- **Format:** `pg{version}` |
| 104 | +- **Examples:** `pg13`, `pg14`, `pg15`, `pg16`, `pg17` |
| 105 | +- **Purpose:** Allows users to install specific PostgreSQL versions |
| 106 | + |
| 107 | +## Installation After Publishing |
| 108 | + |
| 109 | +Once published, users can install specific PostgreSQL versions: |
| 110 | + |
| 111 | +```bash |
| 112 | +# Install PostgreSQL 17 parser |
| 113 | +npm install libpg-query@pg17 |
| 114 | + |
| 115 | +# Install PostgreSQL 16 parser |
| 116 | +npm install libpg-query@pg16 |
| 117 | + |
| 118 | +# Install PostgreSQL 15 parser |
| 119 | +npm install libpg-query@pg15 |
| 120 | + |
| 121 | +# Install PostgreSQL 14 parser |
| 122 | +npm install libpg-query@pg14 |
| 123 | + |
| 124 | +# Install PostgreSQL 13 parser |
| 125 | +npm install libpg-query@pg13 |
| 126 | +``` |
| 127 | + |
| 128 | +## Workflow Details |
| 129 | + |
| 130 | +### What the Script Does |
| 131 | + |
| 132 | +1. **Discovery:** Automatically finds all version packages in `versions/` directory |
| 133 | +2. **Backup:** Creates `.backup` copy of each `package.json` |
| 134 | +3. **Modify:** Temporarily changes package name to `libpg-query` and sets version |
| 135 | +4. **Build:** Runs `pnpm build` (unless `--skip-build`) |
| 136 | +5. **Publish:** Uses `pnpm publish --tag pg{version}` |
| 137 | +6. **Restore:** Returns `package.json` to original state |
| 138 | +7. **Cleanup:** Removes backup files |
| 139 | + |
| 140 | +### Safety Features |
| 141 | + |
| 142 | +- **Dry-run mode:** Test without publishing (`--dry-run`) |
| 143 | +- **Backup/restore:** Original `package.json` files are never permanently modified |
| 144 | +- **Error handling:** Failed publishes don't affect other versions |
| 145 | +- **Confirmation:** 5-second delay before actual publishing |
| 146 | +- **Selective publishing:** Choose specific versions with `--versions` |
| 147 | + |
| 148 | +## Troubleshooting |
| 149 | + |
| 150 | +### Common Issues |
| 151 | + |
| 152 | +**Issue:** "Package already exists" |
| 153 | +```bash |
| 154 | +# Solution: Use a new version number |
| 155 | +node scripts/publish-versions.js --versions "17" --set-version "1.0.1" |
| 156 | +``` |
| 157 | + |
| 158 | +**Issue:** Build fails |
| 159 | +```bash |
| 160 | +# Solution: Skip build if already built |
| 161 | +node scripts/publish-versions.js --versions "17" --skip-build |
| 162 | +``` |
| 163 | + |
| 164 | +**Issue:** Want to test first |
| 165 | +```bash |
| 166 | +# Solution: Always use dry-run first |
| 167 | +node scripts/publish-versions.js --dry-run --versions "17" --set-version "1.0.1" |
| 168 | +``` |
| 169 | + |
| 170 | +### Checking Published Packages |
| 171 | + |
| 172 | +```bash |
| 173 | +# Check what versions are available |
| 174 | +npm view libpg-query dist-tags |
| 175 | + |
| 176 | +# Check specific version info |
| 177 | +npm view libpg-query@pg17 |
| 178 | +``` |
| 179 | + |
| 180 | +## NPM Scripts |
| 181 | + |
| 182 | +The following convenience scripts are available in `package.json`: |
| 183 | + |
| 184 | +```bash |
| 185 | +# Test all versions (dry-run) |
| 186 | +pnpm publish:dry-run |
| 187 | + |
| 188 | +# Publish all versions |
| 189 | +pnpm publish:versions |
| 190 | + |
| 191 | +# Publish specific versions (you provide the version list) |
| 192 | +pnpm publish:specific 16,17 |
| 193 | +``` |
| 194 | + |
| 195 | +## Advanced Usage |
| 196 | + |
| 197 | +### Publishing Workflow for New Release |
| 198 | + |
| 199 | +1. **Update versions in each package** (if needed) |
| 200 | +2. **Build all packages:** |
| 201 | + ```bash |
| 202 | + pnpm build:all |
| 203 | + ``` |
| 204 | +3. **Test publishing:** |
| 205 | + ```bash |
| 206 | + pnpm publish:dry-run |
| 207 | + ``` |
| 208 | +4. **Publish specific versions:** |
| 209 | + ```bash |
| 210 | + node scripts/publish-versions.js --versions "16,17" --set-version "1.1.0" |
| 211 | + ``` |
| 212 | + |
| 213 | +### Batch Publishing with Different Versions |
| 214 | + |
| 215 | +```bash |
| 216 | +# Publish v17 with version 2.0.0 |
| 217 | +node scripts/publish-versions.js --versions "17" --set-version "2.0.0" |
| 218 | + |
| 219 | +# Publish v16 with version 1.9.0 |
| 220 | +node scripts/publish-versions.js --versions "16" --set-version "1.9.0" |
| 221 | +``` |
| 222 | + |
| 223 | +This allows different PostgreSQL versions to have different semantic versions while maintaining the dist-tag system. |
0 commit comments