Skip to content

Commit c924c41

Browse files
Fix CI build failure and add main package publishing support
- Add --disable-thread-safety flag to fix PostgreSQL configure in Emscripten - Add publishMainPackage function to support @pgsql/parser publishing - Add CLI options --main and --publish-as for main package publishing - Add npm scripts for convenient main package publishing - Update documentation with dual publishing strategy examples - Support independent versioning for main package vs version packages Co-Authored-By: Dan Lynch <pyramation@gmail.com>
1 parent 176bb2d commit c924c41

4 files changed

Lines changed: 169 additions & 10 deletions

File tree

PUBLISHING.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,3 +221,73 @@ node scripts/publish-versions.js --versions "16" --set-version "1.9.0"
221221
```
222222

223223
This allows different PostgreSQL versions to have different semantic versions while maintaining the dist-tag system.
224+
225+
## Main Package Publishing (@pgsql/parser)
226+
227+
The main libpg-query package can be published as @pgsql/parser with comprehensive functionality including parse, deparse, parsePlPgSQL, scan, fingerprint, and normalize capabilities.
228+
229+
### Publishing Main Package Examples
230+
231+
#### Example 1: Publishing Main Package (Dry Run)
232+
```bash
233+
# Test publishing main package as @pgsql/parser
234+
node scripts/publish-versions.js --dry-run --main
235+
```
236+
237+
**What happens:**
238+
1. Script backs up `libpg-query/package.json`
239+
2. Temporarily changes name from `libpg-query` to `@pgsql/parser`
240+
3. Keeps existing version (currently 17.3.3)
241+
4. Runs `pnpm build` in `libpg-query/`
242+
5. Would publish with `pnpm publish`
243+
6. Restores original `package.json`
244+
245+
**Result:** Users can install with `npm install @pgsql/parser`
246+
247+
#### Example 2: Publishing with Custom Version
248+
```bash
249+
# Publish main package with version 1.0.0
250+
node scripts/publish-versions.js --main --set-version "1.0.0"
251+
```
252+
253+
#### Example 3: Publishing with Custom Name
254+
```bash
255+
# Publish under different organization
256+
node scripts/publish-versions.js --main --publish-as "@myorg/pg-parser"
257+
```
258+
259+
### Dual Publishing Strategy
260+
261+
This setup enables a dual publishing strategy:
262+
263+
1. **Version-specific packages** (parse-only functionality):
264+
- `libpg-query@pg13`, `libpg-query@pg14`, etc.
265+
- Limited to parsing capabilities
266+
- PostgreSQL version-specific
267+
268+
2. **Comprehensive package** (full functionality):
269+
- `@pgsql/parser`
270+
- Complete feature set: parse, deparse, parsePlPgSQL, scan, fingerprint, normalize
271+
- Latest PostgreSQL version support
272+
273+
### Installation After Publishing
274+
275+
```bash
276+
# Install comprehensive parser
277+
npm install @pgsql/parser
278+
279+
# Install version-specific parser
280+
npm install libpg-query@pg17
281+
```
282+
283+
### NPM Scripts for Main Package
284+
285+
The following convenience scripts are available for main package publishing:
286+
287+
```bash
288+
# Test main package publishing (dry-run)
289+
pnpm publish:main:dry-run
290+
291+
# Publish main package
292+
pnpm publish:main
293+
```

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@
1616
"analyze:sizes": "node scripts/analyze-sizes.js",
1717
"publish:dry-run": "node scripts/publish-versions.js --dry-run",
1818
"publish:versions": "node scripts/publish-versions.js",
19-
"publish:help": "node scripts/publish-versions.js --help"
19+
"publish:help": "node scripts/publish-versions.js --help",
20+
"publish:main": "node scripts/publish-versions.js --main",
21+
"publish:main:dry-run": "node scripts/publish-versions.js --dry-run --main"
2022
},
2123
"devDependencies": {
2224
"@types/node": "^20.0.0"
2325
}
24-
}
26+
}

scripts/publish-versions.js

Lines changed: 92 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,71 @@ function publishPackage(packageInfo, options = {}) {
103103
}
104104
}
105105

106+
function publishMainPackage(options = {}) {
107+
const { dryRun = false, customVersion = null, skipBuild = false, publishAs = '@pgsql/parser' } = options;
108+
109+
console.log(`🚀 libpg-query Main Package Publisher (${publishAs})`);
110+
console.log('='.repeat(50));
111+
112+
if (dryRun) {
113+
console.log('🔍 DRY RUN MODE - No actual publishing will occur\n');
114+
}
115+
116+
const mainPackagePath = './libpg-query';
117+
const packageJsonPath = path.join(mainPackagePath, 'package.json');
118+
119+
if (!fs.existsSync(packageJsonPath)) {
120+
console.log('❌ Main package not found at ./libpg-query');
121+
return;
122+
}
123+
124+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
125+
const publishVersion = customVersion || packageJson.version;
126+
127+
console.log(`Publishing main package as: ${publishAs}`);
128+
console.log(`Version: ${publishVersion}`);
129+
console.log(`Original name: ${packageJson.name}`);
130+
131+
if (dryRun) {
132+
console.log(`[DRY RUN] Would modify package.json: name -> "${publishAs}", version -> "${publishVersion}"`);
133+
if (!skipBuild) {
134+
console.log(`[DRY RUN] Would run: cd ${mainPackagePath} && pnpm build`);
135+
}
136+
console.log(`[DRY RUN] Would run: cd ${mainPackagePath} && pnpm publish`);
137+
return;
138+
}
139+
140+
let backupPath;
141+
try {
142+
backupPath = backupPackageJson(packageJsonPath);
143+
144+
const modifiedPackageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
145+
modifiedPackageJson.name = publishAs;
146+
if (customVersion) {
147+
modifiedPackageJson.version = customVersion;
148+
}
149+
fs.writeFileSync(packageJsonPath, JSON.stringify(modifiedPackageJson, null, 2) + '\n');
150+
151+
if (!skipBuild) {
152+
console.log(`Building main package...`);
153+
execSync('pnpm build', { cwd: mainPackagePath, stdio: 'inherit' });
154+
}
155+
156+
console.log(`Publishing as ${publishAs}...`);
157+
execSync('pnpm publish', { cwd: mainPackagePath, stdio: 'inherit' });
158+
159+
console.log(`✅ Successfully published ${publishAs} (${publishVersion})`);
160+
161+
} catch (error) {
162+
console.error(`❌ Failed to publish main package:`, error.message);
163+
throw error;
164+
} finally {
165+
if (backupPath) {
166+
restorePackageJson(packageJsonPath);
167+
}
168+
}
169+
}
170+
106171
function publishAllVersions(options = {}) {
107172
const { dryRun = false, versions = [], customVersion = null, skipBuild = false } = options;
108173

@@ -171,7 +236,9 @@ function main() {
171236
dryRun: args.includes('--dry-run') || args.includes('-d'),
172237
versions: [],
173238
customVersion: null,
174-
skipBuild: args.includes('--skip-build')
239+
skipBuild: args.includes('--skip-build'),
240+
publishMain: args.includes('--main'),
241+
publishAs: '@pgsql/parser'
175242
};
176243

177244
const versionIndex = args.findIndex(arg => arg === '--versions' || arg === '-v');
@@ -184,14 +251,19 @@ function main() {
184251
options.customVersion = args[customVersionIndex + 1];
185252
}
186253

254+
const publishAsIndex = args.findIndex(arg => arg === '--publish-as');
255+
if (publishAsIndex !== -1 && args[publishAsIndex + 1]) {
256+
options.publishAs = args[publishAsIndex + 1];
257+
}
258+
187259
if (args.includes('--help') || args.includes('-h')) {
188260
console.log(`
189261
libpg-query Multi-Version Publisher
190262
191263
DESCRIPTION:
192264
Publishes multiple PostgreSQL version packages under the unified "libpg-query"
193-
name using dist-tags. Handles workspace naming conflicts by temporarily
194-
modifying package.json files during publishing.
265+
name using dist-tags, and supports publishing the main package as @pgsql/parser.
266+
Handles workspace naming conflicts by temporarily modifying package.json files.
195267
196268
USAGE:
197269
node scripts/publish-versions.js [options]
@@ -201,6 +273,8 @@ OPTIONS:
201273
--versions, -v <list> Comma-separated list of versions to publish (e.g., "13,16,17")
202274
--set-version <version> Set custom version for all packages (e.g., "1.2.3")
203275
--skip-build Skip the build step (assumes packages are already built)
276+
--main Publish the main libpg-query package as @pgsql/parser
277+
--publish-as <name> Custom package name for main package (default: @pgsql/parser)
204278
--help, -h Show this help message
205279
206280
EXAMPLES:
@@ -218,6 +292,15 @@ EXAMPLES:
218292
219293
# Skip build step (if already built)
220294
node scripts/publish-versions.js --versions "17" --skip-build
295+
296+
# Publish main package as @pgsql/parser (dry-run)
297+
node scripts/publish-versions.js --dry-run --main
298+
299+
# Publish main package with custom version
300+
node scripts/publish-versions.js --main --set-version "1.0.0"
301+
302+
# Publish main package with custom name
303+
node scripts/publish-versions.js --main --publish-as "@myorg/pg-parser"
221304
222305
PUBLISHING WORKFLOW:
223306
1. Script discovers all version packages in versions/ directory
@@ -245,11 +328,15 @@ SAFETY FEATURES:
245328
return;
246329
}
247330

