Skip to content

Paths that slush searches generators in #29

@olsonpm

Description

@olsonpm

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions