diff --git a/lib/component.js b/lib/component.js old mode 100644 new mode 100755 index ec4c057c..b5020569 --- a/lib/component.js +++ b/lib/component.js @@ -38,7 +38,7 @@ exports.lookup = function(pkg, paths){ debug('lookup %s', pkg); for (var i = 0; i < paths.length; ++i) { var path = join(paths[i], pkg); - debug('check %s', path); + debug('check %s', join(path, 'component.json')); if (exists(join(path, 'component.json'))) { debug('found %s', path); return path; @@ -66,8 +66,13 @@ exports.dependenciesOf = function(pkg, paths, parent){ var conf = require(resolve(path, 'component.json')); var deps = [conf.dependencies || {}]; if (conf.local) { + var lookupPaths = conf.paths || []; + lookupPaths = lookupPaths.map(function (relPath){ + return join(path, relPath); + }); conf.local.forEach(function(dep){ - deps = deps.concat(exports.dependenciesOf(dep, paths, pkg)); + //append root paths to relative paths of the dependency for backward compatibility + deps = deps.concat(exports.dependenciesOf(dep, paths.concat(lookupPaths), pkg)); }); } return deps; diff --git a/test/fixtures/local/component.json b/test/fixtures/local/component.json new file mode 100644 index 00000000..fb78ce18 --- /dev/null +++ b/test/fixtures/local/component.json @@ -0,0 +1,16 @@ +{ + "name": "local", + "description": "Main component with local dependency chain", + "version": "0.0.1", + "dependencies": {}, + "local": [ + "direct" + ], + "paths": [ + "./" + ], + "main": "index.js", + "scripts": [ + "index.js" + ] +} diff --git a/test/fixtures/local/direct/component.json b/test/fixtures/local/direct/component.json new file mode 100644 index 00000000..28ad7897 --- /dev/null +++ b/test/fixtures/local/direct/component.json @@ -0,0 +1,17 @@ +{ + "name": "direct", + "description": "Local component dependency for main application", + "version": "0.0.1", + "dependencies": {}, + "local": [ + "first", + "second" + ], + "paths": [ + "../others" + ], + "main": "index.js", + "scripts": [ + "index.js" + ] +} diff --git a/test/fixtures/local/direct/index.js b/test/fixtures/local/direct/index.js new file mode 100644 index 00000000..82f3c01d --- /dev/null +++ b/test/fixtures/local/direct/index.js @@ -0,0 +1,4 @@ +var first = require('first'); +var second = require('second'); + +module.exports = first + second; diff --git a/test/fixtures/local/index.js b/test/fixtures/local/index.js new file mode 100644 index 00000000..09199a39 --- /dev/null +++ b/test/fixtures/local/index.js @@ -0,0 +1,2 @@ +var direct = require('direct'); +console.log(direct); diff --git a/test/fixtures/local/others/first/component.json b/test/fixtures/local/others/first/component.json new file mode 100644 index 00000000..630d3e92 --- /dev/null +++ b/test/fixtures/local/others/first/component.json @@ -0,0 +1,12 @@ +{ + "name": "first", + "description": "Local dependency of a local component", + "version": "0.0.1", + "dependencies": { + "component/overlay": "*" + }, + "main": "index.js", + "scripts": [ + "index.js" + ] +} diff --git a/test/fixtures/local/others/first/index.js b/test/fixtures/local/others/first/index.js new file mode 100644 index 00000000..0b5c180d --- /dev/null +++ b/test/fixtures/local/others/first/index.js @@ -0,0 +1 @@ +module.exports = "first"; diff --git a/test/fixtures/local/others/second/component.json b/test/fixtures/local/others/second/component.json new file mode 100644 index 00000000..d1f15ff0 --- /dev/null +++ b/test/fixtures/local/others/second/component.json @@ -0,0 +1,12 @@ +{ + "name": "second", + "description": "Local dependency of a local component", + "version": "0.0.1", + "dependencies": { + "component/emitter": "*" + }, + "main": "index.js", + "scripts": [ + "index.js" + ] +} diff --git a/test/fixtures/local/others/second/index.js b/test/fixtures/local/others/second/index.js new file mode 100644 index 00000000..cea3053d --- /dev/null +++ b/test/fixtures/local/others/second/index.js @@ -0,0 +1 @@ +module.exports = "second"; diff --git a/test/install.js b/test/install.js index a632efb6..83ddec50 100644 --- a/test/install.js +++ b/test/install.js @@ -67,8 +67,15 @@ describe('component install', function(){ done(); }) }) - }) + it('should install dependencies through chain of local dependencies', function(done){ + exec('cd test/fixtures/local && ../../../bin/component install', function(err, stdout){ + if (err) return done(err); + done(); + }) + }) + + }) describe('[name...]', function(){ it('should install the multiple components', function(done){ exec('bin/component install component/overlay component/zepto', function(err, stdout){