Skip to content

Commit 6702eeb

Browse files
committed
multi-parser
1 parent d2dafb5 commit 6702eeb

19 files changed

+639
-1109
lines changed

PUBLISH.md

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,39 @@ This interactive script will:
4141
- Build, prepare, and publish each selected version
4242
- Optionally promote pg17 to latest
4343

44+
### Parser Package
45+
46+
The parser package supports multiple build configurations:
47+
48+
#### Full Build (all versions 13-17)
49+
```bash
50+
pnpm run publish:parser
51+
# or with specific build type
52+
PARSER_BUILD_TYPE=full pnpm run publish:parser
53+
```
54+
55+
#### LTS Build (versions 16-17)
56+
```bash
57+
PARSER_BUILD_TYPE=lts pnpm run publish:parser
58+
```
59+
60+
#### Latest Only (version 17)
61+
```bash
62+
PARSER_BUILD_TYPE=latest pnpm run publish:parser
63+
```
64+
65+
#### Legacy Build (versions 13-15)
66+
```bash
67+
PARSER_BUILD_TYPE=legacy pnpm run publish:parser
68+
```
69+
70+
This command will:
71+
- Navigate to the parser directory
72+
- Build the parser with the specified configuration
73+
- Publish the @pgsql/parser package to npm with appropriate dist-tag
74+
- Note: You should manually bump the version and commit changes before running this
75+
- **Prerequisite**: The version packages must be built first as the parser copies their WASM files during build
76+
4477
## Manual Publishing
4578

4679
### Types Packages
@@ -156,4 +189,108 @@ npm dist-tag add @libpg-query/parser@pg17 latest
156189
```bash
157190
npm install @libpg-query/parser@pg17 # PostgreSQL 17 specific
158191
npm install @libpg-query/parser # Latest version
192+
```
193+
194+
## Parser Package (@pgsql/parser)
195+
196+
### Quick Publish
197+
```bash
198+
cd parser
199+
pnpm version patch
200+
git add . && git commit -m "release: bump @pgsql/parser version"
201+
pnpm build
202+
pnpm test
203+
pnpm publish
204+
```
205+
206+
### Build Configurations
207+
208+
The parser package is now a simple distribution package that copies pre-built WASM files. No TypeScript compilation needed!
209+
210+
#### Available Build Types:
211+
- **full**: All versions (13, 14, 15, 16, 17) - Default
212+
- **lts**: LTS versions only (16, 17)
213+
- **latest**: Latest version only (17)
214+
- **legacy**: Legacy versions (13, 14, 15)
215+
216+
```bash
217+
# Full build (default)
218+
npm run build
219+
220+
# Specific builds
221+
npm run build:lts
222+
npm run build:latest
223+
npm run build:legacy
224+
225+
# Or using environment variable
226+
PARSER_BUILD_TYPE=lts npm run build
227+
```
228+
229+
### Build Process
230+
The simplified parser package:
231+
1. Copies WASM files from the `versions/*/wasm/` directories
232+
2. Generates index files from templates based on the build configuration
233+
3. Creates version-specific export files
234+
4. Creates a `build-info.json` file documenting what was included
235+
236+
The templates automatically adjust to include only the versions specified in the build configuration, ensuring proper TypeScript types and runtime validation.
237+
238+
**Note**: Build scripts use `cross-env` for Windows compatibility.
239+
240+
**Important**: Before building the parser package, ensure that the version packages are built first:
241+
```bash
242+
# Build all version packages first
243+
pnpm build # builds libpg-query versions
244+
245+
# Then build the parser with desired configuration
246+
cd parser
247+
npm run build:lts # or build:full, build:latest, etc.
248+
```
249+
250+
### Publishing with Different Tags
251+
252+
```bash
253+
# Publish full version as latest
254+
npm run build:full
255+
npm publish
256+
257+
# Publish LTS version with lts tag
258+
npm run build:lts
259+
npm publish --tag lts
260+
261+
# Publish legacy version with legacy tag
262+
npm run build:legacy
263+
npm publish --tag legacy
264+
```
265+
266+
### What it does
267+
- Publishes `@pgsql/parser` - a multi-version PostgreSQL parser with dynamic version selection
268+
- Provides a unified interface to work with multiple PostgreSQL versions
269+
- Supports different build configurations for different use cases
270+
- Includes both CommonJS and ESM builds
271+
- Exports version-specific parsers via subpaths (e.g., `@pgsql/parser/v17`)
272+
273+
### Install published package
274+
```bash
275+
# Install latest (full build)
276+
npm install @pgsql/parser
277+
278+
# Install LTS version
279+
npm install @pgsql/parser@lts
280+
281+
# Install legacy version
282+
npm install @pgsql/parser@legacy
283+
284+
# Use version-specific imports:
285+
# import { parse } from '@pgsql/parser/v17'
286+
# import { parse } from '@pgsql/parser/v16'
287+
# import { parse } from '@pgsql/parser/v13'
288+
```
289+
290+
### Alternative: Using npm scripts from root
291+
```bash
292+
# From the repository root:
293+
pnpm build:parser # Build the parser package (full build)
294+
PARSER_BUILD_TYPE=lts pnpm build:parser # Build LTS version
295+
pnpm publish:parser # Publish the parser package
159296
```

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
"publish:versions": "node scripts/publish-versions.js",
2222
"update:versions-types": "node scripts/update-versions-types.js",
2323
"build:parser": "pnpm --filter @pgsql/parser build",
24+
"build:parser:lts": "PARSER_BUILD_TYPE=lts pnpm --filter @pgsql/parser build",
25+
"build:parser:full": "PARSER_BUILD_TYPE=full pnpm --filter @pgsql/parser build",
26+
"build:parser:legacy": "PARSER_BUILD_TYPE=legacy pnpm --filter @pgsql/parser build",
2427
"test:parser": "pnpm --filter @pgsql/parser test",
2528
"publish:parser": "pnpm --filter @pgsql/parser publish"
2629
},

