This guide covers the multi-version publishing workflow for the pgsql-parser monorepo, which supports PostgreSQL versions 13-17 with version-specific npm tags.
Before publishing any packages, you must build the entire monorepo:
pnpm install && pnpm buildThis installs all dependencies and builds all packages in the correct order using Lerna.
The pgsql-parser project uses a sophisticated multi-version publishing system to support different PostgreSQL versions. Each PostgreSQL version has its own:
- Version numbers for each package (parser, deparser, types)
- npm tag for publishing (pg13, pg14, pg15, pg16, pg17)
- libpg-query dependency version
All version mappings are centrally managed in config/versions.json:
{
"versions": {
"13": {
"libpg-query": "13.5.7",
"pgsql-parser": "13.18.0",
"pgsql-deparser": "13.17.0",
"@pgsql/types": "13.11.1",
"npmTag": "pg13"
},
"17": {
"libpg-query": "17.5.5",
"pgsql-parser": "17.7.5",
"pgsql-deparser": "17.8.3",
"@pgsql/types": "17.6.1",
"npmTag": "pg17"
}
}
}In the root:
pnpm bump-versions
The deparser package uses a template-based approach for multi-version publishing.
cd packages/deparser
npm run prepare-versionsThis runs a complete preparation pipeline:
strip-transformer-types- Clean up transformer typesstrip-direct-transformer-types- Clean up direct transformer typesstrip-deparser-types- Clean up deparser typesorganize-transformers- Organize transformers by versiongenerate-version-deparsers- Generate version-specific deparsersgenerate-packages- Generate package.json files for each version
The generate-packages script (scripts/generate-version-packages.ts):
- Uses the template from
config/deparser-versions.json - Creates version-specific packages in
packages/deparser/versions/ - Sets up proper dependencies and npm tags for each PostgreSQL version
# Navigate to a specific version directory
cd packages/deparser/versions/13
# Build the package
npm run build
# dist
cd dist/
# Publish with the correct tag
npm publish --tag pg13**I do 13,14,15,16... since 17 was already publish from the root pnpm lerna publish
Now go to run, fetch fresh versions for config again:
pnpm bump-versions
cd packages/deparser
# Prepare all versions
npm run prepare-versions
# Build and publish each version
for version in versions/*/; do
cd "$version"
npm run build
cd dist/
npm run publish:pkg # Uses the npmTag from config
cd ..
doneThe parser package uses a version preparation script to generate multiple version-specific packages.
cd packages/parser
npm run prepare-versionsThis script (scripts/prepare-versions.ts):
- Reads version configuration from
config/versions.json - Creates version-specific directories in
packages/parser/versions/ - Generates
package.json,tsconfig.json, and source files for each PostgreSQL version - Each version gets its own libpg-query dependency and npm tag
# Navigate to a specific version directory
cd packages/parser/versions/13
# Build the package
npm run build
# cd to dist/
cd dist/
# Publish with the correct tag
npm publish --tag pg13cd packages/parser
# Prepare all versions
npm run prepare-versions
# Build and publish each version
for version in versions/*/; do
cd "$version"
npm run build
npm run publish:pkg # Uses the npmTag from config
cd ..
done