napi-rs

A framework for building compiled Node.js add-ons in Rust via Node-API

OTHER License

Downloads
6.9M
Stars
5.4K
Committers
119

Bot releases are hidden (Show)

napi-rs - [email protected]

Published by Brooooooklyn over 2 years ago

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/[email protected]@2.3.3

napi-rs - [email protected]

Published by Brooooooklyn over 2 years ago

What's Changed

Experimental

Full Changelog: https://github.com/napi-rs/napi-rs/compare/[email protected]@2.3.3

napi-rs - [email protected]

Published by Brooooooklyn over 2 years ago

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/[email protected]@2.3.2

napi-rs - @napi-rs/[email protected]

Published by Brooooooklyn over 2 years ago

2.7.0 (2022-04-27)

Bug Fixes

  • cli: generated type def on multi impl blocks (c3a35a0)

Features

  • cli: add build option to not include the header in dts file (#1140) (c390609)
napi-rs - [email protected]

Published by Brooooooklyn over 2 years ago

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/[email protected]@2.3.2

napi-rs - [email protected]

Published by Brooooooklyn over 2 years ago

What's Changed

New Contributors

Full Changelog: https://github.com/napi-rs/napi-rs/compare/[email protected]@2.3.1

napi-rs - [email protected]

Published by Brooooooklyn over 2 years ago

What's Changed

New Contributors

Full Changelog: https://github.com/napi-rs/napi-rs/compare/[email protected]@2.3.1

napi-rs - [email protected]

Published by Brooooooklyn over 2 years ago

What's Changed

  • docs: add return Promise callback function @Brooooooklyn
  • feat(napi): relax the value type on ThreadSafeFunction @Brooooooklyn
  • feat(napi-derive): support generic types on fn @Brooooooklyn
  • fix(napi-derive): JsUnknown should be unknown type @Brooooooklyn
  • feat(napi): add from_unknown method on FromNapiValue @Brooooooklyn
  • fix(napi): typo unrwap -> unwrap @waltonseymour
  • chore(napi): show tips if create different buffers with same data @Brooooooklyn
  • test(napi): add memory tests for Reference @Brooooooklyn
  • fix(napi): make buffer Send & Sync safe @Brooooooklyn
  • feat(napi): redesign the Reference API (#1118) @Brooooooklyn
  • Revert "chore: unset CARGO_BUILD_TARGET in debian.Dockerfile" @Brooooooklyn
  • chore: unset CARGO_BUILD_TARGET in debian.Dockerfile @Brooooooklyn
  • build: migrate debian image to messense/manylinux2014-cross @Brooooooklyn
  • feat(napi): experimental class reference API @Brooooooklyn
  • fix(napi): remove CString::from_vec_with_nul_unchecked @Brooooooklyn
  • feat(napi): allow empty enums @antoniomuso
  • ci: add binary build check @messense
  • fix(napi): double allocation in create_buffer @Brooooooklyn

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/[email protected]@2.3.0

napi-rs - [email protected]

Published by Brooooooklyn over 2 years ago

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-rs - @napi-rs/[email protected]

Published by Brooooooklyn over 2 years ago

2.6.2 (2022-04-01)

Bug Fixes

napi-rs - @napi-rs/[email protected]

Published by Brooooooklyn over 2 years ago

2.6.1 (2022-04-01)

Bug Fixes

  • cli: should not throw if cargoName is provided but no package.name (8700da1)
napi-rs - @napi-rs/[email protected]

Published by Brooooooklyn over 2 years ago

2.6.0 (2022-04-01)

Bug Fixes

  • cli: prevent crash if GITHUB_REPOSITORY is not specified (ac8406c)
  • cli: respect CARGO_BUILD_TARGET env variable (bd08787)
  • cli: use shell file path instead of commands for zig CC and CXX (09ccfaa)

Features

  • cli: add libc filed in native package.json (ee0279e)
  • cli: add support for building binaries (20b1edc)
  • cli: upgrade ci.yml templates (1cac0ac)
napi-rs - @napi-rs/[email protected]

Published by Brooooooklyn over 2 years ago

2.5.0 (2022-03-22)

Bug Fixes

  • cli: use shell file path instead of commands for zig CC and CXX (09ccfaa)

Features

  • cli: add libc filed in native package.json (ee0279e)
  • cli: upgrade ci.yml templates (1cac0ac)
napi-rs - [email protected]

Published by Brooooooklyn over 2 years ago

What's Changed

New Contributors

Full Changelog: https://github.com/napi-rs/napi-rs/compare/[email protected]@2.2.0

napi-rs - @napi-rs/[email protected]

Published by Brooooooklyn over 2 years ago

2.4.5 (2022-03-05)

Bug Fixes

  • cli: temporary dts path may not be writable (e69f023)
  • napi: race issues with Node.js worker_thread (#1081) (9f3fbaa)
napi-rs - @napi-rs/[email protected]

Published by Brooooooklyn over 2 years ago

2.4.4 (2022-02-11)

Bug Fixes

  • cli: generate ExternalObject type on demand (f9c618e)
napi-rs - [email protected]

Published by Brooooooklyn over 2 years ago

What's Changed

New Contributors

Full Changelog: https://github.com/napi-rs/napi-rs/compare/[email protected]@2.1.0

napi-rs - [email protected]

Published by Brooooooklyn over 2 years ago

What's Changed

New Contributors

Full Changelog: https://github.com/napi-rs/napi-rs/compare/[email protected]@2.1.0

napi-rs - @napi-rs/[email protected]

Published by Brooooooklyn over 2 years ago

2.4.3 (2022-02-09)

Bug Fixes

  • cli: compatible for Node.js 10x (5f359df)
napi-rs - @napi-rs/[email protected]

Published by Brooooooklyn over 2 years ago

2.4.2 (2022-01-19)

Bug Fixes

  • cli: js binding template (25f6754)