Closed jdalton closed 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).
Ah yeah, this can totally be handled with npm
now. Thanks!
This PR forwards/sets the
NPX_CLI_JS
environment variable to match invocations throughnpm
.On Windows there is no mechanism to detect being invoked by
npx
. This PR would make the mechanism consistent across platforms and invocation techniques (vianpm
install orlibnpx
).This allows commands invoked by
npx
to detectnpx
and customize functionality. For examplecreate-esm
can detectnpx
is running it and defer tonpm init
instead ofyarn init
.