Skip to content

Commit

Permalink
fix(typescript): don't include _valid_options marker file in outs
Browse files Browse the repository at this point in the history
Tested by building //packages/angular:npm_package and don't get an extra .d.ts file in the package.
Also tested the negative case by making an invalid option and check that it's still reported.

Fixes #2078
  • Loading branch information
Alex Eagle committed Oct 21, 2020
1 parent 5d405a7 commit 570e34d
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions packages/typescript/internal/ts_project.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ load("@build_bazel_rules_nodejs//:providers.bzl", "DeclarationInfo", "NpmPackage
load("@build_bazel_rules_nodejs//internal/linker:link_node_modules.bzl", "module_mappings_aspect")
load(":ts_config.bzl", "TsConfigInfo", "write_tsconfig")

_ValidOptionsInfo = provider()

_DEFAULT_TSC = (
# BEGIN-INTERNAL
"@npm" +
Expand All @@ -14,7 +16,14 @@ _DEFAULT_TSC = (
_ATTRS = {
"args": attr.string_list(),
"declaration_dir": attr.string(),
"deps": attr.label_list(providers = [DeclarationInfo], aspects = [module_mappings_aspect]),
"deps": attr.label_list(
providers = [
# Provide one or the other of these
[DeclarationInfo],
[_ValidOptionsInfo],
],
aspects = [module_mappings_aspect],
),
"extends": attr.label_list(allow_files = [".json"]),
"link_workspace_root": attr.bool(),
"out_dir": attr.string(),
Expand Down Expand Up @@ -95,6 +104,7 @@ def _ts_project_impl(ctx):
])

deps_depsets = []
inputs = ctx.files.srcs[:]
for dep in ctx.attr.deps:
if TsConfigInfo in dep:
deps_depsets.append(dep[TsConfigInfo].deps)
Expand All @@ -104,8 +114,10 @@ def _ts_project_impl(ctx):
deps_depsets.append(dep[NpmPackageInfo].sources)
if DeclarationInfo in dep:
deps_depsets.append(dep[DeclarationInfo].transitive_declarations)
if _ValidOptionsInfo in dep:
inputs.append(dep[_ValidOptionsInfo].marker)

inputs = ctx.files.srcs + depset(transitive = deps_depsets).to_list()
inputs.extend(depset(transitive = deps_depsets).to_list())

# Gather TsConfig info from both the direct (tsconfig) and indirect (extends) attribute
if TsConfigInfo in ctx.attr.tsconfig:
Expand Down Expand Up @@ -224,9 +236,7 @@ def _validate_options_impl(ctx):
executable = "validator",
)
return [
DeclarationInfo(
transitive_declarations = depset([marker]),
),
_ValidOptionsInfo(marker = marker),
]

validate_options = rule(
Expand Down

0 comments on commit 570e34d

Please sign in to comment.