Skip to content

Commit

Permalink
Provide DeclarationInfo that replaces two fields from "typescript" le…
Browse files Browse the repository at this point in the history
…gacy provider

This is the part of removing the legacy providers, per bazelbuild/bazel#7347

Depends on bazel-contrib#1052

PiperOrigin-RevId: 265167694
  • Loading branch information
alexeagle committed Aug 24, 2019
1 parent 81f53b5 commit c4eafdd
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -483,6 +484,11 @@ def compile_ts(
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"],
Expand All @@ -495,13 +501,14 @@ def compile_ts(
"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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ def rules_typescript_dev_dependencies():
_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"],
)
Expand Down
Original file line number Diff line number Diff line change
@@ -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.""",
+ },
+)

0 comments on commit c4eafdd

Please # to comment.