Skip to content

Commit f297e81

Browse files
authored
fix(typescript): include all .json in js_library DeclarationInfo (#3556)
Fixes #3551
1 parent b341421 commit f297e81

File tree

5 files changed

+22
-4
lines changed

5 files changed

+22
-4
lines changed

internal/js_library/js_library.bzl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,9 @@ def _impl(ctx):
172172
(
173173
file.path.endswith(".d.ts") or
174174
file.path.endswith(".d.ts.map") or
175+
# Any .json can produce types: https://www.typescriptlang.org/tsconfig/#resolveJsonModule
175176
# package.json may be required to resolve "typings" key
176-
file.path.endswith("/package.json")
177+
file.path.endswith(".json")
177178
) and
178179
# exclude eg. external/npm/node_modules/protobufjs/node_modules/@types/node/index.d.ts
179180
# these would be duplicates of the typings provided directly in another dependency.

internal/js_library/test/transitive/BUILD.bazel

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
load("//:index.bzl", "js_library")
22
load(":transitive_declarations_test.bzl", "transitive_declarations_test_suite")
33
load("//packages/typescript:index.bzl", "ts_project")
4+
load("@bazel_skylib//rules:build_test.bzl", "build_test")
45

56
js_library(
67
name = "c",
@@ -19,7 +20,10 @@ ts_project(
1920

2021
js_library(
2122
name = "a",
22-
srcs = ["a.d.ts"],
23+
srcs = [
24+
"a.d.ts",
25+
"e.json",
26+
],
2327
deps = ["b"],
2428
)
2529

@@ -29,3 +33,12 @@ js_library(
2933
)
3034

3135
transitive_declarations_test_suite()
36+
37+
build_test(
38+
name = "json_import",
39+
targets = [
40+
"c",
41+
"b",
42+
"a",
43+
],
44+
)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export declare const a: string;
2+
export * as Foo from "./e.json";
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"name": "test"
3+
}

internal/js_library/test/transitive/transitive_declarations_test.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ def _impl(ctx):
1919
return unittest.end(env)
2020

2121
transitive_declarations_test = unittest.make(_impl, attrs = {
22-
"expected_declarations": attr.string_list(default = ["a.d.ts"]),
22+
"expected_declarations": attr.string_list(default = ["a.d.ts", "e.json"]),
2323
"lib": attr.label(default = ":terminal"),
24-
"expected_runfiles": attr.string_list(default = ["a.d.ts", "b.js", "c.d.ts", "c.txt"]),
24+
"expected_runfiles": attr.string_list(default = ["a.d.ts", "b.js", "c.d.ts", "c.txt", "e.json"]),
2525
})
2626

2727
def transitive_declarations_test_suite():

0 commit comments

Comments
 (0)