Skip to content

Commit

Permalink
Use specific versions for all package managers except yarn
Browse files Browse the repository at this point in the history
  • Loading branch information
SvenW committed Nov 25, 2024
1 parent ca355d9 commit f161f35
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
3 changes: 3 additions & 0 deletions src/python/pants/backend/javascript/package_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,6 @@ def npm(cls, version: str | None) -> PackageManager:
pack_archive_format="{}-{}.tgz",
extra_caches=FrozenDict(),
)

def spec(self) -> str:
return self.name if self.version is None else f"{self.name}@{self.version}"
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,18 @@ async def _run_tool_without_resolve(request: NodeJSToolRequest) -> Process:
)
)
pkg_manager = PackageManager.from_string(pkg_manager_and_version)
if pkg_manager.name == PackageManager.yarn.__name__:
cmd = pkg_manager.name
else:
cmd = pkg_manager.spec()

return await Get(
Process,
NodeJSToolProcess(
env.binaries.binary_dir + "/corepack",
pkg_manager.version,
args=(
pkg_manager.name,
cmd,
*pkg_manager.download_and_execute_args,
request.tool,
*request.args,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ def test_version_option_overrides_default(rule_runner: RuleRunner):
"package_manager, expected_argv",
[
pytest.param("yarn", ("yarn", "dlx", "--quiet"), id="yarn"),
pytest.param("npm", ("npm", "exec", "--yes", "--"), id="npm"),
pytest.param("pnpm", ("pnpm", "dlx"), id="pnpm"),
pytest.param("npm", ("npm@10.8.2", "exec", "--yes", "--"), id="npm"),
pytest.param("pnpm", ("pnpm@9.5.0", "dlx"), id="pnpm"),
],
)
def test_execute_process_with_package_manager(
Expand Down Expand Up @@ -91,8 +91,8 @@ def test_execute_process_with_package_manager(
"package_manager, version",
[
pytest.param("yarn", "1.22.22", id="yarn"),
pytest.param("npm", "10.9.0", id="npm"),
pytest.param("pnpm", "9.12.3", id="pnpm"),
pytest.param("npm", "10.8.2", id="npm"),
pytest.param("pnpm", "9.5.0", id="pnpm"),
],
)
def test_execute_process_with_package_manager_version_from_configuration(
Expand Down Expand Up @@ -199,8 +199,12 @@ def request_package_manager_version_for_tool(
) -> str:
request = tool.request((), EMPTY_DIGEST, "Inspect package manager version", LogLevel.DEBUG)
process = rule_runner.request(Process, [request])
if process.argv[0].find("corepack") != -1:
args = process.argv[:2] + ("--version",)
else:
args = (package_manager, "--version")
result = rule_runner.request(
ProcessResult,
[dataclasses.replace(process, argv=(package_manager, "--version"))],
[dataclasses.replace(process, argv=args)],
)
return result.stdout.decode().strip()

0 comments on commit f161f35

Please sign in to comment.