Changelog
napi

napi

napi@3.0.0-alpha.2

4/15/2024

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi@3.0.0-alpha.1...napi@3.0.0-alpha.2 (opens in a new tab)

napi@2.16.2

4/10/2024

What Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi@2.16.1...napi@2.16.2 (opens in a new tab)

napi-sys@2.4.0

4/10/2024

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi@2.16.1...napi-sys@2.4.0 (opens in a new tab)

napi-derive@2.16.2

4/10/2024

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi-derive@2.16.1...napi-derive@2.16.2 (opens in a new tab)

napi@3.0.0-alpha.1

4/10/2024

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi@3.0.0-alpha.0...napi@3.0.0-alpha.1 (opens in a new tab)

napi@2.16.1

3/26/2024

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi@2.16.0...napi@2.16.1 (opens in a new tab)

napi-derive@2.16.1

3/26/2024

What's Changed

New Contributors

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi-derive@2.16.0...napi-derive@2.16.1 (opens in a new tab)

napi@3.0.0-alpha.0

3/20/2024

What's Changed

New Contributors

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi@2.16.0...napi@3.0.0-alpha.0 (opens in a new tab)

napi@2.16.0

2/28/2024

What's Changed

New Contributors

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi@2.15.4...napi@2.16.0 (opens in a new tab)

napi-derive@2.16.0

2/28/2024

What's Changed

New Contributors

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi@2.15.4...napi-derive@2.16.0 (opens in a new tab)

napi@2.15.4

2/22/2024

What's Changed

New Contributors

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi@2.15.3...napi@2.15.4 (opens in a new tab)

napi@2.15.3

2/21/2024

What's Changed

New Contributors

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi-build@2.1.1...napi@2.15.3 (opens in a new tab)

napi-build@2.1.1

2/18/2024

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi@2.15.2...napi-build@2.1.1 (opens in a new tab)

napi@2.15.2

2/17/2024

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/@napi-rs/cli@3.0.0-alpha.38...napi@2.15.2 (opens in a new tab)

napi-derive@2.15.1

2/8/2024

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi@2.15.1...napi-derive@2.15.1 (opens in a new tab)

napi@2.15.1

2/1/2024

What's Changed

New Contributors

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi@2.15.0...napi@2.15.1 (opens in a new tab)

napi@2.15.0

1/26/2024

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi@2.14.4...napi@2.15.0 (opens in a new tab)

napi-derive@2.15.0

1/26/2024

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi-derive@2.14.6...napi-derive@2.15.0 (opens in a new tab)

napi@2.14.4

1/24/2024

What's changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi@2.14.3...napi@2.14.4 (opens in a new tab)

napi@2.14.3

1/24/2024

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/@napi-rs/cli@3.0.0-alpha.35...napi@2.14.3 (opens in a new tab)

napi@2.14.2

12/31/2023

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi@2.14.1...napi@2.14.2 (opens in a new tab)

napi-derive@2.14.6

12/27/2023

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi-derive@2.14.5...napi-derive@2.14.6 (opens in a new tab)

napi-derive@2.14.5

12/27/2023

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/@napi-rs/cli@3.0.0-alpha.24...napi-derive@2.14.5 (opens in a new tab)

napi-derive@2.14.4

12/13/2023

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi-derive@2.14.3...napi-derive@2.14.4 (opens in a new tab)

napi-derive@2.14.3

12/11/2023

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/@napi-rs/cli@3.0.0-alpha.15...napi-derive@2.14.3 (opens in a new tab)

napi@2.14.1

11/20/2023

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi@2.14.0...napi@2.14.1 (opens in a new tab)

napi-derive@2.14.2

11/20/2023

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi-derive@2.14.1...napi-derive@2.14.2 (opens in a new tab)

napi-derive@2.14.1

11/8/2023

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi-sys@2.3.0...napi-derive@2.14.1 (opens in a new tab)

napi@2.14.0

11/7/2023

What's Changed

New Contributors

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi@2.13.3...napi@2.14.0 (opens in a new tab)

napi-sys@2.3.0

11/7/2023

What's Changed

napi-derive@2.14.0

11/7/2023

What's Changed

napi@2.13.3

8/16/2023

What's Changed

New Contributors

Full Changelog: https://github.com/napi-rs/napi-rs/compare/@napi-rs/cli@3.0.0-alpha.5...napi@2.13.3 (opens in a new tab)

napi@2.13.2

6/14/2023

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi@2.13.1...napi@2.13.2 (opens in a new tab)

napi@2.13.1

5/27/2023

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi@2.13.0...napi@2.13.1 (opens in a new tab)

napi@2.13.0

5/27/2023

What's Changed

New Contributors

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi@2.12.7...napi@2.13.0 (opens in a new tab)

napi@2.12.7

5/20/2023

What's Changed

New Contributors

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi-derive@2.12.5...napi@2.12.7 (opens in a new tab)

napi-derive@2.12.5

4/26/2023

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi-derive@2.12.4...napi-derive@2.12.5 (opens in a new tab)

napi@2.12.6

4/25/2023

What's Changed

New Contributors

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi@2.12.5...napi@2.12.6 (opens in a new tab)

napi-derive@2.12.4

4/25/2023

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi@2.12.5...napi-derive@2.12.4 (opens in a new tab)

napi@2.12.5

4/16/2023

What's Changed

New Contributors

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi@2.12.4...napi@2.12.5 (opens in a new tab)

napi@2.12.4

4/11/2023

What's Changed

New Contributors

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi@2.12.2...napi@2.12.4 (opens in a new tab)

napi-derive@2.12.3

4/11/2023

Core features

#[napi(string_enum)]
pub enum Status {
  Pristine,
  Loading,
  Ready,
}

⬇️⬇️⬇️⬇️⬇️

export const enum Status {
  Pristine = 'Pristine',
  Loading = 'Loading',
  Ready = 'Ready'
}

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi-derive@2.12.2...napi-derive@2.12.3 (opens in a new tab)

napi@2.12.2

3/30/2023

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi@2.12.1...napi@2.12.2 (opens in a new tab)

napi@2.12.1

3/23/2023

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi-derive@2.12.2...napi@2.12.1 (opens in a new tab)

napi-derive@2.12.2

3/22/2023

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi-derive@2.12.1...napi-derive@2.12.2 (opens in a new tab)

napi@2.12.0

3/21/2023

What's Changed

New Contributors

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi@2.11.4...napi@2.12.0 (opens in a new tab)

napi-derive@2.12.1

3/21/2023

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi-derive@2.12.0...napi-derive@2.12.1 (opens in a new tab)

napi-derive@2.12.0

3/21/2023

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi@2.11.4...napi-derive@2.12.0 (opens in a new tab)

napi@2.11.4

3/14/2023

What's Changed

New Contributors

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi@2.11.3...napi@2.11.4 (opens in a new tab)

napi@2.11.3

3/14/2023

What's Changed

New Contributors

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi-derive@2.11.1...napi@2.11.3 (opens in a new tab)

napi-derive@2.11.2

3/14/2023

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi-derive@2.11.1...napi-derive@2.11.2 (opens in a new tab)

napi@2.11.2

2/18/2023

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi@2.11.1...napi@2.11.2 (opens in a new tab)

napi-derive@2.11.1

2/18/2023

Changes

Full Changelog: https://github.com/napi-rs/napi-rs/compare/@napi-rs/cli@2.14.8...napi-derive@2.11.1 (opens in a new tab)

napi@2.11.1

2/9/2023

Error::new API enhancement

Error::new now support passing status: AsRef<str> and message: ToString

pub enum CustomError {
  NapiError(Error<Status>),
  Panic,
}
 
impl AsRef<str> for CustomError {
  fn as_ref(&self) -> &str {
    match self {
      CustomError::Panic => "Panic",
      CustomError::NapiError(e) => e.status.as_ref(),
    }
  }
}
 
#[napi]
pub fn custom_status_code() -> Result<(), CustomError> {
  Err(Error::new(CustomError::Panic, "don't panic"))
}
test('custom status code in Error', (t) => {
  t.throws(() => customStatusCode(), {
    code: 'Panic',
  })
})

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi@2.11.0...napi@2.11.1 (opens in a new tab)

napi@2.11.0

2/8/2023

Spread tuple arguments in ThreadsafeFunction

#[napi]
pub fn accept_threadsafe_function_tuple_args(func: ThreadsafeFunction<(u32, bool, String)>) {
  thread::spawn(move || {
    func.call(
      Ok((1, false, "NAPI-RS".into())),
      ThreadsafeFunctionCallMode::NonBlocking,
    );
  });
}

