core/core.libraries.yml | 12 +++++------ .../Drupal/Core/Asset/JsCollectionOptimizer.php | 4 ++-- .../Drupal/Core/Asset/LibraryDiscoveryParser.php | 6 +++++- .../Core/Asset/LibraryDiscoveryParserTest.php | 23 ++++++++++++++++++++++ .../Core/Asset/library_test_files/js.libraries.yml | 4 ++++ 5 files changed, 40 insertions(+), 9 deletions(-) diff --git a/core/core.libraries.yml b/core/core.libraries.yml index d88cb1e..d0cfb58 100644 --- a/core/core.libraries.yml +++ b/core/core.libraries.yml @@ -21,7 +21,7 @@ classList: url: https://github.com/eligrey/classList.js/blob/master/LICENSE.md gpl-compatible: true js: - assets/vendor/classList/classList.min.js: { weight: -21, browsers: { IE: 'lte IE 9', '!IE': false }, optimized: true } + assets/vendor/classList/classList.min.js: { weight: -21, browsers: { IE: 'lte IE 9', '!IE': false }, minified: true } ckeditor: remote: https://github.com/ckeditor/ckeditor-dev @@ -31,7 +31,7 @@ ckeditor: url: https://github.com/ckeditor/ckeditor-dev/blob/887d81ac1824008b690e439a1b29eb4f13b51212/LICENSE.md gpl-compatible: true js: - assets/vendor/ckeditor/ckeditor.js: { preprocess: false, optimized: true } + assets/vendor/ckeditor/ckeditor.js: { preprocess: false, minified: true } domready: remote: https://github.com/ded/domready @@ -41,7 +41,7 @@ domready: url: https://github.com/ded/domready/blob/v1.0.6/LICENSE gpl-compatible: true js: - assets/vendor/domready/ready.min.js: { weight: -21, optimized: true } + assets/vendor/domready/ready.min.js: { weight: -21, minified: true } drupal: version: VERSION @@ -299,7 +299,7 @@ html5shiv: url: http://www.gnu.org/licenses/gpl-2.0.html gpl-compatible: true js: - assets/vendor/html5shiv/html5.js: { every_page: true, weight: -22, browsers: { IE: 'lte IE 8', '!IE': false }, optimized: true } + assets/vendor/html5shiv/html5.js: { every_page: true, weight: -22, browsers: { IE: 'lte IE 8', '!IE': false }, minified: true } jquery: remote: https://github.com/jquery/jquery @@ -332,7 +332,7 @@ jquery.farbtastic: url: https://github.com/mattfarina/farbtastic/blob/master/LICENSE.txt gpl-compatible: true js: - assets/vendor/farbtastic/farbtastic.js: { optimized: true } + assets/vendor/farbtastic/farbtastic.js: { minified: true } css: component: assets/vendor/farbtastic/farbtastic.css: {} @@ -761,7 +761,7 @@ modernizr: gpl-compatible: true version: v2.6.2 js: - assets/vendor/modernizr/modernizr.min.js: { every_page: true, preprocess: 0, scope: header, weight: -21, optimized: true } + assets/vendor/modernizr/modernizr.min.js: { every_page: true, preprocess: 0, scope: header, weight: -21, minified: true } normalize: remote: https://github.com/necolas/normalize.css diff --git a/core/lib/Drupal/Core/Asset/JsCollectionOptimizer.php b/core/lib/Drupal/Core/Asset/JsCollectionOptimizer.php index bd6566c..dffc40a 100644 --- a/core/lib/Drupal/Core/Asset/JsCollectionOptimizer.php +++ b/core/lib/Drupal/Core/Asset/JsCollectionOptimizer.php @@ -112,8 +112,8 @@ public function optimize(array $js_assets) { // Concatenate each asset within the group. $data = ''; foreach ($js_group['items'] as $js_asset) { - // Optimize this JS file, but only if it's not yet optimized. - if ($js_asset['optimized']) { + // Optimize this JS file, but only if it's not yet minified. + if ($js_asset['minified']) { $data .= file_get_contents($js_asset['data']); } else { diff --git a/core/lib/Drupal/Core/Asset/LibraryDiscoveryParser.php b/core/lib/Drupal/Core/Asset/LibraryDiscoveryParser.php index 4fa6313..1aefe11 100644 --- a/core/lib/Drupal/Core/Asset/LibraryDiscoveryParser.php +++ b/core/lib/Drupal/Core/Asset/LibraryDiscoveryParser.php @@ -135,7 +135,6 @@ public function buildByExtension($extension) { // processing order. if ($type == 'js') { $options['group'] = JS_LIBRARY; - $options['optimized'] = (isset($options['optimized']) ? $options['optimized'] : TRUE; } elseif ($type == 'css') { $options['group'] = $extension_type == 'theme' ? CSS_AGGREGATE_THEME : CSS_AGGREGATE_DEFAULT; @@ -178,6 +177,11 @@ public function buildByExtension($extension) { $options['version'] = $library['version']; } + // Set the 'minified' flag is on JS file assets, default to FALSE. + if ($type == 'js' && $options['type'] == 'file') { + $options['minified'] = isset($options['minified']) ? $options['minified'] : FALSE; + } + $library[$type][] = $options; } } diff --git a/core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryParserTest.php b/core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryParserTest.php index dde3023..da0ed54 100644 --- a/core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryParserTest.php +++ b/core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryParserTest.php @@ -31,6 +31,7 @@ /** * @coversDefaultClass \Drupal\Core\Asset\LibraryDiscoveryParser * @group Asset + * @group Foo */ class LibraryDiscoveryParserTest extends UnitTestCase { @@ -347,6 +348,28 @@ public function testLibraryWithDataTypes() { } /** + * Tests a library with JavaScript-specific flags. + * + * @covers ::buildByExtension() + */ + public function testLibraryWithJavaScript() { + $this->moduleHandler->expects($this->atLeastOnce()) + ->method('moduleExists') + ->with('js') + ->will($this->returnValue(TRUE)); + + $path = __DIR__ . '/library_test_files'; + $path = substr($path, strlen(DRUPAL_ROOT) + 1); + $this->libraryDiscoveryParser->setPaths('module', 'js', $path); + + $libraries = $this->libraryDiscoveryParser->buildByExtension('js'); + $library = $libraries['example']; + + $this->assertCount(2, $library['js']); + $this->assertEquals(FALSE, $library['js'][0]['minified']); + $this->assertEquals(TRUE, $library['js'][1]['minified']); + } + /** * Tests that an exception is thrown when license is missing when 3rd party. * * @expectedException \Drupal\Core\Asset\Exception\LibraryDefinitionMissingLicenseException diff --git a/core/tests/Drupal/Tests/Core/Asset/library_test_files/js.libraries.yml b/core/tests/Drupal/Tests/Core/Asset/library_test_files/js.libraries.yml index e69de29..0fa6115 100644 --- a/core/tests/Drupal/Tests/Core/Asset/library_test_files/js.libraries.yml +++ b/core/tests/Drupal/Tests/Core/Asset/library_test_files/js.libraries.yml @@ -0,0 +1,4 @@ +example: + js: + js/unminified.js: {} + js/minified.js: { minified: true }