|
| 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 | + |
| 5 | +PKG_DIRNAME = "impl" |
| 6 | +PKG_REQUIRE_NAME = "@kbn/shared-ux-markdown" |
| 7 | + |
| 8 | +SOURCE_FILES = glob( |
| 9 | + [ |
| 10 | + "**/*.ts", |
| 11 | + "**/*.tsx", |
| 12 | + "**/*.mdx", |
| 13 | + ], |
| 14 | + exclude = [ |
| 15 | + "**/*.config.js", |
| 16 | + "**/*.mock.*", |
| 17 | + "**/*.test.*", |
| 18 | + "**/*.stories.*", |
| 19 | + "**/__snapshots__/**", |
| 20 | + "**/integration_tests/**", |
| 21 | + "**/mocks/**", |
| 22 | + "**/scripts/**", |
| 23 | + "**/storybook/**", |
| 24 | + "**/test_fixtures/**", |
| 25 | + "**/test_helpers/**", |
| 26 | + ], |
| 27 | +) |
| 28 | + |
| 29 | +SRCS = SOURCE_FILES |
| 30 | + |
| 31 | +filegroup( |
| 32 | + name = "srcs", |
| 33 | + srcs = SRCS, |
| 34 | +) |
| 35 | + |
| 36 | +NPM_MODULE_EXTRA_FILES = [ |
| 37 | + "package.json", |
| 38 | +] |
| 39 | + |
| 40 | +# In this array place runtime dependencies, including other packages and NPM packages |
| 41 | +# which must be available for this code to run. |
| 42 | +# |
| 43 | +# To reference other packages use: |
| 44 | +# "//repo/relative/path/to/package" |
| 45 | +# eg. "//packages/kbn-utils" |
| 46 | +# |
| 47 | +# To reference a NPM package use: |
| 48 | +# "@npm//name-of-package" |
| 49 | +# eg. "@npm//lodash" |
| 50 | +RUNTIME_DEPS = [ |
| 51 | + "@npm//react", |
| 52 | + "@npm//enzyme", |
| 53 | + "@npm//@elastic/eui", |
| 54 | + "//packages/kbn-ambient-ui-types", |
| 55 | +] |
| 56 | + |
| 57 | +# In this array place dependencies necessary to build the types, which will include the |
| 58 | +# :npm_module_types target of other packages and packages from NPM, including @types/* |
| 59 | +# packages. |
| 60 | +# |
| 61 | +# To reference the types for another package use: |
| 62 | +# "//repo/relative/path/to/package:npm_module_types" |
| 63 | +# eg. "//packages/kbn-utils:npm_module_types" |
| 64 | +# |
| 65 | +# References to NPM packages work the same as RUNTIME_DEPS |
| 66 | +TYPES_DEPS = [ |
| 67 | + "@npm//@types/node", |
| 68 | + "@npm//@types/jest", |
| 69 | + "@npm//@types/react", |
| 70 | + "@npm//@elastic/eui", |
| 71 | + "//packages/kbn-ambient-ui-types", |
| 72 | + "//packages/kbn-shared-ux-utility:npm_module_types", |
| 73 | + "//packages/shared-ux/markdown/mocks", |
| 74 | + # "//packages/kbn-shared-ux-markdown-mocks:npm_module_types", |
| 75 | +] |
| 76 | + |
| 77 | +jsts_transpiler( |
| 78 | + name = "target_node", |
| 79 | + srcs = SRCS, |
| 80 | + build_pkg_name = package_name(), |
| 81 | +) |
| 82 | + |
| 83 | +jsts_transpiler( |
| 84 | + name = "target_web", |
| 85 | + srcs = SRCS, |
| 86 | + build_pkg_name = package_name(), |
| 87 | + web = True, |
| 88 | + additional_args = [ |
| 89 | + "--copy-files", |
| 90 | + "--quiet" |
| 91 | + ], |
| 92 | +) |
| 93 | + |
| 94 | +ts_config( |
| 95 | + name = "tsconfig", |
| 96 | + src = "tsconfig.json", |
| 97 | + deps = [ |
| 98 | + "//:tsconfig.base.json", |
| 99 | + "//:tsconfig.bazel.json", |
| 100 | + ], |
| 101 | +) |
| 102 | + |
| 103 | +ts_project( |
| 104 | + name = "tsc_types", |
| 105 | + args = ['--pretty'], |
| 106 | + srcs = SRCS, |
| 107 | + deps = TYPES_DEPS, |
| 108 | + declaration = True, |
| 109 | + declaration_map = True, |
| 110 | + emit_declaration_only = True, |
| 111 | + out_dir = "target_types", |
| 112 | + tsconfig = ":tsconfig", |
| 113 | +) |
| 114 | + |
| 115 | +js_library( |
| 116 | + name = PKG_DIRNAME, |
| 117 | + srcs = NPM_MODULE_EXTRA_FILES, |
| 118 | + deps = RUNTIME_DEPS + [":target_node", ":target_web"], |
| 119 | + package_name = PKG_REQUIRE_NAME, |
| 120 | + visibility = ["//visibility:public"], |
| 121 | +) |
| 122 | + |
| 123 | +pkg_npm( |
| 124 | + name = "npm_module", |
| 125 | + deps = [":" + PKG_DIRNAME], |
| 126 | +) |
| 127 | + |
| 128 | +filegroup( |
| 129 | + name = "build", |
| 130 | + srcs = [":npm_module"], |
| 131 | + visibility = ["//visibility:public"], |
| 132 | +) |
| 133 | + |
| 134 | +pkg_npm_types( |
| 135 | + name = "npm_module_types", |
| 136 | + srcs = SRCS, |
| 137 | + deps = [":tsc_types"], |
| 138 | + package_name = PKG_REQUIRE_NAME, |
| 139 | + tsconfig = ":tsconfig", |
| 140 | + visibility = ["//visibility:public"], |
| 141 | +) |
| 142 | + |
| 143 | +filegroup( |
| 144 | + name = "build_types", |
| 145 | + srcs = [":npm_module_types"], |
| 146 | + visibility = ["//visibility:public"], |
| 147 | +) |
0 commit comments