Skip to content

unify CLI & API under minify()#1811

Merged
alexlamsl merged 24 commits intomishoo:masterfrom
alexlamsl:minify
Apr 15, 2017
Merged

unify CLI & API under minify()#1811
alexlamsl merged 24 commits intomishoo:masterfrom
alexlamsl:minify

Conversation

@alexlamsl
Copy link
Copy Markdown
Collaborator

@alexlamsl alexlamsl commented Apr 13, 2017

  • rename screw_ie8 to ie8
  • rename mangle.except to mangle.reserved
  • rename mangle.properties.ignore_quoted to mangle.properties.keep_quoted
  • compact sourceMap options
  • more stringent verification on input options
  • toplevel shorthands
    • ie8
    • keep_fnames
    • toplevel
    • warnings
  • support arrays and unquoted string values on CLI
  • drop fromString from minify()
    • minify() no longer handles any fs operations
  • unify order of operations for mangle_properties() on CLI & API
    • bin/uglifyjs used to mangle_properties() before even Compressor
    • minify() used to mangle_properties() after Compressor but before mangle_names()
    • both will now do Compressor, mangle_names() then mangle_properties()
  • options.parse / --parse for parser options beyond bare_returns
  • add mangle.properties.builtins to disable built-in reserved list
    • disable with --mangle-props builtins on CLI
  • warnings now off by default
  • add --warn and --verbose on CLI
  • drop --enclose
  • drop --export-all
  • drop --reserved-file
    • use --mangle reserved instead
  • drop --reserve-domprops
    • enabled by default, disable with --mangle-props domprops
  • drop --prefix
    • use --source-map base instead
  • drop --lint
  • remove bin/extract-props.js
  • limit exposure of internal APIs
  • update documentations

closes #96
closes #102
closes #136
closes #166
closes #243
closes #254
closes #261
closes #311
closes #700
closes #748
closes #912
closes #1072
closes #1366
fixes #101
fixes #123
fixes #124
fixes #263
fixes #379
fixes #419
fixes #423
fixes #461
fixes #465
fixes #576
fixes #737
fixes #772
fixes #958
fixes #1036
fixes #1142
fixes #1175
fixes #1220
fixes #1223
fixes #1280
fixes #1359
fixes #1368

@alexlamsl
Copy link
Copy Markdown
Collaborator Author

  • deprecated fromString in minify()
    • minify() no longer handles any fs operations
  • unify order of operations for mangle_properties() on CLI & API
    • bin/uglifyjs used to mangle_properties() before even Compressor
    • minify() used to mangle_properties() after Compressor but before mangle_names()
    • both will now do Compressor, mangle_names() then mangle_properties()

@kzc
Copy link
Copy Markdown
Contributor

kzc commented Apr 13, 2017

Ambitious PR!

Is there a doc for the source map options?

--source-map [options]

What do you plan to do with this misnamed CLI option which is related to mangle-props, not mangle?

--mangle-regex                Only mangle property names matching the regex

@alexlamsl
Copy link
Copy Markdown
Collaborator Author

Is there a doc for the source map options?

Will need to update README.md at some point... 😅

What do you plan to do with this misnamed CLI option which is related to mangle-props, not mangle?

Haven't done those yet, but basically I'll group them all under --mangle-props like I did with --source-map

@kzc
Copy link
Copy Markdown
Contributor

kzc commented Apr 13, 2017

So just to confirm, each module will only get the options pertinent to it rather than the topmost options reference?

i.e., compress.js will only get options.compress, mangle.js scope.js will only get options.mangle, etc?

Some options like warnings are cross concern. How will stuff like that be handled?

Edit: I guess parser.js could finally get its own options now.

@alexlamsl
Copy link
Copy Markdown
Collaborator Author

So just to confirm, each module will only get the options pertinent to it rather than the topmost options reference?

Yes - I handled the cross-domain options with shorthands at the moment, and have minify() propagate those into compress, mangle and output as applicable.

warnings is a special case in that it is actually AST_Node.warn_function which needs to be overridden appropriately. I've handled that for minify() and bin/uglifyjs, so they will output as an array and to stderr respectively.

@kzc
Copy link
Copy Markdown
Contributor

kzc commented Apr 13, 2017

Any reason why not pass the topmost options reference to all modules?

Compress could benefit by seeing an option in mangle in certain cases to facilitate better compression decisions, for example.

@alexlamsl
Copy link
Copy Markdown
Collaborator Author

Any reason why not pass the topmost options reference to all modules?

Just a matter of whether I can manage those changes. 😅

