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

pnpm create / pnpm init should expose an npm_config_user_agent environment variable #4257

Closed
sodatea opened this issue Jan 19, 2022 · 2 comments

Comments

@sodatea
Copy link
Sponsor Member

sodatea commented Jan 19, 2022

pnpm version:

6.27.0

Code to reproduce the issue:

I created a create-soda-test package to print all the environment variables: https://unpkg.com/create-soda-test@0.0.3/index.js
You can run pnpm create soda-test@0.0.3 to see the available environment variables that pnpm create exposes.
There's no npm_config_user_agent.

The environment variable is available in pnpm run though.

Expected behavior:

A npm_config_user_agent environment variable is exposed.

Actual behavior:

process.env.npm_config_user_agent is unavailable in pnpm create or pnpm init, making it impossible to tell where the user is invoking the package from.

Additional information:

  • node -v prints: v16.13.1
  • Windows, macOS, or Linux?: macOS

The use case:

In create-vite and create-vue, we need to show the user a few package-manager-related instructions after the project is scaffolded. Something like:

cd my-project
npm install
npm run dev

When the user invokes these packages via yarn create, pnpm create or pnpm init, we want to show commands that match their preferred package manager.
So we need a way to tell which package manager they are using.

We are told to use process.env.npm_config_user_agent as it's the safest check.
But it's only available in npm init or yarn create, not in the corresponding pnpm commands. Therefore, we are unable to print pnpm-specific commands, despite that we are trying to recommend users to choose pnpm.

@zkochan
Copy link
Member

zkochan commented Jan 19, 2022

There is an issue about it already: #3985

@sodatea
Copy link
Sponsor Member Author

sodatea commented Jan 19, 2022

Ah, sorry, I forgot to search before opening this issue.

@sodatea sodatea closed this as completed Jan 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants