@nitra/check-env 4.0.0 → 4.1.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 +12 -1
- package/package.json +2 -2
- package/src/index.js +17 -11
- package/types/index.d.ts +1 -1
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@ and that you did not leave dangerous development overrides in production.
|
|
|
8
8
|
## Installation
|
|
9
9
|
|
|
10
10
|
```bash
|
|
11
|
-
|
|
11
|
+
bun add @nitra/check-env
|
|
12
12
|
```
|
|
13
13
|
|
|
14
14
|
## Usage
|
|
@@ -31,6 +31,17 @@ If some required environment variable are not set, it will tell you and throw
|
|
|
31
31
|
an error at the end:
|
|
32
32
|

|
|
33
33
|
|
|
34
|
+
## SKIP_CHECK_ENV
|
|
35
|
+
|
|
36
|
+
If the `SKIP_CHECK_ENV` environment variable is set, the library will skip required variable checks and will not throw. This can be useful for local development or specific CI scenarios.
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
SKIP_CHECK_ENV=1 bun node app.js
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
- With `SKIP_CHECK_ENV` enabled, you'll see a warning in logs: `SKIP_CHECK_ENV is set, skipping environment variable check`.
|
|
43
|
+
- The exported `env` will behave like plain `process.env` (no proxy checks for prior validation).
|
|
44
|
+
|
|
34
45
|
## License
|
|
35
46
|
|
|
36
47
|
[MIT](https://github.com/47ng/check-env/blob/master/LICENSE) - Made with ❤️ by [François Best](https://francoisbest.com)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nitra/check-env",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.1.0",
|
|
4
4
|
"description": "Check that the critical environment variables are set",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -32,6 +32,6 @@
|
|
|
32
32
|
"types"
|
|
33
33
|
],
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@nitra/pino": "^2.
|
|
35
|
+
"@nitra/pino": "^2.7.4"
|
|
36
36
|
}
|
|
37
37
|
}
|
package/src/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { log } from '@nitra/pino'
|
|
2
|
+
import { env as pEnv } from 'node:process'
|
|
3
3
|
|
|
4
|
-
const testEnv = name => !
|
|
4
|
+
const testEnv = name => !pEnv[name]
|
|
5
5
|
|
|
6
6
|
const displayMissing = name => {
|
|
7
7
|
log.error(`❌ Missing required environment variable ${name}`)
|
|
@@ -24,9 +24,15 @@ const checked = new Set()
|
|
|
24
24
|
/**
|
|
25
25
|
* Перевірка наявності змінних середовища
|
|
26
26
|
* @function
|
|
27
|
-
* @param {Array.<string>} required
|
|
27
|
+
* @param {Array.<string>} required - список обов'язкових змінних середовища
|
|
28
28
|
*/
|
|
29
29
|
export const checkEnv = required => {
|
|
30
|
+
// Якщо змінна SKIP_CHECK_ENV встановлена, то пропускаємо перевірку
|
|
31
|
+
if (pEnv.SKIP_CHECK_ENV) {
|
|
32
|
+
log.warn('SKIP_CHECK_ENV is set, skipping environment variable check')
|
|
33
|
+
return
|
|
34
|
+
}
|
|
35
|
+
|
|
30
36
|
const missingReq = []
|
|
31
37
|
|
|
32
38
|
for (const name of required) {
|
|
@@ -52,11 +58,11 @@ export default checkEnv
|
|
|
52
58
|
|
|
53
59
|
const envProxyHandler = {
|
|
54
60
|
/**
|
|
55
|
-
*
|
|
56
|
-
* @param target
|
|
57
|
-
* @param prop
|
|
58
|
-
* @param _
|
|
59
|
-
* @returns {string}
|
|
61
|
+
* Проксі-доступ до значень змінних середовища
|
|
62
|
+
* @param {object} target - об'єкт із змінними середовища
|
|
63
|
+
* @param {string} prop - назва змінної середовища
|
|
64
|
+
* @param {unknown} _ - не використовується
|
|
65
|
+
* @returns {string} - значення змінної середовища
|
|
60
66
|
*/
|
|
61
67
|
get(target, prop, _) {
|
|
62
68
|
// Якщо зі списку перевірених то повертаємо значення
|
|
@@ -70,6 +76,6 @@ const envProxyHandler = {
|
|
|
70
76
|
}
|
|
71
77
|
|
|
72
78
|
/**
|
|
73
|
-
* @type {
|
|
79
|
+
* @type {Record<string, string>}
|
|
74
80
|
*/
|
|
75
|
-
export const env = new Proxy(
|
|
81
|
+
export const env = pEnv.SKIP_CHECK_ENV ? pEnv : new Proxy(pEnv, envProxyHandler) // Якщо змінна SKIP_CHECK_ENV встановлена, то пропускаємо перевірку
|