What is @npmcli/node-gyp?
The @npmcli/node-gyp package is a Node.js native addon build tool that interfaces with Google's GYP (Generate Your Projects) to build native addon modules in Node.js. It is a replacement and standalone version of the node-gyp bundled with npm. It helps in compiling Node.js native addon modules using Node.js's libuv and V8, among other dependencies.
What are @npmcli/node-gyp's main functionalities?
Building native addons
This code configures and builds a native addon using specific build settings. It sets the make command, architecture, and debug mode, then runs the build process.
const nodeGyp = require('@npmcli/node-gyp');
const config = {
make: 'make', // or 'gmake' on some systems
arch: process.arch,
debug: false
};
nodeGyp.configure(config, (err) => {
if (err) throw err;
nodeGyp.build((err) => {
if (err) throw err;
console.log('Build completed!');
});
});
Configuration of build environments
This code sample demonstrates how to clean up the build configuration for a project, which is useful when you want to ensure a fresh build environment.
const nodeGyp = require('@npmcli/node-gyp');
nodeGyp.clean((err) => {
if (err) throw err;
console.log('Configuration cleaned up.');
});
Other packages similar to @npmcli/node-gyp
node-pre-gyp
node-pre-gyp is a package that provides functionality similar to @npmcli/node-gyp but focuses on facilitating the publishing and installation of pre-built binaries. This is useful for avoiding the need to compile code on the installation machine, thus speeding up deployment and reducing setup complexity compared to @npmcli/node-gyp which compiles from source.
node-gyp-build
node-gyp-build is designed to simplify the process of building and using pre-compiled native addons. It automatically detects if a pre-built binary is available for a module and falls back to building from source if not. This package offers a simpler interface compared to @npmcli/node-gyp, which requires more manual configuration and build steps.
@npmcli/node-gyp
This is the module npm uses to decide whether a package should be built
using node-gyp
by default.
API
Returns a Promise that resolves to true
or false
based on whether the
package at path
has a binding.gyp
file.
A string with the default string that should be used as the install
script for node-gyp packages.