Skip to content

Commit 3eef8a0

Browse files
committed
Versions
1 parent 8a06903 commit 3eef8a0

File tree

9 files changed

+274
-30
lines changed

9 files changed

+274
-30
lines changed

PUBLISH.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@
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+
- Build, test, and publish each selected version
16+
- Optionally promote pg17 to latest
17+
518
### Types Packages
619
```bash
720
pnpm run publish:types
@@ -113,4 +126,32 @@ pnpm run publish:pkg
113126
npm install libpg-query@pg17 # PostgreSQL 17 specific
114127
npm install libpg-query@pg16 # PostgreSQL 16 specific
115128
npm install libpg-query # Latest/default version
129+
```
130+
131+
## Full Package (@libpg-query/parser)
132+
133+
### Quick Publish
134+
```bash
135+
cd full
136+
pnpm version patch
137+
git add . && git commit -m "release: bump @libpg-query/parser version"
138+
pnpm build
139+
pnpm test
140+
pnpm publish --tag pg17
141+
```
142+
143+
### Promote to latest (optional)
144+
```bash
145+
npm dist-tag add @libpg-query/parser@pg17 latest
146+
```
147+
148+
### What it does
149+
- Publishes `@libpg-query/parser` with tag `pg17`
150+
- Currently based on PostgreSQL 17
151+
- Includes full parser with all features
152+
153+
### Install published package
154+
```bash
155+
npm install @libpg-query/parser@pg17 # PostgreSQL 17 specific
156+
npm install @libpg-query/parser # Latest version
116157
```

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": {

scripts/publish-single-version.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
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');
37+
}

scripts/publish-versions.js

100644100755
Lines changed: 190 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,200 @@
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+
}
2471

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');
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';
78+
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+
const confirm = await question('\nProceed? (y/N): ');
86+
if (confirm.toLowerCase() !== 'y') {
87+
console.log('❌ Publishing cancelled.');
88+
rl.close();
89+
return;
90+
}
91+
92+
console.log('\n🔨 Starting publish process...\n');
93+
94+
// Process each selected version
95+
for (const version of selectedVersions) {
96+
console.log(`\n📦 Publishing PostgreSQL ${version}...`);
97+
const versionPath = path.join(versionsDir, version);
98+
99+
try {
100+
// Version bump
101+
console.log(` 📝 Bumping version (${bump})...`);
102+
execSync(`pnpm version ${bump}`, { cwd: versionPath, stdio: 'inherit' });
103+
104+
// Commit
105+
console.log(` 💾 Committing version bump...`);
106+
execSync(`git add package.json`, { cwd: versionPath });
107+
execSync(`git commit -m "release: bump libpg-query v${version} version"`, { stdio: 'inherit' });
108+
109+
// Build
110+
console.log(` 🔨 Building...`);
111+
execSync('pnpm build', { cwd: versionPath, stdio: 'inherit' });
112+
113+
// Test
114+
console.log(` 🧪 Running tests...`);
115+
execSync('pnpm test', { cwd: versionPath, stdio: 'inherit' });
116+
117+
// Publish
118+
console.log(` 📤 Publishing to npm...`);
119+
execSync('pnpm run publish:pkg', { cwd: versionPath, stdio: 'inherit' });
120+
121+
console.log(` ✅ PostgreSQL ${version} published successfully!`);
122+
} catch (error) {
123+
console.error(` ❌ Failed to publish PostgreSQL ${version}:`, error.message);
124+
const continuePublish = await question('Continue with other versions? (y/N): ');
125+
if (continuePublish.toLowerCase() !== 'y') {
126+
rl.close();
127+
process.exit(1);
128+
}
129+
}
130+
}
131+
132+
// Process full package if selected
133+
if (includeFullPackage) {
134+
console.log(`\n📦 Publishing full package...`);
135+
const fullPath = path.join(__dirname, '..', 'full');
136+
137+
try {
138+
// Version bump
139+
console.log(` 📝 Bumping version (${bump})...`);
140+
execSync(`pnpm version ${bump}`, { cwd: fullPath, stdio: 'inherit' });
141+
142+
// Commit
143+
console.log(` 💾 Committing version bump...`);
144+
execSync(`git add package.json`, { cwd: fullPath });
145+
execSync(`git commit -m "release: bump @libpg-query/parser version"`, { stdio: 'inherit' });
146+
147+
// Build
148+
console.log(` 🔨 Building...`);
149+
execSync('pnpm build', { cwd: fullPath, stdio: 'inherit' });
150+
151+
// Test
152+
console.log(` 🧪 Running tests...`);
153+
execSync('pnpm test', { cwd: fullPath, stdio: 'inherit' });
154+
155+
// Publish with pg17 tag
156+
console.log(` 📤 Publishing to npm with pg17 tag...`);
157+
execSync('pnpm publish --tag pg17', { cwd: fullPath, stdio: 'inherit' });
158+
159+
console.log(` ✅ Full package published successfully with pg17 tag!`);
160+
} catch (error) {
161+
console.error(` ❌ Failed to publish full package:`, error.message);
162+
}
163+
}
164+
165+
// Ask about promoting to latest
166+
if (selectedVersions.includes('17') || includeFullPackage) {
167+
console.log('\n🏷️ Tag Management');
168+
169+
if (selectedVersions.includes('17')) {
170+
const promoteVersions = await question('Promote libpg-query@pg17 to latest? (y/N): ');
171+
if (promoteVersions.toLowerCase() === 'y') {
172+
try {
173+
execSync('npm dist-tag add libpg-query@pg17 latest', { stdio: 'inherit' });
174+
console.log('✅ libpg-query@pg17 promoted to latest');
175+
} catch (error) {
176+
console.error('❌ Failed to promote tag:', error.message);
177+
}
178+
}
179+
}
180+
181+
if (includeFullPackage) {
182+
const promoteFullPackage = await question('Promote @libpg-query/parser@pg17 to latest? (y/N): ');
183+
if (promoteFullPackage.toLowerCase() === 'y') {
184+
try {
185+
execSync('npm dist-tag add @libpg-query/parser@pg17 latest', { stdio: 'inherit' });
186+
console.log('✅ @libpg-query/parser@pg17 promoted to latest');
187+
} catch (error) {
188+
console.error('❌ Failed to promote tag:', error.message);
189+
}
190+
}
191+
}
192+
}
193+
194+
console.log('\n✨ Publishing complete!');
195+
rl.close();
37196
}
197+
198+
main().catch(error => {
199+
console.error('❌ Error:', error);
200+
rl.close();
201+
process.exit(1);
202+
});

