diff --git a/PUBLISH.md b/PUBLISH.md index fda1f86..8077522 100644 --- a/PUBLISH.md +++ b/PUBLISH.md @@ -2,6 +2,21 @@ ## Automated Publishing (Recommended) +### Version Packages (libpg-query) +```bash +pnpm run publish:versions +``` + +This interactive script will: +- Check for uncommitted changes (will error if any exist) +- Let you select which versions to publish (or all) +- Also includes the full package (@libpg-query/parser) +- Ask for version bump type (patch or minor only) +- Ask if you want to skip the build step (useful if already built) +- Always run tests (even if build is skipped) +- Publish each selected version +- Optionally promote pg17 to latest + ### Types Packages ```bash pnpm run publish:types @@ -113,4 +128,32 @@ pnpm run publish:pkg npm install libpg-query@pg17 # PostgreSQL 17 specific npm install libpg-query@pg16 # PostgreSQL 16 specific npm install libpg-query # Latest/default version +``` + +## Full Package (@libpg-query/parser) + +### Quick Publish +```bash +cd full +pnpm version patch +git add . && git commit -m "release: bump @libpg-query/parser version" +pnpm build +pnpm test +pnpm publish --tag pg17 +``` + +### Promote to latest (optional) +```bash +npm dist-tag add @libpg-query/parser@pg17 latest +``` + +### What it does +- Publishes `@libpg-query/parser` with tag `pg17` +- Currently based on PostgreSQL 17 +- Includes full parser with all features + +### Install published package +```bash +npm install @libpg-query/parser@pg17 # PostgreSQL 17 specific +npm install @libpg-query/parser # Latest version ``` \ No newline at end of file diff --git a/README.md b/README.md index e2e92af..11aa3f6 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ Built to power [pgsql-parser](https://github.com/pyramation/pgsql-parser), this ## ๐Ÿš€ For Round-trip Codegen > ๐ŸŽฏ **Want to parse + deparse (full round trip)?** -> We highly recommend using [`pgsql-parser`](https://github.com/launchql/pgsql-parser) which leverages a pure TypeScript deparser that has been battle-tested against 21,000+ SQL statements and is built on top of libpg-query. +> We highly recommend using [`pgsql-parser`](https://github.com/launchql/pgsql-parser) which leverages a pure TypeScript deparser that has been battle-tested against 23,000+ SQL statements and is built on top of libpg-query. ## Installation diff --git a/full/README.md b/full/README.md index 1a31dd9..ffef7e2 100644 --- a/full/README.md +++ b/full/README.md @@ -35,7 +35,7 @@ Built to power [pgsql-parser](https://github.com/pyramation/pgsql-parser), this ## ๐Ÿš€ For Round-trip Codegen > ๐ŸŽฏ **Want to parse + deparse (full round trip)?** -> We highly recommend using [`pgsql-parser`](https://github.com/launchql/pgsql-parser) which leverages a pure TypeScript deparser that has been battle-tested against 21,000+ SQL statements and is built on top of libpg-query. +> We highly recommend using [`pgsql-parser`](https://github.com/launchql/pgsql-parser) which leverages a pure TypeScript deparser that has been battle-tested against 23,000+ SQL statements and is built on top of libpg-query. ## Installation diff --git a/full/package.json b/full/package.json index 26c93be..0b08b3c 100644 --- a/full/package.json +++ b/full/package.json @@ -1,6 +1,6 @@ { "name": "@libpg-query/parser", - "version": "17.5.1", + "version": "17.6.1", "description": "The real PostgreSQL query parser", "homepage": "https://github.com/launchql/libpg-query-node", "main": "./wasm/index.cjs", diff --git a/package.json b/package.json index 66afd46..5766b8c 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "prepare:enums": "node scripts/prepare-enums.js", "publish:types": "node scripts/publish-types.js", "publish:enums": "node scripts/publish-enums.js", + "publish:versions": "node scripts/publish-versions.js", "update:versions-types": "node scripts/update-versions-types.js" }, "devDependencies": { diff --git a/scripts/publish-single-version.js b/scripts/publish-single-version.js new file mode 100644 index 0000000..4dc0b50 --- /dev/null +++ b/scripts/publish-single-version.js @@ -0,0 +1,38 @@ +#!/usr/bin/env node + +const fs = require('fs'); +const path = require('path'); +const { execSync } = require('child_process'); + +const pkgPath = path.join(process.cwd(), 'package.json'); + +if (!fs.existsSync(pkgPath)) { + console.error('โŒ No package.json found in current directory.'); + process.exit(1); +} + +const original = JSON.parse(fs.readFileSync(pkgPath, 'utf8')); +const publishMeta = original['x-publish'] || {}; + +const publishName = publishMeta.publishName || 'libpg-query'; +const distTag = process.env.TAG || publishMeta.distTag || 'latest'; + +if (!original.name || !original.version) { + console.error('โŒ package.json must include name and version'); + process.exit(1); +} + +const modified = { ...original, name: publishName }; + +try { + console.log(`๐Ÿ“ฆ Publishing ${publishName}@${original.version} with tag '${distTag}'...`); + fs.writeFileSync(pkgPath, JSON.stringify(modified, null, 2)); + // npm OK here since it's version, not dist/ package... + execSync(`npm publish --tag ${distTag}`, { stdio: 'inherit' }); + console.log('โœ… Publish complete.'); +} catch (err) { + console.error('โŒ Publish failed:', err.message); +} finally { + fs.writeFileSync(pkgPath, JSON.stringify(original, null, 2)); + console.log('๐Ÿ”„ Restored original package.json'); +} diff --git a/scripts/publish-versions.js b/scripts/publish-versions.js old mode 100644 new mode 100755 index c1ad0aa..ed9d8e0 --- a/scripts/publish-versions.js +++ b/scripts/publish-versions.js @@ -3,35 +3,217 @@ const fs = require('fs'); const path = require('path'); const { execSync } = require('child_process'); +const readline = require('readline'); -const pkgPath = path.join(process.cwd(), 'package.json'); +const rl = readline.createInterface({ + input: process.stdin, + output: process.stdout +}); -if (!fs.existsSync(pkgPath)) { - console.error('โŒ No package.json found in current directory.'); - process.exit(1); -} +const question = (query) => new Promise((resolve) => rl.question(query, resolve)); -const original = JSON.parse(fs.readFileSync(pkgPath, 'utf8')); -const publishMeta = original['x-publish'] || {}; +async function main() { + console.log('๐Ÿš€ Version Packages Publishing Tool\n'); -const publishName = publishMeta.publishName || 'libpg-query'; -const distTag = process.env.TAG || publishMeta.distTag || 'latest'; + // Check for uncommitted changes + try { + execSync('git diff --quiet && git diff --cached --quiet'); + } catch (error) { + console.error('โŒ You have uncommitted changes. Please commit or stash them first.'); + process.exit(1); + } -if (!original.name || !original.version) { - console.error('โŒ package.json must include name and version'); - process.exit(1); -} + // Get all version directories + const versionsDir = path.join(__dirname, '..', 'versions'); + const versionDirs = fs.readdirSync(versionsDir) + .filter(dir => /^\d+$/.test(dir)) + .sort((a, b) => parseInt(b) - parseInt(a)); // Sort descending + + // Also check for full package + const fullPackagePath = path.join(__dirname, '..', 'full', 'package.json'); + const hasFullPackage = fs.existsSync(fullPackagePath); + + console.log('๐Ÿ“ฆ Available packages:'); + versionDirs.forEach(v => console.log(` - PostgreSQL ${v} (versions/${v})`)); + if (hasFullPackage) { + console.log(` - Full package (./full) - PostgreSQL 17`); + } + console.log(); + + // Ask which versions to publish + const publishAll = await question('Publish all packages? (y/N): '); + let selectedVersions = []; + let includeFullPackage = false; + + if (publishAll.toLowerCase() === 'y') { + selectedVersions = versionDirs; + includeFullPackage = hasFullPackage; + } else { + // Let user select versions + for (const version of versionDirs) { + const publish = await question(`Publish PostgreSQL ${version}? (y/N): `); + if (publish.toLowerCase() === 'y') { + selectedVersions.push(version); + } + } + + if (hasFullPackage) { + const publishFull = await question(`Publish full package (PostgreSQL 17)? (y/N): `); + includeFullPackage = publishFull.toLowerCase() === 'y'; + } + } + + if (selectedVersions.length === 0 && !includeFullPackage) { + console.log('\nโŒ No packages selected for publishing.'); + rl.close(); + return; + } + + // Ask for version bump type + console.log('\n๐Ÿ“ˆ Version bump type:'); + console.log(' 1. patch (0.0.x)'); + console.log(' 2. minor (0.x.0)'); + const bumpType = await question('Select bump type (1 or 2): '); + const bump = bumpType === '2' ? 'minor' : 'patch'; -const modified = { ...original, name: publishName }; - -try { - console.log(`๐Ÿ“ฆ Publishing ${publishName}@${original.version} with tag '${distTag}'...`); - fs.writeFileSync(pkgPath, JSON.stringify(modified, null, 2)); - execSync(`npm publish --tag ${distTag}`, { stdio: 'inherit' }); - console.log('โœ… Publish complete.'); -} catch (err) { - console.error('โŒ Publish failed:', err.message); -} finally { - fs.writeFileSync(pkgPath, JSON.stringify(original, null, 2)); - console.log('๐Ÿ”„ Restored original package.json'); + console.log(`\n๐Ÿ“‹ Will publish:`); + selectedVersions.forEach(v => console.log(` - PostgreSQL ${v} (${bump} bump)`)); + if (includeFullPackage) { + console.log(` - Full package (${bump} bump)`); + } + + // Ask about building + const skipBuild = await question('\nSkip build step? (y/N): '); + const shouldBuild = skipBuild.toLowerCase() !== 'y'; + + if (!shouldBuild) { + console.log('โš ๏ธ Build step will be skipped. Make sure packages are already built!'); + } + + const confirm = await question('\nProceed? (y/N): '); + if (confirm.toLowerCase() !== 'y') { + console.log('โŒ Publishing cancelled.'); + rl.close(); + return; + } + + console.log('\n๐Ÿ”จ Starting publish process...\n'); + + // Process each selected version + for (const version of selectedVersions) { + console.log(`\n๐Ÿ“ฆ Publishing PostgreSQL ${version}...`); + const versionPath = path.join(versionsDir, version); + + try { + // Version bump + console.log(` ๐Ÿ“ Bumping version (${bump})...`); + execSync(`pnpm version ${bump}`, { cwd: versionPath, stdio: 'inherit' }); + + // Commit + console.log(` ๐Ÿ’พ Committing version bump...`); + execSync(`git add package.json`, { cwd: versionPath }); + execSync(`git commit -m "release: bump libpg-query v${version} version"`, { stdio: 'inherit' }); + + // Build (if not skipped) + if (shouldBuild) { + console.log(` ๐Ÿ”จ Building...`); + execSync('pnpm build', { cwd: versionPath, stdio: 'inherit' }); + } else { + console.log(` โญ๏ธ Skipping build step`); + } + + // Test (always run) + console.log(` ๐Ÿงช Running tests...`); + execSync('pnpm test', { cwd: versionPath, stdio: 'inherit' }); + + // Publish + console.log(` ๐Ÿ“ค Publishing to npm...`); + execSync('pnpm run publish:pkg', { cwd: versionPath, stdio: 'inherit' }); + + console.log(` โœ… PostgreSQL ${version} published successfully!`); + } catch (error) { + console.error(` โŒ Failed to publish PostgreSQL ${version}:`, error.message); + const continuePublish = await question('Continue with other versions? (y/N): '); + if (continuePublish.toLowerCase() !== 'y') { + rl.close(); + process.exit(1); + } + } + } + + // Process full package if selected + if (includeFullPackage) { + console.log(`\n๐Ÿ“ฆ Publishing full package...`); + const fullPath = path.join(__dirname, '..', 'full'); + + try { + // Version bump + console.log(` ๐Ÿ“ Bumping version (${bump})...`); + execSync(`pnpm version ${bump}`, { cwd: fullPath, stdio: 'inherit' }); + + // Commit + console.log(` ๐Ÿ’พ Committing version bump...`); + execSync(`git add package.json`, { cwd: fullPath }); + execSync(`git commit -m "release: bump @libpg-query/parser version"`, { stdio: 'inherit' }); + + // Build (if not skipped) + if (shouldBuild) { + console.log(` ๐Ÿ”จ Building...`); + execSync('pnpm build', { cwd: fullPath, stdio: 'inherit' }); + } else { + console.log(` โญ๏ธ Skipping build step`); + } + + // Test (always run) + console.log(` ๐Ÿงช Running tests...`); + execSync('pnpm test', { cwd: fullPath, stdio: 'inherit' }); + + // Publish with pg17 tag + console.log(` ๐Ÿ“ค Publishing to npm with pg17 tag...`); + // use npm so staged changes are OK + execSync('npm publish --tag pg17', { cwd: fullPath, stdio: 'inherit' }); + + console.log(` โœ… Full package published successfully with pg17 tag!`); + } catch (error) { + console.error(` โŒ Failed to publish full package:`, error.message); + } + } + + // Ask about promoting to latest + if (selectedVersions.includes('17') || includeFullPackage) { + console.log('\n๐Ÿท๏ธ Tag Management'); + + if (selectedVersions.includes('17')) { + const promoteVersions = await question('Promote libpg-query@pg17 to latest? (y/N): '); + if (promoteVersions.toLowerCase() === 'y') { + try { + execSync('npm dist-tag add libpg-query@pg17 latest', { stdio: 'inherit' }); + console.log('โœ… libpg-query@pg17 promoted to latest'); + } catch (error) { + console.error('โŒ Failed to promote tag:', error.message); + } + } + } + + if (includeFullPackage) { + const promoteFullPackage = await question('Promote @libpg-query/parser@pg17 to latest? (y/N): '); + if (promoteFullPackage.toLowerCase() === 'y') { + try { + execSync('npm dist-tag add @libpg-query/parser@pg17 latest', { stdio: 'inherit' }); + console.log('โœ… @libpg-query/parser@pg17 promoted to latest'); + } catch (error) { + console.error('โŒ Failed to promote tag:', error.message); + } + } + } + } + + console.log('\nโœจ Publishing complete!'); + rl.close(); } + +main().catch(error => { + console.error('โŒ Error:', error); + rl.close(); + process.exit(1); +}); \ No newline at end of file diff --git a/versions/13/README.md b/versions/13/README.md index f703732..745a2ae 100644 --- a/versions/13/README.md +++ b/versions/13/README.md @@ -35,7 +35,7 @@ Built to power [pgsql-parser](https://github.com/pyramation/pgsql-parser), this ## ๐Ÿš€ For Round-trip Codegen > ๐ŸŽฏ **Want to parse + deparse (full round trip)?** -> We highly recommend using [`pgsql-parser`](https://github.com/launchql/pgsql-parser) which leverages a pure TypeScript deparser that has been battle-tested against 21,000+ SQL statements and is built on top of libpg-query. +> We highly recommend using [`pgsql-parser`](https://github.com/launchql/pgsql-parser) which leverages a pure TypeScript deparser that has been battle-tested against 23,000+ SQL statements and is built on top of libpg-query. ## Installation diff --git a/versions/13/package.json b/versions/13/package.json index 90906ad..f44e132 100644 --- a/versions/13/package.json +++ b/versions/13/package.json @@ -1,6 +1,6 @@ { "name": "@libpg-query/v13", - "version": "13.4.1", + "version": "13.5.1", "description": "The real PostgreSQL query parser", "homepage": "https://github.com/launchql/libpg-query-node", "main": "./wasm/index.cjs", @@ -22,7 +22,7 @@ "clean": "pnpm wasm:clean && rimraf wasm/*.js wasm/*.cjs wasm/*.d.ts", "build:js": "node scripts/build.js", "build": "pnpm clean && pnpm wasm:build && pnpm build:js", - "publish:pkg": "node ../../scripts/publish-versions.js", + "publish:pkg": "node ../../scripts/publish-single-version.js", "wasm:make": "docker run --rm -v $(pwd):/src -u $(id -u):$(id -g) -e EMSCRIPTEN=1 emscripten/emsdk emmake make", "wasm:build": "pnpm wasm:make build", "wasm:rebuild": "pnpm wasm:make rebuild", @@ -49,4 +49,4 @@ "plpgsql", "database" ] -} +} \ No newline at end of file diff --git a/versions/14/README.md b/versions/14/README.md index f703732..745a2ae 100644 --- a/versions/14/README.md +++ b/versions/14/README.md @@ -35,7 +35,7 @@ Built to power [pgsql-parser](https://github.com/pyramation/pgsql-parser), this ## ๐Ÿš€ For Round-trip Codegen > ๐ŸŽฏ **Want to parse + deparse (full round trip)?** -> We highly recommend using [`pgsql-parser`](https://github.com/launchql/pgsql-parser) which leverages a pure TypeScript deparser that has been battle-tested against 21,000+ SQL statements and is built on top of libpg-query. +> We highly recommend using [`pgsql-parser`](https://github.com/launchql/pgsql-parser) which leverages a pure TypeScript deparser that has been battle-tested against 23,000+ SQL statements and is built on top of libpg-query. ## Installation diff --git a/versions/14/package.json b/versions/14/package.json index cf555a3..6ed8606 100644 --- a/versions/14/package.json +++ b/versions/14/package.json @@ -1,6 +1,6 @@ { "name": "@libpg-query/v14", - "version": "14.1.1", + "version": "14.2.1", "description": "The real PostgreSQL query parser", "homepage": "https://github.com/launchql/libpg-query-node", "main": "./wasm/index.cjs", @@ -22,7 +22,7 @@ "clean": "pnpm wasm:clean && rimraf wasm/*.js wasm/*.cjs wasm/*.d.ts", "build:js": "node scripts/build.js", "build": "pnpm clean && pnpm wasm:build && pnpm build:js", - "publish:pkg": "node ../../scripts/publish-versions.js", + "publish:pkg": "node ../../scripts/publish-single-version.js", "wasm:make": "docker run --rm -v $(pwd):/src -u $(id -u):$(id -g) emscripten/emsdk emmake make", "wasm:build": "pnpm wasm:make build", "wasm:rebuild": "pnpm wasm:make rebuild", @@ -49,4 +49,4 @@ "plpgsql", "database" ] -} +} \ No newline at end of file diff --git a/versions/15/README.md b/versions/15/README.md index f703732..745a2ae 100644 --- a/versions/15/README.md +++ b/versions/15/README.md @@ -35,7 +35,7 @@ Built to power [pgsql-parser](https://github.com/pyramation/pgsql-parser), this ## ๐Ÿš€ For Round-trip Codegen > ๐ŸŽฏ **Want to parse + deparse (full round trip)?** -> We highly recommend using [`pgsql-parser`](https://github.com/launchql/pgsql-parser) which leverages a pure TypeScript deparser that has been battle-tested against 21,000+ SQL statements and is built on top of libpg-query. +> We highly recommend using [`pgsql-parser`](https://github.com/launchql/pgsql-parser) which leverages a pure TypeScript deparser that has been battle-tested against 23,000+ SQL statements and is built on top of libpg-query. ## Installation diff --git a/versions/15/package.json b/versions/15/package.json index ed17f9e..20b7cc0 100644 --- a/versions/15/package.json +++ b/versions/15/package.json @@ -1,6 +1,6 @@ { "name": "@libpg-query/v15", - "version": "15.3.1", + "version": "15.4.1", "description": "The real PostgreSQL query parser", "homepage": "https://github.com/launchql/libpg-query-node", "main": "./wasm/index.cjs", @@ -22,7 +22,7 @@ "clean": "pnpm wasm:clean && rimraf wasm/*.js wasm/*.cjs wasm/*.d.ts", "build:js": "node scripts/build.js", "build": "pnpm clean && pnpm wasm:build && pnpm build:js", - "publish:pkg": "node ../../scripts/publish-versions.js", + "publish:pkg": "node ../../scripts/publish-single-version.js", "wasm:make": "docker run --rm -v $(pwd):/src -u $(id -u):$(id -g) emscripten/emsdk emmake make", "wasm:build": "pnpm wasm:make build", "wasm:rebuild": "pnpm wasm:make rebuild", @@ -49,4 +49,4 @@ "plpgsql", "database" ] -} +} \ No newline at end of file diff --git a/versions/16/README.md b/versions/16/README.md index f703732..745a2ae 100644 --- a/versions/16/README.md +++ b/versions/16/README.md @@ -35,7 +35,7 @@ Built to power [pgsql-parser](https://github.com/pyramation/pgsql-parser), this ## ๐Ÿš€ For Round-trip Codegen > ๐ŸŽฏ **Want to parse + deparse (full round trip)?** -> We highly recommend using [`pgsql-parser`](https://github.com/launchql/pgsql-parser) which leverages a pure TypeScript deparser that has been battle-tested against 21,000+ SQL statements and is built on top of libpg-query. +> We highly recommend using [`pgsql-parser`](https://github.com/launchql/pgsql-parser) which leverages a pure TypeScript deparser that has been battle-tested against 23,000+ SQL statements and is built on top of libpg-query. ## Installation diff --git a/versions/16/package.json b/versions/16/package.json index 69fdff3..8fcf62f 100644 --- a/versions/16/package.json +++ b/versions/16/package.json @@ -1,6 +1,6 @@ { "name": "@libpg-query/v16", - "version": "16.4.1", + "version": "16.5.1", "description": "The real PostgreSQL query parser", "homepage": "https://github.com/launchql/libpg-query-node", "main": "./wasm/index.cjs", @@ -22,7 +22,7 @@ "clean": "pnpm wasm:clean && rimraf wasm/*.js wasm/*.cjs wasm/*.d.ts", "build:js": "node scripts/build.js", "build": "pnpm clean && pnpm wasm:build && pnpm build:js", - "publish:pkg": "node ../../scripts/publish-versions.js", + "publish:pkg": "node ../../scripts/publish-single-version.js", "wasm:make": "docker run --rm -v $(pwd):/src -u $(id -u):$(id -g) emscripten/emsdk emmake make", "wasm:build": "pnpm wasm:make build", "wasm:rebuild": "pnpm wasm:make rebuild", @@ -49,4 +49,4 @@ "plpgsql", "database" ] -} +} \ No newline at end of file diff --git a/versions/17/README.md b/versions/17/README.md index f703732..745a2ae 100644 --- a/versions/17/README.md +++ b/versions/17/README.md @@ -35,7 +35,7 @@ Built to power [pgsql-parser](https://github.com/pyramation/pgsql-parser), this ## ๐Ÿš€ For Round-trip Codegen > ๐ŸŽฏ **Want to parse + deparse (full round trip)?** -> We highly recommend using [`pgsql-parser`](https://github.com/launchql/pgsql-parser) which leverages a pure TypeScript deparser that has been battle-tested against 21,000+ SQL statements and is built on top of libpg-query. +> We highly recommend using [`pgsql-parser`](https://github.com/launchql/pgsql-parser) which leverages a pure TypeScript deparser that has been battle-tested against 23,000+ SQL statements and is built on top of libpg-query. ## Installation diff --git a/versions/17/package.json b/versions/17/package.json index 10b20af..e7d9cf3 100644 --- a/versions/17/package.json +++ b/versions/17/package.json @@ -1,6 +1,6 @@ { "name": "@libpg-query/v17", - "version": "17.4.1", + "version": "17.5.1", "description": "The real PostgreSQL query parser", "homepage": "https://github.com/launchql/libpg-query-node", "main": "./wasm/index.cjs", @@ -22,7 +22,7 @@ "clean": "pnpm wasm:clean && rimraf wasm/*.js wasm/*.cjs wasm/*.d.ts", "build:js": "node scripts/build.js", "build": "pnpm clean && pnpm wasm:build && pnpm build:js", - "publish:pkg": "node ../../scripts/publish-versions.js", + "publish:pkg": "node ../../scripts/publish-single-version.js", "wasm:make": "docker run --rm -v $(pwd):/src -u $(id -u):$(id -g) emscripten/emsdk emmake make", "wasm:build": "pnpm wasm:make build", "wasm:rebuild": "pnpm wasm:make rebuild", @@ -49,4 +49,4 @@ "plpgsql", "database" ] -} +} \ No newline at end of file