|
| 1 | +load("@npm//@bazel/typescript:index.bzl", "ts_config") |
| 2 | +load("@build_bazel_rules_nodejs//:index.bzl", "js_library") |
| 3 | +load("//src/dev/bazel:index.bzl", "jsts_transpiler", "pkg_npm", "pkg_npm_types", "ts_project") |
| 4 | +load("@build_bazel_rules_nodejs//internal/node:node.bzl", "nodejs_binary") |
| 5 | +load("@build_bazel_rules_nodejs//:index.bzl", "directory_file_path") |
| 6 | + |
| 7 | +PKG_BASE_NAME = "kbn-type-summarizer" |
| 8 | +PKG_REQUIRE_NAME = "@kbn/type-summarizer" |
| 9 | + |
| 10 | +SOURCE_FILES = glob( |
| 11 | + [ |
| 12 | + "src/**/*.ts", |
| 13 | + ], |
| 14 | + exclude = [ |
| 15 | + "**/*.test.*" |
| 16 | + ], |
| 17 | +) |
| 18 | + |
| 19 | +SRCS = SOURCE_FILES |
| 20 | + |
| 21 | +filegroup( |
| 22 | + name = "srcs", |
| 23 | + srcs = SRCS, |
| 24 | +) |
| 25 | + |
| 26 | +NPM_MODULE_EXTRA_FILES = [ |
| 27 | + "package.json", |
| 28 | + "README.md", |
| 29 | +] |
| 30 | + |
| 31 | +RUNTIME_DEPS = [ |
| 32 | + "@npm//@babel/runtime", |
| 33 | + "@npm//@microsoft/api-extractor", |
| 34 | + "@npm//source-map-support", |
| 35 | + "@npm//chalk", |
| 36 | + "@npm//getopts", |
| 37 | + "@npm//is-path-inside", |
| 38 | + "@npm//normalize-path", |
| 39 | + "@npm//source-map", |
| 40 | + "@npm//tslib", |
| 41 | +] |
| 42 | + |
| 43 | +TYPES_DEPS = [ |
| 44 | + "@npm//@microsoft/api-extractor", |
| 45 | + "@npm//@types/jest", |
| 46 | + "@npm//@types/node", |
| 47 | + "@npm//@types/normalize-path", |
| 48 | + "@npm//getopts", |
| 49 | + "@npm//is-path-inside", |
| 50 | + "@npm//normalize-path", |
| 51 | + "@npm//source-map", |
| 52 | + "@npm//tslib", |
| 53 | +] |
| 54 | + |
| 55 | +ts_config( |
| 56 | + name = "tsconfig", |
| 57 | + src = "tsconfig.json", |
| 58 | + deps = [ |
| 59 | + "//:tsconfig.base.json", |
| 60 | + "//:tsconfig.bazel.json", |
| 61 | + ], |
| 62 | +) |
| 63 | + |
| 64 | +ts_project( |
| 65 | + name = "tsc_types", |
| 66 | + args = ['--pretty'], |
| 67 | + srcs = SRCS, |
| 68 | + deps = TYPES_DEPS, |
| 69 | + declaration = True, |
| 70 | + declaration_map = True, |
| 71 | + emit_declaration_only = True, |
| 72 | + out_dir = "target_types", |
| 73 | + root_dir = "src", |
| 74 | + tsconfig = ":tsconfig", |
| 75 | +) |
| 76 | + |
| 77 | +jsts_transpiler( |
| 78 | + name = "target_node", |
| 79 | + srcs = SRCS, |
| 80 | + build_pkg_name = package_name(), |
| 81 | +) |
| 82 | + |
| 83 | +js_library( |
| 84 | + name = PKG_BASE_NAME, |
| 85 | + srcs = NPM_MODULE_EXTRA_FILES, |
| 86 | + deps = RUNTIME_DEPS + [":target_node"], |
| 87 | + package_name = PKG_REQUIRE_NAME, |
| 88 | + visibility = ["//visibility:public"], |
| 89 | +) |
| 90 | + |
| 91 | +directory_file_path( |
| 92 | + name = "bazel-cli-path", |
| 93 | + directory = ":target_node", |
| 94 | + path = "bazel_cli.js", |
| 95 | +) |
| 96 | + |
| 97 | +nodejs_binary( |
| 98 | + name = "bazel-cli", |
| 99 | + data = [ |
| 100 | + ":%s" % PKG_BASE_NAME |
| 101 | + ], |
| 102 | + entry_point = ":bazel-cli-path", |
| 103 | + visibility = ["//visibility:public"], |
| 104 | +) |
| 105 | + |
| 106 | +pkg_npm( |
| 107 | + name = "npm_module", |
| 108 | + deps = [ |
| 109 | + ":%s" % PKG_BASE_NAME, |
| 110 | + ], |
| 111 | +) |
| 112 | + |
| 113 | +filegroup( |
| 114 | + name = "build", |
| 115 | + srcs = [ |
| 116 | + ":npm_module", |
| 117 | + ], |
| 118 | + visibility = ["//visibility:public"], |
| 119 | +) |
| 120 | + |
| 121 | +pkg_npm_types( |
| 122 | + name = "npm_module_types", |
| 123 | + srcs = SRCS, |
| 124 | + deps = [":tsc_types"], |
| 125 | + package_name = PKG_REQUIRE_NAME, |
| 126 | + tsconfig = ":tsconfig", |
| 127 | + visibility = ["//visibility:public"], |
| 128 | +) |
| 129 | + |
| 130 | +filegroup( |
| 131 | + name = "build_types", |
| 132 | + srcs = [ |
| 133 | + ":npm_module_types", |
| 134 | + ], |
| 135 | + visibility = ["//visibility:public"], |
| 136 | +) |
0 commit comments