Provide DeclarationInfo that replaces two fields from "typescript" legacy provider
This is the part of removing the legacy providers, per https://github.com/bazelbuild/bazel/issues/7347
Depends on https://github.com/bazelbuild/rules_nodejs/pull/1052
PiperOrigin-RevId: 265167694
diff --git a/internal/common/compilation.bzl b/internal/common/compilation.bzl
index 70a66d7..3155f0c 100644
--- a/internal/common/compilation.bzl
+++ b/internal/common/compilation.bzl
@@ -17,6 +17,7 @@
load(":common/json_marshal.bzl", "json_marshal")
load(":common/module_mappings.bzl", "module_mappings_aspect")
+load("@build_bazel_rules_nodejs//:declaration_provider.bzl", "DeclarationInfo")
_DEBUG = False
@@ -483,6 +484,11 @@
es5_sources = es5_sources,
es6_sources = es6_sources,
),
+ # TODO(martinprobst): Prune transitive deps, see go/dtspruning
+ DeclarationInfo(
+ declarations = depset(transitive = declarations_depsets),
+ transitive_declarations = transitive_decls,
+ ),
],
"instrumented_files": {
"dependency_attributes": ["deps", "runtime_deps"],
@@ -495,13 +501,14 @@
"module_name": getattr(ctx.attr, "module_name", None),
# Expose the tags so that a Skylark aspect can access them.
"tags": ctx.attr.tags if hasattr(ctx.attr, "tags") else ctx.rule.attr.tags,
- # TODO(martinprobst): Prune transitive deps, only re-export what's needed.
"typescript": {
+ # TODO(b/139705078): remove when consumers migrated to DeclarationInfo
"declarations": depset(transitive = declarations_depsets),
"devmode_manifest": devmode_manifest,
"es5_sources": es5_sources,
"es6_sources": es6_sources,
"replay_params": replay_params,
+ # TODO(b/139705078): remove when consumers migrated to DeclarationInfo
"transitive_declarations": transitive_decls,
"transitive_es6_sources": transitive_es6_sources,
"tsickle_externs": tsickle_externs,
diff --git a/package.bzl b/package.bzl
index 0f4ad48..b751dcb 100644
--- a/package.bzl
+++ b/package.bzl
@@ -30,6 +30,10 @@
_maybe(
http_archive,
name = "build_bazel_rules_nodejs",
+ patch_args = ["-p1"],
+ # Patch in this PR to get the DeclarationInfo provider.
+ # Can remove this once it's released
+ patches = ["@build_bazel_rules_typescript//:rules_nodejs_pr1052.patch"],
sha256 = "6d4edbf28ff6720aedf5f97f9b9a7679401bf7fca9d14a0fff80f644a99992b4",
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/0.32.2/rules_nodejs-0.32.2.tar.gz"],
)
diff --git a/rules_nodejs_pr1052.patch b/rules_nodejs_pr1052.patch
new file mode 100644
index 0000000..e50541e
--- /dev/null
+++ b/rules_nodejs_pr1052.patch
@@ -0,0 +1,34 @@
+diff --git a/declaration_provider.bzl b/declaration_provider.bzl
+new file mode 100644
+index 0000000..b2f89af
+--- /dev/null
++++ b/declaration_provider.bzl
+@@ -0,0 +1,28 @@
++"""This module contains a provider for TypeScript typings files (.d.ts)"""
++
++def provide_declarations(**kwargs):
++ """Factory function for creating checked declarations with externs.
++
++ Do not directly construct DeclarationInfo()
++ """
++
++ # TODO: add some checking actions to ensure the declarations are well-formed
++ return DeclarationInfo(**kwargs)
++
++DeclarationInfo = provider(
++ doc = """The DeclarationInfo provider allows JS rules to communicate typing information.
++TypeScript's .d.ts files are used as the interop format for describing types.
++
++Do not create DeclarationInfo instances directly, instead use the provide_declarations factory function.
++
++TODO(alexeagle): The ts_library#deps attribute should require that this provider is attached.
++
++Note: historically this was a subset of the string-typed "typescript" provider.
++""",
++ # TODO: if we ever enable --declarationMap we will have .d.ts.map files too
++ fields = {
++ "declarations": "A depset of .d.ts files produced by this rule",
++ "transitive_declarations": """A depset of .d.ts files produced by this rule and all its transitive dependencies.
++This prevents needing an aspect in rules that consume the typings, which improves performance.""",
++ },
++)