Skip to content

Commit 2285bc4

Browse files
Remove native build system, use WASM-only builds
- Remove binding.gyp and all C++ source files in src/ directory - Remove node-gyp, node-pre-gyp, and node-addon-api dependencies - Remove native build scripts (buildAddon.sh, buildAddon.bat) - Update package.json exports to use WASM for all environments - Create CommonJS wrapper for WASM module compatibility - Update README to reflect WASM-only build process - Remove binary distribution configuration - Keep all WASM build scripts and dependencies intact This creates a truly interoperable system that doesn't attempt native compilation during npm install. Co-Authored-By: Dan Lynch <[email protected]>
1 parent dafa999 commit 2285bc4

File tree

15 files changed

+85
-635
lines changed

15 files changed

+85
-635
lines changed

Makefile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ CXXFLAGS := -O3
3333
ifdef EMSCRIPTEN
3434
OUT_FILES := $(foreach EXT,.js .wasm,$(WASM_OUT_DIR)/$(WASM_OUT_NAME)$(EXT))
3535
else
36-
OUT_FILES := build/Release/queryparser.node $(wildcard build/*)
36+
$(error Native builds are no longer supported. Use EMSCRIPTEN=1 for WASM builds only.)
3737
endif
3838

3939
# Clone libpg_query source (lives in CACHE_DIR)
@@ -70,8 +70,7 @@ ifdef EMSCRIPTEN
7070
-o $@ \
7171
$(SRC_FILES)
7272
else
73-
# if not wasm, defer to node-gyp
74-
yarn rebuild
73+
$(error Native builds are no longer supported. Use EMSCRIPTEN=1 for WASM builds only.)
7574
endif
7675

7776
# Commands

README.md

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,18 +78,15 @@ Our latest is built with `17-latest` branch from libpg_query
7878
| 10 | 10-latest | | `@1.3.1` ([tree](https://github.com/pyramation/pgsql-parser/tree/39b7b1adc8914253226e286a48105785219a81ca)) |
7979

8080

81-
## Building a binary distribution
81+
## Building WASM Distribution
8282

83-
- Install requirements (`npm i`)
84-
- `npx node-pre-gyp rebuild package`
85-
- With appropriate AWS credentials configured, `npx node-pre-gyp publish`
83+
This package now uses WASM-only builds for true cross-platform compatibility without native compilation.
8684

87-
Or you can run the scripts
85+
- Install requirements (`npm i`)
86+
- Build WASM: `npm run build:wasm`
87+
- Clean WASM build: `npm run clean:wasm`
8888

89-
```
90-
npm run binary:build
91-
npm run binary:publish
92-
```
89+
The WASM build uses Emscripten and emnapi to provide N-API compatibility in WebAssembly.
9390

9491
## Related Projects
9592

binding.gyp

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

index.js

Lines changed: 11 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,24 @@
1-
const PgQuery = require('./build/Release/queryparser');
2-
const { pg_query } = require('./proto');
3-
1+
const wasmModule = require('./wasm/index.cjs');
42

53
module.exports = {
6-
parseQuery(query) {
7-
return new Promise((resolve, reject) => {
8-
PgQuery.parseQueryAsync(query, (err, result) => {
9-
err ? reject(err) : resolve(JSON.parse(result));
10-
});
11-
});
12-
},
13-
14-
deparse(parseTree) {
15-
const msg = pg_query.ParseResult.fromObject(parseTree);
16-
const data = pg_query.ParseResult.encode(msg).finish();
17-
return new Promise((resolve, reject) => {
18-
PgQuery.deparseAsync(data, (err, result) => {
19-
err ? reject(err) : resolve(result);
20-
});
21-
});
22-
},
23-
24-
parsePlPgSQL(query) {
25-
return new Promise((resolve, reject) => {
26-
PgQuery.parsePlPgSQLAsync(query, (err, result) => {
27-
err ? reject(err) : resolve(JSON.parse(result));
28-
});
29-
});
30-
},
31-
4+
parseQuery: wasmModule.parseQuery,
5+
deparse: wasmModule.deparse,
6+
parsePlPgSQL: wasmModule.parsePlPgSQL,
7+
fingerprint: wasmModule.fingerprint,
8+
329
parseQuerySync(query) {
33-
return JSON.parse(PgQuery.parseQuerySync(query));
10+
throw new Error('Sync methods not available in WASM-only build. Use async methods instead.');
3411
},
3512

3613
deparseSync(parseTree) {
37-
const msg = pg_query.ParseResult.fromObject(parseTree);
38-
const data = pg_query.ParseResult.encode(msg).finish();
39-
return PgQuery.deparseSync(data);
14+
throw new Error('Sync methods not available in WASM-only build. Use async methods instead.');
4015
},
4116

4217
parsePlPgSQLSync(query) {
43-
return JSON.parse(PgQuery.parsePlPgSQLSync(query));
44-
},
45-
46-
fingerprint(query) {
47-
return new Promise((resolve, reject) => {
48-
PgQuery.fingerprintAsync(query, (err, result) => {
49-
err ? reject(err) : resolve(result);
50-
});
51-
});
18+
throw new Error('Sync methods not available in WASM-only build. Use async methods instead.');
5219
},
5320

5421
fingerprintSync(query) {
55-
return PgQuery.fingerprintSync(query);
56-
},
22+
throw new Error('Sync methods not available in WASM-only build. Use async methods instead.');
23+
}
5724
};

package.json

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,18 @@
99
"access": "public"
1010
},
1111
"files": [
12-
"binding.gyp",
1312
"index.js",
1413
"index.d.ts",
1514
"proto.js",
1615
"libpg_query/*",
1716
"script/*",
18-
"src/*",
1917
"wasm/*"
2018
],
2119
"exports": {
2220
".": {
2321
"types": "./index.d.ts",
24-
"browser": "./wasm/index.js",
25-
"node": "./index.js",
22+
"import": "./wasm/index.js",
23+
"require": "./index.js",
2624
"default": "./index.js"
2725
},
2826
"./wasm": {
@@ -33,18 +31,13 @@
3331
"scripts": {
3432
"protogen": "node ./script/protogen.js 17-6.1.0",
3533
"clean": "rimraf build",
36-
"configure": "node-pre-gyp configure",
37-
"install": "node-pre-gyp install --fallback-to-build --loglevel verbose",
38-
"rebuild": "node-pre-gyp rebuild --loglevel verbose",
3934
"make:wasm": "docker run --rm -v $(pwd):/src -u $(id -u):$(id -g) emscripten/emsdk emmake make",
4035
"build:wasm": "yarn make:wasm build",
4136
"rebuild:wasm": "yarn make:wasm rebuild",
4237
"clean:wasm": "yarn make:wasm clean",
4338
"clean-cache:wasm": "yarn make:wasm clean-cache",
4439
"workflows": "node script/workflows.js",
45-
"test": "mocha --timeout 5000",
46-
"binary:build": "node-pre-gyp rebuild package",
47-
"binary:publish": "AWS_PROFILE=supabase-dev node-pre-gyp publish"
40+
"test": "mocha --timeout 5000"
4841
},
4942
"author": "Dan Lynch <[email protected]> (http://github.com/pyramation)",
5043
"license": "LICENSE IN LICENSE",
@@ -65,10 +58,7 @@
6558
"dependencies": {
6659
"@emnapi/runtime": "^0.43.1",
6760
"@launchql/protobufjs": "7.2.6",
68-
"@mapbox/node-pre-gyp": "^1.0.8",
69-
"@pgsql/types": "^17.0.0",
70-
"node-addon-api": "^7.0.0",
71-
"node-gyp": "^10.0.1"
61+
"@pgsql/types": "^17.0.0"
7262
},
7363
"keywords": [
7464
"sql",
@@ -78,14 +68,5 @@
7868
"query",
7969
"plpgsql",
8070
"database"
81-
],
82-
"binary": {
83-
"module_name": "queryparser",
84-
"module_path": "./build/Release/",
85-
"host": "https://gnbyoxcowpfpalflhptv.supabase.co/storage/v1/s3",
86-
"remote_path": "./libpg-query-node/",
87-
"bucket": "public-artifacts",
88-
"region": "us-east-1",
89-
"s3ForcePathStyle": true
90-
}
71+
]
9172
}

script/buildAddon.bat

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

script/buildAddon.sh

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

0 commit comments

Comments
 (0)