dotenv-defaults 1.0.1 → 1.1.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 +17 -4
- package/config.js +7 -0
- package/package.json +6 -5
- package/src/index.js +3 -1
- package/src/index.test.js +28 -3
package/README.md
CHANGED
|
@@ -5,9 +5,7 @@ A dotenv system that supports defaults
|
|
|
5
5
|
### Status
|
|
6
6
|
|
|
7
7
|

|
|
8
|
-

|
|
10
|
-
|
|
8
|
+
[](https://greenkeeper.io/)
|
|
11
9
|
|
|
12
10
|
### Installation
|
|
13
11
|
|
|
@@ -22,7 +20,7 @@ npm i dotenv-defaults --save
|
|
|
22
20
|
This module supports all the features from the original [dotenv](https://www.npmjs.com/package/dotenv) module, so usage should be simple enough:
|
|
23
21
|
|
|
24
22
|
```
|
|
25
|
-
# .env.
|
|
23
|
+
# .env.defaults, safe to commit
|
|
26
24
|
HOST=website.com
|
|
27
25
|
EMAIL=test@email.com
|
|
28
26
|
```
|
|
@@ -37,6 +35,9 @@ The result
|
|
|
37
35
|
```js
|
|
38
36
|
require('dotenv-defaults').config()
|
|
39
37
|
|
|
38
|
+
// Or you can also load it directly like this
|
|
39
|
+
require('dotenv-defaults/config')
|
|
40
|
+
|
|
40
41
|
console.log(process.env.HOST)
|
|
41
42
|
// Outputs: omnionline.us
|
|
42
43
|
|
|
@@ -44,6 +45,18 @@ console.log(process.env.EMAIL)
|
|
|
44
45
|
// Outputs: test@email.com
|
|
45
46
|
```
|
|
46
47
|
|
|
48
|
+
##### TypeScript
|
|
49
|
+
Since this module does not provide TypeScript Type Definitions if you try to import it like `import dotenv from "dotenv-defaults"` TypeScript will return an error.
|
|
50
|
+
|
|
51
|
+
Instead you should load it like this:
|
|
52
|
+
```typescript
|
|
53
|
+
import "dotenv-defaults/config"
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
##### CLI
|
|
57
|
+
You can also call this module directly when using the node executable.
|
|
58
|
+
So, for example if you are running a custom script with node and you want to load your environment variables you can do the following `node -r dotenv-defaults/config your-script.js`. (_When using this method, please make sure that you have installed dotenv-defaults with npm or yarn in the same directory_)
|
|
59
|
+
|
|
47
60
|
### Differences
|
|
48
61
|
|
|
49
62
|
The only thing to note is that the original module supported an `options` argument in the `config` function.
|
package/config.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// The purpose of this file is to be able to load the module with...
|
|
2
|
+
// ... "require("dotenv-defaults/config")" in JavaScript or "import "dotenv-defaults/config"" in TypeScript...
|
|
3
|
+
// ... or "node -r dotenv-defaults/config script.js" from the command line
|
|
4
|
+
|
|
5
|
+
(function () {
|
|
6
|
+
require('./src/index').config()
|
|
7
|
+
})()
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dotenv-defaults",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "dotenv... but with defaults!",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -26,15 +26,16 @@
|
|
|
26
26
|
"url": "https://github.com/mrsteele/dotenv-defaults/issues"
|
|
27
27
|
},
|
|
28
28
|
"files": [
|
|
29
|
-
"src"
|
|
29
|
+
"src",
|
|
30
|
+
"config.js"
|
|
30
31
|
],
|
|
31
32
|
"homepage": "https://github.com/mrsteele/dotenv-defaults#readme",
|
|
32
33
|
"dependencies": {
|
|
33
|
-
"dotenv": "^
|
|
34
|
+
"dotenv": "^6.2.0"
|
|
34
35
|
},
|
|
35
36
|
"devDependencies": {
|
|
36
|
-
"jest": "^
|
|
37
|
-
"standard": "^
|
|
37
|
+
"jest": "^25.0.0",
|
|
38
|
+
"standard": "^13.0.1"
|
|
38
39
|
},
|
|
39
40
|
"jest": {
|
|
40
41
|
"coverageDirectory": "./coverage/",
|
package/src/index.js
CHANGED
package/src/index.test.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* global describe, test, expect */
|
|
1
|
+
/* global describe, test, expect, afterEach */
|
|
2
2
|
|
|
3
3
|
const Module = require('./index')
|
|
4
4
|
|
|
@@ -10,8 +10,33 @@ describe('dotenv-defaults', () => {
|
|
|
10
10
|
})
|
|
11
11
|
|
|
12
12
|
describe('config', () => {
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
afterEach(() => {
|
|
14
|
+
delete process.env.TEST
|
|
15
|
+
delete process.env.TEST2
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
test('should be a function', () => {
|
|
19
|
+
expect(typeof Module.config).toEqual('function')
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
test('should by default write to process.env', () => {
|
|
23
|
+
expect(Module.config()).toEqual({
|
|
24
|
+
parsed: {
|
|
25
|
+
TEST: 'hello',
|
|
26
|
+
TEST2: 'whatever'
|
|
27
|
+
}
|
|
28
|
+
})
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
test('should support alternative defaults', () => {
|
|
32
|
+
expect(Module.config({
|
|
33
|
+
defaults: '.env.defaults2'
|
|
34
|
+
})).toEqual({
|
|
35
|
+
parsed: {
|
|
36
|
+
TEST: 'hello',
|
|
37
|
+
TEST2: 'whatever2'
|
|
38
|
+
}
|
|
39
|
+
})
|
|
15
40
|
})
|
|
16
41
|
})
|
|
17
42
|
|