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
10 changes: 9 additions & 1 deletion .github/workflows/JS_build_test_publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,15 @@ jobs:
yarn build:ts
- host: ubuntu-latest
target: aarch64-unknown-linux-musl
# Use napi-rs image for the musl cross-compiler toolchain, but upgrade Node.js
# because @napi-rs/cli@3.x requires Node.js 20+ (via @inquirer/core dependency)
docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine
build: |-
set -eux
# Upgrade Node.js from 18 to 22 (napi-rs image has Node 18, but CLI v3 needs 20+)
# Download official Node.js musl binary (Alpine packages have library incompatibilities)
wget -qO- https://unofficial-builds.nodejs.org/download/release/v22.12.0/node-v22.12.0-linux-x64-musl.tar.gz | tar xz -C /usr/local --strip-components=1
node --version
rustc --version
rustup update stable
rustc --version
Expand Down Expand Up @@ -430,7 +436,8 @@ jobs:
- name: Setup and run tests
uses: addnab/docker-run-action@v3
with:
image: node:lts-alpine
# Use node:20-alpine instead of lts-alpine because @napi-rs/cli@3.x requires Node.js 20+
image: node:20-alpine
options: '--platform linux/arm64 -v ${{ github.workspace }}/tests:/build/tests -v ${{ github.workspace }}/rust:/build/rust -v ${{ github.workspace }}/js:/build/js -w /build/js/optify-config'
run: |
set -ex
Expand Down Expand Up @@ -478,6 +485,7 @@ jobs:
run: |
set -ex
ls -lRh ./artifacts/
mv ./artifacts/*.node .
yarn universal
ls -lh .
shell: bash
Expand Down
7 changes: 4 additions & 3 deletions js/optify-config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ crate-type = ["cdylib"]

[dependencies]
# Default enable napi4 feature, see https://nodejs.org/api/n-api.html#node-api-version-matrix
napi = { version = "2.12.2", default-features = false, features = ["napi4"] }
napi-derive = "2.12.2"
# serde-json is needed for serde_json::Value support
napi = { version = "3.7.0", default-features = false, features = ["napi4", "serde-json"] }
napi-derive = "3.4.0"
optify = { path = "../../rust/optify", version = "0.20.5" }
serde_json = "1.0.140"

[build-dependencies]
napi-build = "2.0.1"
napi-build = "2.3.1"

[profile.release]
lto = true
Expand Down
29 changes: 15 additions & 14 deletions js/optify-config/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@optify/config",
"version": "1.1.6",
"version": "1.1.7",
"description": "Simplifies **configuration driven development**: getting the right configuration options for a process or request using pre-loaded configurations from files (JSON, YAML, etc.) to manage options for feature flags, experiments, or flights.",
"repository": {
"type": "git",
Expand All @@ -17,21 +17,22 @@
"main": "dist/index.js",
"types": "dist/index.d.ts",
"napi": {
"name": "config",
"triples": {
"additional": [
"aarch64-apple-darwin",
"aarch64-unknown-linux-gnu",
"aarch64-unknown-linux-musl",
"x86_64-unknown-freebsd",
"universal-apple-darwin"
]
}
"binaryName": "config",
"targets": [
"x86_64-apple-darwin",
"x86_64-unknown-linux-gnu",
"x86_64-pc-windows-msvc",
"aarch64-apple-darwin",
"aarch64-unknown-linux-gnu",
"aarch64-unknown-linux-musl",
"x86_64-unknown-freebsd",
"universal-apple-darwin"
]
},
"license": "MIT",
"devDependencies": {
"@jest/globals": "^29.7.0",
"@napi-rs/cli": "^2.18.4",
"@napi-rs/cli": "^3.5.0",
"@types/mocha": "^10.0.10",
"corepack": "^0.32.0",
"jest": "^29.7.0",
Expand All @@ -40,7 +41,7 @@
"typescript": "^5.8.3"
},
"engines": {
"node": ">= 10"
"node": ">= 20"
},
"scripts": {
"artifacts": "napi artifacts",
Expand All @@ -49,7 +50,7 @@
"build:ts": "tsc",
"prepublishOnly": "napi prepublish -t npm",
"test": "jest",
"universal": "napi universal",
"universal": "napi universalize",
"version": "napi version"
},
"packageManager": "yarn@4.9.1"
Expand Down
36 changes: 0 additions & 36 deletions js/optify-config/src/convert.rs

This file was deleted.

1 change: 0 additions & 1 deletion js/optify-config/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#![deny(clippy::all)]

mod convert;
mod metadata;
mod preferences;
mod provider;
Expand Down
12 changes: 3 additions & 9 deletions js/optify-config/src/provider.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
#![deny(clippy::all)]

use napi::Env;
use optify::builder::{OptionsProviderBuilder, OptionsRegistryBuilder};
use optify::provider::{OptionsProvider, OptionsRegistry};

use crate::convert::convert_to_js;
use crate::metadata::{to_js_options_metadata, JsOptionsMetadata};
use crate::preferences::JsGetOptionsPreferences;

Expand Down Expand Up @@ -69,20 +67,16 @@ impl JsOptionsProvider {
#[napi]
pub fn get_all_options(
&self,
env: Env,
feature_names: Vec<String>,
preferences: Option<&JsGetOptionsPreferences>,
) -> napi::Result<napi::JsUnknown> {
) -> napi::Result<serde_json::Value> {
let preferences = preferences.map(|p| &p.inner);
match self
self
.inner
.as_ref()
.unwrap()
.get_all_options(&feature_names, None, preferences)
{
Ok(options) => Ok(convert_to_js(env, &options)),
Err(e) => Err(napi::Error::from_reason(e.to_string())),
}
.map_err(|e| napi::Error::from_reason(e.to_string()))
}

/// Gets all options for the specified feature names.
Expand Down
12 changes: 3 additions & 9 deletions js/optify-config/src/watcher.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
#![deny(clippy::all)]

use napi::Env;
use optify::builder::{OptionsRegistryBuilder, OptionsWatcherBuilder};
use optify::provider::{OptionsRegistry, OptionsWatcher};
use std::sync::Arc;

use crate::convert::convert_to_js;
use crate::metadata::{to_js_options_metadata, JsOptionsMetadata};
use crate::preferences::JsGetOptionsPreferences;
use crate::watcher_options::JsWatcherOptions;
Expand Down Expand Up @@ -130,20 +128,16 @@ impl JsOptionsWatcher {
#[napi]
pub fn get_all_options(
&self,
env: Env,
feature_names: Vec<String>,
preferences: Option<&JsGetOptionsPreferences>,
) -> napi::Result<napi::JsUnknown> {
) -> napi::Result<serde_json::Value> {
let preferences = preferences.map(|p| &p.inner);
match self
self
.inner
.as_ref()
.unwrap()
.get_all_options(&feature_names, None, preferences)
{
Ok(options) => Ok(convert_to_js(env, &options)),
Err(e) => Err(napi::Error::from_reason(e.to_string())),
}
.map_err(|e| napi::Error::from_reason(e.to_string()))
}

/// Gets all options for the specified feature names.
Expand Down
4 changes: 4 additions & 0 deletions js/optify-config/tests/provider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ describe('Provider', () => {
expect(options).toEqual(expectedOptions)

const optionsObj = provider.getAllOptions(['feature_A'])
// NOTE: `instanceof Object` is not reliable under Jest because test files run in a VM
// context with their own `Object` constructor; values coming from native bindings may
// be created in a different realm. Prefer structural/type checks instead.
expect(typeof optionsObj).toBe('object')
expect(optionsObj).toEqual(expectedOptions)
})

Expand Down
Loading