mirror of
https://github.com/roleypoly/roleypoly.git
synced 2025-06-16 09:39:09 +00:00
chore: restructure bazel macros
This commit is contained in:
parent
a33aa3841c
commit
a0b4392b05
54 changed files with 80 additions and 56 deletions
1
hack/bazel/js/BUILD.bazel
Normal file
1
hack/bazel/js/BUILD.bazel
Normal file
|
@ -0,0 +1 @@
|
|||
package(default_visibility = ["//visibility:public"])
|
58
hack/bazel/js/jest.bzl
Normal file
58
hack/bazel/js/jest.bzl
Normal file
|
@ -0,0 +1,58 @@
|
|||
# Copied from https://github.com/bazelbuild/rules_nodejs/blob/stable/examples/jest/jest.bzl
|
||||
# Licensed under Apache-2.0, modifications made:
|
||||
# - improved dependency resolution
|
||||
|
||||
load("@npm//jest-cli:index.bzl", "jest", _jest_test = "jest_test")
|
||||
load("//hack/bazel:utils.bzl", "render_deps")
|
||||
|
||||
DEFAULT_DEPS = [
|
||||
"@npm//ts-jest",
|
||||
"@npm//enzyme",
|
||||
"@npm//enzyme-adapter-react-16",
|
||||
"@npm//@types/enzyme",
|
||||
"@npm//jest-environment-enzyme",
|
||||
"@npm//jsdom",
|
||||
"@npm//jest",
|
||||
"@npm//jest-enzyme",
|
||||
"@npm//jest-styled-components",
|
||||
"@npm//enzyme-to-json",
|
||||
"@npm//react-dom",
|
||||
"@npm//@types/react-dom",
|
||||
"//:tsconfig.json",
|
||||
]
|
||||
|
||||
def _impl_jest_test(name, srcs, deps, jest_config, **kwargs):
|
||||
"A macro around the autogenerated jest_test rule"
|
||||
templated_args = [
|
||||
"--no-cache",
|
||||
"--no-watchman",
|
||||
"--ci",
|
||||
"--no-colors",
|
||||
]
|
||||
templated_args.extend(["--config", "$(rootpath %s)" % jest_config])
|
||||
for src in srcs:
|
||||
templated_args.extend(["--runTestsByPath", "$(rootpath %s)" % src])
|
||||
|
||||
data = [jest_config] + srcs + deps + ["//:jest-reporter.js"]
|
||||
_jest_test(
|
||||
name = name,
|
||||
data = data,
|
||||
templated_args = templated_args,
|
||||
**kwargs
|
||||
)
|
||||
|
||||
# This rule is used specifically to update snapshots via `bazel run`
|
||||
jest(
|
||||
name = "%s.update" % name,
|
||||
data = data,
|
||||
templated_args = templated_args + ["-u"],
|
||||
**kwargs
|
||||
)
|
||||
|
||||
def jest_test(src, deps = []):
|
||||
_impl_jest_test(
|
||||
name = src[1:] + "_test",
|
||||
srcs = native.glob(["*.spec.ts", "*.spec.tsx"]),
|
||||
deps = [src] + render_deps(deps) + DEFAULT_DEPS,
|
||||
jest_config = "//:jest.config.js",
|
||||
)
|
36
hack/bazel/js/proto.bzl
Normal file
36
hack/bazel/js/proto.bzl
Normal file
|
@ -0,0 +1,36 @@
|
|||
load("//src/ts-protoc-gen/rules:index.bzl", "typescript_proto_library")
|
||||
load("@npm//@bazel/typescript:index.bzl", "ts_library")
|
||||
|
||||
def _generalize_pb_imports(name, srcs = [], grpc = False):
|
||||
suffix_match = "pb"
|
||||
if grpc:
|
||||
suffix_match = ""
|
||||
native.genrule(
|
||||
name = name,
|
||||
srcs = srcs,
|
||||
outs = ["index.ts"],
|
||||
cmd = """
|
||||
echo $(SRCS) | tr ' ' '\n' | grep '""" + suffix_match + """\\.js$$' | xargs -l1 -I '{}' basename {} .js | xargs -l1 -I'{}' echo 'export * from "./{}"' > $(location index.ts)
|
||||
""",
|
||||
output_to_bindir = True,
|
||||
)
|
||||
|
||||
def ts_proto(proto, name = "ts", grpc = False):
|
||||
typescript_proto_library(
|
||||
name = name + "_proto",
|
||||
proto = proto,
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
_generalize_pb_imports(
|
||||
grpc = grpc,
|
||||
name = name + "_proto_generalized",
|
||||
srcs = [":" + name + "_proto"],
|
||||
)
|
||||
|
||||
ts_library(
|
||||
name = name,
|
||||
srcs = [":" + name + "_proto_generalized"],
|
||||
deps = [":" + name + "_proto"],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
20
hack/bazel/js/react.bzl
Normal file
20
hack/bazel/js/react.bzl
Normal file
|
@ -0,0 +1,20 @@
|
|||
load("@npm//@bazel/typescript:index.bzl", "ts_library")
|
||||
load("//hack/bazel:utils.bzl", "render_deps")
|
||||
|
||||
def react_library(name, deps = [], **kwargs):
|
||||
ts_library(
|
||||
name = name,
|
||||
srcs = native.glob(
|
||||
[
|
||||
"*.ts",
|
||||
"*.tsx",
|
||||
],
|
||||
exclude = native.glob([
|
||||
"*.spec.ts*",
|
||||
"*.story.tsx",
|
||||
"*.stories.tsx",
|
||||
]),
|
||||
),
|
||||
deps = render_deps(deps),
|
||||
**kwargs
|
||||
)
|
Loading…
Add table
Add a link
Reference in a new issue