Permalink
Browse files

replace COMPONENT_PATH with .paths prop. Closes #137

  • Loading branch information...
1 parent 1277748 commit 5f601fda6023ecec0884b4695eaf1336e3675929 @tj tj committed Nov 6, 2012
Showing with 30 additions and 52 deletions.
  1. +3 −3 bin/component-build
  2. +1 −1 bin/component-install
  3. +11 −22 lib/component.js
  4. +13 −25 test/build.js
  5. +2 −1 test/fixtures/path/component.json
View
@@ -71,11 +71,11 @@ builder.copyAssetsTo(program.out);
if (program.dev) builder.prefixUrls('./');
if (program.prefix) builder.prefixUrls(program.prefix);
-var start = new Date;
+// lookup paths
-// COMPONENT_PATH
+if (conf.paths) builder.addLookup(conf.paths);
-builder.addLookup(component.paths());
+var start = new Date;
// --dev
View
@@ -78,7 +78,7 @@ if (local) {
if (conf.local) {
conf.local.forEach(function(pkg){
try {
- var deps = component.dependenciesOf(pkg);
+ var deps = component.dependenciesOf(pkg, conf.paths);
deps.map(normalize).forEach(function(deps){
pkgs = pkgs.concat(deps);
});
View
@@ -27,29 +27,16 @@ var remote = 'http://50.116.26.197/components'; // TODO: settings
exports.utils = utils;
/**
- * Return __COMPONENT_PATH__ values.
- *
- * @return {Array}
- * @api public
- */
-
-exports.paths = function(){
- return process.env.COMPONENT_PATH
- ? process.env.COMPONENT_PATH.split(':')
- : [];
-};
-
-/**
- * Lookup `pkg` within COMPONENT_PATH.
+ * Lookup `pkg` within `paths`.
*
* @param {String} pkg
+ * @param {String} paths
* @return {String} path
- * @api public
+ * @api private
*/
-exports.lookup = function(pkg){
+exports.lookup = function(pkg, paths){
debug('lookup %s', pkg);
- var paths = exports.paths();
for (var i = 0, len = paths.length; i < len; ++i) {
var path = join(paths[i], pkg);
debug('check %s', path);
@@ -67,19 +54,21 @@ exports.lookup = function(pkg){
* packages as dependencies.
*
* @param {String} pkg
+ * @param {Array} [paths]
* @return {Array}
- * @api public
+ * @api private
*/
-exports.dependenciesOf = function(pkg, parent){
- var path = exports.lookup(pkg);
+exports.dependenciesOf = function(pkg, paths, parent){
+ paths = paths || [];
+ var path = exports.lookup(pkg, paths);
if (!path && parent) throw new Error('failed to lookup "' + parent + '"\'s dep "' + pkg + '" within COMPONENT_PATH');
- if (!path) throw new Error('failed to lookup "' + pkg + '" within COMPONENT_PATH');
+ if (!path) throw new Error('failed to lookup "' + pkg + '"');
var conf = require(resolve(path, 'component.json'));
var deps = [conf.dependencies || {}];
if (conf.local) {
conf.local.forEach(function(dep){
- deps = deps.concat(exports.dependenciesOf(dep, pkg));
+ deps = deps.concat(exports.dependenciesOf(dep, paths, pkg));
});
}
return deps;
View
@@ -10,34 +10,22 @@ var exec = require('child_process').exec
, vm = require('vm')
describe('component build', function(){
- describe('when COMPONENT_PATH is set', function(){
- it('should build', function(done){
- exec('cd test/fixtures/path && COMPONENT_PATH=lib ' + bin + '-build -v', function(err, stdout){
- if (err) return done(err);
- stdout.should.include('build/build.js');
- stdout.should.include('duration');
- stdout.should.include('css');
- stdout.should.include('js');
+ it('should build', function(done){
+ exec('cd test/fixtures/path && ' + bin + '-build -v', function(err, stdout){
+ if (err) return done(err);
+ stdout.should.include('build/build.js');
+ stdout.should.include('duration');
+ stdout.should.include('css');
+ stdout.should.include('js');
- var js = fs.readFileSync('test/fixtures/path/build/build.js', 'utf8');
- var ret = vm.runInNewContext(js + '; require("foo")');
- ret.should.equal('baz');
+ var js = fs.readFileSync('test/fixtures/path/build/build.js', 'utf8');
+ var ret = vm.runInNewContext(js + '; require("foo")');
+ ret.should.equal('baz');
- var ret = vm.runInNewContext(js + '; require("baz")');
- ret.should.equal('baz');
+ var ret = vm.runInNewContext(js + '; require("baz")');
+ ret.should.equal('baz');
- done();
- })
- })
- })
-
- describe('when COMPONENT_PATH is omitted', function(){
- it('should fail', function(done){
- exec('cd test/fixtures/path && ' + bin + '-build -v', function(err, stdout, stderr){
- stderr.should.include('error');
- stderr.should.include('failed to lookup "path"\'s dependency "bar"');
- done();
- })
+ done();
})
})
})
@@ -3,5 +3,6 @@
"dependencies": {
"bar": "*"
},
- "scripts": ["index.js"]
+ "scripts": ["index.js"],
+ "paths": ["lib"]
}

0 comments on commit 5f601fd

Please sign in to comment.