Skip to content

Commit 3aeb472

Browse files
authored
Merge pull request #129 from launchql/multi/parser
Multi/parser
2 parents d2dafb5 + 667c0d7 commit 3aeb472

File tree

21 files changed

+711
-1110
lines changed

21 files changed

+711
-1110
lines changed

.github/workflows/ci.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,18 @@ jobs:
163163
run: pnpm install
164164
working-directory: parser
165165

166+
- name: Download v13 WASM Artifacts 📥
167+
uses: actions/download-artifact@v4
168+
with:
169+
name: wasm-artifacts-v13
170+
path: versions/13/wasm/
171+
172+
- name: Download v14 WASM Artifacts 📥
173+
uses: actions/download-artifact@v4
174+
with:
175+
name: wasm-artifacts-v14
176+
path: versions/14/wasm/
177+
166178
- name: Download v15 WASM Artifacts 📥
167179
uses: actions/download-artifact@v4
168180
with:
@@ -181,6 +193,15 @@ jobs:
181193
name: wasm-artifacts-v17
182194
path: versions/17/wasm/
183195

196+
- name: Build Types Packages 🏗
197+
run: |
198+
for version in 13 14 15 16 17; do
199+
echo "Building types for v${version}..."
200+
cd types/${version}
201+
pnpm run build
202+
cd ../..
203+
done
204+
184205
- name: Build Parser 🏗
185206
run: pnpm run build
186207
working-directory: parser
@@ -234,6 +255,18 @@ jobs:
234255
run: pnpm install
235256
working-directory: parser
236257

258+
- name: Download v13 WASM Artifacts 📥
259+
uses: actions/download-artifact@v4
260+
with:
261+
name: wasm-artifacts-v13
262+
path: versions/13/wasm/
263+
264+
- name: Download v14 WASM Artifacts 📥
265+
uses: actions/download-artifact@v4
266+
with:
267+
name: wasm-artifacts-v14
268+
path: versions/14/wasm/
269+
237270
- name: Download v15 WASM Artifacts 📥
238271
uses: actions/download-artifact@v4
239272
with:

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ libpg_query/**/*.proto
2525
npm-debug.log
2626
.claude
2727
.openhands/
28+
.DS_Store

PUBLISH.md

Lines changed: 147 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,118 @@ 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. Copies TypeScript type definitions from the `types/*/dist/` directories
233+
3. Updates import paths to use local types instead of `@pgsql/types`
234+
4. Generates index files from templates based on the build configuration
235+
5. Creates version-specific export files
236+
6. Creates a `build-info.json` file documenting what was included
237+
238+
The templates automatically adjust to include only the versions specified in the build configuration, ensuring proper TypeScript types and runtime validation. The package is completely self-contained with all necessary types bundled.
239+
240+
**Note**: Build scripts use `cross-env` for Windows compatibility.
241+
242+
**Important**: Before building the parser package, ensure that the version packages are built first:
243+
```bash
244+
# Build all version packages first
245+
pnpm build # builds libpg-query versions
246+
247+
# Then build the parser with desired configuration
248+
cd parser
249+
npm run build:lts # or build:full, build:latest, etc.
250+
```
251+
252+
### Types Bundling
253+
The parser build process automatically:
254+
1. Copies TypeScript type definitions from `types/*/dist/` directories
255+
2. Places them in `wasm/v*/types/` for each version
256+
3. Updates all import references from `@pgsql/types` to `./types`
257+
4. Makes the package self-contained without external type dependencies
258+
259+
### Publishing with Different Tags
260+
261+
```bash
262+
# Publish full version as latest
263+
npm run build:full
264+
npm publish
265+
266+
# Publish LTS version with lts tag
267+
npm run build:lts
268+
npm publish --tag lts
269+
270+
# Publish legacy version with legacy tag
271+
npm run build:legacy
272+
npm publish --tag legacy
273+
```
274+
275+
### What it does
276+
- Publishes `@pgsql/parser` - a multi-version PostgreSQL parser with dynamic version selection
277+
- Provides a unified interface to work with multiple PostgreSQL versions
278+
- Supports different build configurations for different use cases
279+
- Includes both CommonJS and ESM builds
280+
- Exports version-specific parsers via subpaths (e.g., `@pgsql/parser/v17`)
281+
- **Self-contained**: Bundles TypeScript types locally (no external @pgsql/types dependency)
282+
283+
### Install published package
284+
```bash
285+
# Install latest (full build)
286+
npm install @pgsql/parser
287+
288+
# Install LTS version
289+
npm install @pgsql/parser@lts
290+
291+
# Install legacy version
292+
npm install @pgsql/parser@legacy
293+
294+
# Use version-specific imports:
295+
# import { parse } from '@pgsql/parser/v17'
296+
# import { parse } from '@pgsql/parser/v16'
297+
# import { parse } from '@pgsql/parser/v13'
298+
```
299+
300+
### Alternative: Using npm scripts from root
301+
```bash
302+
# From the repository root:
303+
pnpm build:parser # Build the parser package (full build)
304+
PARSER_BUILD_TYPE=lts pnpm build:parser # Build LTS version
305+
pnpm publish:parser # Publish the parser package
159306
```

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:

0 commit comments

Comments
 (0)