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

How can I detect if corepack is already enabled? #113

Closed
styfle opened this issue May 27, 2022 · 6 comments
Closed

How can I detect if corepack is already enabled? #113

styfle opened this issue May 27, 2022 · 6 comments

Comments

@styfle
Copy link
Member

styfle commented May 27, 2022

If we were to programmatically enable corepack, we would want to disable after the work is complete.

However, if the user already had corepack enabled, then we wouldn't want to disable it.

Is there a way to get the current state to determine if its already enabled?

@arcanis
Copy link
Contributor

arcanis commented May 27, 2022

Can you detail more the use case you have in mind?

@styfle
Copy link
Member Author

styfle commented May 28, 2022

Basically this PR:

Since corepack is changing global bins, we don't want to run corepack disable if the user had already enabled it. We only want to disable if we were the ones to enable it, thus leaving the user's system in the original state when we're done.

@arcanis
Copy link
Contributor

arcanis commented May 28, 2022

You can detect whether you're running within a Corepack context by checking if COREPACK_ROOT is set in the env, cf here.

That said, for your own use case, I wonder if perhaps the absolute no-risks option wouldn't be to just enable corepack in a temporary folder which you'd add to the PATH of your subshells, and just optionally cleanup at the end of the execution?

@styfle
Copy link
Member Author

styfle commented May 28, 2022

Yeah that sounds good, how would I do that? 🙂

@merceyz
Copy link
Member

merceyz commented May 28, 2022

The enable command allows you to specify where it should install the binaries.

corepack enable --install-directory="/tmp/random-directory"

https://github.com/nodejs/corepack/tree/2b7180eff8635bc344fdde2c7d12ffa0eac14b49#corepack-enable--name

@styfle
Copy link
Member Author

styfle commented May 31, 2022

Thanks! The combination of --install-directory and COREPACK_HOME will work 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants