fix(bazel): ng_package writes unrelevant definitions to bazel out (#27519)
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:
```js
// Notice the double "bazel-out" here.
C:\Users\Paul\_bazel_Paul\kn4tsvyh\execroot\angular_material\bazel-out\x64_windows-fastbuild\bin\src\bazel-out\x64_windows-fastbuild\bin\src\cdk
```
[See logic that causes this](4f9374951d/packages/bazel/src/ng_package/packager.ts (L105-L124)
) (nothing wrong with that logic because it assumes that only paths from within the package are passed to it)
PR Close #27519
This commit is contained in:
parent
3970d00edd
commit
44dfa606ed
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue