build(bazel): add entry_point_name attr to ng_package (#22963)

PR Close #22963
This commit is contained in:
Jeremy Elbourn 2018-03-23 10:11:02 -07:00 committed by Matias Niemelä
parent 27e14b2fb3
commit 2388f24256
1 changed files with 16 additions and 4 deletions

View File

@ -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,