Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fume

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fume

Use factories to fabricate AMD and CommonJS modules

  • 0.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
15
increased by200%
Maintainers
1
Weekly downloads
 
Created
Source

Fume

Use factories to fabricate AMD and CommonJS 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 and CJS 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
    [input]: Input file path(s)
    -s (--sibling): Path of a sibling factory
    -a (--amdify): generate an AMD module
    -c (--cjsify): generate a CJS 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.

FAQs

Package last updated on 14 Oct 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc