napi-postinstall


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 add napi-postinstall
yarn add napi-postinstall
npm i napi-postinstall
bun add napi-postinstall
CLI
napi-postinstall unrs-resolver
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
export interface PackageJson {
name: string
version: string
}
export declare function checkAndPreparePackage(
packageNameOrPackageJson: PackageJson | string,
checkVersion?: boolean,
): Promise<void>
declare function fallback<T = unknown>(
packageJsonPath: string,
checkVersion?: boolean,
): T
export = fallback
Example
const { checkAndPreparePackage, isNpm } = require('napi-postinstall')
if (isNpm()) {
void checkAndPreparePackage('unrs-resolver' )
}
module.exports = require('napi-postinstall/fallback')(
require.resolve('./package.json') ,
true ,
)
Sponsors and Backers

Backers
Changelog
Detailed changes for each release are documented in CHANGELOG.md.
License
MIT © JounQin@1stG.me