Skip to content

Commit 86bef24

Browse files
jbedardalexeagle
authored andcommitted
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.
1 parent 3c11800 commit 86bef24

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

packages/typescript/internal/ts_project.bzl

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ def _join(*elements):
7676
return "/".join(segments)
7777
return "."
7878

79+
def _is_ts_file(file):
80+
ext = file.extension
81+
return ext == "js" or ext == "mjs" or ext == "ts" or ext == "tsx" or ext == "json"
82+
7983
def _ts_project_impl(ctx):
8084
arguments = ctx.actions.args()
8185
execution_requirements = {}
@@ -89,13 +93,20 @@ def _ts_project_impl(ctx):
8993
execution_requirements["worker-key-mnemonic"] = "TsProject"
9094
progress_prefix = "Compiling TypeScript project (worker mode)"
9195

92-
generated_srcs = False
96+
has_generated = None
97+
has_source = None
98+
root_dir_pre = None
9399
for src in ctx.files.srcs:
94-
if src.is_source:
95-
if generated_srcs:
96-
fail("srcs cannot be a mix of generated files and source files")
97-
else:
98-
generated_srcs = True
100+
if _is_ts_file(src):
101+
if src.is_source:
102+
has_source = src.path
103+
root_dir_pre = src.root.path
104+
else:
105+
has_generated = src.path
106+
root_dir_pre = ctx.bin_dir.path
107+
108+
if has_source and has_generated:
109+
fail("srcs cannot be a mix of generated files and source files: %s, %s" % (has_generated, has_source))
99110

100111
# Add user specified arguments *before* rule supplied arguments
101112
arguments.add_all(ctx.attr.args)
@@ -107,7 +118,7 @@ def _ts_project_impl(ctx):
107118
_join(ctx.bin_dir.path, ctx.label.package, ctx.attr.out_dir),
108119
"--rootDir",
109120
_join(
110-
ctx.bin_dir.path if generated_srcs else None,
121+
root_dir_pre,
111122
ctx.label.package,
112123
ctx.attr.root_dir,
113124
),

0 commit comments

Comments
 (0)