Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoInstallSign in
Socket

napi-postinstall

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

napi-postinstall

The `postinstall` script helper for handling native bindings in legacy `npm` versions

Source
npmnpm
Version
0.3.3
Version published
Weekly downloads
7.3M
-67.7%
Maintainers
1
Weekly downloads
 
Created
Source

napi-postinstall

GitHub Actions Workflow Status Codecov type-coverage CodeRabbit Pull Request Reviews npm GitHub Release

Conventional Commits Renovate enabled JavaScript Style Guide Code Style: Prettier changesets

The postinstall script helper for handling native bindings in legacy npm versions, this is a reimplementation of the node-install functionality from esbuild for napi-rs ecosystem packages like rollup, @swc/core and unrs-resolver.

For more details, please refer to the following issues:

TOC

Usage

Install

# pnpm
pnpm add napi-postinstall

# yarn
yarn add napi-postinstall

# npm
npm i napi-postinstall

# bun
bun add napi-postinstall

CLI

napi-postinstall unrs-resolver #<napi-package-name>

You can put it into scripts#postinstall of your package.json:

{
  "scripts": {
    "postinstall": "napi-postinstall unrs-resolver"
  }
}

This will check and prepare the napi binding packages for you automatically.

API

Types

// napi-postinstall
export interface PackageJson {
  name: string
  version: string
}

export declare function checkAndPreparePackage(
  packageNameOrPackageJson: PackageJson | string,
  checkVersion?: boolean,
): Promise<void>

// napi-postinstall/fallback
declare function fallback<T = unknown>(
  packageJsonPath: string,
  checkVersion?: boolean,
): T
export = fallback

Example

// index.js
const { checkAndPreparePackage, isNpm } = require('napi-postinstall')

if (isNpm()) {
  void checkAndPreparePackage('unrs-resolver' /* <napi-package-name> */)
}

// fallback.js
module.exports = require('napi-postinstall/fallback')(
  require.resolve('./package.json') /* <napi-package-json-path> */,
  true /* <check-version> */,
)

Sponsors and Backers

Sponsors

Sponsors

1stGRxTSUnTS
1stG Open Collective sponsorsRxTS Open Collective sponsorsUnTS Open Collective sponsors

Backers

1stGRxTSUnTS
1stG Open Collective backersRxTS Open Collective backersUnTS Open Collective backers

Changelog

Detailed changes for each release are documented in CHANGELOG.md.

License

MIT © JounQin@1stG.me

FAQs

Package last updated on 09 Aug 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts