From c0fcc4f9323624c752bd452cd00c77a1f149375e Mon Sep 17 00:00:00 2001 From: Greg Magolan Date: Mon, 2 Mar 2020 10:01:06 -0800 Subject: [PATCH] feat(rollup): add `args` attribute to rollup_bundle rule Arguments passed to rollup. These can be used to override config file settings. These argument are appended to the command line before all arguments that are always added by the rule such as `--output.dir` or `--output.file`, `--format`, `--config` and `--preserveSymlinks` and also those that are optionally added by the rule such as `--sourcemap`. See rollup CLI docs https://rollupjs.org/guide/en/#command-line-flags for complete list of supported arguments. --- packages/rollup/src/rollup_bundle.bzl | 13 +++++++++++++ packages/rollup/test/sourcemaps/BUILD.bazel | 5 +++++ 2 files changed, 18 insertions(+) diff --git a/packages/rollup/src/rollup_bundle.bzl b/packages/rollup/src/rollup_bundle.bzl index 98722a1854..d41d333746 100644 --- a/packages/rollup/src/rollup_bundle.bzl +++ b/packages/rollup/src/rollup_bundle.bzl @@ -65,6 +65,16 @@ You must not repeat file(s) passed to entry_point/entry_points. # Don't try to constrain the filenames, could be json, svg, whatever allow_files = True, ), + "args": attr.string_list( + doc = """Command line arguments to pass to rollup. Can be used to override config file settings. + +These argument passed on the command line before all arguments that are always added by the +rule such as `--output.dir` or `--output.file`, `--format`, `--config` and `--preserveSymlinks` and +also those that are optionally added by the rule such as `--sourcemap`. + +See rollup CLI docs https://rollupjs.org/guide/en/#command-line-flags for complete list of supported arguments.""", + default = [], + ), "config_file": attr.label( doc = """A rollup.config.js file @@ -286,6 +296,9 @@ def _rollup_bundle(ctx): # See CLI documentation at https://rollupjs.org/guide/en/#command-line-reference args = ctx.actions.args() + # Add user specified arguments *before* rule supplied arguments + args.add_all(ctx.attr.args) + # List entry point argument first to save some argv space # Rollup doc says # When provided as the first options, it is equivalent to not prefix them with --input diff --git a/packages/rollup/test/sourcemaps/BUILD.bazel b/packages/rollup/test/sourcemaps/BUILD.bazel index 836a6ba864..bb8b6d0062 100644 --- a/packages/rollup/test/sourcemaps/BUILD.bazel +++ b/packages/rollup/test/sourcemaps/BUILD.bazel @@ -4,6 +4,11 @@ load("@npm_bazel_rollup//:index.from_src.bzl", "rollup_bundle") rollup_bundle( name = "bundle", srcs = ["s.js"], + # Test existance of args attribute + args = [ + "--environment", + "FOO,BAR:baz", + ], # Use the desugared form to assert that it works entry_points = {"input.js": "bundle"}, sourcemap = "true",