Skip to content

Commit

Permalink
CommonJS-compatible wrapper for dists
Browse files Browse the repository at this point in the history
For non-node builds, wrap the dist code in an anonymous function. For
client-side CommonJS builds, set var io = module.exports.
  • Loading branch information
jdahlq committed May 3, 2012
1 parent 6062a06 commit cceafcc
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion bin/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@ var baseTransports = {
]
};

/**
* Wrappers for client-side usage.
* This enables usage in both top-level browser window and client-side CommonJS systems.
* If doing a node build for server-side client, this wrapper is NOT included.
* @api private
*/
var wrapperPre = "\nvar io = ('undefined' === typeof module ? {} : module.exports);\n(function() {\n";
var wrapperPost = "\n})();";

/**
* Builds a custom Socket.IO distribution based on the transports that you
* need. You can configure the build to create development build or production
Expand Down Expand Up @@ -168,10 +177,14 @@ var builder = module.exports = function () {
// we are done, did we error?
if (error) return callback(error);

// concatinate the file contents in order
// start with the license header
var code = development
, ignore = 0;

// pre-wrapper for non-server-side builds
if (!settings.node) code += wrapperPre;

// concatenate the file contents in order
files.forEach(function (file) {
code += results[file];
});
Expand All @@ -183,6 +196,9 @@ var builder = module.exports = function () {
});
}

// post-wrapper for non-server-side builds
if (!settings.node)code += wrapperPost;

code = activeXObfuscator(code);

// Search for conditional code blocks that need to be removed as they
Expand Down

0 comments on commit cceafcc

Please sign in to comment.