Skip to content

Commit

Permalink
feat(builtin): add a DeclarationInfo provider
Browse files Browse the repository at this point in the history
This gives us a principled way for rules to generate and consume TypeScript typings
  • Loading branch information
alexeagle committed Aug 24, 2019
1 parent 0229ae5 commit 3d7eb13
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions declaration_provider.bzl
Original file line number Diff line number Diff line change
@@ -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 3d7eb13

Please sign in to comment.