Skip to content

Commit cb6bf22

Browse files
committed
updates
1 parent 40cfe29 commit cb6bf22

File tree

9 files changed

+169
-1
lines changed

9 files changed

+169
-1
lines changed

PUBLISH.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Publishing Guide
2+
3+
## Types Packages
4+
5+
### Quick Publish
6+
```bash
7+
# Build and prepare a specific version
8+
pnpm --filter "@libpg-query/types17" run build
9+
pnpm --filter "@libpg-query/types17" run prepare:types
10+
cd types/17/dist && npm publish
11+
12+
# Or build all types
13+
pnpm run build:types
14+
pnpm run prepare:types
15+
```
16+
17+
### What it does
18+
- Transforms `@libpg-query/types17``@pgsql/types` with tag `pg17`
19+
- Transforms `@libpg-query/types16``@pgsql/types` with tag `pg16`
20+
- etc.
21+
22+
### Install published packages
23+
```bash
24+
npm install @pgsql/types@pg17 # PostgreSQL 17 types
25+
npm install @pgsql/types@pg16 # PostgreSQL 16 types
26+
```
27+
28+
## Version Packages
29+
30+
### Quick Publish
31+
```bash
32+
# Build and publish a specific version
33+
cd versions/17
34+
pnpm build
35+
pnpm run publish:pkg
36+
37+
# Or manually with custom tag
38+
cd versions/17
39+
pnpm build
40+
TAG=beta node ../../scripts/publish-versions.js
41+
```
42+
43+
### What it does
44+
- Transforms `@libpg-query/v17``libpg-query` with tag `pg17`
45+
- Transforms `@libpg-query/v16``libpg-query` with tag `pg16`
46+
- Uses `x-publish.publishName` and `x-publish.distTag` from package.json
47+
- Temporarily modifies package.json during publish, then restores it
48+
49+
### Install published packages
50+
```bash
51+
npm install libpg-query@pg17 # PostgreSQL 17 specific
52+
npm install libpg-query@pg16 # PostgreSQL 16 specific
53+
npm install libpg-query # Latest/default version
54+
```

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"clean:all": "pnpm -r clean",
1313
"analyze:sizes": "node scripts/analyze-sizes.js",
1414
"fetch:protos": "node scripts/fetch-protos.js",
15-
"build:types": "node scripts/build-types.js"
15+
"build:types": "node scripts/build-types.js",
16+
"prepare:types": "node scripts/prepare-types.js"
1617
},
1718
"devDependencies": {
1819
"@types/node": "^20.0.0",

scripts/prepare-types.js

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
#!/usr/bin/env node
2+
3+
const fs = require('fs');
4+
const path = require('path');
5+
6+
/**
7+
* Script to prepare types packages for publishing by modifying their dist/package.json
8+
* to use the correct publishing name and dist-tag from x-publish metadata
9+
*/
10+
11+
function preparePackageForPublish(packageDir) {
12+
const packageJsonPath = path.join(packageDir, 'package.json');
13+
const distPackageJsonPath = path.join(packageDir, 'dist', 'package.json');
14+
15+
if (!fs.existsSync(packageJsonPath)) {
16+
console.error(`❌ Package.json not found: ${packageJsonPath}`);
17+
return false;
18+
}
19+
20+
if (!fs.existsSync(distPackageJsonPath)) {
21+
console.error(`❌ Dist package.json not found: ${distPackageJsonPath}`);
22+
return false;
23+
}
24+
25+
try {
26+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
27+
const distPackageJson = JSON.parse(fs.readFileSync(distPackageJsonPath, 'utf8'));
28+
29+
if (!packageJson['x-publish']) {
30+
console.error(`❌ No x-publish metadata found in ${packageDir}`);
31+
return false;
32+
}
33+
34+
const { publishName, distTag } = packageJson['x-publish'];
35+
36+
if (!publishName) {
37+
console.error(`❌ No publishName found in x-publish metadata for ${packageDir}`);
38+
return false;
39+
}
40+
41+
// Modify the dist package.json
42+
distPackageJson.name = publishName;
43+
44+
// Add dist-tag to publishConfig if specified
45+
if (distTag) {
46+
if (!distPackageJson.publishConfig) {
47+
distPackageJson.publishConfig = {};
48+
}
49+
distPackageJson.publishConfig.tag = distTag;
50+
}
51+
52+
// Remove x-publish metadata from the dist version
53+
delete distPackageJson['x-publish'];
54+
55+
// Write the modified package.json back to dist
56+
fs.writeFileSync(distPackageJsonPath, JSON.stringify(distPackageJson, null, 2) + '\n');
57+
58+
console.log(`✅ Prepared ${packageDir} for publishing as ${publishName}${distTag ? ` with tag ${distTag}` : ''}`);
59+
return true;
60+
61+
} catch (error) {
62+
console.error(`❌ Error preparing ${packageDir}: ${error.message}`);
63+
return false;
64+
}
65+
}
66+
67+
function main() {
68+
const typesDir = path.join(__dirname, '..', 'types');
69+
70+
if (!fs.existsSync(typesDir)) {
71+
console.error('❌ Types directory not found');
72+
process.exit(1);
73+
}
74+
75+
const typesPackages = fs.readdirSync(typesDir)
76+
.filter(dir => fs.statSync(path.join(typesDir, dir)).isDirectory())
77+
.sort();
78+
79+
console.log(`📦 Found ${typesPackages.length} types packages: ${typesPackages.join(', ')}\n`);
80+
81+
let successCount = 0;
82+
83+
for (const packageName of typesPackages) {
84+
const packagePath = path.join(typesDir, packageName);
85+
console.log(`🔧 Preparing types/${packageName}...`);
86+
87+
if (preparePackageForPublish(packagePath)) {
88+
successCount++;
89+
}
90+
console.log('');
91+
}
92+
93+
console.log('==================================================');
94+
console.log(`Prepare Summary:`);
95+
console.log(`✅ Successful: ${successCount}`);
96+
console.log(`❌ Failed: ${typesPackages.length - successCount}`);
97+
console.log(`📦 Total packages: ${typesPackages.length}`);
98+
99+
if (successCount < typesPackages.length) {
100+
process.exit(1);
101+
}
102+
}
103+
104+
if (require.main === module) {
105+
main();
106+
}
107+
108+
module.exports = { preparePackageForPublish };
File renamed without changes.

types/13/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"build": "pnpm run clean && tsc && tsc -p tsconfig.esm.json && pnpm run copy",
3030
"build:dev": "pnpm run clean && tsc --declarationMap && tsc -p tsconfig.esm.json && pnpm run copy",
3131
"build:proto": "ts-node scripts/pg-proto-parser",
32+
"prepare:types": "node -e \"require('../../scripts/prepare-types.js').preparePackageForPublish('.')\"",
3233
"lint": "eslint . --fix"
3334
},
3435
"keywords": [],

