lib/utils.js
function (moduleRoot, remapModule, ignores) {
    var tree = madge(moduleRoot, { format: 'amd' }).tree,
        paths = [],
        map = {};

    /**
    * Filter function to test module paths, ignores can be array[string|regexp]|string|regexp
    * @param {string} path - module path
    */
    var matches = function matches (path) {
      if (type(ignores) === TYPES.STRING) {
        return path.search(ignores) > -1;
      } else if (type(ignores) === TYPES.REGEXP) {
        return ignores.test(path);
      } else {
        return ignores.some(function (ignore) {
          return type(ignore) === TYPES.STRING ? (path.search(ignore) > -1) : ignore.test(path);
        });
      }
    };

    //- Generate an array of paths to ignore
    for (var dependency in tree) {
      paths = paths.concat(tree[dependency].filter(matches));
    }

    if (paths.length === 0) {
      console.warn(messages.moduleRemapFoundNone);
    }

    //- Put in a format requirejs can understand
    paths.forEach(function (path) {
      map[path] = remapModule;
    });

    return map;
  }
function (moduleRoot, remapModule, ignores) {
    var tree = madge(moduleRoot, { format: 'amd' }).tree,
        paths = [],
        map = {};

    /**
    * Filter function to test module paths, ignores can be array[string|regexp]|string|regexp
    * @param {string} path - module path
    */
    var matches = function matches (path) {
      if (type(ignores) === TYPES.STRING) {
        return path.search(ignores) > -1;
      } else if (type(ignores) === TYPES.REGEXP) {
        return ignores.test(path);
      } else {
        return ignores.some(function (ignore) {
          return type(ignore) === TYPES.STRING ? (path.search(ignore) > -1) : ignore.test(path);
        });
      }
    };

    //- Generate an array of paths to ignore
    for (var dependency in tree) {
      paths = paths.concat(tree[dependency].filter(matches));
    }

    if (paths.length === 0) {
      console.warn(messages.moduleRemapFoundNone);
    }

    //- Put in a format requirejs can understand
    paths.forEach(function (path) {
      map[path] = remapModule;
    });

    return map;
  }
function ( moduleRoot , remapModule , ignores ) { var tree = madge ( moduleRoot , { format : 'amd' } ) . tree , paths = [ ] , map = { } ; /**
    * Filter function to test module paths, ignores can be array[string|regexp]|string|regexp
    * @param {string} path - module path
    */ var matches = function matches ( path ) { if ( type ( ignores ) === TYPES . STRING ) { return path . search ( ignores ) > - 1 ; } else if ( type ( ignores ) === TYPES . REGEXP ) { return ignores . test ( path ) ; } else { return ignores . some ( function ( ignore ) { return type ( ignore ) === TYPES . STRING ? ( path . search ( ignore ) > - 1 ) : ignore . test ( path ) ; } ) ; } } ; //- Generate an array of paths to ignore for ( var dependency in tree ) { paths = paths . concat ( tree [ dependency ] . filter ( matches ) ) ; } if ( paths . length === 0 ) { console . warn ( messages . moduleRemapFoundNone ) ; } //- Put in a format requirejs can understand paths . forEach ( function ( path ) { map [ path ] = remapModule ; } ) ; return map ; }
Generate a map object that maps all modules matching the ignores pattern to the emptyModule
@param {string} moduleRoot - base dir of your modules
@param {string} remapModule - path to empty module (by empty module I mean a dependency free module)
@param {string|array} ignores - RegEx patterns or basic strings to include in the map
@return {object} map
Generate a map object that maps all modules matching the ignores pattern to the emptyModule