248-
publishAllVersions(options);
331+
if (options.publishMain) {
332+
publishMainPackage(options);
333+
} else {
334+
publishAllVersions(options);
335+
}
249336
}
250337

251338
if (require.main === module) {
252339
main();
253340
}
254341

255-
module.exports = { publishAllVersions, getVersionPackages };
342+
module.exports = { publishAllVersions, publishMainPackage, getVersionPackages };

versions/13/patches/emscripten_disable_spinlocks.patch

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55

66
override PG_CONFIGURE_FLAGS += -q --without-readline --without-zlib
77
+
8-
+# Disable spinlocks when building with Emscripten
8+
+# Disable spinlocks and thread safety when building with Emscripten
99
+ifdef EMSCRIPTEN
10-
+override PG_CONFIGURE_FLAGS += --disable-spinlocks
10+
+override PG_CONFIGURE_FLAGS += --disable-spinlocks --disable-thread-safety
1111
+endif
1212

1313
override TEST_CFLAGS += -I. -I./vendor -g
@@ -21,4 +21,4 @@
2121
+endif
2222
echo "#undef PG_INT128_TYPE" >> ./src/postgres/include/pg_config.h
2323
# Support gcc earlier than 4.6.0 without reconfiguring
24-
echo "#undef HAVE__STATIC_ASSERT" >> ./src/postgres/include/pg_config.h
24+
echo "#undef HAVE__STATIC_ASSERT" >> ./src/postgres/include/pg_config.h

0 commit comments

Comments
 (0)