Empath - Javascript Library Sniffer
Currently in the Javascript community there is simply no concenses about modules. This is a problem. Empath scans a Javascript library and gives you information on how it expects to be consumed.
Install
npm install empath -g
Usage
You've got a Javascript library sitting there in a directory called backbone. Maybe you downloaded it using a package manager or cloned it using git or extracted it as a tarball from github. How do you use it?
$ empath backbone # give it the path of the directory
Searching for main in backbone
has backbone/bower.json? yes
No main found in backbone/bower.json
has backbone/component.json? no
has backbone/package.json? yes
Main found in backbone/package.json: backbone.js
Supports AMD?
no
Supports CommonJS?
yes
dependencies: underscore
exports a object
Globals variables exported
Backbone
Ah, okay. Empath tells you that the main file to include is: backbone.js
at the root of the directory and that it does not support the AMD module format but does support the CommonJS format and depends on underscore. Or if you don't use a module system and just want to include it in a script tag, then it exports Backbone
as a global variable.
Background Information
Module Format
On the issue of module format, there are generally three camps:
- (AMD(Require.js))[http://requirejs.org/docs/whyamd.html]
- CommonJS(Node)
- We don't need a module system, just add globals
Registry
Here is a list of the most popular package registries for Javascript
- NPM - the registry for Node modules, currently the most popular JS registry, but the modules are generally not intended for use in the browser. However, Browserify has been a popular tool in re-targeting Node-style Javascript for browser use. Format: CommonJS.
- Jam - A registry and package manager with a easy workflow. AMD-based.
- Bower - a new registry by Twitter. Format agnostic but does nothing for workflow.
- Component - the only front-end module registry using CommonJS. Requires a build step.
- Volo - Another AMD-based registry with workflow and project scaffolding.
For more information on module registries, take a look a this article by wilmoore.