Permalink
Browse files

Merge branch 'master' of github.com:observing/square into development

Conflicts:
	lib/square.js
  • Loading branch information...
2 parents 5a21ab4 + c78d1d0 commit fcb79497ed2980b0faab6d9fa32ea085e39634e1 @3rd-Eden 3rd-Eden committed May 17, 2012
Showing with 54 additions and 18 deletions.
  1. +7 −2 bin/square
  2. +7 −4 lib/square.js
  3. +20 −4 plugins/update.js
  4. +20 −8 plugins/wrap.js
View
@@ -73,6 +73,7 @@ program
.option('-i, --ignore [files]', 'ignore these files', filters.list)
.option('-f, --filename <file>', 'alternate filenames', filters.list)
.option('-p, --plugin <plugins>', 'which plugins should be included', filters.list)
+ .option('-g, --group <groups>', 'which groups should be processed', filters.list)
.option('-l, --list', 'show a list of plugins');
/**
@@ -148,7 +149,7 @@ program.on('--watch', function watching (live) {
square.logger.notice('changes detected, refreshing %s', files.join(', '));
square.refresh(files);
- square.build(program.extension, function finished (changes) {
+ square.build(program.extension, program.group, function finished (changes) {
// check if we are listening for live changes, if so, emit the changes
if (!socket) return;
@@ -265,6 +266,10 @@ program.ignore = Array.isArray(program.ignore)
? program.ignore
: [];
+program.group = Array.isArray(program.group)
+ ? program.group
+ : [];
+
program.bundle = program.bundle || process.env.PWD;
program.plugin = Array.isArray(program.plugin)
@@ -342,5 +347,5 @@ found.on('end', function end () {
square.plugin(plugin);
});
- square.build(program.extension);
+ square.build(program.extension, program.group);
});
View
@@ -458,12 +458,14 @@ Square.prototype.directive = function directive (data, extension, seen) {
* Build the stuff.
*
* @param {String} extension
+ * @param {Array} groupsout
* @param {Function} fn
* @api public
*/
-Square.prototype.build = function build (extension, fn) {
- var self = this;
+Square.prototype.build = function build (extension, groupsout, fn) {
+ var self = this
+ , files = [];
// default arguments
extension = extension || 'js';
@@ -480,7 +482,6 @@ Square.prototype.build = function build (extension, fn) {
this.on('merge', function merged (collection) {
var layers = self.middleware.slice(0)
, errors = []
- , files = []
, groupCount = collection.groupCount || 1
, backup;
@@ -545,7 +546,8 @@ Square.prototype.build = function build (extension, fn) {
if (!this.stdout) this.write(collection, 'dev', doneGroup);
});
- return this.emit('build');
+ this.emit('build');
+ return this.merge(extension, groupsout);
};
/**
@@ -595,6 +597,7 @@ Square.prototype.tag = function tag (collection, type) {
return _.extend({
type: type || 'min'
, md5: createHash('md5').update(collection.content || '').digest('hex')
+ , group: collection.group
, branch: branch
, sha: sha
, ext: collection.extension || 'js'
View
@@ -110,7 +110,7 @@ module.exports = function setup (options) {
// fetch that update
provider(bundle.latest, configuration, function test (err, version, content) {
if (err) return cb(err);
- if (!version) return cb(new Error('unable to find and parse the version'));
+ if (!version) return cb(new Error('unable to find and parse the version for ' + key));
if (version === bundle.version) return cb();
self.logger.notice('%s is out of date, latest version is %s', key, version.green);
@@ -163,7 +163,15 @@ module.exports = function setup (options) {
exports.download(data, done);
});
- }, next);
+ }, function finished (err, data) {
+ if (err && err.forEach) {
+ err.forEach(function failed (err) {
+ self.logger.error(err);
+ });
+ }
+
+ next();
+ });
};
};
@@ -248,7 +256,13 @@ exports.selector = function fetch (uri, options, fn) {
exports.version = function search (content, options) {
var version;
- return [options.strict, options.loose].some(function some (regexp) {
+ // a "feature" of calling exec on a regexp with a global flag is that it
+ // renders it useless for new calls as it will do checks based on the new
+ // matches. We can bypass this behavior by recompiling regexps
+ [
+ new RegExp(options.strict.source)
+ , new RegExp(options.loose.source)
+ ].some(function some (regexp) {
var match = regexp.exec(content);
if (match && match.length) {
@@ -260,7 +274,9 @@ exports.version = function search (content, options) {
}
return !!version;
- }) ? version : null;
+ });
+
+ return version;
};
/**
View
@@ -4,14 +4,15 @@ var _ = require('underscore')._
, canihas = require('../lib/canihas');
/**
- * Attempts to detect leaking globals and provides a wrapper for it.
+ * Can wrap you compiled code and plurge the leaked globals.
*
* Options:
*
* - `timeout` time to wait for the script to be initialized, number in ms.
* - `header` first section of the leak prevention, string.
* - `body` content for the leak prevention function body, array.
* - `footer` closing section of th leak prevention, string.
+ * - `leaks` should we detect globals and patch it, boolean
*
* @param {Object} options
* @returns {Function} middleware
@@ -22,6 +23,7 @@ module.exports = function setup (options) {
var settings = {
timeout: 1000
, header: '(function (expose) {'
+ , leaks: true
, body: [
'this.contentWindow = this.self = this.window = this;'
, 'var window = this'
@@ -58,6 +60,11 @@ module.exports = function setup (options) {
var logger = this.logger
, timeout = configuration.timeout;
+ if (!configuration.leaks) {
+ output.content = configuration.header + output.content + configuration.footer;
+ return next(null, output);
+ }
+
// search for leaks
exports.sandboxleak(output.content, timeout, function found (err, leaks) {
if (err) {
@@ -125,7 +132,7 @@ module.exports = function setup (options) {
* @api private
*/
-module.exports.description = 'Tries to detect global leaks in your code and attempts to patch it.';
+module.exports.description = 'Can wrap you compiled code and plurge the leaked globals';
/**
* Detect leaking code.
@@ -138,6 +145,8 @@ module.exports.description = 'Tries to detect global leaks in your code and atte
exports.sandboxleak = function sandboxleak (content, timeout, fn) {
canihas.jsdom(function canihasJSDOM (err, jsdom) {
+ if (err) return err;
+
var html = '<html><body></body></html>'
, DOM = jsdom.jsdom;
@@ -151,15 +160,18 @@ exports.sandboxleak = function sandboxleak (content, timeout, fn) {
jsdom.env({
html: html
, src: [ content ]
+ , features: {
+ FetchExternalResources: false
+ }
, done: function done (err, window) {
- if (err) return fn(err);
+ var globals;
- var infected = Object.keys(window)
- , globals = _.difference(infected, regular);
-
- window.close();
+ if (window) {
+ globals = _.difference(Object.keys(window), regular);
+ window.close();
+ }
- fn(null, globals);
+ fn(err, globals);
}
});
});

0 comments on commit fcb7949

Please sign in to comment.