豆豆友情提示:这是一个非官方 GitHub 代理镜像,主要用于网络测试或访问加速。请勿在此进行登录、注册或处理任何敏感信息。进行这些操作请务必访问官方网站 github.com。 Raw 内容也通过此代理提供。
Skip to content

Commit fc8badf

Browse files
committed
fix(bazel): spec-bundle rule should never consider transitive files
Only specs part of the direct sources, or only direct init files should be considered by the rule. Consider an example where one init file relies on another. The second init file should not be picked up as bootstrap file, but instead should just be loaded based on the direct `.init` file.
1 parent 50f0f9e commit fc8badf

File tree

3 files changed

+26
-11
lines changed

3 files changed

+26
-11
lines changed

bazel/spec-bundling/spec-entrypoint.bzl

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,30 +37,36 @@ def _create_entrypoint_file(base_package, spec_files, bootstrap_files):
3737

3838
def _spec_entrypoint_impl(ctx):
3939
output = ctx.actions.declare_file("%s.mjs" % ctx.attr.name)
40-
spec_depsets = []
41-
bootstrap_depsets = []
40+
spec_direct_deps = []
41+
spec_all_deps = []
42+
bootstrap_direct_deps = []
43+
bootstrap_all_deps = []
4244

4345
for dep in ctx.attr.deps:
4446
if JSModuleInfo in dep:
45-
spec_depsets.append(dep[JSModuleInfo].sources)
47+
spec_all_deps.append(dep[JSModuleInfo].sources)
48+
spec_direct_deps.append(dep[JSModuleInfo].direct_sources)
4649
else:
47-
spec_depsets.append(dep[DefaultInfo].files)
50+
spec_all_deps.append(dep[DefaultInfo].files)
51+
spec_direct_deps.append(dep[DefaultInfo].files)
4852

4953
for dep in ctx.attr.bootstrap:
5054
if JSModuleInfo in dep:
51-
bootstrap_depsets.append(dep[JSModuleInfo].sources)
55+
bootstrap_all_deps.append(dep[JSModuleInfo].sources)
56+
bootstrap_direct_deps.append(dep[JSModuleInfo].direct_sources)
5257
else:
53-
bootstrap_depsets.append(dep[DefaultInfo].files)
58+
bootstrap_all_deps.append(dep[DefaultInfo].files)
59+
bootstrap_direct_deps.append(dep[DefaultInfo].files)
5460

5561
# Note: `to_list()` is an expensive operation but we need to do this for every
5662
# dependency here in order to be able to filter out spec files from depsets.
57-
all_spec_files = depset(transitive = spec_depsets).to_list()
58-
spec_files = _filter_files(all_spec_files, ["spec", "test"])
63+
direct_spec_files = depset(transitive = spec_direct_deps).to_list()
64+
spec_files = _filter_files(direct_spec_files, ["spec", "test"])
5965

6066
# Note: `to_list()` is an expensive operation but we need to do this for every
6167
# dependency here in order to be able to filter out spec files from depsets.
62-
all_bootstrap_files = depset(transitive = bootstrap_depsets).to_list()
63-
bootstrap_files = _filter_files(all_bootstrap_files, ["init"])
68+
direct_bootstrap_files = depset(transitive = bootstrap_direct_deps).to_list()
69+
bootstrap_files = _filter_files(direct_bootstrap_files, ["init"])
6470

6571
ctx.actions.write(
6672
output = output,
@@ -73,7 +79,7 @@ def _spec_entrypoint_impl(ctx):
7379
DefaultInfo(files = out_depset),
7480
JSModuleInfo(
7581
direct_sources = out_depset,
76-
sources = depset(transitive = [out_depset] + spec_depsets + bootstrap_depsets),
82+
sources = depset(transitive = [out_depset] + spec_all_deps + bootstrap_all_deps),
7783
),
7884
]
7985

bazel/spec-bundling/test/BUILD.bazel

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,17 @@ load("@npm//@bazel/jasmine:index.bzl", "jasmine_node_test")
44
load("//bazel/spec-bundling:index.bzl", "spec_bundle")
55
load("//tools:defaults.bzl", "ts_library")
66

7+
ts_library(
8+
name = "transitive_should_not_be_loaded",
9+
srcs = ["should_not_be_picked_up.spec.ts"],
10+
)
11+
712
ts_library(
813
name = "test_async_await_lib",
914
testonly = True,
1015
srcs = ["async-await.spec.ts"],
1116
deps = [
17+
":transitive_should_not_be_loaded",
1218
"@npm//@angular/core",
1319
"@npm//@angular/platform-browser-dynamic",
1420
"@npm//@types/jasmine",
@@ -24,6 +30,7 @@ ts_library(
2430
testonly = True,
2531
srcs = ["core_apf_esm_test.ts"],
2632
deps = [
33+
":transitive_should_not_be_loaded",
2734
"@npm//@angular/core",
2835
"@npm//@types/jasmine",
2936
],
@@ -34,6 +41,7 @@ ts_library(
3441
testonly = True,
3542
srcs = ["core_invalid_linker_decl.spec.ts"],
3643
deps = [
44+
":transitive_should_not_be_loaded",
3745
"@npm//@angular/core",
3846
"@npm//@types/jasmine",
3947
],
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
throw new Error('this file should not be loaded at all!');

0 commit comments

Comments
 (0)