@adonisjs/env 6.0.0 → 6.0.1
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 +22 -3
- package/package.json +36 -25
package/README.md
CHANGED
|
@@ -12,8 +12,6 @@ Install the package from the npm packages registry as follows.
|
|
|
12
12
|
|
|
13
13
|
```sh
|
|
14
14
|
npm i @adonisjs/env
|
|
15
|
-
|
|
16
|
-
yarn add @adonisjs/env
|
|
17
15
|
```
|
|
18
16
|
|
|
19
17
|
## EnvLoader
|
|
@@ -52,7 +50,7 @@ const envParser = new EnvParser(`
|
|
|
52
50
|
HOST=localhost
|
|
53
51
|
`)
|
|
54
52
|
|
|
55
|
-
console.log(envParser.parse()) // { PORT: '3000', HOST: 'localhost' }
|
|
53
|
+
console.log(await envParser.parse()) // { PORT: '3000', HOST: 'localhost' }
|
|
56
54
|
```
|
|
57
55
|
|
|
58
56
|
The return value of `parser.parse` is an object with key-value pair. The parser also has support for interpolation.
|
|
@@ -63,6 +61,27 @@ By default, the parser prefers existing `process.env` values when they exist. Ho
|
|
|
63
61
|
new EnvParser(envContents, { ignoreProcessEnv: true })
|
|
64
62
|
```
|
|
65
63
|
|
|
64
|
+
### Identifier
|
|
65
|
+
|
|
66
|
+
You can define an "identifier" to be used for interpolation. The identifier is a string that prefix the environment variable value and let you customize the value resolution.
|
|
67
|
+
|
|
68
|
+
```ts
|
|
69
|
+
import { readFile } from 'node:fs/promises'
|
|
70
|
+
import { EnvParser } from '@adonisjs/env'
|
|
71
|
+
|
|
72
|
+
EnvParser.identifier('file', (value) => {
|
|
73
|
+
return readFile(value, 'utf-8')
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
const envParser = new EnvParser(`
|
|
77
|
+
DB_PASSWORD=file:/run/secret/db_password
|
|
78
|
+
`)
|
|
79
|
+
|
|
80
|
+
console.log(await envParser.parse()) // { DB_PASSWORD: 'Value from file /run/secret/db_password' }
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
This can be useful when you are using secrets manager like `Docker Secret`, `HashiCorp Vault`, `Google Secrets Manager` and others to manage your secrets.
|
|
84
|
+
|
|
66
85
|
## Validating environment variables
|
|
67
86
|
Once you have the parsed objects, you can optionally validate them against a pre-defined schema. We recommend validation for the following reasons.
|
|
68
87
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adonisjs/env",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.0.1",
|
|
4
4
|
"description": "Environment variable manager for Node.js",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"precompile": "npm run lint && npm run clean",
|
|
26
26
|
"compile": "tsup-node && tsc --emitDeclarationOnly --declaration",
|
|
27
27
|
"build": "npm run compile",
|
|
28
|
-
"release": "
|
|
28
|
+
"release": "release-it",
|
|
29
29
|
"version": "npm run build",
|
|
30
30
|
"prepublishOnly": "npm run build",
|
|
31
31
|
"lint": "eslint . --ext=.ts",
|
|
@@ -40,33 +40,33 @@
|
|
|
40
40
|
"author": "virk,adonisjs",
|
|
41
41
|
"license": "MIT",
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@adonisjs/eslint-config": "^1.
|
|
44
|
-
"@adonisjs/prettier-config": "^1.
|
|
45
|
-
"@adonisjs/tsconfig": "^1.
|
|
46
|
-
"@commitlint/cli": "^
|
|
47
|
-
"@commitlint/config-conventional": "^
|
|
48
|
-
"@japa/assert": "^
|
|
49
|
-
"@japa/expect-type": "^2.0.
|
|
50
|
-
"@japa/file-system": "^2.
|
|
51
|
-
"@japa/runner": "^3.1.
|
|
52
|
-
"@swc/core": "^1.
|
|
53
|
-
"@types/node": "^20.
|
|
43
|
+
"@adonisjs/eslint-config": "^1.3.0",
|
|
44
|
+
"@adonisjs/prettier-config": "^1.3.0",
|
|
45
|
+
"@adonisjs/tsconfig": "^1.3.0",
|
|
46
|
+
"@commitlint/cli": "^19.2.2",
|
|
47
|
+
"@commitlint/config-conventional": "^19.2.2",
|
|
48
|
+
"@japa/assert": "^3.0.0",
|
|
49
|
+
"@japa/expect-type": "^2.0.2",
|
|
50
|
+
"@japa/file-system": "^2.3.0",
|
|
51
|
+
"@japa/runner": "^3.1.4",
|
|
52
|
+
"@swc/core": "^1.4.16",
|
|
53
|
+
"@types/node": "^20.12.7",
|
|
54
54
|
"c8": "^9.1.0",
|
|
55
55
|
"cross-env": "^7.0.3",
|
|
56
56
|
"del-cli": "^5.1.0",
|
|
57
57
|
"eslint": "^8.56.0",
|
|
58
58
|
"github-label-sync": "^2.3.1",
|
|
59
|
-
"husky": "^
|
|
60
|
-
"
|
|
61
|
-
"
|
|
59
|
+
"husky": "^9.0.11",
|
|
60
|
+
"prettier": "^3.2.5",
|
|
61
|
+
"release-it": "^17.2.0",
|
|
62
62
|
"ts-node": "^10.9.2",
|
|
63
|
-
"tsup": "^8.0.
|
|
64
|
-
"typescript": "^5.
|
|
63
|
+
"tsup": "^8.0.2",
|
|
64
|
+
"typescript": "^5.4.5"
|
|
65
65
|
},
|
|
66
66
|
"dependencies": {
|
|
67
|
-
"@poppinss/utils": "^6.7.
|
|
67
|
+
"@poppinss/utils": "^6.7.3",
|
|
68
68
|
"@poppinss/validator-lite": "^1.0.3",
|
|
69
|
-
"dotenv": "^16.
|
|
69
|
+
"dotenv": "^16.4.5",
|
|
70
70
|
"split-lines": "^3.0.0"
|
|
71
71
|
},
|
|
72
72
|
"repository": {
|
|
@@ -86,11 +86,22 @@
|
|
|
86
86
|
"access": "public",
|
|
87
87
|
"tag": "latest"
|
|
88
88
|
},
|
|
89
|
-
"
|
|
90
|
-
"
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
89
|
+
"release-it": {
|
|
90
|
+
"git": {
|
|
91
|
+
"commitMessage": "chore(release): ${version}",
|
|
92
|
+
"tagAnnotation": "v${version}",
|
|
93
|
+
"tagName": "v${version}"
|
|
94
|
+
},
|
|
95
|
+
"hooks": {
|
|
96
|
+
"before:init": [
|
|
97
|
+
"npm test"
|
|
98
|
+
]
|
|
99
|
+
},
|
|
100
|
+
"github": {
|
|
101
|
+
"release": true,
|
|
102
|
+
"releaseName": "v${version}",
|
|
103
|
+
"web": true
|
|
104
|
+
}
|
|
94
105
|
},
|
|
95
106
|
"c8": {
|
|
96
107
|
"reporter": [
|