⬇️⬇️⬇️⬇️⬇️⬇️⬇️

export function acceptThreadsafeFunctionTupleArgs(func: (err: Error | null, arg0: number, arg1: boolean, arg2: string) => any): void

What's Changed

New Contributors

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi@2.10.17...napi@2.11.0 (opens in a new tab)

napi@2.10.17

2/8/2023

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi@2.10.16...napi@2.10.17 (opens in a new tab)

napi@2.10.16

2/7/2023

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi@2.10.15...napi@2.10.16 (opens in a new tab)

napi@2.10.15

2/5/2023

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/@napi-rs/cli@2.14.6...napi@2.10.15 (opens in a new tab)

napi@2.10.14

1/31/2023

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi@2.10.13...napi@2.10.14 (opens in a new tab)

napi-derive@2.10.1

1/31/2023

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi-derive@2.10.0...napi-derive@2.10.1 (opens in a new tab)

napi@2.10.13

1/28/2023

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi@2.10.12...napi@2.10.13 (opens in a new tab)

napi@2.10.12

1/28/2023

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi@2.10.11...napi@2.10.12 (opens in a new tab)

napi@2.10.11

1/25/2023

What's Changed

Background

Electron disallowed the create_external_xxx API since electron@21: https://www.electronjs.org/blog/v8-memory-cage (opens in a new tab) NAPI-RS will fallback to use create_buffer_copy if napi_create_external_buffer return the napi_no_external_buffers_allowed status.

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi@2.10.10...napi@2.10.11 (opens in a new tab)

napi@2.10.10

1/24/2023

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/@napi-rs/cli@2.14.4...napi@2.10.10 (opens in a new tab)

napi-derive@2.10.0

1/24/2023

Highlights

ThreadsafeFunction as params and object fields

#[napi]
pub fn accept_callback(callback: ThreadsafeFunction<u32>) {
  std::thread::spawn(move || {
    callback.call(200);
  });
}

⬇️⬇️⬇️⬇️⬇️

export function acceptCallback(callback: (err: Error | null, value: number) -> any)

Disable ToNapiValue for Object

With the object_to_js = false filed, the ThreadsafeFunction could be set as an Object field.

#[napi(object, object_to_js = false)]
pub struct Options {
  pub enable_jsx: bool,
  pub on_data: ThreadsafeFunction<Vec<u8>>,
}

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/@napi-rs/cli@2.14.4...napi-derive@2.10.0 (opens in a new tab)

napi@2.10.9

1/19/2023

What's Changed

Background

Electron disallowed the create_external_xxx API since electron@21: https://www.electronjs.org/blog/v8-memory-cage (opens in a new tab) NAPI-RS will fallback to use create_buffer_copy if napi_create_external_buffer return the napi_no_external_buffers_allowed status.

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi@2.10.8...napi@2.10.9 (opens in a new tab)

napi-sys@2.2.3

1/19/2023

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi@2.10.8...napi-sys@2.2.3 (opens in a new tab)

napi@2.10.8

1/18/2023

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi@2.10.7...napi@2.10.8 (opens in a new tab)

napi@2.10.7

1/16/2023

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi-derive@2.9.5...napi@2.10.7 (opens in a new tab)

napi-derive@2.9.5

1/14/2023

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/@napi-rs/cli@2.14.3...napi-derive@2.9.5 (opens in a new tab)

napi-derive@2.9.4

1/13/2023

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi@2.10.6...napi-derive@2.9.4 (opens in a new tab)

napi@2.10.6

1/11/2023

What's Changed

New Contributors

Full Changelog: https://github.com/napi-rs/napi-rs/compare/@napi-rs/cli@2.14.2...napi@2.10.6 (opens in a new tab)

napi@2.10.5

1/9/2023

What's Changed

New Contributors

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi@2.10.4...napi@2.10.5 (opens in a new tab)

napi@2.10.4

12/29/2022

What's Changed

New Contributors

Full Changelog: https://github.com/napi-rs/napi-rs/compare/@napi-rs/cli@2.14.0...napi@2.10.4 (opens in a new tab)

napi@2.10.3

12/19/2022

What's Changed

