npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

fume

v0.0.1

Published

Use factories to fabricate AMD and CommonJS modules

Downloads

24

Readme

Version

Fume

Use factories to fabricate AMD, CommonJS and UMD modules.

Overview

Fume is a code generation tool which allows you to:

  1. Define modules with factory functions.
  2. Automatic dependencies detection based on your factory's arguments.
  3. Manual dependencies mappings and annotations in your source code.

Write your code inside factory functions which receive dependencies as a list of arguments. Fume will use your factories to generate AMD, CJS and UMD compatible modules.

Fume will try to auto-magically detect inter-factory dependencies in your files. You can also provide platform-based annotations in your source code.

Installation & usage

Install with npm install -g fume

require('fume') for programmatic usage, or use the CLI tool:

fume [input(s)] -s [path] -s [path] ... --amdify --cjsify --umdify
        [input]: Input file path(s)
        -s (--sibling): Path of a sibling factory
        -a (--amdify): generate an AMD module
        -c (--cjsify): generate a CJS module
        -a (--umdify): generate a UMD module
        -o (--out): output directory (optional if input is one file)

You can use the CLI in two modes:

  1. Single factory:
    Build an AMD or a CJS module from a single factory. You may pass in a list of sibling factories which will be analyzed for automatic dependency resolution. If no output directory is specified, the result will be written to the standard output.

  2. Multiple factories: Pass multiple inputs to generate a module for each factory. Factories may be inter-dependent. You may pass in a list of sibling factories which will be analyzed for automatic dependency resolution. Results will be written to the specified output directory.

Source annotations

Annotations are specified in a comment right before the factory function.

Factory name

Annotation: @name

Sets the name of the factory. Will be used to resolve dependencies.

Example:

foo.module.js:

/* @name foo */
function factory(bar){ /* ... */ }

bar.module.js:

/* @name bar */
function factory(){ /* ... */ }

Generated AMD module for foo:

define(['./bar.module'], function factory(bar) {
    /* ... */
});

Specify dependency preference

Annotation: @prefer

Specify which dependency to use in case of ambiguity.

Example:

foo.js:

/**
 * @name foo
 * @prefer bar bar-2.0
 */
function factory(bar){ /* ... */ }

bar-1.0/bar.js:

/* @name bar */
function factory(){ /* ... */ }

bar-2.0/bar.js:

/* @name bar */
function factory(){ /* ... */ }

Note that both bar-1.0/bar and bar-2.0/bar are annotated with the name bar.

Generated AMD module for foo:

define(['./bar-1.0/bar'], function factory(bar) {
    /* ... */
});

Specify AMD / CJS dependency

Annotation: @amd, @cjs

Specify how a dependency should be located when your factory is generated as an AMD module or as a CJS module.

Example:

foo.js:

/**
 * @name foo
 * @amd $ jquery
 * @cjs $ jquery
 * @amd _ lodash-amd
 * @cjs _ lodash-node
 */
function factory($, _){ /* ... */ }

Generated AMD module for foo:

define([
    'jquery',
    'lodash-amd'
], function factory($, _) {
    /* ... */
});

Generated CJS module for foo:

module.exports = function factory($, _) {
    /* ... */
}(require('jquery'), require('lodash-node'));

Notice how the lodash dependency _ is located differently for CJS and AMD.