types/14/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"build": "pnpm run clean && tsc && tsc -p tsconfig.esm.json && pnpm run copy",
3030
"build:dev": "pnpm run clean && tsc --declarationMap && tsc -p tsconfig.esm.json && pnpm run copy",
3131
"build:proto": "ts-node scripts/pg-proto-parser",
32+
"prepare:types": "node -e \"require('../../scripts/prepare-types.js').preparePackageForPublish('.')\"",
3233
"lint": "eslint . --fix"
3334
},
3435
"keywords": [],

types/15/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"build": "pnpm run clean && tsc && tsc -p tsconfig.esm.json && pnpm run copy",
3030
"build:dev": "pnpm run clean && tsc --declarationMap && tsc -p tsconfig.esm.json && pnpm run copy",
3131
"build:proto": "ts-node scripts/pg-proto-parser",
32+
"prepare:types": "node -e \"require('../../scripts/prepare-types.js').preparePackageForPublish('.')\"",
3233
"lint": "eslint . --fix"
3334
},
3435
"keywords": [],

types/16/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"build": "pnpm run clean && tsc && tsc -p tsconfig.esm.json && pnpm run copy",
3030
"build:dev": "pnpm run clean && tsc --declarationMap && tsc -p tsconfig.esm.json && pnpm run copy",
3131
"build:proto": "ts-node scripts/pg-proto-parser",
32+
"prepare:types": "node -e \"require('../../scripts/prepare-types.js').preparePackageForPublish('.')\"",
3233
"lint": "eslint . --fix"
3334
},
3435
"keywords": [],

types/17/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"build": "pnpm run clean && tsc && tsc -p tsconfig.esm.json && pnpm run copy",
3030
"build:dev": "pnpm run clean && tsc --declarationMap && tsc -p tsconfig.esm.json && pnpm run copy",
3131
"build:proto": "ts-node scripts/pg-proto-parser",
32+
"prepare:types": "node -e \"require('../../scripts/prepare-types.js').preparePackageForPublish('.')\"",
3233
"lint": "eslint . --fix"
3334
},
3435
"keywords": [],

0 commit comments

Comments
 (0)