Skip to content
This repository was archived by the owner on Sep 16, 2021. It is now read-only.

Commit fe1856c

Browse files
committed
Add ts_declaration rule.
1 parent 943f66b commit fe1856c

File tree

3 files changed

+56
-3
lines changed

3 files changed

+56
-3
lines changed

defs.bzl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@
1717
Users should not load files under "/internal"
1818
"""
1919
load("//internal:ts_repositories.bzl", _ts_setup_workspace = "ts_setup_workspace")
20-
load("//internal:build_defs.bzl", _ts_library = "ts_library")
20+
load("//internal:build_defs.bzl", _ts_library = "ts_library", _ts_declaration="ts_declaration")
2121
load("//internal:ts_config.bzl", _ts_config = "ts_config")
2222
load("//internal/devserver:ts_devserver.bzl", _ts_devserver = "ts_devserver_macro")
2323
load("//internal/karma:ts_web_test.bzl", _ts_web_test = "ts_web_test_macro")
2424

2525
ts_setup_workspace = _ts_setup_workspace
2626
ts_library = _ts_library
27+
ts_declaration = _ts_declaration
2728
ts_config = _ts_config
2829
ts_devserver = _ts_devserver
2930
# TODO(alexeagle): make ts_web_test work in google3

internal/build_defs.bzl

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,3 +183,54 @@ ts_library = rule(
183183
"tsconfig": "%{name}_tsconfig.json"
184184
}
185185
)
186+
187+
def _ts_declaration_impl(ctx):
188+
"""Implementation of ts_declaration.
189+
190+
Args:
191+
ctx: the context.
192+
193+
Returns:
194+
the struct returned by the call to compile_ts.
195+
"""
196+
ts_providers = compile_ts(ctx, is_library=False,
197+
compile_action=_compile_action,
198+
devmode_compile_action=_devmode_compile_action,
199+
tsc_wrapped_tsconfig=tsc_wrapped_tsconfig)
200+
return ts_providers_dict_to_struct(ts_providers)
201+
202+
ts_declaration = rule(
203+
_ts_declaration_impl,
204+
attrs = dict(COMMON_ATTRIBUTES, **{
205+
"srcs":
206+
attr.label_list(
207+
allow_files=FileType([
208+
".ts",
209+
".tsx",
210+
]),
211+
mandatory=True,),
212+
213+
# TODO(alexeagle): reconcile with google3: ts_library rules should
214+
# be portable across internal/external, so we need this attribute
215+
# internally as well.
216+
"tsconfig":
217+
attr.label(allow_files = True, single_file = True),
218+
"compiler":
219+
attr.label(
220+
default=get_tsc(),
221+
single_file=False,
222+
allow_files=True,
223+
executable=True,
224+
cfg="host"),
225+
"supports_workers": attr.bool(default = True),
226+
"tsickle_typed": attr.bool(default = True),
227+
"_tsc_wrapped_deps": attr.label(default = Label("@build_bazel_rules_typescript_tsc_wrapped_deps//:node_modules")),
228+
# @// is special syntax for the "main" repository
229+
# The default assumes the user specified a target "node_modules" in their
230+
# root BUILD file.
231+
"node_modules": attr.label(default = Label("@//:node_modules")),
232+
}),
233+
outputs = {
234+
"tsconfig": "%{name}_tsconfig.json"
235+
}
236+
)

internal/common/compilation.bzl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,9 @@ def compile_ts(ctx,
197197

198198
if hasattr(ctx.attr,'tsickle_typed') and ctx.attr.tsickle_typed:
199199
if has_sources and ctx.attr.runtime != "nodejs":
200-
# Note: setting this variable controls whether tsickle is run at all.
201-
tsickle_externs = [ctx.new_file(ctx.label.name + ".externs.js")]
200+
if is_library or ctx.attr.generate_externs:
201+
# Note: setting this variable controls whether tsickle is run at all.
202+
tsickle_externs = [ctx.new_file(ctx.label.name + ".externs.js")]
202203

203204
dep_declarations = _collect_dep_declarations(ctx)
204205
input_declarations = dep_declarations.transitive + src_declarations

0 commit comments

Comments
 (0)