commit 161941747f4e5ea5ef11908e2cfe9c4d0edee5b8 Author: Joel Pittet Date: Fri Dec 11 13:21:27 2015 -0800 chages diff --git a/core/includes/file.inc b/core/includes/file.inc index b9c217b..15a1811 100644 --- a/core/includes/file.inc +++ b/core/includes/file.inc @@ -10,6 +10,7 @@ use Drupal\Component\PhpStorage\FileStorage; use Drupal\Component\Utility\Bytes; use Drupal\Core\File\FileSystem; +use Drupal\Core\Site\Settings; use Drupal\Core\StreamWrapper\PublicStream; use Drupal\Core\StreamWrapper\PrivateStream; @@ -945,6 +946,16 @@ function file_scan_directory($dir, $mask, $options = array(), $depth = 0) { $dir_has_slash = (substr($dir, -1) === '/'); } + // By default, do not check for files in common special-purpose directories. + // The folders here are front-end related and they have been added to avoid + // issues with Drupal recursive scanning. In this case, we added node_modules + // and bower_components. This also improves performance on frontend builds. + $ignore_directories = Settings::get('drupal_file_scan_ignore_directories', [ + 'node_modules', + 'bower_components', + ]); + $default_nomask = '/^' . implode('|', $ignore_directories) . '$/'; + $options['key'] = in_array($options['key'], array('uri', 'filename', 'name')) ? $options['key'] : 'uri'; $files = array(); // Avoid warnings when opendir does not have the permissions to open a @@ -953,7 +964,10 @@ function file_scan_directory($dir, $mask, $options = array(), $depth = 0) { if ($handle = @opendir($dir)) { while (FALSE !== ($filename = readdir($handle))) { // Skip this file if it matches the nomask or starts with a dot. - if ($filename[0] != '.' && !(isset($options['nomask']) && preg_match($options['nomask'], $filename))) { + if ($filename[0] != '.' + && !(isset($options['nomask']) && preg_match($options['nomask'], $filename)) + && !(!empty($default_nomask) && preg_match($default_nomask, $filename)) + ) { if ($depth == 0 && $dir_has_slash) { $uri = "$dir$filename"; } diff --git a/core/includes/theme.inc b/core/includes/theme.inc index 4e623b0..35af8e0 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -198,7 +198,7 @@ function drupal_find_theme_templates($cache, $extension, $path) { // Escape the periods in the extension. $regex = '/' . str_replace('.', '\.', $extension) . '$/'; // Get a listing of all template files in the path to search. - $files = file_scan_directory($path, $regex, array('key' => 'filename', 'nomask' => '/^(\..*)|node_modules|bower_components$/')); + $files = file_scan_directory($path, $regex, array('key' => 'filename')); // Find templates that implement registered theme hooks and include that in // what is returned so that the registry knows that the theme has this