zkat / npx

execute npm package binaries (moved)
https://github.com/npm/npx
Other
2.63k stars 105 forks source link

feat: set NPX_CLI_JS environment variable for spawned commands. #178

Closed jdalton closed 6 years ago

jdalton commented 6 years ago

This PR forwards/sets the NPX_CLI_JS environment variable to match invocations through npm.

On Windows there is no mechanism to detect being invoked by npx. This PR would make the mechanism consistent across platforms and invocation techniques (via npm install or libnpx).

This allows commands invoked by npx to detect npx and customize functionality. For example create-esm can detect npx is running it and defer to npm init instead of yarn init.

zkat commented 6 years ago

I would rather not have something like this. I believe these tools should not be special-casing their invocation depending on npx and I think that'll just lead to a lot of unnecessary complexity. This has been requested before, and I've turned it down because of that. npx is meant to be a straightforward tool with as few knobs as possible -- otherwise it will start getting way too confusing.

That said, if you want this for npm init specifically, you can just add an env variable to the call. We can even make it so npx calculates all the npm env vars (from npm's config) that you get when you run in a run-script by using the -c option to npx instead of passing the create command directly. That might be a good addition to the new create command. People would then be able to just look for, say npm_command=init, or npm_init=true to detect whether they're being called through npm (in case they want to integrate with npm itself better, which I think is acceptable).

jdalton commented 6 years ago

Ah yeah, this can totally be handled with npm now. Thanks!