slushjs / slush

The streaming scaffolding system - Gulp as a replacement for Yeoman
http://slushjs.github.io/generators
MIT License
1.24k stars 58 forks source link

Paths that slush searches generators in #29

Open olsonpm opened 9 years ago

olsonpm commented 9 years ago

So given the below modification to bin/slush.js: getModulePaths()

function getModulesPaths () {
  if (process.env.NODE_ENV === 'test') {
    return [path.join(__dirname, '..', 'test')];
  }
  var paths = [];
  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);

  // changed here <---------------------
  console.log('Paths:');
  console.log(paths);

  return paths.map(function(path){
    return path.toLowerCase();
  }).filter(function(path, index, all){
    return all.lastIndexOf(path) === index;
  });
}

Outputs the following on my ubuntu 14.10 machine when I run 'slush'

Paths:
[ 'usr/lib/node_modules',
  '/usr/local/lib/node_modules',
  '/usr/local/lib/node_modules/slush/bin/node_modules',
  '/usr/local/lib/node_modules/slush/node_modules',
  '/usr/local/lib/node_modules',
  '/usr/local/node_modules',
  '/usr/node_modules',
  '/node_modules' ]

Can someone explain the significance of searching all these folders? At first it was a pain just to figure out what require.main.paths was because it's undocumented in node, but even after learning what it was, I still don't understand why it's in use.

Thanks, Phil