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

refactor(pnpm): move pnpm parsing logic to pnpm.bzl #1777

Merged
merged 1 commit into from
Jun 5, 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
7 changes: 7 additions & 0 deletions npm/private/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ bzl_library(
":npm_translate_lock_macro_helpers",
":npm_translate_lock_state",
":npmrc",
":pnpm",
":pnpm_repository",
":transitive_closure",
":utils",
Expand All @@ -218,6 +219,12 @@ bzl_library(
] + (["@bazel_tools//tools/build_defs/repo:cache.bzl"] if bazel_lib_utils.is_bazel_7_or_greater() else []),
)

bzl_library(
name = "pnpm",
srcs = ["pnpm.bzl"],
visibility = ["//npm:__subpackages__"],
)

bzl_library(
name = "transitive_closure",
srcs = ["transitive_closure.bzl"],
Expand Down
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 @@ -259,7 +259,7 @@ def _get_npm_imports(importers, packages, patched_dependencies, only_built_depen
# special case for alias dependencies such as npm:alias-to@version
maybe_package = dep_version[4:]
elif dep_version not in packages:
maybe_package = utils.pnpm_name(dep_package, dep_version)
maybe_package = utils.package_key(dep_package, dep_version)
else:
maybe_package = dep_version
if maybe_package not in linked_packages:
Expand Down
3 changes: 2 additions & 1 deletion npm/private/npm_translate_lock_state.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ load("@bazel_skylib//lib:dicts.bzl", "dicts")
load("@bazel_skylib//lib:paths.bzl", "paths")
load(":npm_translate_lock_helpers.bzl", "helpers")
load(":npmrc.bzl", "parse_npmrc")
load(":pnpm.bzl", "pnpm")
load(":repository_label_store.bzl", "repository_label_store")
load(":utils.bzl", "INTERNAL_ERROR_MSG", "utils")

Expand Down Expand Up @@ -490,7 +491,7 @@ def _load_lockfile(priv, rctx, _, label_store):
if result.return_code:
lock_parse_err = "failed to parse pnpm lock file with yq. '{}' exited with {}: \nSTDOUT:\n{}\nSTDERR:\n{}".format(" ".join(yq_args), result.return_code, result.stdout, result.stderr)
else:
importers, packages, patched_dependencies, lock_version, lock_parse_err = utils.parse_pnpm_lock_json(result.stdout if result.stdout != "null" else None) # NB: yq will return the string "null" if the yaml file is empty
importers, packages, patched_dependencies, lock_version, lock_parse_err = pnpm.parse_pnpm_lock_json(result.stdout if result.stdout != "null" else None) # NB: yq will return the string "null" if the yaml file is empty

priv["lock_version"] = lock_version
priv["importers"] = importers
Expand Down
Loading
Loading