Skip to content

Releases: gfranko/amdclean

New config option, updated prefixTransform, and fixed Regression Bug

08 Oct 17:03
Compare
Choose a tag to compare

Examples

onModuleBundleComplete: function (data) {
  var fs = module.require('fs'),
    amdclean = module.require('amdclean'),
    outputFile = data.path,
    cleanedCode = amdclean.clean({
        'filePath': outputFile,
        'config': {
            'test': {
                'size': 'large'
            }
        }
    });

  fs.writeFileSync(outputFile, cleanedCode);
}

//test.js, which uses simplified CJS wrapping:
//http://requirejs.org/docs/whyamd.html#sugar
define(function (require, exports, module) {
    //Will be the value 'large'
    var size = module.config().size;
});

//test.js which uses a dependency array,
//it asks for the special module ID, 'module':
//https://github.com/jrburke/requirejs/wiki/Differences-between-the-simplified-CommonJS-wrapper-and-standard-AMD-define#wiki-magic
define(['module'], function (module) {
    //Will be the value 'large'
    var size = module.config().size;
});
  • Updated the prefixTransform option to pass BOTH post normalized and pre normalized module names #59
  'prefixTransform': function(postNormalizedModuleName, preNormalizedModuleName) {
    return postNormalizedModuleName;
  }
  • Fixed a regression bug that did not correctly catch all conditional AMD statements #61

Bug Fix - #50

16 Jun 01:48
Compare
Choose a tag to compare

Fixed #50 - Make sure an uninitialized variable does not cause AMDclean to error.

Bug Fixes

13 Jun 07:57
Compare
Choose a tag to compare

This release was focused solely on fixing any remaining issues with projects that depend on many third-party dependencies. #49

Bug Fixes

06 Jun 20:17
Compare
Choose a tag to compare
  • No longer removes black listed parameter names unless the module is CommonJS. This was required to get the Require.js text plugin to work, since the text plugin has a parameter named module, which was black listed (removed) by AMDclean
  • Fixed the optimization of dependencies when the dependencies are more than the number of callback parameters

Complete Rewrite, CommonJS Support, New Option, Multiple Enhancements, Bug Fixes

06 Jun 16:49
Compare
Choose a tag to compare

Complete Rewrite

  • AMDclean has been completely rewritten using... AMDclean. Yes, that's right; AMDclean is it's own user. Check out the source for yourself.

CommonJS Support

  • AMDclean now provides full-fledged CommonJS support by working in conjunction with the Require.js cjsTranslate option. #45
  • The only caveat is that the Require.js filesystem lookup is still used (sorry npm and node_modules fanboys)

New Option

  • The createAnonymousAMDModule has been added, to easily allow library authors to expose an anonymous AMD module instead of always a named AMD module. If you would like to use it, you need to make sure to set the createAnonymousAMDModule option to true (it is false by default).

Multiple Enhancements

  • Make sure to not strip out callback function parameters unless the advancedOptimizations option is set to true (helps with debugging) #44
  • Make sure to still optimize a module even if there is one dependency. The important thing to check for is what is inside the callback function. #43
  • Make sure to not clean optional define() wrappers, that are inside of conditional AMD checks, when the transformAMDChecks option is set to true. Very important for library development. #46
  • Change the default wrap AMDclean option to be:
'wrap': {
  'start': ';(function() {',
  'end': '}());'
}

Reason: Lot's of people are using the Require.js wrap option and becoming confused why all modules are being declared in the global scope. #47

  • Wrap a conditional ternary operator around the module return value of scripts. #48 D3 example:
if (true) {
  d3 = function () {
    return typeof d3 === 'function' ? d3() : d3;
  }();
}

Bug Fixes

  • Comments outside of your modules are no longer being removed. This has been an annoying issue.
  • Optimized modules, that return a function, do not have their function arguments hoisted by accident

Optimizations

12 May 07:28
Compare
Choose a tag to compare

Upgrading to 2.0

  • Please make sure you are using the onModuleBundleComplete Require.js hook and NOT the onBuildWrite Require.js hook. The onBuildWrite hook has been deprecated for AMDclean versions >= 2.0.
  • The globalObject and globalObjectName options have been removed, since all modules are now hoisted to the top of a file.

Optimizations

AMDclean now uses a few different strategies to decrease file size:

Remove Unused Dependencies

AMD

define('example', ['example1', 'example2'], function() {
    var test = true;
});

Standard

// Since no callback parameters were provided in the AMD code,
// the 'example1' and 'example2' parameters were removed
var example;
example = function() {
    var test = true;
}();

Remove Exact Matching Dependencies

AMD

define('example', ['example1', 'example2'], function(example1, anotherExample) {
    var test = true;
});

Standard

// Since the `example1` callback function parameter exactly matched
// the name of the `example1 dependency, it's parameters were removed
var example;
example = function(anotherExample) {
    var test = true;
}(example2);

Hoist Common Non-Matching Dependencies

  • Note - For this behavior, you must set the aggressiveOptimizations option to true

AMD

define('example', ['example1'], function(firstExample) {
    var test = true;
});
define('anotherExample', ['example1'], function(firstExample) {
    var test = true;
});

Standard

// Since the `firstExample` callback function parameter was used more
// than once between modules, it was hoisted up and reused
var example, firstExample;
firstExample = example1;
example = function() {
    var test = true;
};
anotherExample = function() {
    var test = true;
};

UMD Fixes, transformAMDChecks option, Minor Optimizations,

18 Mar 03:31
Compare
Choose a tag to compare

UMD Factory Function Support

This:

(function (factory) {
    if (typeof exports === 'object') {
        module.exports = factory(require('backbone'), require('underscore'));
    } else if (typeof define === 'function' && define.amd) {
        define(['backbone', 'underscore'], factory);
    }
}(function (Backbone, _) {
    Backbone.Validation = (function(_){/*plugin logic*/}(_));
    return Backbone.Validation;
}));

Get's Converted To:

(function (factory) {
        if (typeof exports === 'object') {
            module.exports = factory(amdclean['backbone'], amdclean['underscore']);
        } else if (true) {
            amdclean['backbonevalidation'] = function (backbone, underscore) {
                return factory(backbone, underscore);
            }(amdclean['backbone'], amdclean['underscore']);
        }
    }(function (Backbone, _) {
        Backbone.Validation = (function(_){/*plugin logic*/}(_));
        return Backbone.Validation;
}));

New transformAMDChecks Option

If set to false, no conditional AMD checks will be transformed. This is a very helpful option for library authors.

Minor Optimizations

Callback parameters are no longer specified unnecessarily.

Comments Are No Longer Being Stripped

17 Mar 00:37
Compare
Choose a tag to compare

Comments are no longer getting removed inside of module definitions.

AMD Code

// Comment above the module declaration
define('example', function () {
    // Comment inside the module declaration
    var example;
});

Standard JavaScript Code

// Comment above the module declaration
var example = function () {
    // Comment inside the module declaration
    var example;
}();

Relative File Path Dependencies and CommonJS Require Includes

04 Mar 01:44
Compare
Choose a tag to compare

Relative File Path Dependencies

You can now use relative file paths (as many levels deep as you like) for your AMD dependencies, and they will work as expected. Special thanks to rstone770 for contributing this.

Check out this example:

AMD

define('./modules/example', [
  './example1',
  './example2',
  '../example3'
], function(one, two, three) {
  var test = true;
});

Standard JavaScript

var modules_example=function (one,two,three){
  var test=true;
}(modules_example1,modules_example2,example3);

CommonJS Require Includes with the Global Object Option

You can now use the CommonJS require() syntax with the globalObject option.

Check out this example:

AMD

var example = require('anotherModule');

Standard JavaScript

var amdclean={};
var example=amdclean['anotherModule'];

Fixed Escodegen AMD Web Bug

18 Feb 04:13
Compare
Choose a tag to compare
  • Fixed Escodegen issue when used in an AMD Web environment