Commit dd4fd1ac authored by alexpott's avatar alexpott

Issue #2307717 by Wim Leers, micbar: Fixed Inform Drupal in *.libraries.yml...

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.
parent 5348e2e3
......@@ -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
......
......@@ -112,7 +112,13 @@ public function optimize(array $js_assets) {
// 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";
......
......@@ -177,6 +177,11 @@ public function buildByExtension($extension) {
$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;
}
}
......
......@@ -346,6 +346,28 @@ public function testLibraryWithDataTypes() {
$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.
*
......
example:
js:
js/unminified.js: {}
js/minified.js: { minified: true }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment