Issue #2307717 by Wim Leers, micbar: Fixed Inform Drupal in *.libraries.yml via a new per-JS file "minified" flag whether a JS file has been minified.

8.0.x
Alex Pott 2014-08-19 16:13:03 +01:00
parent 5348e2e361
commit dd4fd1ac24
5 changed files with 44 additions and 7 deletions

View File

@ -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 } }
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 }
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 }
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 } }
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: {}
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 }
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

View File

@ -112,7 +112,13 @@ class JsCollectionOptimizer implements AssetCollectionOptimizerInterface {
// Concatenate each asset within the group.
$data = '';
foreach ($js_group['items'] as $js_asset) {
$data .= $this->optimizer->optimize($js_asset);
// Optimize this JS file, but only if it's not yet minified.
if (isset($js_asset['minified']) && $js_asset['minified']) {
$data .= file_get_contents($js_asset['data']);
}
else {
$data .= $this->optimizer->optimize($js_asset);
}
// Append a ';' and a newline after each JS file to prevent them
// from running together.
$data .= ";\n";

View File

@ -177,6 +177,11 @@ class LibraryDiscoveryParser {
$options['version'] = $library['version'];
}
// Set the 'minified' flag on JS file assets, default to FALSE.
if ($type == 'js' && $options['type'] == 'file') {
$options['minified'] = isset($options['minified']) ? $options['minified'] : FALSE;
}
$library[$type][] = $options;
}
}

View File

@ -346,6 +346,28 @@ class LibraryDiscoveryParserTest extends UnitTestCase {
$this->assertEquals('public://test.css', $library['css'][3]['data']);
}
/**
* 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.
*

View File

@ -0,0 +1,4 @@
example:
js:
js/unminified.js: {}
js/minified.js: { minified: true }