asmcrypto / asmcrypto.js

JavaScript Cryptographic Library with performance in mind.
MIT License
660 stars 182 forks source link

Replaced forced global variable with UMD #83

Closed antelle closed 8 years ago

antelle commented 9 years ago

Thanks for such great project! I have replaced global asmCrypto variable with UMD (Universal Module Definition) pattern, so the library could be accessible in node.js with:

var asmCrypto = require('asmcrypto');

Now require returns nothing and requiring this file results with adding asmCrypto variable to global space. This is very unusual behavior for node.js modules. Also this patch fixes behavior for AMD module systems (like require.js).

antelle commented 9 years ago

It seems that the build is failing because of a problem connecting to sauce labs: there's no failed test in displayed results.

vibornoff commented 9 years ago

Seems umd breaks sourcemaps:

grunt.registerTask('default', ['sources','concat','umd','uglify']);
grunt.registerTask('devel', ['sources','concat','umd','connect','watch']);

Makes asmcrypto.js to look like:

(function (root, factory) {
  if (typeof define === 'function' && define.amd) {
    // AMD. Register as an anonymous module unless amdModuleId is set
    define([], function () {
      return (root['exports'] = factory());
    });
  } else if (typeof exports === 'object') {
    // Node. Does not work with strict CommonJS, but
    // only CommonJS-like environments that support module.exports,
    // like Node.
    module.exports = factory();
  } else {
    root['asmCrypto'] = factory();
  }
}(this, function () {

/*! asmCrypto, (c) 2013 Artem S Vybornov, opensource.org/licenses/MIT */
...

})( {}, function(){return this}() );
//# sourceMappingURL=asmcrypto.js.map
return exports;

}));

Sourcemaps must be adjusted by umd somehow.

/me googling for now...

EDIT: Maybe it worth to get rid of grunt-umd and just add umd header and footer statically?

antelle commented 9 years ago

Thanks for notice. I have updated this PR and replaced the task with insertion from footer within gruntfile, this should work for now. I have checked unit tests and loading from node.js. Also copyright is now inserted into correct position, to the top of file.