[TS/Bazel] Minor improvements to typescript.bzl (#7300)

* Move reflection_ts_fbs into a separate directory (#7342)

Right now, reflection_ts_fbs target is in reflection/BUILD.bazel.

This is not ideal because reflection:reflection_fbs_schema is referenced
from :flatc in the root. Thus, for any Bazel projects that want to
include flatbuffers, they need to include npm / yarn_install and nodejs
support all because reflection/BUILD.bazel loads typescript.bzl and that
requires all TypeScript things.

This PR separated that target into a different subdirectory, freeing
root BUILD.bazel from that dependency.

* Minor improvements to typescript.bzl

* Uses @...// dependencies so that flatbuffers can actually
  be used as an external repo (had forgotten to upstream this earlier).
* Allows using flatbuffer_ts_library to generate reflection schemas
  in the same way that flatbuffer_cc_library does (but default it
  to off to avoid behavioral changes).
* Pass through a package_name attribute to flatbuffer_ts_library to
  allow non-relative imports of generated typescript code.

Co-authored-by: Liu Liu <i@liuliu.me>
This commit is contained in:
James Kuszmaul
2022-08-05 22:04:05 -07:00
committed by GitHub
parent 987bebe678
commit 28e858c855
3 changed files with 50 additions and 14 deletions

16
reflection/ts/BUILD.bazel Normal file
View File

@@ -0,0 +1,16 @@
load("//:typescript.bzl", "flatbuffer_ts_library")
genrule(
name = "copy_schema_to_folder",
srcs = ["//reflection:reflection_fbs_schema"],
outs = ["reflection.fbs"],
cmd = "cp $< $@",
)
flatbuffer_ts_library(
name = "reflection_ts_fbs",
package_name = "flatbuffers_reflection",
srcs = [":reflection.fbs"],
include_reflection = False,
visibility = ["//visibility:public"],
)