Skip to content

Commit

Permalink
put the AMD definitions before the commonjs - some build tools expose…
Browse files Browse the repository at this point in the history
… am exports object
  • Loading branch information
phated committed Jun 18, 2013
1 parent d20873c commit 992cc0d
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 26 deletions.
8 changes: 4 additions & 4 deletions commonjsStrict.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
// the top function.

(function (root, factory) {
if (typeof exports === 'object') {
// CommonJS
factory(exports, require('b'));
} else if (typeof define === 'function' && define.amd) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['exports', 'b'], factory);
} else if (typeof exports === 'object') {
// CommonJS
factory(exports, require('b'));
} else {
// Browser globals
factory((root.commonJsStrict = {}), root.b);
Expand Down
8 changes: 4 additions & 4 deletions commonjsStrictGlobal.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
// in the browser, it will create a global .b that is used below.

(function (root, factory) {
if (typeof exports === 'object') {
// CommonJS
factory(exports, require('b'));
} else if (typeof define === 'function' && define.amd) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['exports', 'b'], function (exports, b) {
factory((root.commonJsStrictGlobal = exports), b);
});
} else if (typeof exports === 'object') {
// CommonJS
factory(exports, require('b'));
} else {
// Browser globals
factory((root.commonJsStrictGlobal = {}), root.b);
Expand Down
8 changes: 4 additions & 4 deletions jqueryPluginCommonjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
// not want to add the extra CommonJS detection.

(function (factory) {
if (typeof exports === 'object') {
// Node/CommonJS
factory(require('jquery'));
} else if (typeof define === 'function' && define.amd) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['jquery'], factory);
} else if (typeof exports === 'object') {
// Node/CommonJS
factory(require('jquery'));
} else {
// Browser globals
factory(jQuery);
Expand Down
16 changes: 8 additions & 8 deletions returnExports.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
// the top function.

(function (root, factory) {
if (typeof exports === 'object') {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['b'], factory);
} else if (typeof exports === 'object') {
// Node. Does not work with strict CommonJS, but
// only CommonJS-like enviroments that support module.exports,
// like Node.
module.exports = factory(require('b'));
} else if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['b'], factory);
} else {
// Browser globals (root is window)
root.returnExports = factory(root.b);
Expand All @@ -39,14 +39,14 @@

// if the module has no dependencies, the above pattern can be simplified to
(function (root, factory) {
if (typeof exports === 'object') {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(factory);
} else if (typeof exports === 'object') {
// Node. Does not work with strict CommonJS, but
// only CommonJS-like enviroments that support module.exports,
// like Node.
module.exports = factory();
} else if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(factory);
} else {
// Browser globals (root is window)
root.returnExports = factory();
Expand Down
12 changes: 6 additions & 6 deletions returnExportsGlobal.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@
// in the browser, it will create a global .b that is used below.

(function (root, factory) {
if (typeof exports === 'object') {
// Node. Does not work with strict CommonJS, but
// only CommonJS-like enviroments that support module.exports,
// like Node.
module.exports = factory(require('b'));
} else if (typeof define === 'function' && define.amd) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['b'], function (b) {
return (root.returnExportsGlobal = factory(b));
});
} else if (typeof exports === 'object') {
// Node. Does not work with strict CommonJS, but
// only CommonJS-like enviroments that support module.exports,
// like Node.
module.exports = factory(require('b'));
} else {
// Browser globals
root.returnExportsGlobal = factory(root.b);
Expand Down

0 comments on commit 992cc0d

Please sign in to comment.