diff --git a/README.md b/README.md index fd3b3f5fc..11fc42de6 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,10 @@ Neon projects to 0.10! Support for [LTS versions of Node](https://github.com/nodejs/LTS#release-schedule) and current are expected. If you're using a different version of Node and believe it should be supported, let us know. +### Bun (experimental) + +[Bun](https://bun.sh/) is an alternate JavaScript runtime that targets Node compatibility. In many cases Neon modules will work in bun; however, at the time of this writing, some Node-API functions are [not implemented](https://github.com/Jarred-Sumner/bun/issues/158). + ### Rust Neon supports Rust stable version 1.18 and higher. We test on the latest stable, beta, and nightly versions of Rust. diff --git a/crates/neon/src/sys/bindings/functions.rs b/crates/neon/src/sys/bindings/functions.rs index 9f6c10aaf..fcf05834b 100644 --- a/crates/neon/src/sys/bindings/functions.rs +++ b/crates/neon/src/sys/bindings/functions.rs @@ -371,19 +371,19 @@ pub(super) unsafe fn load(env: Env) -> Result<(), libloading::Error> { // with `Error: Module did not self-register` if N-API does not exist. let version = get_version(&host, env).expect("Failed to find N-API version"); - napi1::load(&host, version, 1)?; + napi1::load(&host, version, 1); #[cfg(feature = "napi-4")] - napi4::load(&host, version, 4)?; + napi4::load(&host, version, 4); #[cfg(feature = "napi-5")] - napi5::load(&host, version, 5)?; + napi5::load(&host, version, 5); #[cfg(feature = "napi-6")] - napi6::load(&host, version, 6)?; + napi6::load(&host, version, 6); #[cfg(feature = "napi-8")] - napi8::load(&host, version, 8)?; + napi8::load(&host, version, 8); Ok(()) } diff --git a/crates/neon/src/sys/bindings/mod.rs b/crates/neon/src/sys/bindings/mod.rs index 10bd2f015..2e26252e6 100644 --- a/crates/neon/src/sys/bindings/mod.rs +++ b/crates/neon/src/sys/bindings/mod.rs @@ -118,7 +118,7 @@ macro_rules! generate { #[inline(never)] fn panic_load() -> T { - panic!("Must load N-API bindings") + panic!("Node-API symbol has not been loaded") } static mut NAPI: Napi = { @@ -139,21 +139,31 @@ macro_rules! generate { host: &libloading::Library, actual_napi_version: u32, expected_napi_version: u32, - ) -> Result<(), libloading::Error> { + ) { assert!( actual_napi_version >= expected_napi_version, - "Minimum required N-API version {}, found {}.", + "Minimum required Node-API version {}, found {}.", expected_napi_version, actual_napi_version, ); + let print_warn = |err| eprintln!("WARN: {}", err); + NAPI = Napi { $( - $name: *host.get(napi_name!($name).as_bytes())?, + $name: match host.get(napi_name!($name).as_bytes()) { + Ok(f) => *f, + // Node compatible runtimes may not have full coverage of Node-API + // (e.g., bun). Instead of failing to start, warn on start and + // panic when the API is called. + // https://github.com/Jarred-Sumner/bun/issues/158 + Err(err) => { + print_warn(err); + NAPI.$name + }, + }, )* }; - - Ok(()) } $(