Skip to content

Commit

Permalink
Merge pull request #32 from doctyper/feature/namespace-compatibility
Browse files Browse the repository at this point in the history
Add support for scoped npm modules and NODE_PATH env var
  • Loading branch information
Joakim Carlstein committed Feb 24, 2015
2 parents 89cfd26 + 8967e6b commit 2383fd2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
21 changes: 13 additions & 8 deletions bin/slush.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,25 +177,30 @@ function getModulesPaths () {
if (process.env.NODE_ENV === 'test') {
return [path.join(__dirname, '..', 'test')];
}
var sep = (process.platform === 'win32') ? ';' : ':';
var paths = [];
if (process.platform === 'win32') {
paths.push(path.join(process.env.APPDATA, 'npm', 'node_modules'));

if (process.env.NODE_PATH) {
paths = paths.concat(process.env.NODE_PATH.split(sep));
} else {
paths.push('/usr/lib/node_modules');
if (process.platform === 'win32') {
paths.push(path.join(process.env.APPDATA, 'npm', 'node_modules'));
} else {
paths.push('/usr/lib/node_modules');
}
}

paths.push(path.join(__dirname, '..', '..'));
paths.push.apply(paths, require.main.paths);
return paths.map(function(path){
return path.toLowerCase();
}).filter(function(path, index, all){
return paths.filter(function(path, index, all){
return all.lastIndexOf(path) === index;
});
}

function findGenerators (searchpaths) {
return searchpaths.reduce(function (arr, searchpath) {
return arr.concat(glob.sync('slush-*', {cwd: searchpath, stat: true}).map(function (match) {
var generator = {path: path.join(searchpath, match), name: match.slice(6), pkg: {}};
return arr.concat(glob.sync('{@*/,}slush-*', {cwd: searchpath, stat: true}).map(function (match) {
var generator = {path: path.join(searchpath, match), name: match.replace(/(?:@[\w]+[\/|\\]+)?slush-/, ""), pkg: {}};
try {
generator.pkg = require(path.join(searchpath, match, 'package.json'));
} catch (e) {
Expand Down
4 changes: 2 additions & 2 deletions test/slush.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ describe('slush', function () {
});
slush.on('close', function (code) {
code.should.equal(0);
data.should.match(/\[gulp\] ├── default/);
data.should.match(/\[gulp\] └── app/);
data.should.match(/├── default/);
data.should.match(/└── app/);
done();
});
});
Expand Down

0 comments on commit 2383fd2

Please sign in to comment.