Skip to content

Commit d7a36bc

Browse files
committed
fix(bazel): only extract types from within the same package as where the extract_types is called (#2925)
We should only extract types that come from the same package location as where the extract_types are called. Additionally remove extra_js_module_output testing as it is slated for removal. PR Close #2925
1 parent 6a526a9 commit d7a36bc

File tree

5 files changed

+13
-89
lines changed

5 files changed

+13
-89
lines changed

bazel/extract_types.bzl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
load("@build_bazel_rules_nodejs//:providers.bzl", "DeclarationInfo")
1+
load("@aspect_rules_js//js:providers.bzl", "JsInfo")
22

33
def _extract_types_impl(ctx):
44
"""Implementation of the `extract_types` rule."""
5-
depsets = []
5+
types_files = []
66

77
for dep in ctx.attr.deps:
8-
if DeclarationInfo in dep:
9-
depsets.append(dep[DeclarationInfo].transitive_declarations)
8+
if JsInfo in dep:
9+
types_files.extend(dep[JsInfo].transitive_types.to_list())
10+
types_files.extend(dep[JsInfo].types.to_list())
1011

11-
types = depset(transitive = depsets)
12+
types = depset([file for file in types_files if file.short_path.startswith(ctx.label.package)])
1213

1314
return [
1415
DefaultInfo(files = types),

bazel/extract_types_rjs.bzl

Lines changed: 0 additions & 35 deletions
This file was deleted.

bazel/test/BUILD.bazel

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
1+
load("@aspect_rules_ts//ts:defs.bzl", "ts_project")
12
load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_test")
2-
load("//bazel:defaults.bzl", "ts_library")
33
load("//bazel:extract_types.bzl", "extract_types")
4-
load("//bazel:extract_js_module_output.bzl", "extract_js_module_output")
54

6-
ts_library(
5+
ts_project(
76
name = "transitive_lib",
87
testonly = True,
98
srcs = ["transitive_file.ts"],
9+
declaration = True,
10+
tsconfig = "//bazel:tsconfig",
1011
)
1112

12-
ts_library(
13+
ts_project(
1314
name = "test_lib",
1415
testonly = True,
1516
srcs = ["fixture.ts"],
17+
declaration = True,
18+
tsconfig = "//bazel:tsconfig",
1619
deps = [":transitive_lib"],
1720
)
1821

@@ -28,30 +31,9 @@ extract_types(
2831
deps = [":test_lib"],
2932
)
3033

31-
extract_js_module_output(
32-
name = "extract_js_module_output_target",
33-
testonly = True,
34-
forward_linker_mappings = True,
35-
include_declarations = True,
36-
include_default_files = True,
37-
include_external_npm_packages = True,
38-
provider = "JSModuleInfo",
39-
deps = [
40-
":test_lib",
41-
":text_fixture",
42-
],
43-
)
44-
4534
nodejs_test(
4635
name = "extract_types_test",
4736
data = [":extract_types_target"],
4837
entry_point = "extract_types_test.js",
4938
templated_args = ["$(rootpaths :extract_types_target)"],
5039
)
51-
52-
nodejs_test(
53-
name = "extract_js_module_test",
54-
data = [":extract_js_module_output_target"],
55-
entry_point = "extract_js_module_test.js",
56-
templated_args = ["$(rootpaths :extract_js_module_output_target)"],
57-
)

bazel/test/extract_js_module_test.js

Lines changed: 0 additions & 20 deletions
This file was deleted.

bazel/test/extract_types_test.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@ const assert = require('assert');
44
const typeRootpaths = process.argv.slice(2);
55

66
assert.deepStrictEqual(typeRootpaths, [
7-
// TypeScript types transitively added to every `ts_library` target. This might be
8-
// cleaned up in the future, but is captured in this test as it rarely should change.
9-
'../npm/node_modules/typescript/lib/tsserverlibrary.d.ts',
10-
'../npm/node_modules/typescript/lib/typescript.d.ts',
117
// Actual workspace-local `d.ts` files.
128
'bazel/test/fixture.d.ts',
139
'bazel/test/transitive_file.d.ts',

0 commit comments

Comments
 (0)