Skip to content

Commit f8a1ea0

Browse files
devversiondylhunn
authored andcommitted
fix(bazel): do not error if files part of srcs are outside of package (angular#45622)
We recently refactored how the ng package rule deals with static files. As part of this refactoring, transitive files outside of the current Bazel package were flagged as errors, while previously this was just ignored. We need to revert back this behavior (even though code remains much simpler and predicable now) since sass library targets for example reference all transtive files in the default info and break packages then PR Close angular#45622
1 parent 000363e commit f8a1ea0

File tree

5 files changed

+14
-4
lines changed

5 files changed

+14
-4
lines changed

packages/bazel/src/ng_package/ng_package.bzl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -289,12 +289,14 @@ def _ng_package_impl(ctx):
289289

290290
# Static files are files which are simply copied over into the tree artifact. These files
291291
# are not picked up by the entry-point bundling etc. Can also be generated by e.g. a genrule.
292-
static_files = ctx.files.srcs
292+
static_files = []
293293

294-
# Disallow static files outside of the current owning package.
294+
# Collect static files, and skip files outside of the current owning package.
295295
for file in ctx.files.srcs:
296296
if not file.short_path.startswith(owning_package):
297-
fail("Unexpected file. %s is defined outside of %s." % (file, owning_package))
297+
_debug(ctx.var, "File %s is defined outside of %s but part of `srcs`, skipping." % (file, owning_package))
298+
else:
299+
static_files.append(file)
298300

299301
# These accumulators match the directory names where the files live in the
300302
# Angular package format.

packages/bazel/test/ng_package/BUILD.bazel

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
load("//tools:defaults.bzl", "jasmine_node_test", "nodejs_binary", "ts_library")
22

3-
exports_files(["package.json"])
3+
exports_files([
4+
"package.json",
5+
"outside_package.txt",
6+
])
47

58
# The tests in this package must run in separate targets, since they change
69
# working directory and therefore have mutable global state that causes test

packages/bazel/test/ng_package/example-with-ts-library/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ ng_package(
1313
name = "npm_package",
1414
srcs = [
1515
"package.json",
16+
# This file should be just ignored, and not copied into the package.
17+
"//packages/bazel/test/ng_package:outside_package.txt",
1618
],
1719
deps = [
1820
":example",

packages/bazel/test/ng_package/example/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ ng_package(
2222
":arbitrary_genfiles_file",
2323
":extra-styles.css",
2424
":logo.png",
25+
# This file should be just ignored, and not copied into the package.
26+
"//packages/bazel/test/ng_package:outside_package.txt",
2527
],
2628
nested_packages = [
2729
":arbitrary_npm_package",
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This file is not part of the example packages.

0 commit comments

Comments
 (0)