Skip to content

Commit 9a76eb9

Browse files
alan-agius4jbedard
authored andcommitted
fix: handle missing packages in _collect_dep_constraints
When an optional dependency is a "link:" dependency or otherwise not present in the `packages` dictionary, `npm_translate_lock` would fail with a "key not found" error such as: `Error: key "link:@angular/core|packages/core" not found in dictionary` This occurs because `_collect_dep_constraints` iterates over optional dependencies but assumes they all exist in the `packages` dictionary. Link dependencies are often not represented in the lockfile as standard packages, leading to this missing key.
1 parent b809b52 commit 9a76eb9

9 files changed

Lines changed: 154 additions & 0 deletions

File tree

e2e/pnpm_lockfiles/.bazelignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ node_modules/
22
cases/versionless-patch-v9/node_modules
33
cases/docusaurus-direct-peer-v9/node_modules
44
cases/nested-peer-v9/node_modules
5+
cases/workspace-peer-v9/node_modules
6+
cases/workspace-peer-v9/libs/chokidar/node_modules
57
cases/isaacs-cliui-v90/node_modules
68
cases/override-with-alias-url-v9/node_modules
79
projects/a/node_modules

e2e/pnpm_lockfiles/MODULE.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ PNPM_LOCK_TEST_CASES = [
1717
"docusaurus-direct-peer-v9",
1818
"versionless-patch-v9",
1919
"nested-peer-v9",
20+
"workspace-peer-v9",
2021
]
2122

2223
bazel_dep(name = "bazel_lib", version = "3.0.0")
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
load("@bazel_skylib//rules:build_test.bzl", "build_test")
2+
load("@workspace-peer-v9//:defs.bzl", "npm_link_all_packages")
3+
4+
exports_files(["pnpm-lock.yaml"])
5+
6+
npm_link_all_packages()
7+
8+
build_test(
9+
name = "optional_peers_targets",
10+
targets = [
11+
":node_modules",
12+
":node_modules/chokidar",
13+
],
14+
)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
load("@aspect_rules_js//js:defs.bzl", "js_library")
2+
3+
js_library(
4+
name = "pkg",
5+
srcs = ["package.json"],
6+
visibility = ["//visibility:public"],
7+
)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"private": true,
3+
"name": "chokidar"
4+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "workspace-peer",
3+
"private": true,
4+
"pnpm": {
5+
"onlyBuiltDependencies": []
6+
},
7+
"devDependencies": {
8+
"@angular-devkit/core": "21.2.1",
9+
"chokidar": "workspace:*"
10+
}
11+
}

e2e/pnpm_lockfiles/cases/workspace-peer-v9/pnpm-lock.yaml

Lines changed: 109 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
packages:
2+
- '.'
3+
- 'libs/*'

npm/private/npm_translate_lock_helpers.bzl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,9 @@ def _collect_dep_constraints(packages, package_info):
555555

556556
optional_keys = package_info["optional_dependencies"].values() + package_info.get("transitive_optional_closure", {}).keys()
557557
for dep_key in optional_keys:
558+
if dep_key.startswith("link:"):
559+
continue
560+
558561
dep = packages[dep_key]
559562
if dep["os"]:
560563
constraints_os[dep_key] = dep["os"]

0 commit comments

Comments
 (0)