Skip to content

Commit

Permalink
fix(typescript): produce .d.ts as default output rather than empty
Browse files Browse the repository at this point in the history
This lets you type-check a ts_project(emit_declaration_only=True) just by building it (its default outputs)

Fixes #2116
  • Loading branch information
Alex Eagle committed Aug 16, 2020
1 parent 1864e0f commit 34a5008
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 4 deletions.
9 changes: 5 additions & 4 deletions packages/typescript/internal/ts_project.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,9 @@ def _ts_project_impl(ctx):
outputs = json_outs + ctx.outputs.js_outs + ctx.outputs.map_outs + ctx.outputs.typings_outs + ctx.outputs.typing_maps_outs
if ctx.outputs.buildinfo_out:
outputs.append(ctx.outputs.buildinfo_out)
runtime_outputs = depset(json_outs + ctx.outputs.js_outs + ctx.outputs.map_outs)
runtime_outputs = json_outs + ctx.outputs.js_outs + ctx.outputs.map_outs
typings_outputs = ctx.outputs.typings_outs + ctx.outputs.typing_maps_outs + [s for s in ctx.files.srcs if s.path.endswith(".d.ts")]
default_outputs_depset = depset(runtime_outputs) if len(runtime_outputs) else depset(typings_outputs)

if len(outputs) > 0:
run_node(
Expand All @@ -139,14 +140,14 @@ def _ts_project_impl(ctx):
# Only the JavaScript outputs are intended for use in non-TS-aware
# dependents.
DefaultInfo(
files = runtime_outputs,
files = default_outputs_depset,
runfiles = ctx.runfiles(
transitive_files = runtime_outputs,
transitive_files = default_outputs_depset,
collect_default = True,
),
),
js_module_info(
sources = runtime_outputs,
sources = depset(runtime_outputs),
deps = ctx.attr.deps,
),
_TsConfigInfo(tsconfigs = depset([ctx.file.tsconfig] + ctx.files.extends, transitive = [
Expand Down
13 changes: 13 additions & 0 deletions packages/typescript/test/ts_project/declaration_only/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
load("@build_bazel_rules_nodejs//:index.bzl", "generated_file_test")
load("//packages/typescript:index.bzl", "ts_project")

ts_project(
declaration = True,
emit_declaration_only = True,
)

generated_file_test(
name = "test",
src = "a.d.ts_",
generated = ":tsconfig",
)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export declare const a: string;
1 change: 1 addition & 0 deletions packages/typescript/test/ts_project/declaration_only/a.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const a: string = '';
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"compilerOptions": {
"declaration": true,
"emitDeclarationOnly": true,
"types": []
}
}

0 comments on commit 34a5008

Please sign in to comment.