env-has
v0.0.3
Published
Checks that all parameters specified on the command line are defined and not empty in the environment.
Downloads
10
Maintainers
Readme
ENV-HAS
Checks that variable names specified as parameters on the command line are defined in the ENVIRONMENT.
If any of parameters is undefined, null or empty string, process exits with code 1 (Error), otherwise returns with code 0 (Success).
Usage
You can use env-has
command in package.json
scripts to check presence of
certain environment variables. You can do a simple guard that allows you to run your script
succesfully only if you specify all environment variables before run.
You can easily block unwanted npm publish
with env-has
during your npm package development.
Example
If you want to use env-has
to block unwanted package publication, you only need to do those things:
- Put
env-has
intodevDependencies
inpackage.json
:
"devDependencies": {
"env-has": "^0.0.1"
}
- Add
env-has
check forALLOW_NPM_PUBLISH
environment variable intoprepublishOnly
script inpackage.json
(or any other lifecycle script that is called beforenpm publish
):
"scripts": {
"prepublishOnly": "env-has ALLOW_NPM_PUBLISH"
}
Now if you suddenly use npm publish
, it will fail in prepublishOnly
with this error:
$ npm publish
> [email protected] prepublishOnly .
> env-has ALLOW_NPM_PUBLISH
Environment variable "ALLOW_NPM_PUBLISH" is not defined.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] prepublishOnly: `env-has ALLOW_NPM_PUBLISH`
npm ERR! Exit status 1
If you are ok with your package and want to publish it, call npm publish
with arbitrary value
in ALLOW_NPM_PUBLISH
like this (here we use value yes
):
$ ALLOW_NPM_PUBLISH=yes npm publish
This is really usefull if you can't/don't want to use private: true
or publishConfig
in your package.json
.