Skip to content

Commit d9a70d9

Browse files
Add comprehensive build and test instructions to README
- Add detailed WASM-only build instructions with prerequisites - Include step-by-step commands for building and testing - Add troubleshooting section for common issues like fetch failures - Document build artifacts and their purposes - Update table of contents to reflect new sections - Remove outdated binary distribution information Co-Authored-By: Dan Lynch <[email protected]>
1 parent 0759431 commit d9a70d9

File tree

1 file changed

+112
-11
lines changed

1 file changed

+112
-11
lines changed

README.md

Lines changed: 112 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,12 @@ Primarily used for the node.js parser and deparser [pgsql-parser](https://github
2929

3030
1. [Installation](#installation)
3131
2. [Example](#example)
32+
3. [Build Instructions](#build-instructions)
33+
4. [Testing](#testing)
3234
5. [Documentation](#documentation)
33-
3. [Versions](#versions)
34-
4. [Building a binary distribution](#building-a-binary-distribution)
35-
6. [Related Projects](#related-projects)
36-
7. [Credit](#credit)
35+
6. [Versions](#versions)
36+
7. [Related Projects](#related-projects)
37+
8. [Credit](#credit)
3738

3839

3940
## Installation
@@ -49,7 +50,93 @@ const parser = require('libpg-query');
4950
parser.parseQuery('select 1').then(console.log);
5051
```
5152

52-
### Documentation
53+
## Build Instructions
54+
55+
This package uses a **WASM-only build system** for true cross-platform compatibility without native compilation dependencies.
56+
57+
### Prerequisites
58+
59+
- Node.js (version 16 or higher recommended)
60+
- Docker (for WASM compilation using Emscripten)
61+
- yarn or npm
62+
63+
### Building WASM Artifacts
64+
65+
1. **Install dependencies:**
66+
```bash
67+
npm install
68+
# or
69+
yarn install
70+
```
71+
72+
2. **Build WASM artifacts:**
73+
```bash
74+
npm run wasm:build
75+
# or
76+
yarn wasm:build
77+
```
78+
79+
3. **Clean WASM build (if needed):**
80+
```bash
81+
npm run wasm:clean
82+
# or
83+
yarn wasm:clean
84+
```
85+
86+
4. **Rebuild WASM artifacts from scratch:**
87+
```bash
88+
npm run wasm:clean && npm run wasm:build
89+
# or
90+
yarn wasm:clean && yarn wasm:build
91+
```
92+
93+
### Build Process Details
94+
95+
The WASM build process:
96+
- Uses Docker with Emscripten SDK for compilation
97+
- Compiles C wrapper code to WebAssembly
98+
- Generates `wasm/libpg-query.js` and `wasm/libpg-query.wasm` files
99+
- No native compilation or node-gyp dependencies required
100+
101+
## Testing
102+
103+
### Running Tests
104+
105+
```bash
106+
npm test
107+
# or
108+
yarn test
109+
```
110+
111+
### Test Requirements
112+
113+
- WASM artifacts must be built before running tests
114+
- If tests fail with "fetch failed" errors, rebuild WASM artifacts:
115+
```bash
116+
npm run wasm:clean && npm run wasm:build && npm test
117+
```
118+
119+
### Expected Test Output
120+
121+
All tests should pass:
122+
```
123+
Queries
124+
Sync Parsing
125+
✓ should return a single-item parse result for common queries
126+
✓ should support parsing multiple queries
127+
✓ should not parse a bogus query
128+
Async parsing
129+
✓ should return a promise resolving to same result
130+
✓ should reject on bogus queries
131+
Deparsing
132+
✓ async function should return a promise resolving to same SQL
133+
✓ sync function should return a same SQL
134+
[... more tests ...]
135+
136+
18 passing (70ms)
137+
```
138+
139+
## Documentation
53140

54141
### `query.parseQuery(sql)`/`parseQuerySync`
55142

@@ -78,15 +165,29 @@ Our latest is built with `17-latest` branch from libpg_query
78165
| 10 | 10-latest | | `@1.3.1` ([tree](https://github.com/pyramation/pgsql-parser/tree/39b7b1adc8914253226e286a48105785219a81ca)) |
79166

80167

81-
## Building WASM Distribution
168+
## Troubleshooting
169+
170+
### Common Issues
171+
172+
**"fetch failed" errors during tests:**
173+
- This indicates stale or missing WASM artifacts
174+
- Solution: `npm run wasm:clean && npm run wasm:build`
175+
176+
**"WASM module not initialized" errors:**
177+
- Ensure you call an async method first to initialize the WASM module
178+
- Or use the async versions of methods which handle initialization automatically
82179

83-
This package now uses WASM-only builds for true cross-platform compatibility without native compilation.
180+
**Docker permission errors:**
181+
- Ensure Docker is running and accessible
182+
- On Linux, you may need to add your user to the docker group
84183

85-
- Install requirements (`npm i`)
86-
- Build WASM: `npm run build:wasm`
87-
- Clean WASM build: `npm run clean:wasm`
184+
### Build Artifacts
88185

89-
The WASM build uses Emscripten and emnapi to provide N-API compatibility in WebAssembly.
186+
The build process generates these files:
187+
- `wasm/libpg-query.js` - Emscripten-generated JavaScript loader
188+
- `wasm/libpg-query.wasm` - WebAssembly binary
189+
- `wasm/index.js` - ES module exports
190+
- `wasm/index.cjs` - CommonJS exports with sync wrappers
90191

91192
## Related Projects
92193

0 commit comments

Comments
 (0)