From bc59e879a8fb2705ee94b6e970c3254ce5c60e2c Mon Sep 17 00:00:00 2001 From: Tobias Schlatter Date: Mon, 16 Sep 2024 11:19:50 +0200 Subject: [PATCH] RFC: TSC Provider? Idea that came up in https://github.com/aspect-build/rules_ts/pull/693 --- ts/private/ts_lib.bzl | 16 ++-------------- ts/providers.bzl | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 14 deletions(-) create mode 100644 ts/providers.bzl diff --git a/ts/private/ts_lib.bzl b/ts/private/ts_lib.bzl index de940fdb..a31a3786 100644 --- a/ts/private/ts_lib.bzl +++ b/ts/private/ts_lib.bzl @@ -54,10 +54,6 @@ https://docs.aspect.build/rulesets/aspect_rules_js/docs/js_library#deps for more default = 0, values = [-1, 0, 1], ), - "is_typescript_5_or_greater": attr.bool( - doc = "Whether TypeScript version is >= 5.0.0", - default = False, - ), "transpile": attr.int( doc = """\ Whether tsc should be used to produce .js outputs @@ -70,17 +66,10 @@ https://docs.aspect.build/rulesets/aspect_rules_js/docs/js_library#deps for more default = -1, values = [-1, 0, 1], ), - "tsc": attr.label( - doc = "TypeScript compiler binary", - mandatory = True, - executable = True, - cfg = "exec", - ), - "tsc_worker": attr.label( - doc = "TypeScript compiler worker binary", + "tsc_tools": attr.label( mandatory = True, - executable = True, cfg = "exec", + #providers = [TscInfo], ), "tsconfig": attr.label( doc = "tsconfig.json file, see https://www.typescriptlang.org/tsconfig", @@ -92,7 +81,6 @@ https://docs.aspect.build/rulesets/aspect_rules_js/docs/js_library#deps for more settings in the tsconfig.json file""", default = True, ), - "validator": attr.label(mandatory = True, executable = True, cfg = "exec"), "_options": attr.label( default = "@aspect_rules_ts//ts:options", ), diff --git a/ts/providers.bzl b/ts/providers.bzl new file mode 100644 index 00000000..2933992c --- /dev/null +++ b/ts/providers.bzl @@ -0,0 +1,22 @@ +"""Providers for rules_ts.""" + +TscInfo = provider( + doc = """Encapsulates information about a typescript compiler.""" + fields = { + "tsc": "Typescript compiler binary (required)", + "tsc_worker": "Typescript compiler worker", + "validator": "Validator binary (required)", + "is_typescript_5_or_greater": "Whether typescript version is known to be greater than 5.", + }, +) + +def tsc_info(tsc, tsc_worker = None, validator = None, is_typescript_5_or_greater = False): + # TODO: + # - Argument validation + # - Take default validator if it is not set? Is this the right place for it? + return TscInfo( + tsc = tsc, + tsc_worker = tsc_worker, + validator = validator, + is_typescript_5_or_greater = is_typescript_5_or_greater, + )