diff --git a/docs/Built-ins.md b/docs/Built-ins.md
index 9a49109929..4f8d47f2cb 100755
--- a/docs/Built-ins.md
+++ b/docs/Built-ins.md
@@ -1859,7 +1859,7 @@ Other attributes
npm_package_bin(tool, package, package_bin, data, env, outs, args, stderr, stdout, exit_code_out,
- output_dir, link_workspace_root, chdir, kwargs)
+ output_dir, link_workspace_root, chdir, silent_on_success, kwargs)
Run an arbitrary npm package binary (e.g. a program under node_modules/.bin/*) under Bazel.
@@ -2028,6 +2028,13 @@ npm_package_bin(
Defaults to `None`
+silent_on_success
+
+produce no output on stdout nor stderr when program exits with status code 0.
+This makes node binaries match the expected bazel paradigm.
+
+Defaults to `False`
+
kwargs
additional undocumented keyword args
diff --git a/docs/Rollup.md b/docs/Rollup.md
index 6279a1800c..963393e974 100755
--- a/docs/Rollup.md
+++ b/docs/Rollup.md
@@ -198,8 +198,8 @@ rollup_bundle(
rollup_bundle(name, args, config_file, deps, entry_point, entry_points, format, link_workspace_root,
- output_dir, rollup_bin, rollup_worker_bin, silent, sourcemap, srcs, stamp,
- supports_workers)
+ output_dir, rollup_bin, rollup_worker_bin, silent, silent_on_success, sourcemap, srcs,
+ stamp, supports_workers)
Runs the rollup.js CLI under Bazel.
@@ -353,6 +353,15 @@ is a more Bazel-idiomatic experience, however could cause rollup to drop importa
Defaults to `False`
+silent_on_success
+
+(*Boolean*): Even stronger than --silent, defaults to False.
+
+Since the build still emits some texted, even when passed --silent, this uses the same flag as npm_package_bin to
+supress all output on sucess.
+
+Defaults to `False`
+
sourcemap
(*String*): Whether to produce sourcemaps.
diff --git a/docs/TypeScript.md b/docs/TypeScript.md
index 2c3b4610c8..74271f8400 100755
--- a/docs/TypeScript.md
+++ b/docs/TypeScript.md
@@ -231,7 +231,7 @@ for more details about the trade-offs between the two rules.
Some TypeScript options affect which files are emitted, and Bazel wants to know these ahead-of-time.
So several options from the tsconfig file must be mirrored as attributes to ts_project.
-See https://www.typescriptlang.org/tsconfig for a listing of the TypeScript options.
+See https://www.typescriptlang.org/v2/en/tsconfig for a listing of the TypeScript options.
Any code that works with `tsc` should work with `ts_project` with a few caveats:
diff --git a/internal/node/launcher.sh b/internal/node/launcher.sh
index e7f05ab481..886561e760 100644
--- a/internal/node/launcher.sh
+++ b/internal/node/launcher.sh
@@ -185,6 +185,8 @@ for ARG in ${ALL_ARGS[@]+"${ALL_ARGS[@]}"}; do
--bazel_capture_stderr=*) STDERR_CAPTURE="${PWD}/${ARG#--bazel_capture_stderr=}" ;;
# Captures the exit code of the node process to the file specified
--bazel_capture_exit_code=*) EXIT_CODE_CAPTURE="${PWD}/${ARG#--bazel_capture_exit_code=}" ;;
+ # Outputs nothing on success
+ --bazel_silent_on_success=*) SILENT_ON_SUCCESS=true ;;
# Disable the node_loader.js monkey patches for require()
# Note that this means you need an explicit runfiles helper library
# This flag is now a no-op since the default is also false
@@ -338,6 +340,17 @@ else
fi
fi
+if [ "${SILENT_ON_SUCCESS:-}" = true ]; then
+ if [[ -z "${STDOUT_CAPTURE}" ]]; then
+ STDOUT_CAPTURE_IS_NOT_AN_OUTPUT=true
+ STDOUT_CAPTURE=$(mktemp)
+ fi
+ if [[ -z "${STDERR_CAPTURE}" ]]; then
+ STDERR_CAPTURE_IS_NOT_AN_OUTPUT=true
+ STDERR_CAPTURE=$(mktemp)
+ fi
+fi
+
# The EXPECTED_EXIT_CODE lets us write bazel tests which assert that
# a binary fails to run. Otherwise any failure would make such a test
# fail before we could assert that we expected that failure.
@@ -362,6 +375,23 @@ _int() {
kill -INT "${child}" 2>/dev/null
}
+_exit() {
+ EXIT_CODE=$?
+
+ if [[ "$EXIT_CODE" != 0 ]]; then
+ if [ ${STDOUT_CAPTURE_IS_NOT_AN_OUTPUT} = true ]; then
+ cat "$STDOUT_CAPTURE"
+ rm "$STDOUT_CAPTURE"
+ fi
+ if [ ${STDERR_CAPTURE_IS_NOT_AN_OUTPUT} = true ]; then
+ cat "$STDERR_CAPTURE"
+ rm "$STDERR_CAPTURE"
+ fi
+ fi
+
+ exit $EXIT_CODE
+}
+
# Execute the main program
if [[ -n "$NODE_WORKING_DIR" ]]; then
cd "$NODE_WORKING_DIR"
@@ -380,6 +410,7 @@ fi
readonly child=$!
trap _term SIGTERM
trap _int SIGINT
+trap _exit EXIT
wait "${child}"
# Remove trap after first signal has been receieved and wait for child to exit
# (first wait returns immediatel if SIGTERM is received while waiting). Second
diff --git a/internal/node/npm_package_bin.bzl b/internal/node/npm_package_bin.bzl
index 3d7d0847c5..4bdb1de0c5 100644
--- a/internal/node/npm_package_bin.bzl
+++ b/internal/node/npm_package_bin.bzl
@@ -17,6 +17,7 @@ _ATTRS = {
"link_workspace_root": attr.bool(),
"output_dir": attr.bool(),
"outs": attr.output_list(),
+ "silent_on_success": attr.bool(),
"stderr": attr.output(),
"stdout": attr.output(),
"tool": attr.label(
@@ -91,6 +92,7 @@ def _impl(ctx):
stdout = ctx.outputs.stdout,
stderr = ctx.outputs.stderr,
exit_code_out = ctx.outputs.exit_code_out,
+ silent_on_success = ctx.attr.silent_on_success,
link_workspace_root = ctx.attr.link_workspace_root,
)
files = outputs + tool_outputs
@@ -118,6 +120,7 @@ def npm_package_bin(
output_dir = False,
link_workspace_root = False,
chdir = None,
+ silent_on_success = False,
**kwargs):
"""Run an arbitrary npm package binary (e.g. a program under node_modules/.bin/*) under Bazel.
@@ -146,6 +149,8 @@ def npm_package_bin(
exit_code_out: set to capture the exit code of the binary to a file, which can later be used as an input to another target
subject to the same semantics as `outs`. Note that setting this will force the binary to exit 0.
If the binary creates outputs and these are declared, they must still be created
+ silent_on_success: produce no output on stdout nor stderr when program exits with status code 0.
+ This makes node binaries match the expected bazel paradigm.
args: Command-line arguments to the tool.
@@ -239,5 +244,6 @@ def npm_package_bin(
output_dir = output_dir,
tool = tool,
link_workspace_root = link_workspace_root,
+ silent_on_success = silent_on_success,
**kwargs
)
diff --git a/internal/node/test/BUILD.bazel b/internal/node/test/BUILD.bazel
index 5b2195cb5c..d50aa85fda 100644
--- a/internal/node/test/BUILD.bazel
+++ b/internal/node/test/BUILD.bazel
@@ -267,6 +267,21 @@ generated_file_test(
generated = ":minified.stdout.js",
)
+# target that shouldn't print anything on stdout nor stderr when built even through the binary does
+npm_package_bin(
+ name = "loud_binary",
+ args = [
+ "$(execpath terser_input_with_diagnostics.js)",
+ "--compress",
+ "--verbose",
+ "--warn",
+ ],
+ data = ["terser_input_with_diagnostics.js"],
+ output_dir = True,
+ package = "terser",
+ silent_on_success = True,
+)
+
# capture stderr to diagnostics.out, then analyze it in terser_diagnostics_stats printing some stats
# stdout is captured into greeter.min.js (again, without the --output $@ flags)
# the exit code is also capture to a file with exit_code_out, allowing downstream actions to read it
diff --git a/internal/providers/node_runtime_deps_info.bzl b/internal/providers/node_runtime_deps_info.bzl
index e51ce45da9..dd55b28bd5 100644
--- a/internal/providers/node_runtime_deps_info.bzl
+++ b/internal/providers/node_runtime_deps_info.bzl
@@ -127,6 +127,10 @@ def run_node(ctx, inputs, arguments, executable, chdir = None, **kwargs):
add_arg(arguments, "--bazel_capture_exit_code=%s" % exit_code_file.path)
outputs = outputs + [exit_code_file]
+ silent_on_success = kwargs.pop("silent_on_success", False)
+ if silent_on_success:
+ add_arg(arguments, "--bazel_silent_on_success=1")
+
if chdir:
add_arg(arguments, "--bazel_node_working_dir=" + chdir)
diff --git a/packages/rollup/rollup_bundle.bzl b/packages/rollup/rollup_bundle.bzl
index 3cdbd565a3..0689f83cbe 100644
--- a/packages/rollup/rollup_bundle.bzl
+++ b/packages/rollup/rollup_bundle.bzl
@@ -138,6 +138,13 @@ Otherwise, the outputs are assumed to be a single file.
Using --silent can cause rollup to [ignore errors/warnings](https://github.com/rollup/rollup/blob/master/docs/999-big-list-of-options.md#onwarn)
which are only surfaced via logging. Since bazel expects printing nothing on success, setting silent to True
is a more Bazel-idiomatic experience, however could cause rollup to drop important warnings.
+""",
+ ),
+ "silent_on_success": attr.bool(
+ doc = """Even stronger than --silent, defaults to False.
+
+Since the build still emits some texted, even when passed --silent, this uses the same flag as npm_package_bin to
+supress all output on sucess.
""",
),
"sourcemap": attr.string(
@@ -345,6 +352,7 @@ def _rollup_bundle(ctx):
execution_requirements = execution_requirements,
env = {"COMPILATION_MODE": ctx.var["COMPILATION_MODE"]},
link_workspace_root = ctx.attr.link_workspace_root,
+ silent_on_success = ctx.attr.silent_on_success,
)
outputs_depset = depset(outputs)
diff --git a/packages/rollup/test/silent/BUILD.bazel b/packages/rollup/test/silent/BUILD.bazel
new file mode 100644
index 0000000000..143a5be448
--- /dev/null
+++ b/packages/rollup/test/silent/BUILD.bazel
@@ -0,0 +1,15 @@
+load("//packages/rollup:index.bzl", "rollup_bundle")
+
+rollup_bundle(
+ name = "silent",
+ srcs = ["input.js"],
+ entry_points = {"input.js": "silent"},
+ silent = True,
+)
+
+rollup_bundle(
+ name = "silent_on_success",
+ srcs = ["input.js"],
+ entry_points = {"input.js": "silent_on_success"},
+ silent_on_success = True,
+)
diff --git a/packages/rollup/test/silent/input.js b/packages/rollup/test/silent/input.js
new file mode 100644
index 0000000000..702f4280ce
--- /dev/null
+++ b/packages/rollup/test/silent/input.js
@@ -0,0 +1 @@
+console.log("hello");