-
Notifications
You must be signed in to change notification settings - Fork 520
/
Copy pathBUILD.bazel
77 lines (67 loc) · 2.21 KB
/
BUILD.bazel
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# Demonstrate and test the workaround for running build/test actions in the output directory
# Needed for tools like react-scripts and maybe vue-cli which don't allow specifying a path to
# the project when you call them.
# See https://github.com/bazelbuild/rules_nodejs/issues/1840
load("@build_bazel_rules_nodejs//:index.bzl", "generated_file_test", "nodejs_binary", "nodejs_test", "npm_package_bin")
# Trivial tool that expects to run in source directory under the package
nodejs_binary(
name = "tool_cp",
entry_point = "cp.js",
)
# TODO: figure out why this suddenly stopped producing package.json output
# https://github.com/bazelbuild/rules_nodejs/issues/3328
i3328 = ["fix-windows"]
# A tool like react-scripts needs to run in the output directory since it writes outputs
# to $pwd/build
# That means it also needs to find inputs in that directory.
# So we copy all the inputs it needs.
_package_segments = len(package_name().split("/"))
npm_package_bin(
name = "do_copy",
outs = ["package.json"],
# We have to compensate for the changed directory, adapting other arguments
# to reach back to parent directory
args = ["/".join([".."] * _package_segments + ["$@"])],
chdir = package_name(),
data = ["_package.json"],
exit_code_out = "exit.code",
stdout = "do_copy.log",
tags = i3328,
tool = ":tool_cp",
)
generated_file_test(
name = "exit_code_test",
src = "exit_code_test.golden",
generated = ":exit.code",
tags = i3328,
)
# Trivial tool to mock react-scripts
nodejs_binary(
name = "tool_bin",
entry_point = "tool.js",
)
# This tool is like react-scripts and wants to run in our directory
# with our package.json, and always writes to "build/app.js
npm_package_bin(
name = "call_tool",
outs = ["build/app.js"],
chdir = "$(RULEDIR)",
data = ["package.json"],
tags = i3328,
tool = ":tool_bin",
)
nodejs_test(
name = "test",
# Also run a test in the output directory
chdir = package_name() + "/build",
data = ["build/app.js"],
entry_point = "test.js",
tags = i3328,
)
nodejs_test(
name = "test_multithread",
chdir = package_name(),
data = ["worker.js"],
entry_point = "multithread.js",
tags = i3328,
)