From bfd128185ea61998fb497714658747d73ea8ecf8 Mon Sep 17 00:00:00 2001 From: Micky Brunetti Date: Fri, 24 May 2013 11:53:14 +0900 Subject: [PATCH 1/5] Look for local chain of dependencies based on parent dependencies path list --- lib/component.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) mode change 100644 => 100755 lib/component.js diff --git a/lib/component.js b/lib/component.js old mode 100644 new mode 100755 index 007bacd4..113b54a4 --- a/lib/component.js +++ b/lib/component.js @@ -39,8 +39,8 @@ 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); - if (exists(path)) { + debug('check %s', join(path, 'component.json')); + if (exists(join(path, 'component.json'))) { debug('found %s', path); return path; } @@ -67,8 +67,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; From 2c4d3fa1b5b0aebe84fa5706e5020442672004ae Mon Sep 17 00:00:00 2001 From: Micky Brunetti Date: Fri, 7 Jun 2013 12:50:55 +0900 Subject: [PATCH 2/5] * Added Unit Test for chain of dependency --- test/fixtures/local/direct/index.js | 4 ++++ test/fixtures/local/index.js | 2 ++ test/fixtures/local/others/first/index.js | 1 + test/fixtures/local/others/second/index.js | 1 + test/install.js | 9 ++++++++- 5 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/local/direct/index.js create mode 100644 test/fixtures/local/index.js create mode 100644 test/fixtures/local/others/first/index.js create mode 100644 test/fixtures/local/others/second/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/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/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..e5a38267 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 && ../../../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){ From 914fcf5331d5762dc1387bcf6830dd8a4d9bcdcb Mon Sep 17 00:00:00 2001 From: Micky Brunetti Date: Wed, 12 Jun 2013 11:20:31 +0900 Subject: [PATCH 3/5] * Looking for component in the wrong place --- test/install.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/install.js b/test/install.js index e5a38267..83ddec50 100644 --- a/test/install.js +++ b/test/install.js @@ -69,7 +69,7 @@ describe('component install', function(){ }) it('should install dependencies through chain of local dependencies', function(done){ - exec('cd test/fixtures/local && ../../../component install', function(err, stdout){ + exec('cd test/fixtures/local && ../../../bin/component install', function(err, stdout){ if (err) return done(err); done(); }) From f9d62a3e4a32a6727c1b7153c1e5ba1c26d12bfe Mon Sep 17 00:00:00 2001 From: Micky Brunetti Date: Wed, 19 Jun 2013 08:52:56 +0900 Subject: [PATCH 4/5] * Added missing file --- test/fixtures/local/component.json | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 test/fixtures/local/component.json 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" + ] +} From 7799756a77a6c45ca7d13355e24478583a795e83 Mon Sep 17 00:00:00 2001 From: Micky Brunetti Date: Wed, 19 Jun 2013 09:22:16 +0900 Subject: [PATCH 5/5] * Adding missing files --- test/fixtures/local/direct/component.json | 17 +++++++++++++++++ test/fixtures/local/others/first/component.json | 12 ++++++++++++ .../fixtures/local/others/second/component.json | 12 ++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 test/fixtures/local/direct/component.json create mode 100644 test/fixtures/local/others/first/component.json create mode 100644 test/fixtures/local/others/second/component.json 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/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/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" + ] +}