@nitra/check-env 3.2.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 CHANGED
@@ -4,14 +4,11 @@ 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
  [![NPM](https://img.shields.io/npm/v/@nitra/check-env?color=red)](https://www.npmjs.com/package/@nitra/check-env)
7
- [![MIT License](https://img.shields.io/github/license/47ng/check-env.svg?color=blue)](https://github.com/47ng/check-env/blob/next/LICENSE)
8
- [![Continuous Integration](https://github.com/47ng/check-env/workflows/Continuous%20Integration/badge.svg?branch=next)](https://github.com/47ng/check-env/actions)
9
- [![Coverage Status](https://coveralls.io/repos/github/47ng/check-env/badge.svg?branch=next)](https://coveralls.io/github/47ng/check-env?branch=next)
10
7
 
11
8
  ## Installation
12
9
 
13
10
  ```bash
14
- yarn add @nitra/check-env
11
+ bun add @nitra/check-env
15
12
  ```
16
13
 
17
14
  ## Usage
@@ -34,6 +31,17 @@ If some required environment variable are not set, it will tell you and throw
34
31
  an error at the end:
35
32
  !["CLI output"](output.png)
36
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
+
37
45
  ## License
38
46
 
39
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": "3.2.0",
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",
@@ -30,5 +30,8 @@
30
30
  "files": [
31
31
  "src",
32
32
  "types"
33
- ]
33
+ ],
34
+ "dependencies": {
35
+ "@nitra/pino": "^2.7.4"
36
+ }
34
37
  }
package/src/index.js CHANGED
@@ -1,16 +1,16 @@
1
- import process from 'node:process'
1
+ import { log } from '@nitra/pino'
2
+ import { env as pEnv } from 'node:process'
2
3
 
3
- const testEnv = name => !process.env[name]
4
+ const testEnv = name => !pEnv[name]
4
5
 
5
6
  const displayMissing = name => {
6
- console.error(`❌ Missing required environment variable ${name}`)
7
+ log.error(`❌ Missing required environment variable ${name}`)
7
8
  }
8
9
 
9
10
  /**
10
11
  * MissingEnvironmentVariableError
11
- *
12
12
  * @class
13
- * @extends Error
13
+ * @augments Error
14
14
  */
15
15
  export class MissingEnvironmentVariableError extends Error {
16
16
  constructor(envs) {
@@ -23,14 +23,19 @@ const checked = new Set()
23
23
 
24
24
  /**
25
25
  * Перевірка наявності змінних середовища
26
- *
27
26
  * @function
28
- * @param {Array.<String>} required
27
+ * @param {Array.<string>} required - список обов'язкових змінних середовища
29
28
  */
30
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
+
31
36
  const missingReq = []
32
37
 
33
- required.forEach(name => {
38
+ for (const name of required) {
34
39
  // додаємо в список перевірених
35
40
  checked.add(name)
36
41
 
@@ -38,7 +43,7 @@ export const checkEnv = required => {
38
43
  displayMissing(name)
39
44
  missingReq.push(name)
40
45
  }
41
- })
46
+ }
42
47
 
43
48
  if (missingReq.length > 0) {
44
49
  throw new MissingEnvironmentVariableError(missingReq)
@@ -47,15 +52,17 @@ export const checkEnv = required => {
47
52
 
48
53
  /**
49
54
  * Для сумісності з попередніми версіями
50
- *
51
- * @param {Array.<String>} required to capture
55
+ * @param {Array.<string>} required to capture
52
56
  */
53
57
  export default checkEnv
54
58
 
55
59
  const envProxyHandler = {
56
60
  /**
57
- * Set colour of object
58
- * @returns {String}
61
+ * Проксі-доступ до значень змінних середовища
62
+ * @param {object} target - об'єкт із змінними середовища
63
+ * @param {string} prop - назва змінної середовища
64
+ * @param {unknown} _ - не використовується
65
+ * @returns {string} - значення змінної середовища
59
66
  */
60
67
  get(target, prop, _) {
61
68
  // Якщо зі списку перевірених то повертаємо значення
@@ -69,6 +76,6 @@ const envProxyHandler = {
69
76
  }
70
77
 
71
78
  /**
72
- * @type {Object.<string, string>}
79
+ * @type {Record<string, string>}
73
80
  */
74
- export const env = new Proxy(process.env, envProxyHandler)
81
+ export const env = pEnv.SKIP_CHECK_ENV ? pEnv : new Proxy(pEnv, envProxyHandler) // Якщо змінна SKIP_CHECK_ENV встановлена, то пропускаємо перевірку
package/types/index.d.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  * MissingEnvironmentVariableError
3
3
  *
4
4
  * @class
5
- * @extends Error
5
+ * @augments Error
6
6
  */
7
7
  export class MissingEnvironmentVariableError extends Error {
8
8
  constructor(envs: any);