Skip to content

Commit

Permalink
fix(typescript): add json to ts_project DefaultInfo, fix #1988
Browse files Browse the repository at this point in the history
  • Loading branch information
longlho committed Jul 2, 2020
1 parent c1d4885 commit 3f9dd4b
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/typescript/internal/ts_project.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ _ATTRS = {
_OUTPUTS = {
"buildinfo_out": attr.output(),
"js_outs": attr.output_list(),
"json_outs": attr.output_list(),
"map_outs": attr.output_list(),
"typing_maps_outs": attr.output_list(),
"typings_outs": attr.output_list(),
Expand Down Expand Up @@ -96,10 +97,10 @@ def _ts_project_impl(ctx):
inputs = ctx.files.srcs + depset(transitive = deps_depsets).to_list() + [ctx.file.tsconfig]
if ctx.attr.extends:
inputs.extend(ctx.files.extends)
outputs = ctx.outputs.js_outs + ctx.outputs.map_outs + ctx.outputs.typings_outs + ctx.outputs.typing_maps_outs
outputs = 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(ctx.outputs.js_outs + ctx.outputs.map_outs)
runtime_outputs = depset(ctx.outputs.json_outs + ctx.outputs.js_outs + ctx.outputs.map_outs)
typings_outputs = ctx.outputs.typings_outs + [s for s in ctx.files.srcs if s.path.endswith(".d.ts")]

if len(outputs) > 0:
Expand Down Expand Up @@ -389,6 +390,7 @@ def ts_project_macro(
tsconfig = tsconfig,
extends = extends,
outdir = outdir,
json_outs = [_join(outdir, f) for f in srcs if f.endswith(".json")] if not emit_declaration_only else [],
js_outs = _out_paths(srcs, outdir, ".js") if not emit_declaration_only else [],
map_outs = _out_paths(srcs, outdir, ".js.map") if source_map and not emit_declaration_only else [],
typings_outs = _out_paths(srcs, outdir, ".d.ts") if declaration or composite else [],
Expand Down
27 changes: 27 additions & 0 deletions packages/typescript/test/ts_project/json/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
load("@build_bazel_rules_nodejs//:index.bzl", "generated_file_test")
load("//packages/typescript:index.bzl", "ts_project")

SRCS = glob(["**/*.ts*"]) + [
"subdir/foo.json",
"bar.json",
]

ts_project(
name = "tsconfig",
srcs = SRCS,
outdir = "foobar",
)

generated_file_test(
name = "test-subdir",
src = "foo.golden.json",
# Refers to the output from ts_project above
generated = ":foobar/subdir/foo.json",
)

generated_file_test(
name = "test",
src = "bar.golden.json",
# Refers to the output from ts_project above
generated = ":foobar/bar.json",
)
3 changes: 3 additions & 0 deletions packages/typescript/test/ts_project/json/bar.golden.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "bar"
}
3 changes: 3 additions & 0 deletions packages/typescript/test/ts_project/json/bar.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "bar"
}
3 changes: 3 additions & 0 deletions packages/typescript/test/ts_project/json/foo.golden.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "json"
}
4 changes: 4 additions & 0 deletions packages/typescript/test/ts_project/json/subdir/a.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const a: string = 'hello';
import {name} from './foo.json'
export {name} from '../bar.json'
export const jsonName = name
3 changes: 3 additions & 0 deletions packages/typescript/test/ts_project/json/subdir/foo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "json"
}
6 changes: 6 additions & 0 deletions packages/typescript/test/ts_project/json/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"compilerOptions": {
"types": [],
"resolveJsonModule": true
}
}

0 comments on commit 3f9dd4b

Please sign in to comment.