Once I'm comfortable with the current batch, I'll see if I can pass the common options to every stage.

@alexlamsl
Copy link
Copy Markdown
Collaborator Author

Edit: I guess parser.js could finally get its own options now.

Oops, I did forget to mention that in the commit logs, didn't I?

  • options.parse / --parse for parser options beyond bare_returns

- refactor `screw_ie8` to `ie8`
- compact `sourceMap` options
- more stringent verification on input `options`
- toplevel shorthands
  - `ie8`
  - `keep_fnames`
  - `toplevel`
- deprecated `fromString` in `minify()`
  - `minify()` no longer handles any `fs` operations
- unify order of operations for `mangle_properties()` on CLI & API
  - `bin/uglifyjs` used to `mangle_properties()` before even `Compressor`
  - `minify()` used to `mangle_properties()` after `Compressor` but before `mangle_names()`
  - both will now do `Compressor`, `mangle_names()` then `mangle_properties()`
- `options.parse` / `--parse` for parser options beyond `bare_returns`

closes mishoo#96
closes mishoo#1366
fixes mishoo#124
fixes mishoo#263
fixes mishoo#379
fixes mishoo#423
fixes mishoo#576
fixes mishoo#737
fixes mishoo#958
fixes mishoo#1036
fixes mishoo#1175
fixes mishoo#1220
fixes mishoo#1223
fixes mishoo#1280
@alexlamsl
Copy link
Copy Markdown
Collaborator Author

@kzc 4a927b0 shows the current progress with bin/uglifyjs, alongside with source-map documentation as requested in #1811 (comment)

shortcut for `options.compress.warnings="verbose"`
README.md Outdated
--config-file <file> Read `minify()` options from JSON file.
-d --define <expr>[=value] Global definitions.
--ie8 Support non-standard Internet Explorer 8.
Equivalent to setting `screw_ie8: false` in `minify()`
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is screw_ie8 still a minify option?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

screw_ie8 does not exist within the codebase anymore - this part of the documentation has been updated in a subsequent commit as well.

@kzc
Copy link
Copy Markdown
Contributor

kzc commented Apr 14, 2017

I'll see if I can pass the common options to every stage.

I'm not so sure now if it's a good idea to pass topmost options to every stage. Put the idea on hold unless you think it has some merit and will not impact maintainability or performance.

@alexlamsl
Copy link
Copy Markdown
Collaborator Author

I'm not so sure now if it's a good idea to pass topmost options to every stage. Put the idea on hold unless you think it has some merit and will not impact maintainability or performance.

That's what I meant. Given that the change won't affect user-facing part of minify() (or bin/uglifyjs), it's safe to consider in a latter PR.

@alexlamsl
Copy link
Copy Markdown
Collaborator Author

