diff --git a/package.json b/package.json new file mode 100644 index 0000000..e822467 --- /dev/null +++ b/package.json @@ -0,0 +1,23 @@ +{ + "name": "jschannel", + "version": "1.0.0", + "description": "A JavaScript library which implements fancy IPC semantics on top of postMessage.", + "main": "src/jschannel.js", + "directories": { + "doc": "docs", + "example": "example" + }, + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/mozilla/jschannel.git" + }, + "author": "", + "license": "MPL-1.1", + "bugs": { + "url": "https://github.com/mozilla/jschannel/issues" + }, + "homepage": "https://github.com/mozilla/jschannel#readme" +} diff --git a/src/jschannel.js b/src/jschannel.js index a4f6ba2..01b28ca 100644 --- a/src/jschannel.js +++ b/src/jschannel.js @@ -218,7 +218,7 @@ * the onReady function will be passed a single argument which is * the channel object that was returned from build(). */ - return { + var _channel = { build: function(cfg) { var debug = function(m) { if (cfg.debugOutput && window.console && window.console.log) { @@ -617,4 +617,19 @@ return obj; } }; + + if (typeof exports !== 'undefined') { + if (typeof module !== 'undefined' && module.exports) { + exports = module.exports = _channel; + } + exports.Channel = _channel; + } + + if (typeof define === 'function' && define.amd) { + define('jschannel', [], function() { + return _channel; + }); + } + + return _channel; })();