versions/13/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"clean": "pnpm wasm:clean && rimraf wasm/*.js wasm/*.cjs wasm/*.d.ts",
2323
"build:js": "node scripts/build.js",
2424
"build": "pnpm clean && pnpm wasm:build && pnpm build:js",
25-
"publish:pkg": "node ../../scripts/publish-versions.js",
25+
"publish:pkg": "node ../../scripts/publish-single-version.js",
2626
"wasm:make": "docker run --rm -v $(pwd):/src -u $(id -u):$(id -g) -e EMSCRIPTEN=1 emscripten/emsdk emmake make",
2727
"wasm:build": "pnpm wasm:make build",
2828
"wasm:rebuild": "pnpm wasm:make rebuild",

versions/14/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"clean": "pnpm wasm:clean && rimraf wasm/*.js wasm/*.cjs wasm/*.d.ts",
2323
"build:js": "node scripts/build.js",
2424
"build": "pnpm clean && pnpm wasm:build && pnpm build:js",
25-
"publish:pkg": "node ../../scripts/publish-versions.js",
25+
"publish:pkg": "node ../../scripts/publish-single-version.js",
2626
"wasm:make": "docker run --rm -v $(pwd):/src -u $(id -u):$(id -g) emscripten/emsdk emmake make",
2727
"wasm:build": "pnpm wasm:make build",
2828
"wasm:rebuild": "pnpm wasm:make rebuild",

versions/15/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"clean": "pnpm wasm:clean && rimraf wasm/*.js wasm/*.cjs wasm/*.d.ts",
2323
"build:js": "node scripts/build.js",
2424
"build": "pnpm clean && pnpm wasm:build && pnpm build:js",
25-
"publish:pkg": "node ../../scripts/publish-versions.js",
25+
"publish:pkg": "node ../../scripts/publish-single-version.js",
2626
"wasm:make": "docker run --rm -v $(pwd):/src -u $(id -u):$(id -g) emscripten/emsdk emmake make",
2727
"wasm:build": "pnpm wasm:make build",
2828
"wasm:rebuild": "pnpm wasm:make rebuild",

versions/16/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"clean": "pnpm wasm:clean && rimraf wasm/*.js wasm/*.cjs wasm/*.d.ts",
2323
"build:js": "node scripts/build.js",
2424
"build": "pnpm clean && pnpm wasm:build && pnpm build:js",
25-
"publish:pkg": "node ../../scripts/publish-versions.js",
25+
"publish:pkg": "node ../../scripts/publish-single-version.js",
2626
"wasm:make": "docker run --rm -v $(pwd):/src -u $(id -u):$(id -g) emscripten/emsdk emmake make",
2727
"wasm:build": "pnpm wasm:make build",
2828
"wasm:rebuild": "pnpm wasm:make rebuild",

versions/17/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"clean": "pnpm wasm:clean && rimraf wasm/*.js wasm/*.cjs wasm/*.d.ts",
2323
"build:js": "node scripts/build.js",
2424
"build": "pnpm clean && pnpm wasm:build && pnpm build:js",
25-
"publish:pkg": "node ../../scripts/publish-versions.js",
25+
"publish:pkg": "node ../../scripts/publish-single-version.js",
2626
"wasm:make": "docker run --rm -v $(pwd):/src -u $(id -u):$(id -g) emscripten/emsdk emmake make",
2727
"wasm:build": "pnpm wasm:make build",
2828
"wasm:rebuild": "pnpm wasm:make rebuild",

0 commit comments

Comments
 (0)