diff --git a/packages/bazel/src/ng_package/ng_package.bzl b/packages/bazel/src/ng_package/ng_package.bzl index d20644134b..f84d0471fc 100644 --- a/packages/bazel/src/ng_package/ng_package.bzl +++ b/packages/bazel/src/ng_package/ng_package.bzl @@ -153,13 +153,14 @@ def _flatten_paths(directory): result.append(f.map.path) 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): continue # Filter out files that are generated by the Angular Compiler CLI. @@ -184,9 +185,17 @@ def _filter_js_inputs(all_inputs): def _ng_package_impl(ctx): npm_package_directory = ctx.actions.declare_directory("%s.ng_pkg" % ctx.label.name) - 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", + ctx.label.package, + ) # These accumulators match the directory names where the files live in the # Angular package format.