Skip to content

Commit b3b658f

Browse files
authored
Merge pull request #123 from launchql/versions
Versions
2 parents 5cf69aa + 9c1ca92 commit b3b658f

File tree

17 files changed

+312
-48
lines changed

17 files changed

+312
-48
lines changed

β€ŽPUBLISH.mdβ€Ž

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,21 @@
22

33
## Automated Publishing (Recommended)
44

5+
### Version Packages (libpg-query)
6+
```bash
7+
pnpm run publish:versions
8+
```
9+
10+
This interactive script will:
11+
- Check for uncommitted changes (will error if any exist)
12+
- Let you select which versions to publish (or all)
13+
- Also includes the full package (@libpg-query/parser)
14+
- Ask for version bump type (patch or minor only)
15+
- Ask if you want to skip the build step (useful if already built)
16+
- Always run tests (even if build is skipped)
17+
- Publish each selected version
18+
- Optionally promote pg17 to latest
19+
520
### Types Packages
621
```bash
722
pnpm run publish:types
@@ -113,4 +128,32 @@ pnpm run publish:pkg
113128
npm install libpg-query@pg17 # PostgreSQL 17 specific
114129
npm install libpg-query@pg16 # PostgreSQL 16 specific
115130
npm install libpg-query # Latest/default version
131+
```
132+
133+
## Full Package (@libpg-query/parser)
134+
135+
### Quick Publish
136+
```bash
137+
cd full
138+
pnpm version patch
139+
git add . && git commit -m "release: bump @libpg-query/parser version"
140+
pnpm build
141+
pnpm test
142+
pnpm publish --tag pg17
143+
```
144+
145+
### Promote to latest (optional)
146+
```bash
147+
npm dist-tag add @libpg-query/parser@pg17 latest
148+
```
149+
150+
### What it does
151+
- Publishes `@libpg-query/parser` with tag `pg17`
152+
- Currently based on PostgreSQL 17
153+
- Includes full parser with all features
154+
155+
### Install published package
156+
```bash
157+
npm install @libpg-query/parser@pg17 # PostgreSQL 17 specific
158+
npm install @libpg-query/parser # Latest version
116159
```

