8000 fix(npm): pnpm v9 file: archive references · aspect-build/rules_js@9dd5808 · GitHub 8000
[go: up one dir, main page]

Skip to content

Commit 9dd5808

Browse files
committed
fix(npm): pnpm v9 file: archive references
Fix #1977
1 parent d8f63d9 commit 9dd5808

File tree

3 files changed

+56
-84
lines changed

3 files changed

+56
-84
lines changed

e2e/pnpm_lockfiles/v90/snapshots/defs.bzl

Lines changed: 42 additions & 76 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

npm/private/npm_translate_lock_generate.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ sh_binary(
166166
dep_path = helpers.link_package(root_package, dep_version[len("file:"):])
167167
dep_key = "{}+{}".format(dep_package, dep_version)
168168
if not dep_key in fp_links.keys():
169-
msg = "Expected to file: referenced package {} in first-party links".format(dep_key)
169+
msg = "Expected file: referenced package {} in first-party links {}".format(dep_key, fp_links.keys())
170170
fail(msg)
171171
fp_links[dep_key]["link_packages"][link_package] = []
172172
elif dep_version.startswith("link:"):

npm/private/pnpm.bzl

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ load(":utils.bzl", "DEFAULT_REGISTRY_DOMAIN_SLASH", "utils")
55

66
def _is_vendored_tarfile(package_snapshot):
77
if "resolution" in package_snapshot:
8-
return "tarball" in package_snapshot["resolution"]
8+
return "tarball" in package_snapshot["resolution"] and package_snapshot["resolution"]["tarball"].startswith("file:")
99
return False
1010

1111
def _to_package_key(name, version):
@@ -461,9 +461,9 @@ def _convert_v9_packages(packages, snapshots):
461461
result = {}
462462

463463
# Snapshots contains the packages with the keys (which include peers) to return
464-
for package_key, package_snapshot in snapshots.items():
465-
peer_meta_index = package_key.find("(")
466-
static_key = package_key[:peer_meta_index] if peer_meta_index > 0 else package_key
464+
for package_path, package_snapshot in snapshots.items():
465+
peer_meta_index = package_path.find("(")
466+
static_key = package_path[:peer_meta_index] if peer_meta_index > 0 else package_path
467467
if not static_key in packages:
468468
msg = "package {} not found in pnpm 'packages'".format(static_key)
469469
fail(msg)
@@ -474,17 +474,23 @@ def _convert_v9_packages(packages, snapshots):
474474
msg = "package {} has no resolution field".format(static_key)
475475
fail(msg)
476476

477-
# the raw name + version are the key, not including peerDeps+patch
477+
package_key = _convert_pnpm_v6_v9_version_peer_dep(package_path)
478+
479+
# the raw name + version are the static_key, not including peerDeps+patch
478480
version_index = static_key.index("@", 1)
479481
name = static_key[:version_index]
480-
package_key = _convert_pnpm_v6_v9_version_peer_dep(package_key)
481482

482-
# Extract the version including peerDeps+patch from the key
483+
# Extract the version including peerDeps+patch from the package_key
483484
version = package_key[package_key.index("@", 1) + 1:]
484485

485486
# package_data can have the resolved "version" for things like https:// deps
486487
friendly_version = package_data["version"] if "version" in package_data else static_key[version_index + 1:]
487488

489+
# direct reference to tarball files: use the friendly_version to align with pnpm <v9 which
490+
# uses the resolved version in the package store.
491+
if _is_vendored_tarfile(package_data):
492+
version = friendly_version
493+
488494
package_info = _new_package_info(
489495
id = package_data.get("id", None), # TODO: does v9 have "id"?
490496
name = name,

0 commit comments

Comments
 (0)
0