diff --git a/docs/TypeScript.md b/docs/TypeScript.md index b166b425b3..b36977c8da 100755 --- a/docs/TypeScript.md +++ b/docs/TypeScript.md @@ -51,6 +51,15 @@ type-checking and not for producing any build outputs. To use it, add the load statement `load("@npm//typescript:index.bzl", "tsc_test")` to your BUILD file. (Possibly replacing `@npm` with the name of the repository where you installed dependencies) +To get the typings available in the test (as "runfiles"), you may need to gather them from dependencies if they +are not included as default outputs of those dependencies, like so: + +```starlark +filegroup(name = "types", srcs = ["//some:js_library"], output_group = "types") +``` + +And then include the `:types` target in the `data` of the `tsc_test`. + See example in https://github.com/bazelbuild/rules_nodejs/tree/stable/packages/typescript/test/tsc_test ### Option 3: ts_project diff --git a/internal/js_library/js_library.bzl b/internal/js_library/js_library.bzl index 4066d1b70c..dfe4edaa8a 100644 --- a/internal/js_library/js_library.bzl +++ b/internal/js_library/js_library.bzl @@ -225,8 +225,10 @@ def _impl(ctx): runfiles = ctx.runfiles( files = all_files, + # We do not include typings_depsets in the runfiles because that would cause type-check actions to occur + # in every development workflow. transitive_files = depset( - transitive = files_depsets + typings_depsets, + transitive = files_depsets, ), ) deps_runfiles = [d[DefaultInfo].default_runfiles for d in ctx.attr.deps] diff --git a/packages/typescript/index.docs.bzl b/packages/typescript/index.docs.bzl index 97f662c7a6..fb724e09ee 100644 --- a/packages/typescript/index.docs.bzl +++ b/packages/typescript/index.docs.bzl @@ -63,6 +63,15 @@ type-checking and not for producing any build outputs. To use it, add the load statement `load("@npm//typescript:index.bzl", "tsc_test")` to your BUILD file. (Possibly replacing `@npm` with the name of the repository where you installed dependencies) +To get the typings available in the test (as "runfiles"), you may need to gather them from dependencies if they +are not included as default outputs of those dependencies, like so: + +```starlark +filegroup(name = "types", srcs = ["//some:js_library"], output_group = "types") +``` + +And then include the `:types` target in the `data` of the `tsc_test`. + See example in https://github.com/bazelbuild/rules_nodejs/tree/stable/packages/typescript/test/tsc_test ### Option 3: ts_project