parser/.gitignore

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
11
node_modules/
2-
dist/
3-
dist-esm/
2+
wasm/
43
*.log
5-
.DS_Store
6-
src/wasm/*.wasm
7-
src/wasm/*.js
8-
src/types/15/
9-
src/types/16/
10-
src/types/17/
4+
.DS_Store

parser/Makefile.shared

Lines changed: 0 additions & 42 deletions
This file was deleted.

parser/README.md

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,19 @@
1313
<a href="https://github.com/launchql/libpg-query-node/actions/workflows/ci.yml"><img height="20" src="https://img.shields.io/badge/Linux-available-333333?logo=linux&logoColor=white" /></a>
1414
</p>
1515

16-
Multi-version PostgreSQL parser with dynamic version selection. This package provides a unified interface to parse PostgreSQL queries using different parser versions (15, 16, 17).
16+
Multi-version PostgreSQL parser with dynamic version selection. This package provides a unified interface to parse PostgreSQL queries using different parser versions (13, 14, 15, 16, 17).
1717

1818
## Installation
1919

2020
```bash
21+
# Install latest (full build with all versions)
2122
npm install @pgsql/parser
23+
24+
# Install LTS version (PostgreSQL 16-17 only)
25+
npm install @pgsql/parser@lts
26+
27+
# Install legacy version (PostgreSQL 13-15 only)
28+
npm install @pgsql/parser@legacy
2229
```
2330

2431
## Usage
@@ -71,12 +78,12 @@ if (result.error) {
7178

7279
## API
7380

74-
### `parse(query: string, version?: 15 | 16 | 17): Promise<ParseResult>`
81+
### `parse(query: string, version?: 13 | 14 | 15 | 16 | 17): Promise<ParseResult>`
7582

7683
Parse a SQL query with the specified PostgreSQL version.
7784

7885
- `query`: The SQL query string to parse
79-
- `version`: PostgreSQL version (15, 16, or 17). Defaults to 17.
86+
- `version`: PostgreSQL version (13, 14, 15, 16, or 17). Defaults to 17.
8087

8188
Returns a promise that resolves to:
8289
- On success: `{ version: number, result: AST }`
@@ -88,12 +95,14 @@ Class for creating a parser instance with a specific version.
8895

8996
```javascript
9097
const parser = new PgParser(version);
91-
await parser.parse(query);
92-
parser.parseSync(query); // Only available after first parse()
98+
const result = await parser.parse(query);
99+
const syncResult = parser.parseSync(query); // Only available after first parse()
93100
```
94101

95102
## Version Exports
96103

104+
- `@pgsql/parser/v13` - PostgreSQL 13 parser
105+
- `@pgsql/parser/v14` - PostgreSQL 14 parser
97106
- `@pgsql/parser/v15` - PostgreSQL 15 parser
98107
- `@pgsql/parser/v16` - PostgreSQL 16 parser
99108
- `@pgsql/parser/v17` - PostgreSQL 17 parser
@@ -103,6 +112,20 @@ Each version export provides:
103112
- `parse(query)`: Parse a query (async)
104113
- `parseSync(query)`: Parse a query (sync, requires loadModule first)
105114

115+
## Build Configurations
116+
117+
This package supports different build configurations for different use cases:
118+
119+
- **full** (default): All versions (13, 14, 15, 16, 17)
120+
- **lts**: LTS versions only (16, 17)
121+
- **latest**: Latest version only (17)
122+
- **legacy**: Legacy versions (13, 14, 15)
123+
124+
When installing from npm, you can choose the appropriate build using tags:
125+
- `npm install @pgsql/parser` - Full build
126+
- `npm install @pgsql/parser@lts` - LTS build
127+
- `npm install @pgsql/parser@legacy` - Legacy build
128+
106129
## Credits
107130

108131
Built on the excellent work of several contributors:

parser/package.json

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@
1212
"require": "./wasm/index.cjs",
1313
"types": "./wasm/index.d.ts"
1414
},
15+
"./v13": {
16+
"import": "./wasm/v13.js",
17+
"require": "./wasm/v13.cjs",
18+
"types": "./wasm/v13.d.ts"
19+
},
20+
"./v14": {
21+
"import": "./wasm/v14.js",
22+
"require": "./wasm/v14.cjs",
23+
"types": "./wasm/v14.d.ts"
24+
},
1525
"./v15": {
1626
"import": "./wasm/v15.js",
1727
"require": "./wasm/v15.cjs",
@@ -29,13 +39,17 @@
2939
}
3040
},
3141
"files": [
32-
"wasm"
42+
"wasm/**/*"
3343
],
3444
"scripts": {
35-
"clean": "rimraf wasm/*.js wasm/*.cjs wasm/*.d.ts cjs esm",
36-
"build:js": "node scripts/build.js",
37-
"build": "pnpm clean && pnpm build:js",
38-
"test": "vitest"
45+
"clean": "rimraf wasm",
46+
"prepare": "node scripts/prepare.js",
47+
"build": "npm run clean && npm run prepare",
48+
"build:full": "npm run clean && cross-env PARSER_BUILD_TYPE=full npm run prepare",
49+
"build:lts": "npm run clean && cross-env PARSER_BUILD_TYPE=lts npm run prepare",
50+
"build:latest": "npm run clean && cross-env PARSER_BUILD_TYPE=latest npm run prepare",
51+
"build:legacy": "npm run clean && cross-env PARSER_BUILD_TYPE=legacy npm run prepare",
52+
"test": "node --test test/*.test.js"
3953
},
4054
"keywords": [
4155
"postgresql",
@@ -46,6 +60,7 @@
4660
],
4761
"license": "MIT",
4862
"devDependencies": {
49-
"vitest": "^1.0.0"
63+
"cross-env": "^7.0.3",
64+
"rimraf": "^5.0.0"
5065
}
5166
}

0 commit comments

Comments
 (0)