npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@xan105/addons

v2.1.1

Published

ESM loader to integrate native code into Node.js with prebuild support

Downloads

25

Readme

About

ESM loader to integrate native code into Node.js with prebuild support.

This library helps dealing with finding and loading your bindings when using ESM.

Currently supports:

  • [ N-API ] Native addon
  • [ WASI ] WebAssembly System Interface

📦 Scoped @xan105 packages are for my own personal use but feel free to use them.

NB: This library was previously named node-gyp-load

Example

import { dlopen } from "@xan105/addons";

const { foo } = await dlopen("bar.node", {
  cwd: import.meta.dirname
});

foo();

CLI

Prebuild (node-gyp)

Add addons as an install script to your native project:

{
  "scripts": {
    "install": "addons"
  }
}

Install script will check for prebuild(s) before building your project with node-gyp rebuild. You can force compile by doing npm install --build-from-source

Prebuild(s) are expected to be found in the prebuild or prebuilds folder; Organized in subfolders "platform-arch". They should be N-API native addons with the .node file extension.

Example:

MODULE_PATH/
  -prebuilds/
    -win32-x64/
      -targetname.node
      -targetname2.node
    -win32-ia32/
      -targetname.node
      -targetname2.node

NB: Install script is also available with its old name node-gyp-load for backward compatibility.

SRI

This library API has an option to verify hash integrity using Subresource Integrity (SRI) string.

As such there is a convenience script named addons-sri to generate hash for every .node or .wasm files in the current working dir (excluding node_modules).

{
  "scripts": {
    "sri": "addons-sri --algo sha384"
  }
}

You can specify the algo hash through the --algo argument; if omitted it defaults to sha384.

API

⚠️ This module is only available as an ECMAScript module (ESM).

Named export

dlopen(filePath: string, option?: object): Promise<unknown>

Find and load specified addon based on its extention (.node, .wasm, ...).

  • When loading NAPI addons, if you only provide the bindings name (basename) this will automatically search the bindings in known locations such as build/Release, relative to the current working dir. You can change this directory using the cwd option.

  • When loading WASI addons, you can specify the WASI version with the option version.

⚙️ Options

  • cwd?: string (current working dir)

    Current working dir where the node bindings is searched for.

  • version?: string (preview1)

    WASI version. Currently only unstable and preview1 are available.

  • integrity?: string (none)

    Verify the addon hash against specified Subresource Integrity (SRI) string (eg: sha384-base64...).

    In case of NAPI gyp compilation (= no prebuild) this check is skipped.

NAPI Namespace

import {} from "@xan105/addons/napi"

find(module: string, cwd: string): Promise<{ path:string, isPrebuild: boolean }>

Find node bindings by searching in known locations such as build/Release, relative to the specified current working dir.

load(filePath: string): unknown

Load specified node bindings.

WASI Namespace

import {} from "@xan105/addons/wasi"

const VERSION: string[]

WASI version available.

load(filePath: string, version: string): Promise<unknown>

Load specified WASI addon.