Skip to content

Commit

Permalink
fix: support running pnpm on empty lockfile (#1057)
Browse files Browse the repository at this point in the history
Fix #925
  • Loading branch information
jbedard authored May 11, 2023
1 parent 1c1c95d commit 7b1e6e5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
13 changes: 13 additions & 0 deletions npm/private/test/parse_pnpm_lock_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
load("@bazel_skylib//lib:unittest.bzl", "asserts", "unittest")
load("//npm/private:utils.bzl", "utils")

def _parse_empty_lock_test_impl(ctx):
env = unittest.begin(ctx)

parsed = utils.parse_pnpm_lock("")
expected = ({}, {}, {})

asserts.equals(env, expected, parsed)

def _parse_lockfile_v5_test_impl(ctx):
env = unittest.begin(ctx)

Expand Down Expand Up @@ -122,6 +130,11 @@ parse_lockfile_v5_test = unittest.make(
attrs = {},
)

parse_empty_lock_test = unittest.make(
_parse_empty_lock_test_impl,
attrs = {},
)

parse_lockfile_v6_test = unittest.make(
_parse_lockfile_v6_test_impl,
attrs = {},
Expand Down
3 changes: 3 additions & 0 deletions npm/private/utils.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ def _parse_pnpm_lock(content):
"""
parsed = _parse_yaml(content)

if parsed == None:
return {}, {}, {}

if not types.is_dict(parsed):
fail("lockfile should be a starlark dict")
if "lockfileVersion" not in parsed.keys():
Expand Down

0 comments on commit 7b1e6e5

Please sign in to comment.