From d637023389710a4c4c6d90d441671cdfbe57e256 Mon Sep 17 00:00:00 2001 From: Mathieu Olivari Date: Wed, 24 Jun 2026 20:18:50 +0100 Subject: [PATCH] fix(npm): correct package_store_prefix_len for links in external-repo sub-packages `_symlink_package_store` strips `package_store_prefix_len` characters from a dependency's `package_store_directory.short_path` to form the relative symlink target. The length omitted the "/" separators that follow the package path and the repo name, so for a link target in a non-root package of an external repository it stripped two characters too few. The leftover was the trailing "s/" of ".aspect_rules_js/", producing dangling symlinks such as `../../s/@/node_modules/` and `ERR_MODULE_NOT_FOUND` at runtime. In a root module the miscount is only one character and is masked by "//" path collapsing, so it surfaces only when a module's npm packages live in a sub-package (e.g. //frontend) and that module is consumed as an external dependency. Account for both separators: +1 after the package path and +1 after the repo name. --- npm/private/npm_package_store.bzl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/npm/private/npm_package_store.bzl b/npm/private/npm_package_store.bzl index 3dd448abc..d4d1e42d0 100644 --- a/npm/private/npm_package_store.bzl +++ b/npm/private/npm_package_store.bzl @@ -189,9 +189,9 @@ def _npm_package_store_impl(ctx): package_store_prefix_len = _PACKAGE_STORE_PREFIX_LEN if ctx.label.package: - package_store_prefix_len += len(ctx.label.package) + package_store_prefix_len += len(ctx.label.package) + 1 # +1 for the "/" after the package path if ctx.label.repo_name: - package_store_prefix_len += len(ctx.label.repo_name) + 3 # +3 for ../ + package_store_prefix_len += len(ctx.label.repo_name) + 3 + 1 # +3 for "../", +1 for the "/" after the repo name package_key = "{}@{}".format(package, version) package_store_name = utils.package_store_name(package_key)