Skip to content
Merged
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
134 changes: 110 additions & 24 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ jobs:
shell: bash

- name: Build
run: npx nx build:native -- --target ${{ matrix.target }}
run: npx nx run @kevinmichaelchen/cel-typescript-core:build:native --target=${{ matrix.target }}
env:
USE_ZIG: ${{ runner.os == 'Linux' }}
shell: bash
Expand Down Expand Up @@ -129,10 +129,22 @@ jobs:
node-version: 18
cache: npm

- name: Download artifacts
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
name: bindings-${{ matrix.target }}
pattern: bindings-*
merge-multiple: true

- name: Copy binaries to src for testing
run: |
# Copy all .node files found in libs/core to libs/core/src
echo "Copying all .node binaries to libs/core/src/"
find "libs/core" -maxdepth 1 -name "*.node" -exec cp {} "libs/core/src/" \;

# Show what was copied
echo "Files in libs/core/src:"
find "libs/core/src" -type f -name "*.node" | sort
shell: bash

- name: Install dependencies
run: npm install
Expand Down Expand Up @@ -174,42 +186,116 @@ jobs:
pattern: bindings-*
merge-multiple: true

- name: Move artifacts
- name: Process artifacts and prepare packages
run: |
echo "Debug: Showing all downloaded artifacts:"
find . -type f -name "*.node" -ls

echo "\nMoving only cel-typescript binaries to root:"
find . -type f -name "cel-typescript.*.node" -exec mv {} . \;

echo "\nBinaries in root directory:"
ls -la cel-typescript.*.node

# Count our binaries
node_count=$(ls -1 cel-typescript.*.node 2>/dev/null | wc -l)
expected_count=5 # We target 5 platforms

echo "\nFound $node_count cel-typescript binaries (expected $expected_count)"
echo "\nEnsuring binaries exist in their respective package directories:"

# Make sure each package directory has exactly one binary
# Copy only if not already present in the target directory
if [ ! -f libs/darwin-arm64/cel-typescript.darwin-arm64.node ]; then
find . -path "./libs/darwin-arm64" -prune -o -name "cel-typescript.darwin-arm64.node" -exec cp {} libs/darwin-arm64/ \;
fi

if [ ! -f libs/darwin-x64/cel-typescript.darwin-x64.node ]; then
find . -path "./libs/darwin-x64" -prune -o -name "cel-typescript.darwin-x64.node" -exec cp {} libs/darwin-x64/ \;
fi

if [ ! -f libs/linux-x64-gnu/cel-typescript.linux-x64-gnu.node ]; then
find . -path "./libs/linux-x64-gnu" -prune -o -name "cel-typescript.linux-x64-gnu.node" -exec cp {} libs/linux-x64-gnu/ \;
fi

if [ ! -f libs/linux-arm64-gnu/cel-typescript.linux-arm64-gnu.node ]; then
find . -path "./libs/linux-arm64-gnu" -prune -o -name "cel-typescript.linux-arm64-gnu.node" -exec cp {} libs/linux-arm64-gnu/ \;
fi

if [ ! -f libs/win32-x64-msvc/cel-typescript.win32-x64-msvc.node ]; then
find . -path "./libs/win32-x64-msvc" -prune -o -name "cel-typescript.win32-x64-msvc.node" -exec cp {} libs/win32-x64-msvc/ \;
fi

# Verify each package directory has exactly one binary
darwin_arm64_count=$(find libs/darwin-arm64 -maxdepth 1 -name "cel-typescript.darwin-arm64.node" | wc -l)
darwin_x64_count=$(find libs/darwin-x64 -maxdepth 1 -name "cel-typescript.darwin-x64.node" | wc -l)
linux_x64_gnu_count=$(find libs/linux-x64-gnu -maxdepth 1 -name "cel-typescript.linux-x64-gnu.node" | wc -l)
linux_arm64_gnu_count=$(find libs/linux-arm64-gnu -maxdepth 1 -name "cel-typescript.linux-arm64-gnu.node" | wc -l)
win32_x64_msvc_count=$(find libs/win32-x64-msvc -maxdepth 1 -name "cel-typescript.win32-x64-msvc.node" | wc -l)

echo "\nVerifying binaries in package directories:"
echo "darwin-arm64: $darwin_arm64_count"
echo "darwin-x64: $darwin_x64_count"
echo "linux-x64-gnu: $linux_x64_gnu_count"
echo "linux-arm64-gnu: $linux_arm64_gnu_count"
echo "win32-x64-msvc: $win32_x64_msvc_count"

