Skip to content

Commit b4bfa86

Browse files
committed
build(docs-infra): fix playground lezer parsing
When we started fixing the version mismatch with local 1st-party packages, we also re-routed all dependencies like `@lezer/javascript` into `adev/node_modules`. This works fine, but results in a different version mismatch because the codemirror dependencies may resolve the Angular version from `/node_modules`- causing some subtle complex runtime error. This commit fixes this by only re-routing dependencies that have dependency on e.g. `@angular/core` into `adev/node_modules`. Fixes angular#55298.
1 parent cfed97d commit b4bfa86

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

‎adev/tools/local_deps/filter_external_npm_deps.bzl‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,35 @@ load("@build_bazel_rules_nodejs//:providers.bzl", "ExternalNpmPackageInfo", "Lin
55

66
def _filter_external_npm_deps_impl(ctx):
77
problematic_paths = ["external/npm/node_modules/%s" % pkg for pkg in ctx.attr.angular_packages]
8+
has_problematic_transitive_dep = False
89
filtered_deps = []
910

1011
# Note: to_list() is expensive; we need to invoke it here to get the path
1112
# of each transitive dependency to check if it's an angular npm package.
1213
for file in ctx.attr.target[DefaultInfo].default_runfiles.files.to_list():
1314
if not any([file.path.startswith(path) for path in problematic_paths]):
1415
filtered_deps.append(file)
16+
else:
17+
has_problematic_transitive_dep = True
18+
1519
filtered_depset = depset(filtered_deps)
1620

1721
providers = [
1822
DefaultInfo(files = filtered_depset),
1923
]
2024

21-
# Re-route all direct dependency external NPM packages into `adev/node_modules` without
22-
# their transitive packages. This allows transitive dependency resolution to first look for
25+
# Re-route all problematic direct dependency external NPM packages into `adev/node_modules`
26+
# without their transitive packages. This allows transitive dependency resolution to first look for
2327
# e.g. `@angular/core` in `adev/node_modules`, and falls back to top-level node modules.
24-
if ctx.attr.target.label.workspace_name == "npm":
28+
# Note: This does not handle cases where Angular dependencies are transitive in deeper layers.
29+
# This is something to be addressed separately via https://github.com/angular/angular/issues/54858.
30+
if has_problematic_transitive_dep and ctx.attr.target.label.workspace_name == "npm":
2531
providers.append(LinkablePackageInfo(
2632
package_name = ctx.attr.target.label.package,
2733
package_path = "adev",
2834
path = "external/npm/node_modules/%s" % ctx.attr.target.label.package,
2935
files = ctx.attr.target[ExternalNpmPackageInfo].direct_sources,
3036
))
31-
else:
32-
fail("Unknown workspace")
3337

3438
return providers
3539

0 commit comments

Comments
 (0)