diff --git a/packages/bazel/src/ng_package/ng_package.bzl b/packages/bazel/src/ng_package/ng_package.bzl index 95018efa1a..76e06c773f 100644 --- a/packages/bazel/src/ng_package/ng_package.bzl +++ b/packages/bazel/src/ng_package/ng_package.bzl @@ -258,6 +258,9 @@ NG_PACKAGE_ATTRS = dict(NPM_PACKAGE_ATTRS, **dict(ROLLUP_ATTRS, **{ "include_devmode_srcs": attr.bool(default = False), "readme_md": attr.label(allow_single_file = FileType([".md"])), "globals": attr.string_dict(default={}), + "entry_point_name": attr.string( + doc = "Name to use when generating bundle files for the primary entry-point.", + ), "_ng_packager": attr.label( default=Label("//packages/bazel/src/ng_package:packager"), executable=True, cfg="host"), @@ -278,11 +281,20 @@ NG_PACKAGE_ATTRS = dict(NPM_PACKAGE_ATTRS, **dict(ROLLUP_ATTRS, **{ # Currently we just borrow the entry point for this, if it looks like # some/path/to/my/package/index.js # we assume the files should be named "package.*.js" -def primary_entry_point_name(name, entry_point): - return entry_point.split("/")[-2] if entry_point.find("/") >=0 else name +def primary_entry_point_name(name, entry_point, entry_point_name): + if entry_point_name: + # If an explicit entry_point_name is given, use that. + return entry_point_name + elif entry_point.find("/") >= 0: + # If the entry_point has multiple path segments, use the second one. + # E.g., for "@angular/cdk/a11y", use "cdk". + return entry_point.split("/")[-2] + else: + # Fall back to the name of the ng_package rule. + return name -def ng_package_outputs(name, entry_point): - basename = primary_entry_point_name(name, entry_point) +def ng_package_outputs(name, entry_point, entry_point_name): + basename = primary_entry_point_name(name, entry_point, entry_point_name) outputs = { "fesm5": "fesm5/%s.js" % basename, "fesm2015": "fesm2015/%s.js" % basename,