if [ "$node_count" -ne "$expected_count" ]; then
echo "Error: Expected $expected_count binaries but found $node_count"
# Error if any platform is missing its binary
if [ "$darwin_arm64_count" -ne 1 ] || [ "$darwin_x64_count" -ne 1 ] || \
[ "$linux_x64_gnu_count" -ne 1 ] || [ "$linux_arm64_gnu_count" -ne 1 ] || \
[ "$win32_x64_msvc_count" -ne 1 ]; then
echo "Error: Each package directory should have exactly one binary"
exit 1
fi

# Set version for all packages based on tag
if [[ "$GITHUB_REF" == refs/tags/v* ]]; then
VERSION=${GITHUB_REF#refs/tags/v}
echo "Setting version to $VERSION for all packages"

for pkg in libs/darwin-arm64 libs/darwin-x64 libs/linux-x64-gnu libs/linux-arm64-gnu libs/win32-x64-msvc; do
jq ".version = \"$VERSION\"" $pkg/package.json > tmp.json && mv tmp.json $pkg/package.json
done

# Set the core package version too
jq ".version = \"$VERSION\"" libs/core/package.json > tmp.json && mv tmp.json libs/core/package.json

# Update the optionalDependencies in the core package to use version numbers instead of file paths
node -e "const pkg = require('./libs/core/package.json'); \
if (pkg.optionalDependencies) { \
Object.keys(pkg.optionalDependencies).forEach(dep => { \
pkg.optionalDependencies[dep] = '$VERSION'; \
}); \
require('fs').writeFileSync('./libs/core/package.json', JSON.stringify(pkg, null, 2)); \
}"
else
echo "Not a tag push, skipping version update"
fi

- name: Build TypeScript
run: npm run build:ts

- name: Verify package contents
- name: Publish Core Package (Dry Run)
if: github.event_name == 'pull_request'
run: |
echo "Package contents:"
cd libs/core
npm pack --dry-run

- name: Publish
- name: Publish Platform Packages (Dry Run)
if: github.event_name == 'pull_request'
run: |
for pkg in darwin-arm64 darwin-x64 linux-x64-gnu linux-arm64-gnu win32-x64-msvc; do
echo "\n==== Dry run publishing $pkg package ===="
cd libs/$pkg
npm pack --dry-run
cd ../..
done

- name: Publish Core Package
if: startsWith(github.ref, 'refs/tags/v')
run: npm publish --provenance --access public
run: |
cd libs/core
npm publish --provenance --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Publish (Dry Run)
if: github.event_name == 'pull_request'
run: npm publish --dry-run
- name: Publish Platform Packages
if: startsWith(github.ref, 'refs/tags/v')
run: |
for pkg in darwin-arm64 darwin-x64 linux-x64-gnu linux-arm64-gnu win32-x64-msvc; do
echo "\n==== Publishing $pkg package ===="
cd libs/$pkg
npm publish --provenance --access public
cd ../..
done
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Rust
/target
libs/core/target

**/*.rs.bk
Cargo.lock

Expand Down Expand Up @@ -37,3 +38,6 @@ coverage/
.env
.env.local
.env.*.local

# Tarballs from testing with `npm pack`
*.tgz
4 changes: 2 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "cel-rust"]
path = cel-rust
[submodule "libs/core/cel-rust"]
path = libs/core/cel-rust
url = https://github.com/clarkmcc/cel-rust.git
4 changes: 1 addition & 3 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
npx nx run cel-typescript:format:check
npx nx run cel-typescript:check
npx nx run cel-typescript:lint
npm run format
11 changes: 8 additions & 3 deletions biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,19 @@
},
"files": {
"include": ["**/*.ts", "**/*.tsx", "**/*.js", "**/*.jsx", "**/*.json"],
"ignore": [".nx", "index.js", "index.d.ts", "dist/**/*"]
"ignore": [
".nx",
"**/dist/**/*",
"**/target/**",
"**/artifacts/native.d.ts",
"**/native.d.ts"
]
},
"formatter": {
"enabled": true,
"indentStyle": "space",
"indentWidth": 2,
"lineWidth": 80,
"ignore": ["index.js"]
"lineWidth": 80
},
"linter": {
"enabled": true,
Expand Down
1 change: 0 additions & 1 deletion cel-rust
Submodule cel-rust deleted from d84558
4 changes: 0 additions & 4 deletions esm/wrapper.js

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions libs/core/cel-rust
Submodule cel-rust added at 0bf8ab
59 changes: 59 additions & 0 deletions libs/core/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"name": "@kevinmichaelchen/cel-typescript-core",
"version": "0.0.11",
"private": true,
"type": "module",
"description": "TypeScript bindings for the Common Expression Language (CEL) using cel-rust",
"repository": {
"type": "git",
"url": "git+https://github.com/kevinmichaelchen/cel-typescript.git"
},
"author": "Kevin Chen",
"license": "MIT",
"bugs": {
"url": "https://github.com/kevinmichaelchen/cel-typescript/issues"
},
"homepage": "https://github.com/kevinmichaelchen/cel-typescript#readme",
"files": ["dist/src/**"],
"keywords": [
"cel",
"common-expression-language",
"expression-language",
"policy",
"rust",
"napi-rs"
],
"engines": {
"node": ">=18.0.0"
},
"optionalDependencies": {
"@kevinmichaelchen/cel-typescript-darwin-arm64": "file:../darwin-arm64",
"@kevinmichaelchen/cel-typescript-darwin-x64": "file:../darwin-x64",
"@kevinmichaelchen/cel-typescript-linux-x64-gnu": "file:../linux-x64-gnu",
"@kevinmichaelchen/cel-typescript-linux-arm64-gnu": "file:../linux-arm64-gnu",
"@kevinmichaelchen/cel-typescript-win32-x64-msvc": "file:../win32-x64-msvc"
},
"exports": {
".": {
"import": "./dist/src/index.js",
"types": "./dist/src/index.d.ts"
}
},
"types": "./dist/src/index.d.ts",
"napi": {
"name": "cel-typescript",
"package": {
"name": "cel-typescript"
},
"triples": {
"defaults": false,
"additional": [
"aarch64-apple-darwin",
"x86_64-apple-darwin",
"x86_64-unknown-linux-gnu",
"aarch64-unknown-linux-gnu",
"x86_64-pc-windows-msvc"
]
}
}
}
54 changes: 54 additions & 0 deletions libs/core/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"name": "@kevinmichaelchen/cel-typescript-core",
"$schema": "node_modules/nx/schemas/project-schema.json",
"targets": {
"build:native": {
"cache": false,
"executor": "nx:run-commands",
"options": {
"command": "bash {projectRoot}/scripts/build.sh {args.target}"
},
"outputs": [
"{projectRoot}/cel-typescript.darwin-arm64.node",
"{projectRoot}/cel-typescript.darwin-x64.node",
"{projectRoot}/cel-typescript.linux-x64-gnu.node",
"{projectRoot}/cel-typescript.linux-arm64-gnu.node",
"{projectRoot}/cel-typescript.win32-x64-msvc.node",
"{projectRoot}/src/native.cjs",
"{projectRoot}/src/native.d.ts"
]
},
"build:ts": {
"cache": false,
"executor": "nx:run-commands",
"options": {
"command": "tsc -p {projectRoot}/tsconfig.json"
},
"outputs": ["{projectRoot}/dist/**/*"]
},
"build": {
"executor": "nx:noop",
"dependsOn": ["build:native", "build:ts"]
},
"clean": {
"cache": false,
"executor": "nx:run-commands",
"options": {
"commands": [
"rm -rf {projectRoot}/dist",
"rm -f {projectRoot}/*.node",
"rm -rf {projectRoot}/@kevinmichaelchen"
],
"parallel": false
}
},
"test": {
"cache": false,
"executor": "nx:run-commands",
"options": {
"command": "vitest run"
},
"dependsOn": ["build"]
}
}
}
51 changes: 51 additions & 0 deletions libs/core/scripts/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/bash

set -e

# Change directories to where the script lives
cd libs/core

if [ "$USE_ZIG" = "true" ]; then
npx @napi-rs/cli build --platform --target "$1" --release --zig \
--js src/native.cjs \
--dts src/native.d.ts \
--js-package-name @kevinmichaelchen/cel-typescript
else
npx @napi-rs/cli build --platform --target "$1" --release \
--js src/native.cjs \
--dts src/native.d.ts \
--js-package-name @kevinmichaelchen/cel-typescript
fi

# Copy binaries to their respective platform package directories
# Find all .node files in the current directory
echo "******************************************"
echo "DEBUG: Current directory: $(pwd)"
echo "DEBUG: Files in current directory:"
ls -la *.node || echo "No .node files found"
echo "DEBUG: Attempting to copy platform binaries..."
echo "******************************************"

for binary in cel-typescript.*.node; do
if [ -f "$binary" ]; then
# Extract the platform identifier (everything between 'cel-typescript.' and '.node')
platform=$(echo "$binary" | sed -E 's/cel-typescript\.(.+)\.node/\1/')

# Create target directory if it doesn't exist
mkdir -p "../$platform"

# Copy binary to the platform directory
cp "$binary" "../$platform/"

echo "******************************************"
echo "SUCCESS: Copied $binary to ../$platform/"
echo "******************************************"
else
echo "WARNING: Pattern matched $binary but it's not a file"
fi
done

echo "******************************************"
echo "DEBUG: Platform packages after copying:"
ls -la ../*/cel-typescript.*.node || echo "No platform binaries found in packages"
echo "******************************************"
Loading
Loading