Broccoli Node Information Utility

2.2.0 · active · verified Sun Apr 19

broccoli-node-info is a low-level JavaScript utility package designed to interact with Broccoli.js plugin instances (nodes). Its primary function is to provide a thin, normalized wrapper around the `node.__broccoliGetInfo__()` internal API, abstracting away differences between various Broccoli node API versions to consistently return a `nodeInfo` object conforming to the latest specification. This package is primarily leveraged by the core Broccoli `Builder` class but is also invaluable for developers performing node inspection, testing, diagnostics, or creating wrappers, offering a safer alternative to directly accessing private node variables like `_name` or `_inputNodes`. The current stable version is 2.2.0, with recent updates like 2.0.0 and 2.1.0 indicating active maintenance and compatibility updates, such as tracking input changes and support for the `volatile` option. Its release cadence aligns with major Broccoli.js ecosystem updates, ensuring it remains a foundational piece for interacting with Broccoli nodes programmatically.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to use `getNodeInfo` to safely extract information from a Broccoli plugin instance, including handling potential `InvalidNodeError`.

import { getNodeInfo } from 'broccoli-node-info';
import BroccoliPlugin from 'broccoli-plugin';

class MyBroccoliPlugin extends BroccoliPlugin {
  constructor(inputNodes, options) {
    super(inputNodes, {
      annotation: options?.annotation || 'MyBroccoliPlugin',
      name: options?.name || 'MyBroccoliPlugin',
      persistentOutput: true,
      ...options
    });
  }

  async build() {
    // Simulate some build process
    console.log(`Building with ${this.inputNodes.length} input nodes.`);
  }
}

const dummyNode = new MyBroccoliPlugin([], { annotation: 'my-plugin-instance' });

try {
  const nodeInfo = getNodeInfo(dummyNode);
  console.log('Node Name:', nodeInfo.name);
  console.log('Node Annotation:', nodeInfo.annotation);
  console.log('Persistent Output:', nodeInfo.persistentOutput);
  console.log('Input Nodes (raw):', nodeInfo.inputNodes);
} catch (error) {
  console.error('Error getting node info:', error.message);
}

// Example of an invalid node
const invalidNode = 'path/to/my/files'; // Plain string node (deprecated)
try {
  getNodeInfo(invalidNode);
} catch (error) {
  console.error('Caught expected error for invalid node:', error.message);
}

view raw JSON →