Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bench/structs.bench.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Bench } from "tinybench"
import { defineStruct, defineEnum } from "../src/structs_ffi"
import { defineStruct, defineEnum } from "../src/structs_ffi.js"

const SimpleStruct = defineStruct([
["id", "u32"],
Expand Down
1 change: 1 addition & 0 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/01-basic-primitives.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defineStruct } from "../src/structs_ffi"
import { defineStruct } from "../src/structs_ffi.js"

console.log("=== Example 1: Basic Primitive Types ===\n")

Expand Down
2 changes: 1 addition & 1 deletion examples/02-enums.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defineEnum, defineStruct } from "../src/structs_ffi"
import { defineEnum, defineStruct } from "../src/structs_ffi.js"

console.log("=== Example 2: Enums ===\n")

Expand Down
2 changes: 1 addition & 1 deletion examples/03-nested-structs.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defineStruct } from "../src/structs_ffi"
import { defineStruct } from "../src/structs_ffi.js"

console.log("=== Example 3: Nested Structs ===\n")

Expand Down
2 changes: 1 addition & 1 deletion examples/04-arrays.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defineEnum, defineStruct } from "../src/structs_ffi"
import { defineEnum, defineStruct } from "../src/structs_ffi.js"

console.log("=== Example 4: Arrays ===\n")

Expand Down
2 changes: 1 addition & 1 deletion examples/05-defaults-optional.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defineStruct } from "../src/structs_ffi"
import { defineStruct } from "../src/structs_ffi.js"

console.log("=== Example 5: Optional Fields and Defaults ===\n")

Expand Down
2 changes: 1 addition & 1 deletion examples/06-transforms.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defineStruct } from "../src/structs_ffi"
import { defineStruct } from "../src/structs_ffi.js"

console.log("=== Example 6: Pack and Unpack Transforms ===\n")

Expand Down
2 changes: 1 addition & 1 deletion examples/07-validation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defineStruct } from "../src/structs_ffi"
import { defineStruct } from "../src/structs_ffi.js"

console.log("=== Example 7: Field Validation ===\n")

Expand Down
2 changes: 1 addition & 1 deletion examples/08-alloc-struct.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defineStruct, allocStruct } from "../src/structs_ffi"
import { defineStruct, allocStruct } from "../src/structs_ffi.js"

console.log("=== Example 8: Pre-allocating Structs with Arrays ===\n")

Expand Down
2 changes: 1 addition & 1 deletion examples/09-struct-arrays.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defineStruct } from "../src/structs_ffi"
import { defineStruct } from "../src/structs_ffi.js"

console.log("=== Example 9: Arrays of Structs ===\n")

Expand Down
2 changes: 1 addition & 1 deletion examples/10-complex-webgpu.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defineEnum, defineStruct } from "../src/structs_ffi"
import { defineEnum, defineStruct } from "../src/structs_ffi.js"

console.log("=== Example 10: Complex WebGPU-like Structure ===\n")

Expand Down
2 changes: 1 addition & 1 deletion examples/11-object-pointers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defineStruct, objectPtr } from "../src/structs_ffi"
import { defineStruct, objectPtr } from "../src/structs_ffi.js"

console.log("=== Example 11: Object Pointers ===\n")

Expand Down
2 changes: 1 addition & 1 deletion examples/12-object-pointer-arrays.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defineStruct, objectPtr } from "../src/structs_ffi"
import { defineStruct, objectPtr } from "../src/structs_ffi.js"

console.log("=== Example 12: Arrays of Object Pointers ===\n")

Expand Down
2 changes: 1 addition & 1 deletion examples/13-nested-as-pointer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defineStruct } from "../src/structs_ffi"
import { defineStruct } from "../src/structs_ffi.js"

console.log("=== Example 13: Nested Structs as Pointers ===\n")

Expand Down
2 changes: 1 addition & 1 deletion examples/14-field-transforms.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defineEnum, defineStruct } from "../src/structs_ffi"
import { defineEnum, defineStruct } from "../src/structs_ffi.js"

console.log("=== Example 14: Field-level Transforms ===\n")

Expand Down
2 changes: 1 addition & 1 deletion examples/15-pack-into.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defineStruct } from "../src/structs_ffi"
import { defineStruct } from "../src/structs_ffi.js"

console.log("=== Example 15: packInto for Zero-Copy Writes ===\n")

Expand Down
2 changes: 1 addition & 1 deletion examples/16-cstring-vs-char-star.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defineStruct } from "../src/structs_ffi"
import { defineStruct } from "../src/structs_ffi.js"

console.log("=== Example 16: cstring vs char* ===\n")

Expand Down
2 changes: 1 addition & 1 deletion examples/17-condition-fields.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defineStruct } from "../src/structs_ffi"
import { defineStruct } from "../src/structs_ffi.js"

console.log("=== Example 17: Conditional Fields ===\n")

Expand Down
2 changes: 1 addition & 1 deletion examples/18-optional-pointer-transforms.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defineStruct } from "../src/structs_ffi"
import { defineStruct } from "../src/structs_ffi.js"

console.log("=== Example 18: Optional Pointer with Type Transforms ===\n")

Expand Down
2 changes: 1 addition & 1 deletion examples/19-pack-list.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defineStruct } from "../src/structs_ffi"
import { defineStruct } from "../src/structs_ffi.js"

console.log("=== Example 19: packList/unpackList for Efficient Batch Operations ===\n")

Expand Down
2 changes: 1 addition & 1 deletion examples/20-list-unpack-char-star.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defineStruct } from "../src/structs_ffi"
import { defineStruct } from "../src/structs_ffi.js"

console.log("=== Example 20: List Unpacking with char* and lengthOf ===\n")

Expand Down
2 changes: 1 addition & 1 deletion examples/native/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PersonStruct, getAge, getHeight, getWeight, getName, calculateBMI } from "./lib"
import { PersonStruct, getAge, getHeight, getWeight, getName, calculateBMI } from "./lib.js"

console.log("=== Native FFI with Struct Packing ===\n")

Expand Down
2 changes: 1 addition & 1 deletion examples/native/lib.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { dlopen, CString, ptr } from "bun:ffi"
import { defineStruct } from "../../src/structs_ffi"
import { defineStruct } from "../../src/structs_ffi.js"

const PersonStruct = defineStruct([
["age", "u32"],
Expand Down
14 changes: 12 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
{
"name": "bun-ffi-structs",
"version": "0.1.3",
"module": "src/index.ts",
"main": "src/index.ts",
"module": "./dist/index.js",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"license": "MIT",
"type": "module",
"files": [
"dist"
],
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.js"
}
},
"repository": {
"type": "git",
"url": "https://github.com/sst/bun-ffi-structs.git"
Expand Down
14 changes: 0 additions & 14 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,4 @@ bun build src/index.ts --outdir dist --target node
echo "Generating TypeScript declarations..."
bunx tsc --project tsconfig.build.json

echo "Copying package files..."
cp package.json dist/
cp README.md dist/
cp LICENSE dist/ 2>/dev/null || echo "No LICENSE file found"

echo "Updating dist/package.json..."
cd dist
cat package.json | \
sed 's|"module": "src/index.ts"|"module": "index.js"|' | \
sed 's|"main": "src/index.ts"|"main": "index.js"|' | \
sed '/"main":/a\
"types": "index.d.ts",' > package.json.tmp
mv package.json.tmp package.json

echo "Build completed successfully!"
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from "./structs_ffi"
export * from "./types"
export * from "./structs_ffi.js"
export * from "./types.js"
2 changes: 1 addition & 1 deletion src/structs_ffi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import type {
StructDefOptions,
DefineStructReturnType,
PrimitiveToTSType,
} from "./types"
} from "./types.js"

function fatalError(...args: any[]): never {
const message = args.join(" ")
Expand Down
2 changes: 1 addition & 1 deletion src/tests/char-star-unpacking.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, describe, it } from "bun:test"
import { defineStruct } from "../structs_ffi"
import { defineStruct } from "../structs_ffi.js"
import { ptr } from "bun:ffi"

describe("char* automatic unpacking", () => {
Expand Down
2 changes: 1 addition & 1 deletion src/tests/conditional-fields.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, describe, it } from "bun:test"
import { defineEnum, defineStruct } from "../structs_ffi"
import { defineEnum, defineStruct } from "../structs_ffi.js"

describe("conditional fields", () => {
it("should include field when condition returns true", () => {
Expand Down
2 changes: 1 addition & 1 deletion src/tests/example-02-enums.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, it, expect } from "bun:test"
import { defineEnum, defineStruct } from "../structs_ffi"
import { defineEnum, defineStruct } from "../structs_ffi.js"

describe("Example 2: Enums (exact reproduction)", () => {
it("should work exactly like the example", () => {
Expand Down
2 changes: 1 addition & 1 deletion src/tests/field-validation.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect, describe, it } from "bun:test"
import { toArrayBuffer } from "bun:ffi"
import { defineEnum, defineStruct } from "../structs_ffi"
import { defineEnum, defineStruct } from "../structs_ffi.js"

describe("field validation", () => {
it("should validate primitive fields and throw on invalid values", () => {
Expand Down
2 changes: 1 addition & 1 deletion src/tests/graphemes.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect, describe, it } from "bun:test"
import { toArrayBuffer } from "bun:ffi"
import { defineStruct } from "../structs_ffi"
import { defineStruct } from "../structs_ffi.js"

describe("string packing with graphemes and emojis", () => {
it("should pack and unpack char* with byte length (not character count) for ASCII", () => {
Expand Down
2 changes: 1 addition & 1 deletion src/tests/list-packing.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, describe, it } from "bun:test"
import { defineEnum, defineStruct } from "../structs_ffi"
import { defineEnum, defineStruct } from "../structs_ffi.js"

describe("packList", () => {
it("should pack a list of simple structs into a single buffer", () => {
Expand Down
2 changes: 1 addition & 1 deletion src/tests/native.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { dlopen, ptr, toArrayBuffer } from "bun:ffi"
import { execSync } from "child_process"
import { existsSync } from "fs"
import { join } from "path"
import { defineStruct } from "../structs_ffi"
import { defineStruct } from "../structs_ffi.js"

const testDir = __dirname
const libPath = join(testDir, "libtest.dylib")
Expand Down
2 changes: 1 addition & 1 deletion src/tests/struct-complex.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect, describe, it } from "bun:test"
import { toArrayBuffer } from "bun:ffi"
import { defineEnum, defineStruct } from "../structs_ffi"
import { defineEnum, defineStruct } from "../structs_ffi.js"

describe("complex struct with length field and nested arrays", () => {
it("should handle bind group layout-like structure", () => {
Expand Down
2 changes: 1 addition & 1 deletion src/tests/struct-options.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect, describe, it } from "bun:test"
import { toArrayBuffer } from "bun:ffi"
import { defineStruct } from "../structs_ffi"
import { defineStruct } from "../structs_ffi.js"

describe("struct options", () => {
it("should apply mapValue transformation", () => {
Expand Down
2 changes: 1 addition & 1 deletion src/tests/struct-utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, describe, it } from "bun:test"
import { defineEnum, defineStruct, objectPtr, allocStruct } from "../structs_ffi"
import { defineEnum, defineStruct, objectPtr, allocStruct } from "../structs_ffi.js"

describe("struct utilities", () => {
it("should allocate struct buffer", () => {
Expand Down
2 changes: 1 addition & 1 deletion src/tests/structs.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, describe, it } from "bun:test"
import { defineEnum, defineStruct, objectPtr, allocStruct, packObjectArray } from "../structs_ffi"
import { defineEnum, defineStruct, objectPtr, allocStruct, packObjectArray } from "../structs_ffi.js"
import { toArrayBuffer } from "bun:ffi"

describe("Structs FFI", () => {
Expand Down
8 changes: 4 additions & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
"compilerOptions": {
// Environment setup & latest features
"lib": ["ESNext"],
"types": ["bun"],
"target": "ESNext",
"module": "Preserve",
"module": "NodeNext",
"moduleDetection": "force",
"jsx": "react-jsx",
"allowJs": true,

// Bundler mode
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
// Module resolution
"moduleResolution": "NodeNext",
"verbatimModuleSyntax": true,
"noEmit": true,

Expand Down