Skip to content

Commit

Permalink
build(docs-infra): fix playground lezer parsing (#55349)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
devversion authored and pkozlowski-opensource committed Apr 15, 2024
1 parent 9f7b9ed commit 3471c41
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions adev/tools/local_deps/filter_external_npm_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,36 @@ load("@build_bazel_rules_nodejs//:providers.bzl", "ExternalNpmPackageInfo", "Lin

def _filter_external_npm_deps_impl(ctx):
problematic_paths = ["external/npm/node_modules/%s" % pkg for pkg in ctx.attr.angular_packages]
package_name = ctx.attr.target.label.package
has_problematic_transitive_dep = package_name.startswith("@angular-devkit/")
filtered_deps = []

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

filtered_depset = depset(filtered_deps)

providers = [
DefaultInfo(files = filtered_depset),
]

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

return providers

Expand Down

0 comments on commit 3471c41

Please sign in to comment.