gfranko / amdclean

A build tool that converts AMD code to standard JavaScript
http://gregfranko.com/amdclean/
MIT License
449 stars 38 forks source link

Handling of knockoutJS fails to properly register library #74

Open purtuga opened 9 years ago

purtuga commented 9 years ago

KnockoutJS has (I think) an unusual way to register its self under AMD... its code looks like this (ref here):

// Support three module loading scenarios
    if (typeof require === 'function' && typeof exports === 'object' && typeof module === 'object') {
        // [1] CommonJS/Node.js
        var target = module['exports'] || exports; // module.exports is for Node.js
        factory(target, require);
    } else if (typeof define === 'function' && define['amd']) {
        // [2] AMD anonymous module
        define(['exports', 'require'], factory);
    } else {
        // [3] No module loader (plain <script> tag) - put directly in global namespace
        factory(window['ko'] = {});
    }

amdclean converts this to:

// Support three module loading scenarios
      if (typeof require === 'function' && typeof exports === 'object' && typeof module === 'object') {
        // [1] CommonJS/Node.js
        var target = module['exports'] || exports;
        // module.exports is for Node.js
        factory(target, require);
      } else if (true) {
        knockout = function (exports, require) {
          return typeof factory === 'function' ? factory(exports, require) : factory;
        }({}, {});
      } else {
        // [3] No module loader (plain <script> tag) - put directly in global namespace
        factory(window['ko'] = {});
      }

This however, does not register the module because the knockoutjs factory does not return anything - it simply adds its methods to the exports provided on input

Anyway I can fix this during the build process? or get around it?

Thanks in advance.

/Paul.

purtuga commented 9 years ago

Hi Greg, have you had a chance to look at this?