@nitra/check-env 2.0.6 → 3.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/package.json +11 -8
- package/src/index.js +31 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nitra/check-env",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Check that the critical environment variables are set",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -8,8 +8,7 @@
|
|
|
8
8
|
".": "./src/index.js"
|
|
9
9
|
},
|
|
10
10
|
"scripts": {
|
|
11
|
-
"
|
|
12
|
-
"fix": "npx standard --fix && npx prettier --write .",
|
|
11
|
+
"fix": "npx eslint --fix --ext .js . && npx prettier --write '**/*.js'",
|
|
13
12
|
"test": "NODE_OPTIONS=--experimental-vm-modules npx jest"
|
|
14
13
|
},
|
|
15
14
|
"repository": {
|
|
@@ -21,16 +20,20 @@
|
|
|
21
20
|
"email": "contact@francoisbest.com",
|
|
22
21
|
"url": "https://francoisbest.com"
|
|
23
22
|
},
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
"@nitra/prettier-config": "^1.0.0"
|
|
23
|
+
"eslintConfig": {
|
|
24
|
+
"extends": [
|
|
25
|
+
"@nitra"
|
|
26
|
+
]
|
|
29
27
|
},
|
|
30
28
|
"license": "MIT",
|
|
31
29
|
"bugs": {
|
|
32
30
|
"url": "https://github.com/nitra/checkenv/issues"
|
|
33
31
|
},
|
|
32
|
+
"keywords": [
|
|
33
|
+
"env",
|
|
34
|
+
"check-env",
|
|
35
|
+
"nitra"
|
|
36
|
+
],
|
|
34
37
|
"prettier": "@nitra/prettier-config",
|
|
35
38
|
"files": [
|
|
36
39
|
"src"
|
package/src/index.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import process from 'node:process'
|
|
2
|
+
|
|
1
3
|
const testEnv = name => !process.env[name]
|
|
2
4
|
|
|
3
5
|
const displayMissing = name => {
|
|
@@ -11,10 +13,14 @@ export class MissingEnvironmentVariableError extends Error {
|
|
|
11
13
|
}
|
|
12
14
|
}
|
|
13
15
|
|
|
14
|
-
|
|
16
|
+
const checked = new Set()
|
|
17
|
+
export const checkEnv = required => {
|
|
15
18
|
const missingReq = []
|
|
16
19
|
|
|
17
20
|
required.forEach(name => {
|
|
21
|
+
// додаємо в список перевірених
|
|
22
|
+
checked.add(name)
|
|
23
|
+
|
|
18
24
|
if (testEnv(name)) {
|
|
19
25
|
displayMissing(name)
|
|
20
26
|
missingReq.push(name)
|
|
@@ -25,3 +31,27 @@ export default required => {
|
|
|
25
31
|
throw new MissingEnvironmentVariableError(missingReq)
|
|
26
32
|
}
|
|
27
33
|
}
|
|
34
|
+
|
|
35
|
+
// Для сумісності з попередніми версіями
|
|
36
|
+
export default checkEnv
|
|
37
|
+
|
|
38
|
+
const envProxyHandler = {
|
|
39
|
+
/**
|
|
40
|
+
* Set colour of object
|
|
41
|
+
* @returns {String}
|
|
42
|
+
*/
|
|
43
|
+
get(target, prop, _) {
|
|
44
|
+
// Якщо зі списку перевірених то повертаємо значення
|
|
45
|
+
// інакше аварійно завершуємо програму
|
|
46
|
+
if (!checked.has(prop)) {
|
|
47
|
+
throw new Error(`❌ Environment variable ${prop} is not checked`)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return target[prop]
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* @type {Object.<string, string>}
|
|
56
|
+
*/
|
|
57
|
+
export const env = new Proxy(process.env, envProxyHandler)
|