Skip to content

Commit 9bf9864

Browse files
devversionpkozlowski-opensource
authored andcommitted
build(docs-infra): fix playground lezer parsing (#55349)
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 #55298. PR Close #55349
1 parent a3b1dc0 commit 9bf9864

1 file changed

Lines changed: 12 additions & 7 deletions

File tree

‎adev/tools/local_deps/filter_external_npm_deps.bzl‎

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,36 @@ 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+
package_name = ctx.attr.target.label.package
9+
has_problematic_transitive_dep = package_name.startswith("@angular-devkit/")
810
filtered_deps = []
911

1012
# Note: to_list() is expensive; we need to invoke it here to get the path
1113
# of each transitive dependency to check if it's an angular npm package.
1214
for file in ctx.attr.target[DefaultInfo].default_runfiles.files.to_list():
1315
if not any([file.path.startswith(path) for path in problematic_paths]):
1416
filtered_deps.append(file)
17+
else:
18+
has_problematic_transitive_dep = True
19+
1520
filtered_depset = depset(filtered_deps)
1621

1722
providers = [
1823
DefaultInfo(files = filtered_depset),
1924
]
2025

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
26+
# Re-route all problematic direct dependency external NPM packages into `adev/node_modules`
27+
# without their transitive packages. This allows transitive dependency resolution to first look for
2328
# 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":
29+
# Note: This does not handle cases where Angular dependencies are transitive in deeper layers.
30+
# This is something to be addressed separately via https://github.com/angular/angular/issues/54858.
31+
if has_problematic_transitive_dep and ctx.attr.target.label.workspace_name == "npm":
2532
providers.append(LinkablePackageInfo(
26-
package_name = ctx.attr.target.label.package,
33+
package_name = package_name,
2734
package_path = "adev",
28-
path = "external/npm/node_modules/%s" % ctx.attr.target.label.package,
35+
path = "external/npm/node_modules/%s" % package_name,
2936
files = ctx.attr.target[ExternalNpmPackageInfo].direct_sources,
3037
))
31-
else:
32-
fail("Unknown workspace")
3338

3439
return providers
3540

0 commit comments

Comments
 (0)