Skip to content

Commit a1d49ae

Browse files
gregmagolanalexeagle
authored andcommitted
fix(builtin): provide a DeclarationInfo from js_library is any input files are directories (TreeArtifacts)
1 parent 837cb23 commit a1d49ae

File tree

4 files changed

+37
-1
lines changed

4 files changed

+37
-1
lines changed

internal/js_library/js_library.bzl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,10 @@ def _impl(ctx):
157157
js_files.append(file)
158158

159159
# register typings
160-
if (
160+
if file.is_directory:
161+
# assume a directory contains typings since we can't know that it doesn't
162+
typings.append(file)
163+
elif (
161164
(
162165
file.path.endswith(".d.ts") or
163166
file.path.endswith(".d.ts.map") or
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
load("//third_party/github.com/bazelbuild/bazel-skylib:rules/copy_file.bzl", "copy_file")
2+
load("//:index.bzl", "js_library")
3+
load("//packages/typescript:index.bzl", "ts_project")
4+
5+
# Copy lib source directory to a TreeArtifact since bazel file.is_directory
6+
# function does detect source directories
7+
copy_file(
8+
name = "lib_copy",
9+
src = "lib",
10+
# We must give this as the directory in order for it to appear on NODE_PATH
11+
out = "lib_out",
12+
# This attribute comes from rules_nodejs patch of
13+
# https://github.com/bazelbuild/bazel-skylib/pull/323
14+
is_directory = True,
15+
)
16+
17+
js_library(
18+
name = "lib_js_library",
19+
package_name = "directory_declarations_lib",
20+
srcs = [":lib_copy"],
21+
package_path = package_name(),
22+
strip_prefix = "lib_out",
23+
)
24+
25+
ts_project(
26+
name = "b",
27+
srcs = ["b.ts"],
28+
tsconfig = {},
29+
deps = [":lib_js_library"],
30+
)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import * as lib from 'directory_declarations_lib/a'
2+
console.log(lib.a)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export declare const a: string;

0 commit comments

Comments
 (0)