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

Use corepack to run package managers #21550

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

SvenW
Copy link
Contributor

@SvenW SvenW commented Oct 18, 2024

This makes it possible to run NodeJSToolProcesses as interactive processes. Would be nice if we could setup aliases for each package manager instead perhaps as described here.

Do you have any pointers on how to solve it in another way than this?

Fixes #21205

@SvenW SvenW changed the title Use corepack to run package managers so its possible to use interacti… Use corepack to run package managers Oct 18, 2024
@krishnan-chandra
Copy link
Contributor

I would in general be wary of this because corepack is being removed from future versions of Node. I don't know offhand what the best solution might be, but I think it might be adding the actual underlying package manager binaries (pnpm, yarn, npm) inside the binaries directory instead of corepack.

@SvenW
Copy link
Contributor Author

SvenW commented Oct 18, 2024

I would in general be wary of this because corepack is being removed from future versions of Node. I don't know offhand what the best solution might be, but I think it might be adding the actual underlying package manager binaries (pnpm, yarn, npm) inside the binaries directory instead of corepack.

Sure. If that's the case I agree. But that feels like a separate task, no? Corepack usage is already there, moving to using the package managers themselves feels like a separate thing

@krishnan-chandra
Copy link
Contributor

That's a fair counter; since we are using corepack today in many other places I think this is fair game too.

@huonw huonw requested a review from tobni October 24, 2024 05:29
Copy link
Contributor

@huonw huonw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution and thanks for waiting.

I'm unfamiliar with the details of corepack, the deprecation sounds unfortunate, but as observed, Pants already use it in places, so I'm going to get this in. We can revisit if @tobni or others (maybe @AlexTereshenkov?) have alternative ways to approach this.

@huonw huonw added the release-notes:not-required PR doesn't require mention in release notes label Nov 2, 2024
@tobni
Copy link
Contributor

tobni commented Nov 3, 2024

:shipit:

Nodejs Corepack distribution being deprecated is something needs fixing, sure. Adding this feature doesn't really complicate that.

To be clear, corepack isn't deprecated, just the node binaries distribution containing corepack.

@SvenW SvenW force-pushed the fix/node-interactive-process branch from 30c9ed4 to de72643 Compare November 6, 2024 10:28
Comment on lines 88 to 95
pytest.param("npm", "10.8.2", id="npm"),
pytest.param("pnpm", "9.5.0", id="pnpm"),
pytest.param("npm", "10.9.0", id="npm"),
pytest.param("pnpm", "9.12.3", id="pnpm"),
Copy link
Contributor

@huonw huonw Nov 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just checking before merging: can you expand a bit on why these changed?

(No need to revert/change again, but I'd like to be sure that we don't have to update them again when new versions are released, so that these tests don't depend on external state.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, those are now picked up by the version installed via corepack. I'm not really sure on how we could lock them, when running the activate command for corepack perhaps?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, thanks.

It's definitely unexpected to me that setting --nodejs-package-managers={...} with explicit versions doesn't end up using those exact versions, I think we may need to fix this.

@tobni, any opinions/advice?

Copy link
Contributor

@huonw huonw Nov 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, looking at https://github.com/nodejs/corepack?tab=readme-ov-file#utility-commands suggests that we could run like, for instance, args=("[email protected]", ...). So, maybe:

  1. add a method for getting the ...@... installation specification to PackageManager, e.g.:
    def spec(self) -> str:
        return f"{self.name}@{self.version}" if self.version is not None else self.name
  2. invoke the process with args=(pkg_manager.spec(), ...)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, nice find. I'll try and see if I can get to it later this week

Copy link
Contributor Author

@SvenW SvenW Nov 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just quickly tested this and it seems to work for all package managers except yarn that ends up with this error error Couldn't find a package.json file in "/private/tmp/pants-sandbox-pPJw4m"
Might be connected to nodejs/corepack#334

@benjyw
Copy link
Contributor

benjyw commented Nov 21, 2024

Hi folks, what's the status on this? @huonw , could this be merged as-is?

@SvenW
Copy link
Contributor Author

SvenW commented Nov 22, 2024

Hi folks, what's the status on this? @huonw , could this be merged as-is?

I've gotten stuck on other work unfortunately and I didn't manage to get all package managers running with the version specified in the run args. yarn for example got caught on the error I wrote about earlier

@SvenW SvenW force-pushed the fix/node-interactive-process branch from 24d7301 to f161f35 Compare November 25, 2024 10:12
@SvenW
Copy link
Contributor Author

SvenW commented Nov 25, 2024

I made some changes so we're able to run package managers on a specific version. I was unable to get it running for yarn so therefor the somewhat ugly fix to disregard that specific package manager for now. Would love any help on getting it running with yarn as well but this will at least keep us from needing to update test versions as often :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-notes:not-required PR doesn't require mention in release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NodeJSProcess as an InteractiveProcess can't locate the tool
5 participants