Skip to content

Commit

Permalink
Expose a target //:foo_tsconfig.json for a ts_library at //:foo
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 168047566
  • Loading branch information
Typescript Team authored and alexeagle committed Sep 12, 2017
1 parent c462e46 commit 85f865b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,7 @@ ts_library = rule(
# root BUILD file.
"node_modules": attr.label(default = Label("@//:node_modules")),
}),
outputs = {
"tsconfig": "%{name}_tsconfig.json"
}
)
Original file line number Diff line number Diff line change
Expand Up @@ -187,40 +187,39 @@ def compile_ts(ctx,
# in Chrome's chrome://tracing/ UI.
perf_trace = False

if has_sources:
compilation_inputs = input_declarations + extra_dts_files + srcs
tsickle_externs_path = tsickle_externs[0] if tsickle_externs else None
compilation_inputs = input_declarations + extra_dts_files + srcs
tsickle_externs_path = tsickle_externs[0] if tsickle_externs else None

# Calculate allowed dependencies for strict deps enforcement.
allowed_deps = srcs[:] # A target's sources may depend on each other.
for dep in ctx.attr.deps:
if hasattr(dep, "typescript"):
allowed_deps += dep.typescript.declarations
allowed_deps += extra_dts_files

tsconfig_json_es6 = ctx.new_file(ctx.label.name + "_tsconfig.json")
tsconfig_es6 = tsc_wrapped_tsconfig(
ctx,
compilation_inputs,
srcs,
jsx_factory=jsx_factory,
tsickle_externs=tsickle_externs_path,
type_blacklisted_declarations=type_blacklisted_declarations,
allowed_deps=allowed_deps)
# Do not produce declarations in ES6 mode, tsickle cannot produce correct
# .d.ts (or even errors) from the altered Closure-style JS emit.
tsconfig_es6["compilerOptions"]["declaration"] = False
outputs = transpiled_closure_js + tsickle_externs
if perf_trace:
perf_trace_file = ctx.new_file(ctx.label.name + ".es6.trace")
tsconfig_es6["bazelOptions"]["perfTracePath"] = perf_trace_file.path
outputs.append(perf_trace_file)
files += [perf_trace_file]
ctx.file_action(output=tsconfig_json_es6,
content=json_marshal(tsconfig_es6))
# Calculate allowed dependencies for strict deps enforcement.
allowed_deps = srcs[:] # A target's sources may depend on each other.
for dep in ctx.attr.deps:
if hasattr(dep, "typescript"):
allowed_deps += dep.typescript.declarations
allowed_deps += extra_dts_files

tsconfig_es6 = tsc_wrapped_tsconfig(
ctx,
compilation_inputs,
srcs,
jsx_factory=jsx_factory,
tsickle_externs=tsickle_externs_path,
type_blacklisted_declarations=type_blacklisted_declarations,
allowed_deps=allowed_deps)
# Do not produce declarations in ES6 mode, tsickle cannot produce correct
# .d.ts (or even errors) from the altered Closure-style JS emit.
tsconfig_es6["compilerOptions"]["declaration"] = False
outputs = transpiled_closure_js + tsickle_externs
if perf_trace:
perf_trace_file = ctx.new_file(ctx.label.name + ".es6.trace")
tsconfig_es6["bazelOptions"]["perfTracePath"] = perf_trace_file.path
outputs.append(perf_trace_file)
files += [perf_trace_file]
ctx.file_action(output=ctx.outputs.tsconfig,
content=json_marshal(tsconfig_es6))

inputs = compilation_inputs + [tsconfig_json_es6]
compile_action(ctx, inputs, outputs, tsconfig_json_es6.path)
if has_sources:
inputs = compilation_inputs + [ctx.outputs.tsconfig]
compile_action(ctx, inputs, outputs, ctx.outputs.tsconfig.path)

devmode_manifest = ctx.new_file(ctx.label.name + ".es5.MF")
tsconfig_json_es5 = ctx.new_file(ctx.label.name + "_es5_tsconfig.json")
Expand Down

0 comments on commit 85f865b

Please sign in to comment.