Skip to content

Commit

Permalink
Change dependency-resolving code so that modules work sensibly when c…
Browse files Browse the repository at this point in the history
…oncatenated with jsbuild.
  • Loading branch information
jcoglan committed Jan 5, 2013
1 parent 5c2be15 commit d41c913
Show file tree
Hide file tree
Showing 55 changed files with 131 additions and 115 deletions.
2 changes: 2 additions & 0 deletions bin/jsbuild
Expand Up @@ -33,6 +33,8 @@ var fs = require('fs'),
include = params.argv.remain.slice(), include = params.argv.remain.slice(),
dir = new RegExp('^' + path.resolve(params.directory || '.') + '/') dir = new RegExp('^' + path.resolve(params.directory || '.') + '/')


JSCLASS_PATH = path.dirname(__filename) + '/../src';

var C = require('../src/console').Console, var C = require('../src/console').Console,
P = require('../index') P = require('../index')


Expand Down
6 changes: 5 additions & 1 deletion index.js
@@ -1,4 +1,8 @@
var path = require('path'); var path = require('path'),
cleanup = (typeof JSCLASS_PATH === 'undefined');

JSCLASS_PATH = path.dirname(__filename) + '/src'; JSCLASS_PATH = path.dirname(__filename) + '/src';
module.exports = require(JSCLASS_PATH + '/loader'); module.exports = require(JSCLASS_PATH + '/loader');


if (cleanup) delete JSCLASS_PATH;

5 changes: 3 additions & 2 deletions source/benchmark.js
@@ -1,7 +1,8 @@
(function(factory) { (function(factory) {
var E = (typeof exports === 'object'), var E = (typeof exports === 'object'),
js = E ? require('./core') : JS, js = (typeof JS === 'undefined') ? require('./core') : JS,
Console = (E ? require('./console') : JS).Console;
Console = js.Console || require('./console').Console;


if (E) exports.JS = exports; if (E) exports.JS = exports;
factory(js, Console, E ? exports : js); factory(js, Console, E ? exports : js);
Expand Down
6 changes: 3 additions & 3 deletions source/command.js
@@ -1,9 +1,9 @@
(function(factory) { (function(factory) {
var E = (typeof exports === 'object'), var E = (typeof exports === 'object'),
js = E ? require('./core') : JS, js = (typeof JS === 'undefined') ? require('./core') : JS,


Enumerable = (E ? require('./enumerable') : js).Enumerable, Enumerable = js.Enumerable || require('./enumerable').Enumerable,
Observable = (E ? require('./observable') : js).Observable; Observable = js.Observable || require('./observable').Observable;


if (E) exports.JS = exports; if (E) exports.JS = exports;
factory(js, Enumerable, Observable, E ? exports : js); factory(js, Enumerable, Observable, E ? exports : js);
Expand Down
2 changes: 1 addition & 1 deletion source/comparable.js
@@ -1,6 +1,6 @@
(function(factory) { (function(factory) {
var E = (typeof exports === 'object'), var E = (typeof exports === 'object'),
js = E ? require('./core') : JS; js = (typeof JS === 'undefined') ? require('./core') : JS;


if (E) exports.JS = exports; if (E) exports.JS = exports;
factory(js, E ? exports : js); factory(js, E ? exports : js);
Expand Down
4 changes: 2 additions & 2 deletions source/console/_head.js
@@ -1,8 +1,8 @@
(function(factory) { (function(factory) {
var E = (typeof exports === 'object'), var E = (typeof exports === 'object'),
js = E ? require('./core') : JS, js = (typeof JS === 'undefined') ? require('./core') : JS,


Enumerable = (E ? require('./enumerable') : js).Enumerable; Enumerable = js.Enumerable || require('./enumerable').Enumerable;


if (E) exports.JS = exports; if (E) exports.JS = exports;
factory(js, Enumerable, E ? exports : js); factory(js, Enumerable, E ? exports : js);
Expand Down
2 changes: 1 addition & 1 deletion source/constant_scope.js
@@ -1,6 +1,6 @@
(function(factory) { (function(factory) {
var E = (typeof exports === 'object'), var E = (typeof exports === 'object'),
js = E ? require('./core') : JS; js = (typeof JS === 'undefined') ? require('./core') : JS;


if (E) exports.JS = exports; if (E) exports.JS = exports;
factory(js, E ? exports : js); factory(js, E ? exports : js);
Expand Down
11 changes: 6 additions & 5 deletions source/core/_head.js
@@ -1,15 +1,16 @@
<%= license %> <%= license %>


var JS = (typeof JS === 'undefined') ? {} : JS;

(function(factory) { (function(factory) {
var $ = (typeof this.global === 'object') ? this.global : this, var $ = (typeof this.global === 'object') ? this.global : this,
E = (typeof exports === 'object'); E = (typeof exports === 'object');


if (E) if (E) {
exports.JS = exports; exports.JS = exports;
else JS = exports;
$.JS = $.JS || {}; }

factory($, JS);
factory($, E ? exports : $.JS);


})(function(global, exports) { })(function(global, exports) {


5 changes: 3 additions & 2 deletions source/core/method.js
Expand Up @@ -81,7 +81,7 @@ JS.extend(JS.Method.prototype, {
return returnValue; return returnValue;
}; };


var StackTrace = ((typeof require === 'function') ? require('./stack_trace') : global.JS).StackTrace; var StackTrace = trace && (exports.StackTrace || require('./stack_trace').StackTrace);
if (trace) return StackTrace.wrap(compiled, method, environment); if (trace) return StackTrace.wrap(compiled, method, environment);
return compiled; return compiled;
}, },
Expand Down Expand Up @@ -134,7 +134,8 @@ JS.Method.keyword = function(name, filter) {
}; };


JS.Method.tracing = function(classes, block, context) { JS.Method.tracing = function(classes, block, context) {
global.JS.require('JS.StackTrace', function(StackTrace) { var pkg = exports.require ? exports : require('./loader');
pkg.require('JS.StackTrace', function(StackTrace) {
var logger = StackTrace.logger, var logger = StackTrace.logger,
active = logger.active; active = logger.active;


Expand Down
2 changes: 1 addition & 1 deletion source/decorator.js
@@ -1,6 +1,6 @@
(function(factory) { (function(factory) {
var E = (typeof exports === 'object'), var E = (typeof exports === 'object'),
js = E ? require('./core') : JS; js = (typeof JS === 'undefined') ? require('./core') : JS;


if (E) exports.JS = exports; if (E) exports.JS = exports;
factory(js, E ? exports : js); factory(js, E ? exports : js);
Expand Down
2 changes: 1 addition & 1 deletion source/deferrable.js
@@ -1,6 +1,6 @@
(function(factory) { (function(factory) {
var E = (typeof exports === 'object'), var E = (typeof exports === 'object'),
js = E ? require('./core') : JS; js = (typeof JS === 'undefined') ? require('./core') : JS;


if (E) exports.JS = exports; if (E) exports.JS = exports;
factory(js, E ? exports : js); factory(js, E ? exports : js);
Expand Down
2 changes: 1 addition & 1 deletion source/dom/_head.js
@@ -1,6 +1,6 @@
(function(factory) { (function(factory) {
var E = (typeof exports === 'object'), var E = (typeof exports === 'object'),
js = E ? require('./core') : JS; js = (typeof JS === 'undefined') ? require('./core') : JS;


if (E) exports.JS = exports; if (E) exports.JS = exports;
factory(js, E ? exports : js); factory(js, E ? exports : js);
Expand Down
2 changes: 1 addition & 1 deletion source/enumerable.js
@@ -1,6 +1,6 @@
(function(factory) { (function(factory) {
var E = (typeof exports === 'object'), var E = (typeof exports === 'object'),
js = E ? require('./core') : JS; js = (typeof JS === 'undefined') ? require('./core') : JS;


if (E) exports.JS = exports; if (E) exports.JS = exports;
factory(js, E ? exports : js); factory(js, E ? exports : js);
Expand Down
2 changes: 1 addition & 1 deletion source/forwardable.js
@@ -1,6 +1,6 @@
(function(factory) { (function(factory) {
var E = (typeof exports === 'object'), var E = (typeof exports === 'object'),
js = E ? require('./core') : JS; js = (typeof JS === 'undefined') ? require('./core') : JS;


if (E) exports.JS = exports; if (E) exports.JS = exports;
factory(js, E ? exports : js); factory(js, E ? exports : js);
Expand Down
6 changes: 3 additions & 3 deletions source/hash.js
@@ -1,9 +1,9 @@
(function(factory) { (function(factory) {
var E = (typeof exports === 'object'), var E = (typeof exports === 'object'),
js = E ? require('./core') : JS, js = (typeof JS === 'undefined') ? require('./core') : JS,


Enumerable = (E ? require('./enumerable') : js).Enumerable, Enumerable = js.Enumerable || require('./enumerable').Enumerable,
Comparable = (E ? require('./comparable') : js).Comparable; Comparable = js.Comparable || require('./comparable').Comparable;


if (E) exports.JS = exports; if (E) exports.JS = exports;
factory(js, Enumerable, Comparable, E ? exports : js); factory(js, Enumerable, Comparable, E ? exports : js);
Expand Down
5 changes: 3 additions & 2 deletions source/linked_list.js
@@ -1,7 +1,8 @@
(function(factory) { (function(factory) {
var E = (typeof exports === 'object'), var E = (typeof exports === 'object'),
js = E ? require('./core') : JS, js = (typeof JS === 'undefined') ? require('./core') : JS,
Enumerable = (E ? require('./enumerable') : js).Enumerable;
Enumerable = js.Enumerable || require('./enumerable').Enumerable;


if (E) exports.JS = exports; if (E) exports.JS = exports;
factory(js, Enumerable, E ? exports : js); factory(js, Enumerable, E ? exports : js);
Expand Down
2 changes: 1 addition & 1 deletion source/method_chain.js
@@ -1,6 +1,6 @@
(function(factory) { (function(factory) {
var E = (typeof exports === 'object'), var E = (typeof exports === 'object'),
js = E ? require('./core') : JS; js = (typeof JS === 'undefined') ? require('./core') : JS;


if (E) exports.JS = exports; if (E) exports.JS = exports;
factory(js, E ? exports : js); factory(js, E ? exports : js);
Expand Down
2 changes: 1 addition & 1 deletion source/observable.js
@@ -1,6 +1,6 @@
(function(factory) { (function(factory) {
var E = (typeof exports === 'object'), var E = (typeof exports === 'object'),
js = E ? require('./core') : JS; js = (typeof JS === 'undefined') ? require('./core') : JS;


if (E) exports.JS = exports; if (E) exports.JS = exports;
factory(js, E ? exports : js); factory(js, E ? exports : js);
Expand Down
7 changes: 5 additions & 2 deletions source/package/_head.js
Expand Up @@ -6,8 +6,11 @@ var JS = (typeof JS === 'undefined') ? {} : JS;
var $ = (typeof this.global === 'object') ? this.global : this, var $ = (typeof this.global === 'object') ? this.global : this,
E = (typeof exports === 'object'); E = (typeof exports === 'object');


if (E) exports.JS = exports; if (E) {
factory($, E ? exports : JS); exports.JS = exports;
JS = exports;
}
factory($, JS);


})(function(global, exports) { })(function(global, exports) {


4 changes: 2 additions & 2 deletions source/package/config.js
Expand Up @@ -97,8 +97,8 @@ P.packages(function() { with(this) {
'JS.OrderedSet', 'JS.OrderedSet',
'JS.SortedSet') 'JS.SortedSet')
.requires('JS.Class', .requires('JS.Class',
'JS.Enumerable') 'JS.Enumerable',
.uses( 'JS.Hash'); 'JS.Hash');


module('linked_list') .provides('JS.LinkedList', module('linked_list') .provides('JS.LinkedList',
'JS.LinkedList.Doubly', 'JS.LinkedList.Doubly',
Expand Down
2 changes: 1 addition & 1 deletion source/proxy.js
@@ -1,6 +1,6 @@
(function(factory) { (function(factory) {
var E = (typeof exports === 'object'), var E = (typeof exports === 'object'),
js = E ? require('./core') : JS; js = (typeof JS === 'undefined') ? require('./core') : JS;


if (E) exports.JS = exports; if (E) exports.JS = exports;
factory(js, E ? exports : js); factory(js, E ? exports : js);
Expand Down
6 changes: 3 additions & 3 deletions source/range.js
@@ -1,9 +1,9 @@
(function(factory) { (function(factory) {
var E = (typeof exports === 'object'), var E = (typeof exports === 'object'),
js = E ? require('./core') : JS, js = (typeof JS === 'undefined') ? require('./core') : JS,


Enumerable = (E ? require('./enumerable') : js).Enumerable, Enumerable = js.Enumerable || require('./enumerable').Enumerable,
Hash = (E ? require('./hash') : js).Hash; Hash = js.Hash || require('./hash').Hash;


if (E) exports.JS = exports; if (E) exports.JS = exports;
factory(js, Enumerable, Hash, E ? exports : js); factory(js, Enumerable, Hash, E ? exports : js);
Expand Down
6 changes: 3 additions & 3 deletions source/set.js
@@ -1,9 +1,9 @@
(function(factory) { (function(factory) {
var E = (typeof exports === 'object'), var E = (typeof exports === 'object'),
js = E ? require('./core') : JS, js = (typeof JS === 'undefined') ? require('./core') : JS,


Enumerable = (E ? require('./enumerable') : js).Enumerable, Enumerable = js.Enumerable || require('./enumerable').Enumerable,
hash = (E ? require('./hash') : js); hash = js.Hash ? js : require('./hash');


if (E) exports.JS = exports; if (E) exports.JS = exports;
factory(js, Enumerable, hash, E ? exports : js); factory(js, Enumerable, hash, E ? exports : js);
Expand Down
8 changes: 4 additions & 4 deletions source/stack_trace.js
@@ -1,10 +1,10 @@
(function(factory) { (function(factory) {
var E = (typeof exports === 'object'), var E = (typeof exports === 'object'),
js = E ? require('./core') : JS, js = (typeof JS === 'undefined') ? require('./core') : JS,


Observable = (E ? require('./observable') : js).Observable, Observable = js.Observable || require('./observable').Observable,
Enumerable = (E ? require('./enumerable') : js).Enumerable, Enumerable = js.Enumerable || require('./enumerable').Enumerable,
Console = (E ? require('./console') : js).Console; Console = js.Console || require('./console').Console;


if (E) exports.JS = exports; if (E) exports.JS = exports;
factory(js, Observable, Enumerable, Console, E ? exports : js); factory(js, Observable, Enumerable, Console, E ? exports : js);
Expand Down
2 changes: 1 addition & 1 deletion source/state.js
@@ -1,6 +1,6 @@
(function(factory) { (function(factory) {
var E = (typeof exports === 'object'), var E = (typeof exports === 'object'),
js = E ? require('./core') : JS; js = (typeof JS === 'undefined') ? require('./core') : JS;


if (E) exports.JS = exports; if (E) exports.JS = exports;
factory(js, E ? exports : js); factory(js, E ? exports : js);
Expand Down
18 changes: 9 additions & 9 deletions source/test/_head.js
@@ -1,15 +1,15 @@
(function(factory) { (function(factory) {
var E = (typeof exports === 'object'), var E = (typeof exports === 'object'),
js = E ? require('./core') : JS, js = (typeof JS === 'undefined') ? require('./core') : JS,


Console = (E ? require('./console') : js).Console, Console = js.Console || require('./console').Console,
DOM = (E ? require('./dom') : js).DOM, DOM = js.DOM || require('./dom').DOM,
Enumerable = (E ? require('./enumerable') : js).Enumerable, Enumerable = js.Enumerable || require('./enumerable').Enumerable,
SortedSet = (E ? require('./set') : js).SortedSet, SortedSet = js.SortedSet || require('./set').SortedSet,
Range = (E ? require('./range') : js).Range, Range = js.Range || require('./range').Range,
MethodChain = (E ? require('./method_chain') : js).MethodChain, MethodChain = js.MethodChain || require('./method_chain').MethodChain,
Comparable = (E ? require('./comparable') : js).Comparable, Comparable = js.Comparable || require('./comparable').Comparable,
StackTrace = (E ? require('./stack_trace') : js).StackTrace; StackTrace = js.StackTrace || require('./stack_trace').StackTrace;


if (E) exports.JS = exports; if (E) exports.JS = exports;
factory(js, Console, DOM, Enumerable, SortedSet, Range, MethodChain, Comparable, StackTrace, E ? exports : js); factory(js, Console, DOM, Enumerable, SortedSet, Range, MethodChain, Comparable, StackTrace, E ? exports : js);
Expand Down
5 changes: 3 additions & 2 deletions source/tsort.js
@@ -1,7 +1,8 @@
(function(factory) { (function(factory) {
var E = (typeof exports === 'object'), var E = (typeof exports === 'object'),
js = E ? require('./core') : JS, js = (typeof JS === 'undefined') ? require('./core') : JS,
Hash = (E ? require('./hash') : js).Hash;
Hash = js.Hash || require('./hash').Hash;


if (E) exports.JS = exports; if (E) exports.JS = exports;
factory(js, Hash, E ? exports : js); factory(js, Hash, E ? exports : js);
Expand Down
2 changes: 1 addition & 1 deletion test/console.js
Expand Up @@ -19,7 +19,7 @@ if (this.ActiveXObject) load = function(path) {
} }


if (typeof require === 'function') { if (typeof require === 'function') {
$.JS = require('../' + path + 'loader'); $.PKG = require('../' + path + 'loader');
require('./runner'); require('./runner');
} else { } else {
load(path + 'loader.js'); load(path + 'loader.js');
Expand Down
2 changes: 1 addition & 1 deletion test/examples/async.js
@@ -1,5 +1,5 @@
JSCLASS_PATH = "build/min/" JSCLASS_PATH = "build/min/"
require("../../" + JSCLASS_PATH + "loader") var JS = require("../../" + JSCLASS_PATH + "loader")


JS.require("JS.Test", "JS.MethodChain", function(Test, MC) { JS.require("JS.Test", "JS.MethodChain", function(Test, MC) {


Expand Down
2 changes: 1 addition & 1 deletion test/examples/benchmarks.js
Expand Up @@ -4,7 +4,7 @@
})() })()


if (typeof require === 'function') if (typeof require === 'function')
require('../../' + JSCLASS_PATH + 'loader') var JS = require('../../' + JSCLASS_PATH + 'loader')
else else
load(JSCLASS_PATH + 'loader.js') load(JSCLASS_PATH + 'loader.js')


Expand Down
2 changes: 1 addition & 1 deletion test/examples/reformat.js
Expand Up @@ -6,7 +6,7 @@
// $ node test/console -f json | node test/examples/reformat -f tap // $ node test/console -f json | node test/examples/reformat -f tap


JSCLASS_PATH = 'build/src' JSCLASS_PATH = 'build/src'
require('../../' + JSCLASS_PATH + '/loader') var JS = require('../../' + JSCLASS_PATH + '/loader')


JS.require('JS.Test', function(Test) { JS.require('JS.Test', function(Test) {
var options = require('nopt')({format: String}), var options = require('nopt')({format: String}),
Expand Down
2 changes: 1 addition & 1 deletion test/examples/tracing.js
Expand Up @@ -15,7 +15,7 @@ if (this.ActiveXObject) load = function(path) {
})() })()


if (typeof require === 'function') { if (typeof require === 'function') {
require('../../' + JSCLASS_PATH + 'loader') var JS = require('../../' + JSCLASS_PATH + 'loader')
} else { } else {
load(JSCLASS_PATH + 'loader.js') load(JSCLASS_PATH + 'loader.js')
} }
Expand Down
4 changes: 2 additions & 2 deletions test/phantom.js
@@ -1,7 +1,7 @@
JSCLASS_PATH = '../build/src' JSCLASS_PATH = '../build/src'
require(JSCLASS_PATH + '/loader') var pkg = require(JSCLASS_PATH + '/loader')


JS.require('JS.Test', function(Test) { pkg.require('JS.Test', function(Test) {
var page = new WebPage(), var page = new WebPage(),
reporter = new Test.Reporters.PhantomJS({}, page) reporter = new Test.Reporters.PhantomJS({}, page)


Expand Down
18 changes: 10 additions & 8 deletions test/runner.js
@@ -1,9 +1,10 @@
JS.ENV.CWD = (typeof CWD === 'undefined') ? '.' : CWD PKG = (typeof PKG === 'object') ? PKG : JS
PKG.ENV.CWD = (typeof CWD === 'undefined') ? '.' : CWD


JS.cacheBust = true PKG.cacheBust = true
if (JS.ENV.JS_DEBUG) JS.debug = true if (PKG.ENV.JS_DEBUG) PKG.debug = true


JS.packages(function() { with(this) { PKG.packages(function() { with(this) {
autoload(/^(.*)Spec$/, {from: CWD + '/test/specs', require: 'JS.$1'}) autoload(/^(.*)Spec$/, {from: CWD + '/test/specs', require: 'JS.$1'})


pkg('Test.UnitSpec').requires('JS.Set', 'JS.Observable') pkg('Test.UnitSpec').requires('JS.Set', 'JS.Observable')
Expand All @@ -15,9 +16,10 @@ JS.packages(function() { with(this) {
pkg('Test.MockingSpec').requires('TestSpecHelpers') pkg('Test.MockingSpec').requires('TestSpecHelpers')
}}) }})


JS.require('JS', 'JS.Test', function(js, Test) { PKG.require('JS', 'JS.Test', function(JS, Test) {
js.extend(JS, js) PKG.ENV.JS = JS
JS.Test = Test JS.Package = PKG.Package
JS.Test = Test


var specs = [ 'Test.UnitSpec', var specs = [ 'Test.UnitSpec',
'Test.ContextSpec', 'Test.ContextSpec',
Expand Down Expand Up @@ -51,6 +53,6 @@ JS.require('JS', 'JS.Test', function(js, Test) {


specs = Test.filter(specs, 'Spec') specs = Test.filter(specs, 'Spec')
specs.push(function() { Test.autorun() }) specs.push(function() { Test.autorun() })
JS.require.apply(JS, specs) PKG.require.apply(PKG, specs)
}) })


0 comments on commit d41c913

Please sign in to comment.