Skip to content
This repository has been archived by the owner on Mar 27, 2019. It is now read-only.

Follow the chain of paths for local dependencies #337

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions lib/component.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
16 changes: 16 additions & 0 deletions test/fixtures/local/component.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
17 changes: 17 additions & 0 deletions test/fixtures/local/direct/component.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
4 changes: 4 additions & 0 deletions test/fixtures/local/direct/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
var first = require('first');
var second = require('second');

module.exports = first + second;
2 changes: 2 additions & 0 deletions test/fixtures/local/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
var direct = require('direct');
console.log(direct);
12 changes: 12 additions & 0 deletions test/fixtures/local/others/first/component.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
1 change: 1 addition & 0 deletions test/fixtures/local/others/first/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = "first";
12 changes: 12 additions & 0 deletions test/fixtures/local/others/second/component.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
1 change: 1 addition & 0 deletions test/fixtures/local/others/second/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = "second";
9 changes: 8 additions & 1 deletion test/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down