β€ŽREADME.mdβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Built to power [pgsql-parser](https://github.com/pyramation/pgsql-parser), this
3535
## πŸš€ For Round-trip Codegen
3636

3737
> 🎯 **Want to parse + deparse (full round trip)?**
38-
> 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.
38+
> 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.
3939
4040
## Installation
4141

β€Žfull/README.mdβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Built to power [pgsql-parser](https://github.com/pyramation/pgsql-parser), this
3535
## πŸš€ For Round-trip Codegen
3636

3737
> 🎯 **Want to parse + deparse (full round trip)?**
38-
> 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.
38+
> 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.
3939
4040
## Installation
4141

β€Žfull/package.jsonβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@libpg-query/parser",
3-
"version": "17.5.1",
3+
"version": "17.6.1",
44
"description": "The real PostgreSQL query parser",
55
"homepage": "https://github.com/launchql/libpg-query-node",
66
"main": "./wasm/index.cjs",

β€Žpackage.jsonβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"prepare:enums": "node scripts/prepare-enums.js",
1919
"publish:types": "node scripts/publish-types.js",
2020
"publish:enums": "node scripts/publish-enums.js",
21+
"publish:versions": "node scripts/publish-versions.js",
2122
"update:versions-types": "node scripts/update-versions-types.js"
2223
},
2324
"devDependencies": {
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env node
2+
3+
const fs = require('fs');
4+
const path = require('path');
5+
const { execSync } = require('child_process');
6+
7+
const pkgPath = path.join(process.cwd(), 'package.json');
8+
9+
if (!fs.existsSync(pkgPath)) {
10+
console.error('❌ No package.json found in current directory.');
11+
process.exit(1);
12+
}
13+
14+
const original = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
15+
const publishMeta = original['x-publish'] || {};
16+
17+
const publishName = publishMeta.publishName || 'libpg-query';
18+
const distTag = process.env.TAG || publishMeta.distTag || 'latest';
19+
20+
if (!original.name || !original.version) {
21+
console.error('❌ package.json must include name and version');
22+
process.exit(1);
23+
}
24+
25+
const modified = { ...original, name: publishName };
26+
27+
try {
28+
console.log(`πŸ“¦ Publishing ${publishName}@${original.version} with tag '${distTag}'...`);
29+
fs.writeFileSync(pkgPath, JSON.stringify(modified, null, 2));
30+
// npm OK here since it's version, not dist/ package...
31+
execSync(`npm publish --tag ${distTag}`, { stdio: 'inherit' });
32+
console.log('βœ… Publish complete.');
33+
} catch (err) {
34+
console.error('❌ Publish failed:', err.message);
35+
} finally {
36+
fs.writeFileSync(pkgPath, JSON.stringify(original, null, 2));
37+
console.log('πŸ”„ Restored original package.json');
38+
}

β€Žscripts/publish-versions.jsβ€Ž

100644100755
Lines changed: 207 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,217 @@
33
const fs = require('fs');
44
const path = require('path');
55
const { execSync } = require('child_process');
6+
const readline = require('readline');
67

7-
const pkgPath = path.join(process.cwd(), 'package.json');
8+
const rl = readline.createInterface({
9+
input: process.stdin,
10+
output: process.stdout
11+
});
812

9-
if (!fs.existsSync(pkgPath)) {
10-
console.error('❌ No package.json found in current directory.');
11-
process.exit(1);
12-
}
13+
const question = (query) => new Promise((resolve) => rl.question(query, resolve));
1314

14-
const original = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
15-
const publishMeta = original['x-publish'] || {};
15+
async function main() {
16+
console.log('πŸš€ Version Packages Publishing Tool\n');
1617

17-
const publishName = publishMeta.publishName || 'libpg-query';
18-
const distTag = process.env.TAG || publishMeta.distTag || 'latest';
18+
// Check for uncommitted changes
19+
try {
20+
execSync('git diff --quiet && git diff --cached --quiet');
21+
} catch (error) {
22+
console.error('❌ You have uncommitted changes. Please commit or stash them first.');
23+
process.exit(1);
24+
}
1925

20-
if (!original.name || !original.version) {
21-
console.error('❌ package.json must include name and version');
22-
process.exit(1);
23-
}
26+
// Get all version directories
27+
const versionsDir = path.join(__dirname, '..', 'versions');
28+
const versionDirs = fs.readdirSync(versionsDir)
29+
.filter(dir => /^\d+$/.test(dir))
30+
.sort((a, b) => parseInt(b) - parseInt(a)); // Sort descending
31+
32+
// Also check for full package
33+
const fullPackagePath = path.join(__dirname, '..', 'full', 'package.json');
34+
const hasFullPackage = fs.existsSync(fullPackagePath);
35+
36+
console.log('πŸ“¦ Available packages:');
37+
versionDirs.forEach(v => console.log(` - PostgreSQL ${v} (versions/${v})`));
38+
if (hasFullPackage) {
39+
console.log(` - Full package (./full) - PostgreSQL 17`);
40+
}
41+
console.log();
42+
43+
// Ask which versions to publish
44+
const publishAll = await question('Publish all packages? (y/N): ');
45+
let selectedVersions = [];
46+
let includeFullPackage = false;
47+
48+
if (publishAll.toLowerCase() === 'y') {
49+
selectedVersions = versionDirs;
50+
includeFullPackage = hasFullPackage;
51+
} else {
52+
// Let user select versions
53+
for (const version of versionDirs) {
54+
const publish = await question(`Publish PostgreSQL ${version}? (y/N): `);
55+
if (publish.toLowerCase() === 'y') {
56+
selectedVersions.push(version);
57+
}
58+
}
59+
60+
if (hasFullPackage) {
61+
const publishFull = await question(`Publish full package (PostgreSQL 17)? (y/N): `);
62+
includeFullPackage = publishFull.toLowerCase() === 'y';
63+
}
64+
}
65+
66+
if (selectedVersions.length === 0 && !includeFullPackage) {
67+
console.log('\n❌ No packages selected for publishing.');
68+
rl.close();
69+
return;
70+
}
71+
72+
// Ask for version bump type
73+
console.log('\nπŸ“ˆ Version bump type:');
74+
console.log(' 1. patch (0.0.x)');
75+
console.log(' 2. minor (0.x.0)');
76+
const bumpType = await question('Select bump type (1 or 2): ');
77+
const bump = bumpType === '2' ? 'minor' : 'patch';
2478

25-
const modified = { ...original, name: publishName };
26-
27-
try {
28-
console.log(`πŸ“¦ Publishing ${publishName}@${original.version} with tag '${distTag}'...`);
29-
fs.writeFileSync(pkgPath, JSON.stringify(modified, null, 2));
30-
execSync(`npm publish --tag ${distTag}`, { stdio: 'inherit' });
31-
console.log('βœ… Publish complete.');
32-
} catch (err) {
33-
console.error('❌ Publish failed:', err.message);
34-
} finally {
35-
fs.writeFileSync(pkgPath, JSON.stringify(original, null, 2));
36-
console.log('πŸ”„ Restored original package.json');
79+
console.log(`\nπŸ“‹ Will publish:`);
80+
selectedVersions.forEach(v => console.log(` - PostgreSQL ${v} (${bump} bump)`));
81+
if (includeFullPackage) {
82+
console.log(` - Full package (${bump} bump)`);
83+
}
84+
85+
// Ask about building
86+
const skipBuild = await question('\nSkip build step? (y/N): ');
87+
const shouldBuild = skipBuild.toLowerCase() !== 'y';
88+
89+
if (!shouldBuild) {
90+
console.log('⚠️ Build step will be skipped. Make sure packages are already built!');
91+
}
92+
93+
const confirm = await question('\nProceed? (y/N): ');
94+
if (confirm.toLowerCase() !== 'y') {
95+
console.log('❌ Publishing cancelled.');
96+
rl.close();
97+
return;
98+
}
99+
100+
console.log('\nπŸ”¨ Starting publish process...\n');
101+
102+
// Process each selected version
103+
for (const version of selectedVersions) {
104+
console.log(`\nπŸ“¦ Publishing PostgreSQL ${version}...`);
105+
const versionPath = path.join(versionsDir, version);
106+
107+
try {
108+
// Version bump
109+
console.log(` πŸ“ Bumping version (${bump})...`);
110+
execSync(`pnpm version ${bump}`, { cwd: versionPath, stdio: 'inherit' });
111+
112+
// Commit
113+
console.log(` πŸ’Ύ Committing version bump...`);
114+
execSync(`git add package.json`, { cwd: versionPath });
115+
execSync(`git commit -m "release: bump libpg-query v${version} version"`, { stdio: 'inherit' });
116+
117+
// Build (if not skipped)
118+
if (shouldBuild) {
119+
console.log(` πŸ”¨ Building...`);
120+
execSync('pnpm build', { cwd: versionPath, stdio: 'inherit' });
121+
} else {
122+
console.log(` ⏭️ Skipping build step`);
123+
}
124+
125+
// Test (always run)
126+
console.log(` πŸ§ͺ Running tests...`);
127+
execSync('pnpm test', { cwd: versionPath, stdio: 'inherit' });
128+
129+
// Publish
130+
console.log(` πŸ“€ Publishing to npm...`);
131+
execSync('pnpm run publish:pkg', { cwd: versionPath, stdio: 'inherit' });
132+
133+
console.log(` βœ… PostgreSQL ${version} published successfully!`);
134+
} catch (error) {
135+
console.error(` ❌ Failed to publish PostgreSQL ${version}:`, error.message);
136+
const continuePublish = await question('Continue with other versions? (y/N): ');
137+
if (continuePublish.toLowerCase() !== 'y') {
138+
rl.close();
139+
process.exit(1);
140+
}
141+
}
142+
}
143+
144+
// Process full package if selected
145+
if (includeFullPackage) {
146+
console.log(`\nπŸ“¦ Publishing full package...`);
147+
const fullPath = path.join(__dirname, '..', 'full');
148+
149+
try {
150+
// Version bump
151+
console.log(` πŸ“ Bumping version (${bump})...`);
152+
execSync(`pnpm version ${bump}`, { cwd: fullPath, stdio: 'inherit' });
153+
154+
// Commit
155+
console.log(` πŸ’Ύ Committing version bump...`);
156+
execSync(`git add package.json`, { cwd: fullPath });
157+
execSync(`git commit -m "release: bump @libpg-query/parser version"`, { stdio: 'inherit' });
158+
159+
// Build (if not skipped)
160+
if (shouldBuild) {
161+
console.log(` πŸ”¨ Building...`);
162+
execSync('pnpm build', { cwd: fullPath, stdio: 'inherit' });
163+
} else {
164+
console.log(` ⏭️ Skipping build step`);
165+
}
166+
167+
// Test (always run)
168+
console.log(` πŸ§ͺ Running tests...`);
169+
execSync('pnpm test', { cwd: fullPath, stdio: 'inherit' });
170+
171+
// Publish with pg17 tag
172+
console.log(` πŸ“€ Publishing to npm with pg17 tag...`);
173+
// use npm so staged changes are OK
174+
execSync('npm publish --tag pg17', { cwd: fullPath, stdio: 'inherit' });
175+
176+
console.log(` βœ… Full package published successfully with pg17 tag!`);
177+
} catch (error) {
178+
console.error(` ❌ Failed to publish full package:`, error.message);
179+
}
180+
}
181+
182+
// Ask about promoting to latest
183+
if (selectedVersions.includes('17') || includeFullPackage) {
184+
console.log('\n🏷️ Tag Management');
185+
186+
if (selectedVersions.includes('17')) {
187+
const promoteVersions = await question('Promote libpg-query@pg17 to latest? (y/N): ');
188+
if (promoteVersions.toLowerCase() === 'y') {
189+
try {
190+
execSync('npm dist-tag add libpg-query@pg17 latest', { stdio: 'inherit' });
191+
console.log('βœ… libpg-query@pg17 promoted to latest');
192+
} catch (error) {
193+
console.error('❌ Failed to promote tag:', error.message);
194+
}
195+
}
196+
}
197+
198+
if (includeFullPackage) {
199+
const promoteFullPackage = await question('Promote @libpg-query/parser@pg17 to latest? (y/N): ');
200+
if (promoteFullPackage.toLowerCase() === 'y') {
201+
try {
202+
execSync('npm dist-tag add @libpg-query/parser@pg17 latest', { stdio: 'inherit' });
203+
console.log('βœ… @libpg-query/parser@pg17 promoted to latest');
204+
} catch (error) {
205+
console.error('❌ Failed to promote tag:', error.message);
206+
}
207+
}
208+
}
209+
}
210+
211+
console.log('\n✨ Publishing complete!');
212+
rl.close();
37213
}
214+
215+
main().catch(error => {
216+
console.error('❌ Error:', error);
217+
rl.close();
218+
process.exit(1);
219+
});

β€Žversions/13/README.mdβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Built to power [pgsql-parser](https://github.com/pyramation/pgsql-parser), this
3535
## πŸš€ For Round-trip Codegen
3636

3737
> 🎯 **Want to parse + deparse (full round trip)?**
38-
> 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.
38+
> 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.
3939
4040
## Installation
4141

0 commit comments

Comments
Β (0)