From 563bad751fb0205960fcaf40ea499e2f24fe94a6 Mon Sep 17 00:00:00 2001 From: Greg Magolan Date: Wed, 30 Oct 2019 00:37:23 -0700 Subject: [PATCH] feat(terser): add `args` attribute to support additional command line arguments Terser only parses minify() args from the config_file so additional arguments such as --comments may be passed to the rule this attribute. See https://github.com/terser/terser#command-line-usage for a list of terser CLI options. --- packages/terser/src/terser_minified.bzl | 8 ++++++++ packages/terser/test/args/BUILD.bazel | 16 ++++++++++++++++ packages/terser/test/args/input.js | 12 ++++++++++++ .../terser/test/args/output.debug.golden.js_ | 12 ++++++++++++ packages/terser/test/args/output.golden.js_ | 8 ++++++++ 5 files changed, 56 insertions(+) create mode 100644 packages/terser/test/args/BUILD.bazel create mode 100644 packages/terser/test/args/input.js create mode 100644 packages/terser/test/args/output.debug.golden.js_ create mode 100644 packages/terser/test/args/output.golden.js_ diff --git a/packages/terser/src/terser_minified.bzl b/packages/terser/src/terser_minified.bzl index b1992ba744..8c3e5aaab1 100644 --- a/packages/terser/src/terser_minified.bzl +++ b/packages/terser/src/terser_minified.bzl @@ -43,6 +43,13 @@ If you want to do this, you can pass a filegroup here.""", allow_files = [".js", ".map", ".mjs"], mandatory = True, ), + "args": attr.string_list( + doc = """Additional command line arguments to pass to terser. + +Terser only parses minify() args from the config file so additional arguments such as `--comments` may +be passed to the rule using this attribute. See https://github.com/terser/terser#command-line-usage for the +full list of terser CLI options.""", + ), "config_file": attr.label( doc = """A JSON file containing Terser minify() options. @@ -156,6 +163,7 @@ def _terser(ctx): ) args.add_all(["--config-file", opts.path]) + args.add_all(ctx.attr.args) ctx.actions.run( inputs = inputs, diff --git a/packages/terser/test/args/BUILD.bazel b/packages/terser/test/args/BUILD.bazel new file mode 100644 index 0000000000..bcedadaa15 --- /dev/null +++ b/packages/terser/test/args/BUILD.bazel @@ -0,0 +1,16 @@ +load("@build_bazel_rules_nodejs//internal/golden_file_test:golden_file_test.bzl", "golden_file_test") +load("@npm_bazel_terser//:index.from_src.bzl", "terser_minified") + +terser_minified( + name = "out.min", + src = "input.js", + args = ["--comments"], + sourcemap = False, +) + +golden_file_test( + name = "test", + actual = "out.min", + golden = "output.golden.js_", + golden_debug = "output.debug.golden.js_", +) diff --git a/packages/terser/test/args/input.js b/packages/terser/test/args/input.js new file mode 100644 index 0000000000..63e0c071e7 --- /dev/null +++ b/packages/terser/test/args/input.js @@ -0,0 +1,12 @@ +/** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ +class A { + doThing() { + console.error('thing'); + } +} diff --git a/packages/terser/test/args/output.debug.golden.js_ b/packages/terser/test/args/output.debug.golden.js_ new file mode 100644 index 0000000000..daf2c758a6 --- /dev/null +++ b/packages/terser/test/args/output.debug.golden.js_ @@ -0,0 +1,12 @@ +/** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ +class A { + doThing() { + console.error("thing"); + } +} \ No newline at end of file diff --git a/packages/terser/test/args/output.golden.js_ b/packages/terser/test/args/output.golden.js_ new file mode 100644 index 0000000000..fb0400fbc3 --- /dev/null +++ b/packages/terser/test/args/output.golden.js_ @@ -0,0 +1,8 @@ +/** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ +class A{doThing(){console.error("thing")}} \ No newline at end of file