function fileExistsWithCaseSync (filepath) {
  const { base, dir, root } = path.parse(filepath)

  if (dir === root || dir === '.') {
    return true
  }

  try {
    const filenames = fs.readdirSync(dir)
    if (!filenames.includes(base)) {
      return false
    }
  } catch (e) {
    // dir does not exist
    return false
  }

  return fileExistsWithCaseSync(dir)
}
function fileExistsWithCaseSync (filepath) {
  const { base, dir, root } = path.parse(filepath)

  if (dir === root || dir === '.') {
    return true
  }

  try {
    const filenames = fs.readdirSync(dir)
    if (!filenames.includes(base)) {
      return false
    }
  } catch (e) {
    // dir does not exist
    return false
  }

  return fileExistsWithCaseSync(dir)
}
function fileExistsWithCaseSync ( filepath ) { const { base , dir , root } = path . parse ( filepath ) if ( dir === root || dir === '.' ) { return true } try { const filenames = fs . readdirSync ( dir ) if ( ! filenames . includes ( base ) ) { return false } } catch ( e ) { // dir does not exist return false } return fileExistsWithCaseSync ( dir ) }
Based on https://stackoverflow.com/questions/27367261/check-if-file-exists-case-sensitive Case checking is required, to avoid errors raised by case-sensitive-paths-webpack-plugin
Based on https : // stackoverflow . com / questions / 27367261 / check - if - file - exists - case - sensitive Case checking is required to avoid errors raised by case - sensitive - paths - webpack - plugin
Check if filepath exists in the current directory