Skip to content

Commit e9d64a3

Browse files
committed
build: preserve peerDependenciesMeta in snapshots
Addresses an issue where publishing snapshot builds would replace the value with the package SHAs in `peerDependenciesMeta`. See: https://github.com/angular/angular-build-builds/blob/d4d0f1ca0932bd4fe2df4cc2da10d132789dcd8f/package.json#L89
1 parent 0574076 commit e9d64a3

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

tools/snapshot_repo_filter.bzl

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,30 @@
66
load("//:constants.bzl", "SNAPSHOT_REPOS")
77

88
def _generate_snapshot_repo_filter():
9-
filter = ""
10-
for (i, pkg_name) in enumerate(SNAPSHOT_REPOS.keys()):
11-
filter += "{sep}(..|objects|select(has(\"{pkg_name}\")))[\"{pkg_name}\"] |= \"github:{snapshot_repo}#BUILD_SCM_HASH-PLACEHOLDER\"\n".format(
12-
sep = "| " if i > 0 else "",
13-
pkg_name = pkg_name,
14-
snapshot_repo = SNAPSHOT_REPOS[pkg_name],
9+
"""
10+
Generates a jq filter string to replace direct package.json dependencies, peerDependencies,
11+
and optionalDependencies with snapshot repository URLs.
12+
"""
13+
individual_pkg_filters = []
14+
for pkg_name, snapshot_repo in SNAPSHOT_REPOS.items():
15+
individual_pkg_filters.append(
16+
"""
17+
if has("{pkg_name}") then ."{pkg_name}" = "github:{snapshot_repo}#BUILD_SCM_HASH-PLACEHOLDER" else . end
18+
""".format(
19+
pkg_name = pkg_name,
20+
snapshot_repo = snapshot_repo,
21+
),
1522
)
16-
return filter
23+
24+
chained_filters_for_object = " | ".join(individual_pkg_filters)
25+
26+
return """
27+
(select(has("dependencies")) | .dependencies) |= ({chained_filters}) |
28+
(select(has("peerDependencies")) | .peerDependencies) |= ({chained_filters}) |
29+
(select(has("optionalDependencies")) | .optionalDependencies) |= ({chained_filters})
30+
""".format(
31+
chained_filters = chained_filters_for_object,
32+
)
1733

1834
# jq filter that replaces package.json dependencies with snapshot repos
1935
SNAPSHOT_REPO_JQ_FILTER = _generate_snapshot_repo_filter()

0 commit comments

Comments
 (0)