So the items left to consider for bin/uglifyjs thus this PR are:

  • --lint (anybody saw uglify and thought it's about lint?)
  • --reserved-file
  • --reserve-domprops (great - we can't even agree on past or present tense)
  • --name-cache this should share serialisation code with --reserved-file

The rest are moved into their respective major switches and documented accordingly. And I got rid of that --prefix 3 source-map thing because frankly, I couldn't get my head round on how it's supposed to work intuitively, i.e. just write the path out with --sourcemap base=<path to truncate> and call it a day.

In terms of syntax sugar I've introduced -c warnings=verbose to be a shorthand of -c warnings="verbose" (obviously applies to string values in general). We also accept arrays now, so with the two combined you can do -c pure_funcs=[Math.cos,require] which should be less cumbersome than before. Oh and I deprecated hyphenated shorthands, i.e. -c pure-funcs will no longer work.

@kzc
Copy link
Copy Markdown
Contributor

kzc commented Apr 14, 2017

The linter can go as it doesn't work very well anyway. The angular-specific stuff should be dropped. Get all the flags to agree on tense and plurality.

Shouldn't warnings be moved to its own CLI flag --warnings as it'll apply to all modules? Ditto for warnings as topmost minify() option.

@alexlamsl
Copy link
Copy Markdown
Collaborator Author

Restarting test/ufuzz.js (was ~0.4MFuzz) - not that I expect anything to break, but no harm getting my unpaid intern box to do some work over Easter.

@alexlamsl
Copy link
Copy Markdown
Collaborator Author

Consider adding wording in README to discourage use of the low level API in favor of minify().

Add them around here? https://github.com/mishoo/UglifyJS2#the-hard-way

@kzc
Copy link
Copy Markdown
Contributor

kzc commented Apr 15, 2017

Yes.

Or consider not exporting low level API at all.

@alexlamsl
Copy link
Copy Markdown
Collaborator Author

Or consider not exporting low level API at all.

I'm more than happy to do that, to be honest.

@kzc
Copy link
Copy Markdown
Contributor

kzc commented Apr 15, 2017

Can you expose the low level API to tests only?

@alexlamsl
Copy link
Copy Markdown
Collaborator Author

Can you expose the low level API to tests only?

I'm thinking about that. I guess if I separate those from tools/exports.js into say tools/debug.js we should have them quite handy.

BTW, do you know what's the use for bin/extract-props.js?

remove unsupported features from documentation
@alexlamsl
Copy link
Copy Markdown
Collaborator Author

a70e9b0 removes ones that aren't even used by tests, but otherwise retain the rest albeit no longer mentioned under README.md

My thinking is now that they are declared as unsupported, we can remove them from the export list altogether in a latter PR.

@kzc
Copy link
Copy Markdown
Contributor

kzc commented Apr 15, 2017

BTW, do you know what's the use for bin/extract-props.js?

No idea.

@alexlamsl
Copy link
Copy Markdown
Collaborator Author

... you won't say a word if anything were to happen to it? 😏

@kzc
Copy link
Copy Markdown
Contributor

kzc commented Apr 15, 2017

Fine by me.

@alexlamsl alexlamsl merged commit ec443e4 into mishoo:master Apr 15, 2017
@alexlamsl alexlamsl deleted the minify branch April 15, 2017 15:50
@kzc
Copy link
Copy Markdown
Contributor

kzc commented Apr 15, 2017

@alexlamsl Nice work!

Noticed that there are still references to the low level API in README. Search for "figure_out_scope".

@alexlamsl
Copy link
Copy Markdown
Collaborator Author

@kzc thanks for keeping an eye out as always 😉

Will open a new PR to fix up the docs in a moment.

@alexlamsl alexlamsl mentioned this pull request Apr 15, 2017
@avdg
Copy link
Copy Markdown
Contributor

avdg commented Apr 16, 2017

Wishing to be able to configure the croak parameter in the minify function. For me it's a pain to maintain all these options on multiple versions of uglify :P

@kzc
Copy link
Copy Markdown
Contributor

kzc commented Apr 17, 2017

@alexlamsl How does one craft a 3.x CLI command to do the equivalent of this 2.x command?

$ echo 'var o = {foo:1, bar:2};' | uglifyjs --mangle-props
var o={a:1,b:2};

@alexlamsl
Copy link
Copy Markdown
Collaborator Author

alexlamsl commented Apr 17, 2017

@kzc this works on current master:

$ echo 'var o = {foo:1, bar:2};' | uglifyjs --mangle-props
var o={o:1,v:2};

@kzc
Copy link
Copy Markdown
Contributor

kzc commented Apr 17, 2017

@alexlamsl Nevermind - I didn't npm install to get commander.

@alexlamsl
Copy link
Copy Markdown
Collaborator Author

@kzc ah - I've got bitten by that once on the fuzzing box.

Otherwise I'm always thrilled to nuke node_modules just to watch it shrinks dramatically. 🍿 😎

@azu azu mentioned this pull request May 8, 2017
chris-morgan added a commit to chris-morgan/overture that referenced this pull request Jun 29, 2017
There are actually a couple of improvements along the way, so we might
as well.

uglify-js 3 is a thing, but I’m not going up to it yet because of
certain breaking changes that could potentially cause trouble:
mishoo/UglifyJS#1811
chris-morgan added a commit to chris-morgan/overture that referenced this pull request Jun 30, 2017
There are actually a couple of improvements along the way, so we might
as well.

uglify-js 3 is a thing, but I’m not going up to it yet because of
certain breaking changes that could potentially cause trouble:
mishoo/UglifyJS#1811
chris-morgan added a commit to chris-morgan/overture that referenced this pull request Jun 30, 2017
There are actually a couple of improvements along the way, so we might
as well.

Although uglify-js 3 has [breaking changes], these do not affect
Overture and should not affect anything that uses the Overture
repository.

[breaking changes]: mishoo/UglifyJS#1811
chris-morgan added a commit to chris-morgan/overture that referenced this pull request Jul 4, 2017
There are actually a couple of improvements along the way, so we might
as well.

Although uglify-js 3 has [breaking changes], these do not affect
Overture and should not affect anything that uses the Overture
repository.

[breaking changes]: mishoo/UglifyJS#1811
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment