From 535fa51ba1c7dbd737fca0d69f734b6919ea6863 Mon Sep 17 00:00:00 2001 From: Jason Bedard Date: Tue, 6 Oct 2020 14:34:23 -0700 Subject: [PATCH] fix(typescript): specify rootDir as absolute path Also allow non-ts files across src/bin dir, since they are not emitted we don't need the rootdir calculation to take them into account. This lets the Angular compiler accept .ts sources from source dir even if the css inputs are generated. --- packages/typescript/internal/ts_project.bzl | 25 +++++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/packages/typescript/internal/ts_project.bzl b/packages/typescript/internal/ts_project.bzl index 2280c4d0c6..19508b2985 100644 --- a/packages/typescript/internal/ts_project.bzl +++ b/packages/typescript/internal/ts_project.bzl @@ -76,6 +76,10 @@ def _join(*elements): return "/".join(segments) return "." +def _is_ts_file(file): + ext = file.extension + return ext == "js" or ext == "mjs" or ext == "ts" or ext == "tsx" or ext == "json" + def _ts_project_impl(ctx): arguments = ctx.actions.args() execution_requirements = {} @@ -89,13 +93,20 @@ def _ts_project_impl(ctx): execution_requirements["worker-key-mnemonic"] = "TsProject" progress_prefix = "Compiling TypeScript project (worker mode)" - generated_srcs = False + has_generated = None + has_source = None + root_dir_pre = None for src in ctx.files.srcs: - if src.is_source: - if generated_srcs: - fail("srcs cannot be a mix of generated files and source files") - else: - generated_srcs = True + if _is_ts_file(src): + if src.is_source: + has_source = src.path + root_dir_pre = src.root.path + else: + has_generated = src.path + root_dir_pre = ctx.bin_dir.path + + if has_source and has_generated: + fail("srcs cannot be a mix of generated files and source files: %s, %s" % (has_generated, has_source)) # Add user specified arguments *before* rule supplied arguments arguments.add_all(ctx.attr.args) @@ -107,7 +118,7 @@ def _ts_project_impl(ctx): _join(ctx.bin_dir.path, ctx.label.package, ctx.attr.out_dir), "--rootDir", _join( - ctx.bin_dir.path if generated_srcs else None, + root_dir_pre, ctx.label.package, ctx.attr.root_dir, ),