Skip to content

Commit 3a732f8

Browse files
committed
refactor: raise unsupported package manager
1 parent 86475c8 commit 3a732f8

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/python/pants/backend/javascript/nodejs_project.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,13 @@ def generate_lockfile_args(self) -> tuple[str, ...]:
8080
def immutable_install_args(self) -> tuple[str, ...]:
8181
if self.package_manager == "npm":
8282
return ("clean-install",)
83+
if self.package_manager == "pnpm":
84+
return ("install", "--frozen-lockfile")
8385
if self.package_manager == "yarn":
8486
if nodesemver.satisfies(self.package_manager_version, "1.x"):
8587
return ("install", "--frozen-lockfile")
8688
return ("install", "--immutable")
87-
return ("install", "--frozen-lockfile")
89+
raise ValueError(f"Unsupported package manager: {self.package_manager}")
8890

8991
@property
9092
def workspace_specifier_arg(self) -> str:

src/python/pants/backend/javascript/nodejs_project_test.py

+13
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,19 @@ def test_immutable_install_args_property(rule_runner: RuleRunner) -> None:
9595
}
9696

9797

98+
def test_immutable_install_args_property_with_unsupported_package_manager(rule_runner: RuleRunner) -> None:
99+
rule_runner.write_files(
100+
{
101+
"src/js/foo/BUILD": "package_json()",
102+
"src/js/foo/package.json": given_package("foo", "0.0.1", package_manager="[email protected]"),
103+
}
104+
)
105+
projects = rule_runner.request(AllNodeJSProjects, [])
106+
expected_error = "Unsupported package manager: bar"
107+
with pytest.raises(ValueError, match=expected_error):
108+
{project.immutable_install_args for project in projects}
109+
110+
98111
def test_root_package_json_is_supported(rule_runner: RuleRunner) -> None:
99112
rule_runner.write_files(
100113
{

0 commit comments

Comments
 (0)