New Contributors

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi@2.10.2...napi@2.10.3 (opens in a new tab)

napi-derive@2.9.3

12/9/2022

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi-derive@2.9.2...napi-derive@2.9.3 (opens in a new tab)

napi@2.10.2

12/8/2022

What's Changed

New Contributors

Full Changelog: https://github.com/napi-rs/napi-rs/compare/@napi-rs/cli@2.13.0...napi@2.10.2 (opens in a new tab)

napi@2.10.1

11/12/2022

What's Changed

New Contributors

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi@2.10.0...napi@2.10.1 (opens in a new tab)

napi@2.10.0

10/4/2022

What's Changed

New Contributors

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi@2.9.1...napi@2.10.0 (opens in a new tab)

napi@2.9.1

9/8/2022

What's Changed

New Contributors

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi@2.9.0...napi@2.9.1 (opens in a new tab)

napi-derive@2.9.1

9/8/2022

What's Changed

New Contributors

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi@2.9.0...napi-derive@2.9.1 (opens in a new tab)

napi@2.9.0

8/23/2022

Core changes

as_object for ClassInstance

You can use the ClassInstance as Object on the Rust side and manipulate it.

#[napi]
impl CanvasElement {
  #[napi(constructor)]
  pub fn new(mut env: Env, mut this: This, width: u32, height: u32) -> Result<Self> {
    let ctx = CanvasRenderingContext2D::into_instance(
      CanvasRenderingContext2D {
        context: Context::new(width, height, ColorSpace::default())?,
      },
      env,
    )?;
    ctx.as_object(env).define_properties(&[
      Property::new(FILL_STYLE_HIDDEN_NAME)?
        .with_value(&env.create_string("#000")?)
        .with_property_attributes(PropertyAttributes::Writable | PropertyAttributes::Configurable),
      Property::new(STROKE_STYLE_HIDDEN_NAME)?
        .with_value(&env.create_string("#000")?)
        .with_property_attributes(PropertyAttributes::Writable | PropertyAttributes::Configurable),
    ])?;
    env.adjust_external_memory((width * height * 4) as i64)?;
    this.define_properties(&[Property::new("ctx")?
      .with_value(&ctx)
      .with_property_attributes(PropertyAttributes::Default)])?;
    Ok(Self { width, height, ctx })
  }
}

as_unknown for Either types

For the scenario that preserves original JavaScript values in Either types and sets them into object property, and retrieves it back in the other place.

  #[napi(getter)]
  pub fn get_fill_style(&self, this: This) -> Result<Unknown> {
    this.get_named_property_unchecked(FILL_STYLE_HIDDEN_NAME)
  }
 
  #[napi(setter, return_if_invalid)]
  pub fn set_fill_style(
    &mut self,
    env: Env,
    mut this: This,
    fill_style: Either3<JsString, ClassInstance<CanvasGradient>, ClassInstance<CanvasPattern>>,
  ) -> Result<()> {
    // ... some logic
    let raw_fill_style = fill_style.as_unknown(env);  
    this.set(FILL_STYLE_HIDDEN_NAME, &raw_fill_style)?;
    Ok(())
  }

ToNapiValue for f32

You can use f32 as the return type:

#[napi]
pub fn return_f32() -> f32 {
  3.14
}

What's Changed

New Contributors

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi-derive@2.8.0...napi@2.9.0 (opens in a new tab)

napi-derive@2.9.0

8/23/2022

What's Changed

New Contributors

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi-derive@2.8.0...napi-derive@2.9.0 (opens in a new tab)

napi@2.8.0

8/17/2022

Core changes

Custom finalize trait

https://napi.rs/docs/concepts/class#custom-finalize-logic (opens in a new tab)

use napi::bindgen_prelude::*;
use napi_derive::napi;
 
#[napi(custom_finalize)]
pub struct CustomFinalize {
  width: u32,
  height: u32,
  inner: Vec<u8>,
}
 
#[napi]
impl CustomFinalize {
  #[napi(constructor)]
  pub fn new(mut env: Env, width: u32, height: u32) -> Result<Self> {
    let inner = vec![0; (width * height * 4) as usize];
    let inner_size = inner.len();
    env.adjust_external_memory(inner_size as i64)?;
    Ok(Self {
      width,
      height,
      inner,
    })
  }
}
 
