@@ -29,6 +29,7 @@ _ATTRS = {
2929_OUTPUTS = {
3030 "buildinfo_out" : attr .output (),
3131 "js_outs" : attr .output_list (),
32+ "json_outs" : attr .output_list (),
3233 "map_outs" : attr .output_list (),
3334 "typing_maps_outs" : attr .output_list (),
3435 "typings_outs" : attr .output_list (),
@@ -96,10 +97,17 @@ def _ts_project_impl(ctx):
9697 inputs = ctx .files .srcs + depset (transitive = deps_depsets ).to_list () + [ctx .file .tsconfig ]
9798 if ctx .attr .extends :
9899 inputs .extend (ctx .files .extends )
99- outputs = ctx .outputs .js_outs + ctx .outputs .map_outs + ctx .outputs .typings_outs + ctx .outputs .typing_maps_outs
100+
101+ json_outs = ctx .outputs .json_outs
102+
103+ # If there are no predeclared json_outs (probably bc of no .json or no outdir),
104+ # let's try to search for them in srcs so we can declare them as output
105+ if not json_outs :
106+ json_outs = [ctx .actions .declare_file (src .basename , sibling = src ) for src in ctx .files .srcs if src .basename .endswith (".json" )]
107+ outputs = json_outs + ctx .outputs .js_outs + ctx .outputs .map_outs + ctx .outputs .typings_outs + ctx .outputs .typing_maps_outs
100108 if ctx .outputs .buildinfo_out :
101109 outputs .append (ctx .outputs .buildinfo_out )
102- runtime_outputs = depset (ctx .outputs .js_outs + ctx .outputs .map_outs )
110+ runtime_outputs = depset (json_outs + ctx .outputs .js_outs + ctx .outputs .map_outs )
103111 typings_outputs = ctx .outputs .typings_outs + [s for s in ctx .files .srcs if s .path .endswith (".d.ts" )]
104112
105113 if len (outputs ) > 0 :
@@ -390,6 +398,9 @@ def ts_project_macro(
390398 tsconfig = tsconfig ,
391399 extends = extends ,
392400 outdir = outdir ,
401+ # JSON files are special. They are output if outdir is set since tsc will
402+ # copy them to outdir. Otherwise they are kind of both.
403+ json_outs = [_join (outdir , f ) for f in srcs if f .endswith (".json" )] if outdir and not emit_declaration_only else [],
393404 js_outs = _out_paths (srcs , outdir , ".js" ) if not emit_declaration_only else [],
394405 map_outs = _out_paths (srcs , outdir , ".js.map" ) if source_map and not emit_declaration_only else [],
395406 typings_outs = _out_paths (srcs , outdir , ".d.ts" ) if declaration or composite else [],
0 commit comments