Skip to content
This repository was archived by the owner on Dec 7, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Changelog

<!-- Add new, unreleased items here. -->
## Unreleased
- Added support for `exclude` option in `polymer.json` for the build command's `minify` and `compile` options for `css`, `js` and `html` files.
- Added `--fix` option to `polymer lint`. When passed, some warnings with simple mechanical solutions will be fixed.
- Also supports warnings which can be addressed with less-safe changes via
an interactive prompt and the `--edits` flag. See `polymer lint --help` for
Expand All @@ -10,6 +10,8 @@
- Also works with `--fix` to automatically fix and report warnings as you work!
- `build` Added a CLI argument for setting the `basePath` option: `--base-path`.
- Derives node version check from the package.json.
- The polymer.json project config can now specify paths to exclude when minifying files and compiling JavaScript. See https://github.com/Polymer/polymer-project-config/issues/50 for more.
<!-- Add new, unreleased items here. -->

## v1.5.7 [10-11-2017]
- Updated css-slam, bower and other dependencies.
Expand Down
4 changes: 4 additions & 0 deletions custom_typings/matcher.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare module 'matcher' {
import {matcher} from 'matcher';
export = matcher;
}
4,796 changes: 3,429 additions & 1,367 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,14 @@
"gunzip-maybe": "^1.3.1",
"html-minifier": "^3.0.1",
"inquirer": "^1.0.2",
"matcher": "^1.0.0",
"merge-stream": "^1.0.1",
"mz": "^2.6.0",
"plylog": "^0.4.0",
"polymer-analyzer": "^2.6.0",
"polymer-build": "^2.1.0",
"polymer-linter": "^2.2.0",
"polymer-project-config": "^3.4.0",
"polymer-project-config": "^3.8.1",
"polyserve": "^0.23.0",
"request": "^2.72.0",
"rimraf": "^2.6.1",
Expand Down
35 changes: 25 additions & 10 deletions src/build/optimize-streams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import * as gulpif from 'gulp-if';
import {minify as htmlMinify, Options as HTMLMinifierOptions} from 'html-minifier';
import * as logging from 'plylog';
import {Transform} from 'stream';
import * as vinyl from 'vinyl';
import matcher = require('matcher');


const babelPresetES2015 = require('babel-preset-es2015');
Expand All @@ -38,9 +40,9 @@ export type CSSOptimizeOptions = {
stripWhitespace?: boolean;
};
export interface OptimizeOptions {
html?: {minify?: boolean};
css?: {minify?: boolean};
js?: {minify?: boolean, compile?: boolean};
html?: {minify?: boolean|{exclude?: string[]}};
css?: {minify?: boolean|{exclude?: string[]}};
js?: {minify?: boolean|{exclude?: string[]}, compile?: boolean|{exclude?: string[]}};
}
;

Expand Down Expand Up @@ -192,27 +194,40 @@ export function getOptimizeStreams(options?: OptimizeOptions):

// compile ES6 JavaScript using babel
if (options.js && options.js.compile) {
streams.push(gulpif(/\.js$/, new JSDefaultCompileTransform()));
streams.push(gulpif(matchesExtAndNotExcluded('.js', options.js.compile),
new JSDefaultCompileTransform()));
}

// minify code (minify should always be the last transform)
if (options.html && options.html.minify) {
streams.push(gulpif(
/\.html$/,
streams.push(gulpif(matchesExtAndNotExcluded('.html', options.html.minify),
new HTMLOptimizeTransform(
{collapseWhitespace: true, removeComments: true})));
}
if (options.css && options.css.minify) {
streams.push(
gulpif(/\.css$/, new CSSMinifyTransform({stripWhitespace: true})));
gulpif(matchesExtAndNotExcluded('.css', options.css.minify),
new CSSMinifyTransform({stripWhitespace: true})));
// TODO(fks): Remove this InlineCSSOptimizeTransform stream once CSS
// is properly being isolated by splitHtml() & rejoinHtml().
streams.push(gulpif(
/\.html$/, new InlineCSSOptimizeTransform({stripWhitespace: true})));
streams.push(gulpif(matchesExtAndNotExcluded('.html', options.css.minify),
new InlineCSSOptimizeTransform({stripWhitespace: true})));
}
if (options.js && options.js.minify) {
streams.push(gulpif(/\.js$/, new JSDefaultMinifyTransform()));
streams.push(gulpif(matchesExtAndNotExcluded('.js', options.js.minify),
new JSDefaultMinifyTransform()));
}

return streams;
};

function matchesExtAndNotExcluded(
extension: string,
option: boolean|{exclude?: string[]}) {
const exclude = typeof option === 'object' && option.exclude || [];
return (fs: vinyl) => {
return !!fs.path &&
fs.relative.endsWith(extension) &&
!exclude.some((pattern: string) => matcher.isMatch(fs.relative, pattern));
};
}
1 change: 0 additions & 1 deletion src/test/integration/build_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ suite('polymer build', function() {
binPath,
[
'build',
'--add-push-manifest',
'--add-service-worker',
'--bundle',
'--css-minify',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<html><head><script>!function(e){var r=e.babelHelpers={};r.typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},r.classCallCheck=function(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")},r.createClass=function(){function e(e,r){for(var t=0;t<r.length;t++){var n=r[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(r,t,n){return t&&e(r.prototype,t),n&&e(r,n),r}}(),r.defineEnumerableProperties=function(e,r){for(var t in r){var n=r[t];n.configurable=n.enumerable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,t,n)}return e},r.defaults=function(e,r){for(var t=Object.getOwnPropertyNames(r),n=0;n<t.length;n++){var o=t[n],i=Object.getOwnPropertyDescriptor(r,o);i&&i.configurable&&void 0===e[o]&&Object.defineProperty(e,o,i)}return e},r.defineProperty=function(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e},r.extends=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e},r.get=function e(r,t,n){null===r&&(r=Function.prototype);var o=Object.getOwnPropertyDescriptor(r,t);if(void 0===o){var i=Object.getPrototypeOf(r);return null===i?void 0:e(i,t,n)}if("value"in o)return o.value;var a=o.get;if(void 0!==a)return a.call(n)},r.inherits=function(e,r){if("function"!=typeof r&&null!==r)throw new TypeError("Super expression must either be null or a function, not "+typeof r);e.prototype=Object.create(r&&r.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),r&&(Object.setPrototypeOf?Object.setPrototypeOf(e,r):e.__proto__=r)},r.instanceof=function(e,r){return null!=r&&"undefined"!=typeof Symbol&&r[Symbol.hasInstance]?r[Symbol.hasInstance](e):e instanceof r},r.newArrowCheck=function(e,r){if(e!==r)throw new TypeError("Cannot instantiate an arrow function")},r.objectDestructuringEmpty=function(e){if(null==e)throw new TypeError("Cannot destructure undefined")},r.objectWithoutProperties=function(e,r){var t={};for(var n in e)r.indexOf(n)>=0||Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t},r.possibleConstructorReturn=function(e,r){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!r||"object"!=typeof r&&"function"!=typeof r?e:r},r.set=function e(r,t,n,o){var i=Object.getOwnPropertyDescriptor(r,t);if(void 0===i){var a=Object.getPrototypeOf(r);null!==a&&e(a,t,n,o)}else if("value"in i&&i.writable)i.value=n;else{var u=i.set;void 0!==u&&u.call(o,n)}return n},r.slicedToArray=function(){function e(e,r){var t=[],n=!0,o=!1,i=void 0;try{for(var a,u=e[Symbol.iterator]();!(n=(a=u.next()).done)&&(t.push(a.value),!r||t.length!==r);n=!0);}catch(e){o=!0,i=e}finally{try{!n&&u.return&&u.return()}finally{if(o)throw i}}return t}return function(r,t){if(Array.isArray(r))return r;if(Symbol.iterator in Object(r))return e(r,t);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),r.taggedTemplateLiteral=function(e,r){return Object.freeze(Object.defineProperties(e,{raw:{value:Object.freeze(r)}}))},r.temporalRef=function(e,r,t){if(e===t)throw new ReferenceError(r+" is not defined - temporal dead zone");return e},r.temporalUndefined={},r.toArray=function(e){return Array.isArray(e)?e:Array.from(e)},r.toConsumableArray=function(e){if(Array.isArray(e)){for(var r=0,t=Array(e.length);r<e.length;r++)t[r]=e[r];return t}return Array.from(e)}}("undefined"==typeof global?self:global);</script>

</head><body><div hidden="" by-polymer-bundler=""><script>var Foo=function(a){function b(){return babelHelpers.classCallCheck(this,b),babelHelpers.possibleConstructorReturn(this,(b.__proto__||Object.getPrototypeOf(b)).apply(this,arguments))}return babelHelpers.inherits(b,a),b}(HTMLElement);</script><template>I'm foo.html!</template></div><div>hello world</div></body></html>
</head><body><div hidden="" by-polymer-bundler=""><script>var Foo=function(a){function b(){return babelHelpers.classCallCheck(this,b),babelHelpers.possibleConstructorReturn(this,(b.__proto__||Object.getPrototypeOf(b)).apply(this,arguments))}return babelHelpers.inherits(b,a),b}(HTMLElement);</script><script>function foo(){alert('foo')}</script><script>function bar() {
alert('bar');
}</script><template>I'm foo.html!</template></div><div>hello world</div><script>(function(){alert('index IIFE')})();</script></body></html>
19 changes: 16 additions & 3 deletions src/test/integration/fixtures/build-simple/expected/polymer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@
"bundle": false,
"js": {
"compile": false,
"minify": false
"minify": {
"exclude": [
"*.html*",
"bar.js"
]
}
},
"css": {
"minify": false
Expand All @@ -27,8 +32,16 @@
"name": "bundled-compiled",
"bundle": true,
"js": {
"compile": true,
"minify": true
"compile": {
"exclude": [
"foo.js"
]
},
"minify": {
"exclude": [
"bar.js"
]
}
},
"css": {
"minify": true
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function bar() {
alert('bar');
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
class Foo extends HTMLElement {
}
</script>
<script src="foo.js"></script>
<script src="bar.js"></script>
<template>
I'm foo.html!
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
function foo(){alert('foo')}
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,10 @@
<link rel="import" href="./foo.html">

<div>hello world</div>

<script>
(function () {
alert('index IIFE');
})();
</script>

3 changes: 3 additions & 0 deletions src/test/integration/fixtures/build-simple/source/bar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function bar() {
alert('bar');
}
2 changes: 2 additions & 0 deletions src/test/integration/fixtures/build-simple/source/foo.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
class Foo extends HTMLElement {
}
</script>
<script src="foo.js"></script>
<script src="bar.js"></script>
<template>
I'm foo.html!
</template>
3 changes: 3 additions & 0 deletions src/test/integration/fixtures/build-simple/source/foo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function foo() {
alert('foo');
}
5 changes: 5 additions & 0 deletions src/test/integration/fixtures/build-simple/source/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@

<div>hello world</div>

<script>
(function () {
alert('index IIFE');
})();
</script>
19 changes: 16 additions & 3 deletions src/test/integration/fixtures/build-simple/source/polymer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
"bundle": false,
"js": {
"compile": false,
"minify": false
"minify": {
"exclude": [
"*.html*",
"bar.js"
]
}
},
"css": {
"minify": false
Expand All @@ -18,8 +23,16 @@
"name": "bundled-compiled",
"bundle": true,
"js": {
"compile": true,
"minify": true
"compile": {
"exclude": [
"foo.js"
]
},
"minify": {
"exclude": [
"bar.js"
]
}
},
"css": {
"minify": true
Expand Down

This file was deleted.