A command line tool for easily making prebuilt binaries for multiple versions of Node.js, Electron or node-webkit on a specific platform
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Runtime configuration system supporting command-line arguments, config files, and environment variables with automatic target selection and prebuild configuration.
Main configuration object combining defaults, RC files, and command-line arguments.
/**
* Runtime configuration object parsed from command line, config files, and defaults
*/
interface ConfigurationOptions {
/** Target version(s) to build for - can be single version or array */
target: string | string[];
/** Runtime to build for */
runtime: 'node' | 'napi' | 'electron' | 'node-webkit';
/** Target CPU architecture */
arch: string;
/** Target platform */
platform: string;
/** LIBC variant for Linux builds */
libc: string;
/** Build backend to use */
backend: 'node-gyp' | 'node-ninja' | 'nw-gyp' | 'cmake-js';
/** Additional format parameters for node-gyp */
format: string | false;
/** Build all supported ABI versions */
all: boolean;
/** Force rebuild even if output exists */
force: boolean;
/** Build in debug mode */
debug: boolean;
/** Enable verbose logging */
verbose: boolean;
/** Working directory for build */
path: string;
/** Strip debug symbols from output */
strip: boolean;
/** GitHub token for uploading releases */
upload?: string;
/** Upload all files from prebuilds directory */
'upload-all'?: string;
/** Tag prefix for GitHub releases */
'tag-prefix': string;
/** Mark release as prerelease */
prerelease: boolean;
/** Regex pattern for files to include in package */
'include-regex': RegExp;
/** Script to run before building */
preinstall?: string;
/** Script to run before packing */
prepack?: string;
/** Processed prebuild targets array */
prebuild?: PrebuildTarget[];
/** Command line arguments */
argv?: string[];
}
interface PrebuildTarget {
runtime: Runtime;
target: string;
}
type Runtime = 'node' | 'napi' | 'electron' | 'node-webkit';Usage Examples:
const rc = require('prebuild/rc');
// Access configuration
console.log('Building for:', rc.runtime, rc.target);
console.log('Architecture:', rc.arch);
console.log('Backend:', rc.backend);
// Check if uploading
if (rc.upload) {
console.log('Will upload to GitHub with token');
}
// Access prebuild targets
rc.prebuild.forEach(target => {
console.log(`Target: ${target.runtime} ${target.target}`);
});Default values applied before parsing command-line arguments and config files.
/**
* Default configuration values
*/
interface DefaultConfiguration {
target: string; // process.versions.node
runtime: 'node';
arch: string; // process.arch
libc: string; // auto-detected or empty
platform: string; // process.platform
all: false;
force: false;
debug: false;
verbose: false;
path: '.';
backend: 'node-gyp';
format: false;
'include-regex': '\\.node$';
'tag-prefix': 'v';
prerelease: false;
}Supported command-line argument aliases for common options.
/**
* Command line argument aliases
*/
interface CommandAliases {
target: 't';
runtime: 'r';
help: 'h';
arch: 'a';
path: 'p';
force: 'f';
version: 'v';
upload: 'u';
preinstall: 'i';
prepack: 'c';
}Usage Examples:
# Long form arguments
prebuild --target 16.14.0 --runtime node --arch x64
# Short form aliases
prebuild -t 16.14.0 -r node -a x64
# Upload with token
prebuild --all --upload ghp_token123
# Using aliases
prebuild --all -u ghp_token123Automatic Node-API version handling and validation.
/**
* Node-API specific configuration handling
*/
interface NapiConfiguration {
/** Available Node-API build versions */
napiBuildVersions: number[];
/** Best Node-API version for current Node.js */
bestNapiBuildVersion: number;
/** Supported Node-API versions from package.json */
supportedVersions: number[];
}Usage Examples:
// Building for Node-API (configured automatically)
// Command: prebuild -r napi --all
// Results in prebuild targets for all supported Node-API versions
// Single Node-API version
// Command: prebuild -r napi -t 3
// Results in prebuild target for Node-API version 3Configuration file support using the 'rc' module with ~/.prebuildrc files.
/**
* RC file configuration options
*/
interface RcFileOptions {
/** GitHub upload token */
upload?: string;
/** Default target versions */
target?: string | string[];
/** Default runtime */
runtime?: Runtime;
/** Default architecture */
arch?: string;
/** Default build backend */
backend?: Backend;
/** Enable verbose logging by default */
verbose?: boolean;
/** Default tag prefix for releases */
'tag-prefix'?: string;
}RC File Example (~/.prebuildrc):
{
"upload": "ghp_your_github_token_here",
"verbose": true,
"tag-prefix": "v",
"backend": "node-gyp"
}Environment variables that affect configuration.
/**
* Recognized environment variables
*/
interface EnvironmentVariables {
/** LIBC family detection override */
LIBC?: string;
/** Strip command override (defaults to 'strip') */
STRIP?: string;
/** NVM mirror URLs (automatically deleted) */
NVM_IOJS_ORG_MIRROR?: string;
NVM_NODEJS_ORG_MIRROR?: string;
}Automatic target selection based on runtime and flags.
/**
* Target selection for different scenarios
*/
interface TargetSelection {
/** When --all is used with Node.js runtime */
allNodeTargets: PrebuildTarget[]; // All supported Node.js ABI versions
/** When --all is used with Node-API runtime */
allNapiTargets: PrebuildTarget[]; // All supported Node-API versions
/** When specific targets provided */
specificTargets: PrebuildTarget[];
/** Default when no targets specified */
defaultTarget: PrebuildTarget;
}~/.prebuildrc and project-level .prebuildrc filesLIBC and other env vars appliedtype Runtime = 'node' | 'napi' | 'electron' | 'node-webkit';
type Backend = 'node-gyp' | 'node-ninja' | 'nw-gyp' | 'cmake-js';
interface PrebuildTarget {
runtime: Runtime;
target: string;
}Install with Tessl CLI
npx tessl i tessl/npm-prebuild