Skip to content

Commit 48afd14

Browse files
chore: generate .node files from libs/core
1 parent b60fb2c commit 48afd14

File tree

8 files changed

+174
-46
lines changed

8 files changed

+174
-46
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Rust
2-
/target
2+
**/target
33
**/*.rs.bk
44
Cargo.lock
55

biome.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@
55
},
66
"files": {
77
"include": ["**/*.ts", "**/*.tsx", "**/*.js", "**/*.jsx", "**/*.json"],
8-
"ignore": [".nx", "dist/**/*", "src/native.cjs", "src/native.d.ts"]
8+
"ignore": [
9+
".nx",
10+
"dist/**/*",
11+
"src/native.cjs",
12+
"src/native.d.ts",
13+
"libs/core/target/**/*"
14+
]
915
},
1016
"formatter": {
1117
"enabled": true,

libs/core/package.json

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,38 @@
1111
"types": "./dist/src/index.d.ts"
1212
}
1313
},
14-
"license": "MIT",
14+
"napi": {
15+
"name": "@kevinmichaelchen/cel-typescript",
16+
"triples": {
17+
"defaults": false,
18+
"additional": [
19+
"aarch64-apple-darwin",
20+
"x86_64-apple-darwin",
21+
"x86_64-unknown-linux-gnu",
22+
"aarch64-unknown-linux-gnu",
23+
"x86_64-pc-windows-msvc"
24+
]
25+
}
26+
},
1527
"engines": {
16-
"node": ">= 10"
17-
}
28+
"node": ">=18.0.0"
29+
},
30+
"author": "Kevin Chen",
31+
"repository": {
32+
"type": "git",
33+
"url": "git+https://github.com/kevinmichaelchen/cel-typescript.git"
34+
},
35+
"license": "MIT",
36+
"bugs": {
37+
"url": "https://github.com/kevinmichaelchen/cel-typescript/issues"
38+
},
39+
"homepage": "https://github.com/kevinmichaelchen/cel-typescript#readme",
40+
"keywords": [
41+
"cel",
42+
"common-expression-language",
43+
"expression-language",
44+
"policy",
45+
"rust",
46+
"napi-rs"
47+
]
1848
}

libs/core/project.json

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
{
2+
"name": "core",
3+
"$schema": "../../node_modules/nx/schemas/project-schema.json",
4+
"sourceRoot": "libs/core/src",
5+
"projectType": "library",
6+
"targets": {
7+
"build:native": {
8+
"executor": "nx:run-commands",
9+
"options": {
10+
"command": "bash libs/core/scripts/build.sh"
11+
},
12+
"cache": false,
13+
"inputs": [
14+
"{projectRoot}/src/**/*",
15+
"{projectRoot}/Cargo.toml",
16+
"{projectRoot}/Cargo.lock",
17+
"{projectRoot}/package.json"
18+
],
19+
"outputs": ["{workspaceRoot}/cel-typescript.node"]
20+
},
21+
"build:ts": {
22+
"executor": "@nx/js:tsc",
23+
"outputs": ["{workspaceRoot}/dist/{projectRoot}"],
24+
"options": {
25+
"outputPath": "dist/libs/core",
26+
"main": "libs/core/src/index.ts",
27+
"tsConfig": "libs/core/tsconfig.json",
28+
"assets": ["libs/core/*.md"]
29+
},
30+
"cache": true,
31+
"inputs": [
32+
"{projectRoot}/src/**/*.ts",
33+
"{projectRoot}/tsconfig.json",
34+
"{workspaceRoot}/package.json"
35+
]
36+
},
37+
"lint": {
38+
"executor": "@nx/eslint:lint",
39+
"outputs": ["{options.outputFile}"],
40+
"options": {
41+
"lintFilePatterns": ["libs/core/**/*.ts"]
42+
}
43+
},
44+
"test": {
45+
"executor": "@nx/vite:test",
46+
"outputs": ["coverage/libs/core"],
47+
"options": {
48+
"passWithNoTests": true,
49+
"reportsDirectory": "../../coverage/libs/core"
50+
},
51+
"cache": true,
52+
"inputs": [
53+
"{projectRoot}/__tests__/**/*",
54+
"{projectRoot}/src/**/*",
55+
"{projectRoot}/vitest.config.ts",
56+
"{projectRoot}/Cargo.toml",
57+
"{projectRoot}/build.rs",
58+
"{workspaceRoot}/package.json"
59+
]
60+
}
61+
},
62+
"tags": []
63+
}

libs/core/scripts/build.sh

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/bin/bash
2+
3+
# Exit on error
4+
set -e
5+
6+
# See https://napi.rs/docs/cli/build for details
7+
8+
# Debug information
9+
echo "Script location: $0"
10+
echo "Current directory: $(pwd)"
11+
echo "Arguments: $@"
12+
13+
# Change to the core directory where Cargo.toml is located
14+
cd "$(dirname "$0")/.." || exit 1
15+
echo "Changed to directory: $(pwd)"
16+
17+
# Set default target if not provided
18+
TARGET=${1:-""}
19+
20+
# Build command with proper error handling
21+
build_native() {
22+
# Use a temporary file to capture any error output
23+
local temp_err=$(mktemp)
24+
25+
if [ "$USE_ZIG" = "true" ]; then
26+
npx @napi-rs/cli build \
27+
--platform \
28+
--target "$TARGET" \
29+
--js src/native.cjs \
30+
--dts src/native.d.ts \
31+
--release \
32+
--zig 2>"$temp_err" || { cat "$temp_err"; rm "$temp_err"; exit 1; }
33+
else
34+
npx @napi-rs/cli build \
35+
--platform \
36+
--target "$TARGET" \
37+
--js src/native.cjs \
38+
--dts src/native.d.ts \
39+
--release 2>"$temp_err" || { cat "$temp_err"; rm "$temp_err"; exit 1; }
40+
fi
41+
42+
rm "$temp_err"
43+
return 0
44+
}
45+
46+
# Execute the build function
47+
build_native
48+
49+
# If we get here, the build was successful
50+
echo "Build completed successfully"
51+
exit 0

