Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(pnpm): npm aliases to url specifiers #1772

Merged
merged 2 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion e2e/pnpm_lockfiles/lockfile-test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def lockfile_test(name = None):
# Odd git/http versions
":node_modules/debug",
":node_modules/hello",
# ":node_modules/jsonify", TODO: v9
":node_modules/jsonify",

# npm: alias
":node_modules/@aspect-test/a2",
Expand Down
5 changes: 4 additions & 1 deletion e2e/pnpm_lockfiles/v90/snapshots/defs.bzl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion npm/private/npm_translate_lock_helpers.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def _get_npm_imports(importers, packages, patched_dependencies, only_built_depen
if dep_version.startswith("npm:"):
# special case for alias dependencies such as npm:alias-to@version
maybe_package = dep_version[4:]
elif dep_version[0].isdigit():
elif dep_version not in packages:
maybe_package = utils.pnpm_name(dep_package, dep_version)
else:
maybe_package = dep_version
Expand Down
4 changes: 2 additions & 2 deletions npm/private/transitive_closure.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ def gather_transitive_closure(packages, package, no_optional, cache = {}):
# an aliased dependency
package_key = version[4:]
name, version = utils.parse_pnpm_package_key(name, version)
elif version[0].isdigit():
elif version not in packages:
package_key = utils.pnpm_name(name, version)
else:
package_key = version
transitive_closure[name] = transitive_closure.get(name, [])
if version in transitive_closure[name]:
continue
transitive_closure[name].append(version)
if package_key.startswith("link:"):
if version.startswith("link:"):
# we don't need to drill down through first-party links for the transitive closure since there are no cycles
# allowed in first-party links
continue
Expand Down
17 changes: 7 additions & 10 deletions npm/private/utils.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def _convert_v5_v6_file_package(package_path, package_snapshot):
else:
friendly_version = package_snapshot["version"] if "version" in package_snapshot else version

return _to_package_key(name, version), name, version, friendly_version
jbedard marked this conversation as resolved.
Show resolved Hide resolved
return name, version, friendly_version

def _convert_v5_packages(packages):
result = {}
Expand All @@ -207,22 +207,22 @@ def _convert_v5_packages(packages):

if package_path.startswith("file:"):
# direct reference to file
package_key, name, version, friendly_version = _convert_v5_v6_file_package(package_path, package_snapshot)
name, version, friendly_version = _convert_v5_v6_file_package(package_path, package_snapshot)
elif "name" in package_snapshot and "version" in package_snapshot:
# key/path is complicated enough the real name+version are properties
name = package_snapshot["name"]
version = _strip_v5_default_registry_to_version(name, package_path)
friendly_version = package_snapshot["version"]
package_key = _to_package_key(name, version)
elif package_path.startswith("/"):
# a simple /name/version[_peer_info]
name, version = package_path[1:].rsplit("/", 1)
friendly_version = _strip_v5_peer_dep_or_patched_version(version)
package_key = _to_package_key(name, version)
else:
msg = "unexpected package path: {} of {}".format(package_path, package_snapshot)
fail(msg)

package_key = _to_package_key(name, version)

package_info = _new_package_info(
id = package_snapshot.get("id", None),
name = name,
Expand Down Expand Up @@ -364,22 +364,22 @@ def _convert_v6_packages(packages):

if package_path.startswith("file:"):
# direct reference to file
package_key, name, version, friendly_version = _convert_v5_v6_file_package(package_path, package_snapshot)
name, version, friendly_version = _convert_v5_v6_file_package(package_path, package_snapshot)
elif "name" in package_snapshot and "version" in package_snapshot:
# key/path is complicated enough the real name+version are properties
name = package_snapshot["name"]
version = _strip_v6_default_registry_to_version(name, package_path)
friendly_version = package_snapshot["version"]
package_key = _to_package_key(name, version)
elif package_path.startswith("/"):
# plain /pkg@version(_peer_info)
name, version = package_path[1:].rsplit("@", 1)
friendly_version = _strip_v5_peer_dep_or_patched_version(version) # NOTE: already converted to v5 peer style
package_key = _to_package_key(name, version)
else:
msg = "unexpected package path: {} of {}".format(package_path, package_snapshot)
fail(msg)

package_key = _to_package_key(name, version)

package_info = _new_package_info(
id = package_snapshot.get("id", None),
name = name,
Expand Down Expand Up @@ -501,9 +501,6 @@ def _convert_v9_packages(packages, snapshots):
# package_data can have the resolved "version" for things like https:// deps
friendly_version = package_data["version"] if "version" in package_data else static_key[version_index + 1:]

# Convert the package_key to a rules_js compatible format
package_key = _to_package_key(name, version)
jbedard marked this conversation as resolved.
Show resolved Hide resolved

package_info = _new_package_info(
id = package_data.get("id", None), # TODO: does v9 have "id"?
name = name,
Expand Down