This repository has been archived by the owner on May 1, 2024. It is now read-only.
Replies: 2 comments 1 reply
-
I’d love to see an |
Beta Was this translation helpful? Give feedback.
0 replies
-
This will not work in windowsHere's a band-aid if you do not need to support windows ~/D/n/s/npx $ cat package.json
{
"name": "npx",
"version": "1.0.0",
"scripts": {
"example": "node -r dotenv/config $(npm prefix -g)/bin/npx foo bar"
},
"dependencies": {
"dotenv": "^16.0.3"
},
"bin": {
"foo": "./foo.js"
}
}
~/D/n/s/npx $ cat .env
HELLO=WORLD
~/D/n/s/npx $ cat foo.js
#!/usr/bin/env node
console.log(process.env.HELLO)
console.log(process.argv)
~/D/n/s/npx $ npm run example
> [email protected] example
> node -r dotenv/config $(npm prefix -g)/bin/npx foo bar
WORLD
[
'/Users/wraithgar/.nvm/versions/node/v18.12.0/bin/node',
'/Users/wraithgar/.npm/_npx/c95967b95d2bdfc5/node_modules/.bin/foo',
'bar'
]
Unfortunately the "bin" directory in windows is the global prefix, not a subdirectory. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Background
As of
npm@9
,npm bin
is removed.Problem
My team uses some npm scripts that are structured like the following:
The alternative to
npm bin
provided in the npm v9 release notes says "usenpx
ornpm exec
to execute binaries", though I don't believe they support this use case of injectingdotenv
.Alternatives
node_modules/.bin/some-cli
: 👎 (this is bad because the path is an npm implementation detail, right?)$(which some-cli)
: I don't think this is portable to Windowsdotenv-cli
looks promising (dotenv npx some-cli
?), though it's annoying to install another dependency for thisQuestion
Is there any recommendation for updating this script to be compatible with npm v9?
Beta Was this translation helpful? Give feedback.
All reactions