Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including compartment with all npm packages installed. Try it out:

var compartment = require("compartment")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

compartment v0.3.0

A type of dependency graph, component manager, and package builder.

Compartment v0.3.0

Compartment is part dependency graph, part component manager, part package builder, all handled through a manifest file. The manifest simply stores a list of components and their dependency on other components from the same manifest. Compartment provides an easy mechanism to create custom packaging builds with resolution for file types, system paths, and requirements.


Compartment was built to handle the dependencies for front-end files, like CSS and JS. It allows components to define source paths for multiple file types, making it really easy to customize and package. However, Compartment is pretty abstract and can be used in any way possible.


Require the module and instantiate a new instance.

var Compartment = require('compartment'),
    graph = new Compartment();

Define the types of files the graph will support.

    css: '/src/css/',
    js: '/src/js/'

Either load the list of components from a manifest file, or define manually. Each component supports the following properties:

  • name - Name of component
  • category - The type of component
  • require - A list of other components that this component requires
  • provide - A list of other components that this component includes
  • priority - The order in which to sort components in the chain
  • source - An object mapping of types (defined above) to a list of values

    button: {
        category: 'component',
        source: {
            css: ['button.css']
    buttonGroup: {
        category: 'component',
        require: ['button'],
        source: {
            css: ['button-group.css']
    modal: {
        category: 'component',
        source: {
            css: ['modal.css'],
            js: ['modal.js']

Build a chain of components (or all) with optional category filtering.

graph.buildChain(); // all
graph.buildChain(['buttonGroup']); // build buttonGroup and dependencies
graph.buildChain(null, 'component'); // filter all by category

Return a merged list of sources based on the type.

// ['/src/css/button.css', '/src/css/button-group.css']

Running Tests

Run the following command in the project root to run all tests.



RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free