Registry / devops / ninja-build-gen

ninja-build-gen

JSON →
library0.2.2jsnpmunverified

ninja-build-gen is a JavaScript library designed to programmatically create manifest files for the Ninja build system. As of its latest version, 0.2.2, published over a decade ago, the project appears to be abandoned, with no known active development or recent updates. It provides a low-level API to define build rules, edges, and variables directly in JavaScript, outputting a standard `build.ninja` file. It differentiates itself by offering direct, code-based generation of Ninja manifests, enabling developers to define their build logic dynamically. However, it explicitly does not include the Ninja build system itself, nor does it provide high-level features like file globbing or pattern matching, recommending external libraries such as `glob` or `globule` for such functionalities. Its minimal scope focuses solely on generating the build file structure.

npm install ninja-build-gen
INSTALL
IMPORT
SIG · NINJA-BUILD-GEN
N
ninja-build-gen
devopsjavascriptv0.2.2
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ninjaBuildGen
const ninjaBuildGen = require('ninja-build-gen');
import ninjaBuildGen from 'ninja-build-gen';
This package is CommonJS-only, designed for Node.js versions >=0.8.0. ES module imports (`import`) are not supported natively and will cause errors without transpilation or specific Node.js loader configurations.
ninja
const ninjaBuildGen = require('ninja-build-gen'); const ninja = ninjaBuildGen('1.3', 'build');
The primary API is accessed by calling the `ninjaBuildGen` function, which returns a Ninja manifest object (`ninja`) to which rules and edges are added.
escape
const ninjaBuildGen = require('ninja-build-gen'); const escapedString = ninjaBuildGen.escape('string with spaces');
import { escape } from 'ninja-build-gen';
The `escape` utility function is a static method on the main `ninjaBuildGen` export, used for sanitizing strings for Ninja files.

Demonstrates how to initialize `ninja-build-gen`, define custom build rules for CoffeeScript and Stylus, create build edges for source files, set a default target, and save the generated `build.ninja` file. This script effectively acts as a 'configure.js' for a project.

const ninjaBuildGen = require('ninja-build-gen'); const fs = require('fs'); // Create a new Ninja build file for version 1.3, with 'build' as the build directory const ninja = ninjaBuildGen('1.3', 'build'); // Add rules for CoffeeScript and Stylus compilation ninja.rule('coffee') .run('coffee -cs < $in > $out') .description("Compile Coffeescript '$in' to '$out'."); ninja.rule('stylus') .run('stylus $in -o $$(dirname $out)') .description("Compile Stylus '$in' to '$out'"); // Define build edges (tasks) using the created rules ninja.edge('foo.js').from('foo.coffee').using('coffee'); ninja.edge('bar.js').from('bar.coffee').using('coffee'); ninja.edge('glo.css').from('glo.stylus').using('stylus'); // Create an aggregate edge for all assets and set it as the default build target ninja.edge('assets').from(['foo.js', 'bar.js', 'glo.css']); ninja.byDefault('assets'); // Save the generated Ninja manifest to 'build.ninja' ninja.save('build.ninja'); console.log('Generated build.ninja successfully.'); console.log('To build, run: node configure.js && ninja');
Debug
Known issues
breakingThis package is severely outdated (v0.2.2, last published 10+ years ago) and is unlikely to function without issues in modern Node.js environments (v12+). It predates significant changes in Node.js, including the widespread adoption of ES Modules and modern JavaScript syntax, and may require specific legacy Node.js versions or polyfills to run.
fix
Consider using alternative, actively maintained build automation tools or package an older Node.js version in a container for compatibility.
affects: >=0.2.2
gotchaThe `ninja-build-gen` library only *generates* Ninja build files; it does not include the Ninja build system itself. Users must separately install the Ninja build tool (e.g., via `apt`, `brew`, or the `ninja-build` npm package) to execute the generated `build.ninja` files.
fix
Install the Ninja build system globally or as a project dependency (e.g., `npm install ninja-build --save-dev`) and ensure it's available in your PATH.
affects: >=0.1.0
gotcha`ninja-build-gen` provides only a low-level API for build file generation. It explicitly does *not* offer features like file globbing, wildcards, or directory scanning. Developers are expected to integrate other libraries, such as `glob` or `globule`, to manage file discovery and mapping for their build processes.
fix
Integrate a file globbing library (e.g., `npm install glob globule`) and use its API to programmatically determine input and output files before defining Ninja edges.
affects: >=0.1.0
gotchaThe package is written exclusively for CommonJS (`require`) and does not natively support ES Modules (`import`). Attempting to use `import` syntax will result in errors in modern Node.js environments unless transpilation or specific Node.js loader configurations are in place.
fix
Ensure your project uses CommonJS (`.js` files with `require`) or configure your build system (e.g., Webpack, Rollup, Babel) to transpile to CommonJS if using ES Modules.
affects: >=0.1.0
Errors
Common errors & fixes
ReferenceError: require is not defined in ES module scope
Attempting to use `require()` syntax within an ES Module (`.mjs` file or `.js` file with `"type": "module"` in `package.json`).
fix
Rename your file to `.cjs` or change your `package.json` to `"type": "commonjs"`. Alternatively, restructure your project to use older Node.js versions compatible with CommonJS as default.
TypeError: ninjaBuildGen is not a function
This error typically occurs if `require('ninja-build-gen')` did not successfully return the function, often due to an incorrect import method (e.g., `import { ninjaBuildGen } from 'ninja-build-gen'`) or an issue with the CommonJS module loading itself.
fix
Ensure you are using `const ninjaBuildGen = require('ninja-build-gen');` and that the package is correctly installed and accessible in your Node.js environment.
command not found: ninja
After generating `build.ninja` with `ninja-build-gen`, the `ninja` executable itself is not found in the system's PATH.
fix
Install the Ninja build system globally (e.g., `sudo apt-get install ninja-build` on Linux, `brew install ninja` on macOS) or install `npm install ninja-build --save-dev` and invoke it via `npx ninja` or a package script.
Upgrade
Version history
0.2.2latest on npm
Audit
Dependencies
ninja-buildoptionalProvides the Ninja build system executable, which is necessary to run the generated build files. This package only generates the files.
globoptionalRecommended for advanced usage scenarios requiring file discovery and globbing patterns to define build edges.
globuleoptionalRecommended for advanced usage scenarios involving file matching and output filename generation.
Agent activity
2 hits · last 30 days
node
2
Resources
ninja-build-gen — npm install ninja-build-gen · libregistry