impl ObjectFinalize for CustomFinalize {
  fn finalize(self, mut env: Env) -> Result<()> {
    env.adjust_external_memory(-(self.inner.len() as i64))?;
    Ok(())
  }
}

Inject This in functions

https://napi.rs/docs/concepts/inject-this (opens in a new tab)

use napi::bindgen_prelude::*;
use napi_derive::napi;
 
#[napi(constructor)]
pub struct Width {
  pub value: i32,
}
 
#[napi]
pub fn plus_one(this: This<&Width>) -> i32 {
  this.value + 1
}

instance of

https://napi.rs/docs/concepts/class#instance-of (opens in a new tab)

use napi::bindgen_prelude::*;
use napi_derive::napi;
 
#[napi]
pub struct NativeClass {}
 
#[napi]
pub fn is_native_class_instance(env: Env, value: Unknown) -> Result<bool> {
  NativeClass::instance_of(env, value)
}
import { NativeClass, isNativeClassInstance } from './index.js'
 
const nc = new NativeClass()
console.log(isNativeClassInstance(nc)) // true
console.log(isNativeClassInstance(1)) // false

What's Changed

New Contributors

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi@2.7.0...napi@2.8.0 (opens in a new tab)

napi-derive@2.8.0

8/17/2022

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi-derive@2.7.0...napi-derive@2.8.0 (opens in a new tab)

napi@2.7.0

8/7/2022

Core features

Set property attribute in napi macro

The Object property attribute in objects and Class created by NAPI-RS is Writable & Configurable & Enumerable by default now.

For NativeClass:

#[napi]
pub struct NativeClass  {}
 
#[napi]
impl NativeClass {
  #[napi]
  pub fn hello(&self) {
    println!("hello");
  }
}

Before:

const instance = new NativeClass()
instance.hello = function() {} // Cannot assign to read only property \'hello\' of object \'#<NativeClass>\'

After:

const instance = new NativeClass()
instance.hello = function() {} // Just fine

You can also configure the Property attribute via #[napi]:

#[napi]
pub struct NativeClass  {}
 
#[napi]
impl NativeClass {
  #[napi(configurable = false, writable = false, enumerable = false)]
  pub fn hello(&self) {
    println!("hello");
  }
}

What's Changed

New Contributors

napi-derive@2.7.0

8/7/2022

What's Changed

napi@2.6.3

7/11/2022

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi@2.6.2...napi@2.6.3 (opens in a new tab)

napi@2.6.2

7/8/2022

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi@2.6.1...napi@2.6.2 (opens in a new tab)

napi@2.6.1

7/6/2022

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi-derive@2.6.0...napi@2.6.1 (opens in a new tab)

napi@2.6.0

7/6/2022

What's Changed

New Contributors

Full Changelog: https://github.com/napi-rs/napi-rs/compare/@napi-rs/cli@2.10.0...@napi-rs/cli@2.10.1 (opens in a new tab)

napi-derive@2.6.0

7/6/2022

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi-derive@2.5.0...napi-derive@2.6.0 (opens in a new tab)

napi@2.5.0

6/10/2022

What's Changed

New Contributors

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi@2.4.3...napi@2.5.0 (opens in a new tab)

napi-derive@2.5.0

6/10/2022

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi-derive@2.4.1...napi-derive@2.5.0 (opens in a new tab)

napi-build@2.0.1

6/10/2022

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi-build@2.0.0...napi-build@2.0.1 (opens in a new tab)

napi@2.4.3

5/12/2022

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi@2.4.2...napi@2.4.3 (opens in a new tab)

napi@2.4.2

5/10/2022

What's Changed

Experimental

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi@2.4.1...napi@2.4.2 (opens in a new tab)

napi-sys@2.2.2

5/10/2022

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi-sys@2.2.1...napi-sys@2.2.2 (opens in a new tab)

napi@2.4.1

5/7/2022

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi-sys@2.2.0...napi@2.4.1 (opens in a new tab)

napi@2.4.0

5/7/2022

What's Changed

New Contributors

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi-derive@2.3.3...napi@2.4.0 (opens in a new tab)

napi-sys@2.2.1

5/7/2022

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi-sys@2.2.0...napi-sys@2.2.1 (opens in a new tab)

napi-sys@2.2.0

