packages/react-qml-cli/src/utils/findProvidesModule.js
function findProvidesModule(directories, opts = {}) {
  const options = Object.assign({}, defaultOpts, opts);

  const modulesMap = {};

  const walk = dir => {
    const stat = fs.lstatSync(dir);

    if (stat.isDirectory()) {
      fs.readdirSync(dir).forEach(file => {
        if (options.blacklist.indexOf(file) >= 0) {
          return;
        }
        walk(path.join(dir, file));
      });
      return;
    }

    if (stat.isFile()) {
      const jsFileName = getJSFileName(dir);
      if (!jsFileName) {
        return;
      }

      const fileName = getPlatformFileName(jsFileName, options.platforms);

      const moduleName = getProvidedModuleName(dir);
      if (!moduleName) {
        return;
      }

      // Throw when duplicated modules are provided from a different
      // fileName
      if (modulesMap[moduleName] && modulesMap[moduleName] !== fileName) {
        throw new Error('Duplicate haste module found');
      }
      modulesMap[moduleName] = fileName;
    }
  };

  directories.forEach(walk);

  return modulesMap;
}
function findProvidesModule(directories, opts = {}) {
  const options = Object.assign({}, defaultOpts, opts);

  const modulesMap = {};

  const walk = dir => {
    const stat = fs.lstatSync(dir);

    if (stat.isDirectory()) {
      fs.readdirSync(dir).forEach(file => {
        if (options.blacklist.indexOf(file) >= 0) {
          return;
        }
        walk(path.join(dir, file));
      });
      return;
    }

    if (stat.isFile()) {
      const jsFileName = getJSFileName(dir);
      if (!jsFileName) {
        return;
      }

      const fileName = getPlatformFileName(jsFileName, options.platforms);

      const moduleName = getProvidedModuleName(dir);
      if (!moduleName) {
        return;
      }

      // Throw when duplicated modules are provided from a different
      // fileName
      if (modulesMap[moduleName] && modulesMap[moduleName] !== fileName) {
        throw new Error('Duplicate haste module found');
      }
      modulesMap[moduleName] = fileName;
    }
  };

  directories.forEach(walk);

  return modulesMap;
}
function findProvidesModule ( directories , opts = { } ) { const options = Object . assign ( { } , defaultOpts , opts ) ; const modulesMap = { } ; const walk = dir => { const stat = fs . lstatSync ( dir ) ; if ( stat . isDirectory ( ) ) { fs . readdirSync ( dir ) . forEach ( file => { if ( options . blacklist . indexOf ( file ) >= 0 ) { return ; } walk ( path . join ( dir , file ) ) ; } ) ; return ; } if ( stat . isFile ( ) ) { const jsFileName = getJSFileName ( dir ) ; if ( ! jsFileName ) { return ; } const fileName = getPlatformFileName ( jsFileName , options . platforms ) ; const moduleName = getProvidedModuleName ( dir ) ; if ( ! moduleName ) { return ; } // Throw when duplicated modules are provided from a different // fileName if ( modulesMap [ moduleName ] && modulesMap [ moduleName ] !== fileName ) { throw new Error ( 'Duplicate haste module found' ) ; } modulesMap [ moduleName ] = fileName ; } } ; directories . forEach ( walk ) ; return modulesMap ; }
Recursively loops over given directories and returns a map of all
haste modules
Recursively loops over given directories and returns a map of all haste modules