Skip to content

Releases: gfranko/amdclean

Bug Fixes and 4 New Options

18 Feb 03:51
Compare
Choose a tag to compare

Bug Fixes

  • Conditional AMD checks were always getting cleaned. #28

New Options

  • prefixMode - Allows you to decide whether you would like your module names normalized with underscores or the camel case convention
  • prefixTransform - Function hook that gives users full control to write their own logic for how module names are transformed. #26
  • removeModules - An array of module names that should be removed from the source (e.g. removing the RequireJS text! plugin from getting inlined) #29
  • wrap - Similar functionality to the RequireJS wrap option. This was added for web apps that use the globalObject AMDClean option and the onModuleBundleComplete RequireJS hook, but want the "global" object locally scoped. #31

Fixed Web Based Instances

12 Feb 21:49
Compare
Choose a tag to compare

Will now work correctly in web browsers (AMD or non-AMD)

New removeUseStricts Option and Minor Optimization Improvement

09 Feb 17:57
Compare
Choose a tag to compare

New removeUseStricts Option

  • All use strict statements from your cleaned modules will now be removed by default. If you would like to keep them, then you must turn the removeUseStricts option to false. Like this:
amdclean.clean({
  'code': 'define("example", function() { "use strict"; var example = true; })',
  'removeUseStricts': false
});

Optimization Improvement

  • There has been a minor optimization improvement that will convert empty module definitions to undefined. For example:

AMD

define('example', function() {
});

Standard

var example = undefined;

Stable and Ready

09 Feb 07:23
Compare
Choose a tag to compare

After a few more minor bug fixes, AMDClean is now at version 1.0! It is ready for prime time and is already being used on a number of production applications/libraries. Enjoy =)

Love, Greg

Optimization and Bug Fixes

09 Feb 05:17
Compare
Choose a tag to compare

The 0.7.0 AMDClean release includes significant improvements/optimizations to the transpiling intelligence and a few small bug fixes. This means that your files will be even smaller than before. We are closing in on a 1.0.0 release people...

Transpiling Optimizations

  • define() method transpiling has been dramatically optimized (#22). Here are a few examples:

AMD

define('example', [], function() {
  return function(name) {
    return 'Hello ' + name;
  };
});

Standard

var example = function (name) {
  return 'Hello ' + name;
};

AMD

define('example', [], function() {
  return 'I love AMDClean';
});

Standard

var example = 'I love AMDClean';

AMD

define('example', function () {
  'use strict';
  return function (thing) {
    return !isNaN(parseFloat(thing)) && isFinite(thing);
  };
});

Standard

var example = function (thing) {
  'use strict';
  return !isNaN(parseFloat(thing)) && isFinite(thing);
};

Comments No Longer Stripped

  • Source code comments will no longer be stripped by default (#23). If you would like comments to be stripped, then you can set the escodegen comment option to false. Like this:
amdclean.clean({
  'code': 'define("example", function() { });',
  'escodegen': { comment: false }
});

AMDClean for Web Apps

26 Jan 20:32
Compare
Choose a tag to compare

With the 0.6.0 release, AMDClean can now be reliably used to replace Almond.js in your web apps. Here are the changes that make this possible:

Converting Third-Party Libraries

Let's use jQuery as an example. In the jQuery source code, there is the following conditional AMD check to see if an AMD loader is being used:

// jQuery Source
if ( typeof define === "function" && define.amd ) {
    define( "jquery", [], function() {
        return jQuery;
    });
}

AMDClean will now transform the jQuery source to this:

if ( true ) {
var jquery = function () {
        return jQuery;
    }();
}

Before version 0.6.0, AMDClean would have left the AMD conditional if statement alone, and would not know the return value for the jquery module (causing a syntax error in your web app).

Correctly Transforming Define() Methods That Assume CommonJS support

Let's use the Esprima library as an example. Esprima uses the following syntax to conditionally check to see if an AMD loader is being used:

// Esprima Source
(function (root, factory) {
    'use strict';

    // Universal Module Definition (UMD) to support AMD, CommonJS/Node.js,
    // Rhino, and plain browser loading.
    if (typeof define === 'function' && define.amd) {
        define(['exports'], factory);
    } else if (typeof exports !== 'undefined') {
        factory(exports);
    } else {
        factory((root.esprima = {}));
    }
}(this, function (exports) {
  // Esprima source code
  // ...
  // Does not return anything
}));

In the above code example, Esprima is conditionally defining an anonymous AMD module by passing the function identifier, factory.

The factory function that is being passed does not return any value inside of its function body, and instead just assigns properties to its exports argument. It does this since it expects Require.js to automatically understand that it is using CommonJS syntax and to return the exports argument as the module return value.

With the 0.6.0 release, AMDClean is now smart enough to correctly transform this conditional AMD definition. Here is how AMDClean now transforms the above code:

(function (root, factory) {
    'use strict';

    // Universal Module Definition (UMD) to support AMD, CommonJS/Node.js,
    // Rhino, and plain browser loading.
    if (true) {
      var esprima = function (module) {
        return factory();
    }({});
    } else if (typeof exports !== 'undefined') {
        factory(exports);
    } else {
        factory((root.esprima = {}));
    }
}(this, function (exports) {
  exports = exports || {};
  // Esprima source code
  // ...
  // Returns exports
  return exports;
}));

Shimmed Library Support

17 Jan 07:37
Compare
Choose a tag to compare
  • Automatically clean shimmed libraries and provide new instructions using the onModuleBundleComplete config property.
  • Added the shimOverrides option that allows you to pass an expression to override shimmed module return values

New Options, Gulp.js Build, More Unit Tests, Updated Docs

13 Jan 05:42
Compare
Choose a tag to compare

Changelog:

  1. Integrated Gulp.js for the project build system.
  2. Automatically removed require method calls with empty callback function expressions
  3. Updated the contributing guide
  4. Added a new removeAllRequires option that will remove all require method calls from the code
  5. Added a new ignoreModules option that will ignore (not remove) specified AMD defined modules
  6. Added a new commentCleanName option that allows you to customize the comment text that will exclude certain modules from being cleaned
  7. Updated Jasmine unit tests
  8. Updated contributing guide

Bug Fixes

26 Nov 23:04
Compare
Choose a tag to compare

Simplified CJS, Global Object, Expose Global Modules, Bug Fixes

25 Nov 08:11
Compare
Choose a tag to compare

Enhancements

  • Simplified CJS support: #8
  • Added globalOption option to support scoping all local modules to one JavaScript object: #7
  • Added globalModules option to support making one or more local modules global on the window object: #12

Bug Fixes

  • Alias reserved words with an _ : #13 and #10
  • Allow $ and _ characters in module names : #16