-
Notifications
You must be signed in to change notification settings - Fork 127
Cleanup how optimize streams work, in preparation for babel stream #524
Conversation
polymerProject.splitHtml(), | ||
getOptimizeStreams(optimizeOptions), | ||
polymerProject.rejoinHtml() | ||
]).reduce((a: NodeJS.ReadableStream, b: NodeJS.ReadWriteStream) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's extract this into a named function that self-documents:
import {pipeStreams} from './streams';
const sourcesStream = pipeStreams([
polymerProject.sources(),
polymerProject.splitHtml(),
]);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good call
polymerProject.splitHtml(), | ||
getOptimizeStreams(optimizeOptions), | ||
polymerProject.rejoinHtml() | ||
]).reduce((a: NodeJS.ReadableStream, b: NodeJS.ReadWriteStream) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
* OptimizeOptions given. | ||
*/ | ||
export function getOptimizeStreams(optimizeOptions: OptimizeOptions) { | ||
let streams = []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const
@@ -30,6 +30,11 @@ export type FileCB = (error?: any, file?: File) => void; | |||
export type CSSOptimizeOptions = { | |||
stripWhitespace?: boolean; | |||
}; | |||
export interface OptimizeOptions { | |||
htmlMinify?: HTMLMinifierOptions; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not have the nested structure here that we do in BuildOptions? Then in #525 instead of adding a jsCompile
property, you add compile
to the js
property. Or to go further, just get rid of this interface and pass BuildOptions to getOptimizeStreams
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to pass this subset of build options to getOptimizeStreams() to simplify the interface. But I can match the nested structure from BuildOptions if you prefer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, nested looks much cleaner (less mapping and plays much nicer with TS)
@@ -32,6 +32,21 @@ export class BuildCommand implements Command { | |||
|
|||
args = [ | |||
{ | |||
name: 'js-minify', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not so sure about this change. The reason for namespacing flags like html.collapseWhitespace
was to at some point be able to easily map flags to build options. Continuing that pattern would lead to js.minify, css.minify and html.minify.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really dislike the .
in the command line flag, a dash feels much more natural and doesn't break the expected CLI dash-case naming convention. We can still map easily regardless of .
or -
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's that uncommon to use .
when flags map to JSON-like structures. Mapping with -
is harder: does foo-bar-baz
map to foo.bar.baz
, foo.bar-baz
, etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But the user will never know about or use that JSON-like structure, right? If we were maintaining a large set of rules or mapping to an interface that the user was familiar with I would agree, but I don't see the point in breaking our expected naming system by mapping to an internal interface that could change at any time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The user probably will, when we explain that the flags map to the options in polymer.json
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I hadn't assumed we'd use the same options for build()
in polymer.json
.
Can we table this decision then until we start on the polymer.json options? I think that will be a more productive conversation when those options actually exist vs. planning for something we haven't really thought through yet (at least I haven't yet).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can, but the pattern had been set up with that goal in mind. If we defer the discussion can we stick with the current pattern?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure thing, rolling back
discussed and planned out in person, our flags will use this format (https://docs.google.com/document/d/1mD1cVhxdxY-bUsGBX44anC1875Afx7UHue4uRCNVc4o). Updating the BuildOptions to match the planned polymer.json options now.
@justinfagnani comments addressed, PTAL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly fine, though we're changing the options available to pipe through to the minifiers. I had thought that we wanted to expand these options. I want to be sure we're on the right path there.
@@ -44,11 +59,6 @@ export class BuildCommand implements Command { | |||
'additional `<link rel="prefetch">` tags into ' + | |||
'entrypoint and `<link rel="import">` tags into fragments and shell.' | |||
}, | |||
{ | |||
name: 'html.collapseWhitespace', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we deprecate for one release before removing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, collapseWhitespace is only one of many options offered here: https://www.npmjs.com/package/html-minifier
Are we now mapping minify to a specific set of those?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the way command-line-args
works, anyone who is using this will get an error once this is removed. That feels like enough to me, wdyt? Are enough people actually using this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In regards to expanding vs. shrinking these options, we're simply adding a flag to turn a default minify on/off. This doesn't prevent us from supporting custom minify options via this same flag later down the road. (Unless you're suggesting we continue the current scheme with a flag for every possible option). The intention here is to bring us closer to supporting cli options and polymer.json
options, not farther away.
Again, I don't think we should spend too much time going back and forth on how these CLI flags will match the polymer.json
interface, when that interface doesn't even exist yet. I'd much rather discuss that when we do add the polymer.json
interface, either in a design proposal or the PR itself. This won't be going out to users until then.
@justinfagnani PTAL |
@justinfagnani code now matches our new design doc, PTAL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Please squash :)
* Convert build to single build stream (#509) * Convert build to single build stream, add bundled flag * Clarify `--add-prefetch` build flag (#510) * rename confusing --insert-dependency-links flag to --prefetch-dependencies * rename prefetchDepedencies to addPrefetchLinks * rename to insert-prefetch-links * respond to review comments * Cleanup how optimize streams work, in preparation for babel stream (#524) * Cleanup how optimize streams work, in preparation for babel stream * death to lets * redeisn optimize interface * pull stream piping into a helper function * rollback cli dash-case naming * remove unused gulpif * update buildoptions to match planned polymer.json options * add babel to build stream, replace uglify with babili es2015 minifier (#525) * Cleanup how optimize streams work, in preparation for babel stream * add babel to build stream * death to lets * redeisn optimize interface * pull stream piping into a helper function * rollback cli dash-case naming * replace uglify with babili * fix bad merge conflict * fixup js-minify description * remove unused gulpif * update buildoptions to match planned polymer.json options * remove old comment * let to const * add service worker flag to build command (#534) * add service worker flag to build command * reword flags and descriptions * quick reword again * get rid of skiplibcheck * debug to info * Add support for polymer.json build configurations (#545) * Add support for named build permutations * respond to PR feedback * add comments on build function * update logging to be cleaner * update for new naming rules * update polymer-project-config to v1.2.0 * Update CHANGELOG.md * update polymer-build version, update shrinkwrap
This PR addresses two problems:
getOptimizeStreams
to calculate and return the optimize streams that we need.This PR should be a noop functionality-wise, and prepares for a much easier diff in #525.