Do you want to request a feature or report a bug?
Feature
What is the current behavior?
When a user is running a package via yarn create or npx, the package is unable to determine whether it was yarn that launched the package. This is useful for running additional yarn commands in the repo over npm-based ones.
If the current behavior is a bug, please provide the steps to reproduce.
yarn create @neutrinojs/project scaffolds the project using npm commands because it doesn't know the user is using yarn to run it.
What is the expected behavior?
Should have a way to sniff that this is yarn-based, probably through an environment variable.
Please mention your node.js, yarn and operating system version.
โฏ node --version
v9.2.0
โฏ yarn --version
1.3.2
โฏ uname -a
Darwin pro.local 17.2.0 Darwin Kernel Version 17.2.0: Fri Sep 29 18:27:05 PDT 2017; root:xnu-4570.20.62~3/RELEASE_X86_64 x86_64 # macOS High Sierra
The npm_execpath env var will give you the path to the package manager that is executing:
~/Projects/yarn-test ๐ yarn run env | grep npm_execpath
"npm_execpath": "/Users/jvalore/.yarn/bin/yarn.js",
~/Projects/yarn-test ๐ npm run env | grep npm_execpath
npm_execpath=/Users/jvalore/.nvm/versions/node/v8.5.0/lib/node_modules/npm/bin/npm-cli.js
which is useful if you need to run additional package manager commands. (node $npm_execpath install for example)
You could potentially also regex check the user agent string:
~/Projects/yarn-test ๐ yarn run env | grep npm_config_user_agent
"npm_config_user_agent": "yarn/1.3.2 npm/? node/v8.5.0 darwin x64",
~/Projects/yarn-test ๐ npm run env | grep npm_config_user_agent
npm_config_user_agent=npm/5.5.1 node/v8.5.0 darwin x64
This post is about the create command, not the run scripts. The create command spawns a new node process and from what I could tell doesn't pass anything identifiable in the spawned env.
Ah yes, you're right. Sorry about that. It looks like we don't build up all the env vars when we spawn a yarn create shell.
I'm guessing at least some, if not all, of the normal npm_* env vars should be set during yarn create just like yarn run and other lifecycle scripts.
@arcanis it looks like you wrote yarn create originally. Was it intentional that there are no npm_* env vars? Do you think it would be a problem if we added them?
Or perhaps instead we just add some other env var just to indicate that Yarn ran this?
@rally25rs @arcanis I have opened #7127 to at least get some environment parity.
Most helpful comment
The
npm_execpathenv var will give you the path to the package manager that is executing:which is useful if you need to run additional package manager commands. (
node $npm_execpath installfor example)You could potentially also regex check the user agent string: