diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d039a4a..00ddcc8 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -46,9 +46,6 @@ jobs: - name: Build Native Binding run: pnpm --filter rstack build:native:release - - name: Test Native Binding - run: pnpm --filter rstack test:native - - name: Check Generated Native Files run: git diff --exit-code -- packages/rstack/binding.cjs packages/rstack/binding.d.cts diff --git a/packages/rstack/package.json b/packages/rstack/package.json index 6bd60eb..ce8b0c0 100644 --- a/packages/rstack/package.json +++ b/packages/rstack/package.json @@ -56,6 +56,8 @@ }, "files": [ "bin", + "binding.cjs", + "binding.d.cts", "dist", "types", "THIRD_PARTY_NOTICES.md" @@ -65,8 +67,7 @@ "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", "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", "dev": "rslib -w", - "test": "rs test", - "test:native": "node --test tests/native-smoke.cjs" + "test": "rs test" }, "dependencies": { "@rsbuild/core": "catalog:", diff --git a/packages/rstack/rslib.config.ts b/packages/rstack/rslib.config.ts index bf5cf0e..80c4fe5 100644 --- a/packages/rstack/rslib.config.ts +++ b/packages/rstack/rslib.config.ts @@ -20,6 +20,7 @@ export default defineConfig({ lib: './src/lib.ts', lint: './src/lint.ts', test: './src/test.ts', + 'native/index': './src/native/index.ts', fmtWorker: './src/fmt/worker.ts', }, define: { diff --git a/packages/rstack/src/native/index.ts b/packages/rstack/src/native/index.ts new file mode 100644 index 0000000..bf68232 --- /dev/null +++ b/packages/rstack/src/native/index.ts @@ -0,0 +1,10 @@ +import { createRequire } from 'node:module'; +import path from 'node:path'; + +export type NativeBinding = typeof import('../../binding.cjs'); + +const require = createRequire(import.meta.url); +export const loadNativeBinding = (): NativeBinding => { + const packageJsonPath = require.resolve('rstack/package.json'); + return require(path.join(path.dirname(packageJsonPath), 'binding.cjs')) as NativeBinding; +}; diff --git a/packages/rstack/tests/native-smoke.cjs b/packages/rstack/tests/native-smoke.cjs deleted file mode 100644 index edad44a..0000000 --- a/packages/rstack/tests/native-smoke.cjs +++ /dev/null @@ -1,8 +0,0 @@ -const assert = require('node:assert/strict'); -const test = require('node:test'); - -const { nativePing } = require('../binding.cjs'); - -test('passes a string from JavaScript through Rust and back', () => { - assert.equal(nativePing('rstack'), 'pong:rstack'); -}); diff --git a/packages/rstack/tests/native/smoke.test.ts b/packages/rstack/tests/native/smoke.test.ts new file mode 100644 index 0000000..2e01b53 --- /dev/null +++ b/packages/rstack/tests/native/smoke.test.ts @@ -0,0 +1,6 @@ +import { expect, test } from 'rstack/test'; +import { loadNativeBinding } from '../../dist/native/index.js'; + +test('passes a string through the private loader and Rust', () => { + expect(loadNativeBinding().nativePing('rstack')).toBe('pong:rstack'); +}); diff --git a/scripts/dictionary.txt b/scripts/dictionary.txt index 650e7fd..b582a20 100644 --- a/scripts/dictionary.txt +++ b/scripts/dictionary.txt @@ -7,6 +7,7 @@ fnames huskyrc indentable llms +napi noformat noprettier nosystem