@nitra/check-env 2.0.3

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/.cspell.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "version": "0.2",
3
+ "language": "en,uk,ru-ru,nitra",
4
+ "ignorePaths": [
5
+ "**/node_modules/**",
6
+ "**/vscode-extension/**",
7
+ "**/.git/**",
8
+ ".vscode",
9
+ "report",
10
+ "yarn.lock"
11
+ ],
12
+ "import": [
13
+ "@nitra/cspell-dict/cspell-ext.json",
14
+ "@cspell/dict-ru_ru/cspell-ext.json",
15
+ "@cspell/dict-uk-ua/cspell-ext.json"
16
+ ],
17
+ "words": ["vitaliytv"]
18
+ }
@@ -0,0 +1,10 @@
1
+ const prettierConfigStandard = require("prettier-config-standard");
2
+
3
+ const modifiedConfig = {
4
+ ...prettierConfigStandard,
5
+ ...{
6
+ arrowParens: "avoid",
7
+ },
8
+ };
9
+
10
+ module.exports = modifiedConfig;
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 François Best <contact@francoisbest.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # `check-env`
2
+
3
+ Check that the critical environment variables are set for your app,
4
+ and that you did not leave dangerous development overrides in production.
5
+
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
+ [![Dependabot Status](https://api.dependabot.com/badges/status?host=github&repo=47ng/check-env)](https://dependabot.com)
11
+
12
+ ## Installation
13
+
14
+ ```
15
+ yarn add @nitra/check-env
16
+ ```
17
+
18
+ ## Usage
19
+
20
+ ```js
21
+ import checkEnv from '@nitra/check-env'
22
+
23
+ checkEnv(
24
+ // Will log an error and throw if any of these are missing:
25
+ [
26
+ 'SOME_API_SECRET',
27
+ 'PRIVATE_TOKEN',
28
+ 'SOME_OTHER_IMPORTANT_THING'
29
+ // ...
30
+ ]
31
+ )
32
+ ```
33
+
34
+ If some required environment variable are not set, it will tell you and throw
35
+ an error at the end:
36
+ !["CLI output"](output.png)
37
+
38
+ ## License
39
+
40
+ [MIT](https://github.com/47ng/check-env/blob/master/LICENSE) - Made with ❤️ by [François Best](https://francoisbest.com)
41
+
42
+ Using this package at work ? [Sponsor me](https://github.com/sponsors/franky47) to help with support and maintenance.
package/output.png ADDED
Binary file
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "@nitra/check-env",
3
+ "version": "2.0.3",
4
+ "description": "Check that the critical environment variables are set",
5
+ "type": "module",
6
+ "exports": {
7
+ ".": "./src/index.js"
8
+ },
9
+ "scripts": {
10
+ "standard": "npx standard --fix",
11
+ "fix": "npx standard --fix && npx prettier --write .",
12
+ "test": "NODE_OPTIONS=--experimental-vm-modules npx jest"
13
+ },
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git+https://github.com/nitra/checkenv.git"
17
+ },
18
+ "author": {
19
+ "name": "François Best",
20
+ "email": "contact@francoisbest.com",
21
+ "url": "https://francoisbest.com"
22
+ },
23
+ "devDependencies": {
24
+ "@cspell/dict-ru_ru": "^2.0.2",
25
+ "@cspell/dict-uk-ua": "^1.0.20",
26
+ "@nitra/cspell-dict": "^1.0.8",
27
+ "prettier-config-standard": "^4.0.0"
28
+ },
29
+ "license": "MIT",
30
+ "bugs": {
31
+ "url": "https://github.com/nitra/checkenv/issues"
32
+ }
33
+ }
@@ -0,0 +1,71 @@
1
+ /* global it, expect, test */
2
+ import checkEnv from '../src/index.js'
3
+ import { jest } from '@jest/globals'
4
+
5
+ test('Empty options', () => {
6
+ console.error = jest.fn()
7
+ console.warn = jest.fn()
8
+ expect(() => checkEnv([])).not.toThrow()
9
+ expect(console.error).not.toHaveBeenCalled()
10
+ expect(console.warn).not.toHaveBeenCalled()
11
+ })
12
+
13
+ test('A single required env is missing', () => {
14
+ console.error = jest.fn()
15
+ console.warn = jest.fn()
16
+ expect(() => checkEnv(['foo'])).toThrowError()
17
+ expect(console.error).toHaveBeenCalledTimes(1)
18
+ expect(console.warn).not.toHaveBeenCalled()
19
+ })
20
+
21
+ test('All required envs are missing', () => {
22
+ const input = ['foo', 'bar']
23
+ console.error = jest.fn()
24
+ console.warn = jest.fn()
25
+ expect(() => checkEnv(input)).toThrowError()
26
+ expect(console.error).toHaveBeenCalledTimes(2)
27
+ expect(console.warn).not.toHaveBeenCalled()
28
+ })
29
+
30
+ test('Some required env are missing', () => {
31
+ const input = ['foo', 'NODE_ENV']
32
+ process.env['NODE_ENV'] = 'production'
33
+
34
+ console.error = jest.fn()
35
+ console.warn = jest.fn()
36
+ expect(() => checkEnv(input)).toThrowError()
37
+ expect(console.error).toHaveBeenCalledTimes(1)
38
+ expect(console.warn).not.toHaveBeenCalled()
39
+ })
40
+
41
+ test('A single required envs is available', () => {
42
+ const input = ['NODE_ENV']
43
+ process.env['NODE_ENV'] = 'production'
44
+
45
+ console.error = jest.fn()
46
+ console.warn = jest.fn()
47
+ checkEnv(input)
48
+ expect(console.error).not.toHaveBeenCalled()
49
+ expect(console.warn).not.toHaveBeenCalled()
50
+ })
51
+
52
+ test('Error message type', () => {
53
+ const input = ['foo']
54
+
55
+ expect(() => checkEnv(input)).toThrowError(
56
+ checkEnv.MissingEnvironmentVariableError
57
+ )
58
+ })
59
+
60
+ test('Error message contains name of missing variable', () => {
61
+ const input = ['foo']
62
+
63
+ try {
64
+ const run = () => checkEnv(input)
65
+ run()
66
+ expect(run).not.toHaveReturned() // Should throw
67
+ } catch (error) {
68
+ // Only missing required variables are shown in the message string
69
+ expect(error.message).toMatch('foo')
70
+ }
71
+ })