Skip to content

Commit fb32196

Browse files
JeanMechedevversion
authored andcommitted
build: Add LICENSE file to the generated packages (angular#58033)
This commit adds a parameter to `ng_package` to specify a license file that will be bundled with the generated packages. fixes angular#58029 PR Close angular#58033
1 parent d60bb51 commit fb32196

File tree

5 files changed

+74
-1
lines changed

5 files changed

+74
-1
lines changed

packages/bazel/src/ng_package/ng_package.bzl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,13 @@ def _ng_package_impl(ctx):
478478
# placeholder
479479
packager_args.add("")
480480

481+
if ctx.file.license:
482+
packager_inputs.append(ctx.file.license)
483+
packager_args.add(ctx.file.license.path)
484+
else:
485+
#placeholder
486+
packager_args.add("")
487+
481488
packager_args.add(_serialize_files_for_arg(fesm2022))
482489
packager_args.add(_serialize_files_for_arg(esm2022))
483490
packager_args.add(_serialize_files_for_arg(static_files))
@@ -537,6 +544,10 @@ _NG_PACKAGE_ATTRS = dict(PKG_NPM_ATTRS, **{
537544
Configured substitutions are applied like with other files in the package.""",
538545
allow_single_file = [".txt"],
539546
),
547+
"license": attr.label(
548+
doc = """A textfile that will be copied to the root of the npm package.""",
549+
allow_single_file = True,
550+
),
540551
"deps": attr.label_list(
541552
doc = """ Targets that produce production JavaScript outputs, such as `ts_library`.""",
542553
aspects = _NG_PACKAGE_DEPS_ASPECTS,

packages/bazel/src/ng_package/packager.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ function main(args: string[]): void {
6868
// Path to the package's README.md.
6969
readmeMd,
7070

71+
// Path to the package's LICENSE file.
72+
licenseFile,
73+
7174
// List of rolled-up flat ES2022 modules
7275
fesm2022Arg,
7376

@@ -91,6 +94,10 @@ function main(args: string[]): void {
9194
copyFile(readmeMd, 'README.md');
9295
}
9396

97+
if (licenseFile) {
98+
copyFile(licenseFile, 'LICENSE');
99+
}
100+
94101
/**
95102
* Writes a file with the specified content into the package output.
96103
* @param outputRelativePath Relative path in the output directory where the

packages/bazel/test/ng_package/example_package.golden

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
LICENSE
12
README.md
23
_index.scss
34
a11y
@@ -23,6 +24,31 @@ package.json
2324
secondary
2425
secondary/index.d.ts
2526
some-file.txt
27+
--- LICENSE ---
28+
29+
The MIT License
30+
31+
Copyright (c) 2010-2024 Google LLC. https://angular.dev/license
32+
33+
Permission is hereby granted, free of charge, to any person obtaining a copy
34+
of this software and associated documentation files (the "Software"), to deal
35+
in the Software without restriction, including without limitation the rights
36+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
37+
copies of the Software, and to permit persons to whom the Software is
38+
furnished to do so, subject to the following conditions:
39+
40+
The above copyright notice and this permission notice shall be included in
41+
all copies or substantial portions of the Software.
42+
43+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
44+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
45+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
46+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
47+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
48+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
49+
THE SOFTWARE.
50+
51+
2652
--- README.md ---
2753

2854
Angular

packages/bazel/test/ng_package/example_with_ts_library_package.golden

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
LICENSE
12
README.md
23
fesm2022
34
fesm2022/example-with-ts-library.mjs
@@ -12,6 +13,31 @@ portal
1213
portal/index.d.ts
1314
utils
1415
utils/index.d.ts
16+
--- LICENSE ---
17+
18+
The MIT License
19+
20+
Copyright (c) 2010-2024 Google LLC. https://angular.dev/license
21+
22+
Permission is hereby granted, free of charge, to any person obtaining a copy
23+
of this software and associated documentation files (the "Software"), to deal
24+
in the Software without restriction, including without limitation the rights
25+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
26+
copies of the Software, and to permit persons to whom the Software is
27+
furnished to do so, subject to the following conditions:
28+
29+
The above copyright notice and this permission notice shall be included in
30+
all copies or substantial portions of the Software.
31+
32+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
33+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
34+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
35+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
36+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
37+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
38+
THE SOFTWARE.
39+
40+
1541
--- README.md ---
1642

1743
Angular

tools/defaults.bzl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,12 +188,14 @@ def ng_module(name, tsconfig = None, entry_point = None, testonly = False, deps
188188
**kwargs
189189
)
190190

191-
def ng_package(name, readme_md = None, license_banner = None, deps = [], **kwargs):
191+
def ng_package(name, readme_md = None, license_banner = None, license = None, deps = [], **kwargs):
192192
"""Default values for ng_package"""
193193
if not readme_md:
194194
readme_md = "//packages:README.md"
195195
if not license_banner:
196196
license_banner = "//packages:license-banner.txt"
197+
if not license:
198+
license = "//:LICENSE"
197199
visibility = kwargs.pop("visibility", None)
198200

199201
common_substitutions = dict(kwargs.pop("substitutions", {}), **PKG_GROUP_REPLACEMENTS)
@@ -209,6 +211,7 @@ def ng_package(name, readme_md = None, license_banner = None, deps = [], **kwarg
209211
deps = deps,
210212
validate = True,
211213
readme_md = readme_md,
214+
license = license,
212215
license_banner = license_banner,
213216
substitutions = select({
214217
"//:stamp": stamped_substitutions,

0 commit comments

Comments
 (0)