Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fixes problem with Date.now being overwritten and gets build with the…

… exceptions of templates and special types to work
  • Loading branch information...
commit dbdd02fae942c491cc26634f03956061367950f4 1 parent b787f17
Justin Meyer justinbmeyer authored
3  build/apps/apps.js
View
@@ -195,7 +195,8 @@ steal('steal','steal/build/js','steal/build/css',function( steal ) {
file.appNames.push(appName);
}
steel.dependencies.forEach(function(dependency){
- if ( dependency.dependencies &&
+ // TODO: check status
+ if (dependency && dependency.dependencies &&
// don't follow functions
dependency.options.buildType != 'fn' &&
!dependency.options.ignore) {
23 build/js/js.js
View
@@ -41,7 +41,13 @@ steal('steal','steal/build/css',function( steal ) {
// seperate out css and js
exclude = exclude || [];
var jses = [],
- csses = [];
+ csses = [],
+ lineMap = {},
+ lineNum = 0,
+ numLines = function(text){
+ var matches = text.match(/\n/g);
+ return matches? matches.length + 1 : 1
+ };
// if even one file has compress: false, we can't compress the whole package at once
var canCompressPackage = true;
@@ -55,7 +61,12 @@ steal('steal','steal/build/css',function( steal ) {
if(file.buildType == 'js'){
var source = steal.build.js.clean(file.text);
if(file.minify !== false){
- source = steal.build.js.minify(source);
+ try{
+ source = steal.build.js.minify(source);
+ } catch(error){
+ print("ERROR minifying "+file.id+"\n"+error.err)
+ }
+
}
file.text = source;
}
@@ -108,16 +119,22 @@ steal('steal','steal/build/css',function( steal ) {
// add dependencies
code.push.apply(code, dependencyCalls);
+
+ lineNum += code.length
// add js code
jses.forEach(function(file){
+
code.push( file.text, "steal.executed('"+file.id+"')" );
+ lineMap[lineNum] = file.id+"";
+ var linesCount = numLines(file.text)+1;
+ lineNum += linesCount;
});
var jsCode = code.join(";\n") + "\n";
if(canCompressPackage){
jsCode = steal.build.js.clean(jsCode);
- jsCode = steal.build.js.minify(jsCode);
+ jsCode = steal.build.js.minify(jsCode,{currentLineMap: lineMap});
}
var csspackage = steal.build.css.makePackage(csses, cssPackage);
40 build/js/jsminify.js
View
@@ -51,7 +51,9 @@ steal('steal','steal/parse',function(steal, parse){
* - quiet - should the compression happen w/o errors
* - compressor - which minification engine, defaults to localClosure
* - currentLineMap - a map of lines to JS files, used for error reporting when minifying
- * several files at once.
+ * several files at once. EX:
+ *
+ * {0: "foo.js", 100: "bar.js"}
*/
js.minify = function(source, options){
// return source;
@@ -161,31 +163,37 @@ steal('steal','steal/parse',function(steal, parse){
// if there's an error, go through the lines and find the right location
if( /ERROR/.test(options.err) ){
if (!currentLineMap) {
- print(options.err)
+ throw options
}
else {
-
+ print("HOLLER")
var errMatch;
while (errMatch = /\:(\d+)\:\s(.*)/g.exec(options.err)) {
+
var lineNbr = parseInt(errMatch[1], 10),
- found = false,
- item,
- lineCount = 0,
- i = 0,
realLine,
error = errMatch[2];
- while (!found) {
- item = currentLineMap[i];
- lineCount += item.lines;
- if (lineCount >= lineNbr) {
- found = true;
- realLine = lineNbr - (lineCount - item.lines);
+
+ var lastNum, lastId;
+ print(lineNbr);
+ for( var lineNum in currentLineMap ) {
+ if( lineNbr < parseInt( lineNum) ){
+ break;
}
- i++;
+ print("checked "+lineNum+" "+currentLineMap[lineNum])
+ lastNum = parseInt(lineNum);
+ lastId = currentLineMap[lineNum];
}
- steal.print('ERROR in ' + item.src + ' at line ' + realLine + ': ' + error + '\n');
- var text = readFile(item.src), split = text.split(/\n/), start = realLine - 2, end = realLine + 2;
+ realLine = lineNbr - lastNum;
+
+ steal.print('ERROR in ' + lastId + ' at line ' + realLine + ': ' + error + '\n');
+
+
+ var text = readFile(lastId),
+ split = text.split(/\n/),
+ start = realLine - 2,
+ end = realLine + 2;
if (start < 0)
start = 0;
if (end > split.length - 1)
34 build/open/open.js
View
@@ -26,7 +26,7 @@ steal('steal',function(s){
// }
// }
while(i < depends.length){
- if(depends[i].waits){
+ if(depends[i] === null || depends[i].waits){
// once we found something like this ...
// if(includeFns){
// var steals = depends.splice(0,i+1),
@@ -79,13 +79,16 @@ steal('steal',function(s){
},
touch = function(steals, CB){
for(var i =0; i < steals.length; i++){
- var uniqueId = steals[i].options.id;
- //print(" Touching "+uniqueId )
- if(!touched[uniqueId]){
- CB( steals[i] );
- touched[uniqueId] = true;
+ if(steals[i]){
+ var uniqueId = steals[i].options.id;
+ //print(" Touching "+uniqueId )
+ if(!touched[uniqueId]){
+ CB( steals[i] );
+ touched[uniqueId] = true;
+ }
}
+
}
},
eachSteal = function(steals, CB, depth, includeFns){
@@ -140,9 +143,9 @@ steal('steal',function(s){
* @return {Object} an object with properties that makes extracting
* the content for a certain tag slightly easier.
*/
- steal.build.open = function( url, stealData, cb, depth, includeFns ) {
+ s.build.open = function( url, stealData, cb, depth, includeFns ) {
// save and remove the old steal
- var oldSteal = window.steal || steal,
+ var oldSteal = s,
// new steal is the steal opened
newSteal;
@@ -219,12 +222,12 @@ steal('steal',function(s){
}
var items = [];
// iterate
- iterate(rootSteal, function(stealer){
+ iterate(rootSteal, function(resource){
- if( filter(stealer) ) {
- stealer.options.text = stealer.options.text || loadScriptText(stealer);
- func(stealer.options, stealer );
- items.push(stealer.options);
+ if( filter(resource) ) {
+ resource.options.text = resource.options.text || loadScriptText(resource);
+ func(resource.options, resource );
+ items.push(resource.options);
}
}, depth, includeFns );
},
@@ -273,8 +276,9 @@ steal('steal',function(s){
steal.build.open.firstSteal =function(rootSteal){
var stel;
for(var i =0; i < rootSteal.dependencies.length; i++){
- stel = rootSteal.dependencies[i]
- if(stel.options.buildType != 'fn' && stel.options.id != 'steal/dev/dev.js' && stel.options.id != 'stealconfig.js'){
+ stel = rootSteal.dependencies[i];
+
+ if(stel && stel.options.buildType != 'fn' && stel.options.id != 'steal/dev/dev.js' && stel.options.id != 'stealconfig.js'){
return stel;
}
}
8 buildjs
View
@@ -1,10 +1,10 @@
load("steal/rhino/rhino.js");
-steal('steal/build',
+steal('steal','steal/build',
'steal/build/js',
'steal/build/css',
'steal/build/apps',
-function () {
+function (s) {
//check if args
var urls = [];
while (_args.length) {
@@ -16,9 +16,9 @@ function () {
}
if (urls.length > 1) {
- steal.build.apps(urls);
+ s.build.apps(urls);
} else {
- steal.build(urls[0], _args);
+ s.build(urls[0], _args);
}
});
6 dev/dev.js
View
@@ -50,7 +50,8 @@ steal.dev = {
* @param {String} out the message
*/
warn: function( out ) {
- if(steal.options.logLevel < 2){
+ var ll = steal.config().logLevel;
+ if(ll < 2){
Array.prototype.unshift.call(arguments, 'steal.js WARN:');
if ( window.console && console.warn ) {
this._logger( "warn", Array.prototype.slice.call(arguments) );
@@ -70,7 +71,8 @@ steal.dev = {
* @param {String} out the message
*/
log: function( out ) {
- if (steal.options.logLevel < 1) {
+ var ll = steal.config().logLevel;
+ if (ll < 1) {
if (window.console && console.log) {
Array.prototype.unshift.call(arguments, 'steal.js INFO:');
this._logger( "log", Array.prototype.slice.call(arguments) );
41 rhino/env.js
View
@@ -57,7 +57,7 @@ Envjs.reportError = function(e, fn){
console.log("-"+name+
new Array(max-name.length).join(" ")+
" = "+
- (""+e[name]).split("\n").join(space) );
+ (""+(typeof e[name] === "function" ? e[name]() : e[name] ) ).split("\n").join(space) );
}
if(typeof fn === 'string'){
var args = [space+fn];
@@ -406,11 +406,17 @@ Envjs.loadLocalScript = function(script){
xhr.onreadystatechange = function(){
//console.log("readyState %s", xhr.readyState);
if(xhr.readyState === 4){
- Envjs.eval(
- script.ownerDocument.ownerWindow,
- xhr.responseText,
- filename
- );
+ try {
+ Envjs.eval(
+ script.ownerDocument.ownerWindow,
+ xhr.responseText,
+ filename
+ );
+ } catch (e) {
+ console.log("could not load script %s \n %s", filename, e );
+ Envjs.onScriptLoadError(script, e);
+ }
+
}
};
xhr.send(null, false);
@@ -6743,7 +6749,7 @@ __extend__(Document.prototype, DocumentEvent.prototype);
*/
//CLOSURE_START
-(function(){
+(function(Date){
@@ -6755,7 +6761,10 @@ __extend__(Document.prototype, DocumentEvent.prototype);
//private
var $timers = [],
- EVENT_LOOP_RUNNING = false;
+ EVENT_LOOP_RUNNING = false,
+ getNow = function(){
+ return new Date().getTime()
+ };
$timers.lock = function(fn){
Envjs.sync(fn)();
@@ -6777,7 +6786,7 @@ Envjs.clear = function(){
var Timer = function(fn, interval){
this.fn = fn;
this.interval = interval;
- this.at = Date.now() + interval;
+ this.at = getNow() + interval;
// allows for calling wait() from callbacks
this.running = false;
};
@@ -6896,7 +6905,7 @@ clearInterval = clearTimeout = function(num){
Envjs.wait = function(wait) {
//console.log('wait %s', wait);
var delta_wait,
- start = Date.now(),
+ start = getNow(),
was_running = EVENT_LOOP_RUNNING;
if (wait < 0) {
@@ -6905,7 +6914,7 @@ Envjs.wait = function(wait) {
}
EVENT_LOOP_RUNNING = true;
if (wait !== 0 && wait !== null && wait !== undefined){
- wait += Date.now();
+ wait += getNow();
}
var earliest,
@@ -6938,7 +6947,7 @@ Envjs.wait = function(wait) {
}
});
//next sleep time
- sleep = earliest && earliest.at - Date.now();
+ sleep = earliest && earliest.at - getNow();
/*console.log('timer loop earliest %s sleep %s', earliest, sleep);*/
if ( earliest && sleep <= 0 ) {
nextfn = earliest.fn;
@@ -6952,7 +6961,7 @@ Envjs.wait = function(wait) {
earliest.running = false;
}
goal = earliest.at + earliest.interval;
- now = Date.now();
+ now = getNow();
if ( goal < now ) {
earliest.at = now;
} else {
@@ -6964,7 +6973,7 @@ Envjs.wait = function(wait) {
// bunch of subtle cases here ...
if ( !earliest ) {
// no events in the queue (but maybe XHR will bring in events, so ...
- if ( !wait || wait < Date.now() ) {
+ if ( !wait || wait < getNow() ) {
// Loop ends if there are no events and a wait hasn't been
// requested or has expired
break;
@@ -6976,7 +6985,7 @@ Envjs.wait = function(wait) {
//TODO: why waste a check on a tight
// loop if it just falls through?
// if they will happen within the next delta, fall through to sleep
- } else */if ( wait === 0 || ( wait > 0 && wait < Date.now () ) ) {
+ } else */if ( wait === 0 || ( wait > 0 && wait < getNow () ) ) {
// loop ends even if there are events but the user
// specifcally asked not to wait too long
break;
@@ -7004,7 +7013,7 @@ Envjs.wait = function(wait) {
* @license MIT
*/
//CLOSURE_END
-}());
+}(Date));
/*
* Pure JavaScript Browser Environment
* By John Resig <http://ejohn.org/> and the Envjs Team
79 steal.js
View
@@ -278,6 +278,7 @@
//
// whenEach(resources,"complete",resource,"execute")
var whenEach = function( arr, func, obj, func2 ) {
+
var deferreds = map(arr, func)
return Deferred.when.apply(Deferred, deferreds).then(function() {
if ( isFn(obj[func2]) ) {
@@ -286,23 +287,8 @@
obj[func2].resolve();
}
- })
- },
- // Used to call methods on multiple objects when
- // a single deferred is resolved:
- //
- // whenThe(resource,"complete",resources,"load")
- //
- // TODO: this might be no longer used
- whenThe = function( obj, func, items, func2 ) {
-
- each(items, function( i, item ) {
- Deferred.when(obj[func]).then(function() {
- item[func2]();
- })
- })
-
- };
+ });
+ };
// ## URI ##
/**
@@ -775,22 +761,9 @@
each: each,
extend: extend,
Deferred: Deferred,
+ // Currently used a few places
isRhino: win.load && win.readUrl && win.readFile,
/**
- * @attribute options
- * Configurable options
- */
- options: {
- env: "development",
- // TODO: document this
- loadProduction: true,
- needs: {
- less: "steal/less/less.js",
- coffee: "steal/coffee/coffee.js"
- },
- logLevel: 0
- },
- /**
* @hide
* Makes options
* @param {Object} options
@@ -1157,6 +1130,7 @@
}
}
},
+
// Calling complete indicates that all dependencies have
// been completed for this resource
complete: function() {
@@ -1202,7 +1176,7 @@
this.complete();
return;
}
-
+ //print("-setting up "+this.options.id)
// now we have to figure out how to wire up our pending steals
var self = this,
// the current
@@ -1213,14 +1187,14 @@
// iterate through the collection and add all the 'needs'
// before fetching...
each(myqueue, function( i, item ) {
-
- if ( isProduction && item.ignore ) {
- return;
- }
if( item === null){
stealInstances.push(null);
return
}
+ if ( isProduction && item.ignore ) {
+ return;
+ }
+
// make a steal object
var stel = Resource.make(item);
if ( packHash[stel.options.id] && stel.options.type !== 'fn' ) { // if we are production, and this is a package, mark as loading, but steal package?
@@ -1237,14 +1211,16 @@
stealInstances.push(Resource.make(function() {}), Resource.make(raw));
});*/
});
-
+ //print("-instances "+this.options.id)
// The set of resources before the previous "wait" resource
var priorSet = [],
// The current set of resources after and including the
// previous "wait" resource
set = [],
// The first set of resources that we will execute
- // right away
+ // right away. This should be the first set of dependencies
+ // that we can load in parallel. If something has
+ // a need, the need should be in this set
firstSet = [],
// Should we be adding resources to the
// firstSet
@@ -1278,10 +1254,11 @@
// if there are needs, this can not be part of the "firstSet"
each(stel.options.needs || [], function( i, raw ) {
var need= Resource.make(raw);
- need.execute()
waitsOn.push(need);
+ // add needs to first set to execute
+ firstSet.push(need)
});
- whenEach(waitsOn, "completed", stel, "execute");
+ waitsOn.length && whenEach(waitsOn, "completed", stel, "execute");
// what is this used for?
stel.waitedOn = stel.waitedOn ? stel.waitedOn.concat(priorSet) : priorSet.slice(0);
@@ -1849,18 +1826,20 @@
cur.executed();
};
- // if we are in rhino, start loading dependencies right away
+ // If we are in the browser, wait a
+ // brief timeout before executing the rootResource.
+ // This allows embeded script tags with steal to be part of
+ // the initial set
if ( win.setTimeout ) {
- // otherwise wait a small timeout to make
- // sure we get all steals in the current file
+ // we want to insert a "wait" after the current pending
var first = pending.slice(0);
pending = [];
setTimeout(function() {
-
- pending.unshift.apply(pending, first.concat([null]));
+ pending = first.concat(null,pending);
go();
}, 0)
} else {
+ // if we are in rhino, start loading dependencies right away
go()
}
}
@@ -1977,17 +1956,17 @@
// =========== DEBUG =========
-/*var name = function(stel){
+ /*var name = function(stel){
if(stel.options && stel.options.type == "fn"){
- return stel.orig.name? stel.orig.name : "fn";//(""+stel.orig).substr(0,10)
+ return stel.orig.name? stel.orig.name : stel.options.id+":fn";//(""+stel.orig).substr(0,10)
}
return stel.options ? stel.options.id + "": "CONTAINER"
}
- Resource.prototype.load = before( Resource.prototype.load, function(){
- console.log(" load", name(this), this.loading, steal._id, this.id)
- })
+ //Resource.prototype.load = before( Resource.prototype.load, function(){
+ // console.log(" load", name(this), this.loading, steal._id, this.id)
+ //})
Resource.prototype.executed = before(Resource.prototype.executed, function(){
var namer= name(this)
Please sign in to comment.
Something went wrong with that request. Please try again.