Skip to content

Commit e5fff19

Browse files
committed
feat(native): add internal binding loader
1 parent 22bdcfe commit e5fff19

7 files changed

Lines changed: 21 additions & 13 deletions

File tree

.github/workflows/test.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,6 @@ jobs:
4646
- name: Build Native Binding
4747
run: pnpm --filter rstack build:native:release
4848

49-
- name: Test Native Binding
50-
run: pnpm --filter rstack test:native
51-
5249
- name: Check Generated Native Files
5350
run: git diff --exit-code -- packages/rstack/binding.cjs packages/rstack/binding.d.cts
5451

packages/rstack/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@
5656
},
5757
"files": [
5858
"bin",
59+
"binding.cjs",
60+
"binding.d.cts",
5961
"dist",
6062
"types",
6163
"THIRD_PARTY_NOTICES.md"
@@ -65,8 +67,7 @@
6567
"build:native": "napi build --platform --manifest-path ../../Cargo.toml --package rstack-binding --package-json-path package.json --output-dir . --js binding.cjs --dts binding.d.cts",
6668
"build:native:release": "napi build --platform --release --manifest-path ../../Cargo.toml --package rstack-binding --package-json-path package.json --output-dir . --js binding.cjs --dts binding.d.cts",
6769
"dev": "rslib -w",
68-
"test": "rs test",
69-
"test:native": "node --test tests/native-smoke.cjs"
70+
"test": "rs test"
7071
},
7172
"dependencies": {
7273
"@rsbuild/core": "catalog:",

packages/rstack/rslib.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export default defineConfig({
2020
lib: './src/lib.ts',
2121
lint: './src/lint.ts',
2222
test: './src/test.ts',
23+
'native/index': './src/native/index.ts',
2324
fmtWorker: './src/fmt/worker.ts',
2425
},
2526
define: {
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { createRequire } from 'node:module';
2+
import path from 'node:path';
3+
4+
export type NativeBinding = typeof import('../../binding.cjs');
5+
6+
const require = createRequire(import.meta.url);
7+
export const loadNativeBinding = (): NativeBinding => {
8+
const packageJsonPath = require.resolve('rstack/package.json');
9+
return require(path.join(path.dirname(packageJsonPath), 'binding.cjs')) as NativeBinding;
10+
};

packages/rstack/tests/native-smoke.cjs

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { expect, test } from 'rstack/test';
2+
import { loadNativeBinding } from '../../dist/native/index.js';
3+
4+
test('passes a string through the private loader and Rust', () => {
5+
expect(loadNativeBinding().nativePing('rstack')).toBe('pong:rstack');
6+
});

scripts/dictionary.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ fnames
77
huskyrc
88
indentable
99
llms
10+
napi
1011
noformat
1112
noprettier
1213
nosystem

0 commit comments

Comments
 (0)