Skip to content

Commit

Permalink
Merge 2cedee5 into c1210d0
Browse files Browse the repository at this point in the history
  • Loading branch information
floatdrop committed Dec 26, 2013
2 parents c1210d0 + 2cedee5 commit e6057b6
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 12 deletions.
27 changes: 16 additions & 11 deletions lib/env/resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,23 @@ exports.lookup = function () {

exports._getNpmGenerators = function () {
var modules = [];
this.paths
.map(function (root) {
return findup('node_modules/', { cwd: root });
})
.forEach(function (root) {
if (!root) return;
var found = glob.sync('generator-*', { cwd: root, stat: true })
.map(function( match ) {
return fs.realpathSync(path.join(root, match));
});
modules = modules.concat(found);
var nodeModules = [];

this.paths.forEach(function (root) {
var found = findup('node_modules/', { cwd: root });
while (found && found !== path.dirname(found)) {
nodeModules.push(found);
found = findup('node_modules/', { cwd: path.dirname(path.dirname(found)) });
}
});

nodeModules.forEach(function (root) {
if (!root) return;
var found = glob.sync('generator-*', { cwd: root, stat: true }).map(function (match) {
return fs.realpathSync(path.join(root, match));
});
modules = found.concat(modules);
});

return modules;
};
Expand Down
29 changes: 28 additions & 1 deletion test/env.resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ describe('Environment Resolver', function () {
});

describe('#lookup', function () {

it('register local generators', function () {
assert.ok(this.env.get('dummy:app'));
assert.ok(this.env.get('dummy:yo'));
Expand All @@ -61,6 +62,32 @@ describe('Environment Resolver', function () {
it('register symlinked generators', function() {
assert.ok(this.env.get('extend:support:scaffold'));
});
});

describe('when there\'s ancestor node_modules/ folder', function() {

before(function () {
this.projectSubRoot = path.join(this.projectRoot, 'subdir');
process.chdir(this.projectSubRoot);
shell.exec('npm install', { silent: true });
});

beforeEach(function () {
this.env = new Environment();
assert.equal(this.env.namespaces().length, 0, 'ensure env is empty');
this.env.lookup();
});

it('register generators in ancestor node_modules directory', function () {
assert.ok(this.env.get('jquery:app'));
});

it('register generators in right order (nearest first)', function () {
var app = this.env.get('dummy:app');
assert.ok(app);
assert.ok(app.resolved.indexOf('subdir') !== -1);
});

});

});
});
6 changes: 6 additions & 0 deletions test/fixtures/lookup-project/subdir/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "lookup-subdir-dummy-env",
"dependencies": {
"generator-dummy": "~0.1.0"
}
}

0 comments on commit e6057b6

Please sign in to comment.