Skip to content

Commit

Permalink
fix(typescript): specify rootDir as absolute path
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jbedard authored and Alex Eagle committed Nov 10, 2020
1 parent d977c73 commit 535fa51
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions packages/typescript/internal/ts_project.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand All @@ -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)
Expand All @@ -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,
),
Expand Down

0 comments on commit 535fa51

Please sign in to comment.