Skip to content
Browse files

fix(bazel): ng_package writes unrelevant definitions to bazel out

In order to keep the bazel bin directory as clean as possible, we should not write definition files that are not relevant to a `ng_package` to an undesired location in the bazel bin directory. This currently just happens because we only filter out external definition files while we also should filter out definitions that aren't just in the current package.

The `packager.ts` file currently tries to write these files to the package, but fails because those are not inside of the current package. So the logic to create a relative path for the file fails, and the definition will be copied to a location like:

// Notice the double "bazel-out" here.

[See logic that causes this]( (nothing wrong with that logic because it assumes that only paths from within the package are passed to it)
  • Loading branch information...
devversion committed Dec 6, 2018
1 parent 7f221d8 commit 0b6ef91f29d6428a332c27176471fda6630e4ff2
Showing with 14 additions and 8 deletions.
  1. +14 −8 packages/bazel/src/ng_package/ng_package.bzl
@@ -153,13 +153,14 @@ def _flatten_paths(directory):
return result

# takes an depset of files and returns an array that doesn't contain any generated files by ngc
def _filter_out_generated_files(files, extension, filter_external_files):
# Takes a depset of files and returns a depset that doesn't contain any generated files by NGC.
# Optionally can filter out files that do not belong to a specified package path.
def _filter_out_generated_files(files, extension, package_path = None):
result = []
for file in files:
# If the "filter_external_files" parameter has been set to true, filter out files
# that refer to external workspaces.
if filter_external_files and file.short_path.startswith("../"):
# If the "package_path" parameter has been specified, filter out files
# that do not start with the the specified package path.
if package_path and not file.short_path.startswith(package_path):

# Filter out files that are generated by the Angular Compiler CLI.
@@ -184,9 +185,14 @@ def _filter_js_inputs(all_inputs):
def _ng_package_impl(ctx):
npm_package_directory = ctx.actions.declare_directory("%s.ng_pkg" %

esm_2015_files = _filter_out_generated_files(collect_es6_sources(ctx), "js", False)
esm5_sources = _filter_out_generated_files(flatten_esm5(ctx), "js", False)
type_definitions = _filter_out_generated_files(collect_type_definitions(ctx), "d.ts", True)
esm_2015_files = _filter_out_generated_files(collect_es6_sources(ctx), "js")
esm5_sources = _filter_out_generated_files(flatten_esm5(ctx), "js")

# Filter out all TypeScript definitions generated by NGC as well as definition files
# that do not belong to the current package. We only want to package types that belong
# to the current package.
type_definitions = _filter_out_generated_files(collect_type_definitions(ctx), "d.ts",

# These accumulators match the directory names where the files live in the
# Angular package format.

0 comments on commit 0b6ef91

Please sign in to comment.
You can’t perform that action at this time.