Skip to content

Commit a8c192e

Browse files
gregmagolanalexeagle
authored andcommitted
Fix issue #435
1 parent 143b8f7 commit a8c192e

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

npm/private/npm_translate_lock.bzl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,10 @@ load("@aspect_rules_js//js:defs.bzl", _js_library = "js_library")"""]
543543
version = package_info.get("version")
544544
deps = package_info.get("dependencies")
545545
if version.startswith("file:"):
546-
dep_path = _link_package(root_package, version[len("file:"):])
546+
if version in packages and packages[version]["id"]:
547+
dep_path = _link_package(root_package, packages[version]["id"][len("file:"):])
548+
else:
549+
dep_path = _link_package(root_package, version[len("file:"):])
547550
dep_key = "{}+{}".format(name, version)
548551
transitive_deps = {}
549552
for raw_package, raw_version in deps.items():
@@ -589,7 +592,10 @@ load("@aspect_rules_js//js:defs.bzl", _js_library = "js_library")"""]
589592
link_package = _link_package(root_package, import_path)
590593
for dep_package, dep_version in dependencies.items():
591594
if dep_version.startswith("file:"):
592-
dep_path = _link_package(root_package, dep_version[len("file:"):])
595+
if dep_version in packages and packages[dep_version]["id"]:
596+
dep_path = _link_package(root_package, packages[dep_version]["id"][len("file:"):])
597+
else:
598+
dep_path = _link_package(root_package, dep_version[len("file:"):])
593599
dep_key = "{}+{}".format(dep_package, dep_version)
594600
if not dep_key in fp_links.keys():
595601
fail("Expected to file: referenced package {} in first-party links".format(dep_key))

npm/private/transitive_closure.bzl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,12 @@ def gather_transitive_closure(packages, no_optional, direct_deps, transitive_clo
4040
if version in transitive_closure[name]:
4141
continue
4242
transitive_closure[name].insert(0, version)
43-
package_info = packages[package_key]
43+
if package_key.startswith("link:"):
44+
# we don't need to drill down through first-party links for the transitive closure since there are no cycles
45+
# allowed in first-party links
46+
continue
47+
else:
48+
package_info = packages[package_key]
4449
stack.append(package_info["dependencies"] if no_optional else dicts.add(package_info["dependencies"], package_info["optionalDependencies"]))
4550

4651
def _gather_package_info(package_path, package_snapshot):
@@ -71,6 +76,7 @@ def _gather_package_info(package_path, package_snapshot):
7176

7277
if "resolution" not in package_snapshot:
7378
fail("package %s has no resolution field" % package_path)
79+
id = package_snapshot["id"] if "id" in package_snapshot else None
7480
resolution = package_snapshot["resolution"]
7581
integrity = resolution["integrity"] if "integrity" in resolution else None
7682
tarball = resolution["tarball"] if "tarball" in resolution else None
@@ -81,6 +87,7 @@ def _gather_package_info(package_path, package_snapshot):
8187

8288
return package_key, {
8389
"name": name,
90+
"id": id,
8491
"version": version,
8592
"friendly_version": friendly_version,
8693
"integrity": integrity,

0 commit comments

Comments
 (0)