Skip to content

Commit

Permalink
refactor(pnpm): move pnpm parsing logic to pnpm.bzl
Browse files Browse the repository at this point in the history
  • Loading branch information
jbedard committed Jun 4, 2024
1 parent 677033d commit 3e6d5b2
Show file tree
Hide file tree
Showing 8 changed files with 655 additions and 626 deletions.
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

0 comments on commit 3e6d5b2

Please sign in to comment.