@nitra/check-env 3.1.0 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -3
- package/package.json +5 -11
- package/src/index.js +11 -10
package/README.md
CHANGED
|
@@ -4,9 +4,6 @@ Check that the critical environment variables are set for your app,
|
|
|
4
4
|
and that you did not leave dangerous development overrides in production.
|
|
5
5
|
|
|
6
6
|
[](https://www.npmjs.com/package/@nitra/check-env)
|
|
7
|
-
[](https://github.com/47ng/check-env/blob/next/LICENSE)
|
|
8
|
-
[](https://github.com/47ng/check-env/actions)
|
|
9
|
-
[](https://coveralls.io/github/47ng/check-env?branch=next)
|
|
10
7
|
|
|
11
8
|
## Installation
|
|
12
9
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nitra/check-env",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "Check that the critical environment variables are set",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -8,10 +8,6 @@
|
|
|
8
8
|
"exports": {
|
|
9
9
|
".": "./src/index.js"
|
|
10
10
|
},
|
|
11
|
-
"scripts": {
|
|
12
|
-
"fix": "npx eslint --fix --ext .js . && npx prettier --write '**/*.js'",
|
|
13
|
-
"test": "NODE_OPTIONS=--experimental-vm-modules npx jest"
|
|
14
|
-
},
|
|
15
11
|
"repository": {
|
|
16
12
|
"type": "git",
|
|
17
13
|
"url": "git+https://github.com/nitra/checkenv.git"
|
|
@@ -21,11 +17,6 @@
|
|
|
21
17
|
"email": "contact@francoisbest.com",
|
|
22
18
|
"url": "https://francoisbest.com"
|
|
23
19
|
},
|
|
24
|
-
"eslintConfig": {
|
|
25
|
-
"extends": [
|
|
26
|
-
"@nitra"
|
|
27
|
-
]
|
|
28
|
-
},
|
|
29
20
|
"license": "MIT",
|
|
30
21
|
"bugs": {
|
|
31
22
|
"url": "https://github.com/nitra/checkenv/issues"
|
|
@@ -39,5 +30,8 @@
|
|
|
39
30
|
"files": [
|
|
40
31
|
"src",
|
|
41
32
|
"types"
|
|
42
|
-
]
|
|
33
|
+
],
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@nitra/pino": "^2.3.0"
|
|
36
|
+
}
|
|
43
37
|
}
|
package/src/index.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import process from 'node:process'
|
|
2
|
+
import log from '@nitra/pino'
|
|
2
3
|
|
|
3
4
|
const testEnv = name => !process.env[name]
|
|
4
5
|
|
|
5
6
|
const displayMissing = name => {
|
|
6
|
-
|
|
7
|
+
log.error(`❌ Missing required environment variable ${name}`)
|
|
7
8
|
}
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* MissingEnvironmentVariableError
|
|
11
|
-
*
|
|
12
12
|
* @class
|
|
13
|
-
* @
|
|
13
|
+
* @augments Error
|
|
14
14
|
*/
|
|
15
15
|
export class MissingEnvironmentVariableError extends Error {
|
|
16
16
|
constructor(envs) {
|
|
@@ -23,14 +23,13 @@ const checked = new Set()
|
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
25
|
* Перевірка наявності змінних середовища
|
|
26
|
-
*
|
|
27
26
|
* @function
|
|
28
|
-
* @param {Array.<
|
|
27
|
+
* @param {Array.<string>} required
|
|
29
28
|
*/
|
|
30
29
|
export const checkEnv = required => {
|
|
31
30
|
const missingReq = []
|
|
32
31
|
|
|
33
|
-
|
|
32
|
+
for (const name of required) {
|
|
34
33
|
// додаємо в список перевірених
|
|
35
34
|
checked.add(name)
|
|
36
35
|
|
|
@@ -38,7 +37,7 @@ export const checkEnv = required => {
|
|
|
38
37
|
displayMissing(name)
|
|
39
38
|
missingReq.push(name)
|
|
40
39
|
}
|
|
41
|
-
}
|
|
40
|
+
}
|
|
42
41
|
|
|
43
42
|
if (missingReq.length > 0) {
|
|
44
43
|
throw new MissingEnvironmentVariableError(missingReq)
|
|
@@ -47,15 +46,17 @@ export const checkEnv = required => {
|
|
|
47
46
|
|
|
48
47
|
/**
|
|
49
48
|
* Для сумісності з попередніми версіями
|
|
50
|
-
*
|
|
51
|
-
* @param {Array.<String>} required to capture
|
|
49
|
+
* @param {Array.<string>} required to capture
|
|
52
50
|
*/
|
|
53
51
|
export default checkEnv
|
|
54
52
|
|
|
55
53
|
const envProxyHandler = {
|
|
56
54
|
/**
|
|
57
55
|
* Set colour of object
|
|
58
|
-
* @
|
|
56
|
+
* @param target
|
|
57
|
+
* @param prop
|
|
58
|
+
* @param _
|
|
59
|
+
* @returns {string}
|
|
59
60
|
*/
|
|
60
61
|
get(target, prop, _) {
|
|
61
62
|
// Якщо зі списку перевірених то повертаємо значення
|