CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-prebuild

A command line tool for easily making prebuilt binaries for multiple versions of Node.js, Electron or node-webkit on a specific platform

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

Prebuild

Prebuild is a command line tool and JavaScript library for easily making prebuilt binaries for multiple versions of Node.js, Node-API, Electron, and NW.js on a specific platform. It automates the complex process of cross-compilation by downloading appropriate headers, managing build environments, and uploading prebuilt binaries to GitHub releases for distribution.

Package Information

  • Package Name: prebuild
  • Package Type: npm
  • Language: JavaScript
  • Installation: npm install -g prebuild (CLI) or npm install prebuild (programmatic)

Core Imports

const { build } = require('prebuild');

For individual modules:

const build = require('prebuild/build');
const upload = require('prebuild/upload'); 
const util = require('prebuild/util');
const prebuild = require('prebuild/prebuild');

Basic Usage

CLI Usage

# Build for all supported ABI versions
prebuild --all

# Build for specific targets
prebuild -t 16.14.0 -t 18.0.0

# Build for Node-API
prebuild -t 3 -r napi

# Build for Electron
prebuild -t 22.0.0 -r electron

# Build and upload to GitHub
prebuild --all --upload <github-token>

# Strip debug symbols
prebuild --all --strip

Programmatic Usage

const { build } = require('prebuild');

// Build for current Node.js version
build({
  pkg: require('./package.json'),
  log: console
}, '16.14.0', (err) => {
  if (err) throw err;
  console.log('Build completed');
});

Architecture

Prebuild is built around several key components:

  • CLI Interface: Command-line tool (bin.js) that orchestrates the build process
  • Build System: Core build logic (build.js, prebuild.js) that manages compilation
  • Backend Abstraction: Support for multiple build systems (node-gyp, cmake-js, nw-gyp, node-ninja)
  • Cross-Platform Support: Handles Node.js, Node-API, Electron, and NW.js runtimes
  • Artifact Management: Packaging (pack.js), stripping (strip.js), and upload (upload.js) functionality
  • Configuration System: Runtime configuration (rc.js) with command-line and config file support

Capabilities

Build System

Core build functionality for compiling native modules against different Node.js runtimes and versions.

/**
 * Build native module for specified target and runtime
 * @param opts - Build options including pkg, log, backend, debug flags
 * @param version - Target version to build for
 * @param cb - Callback function (err) => void
 */
function build(opts, version, cb);

interface BuildOptions {
  pkg: PackageJson;
  log?: Logger;
  preinstall?: string;
  gyp?: object;
  backend?: 'node-gyp' | 'node-ninja' | 'nw-gyp' | 'cmake-js';
  args?: string[];
  debug?: boolean;
}

Build System

Configuration Management

Runtime configuration system supporting command-line arguments, config files, and environment variables.

/**
 * Parsed configuration object with defaults and CLI arguments
 */
interface ConfigurationOptions {
  target: string | string[];
  runtime: 'node' | 'napi' | 'electron' | 'node-webkit';
  arch: string;
  platform: string;
  backend: string;
  debug: boolean;
  strip: boolean;
  upload?: string;
  all: boolean;
  force: boolean;
  verbose: boolean;
  'include-regex': RegExp;
  'tag-prefix': string;
  prerelease: boolean;
}

Configuration

Upload System

GitHub releases integration for uploading prebuilt binaries with automatic release creation.

/**
 * Upload prebuilt binaries to GitHub releases
 * @param opts - Upload options including files, token, and release settings
 * @param cb - Callback function (err, result) => void
 */
function upload(opts, cb);

interface UploadOptions {
  pkg: PackageJson;
  files: string[];
  upload: string; // GitHub token
  'tag-prefix'?: string;
  prerelease?: boolean;
  gh?: object;
}

interface UploadResult {
  new: string[];
  old: string[];
}

Upload System

Utilities

Common utility functions for file operations, process spawning, and path generation.

/**
 * Generate tar file path for prebuilt binary
 * @param opts - Options containing package info and build settings
 * @param abi - ABI version string
 * @returns Generated tar file path
 */
function getTarPath(opts, abi): string;

/**
 * Spawn child process with error handling
 * @param cmd - Command to execute
 * @param args - Command arguments
 * @param cb - Callback function (err) => void
 */
function spawn(cmd, args, cb): void;

/**
 * Execute shell command or JavaScript file
 * @param item - Shell command or .js file path
 * @param cb - Callback function (err) => void
 */
function run(item, cb): void;

Utilities

Types

interface PackageJson {
  name: string;
  version: string;
  binary?: {
    module_name?: string; 
    module_path?: string;
    napi_versions?: number[];
  };
}

interface Logger {
  info: (...args: any[]) => void;
  verbose: (...args: any[]) => void;
  error: (...args: any[]) => void;
}

type Runtime = 'node' | 'napi' | 'electron' | 'node-webkit';
type Backend = 'node-gyp' | 'node-ninja' | 'nw-gyp' | 'cmake-js';
Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/prebuild@13.0.x
Publish Source
CLI
Badge
tessl/npm-prebuild badge