libs/core/src/native.cjs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ switch (platform) {
3737
if (localFileExisted) {
3838
nativeBinding = require('./@kevinmichaelchen/cel-typescript.android-arm64.node')
3939
} else {
40-
nativeBinding = require('@kevinmichaelchen/cel-typescript-android-arm64')
40+
nativeBinding = require('@kevinmichaelchen/cel-typescript-core-android-arm64')
4141
}
4242
} catch (e) {
4343
loadError = e
@@ -49,7 +49,7 @@ switch (platform) {
4949
if (localFileExisted) {
5050
nativeBinding = require('./@kevinmichaelchen/cel-typescript.android-arm-eabi.node')
5151
} else {
52-
nativeBinding = require('@kevinmichaelchen/cel-typescript-android-arm-eabi')
52+
nativeBinding = require('@kevinmichaelchen/cel-typescript-core-android-arm-eabi')
5353
}
5454
} catch (e) {
5555
loadError = e
@@ -69,7 +69,7 @@ switch (platform) {
6969
if (localFileExisted) {
7070
nativeBinding = require('./@kevinmichaelchen/cel-typescript.win32-x64-msvc.node')
7171
} else {
72-
nativeBinding = require('@kevinmichaelchen/cel-typescript-win32-x64-msvc')
72+
nativeBinding = require('@kevinmichaelchen/cel-typescript-core-win32-x64-msvc')
7373
}
7474
} catch (e) {
7575
loadError = e
@@ -83,7 +83,7 @@ switch (platform) {
8383
if (localFileExisted) {
8484
nativeBinding = require('./@kevinmichaelchen/cel-typescript.win32-ia32-msvc.node')
8585
} else {
86-
nativeBinding = require('@kevinmichaelchen/cel-typescript-win32-ia32-msvc')
86+
nativeBinding = require('@kevinmichaelchen/cel-typescript-core-win32-ia32-msvc')
8787
}
8888
} catch (e) {
8989
loadError = e
@@ -97,7 +97,7 @@ switch (platform) {
9797
if (localFileExisted) {
9898
nativeBinding = require('./@kevinmichaelchen/cel-typescript.win32-arm64-msvc.node')
9999
} else {
100-
nativeBinding = require('@kevinmichaelchen/cel-typescript-win32-arm64-msvc')
100+
nativeBinding = require('@kevinmichaelchen/cel-typescript-core-win32-arm64-msvc')
101101
}
102102
} catch (e) {
103103
loadError = e
@@ -113,7 +113,7 @@ switch (platform) {
113113
if (localFileExisted) {
114114
nativeBinding = require('./@kevinmichaelchen/cel-typescript.darwin-universal.node')
115115
} else {
116-
nativeBinding = require('@kevinmichaelchen/cel-typescript-darwin-universal')
116+
nativeBinding = require('@kevinmichaelchen/cel-typescript-core-darwin-universal')
117117
}
118118
break
119119
} catch {}
@@ -124,7 +124,7 @@ switch (platform) {
124124
if (localFileExisted) {
125125
nativeBinding = require('./@kevinmichaelchen/cel-typescript.darwin-x64.node')
126126
} else {
127-
nativeBinding = require('@kevinmichaelchen/cel-typescript-darwin-x64')
127+
nativeBinding = require('@kevinmichaelchen/cel-typescript-core-darwin-x64')
128128
}
129129
} catch (e) {
130130
loadError = e
@@ -138,7 +138,7 @@ switch (platform) {
138138
if (localFileExisted) {
139139
nativeBinding = require('./@kevinmichaelchen/cel-typescript.darwin-arm64.node')
140140
} else {
141-
nativeBinding = require('@kevinmichaelchen/cel-typescript-darwin-arm64')
141+
nativeBinding = require('@kevinmichaelchen/cel-typescript-core-darwin-arm64')
142142
}
143143
} catch (e) {
144144
loadError = e
@@ -157,7 +157,7 @@ switch (platform) {
157157
if (localFileExisted) {
158158
nativeBinding = require('./@kevinmichaelchen/cel-typescript.freebsd-x64.node')
159159
} else {
160-
nativeBinding = require('@kevinmichaelchen/cel-typescript-freebsd-x64')
160+
nativeBinding = require('@kevinmichaelchen/cel-typescript-core-freebsd-x64')
161161
}
162162
} catch (e) {
163163
loadError = e
@@ -174,7 +174,7 @@ switch (platform) {
174174
if (localFileExisted) {
175175
nativeBinding = require('./@kevinmichaelchen/cel-typescript.linux-x64-musl.node')
176176
} else {
177-
nativeBinding = require('@kevinmichaelchen/cel-typescript-linux-x64-musl')
177+
nativeBinding = require('@kevinmichaelchen/cel-typescript-core-linux-x64-musl')
178178
}
179179
} catch (e) {
180180
loadError = e
@@ -187,7 +187,7 @@ switch (platform) {
187187
if (localFileExisted) {
188188
nativeBinding = require('./@kevinmichaelchen/cel-typescript.linux-x64-gnu.node')
189189
} else {
190-
nativeBinding = require('@kevinmichaelchen/cel-typescript-linux-x64-gnu')
190+
nativeBinding = require('@kevinmichaelchen/cel-typescript-core-linux-x64-gnu')
191191
}
192192
} catch (e) {
193193
loadError = e
@@ -203,7 +203,7 @@ switch (platform) {
203203
if (localFileExisted) {
204204
nativeBinding = require('./@kevinmichaelchen/cel-typescript.linux-arm64-musl.node')
205205
} else {
206-
nativeBinding = require('@kevinmichaelchen/cel-typescript-linux-arm64-musl')
206+
nativeBinding = require('@kevinmichaelchen/cel-typescript-core-linux-arm64-musl')
207207
}
208208
} catch (e) {
209209
loadError = e
@@ -216,7 +216,7 @@ switch (platform) {
216216
if (localFileExisted) {
217217
nativeBinding = require('./@kevinmichaelchen/cel-typescript.linux-arm64-gnu.node')
218218
} else {
219-
nativeBinding = require('@kevinmichaelchen/cel-typescript-linux-arm64-gnu')
219+
nativeBinding = require('@kevinmichaelchen/cel-typescript-core-linux-arm64-gnu')
220220
}
221221
} catch (e) {
222222
loadError = e
@@ -232,7 +232,7 @@ switch (platform) {
232232
if (localFileExisted) {
233233
nativeBinding = require('./@kevinmichaelchen/cel-typescript.linux-arm-musleabihf.node')
234234
} else {
235-
nativeBinding = require('@kevinmichaelchen/cel-typescript-linux-arm-musleabihf')
235+
nativeBinding = require('@kevinmichaelchen/cel-typescript-core-linux-arm-musleabihf')
236236
}
237237
} catch (e) {
238238
loadError = e
@@ -245,7 +245,7 @@ switch (platform) {
245245
if (localFileExisted) {
246246
nativeBinding = require('./@kevinmichaelchen/cel-typescript.linux-arm-gnueabihf.node')
247247
} else {
248-
nativeBinding = require('@kevinmichaelchen/cel-typescript-linux-arm-gnueabihf')
248+
nativeBinding = require('@kevinmichaelchen/cel-typescript-core-linux-arm-gnueabihf')
249249
}
250250
} catch (e) {
251251
loadError = e
@@ -261,7 +261,7 @@ switch (platform) {
261261
if (localFileExisted) {
262262
nativeBinding = require('./@kevinmichaelchen/cel-typescript.linux-riscv64-musl.node')
263263
} else {
264-
nativeBinding = require('@kevinmichaelchen/cel-typescript-linux-riscv64-musl')
264+
nativeBinding = require('@kevinmichaelchen/cel-typescript-core-linux-riscv64-musl')
265265
}
266266
} catch (e) {
267267
loadError = e
@@ -274,7 +274,7 @@ switch (platform) {
274274
if (localFileExisted) {
275275
nativeBinding = require('./@kevinmichaelchen/cel-typescript.linux-riscv64-gnu.node')
276276
} else {
277-
nativeBinding = require('@kevinmichaelchen/cel-typescript-linux-riscv64-gnu')
277+
nativeBinding = require('@kevinmichaelchen/cel-typescript-core-linux-riscv64-gnu')
278278
}
279279
} catch (e) {
280280
loadError = e
@@ -289,7 +289,7 @@ switch (platform) {
289289
if (localFileExisted) {
290290
nativeBinding = require('./@kevinmichaelchen/cel-typescript.linux-s390x-gnu.node')
291291
} else {
292-
nativeBinding = require('@kevinmichaelchen/cel-typescript-linux-s390x-gnu')
292+
nativeBinding = require('@kevinmichaelchen/cel-typescript-core-linux-s390x-gnu')
293293
}
294294
} catch (e) {
295295
loadError = e

nx.json

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,6 @@
22
"$schema": "./node_modules/nx/schemas/nx-schema.json",
33
"defaultBase": "main",
44
"targetDefaults": {
5-
"build:native": {
6-
"cache": true,
7-
"inputs": [
8-
"{projectRoot}/src/**/*",
9-
"{projectRoot}/Cargo.toml",
10-
"{projectRoot}/Cargo.lock"
11-
],
12-
"outputs": ["{workspaceRoot}/cel-typescript.*.node"]
13-
},
145
"build:ts": {
156
"cache": true,
167
"inputs": [

package.json

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,8 @@
44
"type": "module",
55
"private": true,
66
"description": "TypeScript bindings for the Common Expression Language (CEL) using cel-rust",
7-
"napi": {
8-
"name": "@kevinmichaelchen/cel-typescript",
9-
"triples": {
10-
"defaults": false,
11-
"additional": [
12-
"aarch64-apple-darwin",
13-
"x86_64-apple-darwin",
14-
"x86_64-unknown-linux-gnu",
15-
"aarch64-unknown-linux-gnu",
16-
"x86_64-pc-windows-msvc"
17-
]
18-
}
19-
},
207
"scripts": {
21-
"build:native": "nx build:native",
8+
"build:native": "nx run core:build:native",
229
"build:ts": "nx build:ts",
2310
"format": "nx run cel-typescript:format",
2411
"format:check": "nx run cel-typescript:format:check",

0 commit comments

Comments
 (0)