|
| 1 | +# Copyright 2017 The Bazel Authors. All rights reserved. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +load("@build_bazel_rules_nodejs//:tools/defaults.bzl", "npm_package") |
| 16 | +load("@npm_node_patches//mocha:index.bzl", "mocha_test") |
| 17 | +load("@npm_node_patches//typescript:index.bzl", "tsc") |
| 18 | + |
| 19 | +package(default_visibility = ["//visibility:public"]) |
| 20 | + |
| 21 | +filegroup( |
| 22 | + name = "node-patches", |
| 23 | + srcs = [ |
| 24 | + "package.json", |
| 25 | + ":compile", |
| 26 | + ], |
| 27 | +) |
| 28 | + |
| 29 | +npm_package( |
| 30 | + name = "npm_package", |
| 31 | + srcs = [ |
| 32 | + "README.md", |
| 33 | + ], |
| 34 | + deps = [ |
| 35 | + ":node-patches", |
| 36 | + ], |
| 37 | +) |
| 38 | + |
| 39 | +sources = glob( |
| 40 | + [ |
| 41 | + "src/*.ts", |
| 42 | + ], |
| 43 | + exclude = ["src/*.d.ts"], |
| 44 | +) + ["register.ts"] |
| 45 | + |
| 46 | +tests = glob( |
| 47 | + ["test/**/*.ts"], |
| 48 | + exclude = ["test/**/*.d.ts"], |
| 49 | +) |
| 50 | + |
| 51 | +tsc( |
| 52 | + name = "compile", |
| 53 | + # TODO: we ought to compile tests separately? |
| 54 | + outs = [s.replace(".ts", ext) for ext in [ |
| 55 | + ".js", |
| 56 | + ".d.ts", |
| 57 | + ] for s in sources + tests], |
| 58 | + args = [ |
| 59 | + "-p", |
| 60 | + "$(location tsconfig-bazel.json)", |
| 61 | + "--outDir", |
| 62 | + "$@", |
| 63 | + ], |
| 64 | + data = sources + tests + [ |
| 65 | + "tsconfig-bazel.json", |
| 66 | + "@npm_node_patches//:node_modules", |
| 67 | + ], |
| 68 | +) |
| 69 | + |
| 70 | +test_js = [s.replace(".ts", ".js") for s in tests] |
| 71 | + |
| 72 | +mocha_test( |
| 73 | + name = "unit_test", |
| 74 | + args = ["$(location %s)" % s for s in test_js], |
| 75 | + data = test_js + [s.replace(".ts", ".js") for s in sources] + [ |
| 76 | + "@npm_node_patches//:node_modules", |
| 77 | + ], |
| 78 | + tags = [ |
| 79 | + "fix-windows", |
| 80 | + ], |
| 81 | +) |
0 commit comments