Skip to content

Commit 83ea1a2

Browse files
chore: new loader file
1 parent 519d8b0 commit 83ea1a2

File tree

5 files changed

+86
-60
lines changed

5 files changed

+86
-60
lines changed

biome.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
},
66
"files": {
77
"include": ["**/*.ts", "**/*.tsx", "**/*.js", "**/*.jsx", "**/*.json"],
8-
"ignore": [".nx", "index.js", "index.d.ts", "dist/**/*"]
8+
"ignore": [".nx", "dist/**/*", "src/native.cjs", "src/native.d.ts"]
99
},
1010
"formatter": {
1111
"enabled": true,
1212
"indentStyle": "space",
1313
"indentWidth": 2,
1414
"lineWidth": 80,
15-
"ignore": ["index.js", "index.d.ts"]
15+
"ignore": ["src/native.cjs", "src/native.d.ts"]
1616
},
1717
"linter": {
1818
"enabled": true,

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "0.0.11",
44
"type": "module",
55
"description": "TypeScript bindings for the Common Expression Language (CEL) using cel-rust",
6-
"files": ["dist/src/**/*", "*.node", "index.js", "index.d.ts"],
6+
"files": ["dist/src/**/*"],
77
"types": "./dist/src/index.d.ts",
88
"exports": {
99
".": {
@@ -12,7 +12,7 @@
1212
}
1313
},
1414
"napi": {
15-
"name": "cel-typescript",
15+
"name": "@kevinmichaelchen/cel-typescript",
1616
"triples": {
1717
"defaults": false,
1818
"additional": [

scripts/build.sh

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,33 @@
11
#!/bin/bash
22

3+
# See https://napi.rs/docs/cli/build for details
4+
35
if [ "$USE_ZIG" = "true" ]; then
4-
npx @napi-rs/cli build --platform --target "$1" --js src/native.cjs --release --zig
6+
npx @napi-rs/cli build \
7+
# Add platform triple to the .node file (e.g., [name].linux-x64-gnu.node)
8+
--platform \
9+
10+
# Target triple (e.g., x86_64-apple-darwin)
11+
--target "$1" \
12+
13+
# The filename and path of the JavaScript binding file
14+
--js src/native.cjs \
15+
16+
# TypeScript declaration file
17+
--dts src/native.d.ts \
18+
19+
# Bypass to cargo build --release
20+
--release \
21+
22+
# @napi-rs/cli will use zig as cc / cxx and linker to build your program.
23+
--zig
24+
525
else
6-
npx @napi-rs/cli build --platform --target "$1" --js src/native.cjs --release
26+
npx @napi-rs/cli build \
27+
--platform \
28+
--target "$1" \
29+
--js src/native.cjs \
30+
--dts src/native.d.ts \
31+
--release
32+
733
fi

index.js renamed to src/native.cjs

Lines changed: 54 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,24 @@ switch (platform) {
3232
case 'android':
3333
switch (arch) {
3434
case 'arm64':
35-
localFileExisted = existsSync(join(__dirname, 'cel-typescript.android-arm64.node'))
35+
localFileExisted = existsSync(join(__dirname, '@kevinmichaelchen/cel-typescript.android-arm64.node'))
3636
try {
3737
if (localFileExisted) {
38-
nativeBinding = require('./cel-typescript.android-arm64.node')
38+
nativeBinding = require('./@kevinmichaelchen/cel-typescript.android-arm64.node')
3939
} else {
40-
nativeBinding = require('cel-typescript-android-arm64')
40+
nativeBinding = require('@kevinmichaelchen/cel-typescript-android-arm64')
4141
}
4242
} catch (e) {
4343
loadError = e
4444
}
4545
break
4646
case 'arm':
47-
localFileExisted = existsSync(join(__dirname, 'cel-typescript.android-arm-eabi.node'))
47+
localFileExisted = existsSync(join(__dirname, '@kevinmichaelchen/cel-typescript.android-arm-eabi.node'))
4848
try {
4949
if (localFileExisted) {
50-
nativeBinding = require('./cel-typescript.android-arm-eabi.node')
50+
nativeBinding = require('./@kevinmichaelchen/cel-typescript.android-arm-eabi.node')
5151
} else {
52-
nativeBinding = require('cel-typescript-android-arm-eabi')
52+
nativeBinding = require('@kevinmichaelchen/cel-typescript-android-arm-eabi')
5353
}
5454
} catch (e) {
5555
loadError = e
@@ -63,41 +63,41 @@ switch (platform) {
6363
switch (arch) {
6464
case 'x64':
6565
localFileExisted = existsSync(
66-
join(__dirname, 'cel-typescript.win32-x64-msvc.node')
66+
join(__dirname, '@kevinmichaelchen/cel-typescript.win32-x64-msvc.node')
6767
)
6868
try {
6969
if (localFileExisted) {
70-
nativeBinding = require('./cel-typescript.win32-x64-msvc.node')
70+
nativeBinding = require('./@kevinmichaelchen/cel-typescript.win32-x64-msvc.node')
7171
} else {
72-
nativeBinding = require('cel-typescript-win32-x64-msvc')
72+
nativeBinding = require('@kevinmichaelchen/cel-typescript-win32-x64-msvc')
7373
}
7474
} catch (e) {
7575
loadError = e
7676
}
7777
break
7878
case 'ia32':
7979
localFileExisted = existsSync(
80-
join(__dirname, 'cel-typescript.win32-ia32-msvc.node')
80+
join(__dirname, '@kevinmichaelchen/cel-typescript.win32-ia32-msvc.node')
8181
)
8282
try {
8383
if (localFileExisted) {
84-
nativeBinding = require('./cel-typescript.win32-ia32-msvc.node')
84+
nativeBinding = require('./@kevinmichaelchen/cel-typescript.win32-ia32-msvc.node')
8585
} else {
86-
nativeBinding = require('cel-typescript-win32-ia32-msvc')
86+
nativeBinding = require('@kevinmichaelchen/cel-typescript-win32-ia32-msvc')
8787
}
8888
} catch (e) {
8989
loadError = e
9090
}
9191
break
9292
case 'arm64':
9393
localFileExisted = existsSync(
94-
join(__dirname, 'cel-typescript.win32-arm64-msvc.node')
94+
join(__dirname, '@kevinmichaelchen/cel-typescript.win32-arm64-msvc.node')
9595
)
9696
try {
9797
if (localFileExisted) {
98-
nativeBinding = require('./cel-typescript.win32-arm64-msvc.node')
98+
nativeBinding = require('./@kevinmichaelchen/cel-typescript.win32-arm64-msvc.node')
9999
} else {
100-
nativeBinding = require('cel-typescript-win32-arm64-msvc')
100+
nativeBinding = require('@kevinmichaelchen/cel-typescript-win32-arm64-msvc')
101101
}
102102
} catch (e) {
103103
loadError = e
@@ -108,37 +108,37 @@ switch (platform) {
108108
}
109109
break
110110
case 'darwin':
111-
localFileExisted = existsSync(join(__dirname, 'cel-typescript.darwin-universal.node'))
111+
localFileExisted = existsSync(join(__dirname, '@kevinmichaelchen/cel-typescript.darwin-universal.node'))
112112
try {
113113
if (localFileExisted) {
114-
nativeBinding = require('./cel-typescript.darwin-universal.node')
114+
nativeBinding = require('./@kevinmichaelchen/cel-typescript.darwin-universal.node')
115115
} else {
116-
nativeBinding = require('cel-typescript-darwin-universal')
116+
nativeBinding = require('@kevinmichaelchen/cel-typescript-darwin-universal')
117117
}
118118
break
119119
} catch {}
120120
switch (arch) {
121121
case 'x64':
122-
localFileExisted = existsSync(join(__dirname, 'cel-typescript.darwin-x64.node'))
122+
localFileExisted = existsSync(join(__dirname, '@kevinmichaelchen/cel-typescript.darwin-x64.node'))
123123
try {
124124
if (localFileExisted) {
125-
nativeBinding = require('./cel-typescript.darwin-x64.node')
125+
nativeBinding = require('./@kevinmichaelchen/cel-typescript.darwin-x64.node')
126126
} else {
127-
nativeBinding = require('cel-typescript-darwin-x64')
127+
nativeBinding = require('@kevinmichaelchen/cel-typescript-darwin-x64')
128128
}
129129
} catch (e) {
130130
loadError = e
131131
}
132132
break
133133
case 'arm64':
134134
localFileExisted = existsSync(
135-
join(__dirname, 'cel-typescript.darwin-arm64.node')
135+
join(__dirname, '@kevinmichaelchen/cel-typescript.darwin-arm64.node')
136136
)
137137
try {
138138
if (localFileExisted) {
139-
nativeBinding = require('./cel-typescript.darwin-arm64.node')
139+
nativeBinding = require('./@kevinmichaelchen/cel-typescript.darwin-arm64.node')
140140
} else {
141-
nativeBinding = require('cel-typescript-darwin-arm64')
141+
nativeBinding = require('@kevinmichaelchen/cel-typescript-darwin-arm64')
142142
}
143143
} catch (e) {
144144
loadError = e
@@ -152,12 +152,12 @@ switch (platform) {
152152
if (arch !== 'x64') {
153153
throw new Error(`Unsupported architecture on FreeBSD: ${arch}`)
154154
}
155-
localFileExisted = existsSync(join(__dirname, 'cel-typescript.freebsd-x64.node'))
155+
localFileExisted = existsSync(join(__dirname, '@kevinmichaelchen/cel-typescript.freebsd-x64.node'))
156156
try {
157157
if (localFileExisted) {
158-
nativeBinding = require('./cel-typescript.freebsd-x64.node')
158+
nativeBinding = require('./@kevinmichaelchen/cel-typescript.freebsd-x64.node')
159159
} else {
160-
nativeBinding = require('cel-typescript-freebsd-x64')
160+
nativeBinding = require('@kevinmichaelchen/cel-typescript-freebsd-x64')
161161
}
162162
} catch (e) {
163163
loadError = e
@@ -168,26 +168,26 @@ switch (platform) {
168168
case 'x64':
169169
if (isMusl()) {
170170
localFileExisted = existsSync(
171-
join(__dirname, 'cel-typescript.linux-x64-musl.node')
171+
join(__dirname, '@kevinmichaelchen/cel-typescript.linux-x64-musl.node')
172172
)
173173
try {
174174
if (localFileExisted) {
175-
nativeBinding = require('./cel-typescript.linux-x64-musl.node')
175+
nativeBinding = require('./@kevinmichaelchen/cel-typescript.linux-x64-musl.node')
176176
} else {
177-
nativeBinding = require('cel-typescript-linux-x64-musl')
177+
nativeBinding = require('@kevinmichaelchen/cel-typescript-linux-x64-musl')
178178
}
179179
} catch (e) {
180180
loadError = e
181181
}
182182
} else {
183183
localFileExisted = existsSync(
184-
join(__dirname, 'cel-typescript.linux-x64-gnu.node')
184+
join(__dirname, '@kevinmichaelchen/cel-typescript.linux-x64-gnu.node')
185185
)
186186
try {
187187
if (localFileExisted) {
188-
nativeBinding = require('./cel-typescript.linux-x64-gnu.node')
188+
nativeBinding = require('./@kevinmichaelchen/cel-typescript.linux-x64-gnu.node')
189189
} else {
190-
nativeBinding = require('cel-typescript-linux-x64-gnu')
190+
nativeBinding = require('@kevinmichaelchen/cel-typescript-linux-x64-gnu')
191191
}
192192
} catch (e) {
193193
loadError = e
@@ -197,26 +197,26 @@ switch (platform) {
197197
case 'arm64':
198198
if (isMusl()) {
199199
localFileExisted = existsSync(
200-
join(__dirname, 'cel-typescript.linux-arm64-musl.node')
200+
join(__dirname, '@kevinmichaelchen/cel-typescript.linux-arm64-musl.node')
201201
)
202202
try {
203203
if (localFileExisted) {
204-
nativeBinding = require('./cel-typescript.linux-arm64-musl.node')
204+
nativeBinding = require('./@kevinmichaelchen/cel-typescript.linux-arm64-musl.node')
205205
} else {
206-
nativeBinding = require('cel-typescript-linux-arm64-musl')
206+
nativeBinding = require('@kevinmichaelchen/cel-typescript-linux-arm64-musl')
207207
}
208208
} catch (e) {
209209
loadError = e
210210
}
211211
} else {
212212
localFileExisted = existsSync(
213-
join(__dirname, 'cel-typescript.linux-arm64-gnu.node')
213+
join(__dirname, '@kevinmichaelchen/cel-typescript.linux-arm64-gnu.node')
214214
)
215215
try {
216216
if (localFileExisted) {
217-
nativeBinding = require('./cel-typescript.linux-arm64-gnu.node')
217+
nativeBinding = require('./@kevinmichaelchen/cel-typescript.linux-arm64-gnu.node')
218218
} else {
219-
nativeBinding = require('cel-typescript-linux-arm64-gnu')
219+
nativeBinding = require('@kevinmichaelchen/cel-typescript-linux-arm64-gnu')
220220
}
221221
} catch (e) {
222222
loadError = e
@@ -226,26 +226,26 @@ switch (platform) {
226226
case 'arm':
227227
if (isMusl()) {
228228
localFileExisted = existsSync(
229-
join(__dirname, 'cel-typescript.linux-arm-musleabihf.node')
229+
join(__dirname, '@kevinmichaelchen/cel-typescript.linux-arm-musleabihf.node')
230230
)
231231
try {
232232
if (localFileExisted) {
233-
nativeBinding = require('./cel-typescript.linux-arm-musleabihf.node')
233+
nativeBinding = require('./@kevinmichaelchen/cel-typescript.linux-arm-musleabihf.node')
234234
} else {
235-
nativeBinding = require('cel-typescript-linux-arm-musleabihf')
235+
nativeBinding = require('@kevinmichaelchen/cel-typescript-linux-arm-musleabihf')
236236
}
237237
} catch (e) {
238238
loadError = e
239239
}
240240
} else {
241241
localFileExisted = existsSync(
242-
join(__dirname, 'cel-typescript.linux-arm-gnueabihf.node')
242+
join(__dirname, '@kevinmichaelchen/cel-typescript.linux-arm-gnueabihf.node')
243243
)
244244
try {
245245
if (localFileExisted) {
246-
nativeBinding = require('./cel-typescript.linux-arm-gnueabihf.node')
246+
nativeBinding = require('./@kevinmichaelchen/cel-typescript.linux-arm-gnueabihf.node')
247247
} else {
248-
nativeBinding = require('cel-typescript-linux-arm-gnueabihf')
248+
nativeBinding = require('@kevinmichaelchen/cel-typescript-linux-arm-gnueabihf')
249249
}
250250
} catch (e) {
251251
loadError = e
@@ -255,26 +255,26 @@ switch (platform) {
255255
case 'riscv64':
256256
if (isMusl()) {
257257
localFileExisted = existsSync(
258-
join(__dirname, 'cel-typescript.linux-riscv64-musl.node')
258+
join(__dirname, '@kevinmichaelchen/cel-typescript.linux-riscv64-musl.node')
259259
)
260260
try {
261261
if (localFileExisted) {
262-
nativeBinding = require('./cel-typescript.linux-riscv64-musl.node')
262+
nativeBinding = require('./@kevinmichaelchen/cel-typescript.linux-riscv64-musl.node')
263263
} else {
264-
nativeBinding = require('cel-typescript-linux-riscv64-musl')
264+
nativeBinding = require('@kevinmichaelchen/cel-typescript-linux-riscv64-musl')
265265
}
266266
} catch (e) {
267267
loadError = e
268268
}
269269
} else {
270270
localFileExisted = existsSync(
271-
join(__dirname, 'cel-typescript.linux-riscv64-gnu.node')
271+
join(__dirname, '@kevinmichaelchen/cel-typescript.linux-riscv64-gnu.node')
272272
)
273273
try {
274274
if (localFileExisted) {
275-
nativeBinding = require('./cel-typescript.linux-riscv64-gnu.node')
275+
nativeBinding = require('./@kevinmichaelchen/cel-typescript.linux-riscv64-gnu.node')
276276
} else {
277-
nativeBinding = require('cel-typescript-linux-riscv64-gnu')
277+
nativeBinding = require('@kevinmichaelchen/cel-typescript-linux-riscv64-gnu')
278278
}
279279
} catch (e) {
280280
loadError = e
@@ -283,13 +283,13 @@ switch (platform) {
283283
break
284284
case 's390x':
285285
localFileExisted = existsSync(
286-
join(__dirname, 'cel-typescript.linux-s390x-gnu.node')
286+
join(__dirname, '@kevinmichaelchen/cel-typescript.linux-s390x-gnu.node')
287287
)
288288
try {
289289
if (localFileExisted) {
290-
nativeBinding = require('./cel-typescript.linux-s390x-gnu.node')
290+
nativeBinding = require('./@kevinmichaelchen/cel-typescript.linux-s390x-gnu.node')
291291
} else {
292-
nativeBinding = require('cel-typescript-linux-s390x-gnu')
292+
nativeBinding = require('@kevinmichaelchen/cel-typescript-linux-s390x-gnu')
293293
}
294294
} catch (e) {
295295
loadError = e
File renamed without changes.

0 commit comments

Comments
 (0)