5/7/2022

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi-derive@2.3.3...napi-sys@2.2.0 (opens in a new tab)

napi-build@2.0.0

5/7/2022

What's Changed

BREAKING

You must use napi 2.4+ with the napi-build@2

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi-derive@2.3.3...napi-build@2.0.0 (opens in a new tab)

napi@2.3.3

4/27/2022

What's Changed

Experimental

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi@2.3.2...napi@2.3.3 (opens in a new tab)

napi-derive@2.3.3

4/27/2022

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi-derive@2.3.2...napi-derive@2.3.3 (opens in a new tab)

napi-derive@2.3.2

4/27/2022

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi-derive@2.3.1...napi-derive@2.3.2 (opens in a new tab)

napi@2.3.2

4/25/2022

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi@2.3.1...napi@2.3.2 (opens in a new tab)

napi-derive@2.3.1

4/25/2022

What's Changed

New Contributors

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi@2.3.1...napi-derive@2.3.1 (opens in a new tab)

napi@2.3.1

4/15/2022

What's Changed

New Contributors

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi@2.3.0...napi@2.3.1 (opens in a new tab)

napi@2.3.0

4/15/2022

What's Changed

Reference API

use napi::bindgen_prelude::*;
 
pub struct Repository {
  dir: String,
}
 
impl Repository {
  fn remote(&self) -> Remote {
    Remote { inner: self }
  }
}
 
pub struct Remote<'repo> {
  inner: &'repo Repository,
}
 
impl<'repo> Remote<'repo> {
  fn name(&self) -> String {
    "origin".to_owned()
  }
}
 
#[napi]
pub struct JsRepo {
  inner: Repository,
}
 
#[napi]
impl JsRepo {
  #[napi(constructor)]
  pub fn new(dir: String) -> Self {
    JsRepo {
      inner: Repository { dir },
    }
  }
 
  #[napi]
  pub fn remote(&self, reference: Reference<JsRepo>, env: Env) -> Result<JsRemote> {
    Ok(JsRemote {
      inner: reference.share_with(env, |repo| Ok(repo.inner.remote()))?,
    })
  }
}
 
#[napi]
pub struct JsRemote {
  inner: SharedReference<JsRepo, Remote<'static>>,
}
 
#[napi]
impl JsRemote {
  #[napi]
  pub fn name(&self) -> String {
    self.inner.name()
  }
}
const repo = new JsRepo('.')
t.is(repo.remote().name(), 'origin')

New Contributors

Full Changelog: https://github.com/napi-rs/napi-rs/compare/@napi-rs/cli@2.2.0...napi@2.3.0 (opens in a new tab)

napi@2.3.0-alpha.1

4/7/2022

Features

  • Provide Reference API to keep class reference alive with JavaScript instance.
  • Allow injecting Reference into parameters like Env.
  • Add tests to ensure no memory leak happened in the new Reference API.
  • Buffer now can be used in struct which is implemented Task trait.
use napi::bindgen_prelude::*;
 
pub struct Repository {
  dir: String,
}
 
impl Repository {
  fn remote(&self) -> Remote {
    Remote { inner: self }
  }
}
 
pub struct Remote<'repo> {
  inner: &'repo Repository,
}
 
impl<'repo> Remote<'repo> {
  fn name(&self) -> String {
    "origin".to_owned()
  }
}
 
#[napi]
pub struct JsRepo {
  inner: Repository,
}
 
#[napi]
impl JsRepo {
  #[napi(constructor)]
  pub fn new(dir: String) -> Self {
    JsRepo {
      inner: Repository { dir },
    }
  }
 
  #[napi]
  pub fn remote(&self, reference: Reference<JsRepo>, env: Env) -> Result<JsRemote> {
    Ok(JsRemote {
      inner: reference.share_with(env, |repo| Ok(repo.inner.remote()))?,
    })
  }
}
 
#[napi]
pub struct JsRemote {
  inner: SharedReference<JsRepo, Remote<'static>>,
}
 
#[napi]
impl JsRemote {
  #[napi]
  pub fn name(&self) -> String {
    self.inner.name()
  }
}
const repo = new JsRepo('.')
t.is(repo.remote().name(), 'origin')

napi@2.2.0

3/6/2022

What's Changed

New Contributors

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi@2.1.0...napi@2.2.0 (opens in a new tab)