{"action":"created","issue":{"url":"https://api.github.com/repos/metafizzy/isotope/issues/959","labels_url":"https://api.github.com/repos/metafizzy/isotope/issues/959/labels{/name}","comments_url":"https://api.github.com/repos/metafizzy/isotope/issues/959/comments","events_url":"https://api.github.com/repos/metafizzy/isotope/issues/959/events","html_url":"https://github.com/metafizzy/isotope/issues/959","id":96212481,"number":959,"title":"Testing for CommonJs env different for EventEmitter","user":{"login":"mhkeller","id":498744,"avatar_url":"https://avatars.githubusercontent.com/u/498744?v=3","gravatar_id":"","url":"https://api.github.com/users/mhkeller","html_url":"https://github.com/mhkeller","followers_url":"https://api.github.com/users/mhkeller/followers","following_url":"https://api.github.com/users/mhkeller/following{/other_user}","gists_url":"https://api.github.com/users/mhkeller/gists{/gist_id}","starred_url":"https://api.github.com/users/mhkeller/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mhkeller/subscriptions","organizations_url":"https://api.github.com/users/mhkeller/orgs","repos_url":"https://api.github.com/users/mhkeller/repos","events_url":"https://api.github.com/users/mhkeller/events{/privacy}","received_events_url":"https://api.github.com/users/mhkeller/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-07-21T02:46:57Z","updated_at":"2015-07-21T17:14:01Z","closed_at":null,"body":"In most places, the library checks for a CommonJs environment by checking for `exports` like [the following](https://github.com/metafizzy/isotope/blob/feff43802bb689b3ab9d05855d8f3320640367a2/dist/isotope.pkgd.js#L224-L229)\r\n\r\n````js\r\nif ( typeof define === 'function' && define.amd ) {\r\n  // AMD\r\n  define( 'eventie/eventie',eventie );\r\n} else if ( typeof exports === 'object' ) {\r\n  // CommonJS\r\n  module.exports = eventie;\r\n} else {\r\n  // browser global\r\n  window.eventie = eventie;\r\n}\r\n`````\r\n\r\nFor `EventEmitter` it checks for `module` and `module.exports` [like this](https://github.com/metafizzy/isotope/blob/feff43802bb689b3ab9d05855d8f3320640367a2/dist/isotope.pkgd.js#L693-L704)\r\n\r\n````js\r\n    // Expose the class either via AMD, CommonJS or the global object\r\n    if (typeof define === 'function' && define.amd) {\r\n        define('eventEmitter/EventEmitter',[],function () {\r\n            return EventEmitter;\r\n        });\r\n    }\r\n    else if (typeof module === 'object' && module.exports){\r\n        module.exports = EventEmitter;\r\n    }\r\n    else {\r\n        exports.EventEmitter = EventEmitter;\r\n    }\r\n````\r\n\r\nI imagine this different style is just from how the [EventEmitter](https://github.com/Olical/EventEmitter) library that Isotope pulls from does it? \r\n\r\nThe problem this is causing is I'm packaging Isotope in an [Electron](http://github.com/atom/electron) app, which reads scripts in a CommonJs environment. This can cause some issues for libs like jQuery that detect their environment and load differently. A few workarounds are discussed here https://github.com/atom/electron/issues/254 \r\n\r\nThe main problem is that Isotope loads fine as a browser global since ` typeof exports === 'object'` is `false` in the electron environment, *except* it doesn't expose `EventEmitter` to itself since the check for that, `typeof module === 'object' && module.exports`, is `true`. \r\n\r\nIt could be that Electron isn't faithfully replicating the CommonJs environment. My solution for now is to fork the library and make sure that it loads `EventEmitter` as a browser global unless there are better suggestions or this is a candidate to be standardized."},"comment":{"url":"https://api.github.com/repos/metafizzy/isotope/issues/comments/123406074","html_url":"https://github.com/metafizzy/isotope/issues/959#issuecomment-123406074","issue_url":"https://api.github.com/repos/metafizzy/isotope/issues/959","id":123406074,"user":{"login":"Olical","id":315229,"avatar_url":"https://avatars.githubusercontent.com/u/315229?v=3","gravatar_id":"","url":"https://api.github.com/users/Olical","html_url":"https://github.com/Olical","followers_url":"https://api.github.com/users/Olical/followers","following_url":"https://api.github.com/users/Olical/following{/other_user}","gists_url":"https://api.github.com/users/Olical/gists{/gist_id}","starred_url":"https://api.github.com/users/Olical/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Olical/subscriptions","organizations_url":"https://api.github.com/users/Olical/orgs","repos_url":"https://api.github.com/users/Olical/repos","events_url":"https://api.github.com/users/Olical/events{/privacy}","received_events_url":"https://api.github.com/users/Olical/received_events","type":"User","site_admin":false},"created_at":"2015-07-21T17:14:01Z","updated_at":"2015-07-21T17:14:01Z","body":"I'm not totally sure about swapping to global UMD though. That seems pretty dangerous. Could quite easily override someone else's global property."}}