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

grunt-amd-commonjs-wrapper

v0.0.4

Published

Convert AMD Modules with declared dependencies into the Simplified CommonJS Wrapper style

Downloads

4

Readme

grunt-amd-commonjs-wrapper

Convert a normal amd module to the simplified commonjs style amd module

What problem does this solve?

Specifying all the dependencies in an array, then receiving them in a callback makes it very difficult for a linter to detect unused dependencies. This in turn makes it hard to detect if files aren't being built into any requirejs build files.

require(['dep1', 'dep2', 'dep3'], function (dep1, dep2, dep3) {
    // dep1 and dep2 are unused, but this will pass lint
    return dep3;
});

When to use?

This is the opposite of most grunt tasks that you'd use as part of your build, in that it (hopefully) makes your code more readable and easy to lint. This means that you're only likely to use it a single time to convert the style of a huge project.

In addition, some people prefer writing their modules in the commonjs style (especially if you want to run your code in node as well). Once you've used this task to convert your modules, you could even just strip off the outer define call and re-add it at build time with something like grunt-amd-wrap.

Examples

define(['dep1', 'dep2'], function (var1, var2) {
    return var1 + var2;
});

becomes

define(function (require, exports, module) {
    var var1 = require('dep1');
    var var2 = require('dep2');
    return var1 + var2;
});

#####supports variable-less dependencies

define(['dep1', 'dep2'], function () {
});

becomes

define(function (require, exports, module) {
    require('dep1');
    require('dep2');
});

#####supports named modules

define('modulename', ['dep'], function () {
});

becomes

define('modulename', function (require, exports, module) {
    require('dep');
});

#####supports 'use strict'

define('modulename', ['dep'], function () {
    'use strict';
});

becomes

define('modulename', function (require, exports, module) {
    'use strict';
    require('dep');
});

#####leaves commonjs wrapper modules alone

define('modulename', function (require, exports, module) {
    'use strict';
});

remains

define('modulename', function (require, exports, module) {
    'use strict';
});

Whitespace Warning

There is an attempt to match the indentation of the rest of the file, but its far from perfect. Might upset your linter.

Relative Path Warning

If you're using paths not declared in your requirejs config file, then this will probably break all your paths. This is due to the commonjs style require statements using relative paths, rather than making all paths relative to your requirejs config baseUrl setting.