Skip to content

Commit 103b665

Browse files
authored
feat: support custom progress messages (#807)
For Angular we fully rely on `ts_project` just with a custom `tsc` executable. We would like to have better distinction between Angular or TypeScript targets. It seems like it would be useful to control the progress message. This would also allow better distinction when e.g. compiling with a different configuration. e.g. we use a transition for Angular to compile with a different compilation mode when shipping to npm
1 parent f332843 commit 103b665

File tree

3 files changed

+40
-19
lines changed

3 files changed

+40
-19
lines changed

docs/rules.md

Lines changed: 10 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ts/private/ts_lib.bzl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,20 @@ https://docs.aspect.build/rulesets/aspect_rules_js/docs/js_library#deps for more
115115
settings in the tsconfig.json file""",
116116
default = True,
117117
),
118+
"build_progress_message": attr.string(
119+
doc = """\
120+
Custom progress message for the build action.
121+
You can use {label} and {tsconfig_path} as substitutions.
122+
""",
123+
default = "Transpiling{emit_part}{type_check_part} TypeScript project {label} [tsc -p {tsconfig_path}]",
124+
),
125+
"isolated_typecheck_progress_message": attr.string(
126+
doc = """\
127+
Custom progress message for the isolated typecheck action.
128+
You can use {label} and {tsconfig_path} as substitutions.
129+
""",
130+
default = "Type-checking TypeScript project {label} [tsc -p {tsconfig_path}]",
131+
),
118132
"validator": attr.label(mandatory = True, executable = True, cfg = "exec"),
119133
"_options": attr.label(
120134
default = "@aspect_rules_ts//ts:options",

ts/private/ts_project.bzl

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,11 @@ See https://github.com/aspect-build/rules_ts/issues/361 for more details.
277277
else:
278278
env["JS_BINARY__STDOUT_OUTPUT_FILE"] = typecheck_output.path
279279

280+
progress_message = ctx.attr.isolated_typecheck_progress_message.format(
281+
label = ctx.label,
282+
tsconfig_path = tsconfig_path,
283+
)
284+
280285
ctx.actions.run(
281286
executable = executable,
282287
inputs = tsc_transitive_inputs_depset,
@@ -285,10 +290,7 @@ See https://github.com/aspect-build/rules_ts/issues/361 for more details.
285290
mnemonic = "TsProjectCheck",
286291
execution_requirements = execution_requirements,
287292
resource_set = resource_set(ctx.attr),
288-
progress_message = "Type-checking TypeScript project %s [tsc -p %s]" % (
289-
ctx.label,
290-
tsconfig_path,
291-
),
293+
progress_message = progress_message,
292294
env = env,
293295
)
294296
else:
@@ -323,6 +325,15 @@ See https://github.com/aspect-build/rules_ts/issues/361 for more details.
323325
tsc_emit_arguments.use_param_file("@%s", use_always = True)
324326
tsc_emit_arguments.set_param_file_format("multiline")
325327

328+
progress_message = ctx.attr.build_progress_message.format(
329+
label = ctx.label,
330+
tsconfig_path = tsconfig_path,
331+
# Internal replacement for the default message; mentioning what is being emitted if not both
332+
emit_part = "" if use_tsc_for_dts and use_tsc_for_js else " (dts)" if use_tsc_for_dts else " (js)",
333+
# Internal replacement for the default message; mention type-checking if done in this action
334+
type_check_part = " & type-checking" if not ctx.attr.isolated_typecheck else "",
335+
)
336+
326337
ctx.actions.run(
327338
executable = executable,
328339
inputs = inputs_depset,
@@ -331,14 +342,7 @@ See https://github.com/aspect-build/rules_ts/issues/361 for more details.
331342
mnemonic = "TsProjectEmit" if ctx.attr.isolated_typecheck else "TsProject",
332343
execution_requirements = execution_requirements,
333344
resource_set = resource_set(ctx.attr),
334-
progress_message = "Transpiling%s%s TypeScript project %s [tsc -p %s]" % (
335-
# Mention what is being emitted if not both
336-
"" if use_tsc_for_dts and use_tsc_for_js else " (dts)" if use_tsc_for_dts else " (js)",
337-
# Mention type-checking if done in this action
338-
" & type-checking" if not ctx.attr.isolated_typecheck else "",
339-
ctx.label,
340-
tsconfig_path,
341-
),
345+
progress_message = progress_message,
342346
env = {
343347
"BAZEL_BINDIR": ctx.bin_dir.path,
344348
},

0 commit comments

Comments
 (0)