src/importer.js
function findImportedPath(url, prev, includedFilesMap, includedPaths) {
  let candidateFromPaths;

  if(prev !== 'stdin') {
    const prevPath = path.posix.dirname(prev);
    candidateFromPaths = [prevPath, ...includedPaths];
  } else {
    candidateFromPaths = [...includedPaths];
  }

  for(let i = 0; i < candidateFromPaths.length; i++) {
    let candidatePath;
    let candidateFromPath = normalizePath(makeAbsolute(candidateFromPaths[i]));
    if (path.isAbsolute(url)) {
      candidatePath = normalizePath(url);
    } else {
      // Get normalize absolute candidate from path
      candidatePath = path.posix.join(candidateFromPath, url);
    }

    if(includedFilesMap[candidatePath]) {
      return candidatePath;
    } else {
      let urlBasename = path.posix.basename(url);
      let indexOfBasename = url.lastIndexOf(urlBasename);
      let partialUrl = `${url.substring(0, indexOfBasename)}_${urlBasename}`;

      if (path.isAbsolute(partialUrl)) {
        candidatePath = normalizePath(partialUrl);
      } else {
        candidatePath = path.posix.join(candidateFromPath, partialUrl);
      }

      if(includedFilesMap[candidatePath]) {
        return candidatePath;
      }
    }
  }

  return null;
}
function findImportedPath(url, prev, includedFilesMap, includedPaths) {
  let candidateFromPaths;

  if(prev !== 'stdin') {
    const prevPath = path.posix.dirname(prev);
    candidateFromPaths = [prevPath, ...includedPaths];
  } else {
    candidateFromPaths = [...includedPaths];
  }

  for(let i = 0; i < candidateFromPaths.length; i++) {
    let candidatePath;
    let candidateFromPath = normalizePath(makeAbsolute(candidateFromPaths[i]));
    if (path.isAbsolute(url)) {
      candidatePath = normalizePath(url);
    } else {
      // Get normalize absolute candidate from path
      candidatePath = path.posix.join(candidateFromPath, url);
    }

    if(includedFilesMap[candidatePath]) {
      return candidatePath;
    } else {
      let urlBasename = path.posix.basename(url);
      let indexOfBasename = url.lastIndexOf(urlBasename);
      let partialUrl = `${url.substring(0, indexOfBasename)}_${urlBasename}`;

      if (path.isAbsolute(partialUrl)) {
        candidatePath = normalizePath(partialUrl);
      } else {
        candidatePath = path.posix.join(candidateFromPath, partialUrl);
      }

      if(includedFilesMap[candidatePath]) {
        return candidatePath;
      }
    }
  }

  return null;
}
function findImportedPath ( url , prev , includedFilesMap , includedPaths ) { let candidateFromPaths ; if ( prev !== 'stdin' ) { const prevPath = path . posix . dirname ( prev ) ; candidateFromPaths = [ prevPath , ... includedPaths ] ; } else { candidateFromPaths = [ ... includedPaths ] ; } for ( let i = 0 ; i < candidateFromPaths . length ; i ++ ) { let candidatePath ; let candidateFromPath = normalizePath ( makeAbsolute ( candidateFromPaths [ i ] ) ) ; if ( path . isAbsolute ( url ) ) { candidatePath = normalizePath ( url ) ; } else { // Get normalize absolute candidate from path candidatePath = path . posix . join ( candidateFromPath , url ) ; } if ( includedFilesMap [ candidatePath ] ) { return candidatePath ; } else { let urlBasename = path . posix . basename ( url ) ; let indexOfBasename = url . lastIndexOf ( urlBasename ) ; let partialUrl = ` ${ url . substring ( 0 , indexOfBasename ) } ${ urlBasename } ` ; if ( path . isAbsolute ( partialUrl ) ) { candidatePath = normalizePath ( partialUrl ) ; } else { candidatePath = path . posix . join ( candidateFromPath , partialUrl ) ; } if ( includedFilesMap [ candidatePath ] ) { return candidatePath ; } } } return null ; }
Search for the imported file in order of included paths
Search for the imported file in order of included paths