diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index f256d67..3e3bfc0 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -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 @@ -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 @@ -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 }} diff --git a/.gitignore b/.gitignore index ae786db..f03bed5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ # Rust -/target +libs/core/target + **/*.rs.bk Cargo.lock @@ -37,3 +38,6 @@ coverage/ .env .env.local .env.*.local + +# Tarballs from testing with `npm pack` +*.tgz \ No newline at end of file diff --git a/.gitmodules b/.gitmodules index 8fe83d9..224c7b6 100644 --- a/.gitmodules +++ b/.gitmodules @@ -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 diff --git a/.husky/pre-commit b/.husky/pre-commit index 99fc856..b7807b0 100644 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -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 \ No newline at end of file diff --git a/biome.json b/biome.json index 8240f9c..b0140c0 100644 --- a/biome.json +++ b/biome.json @@ -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, diff --git a/cel-rust b/cel-rust deleted file mode 160000 index d84558a..0000000 --- a/cel-rust +++ /dev/null @@ -1 +0,0 @@ -Subproject commit d84558acf2eb76e1145b9a106e05b2189911a176 diff --git a/esm/wrapper.js b/esm/wrapper.js deleted file mode 100644 index 664bedd..0000000 --- a/esm/wrapper.js +++ /dev/null @@ -1,4 +0,0 @@ -import * as native from "../index.js"; -export const CelProgram = native.CelProgram; -export const evaluate = native.evaluate; -export default native; diff --git a/.npmignore b/libs/core/.npmignore similarity index 100% rename from .npmignore rename to libs/core/.npmignore diff --git a/Cargo.toml b/libs/core/Cargo.toml similarity index 100% rename from Cargo.toml rename to libs/core/Cargo.toml diff --git a/__tests__/cel.test.ts b/libs/core/__tests__/cel.test.ts similarity index 100% rename from __tests__/cel.test.ts rename to libs/core/__tests__/cel.test.ts diff --git a/build.rs b/libs/core/build.rs similarity index 100% rename from build.rs rename to libs/core/build.rs diff --git a/libs/core/cel-rust b/libs/core/cel-rust new file mode 160000 index 0000000..0bf8ab2 --- /dev/null +++ b/libs/core/cel-rust @@ -0,0 +1 @@ +Subproject commit 0bf8ab2708bdffd45cc80501f2bdc085794e6caf diff --git a/libs/core/package.json b/libs/core/package.json new file mode 100644 index 0000000..34a0bf9 --- /dev/null +++ b/libs/core/package.json @@ -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" + ] + } + } +} diff --git a/libs/core/project.json b/libs/core/project.json new file mode 100644 index 0000000..5a73b96 --- /dev/null +++ b/libs/core/project.json @@ -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"] + } + } +} diff --git a/libs/core/scripts/build.sh b/libs/core/scripts/build.sh new file mode 100755 index 0000000..eea352a --- /dev/null +++ b/libs/core/scripts/build.sh @@ -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 "******************************************" \ No newline at end of file diff --git a/src/index.ts b/libs/core/src/index.ts similarity index 94% rename from src/index.ts rename to libs/core/src/index.ts index baf68e4..3592fff 100644 --- a/src/index.ts +++ b/libs/core/src/index.ts @@ -1,3 +1,5 @@ +import { createRequire } from "node:module"; + export interface CelContext { [key: string]: any; } @@ -33,9 +35,8 @@ class CelProgram { static async compile(source: string): Promise { if (!CelProgram.nativeModule) { // Use the NAPI-RS generated loader which handles platform detection - const nativeBinding = await import( - "@kevinmichaelchen/cel-typescript/native" - ); + const require = createRequire(import.meta.url); + const nativeBinding = require("./native.cjs"); CelProgram.nativeModule = nativeBinding.CelProgram; console.log("Imported native CelProgram:", CelProgram.nativeModule); } diff --git a/src/lib.rs b/libs/core/src/lib.rs similarity index 100% rename from src/lib.rs rename to libs/core/src/lib.rs diff --git a/index.js b/libs/core/src/native.cjs similarity index 83% rename from index.js rename to libs/core/src/native.cjs index 2ef3bc4..31c5673 100644 --- a/index.js +++ b/libs/core/src/native.cjs @@ -37,7 +37,7 @@ switch (platform) { if (localFileExisted) { nativeBinding = require('./cel-typescript.android-arm64.node') } else { - nativeBinding = require('cel-typescript-android-arm64') + nativeBinding = require('@kevinmichaelchen/cel-typescript-android-arm64') } } catch (e) { loadError = e @@ -49,7 +49,7 @@ switch (platform) { if (localFileExisted) { nativeBinding = require('./cel-typescript.android-arm-eabi.node') } else { - nativeBinding = require('cel-typescript-android-arm-eabi') + nativeBinding = require('@kevinmichaelchen/cel-typescript-android-arm-eabi') } } catch (e) { loadError = e @@ -69,7 +69,7 @@ switch (platform) { if (localFileExisted) { nativeBinding = require('./cel-typescript.win32-x64-msvc.node') } else { - nativeBinding = require('cel-typescript-win32-x64-msvc') + nativeBinding = require('@kevinmichaelchen/cel-typescript-win32-x64-msvc') } } catch (e) { loadError = e @@ -83,7 +83,7 @@ switch (platform) { if (localFileExisted) { nativeBinding = require('./cel-typescript.win32-ia32-msvc.node') } else { - nativeBinding = require('cel-typescript-win32-ia32-msvc') + nativeBinding = require('@kevinmichaelchen/cel-typescript-win32-ia32-msvc') } } catch (e) { loadError = e @@ -97,7 +97,7 @@ switch (platform) { if (localFileExisted) { nativeBinding = require('./cel-typescript.win32-arm64-msvc.node') } else { - nativeBinding = require('cel-typescript-win32-arm64-msvc') + nativeBinding = require('@kevinmichaelchen/cel-typescript-win32-arm64-msvc') } } catch (e) { loadError = e @@ -113,7 +113,7 @@ switch (platform) { if (localFileExisted) { nativeBinding = require('./cel-typescript.darwin-universal.node') } else { - nativeBinding = require('cel-typescript-darwin-universal') + nativeBinding = require('@kevinmichaelchen/cel-typescript-darwin-universal') } break } catch {} @@ -124,7 +124,7 @@ switch (platform) { if (localFileExisted) { nativeBinding = require('./cel-typescript.darwin-x64.node') } else { - nativeBinding = require('cel-typescript-darwin-x64') + nativeBinding = require('@kevinmichaelchen/cel-typescript-darwin-x64') } } catch (e) { loadError = e @@ -138,7 +138,7 @@ switch (platform) { if (localFileExisted) { nativeBinding = require('./cel-typescript.darwin-arm64.node') } else { - nativeBinding = require('cel-typescript-darwin-arm64') + nativeBinding = require('@kevinmichaelchen/cel-typescript-darwin-arm64') } } catch (e) { loadError = e @@ -157,7 +157,7 @@ switch (platform) { if (localFileExisted) { nativeBinding = require('./cel-typescript.freebsd-x64.node') } else { - nativeBinding = require('cel-typescript-freebsd-x64') + nativeBinding = require('@kevinmichaelchen/cel-typescript-freebsd-x64') } } catch (e) { loadError = e @@ -174,7 +174,7 @@ switch (platform) { if (localFileExisted) { nativeBinding = require('./cel-typescript.linux-x64-musl.node') } else { - nativeBinding = require('cel-typescript-linux-x64-musl') + nativeBinding = require('@kevinmichaelchen/cel-typescript-linux-x64-musl') } } catch (e) { loadError = e @@ -187,7 +187,7 @@ switch (platform) { if (localFileExisted) { nativeBinding = require('./cel-typescript.linux-x64-gnu.node') } else { - nativeBinding = require('cel-typescript-linux-x64-gnu') + nativeBinding = require('@kevinmichaelchen/cel-typescript-linux-x64-gnu') } } catch (e) { loadError = e @@ -203,7 +203,7 @@ switch (platform) { if (localFileExisted) { nativeBinding = require('./cel-typescript.linux-arm64-musl.node') } else { - nativeBinding = require('cel-typescript-linux-arm64-musl') + nativeBinding = require('@kevinmichaelchen/cel-typescript-linux-arm64-musl') } } catch (e) { loadError = e @@ -216,7 +216,7 @@ switch (platform) { if (localFileExisted) { nativeBinding = require('./cel-typescript.linux-arm64-gnu.node') } else { - nativeBinding = require('cel-typescript-linux-arm64-gnu') + nativeBinding = require('@kevinmichaelchen/cel-typescript-linux-arm64-gnu') } } catch (e) { loadError = e @@ -232,7 +232,7 @@ switch (platform) { if (localFileExisted) { nativeBinding = require('./cel-typescript.linux-arm-musleabihf.node') } else { - nativeBinding = require('cel-typescript-linux-arm-musleabihf') + nativeBinding = require('@kevinmichaelchen/cel-typescript-linux-arm-musleabihf') } } catch (e) { loadError = e @@ -245,7 +245,7 @@ switch (platform) { if (localFileExisted) { nativeBinding = require('./cel-typescript.linux-arm-gnueabihf.node') } else { - nativeBinding = require('cel-typescript-linux-arm-gnueabihf') + nativeBinding = require('@kevinmichaelchen/cel-typescript-linux-arm-gnueabihf') } } catch (e) { loadError = e @@ -261,7 +261,7 @@ switch (platform) { if (localFileExisted) { nativeBinding = require('./cel-typescript.linux-riscv64-musl.node') } else { - nativeBinding = require('cel-typescript-linux-riscv64-musl') + nativeBinding = require('@kevinmichaelchen/cel-typescript-linux-riscv64-musl') } } catch (e) { loadError = e @@ -274,7 +274,7 @@ switch (platform) { if (localFileExisted) { nativeBinding = require('./cel-typescript.linux-riscv64-gnu.node') } else { - nativeBinding = require('cel-typescript-linux-riscv64-gnu') + nativeBinding = require('@kevinmichaelchen/cel-typescript-linux-riscv64-gnu') } } catch (e) { loadError = e @@ -289,7 +289,7 @@ switch (platform) { if (localFileExisted) { nativeBinding = require('./cel-typescript.linux-s390x-gnu.node') } else { - nativeBinding = require('cel-typescript-linux-s390x-gnu') + nativeBinding = require('@kevinmichaelchen/cel-typescript-linux-s390x-gnu') } } catch (e) { loadError = e diff --git a/index.d.ts b/libs/core/src/native.d.ts similarity index 100% rename from index.d.ts rename to libs/core/src/native.d.ts diff --git a/libs/core/tsconfig.json b/libs/core/tsconfig.json new file mode 100644 index 0000000..674d97f --- /dev/null +++ b/libs/core/tsconfig.json @@ -0,0 +1,17 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "outDir": "./dist", + "rootDir": "./", + "moduleResolution": "nodenext", + "module": "NodeNext", + "baseUrl": ".", + "paths": { + "@kevinmichaelchen/cel-typescript-core-darwin-arm64": [ + "./artifacts/cel-typescript.darwin-arm64.node" + ] + } + }, + "include": ["src/**/*", "__tests__/**/*"], + "exclude": ["node_modules", "dist"] +} diff --git a/vitest.config.ts b/libs/core/vitest.config.ts similarity index 75% rename from vitest.config.ts rename to libs/core/vitest.config.ts index 6041fbc..a8f45ba 100644 --- a/vitest.config.ts +++ b/libs/core/vitest.config.ts @@ -7,9 +7,7 @@ export default defineConfig({ environment: "node", }, resolve: { - alias: { - "#native": "../cel-typescript.darwin-arm64.node", - }, + alias: {}, }, assetsInclude: ["**/*.node"], }); diff --git a/libs/darwin-arm64/package.json b/libs/darwin-arm64/package.json new file mode 100644 index 0000000..7ee6157 --- /dev/null +++ b/libs/darwin-arm64/package.json @@ -0,0 +1,12 @@ +{ + "name": "@kevinmichaelchen/cel-typescript-darwin-arm64", + "version": "0.0.0", + "os": ["darwin"], + "cpu": ["arm64"], + "main": "cel-typescript.darwin-arm64.node", + "files": ["cel-typescript.darwin-arm64.node"], + "license": "MIT", + "engines": { + "node": ">=18.0.0" + } +} diff --git a/libs/darwin-arm64/project.json b/libs/darwin-arm64/project.json new file mode 100644 index 0000000..714b804 --- /dev/null +++ b/libs/darwin-arm64/project.json @@ -0,0 +1,14 @@ +{ + "name": "@kevinmichaelchen/cel-typescript-darwin-arm64", + "$schema": "node_modules/nx/schemas/project-schema.json", + "targets": { + "clean": { + "cache": false, + "executor": "nx:run-commands", + "options": { + "commands": ["rm -f {projectRoot}/*.node"], + "parallel": false + } + } + } +} diff --git a/libs/darwin-x64/package.json b/libs/darwin-x64/package.json new file mode 100644 index 0000000..6535178 --- /dev/null +++ b/libs/darwin-x64/package.json @@ -0,0 +1,12 @@ +{ + "name": "@kevinmichaelchen/cel-typescript-darwin-x64", + "version": "0.0.0", + "os": ["darwin"], + "cpu": ["x64"], + "main": "cel-typescript.darwin-x64.node", + "files": ["cel-typescript.darwin-x64.node"], + "license": "MIT", + "engines": { + "node": ">=18.0.0" + } +} diff --git a/libs/linux-arm64-gnu/package.json b/libs/linux-arm64-gnu/package.json new file mode 100644 index 0000000..f8387cd --- /dev/null +++ b/libs/linux-arm64-gnu/package.json @@ -0,0 +1,12 @@ +{ + "name": "@kevinmichaelchen/cel-typescript-linux-arm64-gnu", + "version": "0.0.0", + "os": ["linux"], + "cpu": ["arm64"], + "main": "cel-typescript.linux-arm64-gnu.node", + "files": ["cel-typescript.linux-arm64-gnu.node"], + "license": "MIT", + "engines": { + "node": ">=18.0.0" + } +} diff --git a/libs/linux-x64-gnu/package.json b/libs/linux-x64-gnu/package.json new file mode 100644 index 0000000..cc9aced --- /dev/null +++ b/libs/linux-x64-gnu/package.json @@ -0,0 +1,12 @@ +{ + "name": "@kevinmichaelchen/cel-typescript-linux-x64-gnu", + "version": "0.0.0", + "os": ["linux"], + "cpu": ["x64"], + "main": "cel-typescript.linux-x64-gnu.node", + "files": ["cel-typescript.linux-x64-gnu.node"], + "license": "MIT", + "engines": { + "node": ">=18.0.0" + } +} diff --git a/libs/win32-x64-msvc/package.json b/libs/win32-x64-msvc/package.json new file mode 100644 index 0000000..ccbbafd --- /dev/null +++ b/libs/win32-x64-msvc/package.json @@ -0,0 +1,12 @@ +{ + "name": "@kevinmichaelchen/cel-typescript-win32-x64-msvc", + "version": "0.0.0", + "os": ["win32"], + "cpu": ["x64"], + "main": "cel-typescript.win32-x64-msvc.node", + "files": ["cel-typescript.win32-x64-msvc.node"], + "license": "MIT", + "engines": { + "node": ">=18.0.0" + } +} diff --git a/nx.json b/nx.json index 5ad414c..865f5e9 100644 --- a/nx.json +++ b/nx.json @@ -32,18 +32,28 @@ ] }, "format": { - "cache": true, - "inputs": [ - "{projectRoot}/**/*.{ts,tsx,js,jsx,json,md}", - "{projectRoot}/biome.json" - ] + "executor": "nx:run-commands", + "options": { + "command": "biome format --write ." + } + }, + "format:check": { + "executor": "nx:run-commands", + "options": { + "command": "biome format ." + } }, "lint": { - "cache": true, - "inputs": [ - "{projectRoot}/**/*.{ts,tsx,js,jsx}", - "{projectRoot}/biome.json" - ] + "executor": "nx:run-commands", + "options": { + "command": "biome lint ." + } + }, + "check": { + "executor": "nx:run-commands", + "options": { + "command": "biome check ." + } } }, "namedInputs": { diff --git a/package-lock.json b/package-lock.json index 3cc2458..94a8fe1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,13 +1,12 @@ { "name": "@kevinmichaelchen/cel-typescript", - "version": "0.0.10", + "version": "0.0.11", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@kevinmichaelchen/cel-typescript", - "version": "0.0.10", - "license": "MIT", + "version": "0.0.11", "devDependencies": { "@biomejs/biome": "^1.9.4", "@napi-rs/cli": "^2.18.4", @@ -21,9 +20,6 @@ "ts-node": "^10.9.2", "typescript": "^5.0.0", "vitest": "^3.1.2" - }, - "engines": { - "node": ">=18.0.0" } }, "node_modules/@ampproject/remapping": { diff --git a/package.json b/package.json index 9d66f9c..c5a0357 100644 --- a/package.json +++ b/package.json @@ -1,64 +1,16 @@ { "name": "@kevinmichaelchen/cel-typescript", "version": "0.0.11", - "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/**/*", "*.node", "index.js", "index.d.ts"], - "keywords": [ - "cel", - "common-expression-language", - "expression-language", - "policy", - "rust", - "napi-rs" - ], - "engines": { - "node": ">=18.0.0" - }, - "exports": { - ".": { - "import": "./dist/src/index.js", - "types": "./dist/src/index.d.ts" - }, - "./native": { - "import": "./esm/wrapper.js", - "types": "./index.d.ts" - } - }, - "types": "./dist/src/index.d.ts", - "napi": { - "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" - ] - } - }, + "private": true, "scripts": { - "build:native": "nx build:native", - "build:ts": "nx build:ts", - "format": "nx run cel-typescript:format", - "format:check": "nx run cel-typescript:format:check", - "lint": "nx lint", + "build": "nx run-many -t build", + "build:native": "nx run-many -t build:native", + "build:ts": "nx run-many -t build:ts", "check": "nx check", - "build": "nx build", - "test": "nx test", - "clean": "nx clean" + "clean": "nx run-many -t clean", + "format": "biome format . && biome check . && biome lint .", + "format:fix": "biome format --write . && biome check --write . && biome lint .", + "test": "nx run-many -t test" }, "devDependencies": { "@biomejs/biome": "^1.9.4", diff --git a/project.json b/project.json deleted file mode 100644 index 04d8380..0000000 --- a/project.json +++ /dev/null @@ -1,68 +0,0 @@ -{ - "name": "cel-typescript", - "$schema": "node_modules/nx/schemas/project-schema.json", - "targets": { - "build:native": { - "executor": "nx:run-commands", - "options": { - "command": "bash scripts/build.sh {args.target}" - }, - "outputs": [ - "{workspaceRoot}/cel-typescript.darwin-arm64.node", - "{workspaceRoot}/cel-typescript.darwin-x64.node", - "{workspaceRoot}/cel-typescript.linux-x64-gnu.node", - "{workspaceRoot}/cel-typescript.linux-arm64-gnu.node", - "{workspaceRoot}/cel-typescript.win32-x64-msvc.node" - ] - }, - "build:ts": { - "executor": "nx:run-commands", - "options": { - "command": "tsc" - }, - "outputs": ["{workspaceRoot}/dist/**/*"] - }, - "build": { - "executor": "nx:noop", - "dependsOn": ["build:native", "build:ts"] - }, - "clean": { - "executor": "nx:run-commands", - "options": { - "commands": ["rm -rf dist", "rm -f *.node"], - "parallel": false - } - }, - "test": { - "executor": "nx:run-commands", - "options": { - "command": "vitest run" - }, - "dependsOn": ["build"] - }, - "format": { - "executor": "nx:run-commands", - "options": { - "command": "biome format --write ." - } - }, - "format:check": { - "executor": "nx:run-commands", - "options": { - "command": "biome format ." - } - }, - "lint": { - "executor": "nx:run-commands", - "options": { - "command": "biome lint ." - } - }, - "check": { - "executor": "nx:run-commands", - "options": { - "command": "biome check ." - } - } - } -} diff --git a/scripts/build.sh b/scripts/build.sh deleted file mode 100755 index a779dea..0000000 --- a/scripts/build.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash - -if [ "$USE_ZIG" = "true" ]; then - npx @napi-rs/cli build --platform --target "$1" --release --zig -else - npx @napi-rs/cli build --platform --target "$1" --release -fi diff --git a/tsconfig.json b/tsconfig.base.json similarity index 74% rename from tsconfig.json rename to tsconfig.base.json index b0a5bdf..0dee9bc 100644 --- a/tsconfig.json +++ b/tsconfig.base.json @@ -4,7 +4,6 @@ "module": "NodeNext", "moduleResolution": "NodeNext", "declaration": true, - "outDir": "./dist", "rootDir": "./", "strict": true, "esModuleInterop": true, @@ -12,7 +11,5 @@ "forceConsistentCasingInFileNames": true, "allowJs": true, "baseUrl": "." - }, - "include": ["src/**/*", "__tests__/**/*"], - "exclude": ["node_modules", "dist"] + } }