|
| 1 | +""" |
| 2 | + Defaults for the `//dev-infra` Bazel package. These are different than |
| 3 | + the defaults in `//tools:defaults.bzl` which are specific to the package |
| 4 | + structure as seen within `/packages/`. |
| 5 | +""" |
| 6 | + |
| 7 | +load("@build_bazel_rules_nodejs//:index.bzl", "generated_file_test") |
| 8 | +load("@npm//@bazel/jasmine:index.bzl", _jasmine_node_test = "jasmine_node_test") |
| 9 | +load("@npm//@bazel/typescript:index.bzl", _ts_library = "ts_library") |
| 10 | +load("@npm//@bazel/rollup:index.bzl", "rollup_bundle") |
| 11 | + |
| 12 | +NPM_PACKAGE_NAME = "@angular/dev-infra-private" |
| 13 | + |
| 14 | +def _compute_module_name(): |
| 15 | + current_pkg = native.package_name() |
| 16 | + |
| 17 | + if current_pkg == "dev-infra": |
| 18 | + return NPM_PACKAGE_NAME |
| 19 | + |
| 20 | + # For deep targets within `//dev-infra` construct the module name in a way that matches |
| 21 | + # the structure within the NPM package (i.e. simply appending the actual package path) |
| 22 | + return "%s/%s" % (NPM_PACKAGE_NAME, current_pkg[len("dev-infra/"):]) |
| 23 | + |
| 24 | +def ts_library(name, **kwargs): |
| 25 | + _ts_library( |
| 26 | + name = name, |
| 27 | + # If no `module_name` is set, compute a module name based on the current Bazel |
| 28 | + # package. The module names should match the NPM package structure so that the NPM |
| 29 | + # package can be used properly. Note that we disallow any custom `module_name` for |
| 30 | + # `//dev-infra` as this usually signifies a mistake we want to raise awareness for. |
| 31 | + module_name = _compute_module_name(), |
| 32 | + # We use the module name as package name, so that the target can be resolved within |
| 33 | + # NodeJS executions, by activating the Bazel NodeJS linker. |
| 34 | + # See: https://github.com/bazelbuild/rules_nodejs/pull/2799. |
| 35 | + package_name = _compute_module_name(), |
| 36 | + **kwargs |
| 37 | + ) |
| 38 | + |
| 39 | +def jasmine_node_test(**kwargs): |
| 40 | + _jasmine_node_test(**kwargs) |
| 41 | + |
| 42 | +# This file continues to serve as indicator for `rules_nodejs` and instructs it to preserve the |
| 43 | +# content output in the NPM install workspace. This allows consumers to use rules and targets from |
| 44 | +# within Bazel. e.g. by using `@npm//@angular/dev-infra-private/<..>`. |
| 45 | +# See: https://github.com/bazelbuild/rules_nodejs/commit/4f508b1a0be1f5444e9c13b0439e649449792fef. |
| 46 | + |
| 47 | +def ng_dev_rolled_up_generated_file(name, entry_point, deps = [], rollup_args = []): |
| 48 | + """Rollup and generated file test macro. |
| 49 | +
|
| 50 | + This provides a single macro to create a rollup bundled script and a generated file |
| 51 | + test for the created script to ensure it stays up to date in the repository. |
| 52 | + """ |
| 53 | + rollup_bundle( |
| 54 | + name = "%s_bundle" % name, |
| 55 | + args = rollup_args, |
| 56 | + entry_point = entry_point, |
| 57 | + format = "cjs", |
| 58 | + silent = True, |
| 59 | + sourcemap = "false", |
| 60 | + deps = deps, |
| 61 | + ) |
| 62 | + |
| 63 | + generated_file_test( |
| 64 | + name = name, |
| 65 | + src = "%s.js" % name, |
| 66 | + generated = "%s_bundle" % name, |
| 67 | + ) |
0 commit comments