@dotenvx/dotenvx 1.31.3 → 1.32.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/CHANGELOG.md +21 -1
- package/README.md +31 -31
- package/package.json +1 -1
- package/src/cli/actions/ext/prebuild.js +19 -51
- package/src/cli/actions/ext/precommit.js +3 -3
- package/src/cli/actions/ext/scan.js +1 -1
- package/src/cli/dotenvx.js +3 -3
- package/src/lib/main.d.ts +0 -8
- package/src/lib/services/prebuild.js +81 -0
- package/src/lib/services/precommit.js +16 -9
- package/src/shared/logger.js +0 -33
package/CHANGELOG.md
CHANGED
|
@@ -2,7 +2,27 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
-
[Unreleased](https://github.com/dotenvx/dotenvx/compare/v1.
|
|
5
|
+
[Unreleased](https://github.com/dotenvx/dotenvx/compare/v1.32.1...main)
|
|
6
|
+
|
|
7
|
+
## [1.32.1](https://github.com/dotenvx/dotenvx/compare/v1.32.0...v1.32.1)
|
|
8
|
+
|
|
9
|
+
### Changed
|
|
10
|
+
|
|
11
|
+
* remove duplicated help messages ([#504](https://github.com/dotenvx/dotenvx/pull/504))
|
|
12
|
+
|
|
13
|
+
## [1.32.0](https://github.com/dotenvx/dotenvx/compare/v1.31.3...v1.32.0)
|
|
14
|
+
|
|
15
|
+
### Added
|
|
16
|
+
|
|
17
|
+
* add encrypted check support for `ext prebuild` ([#501](https://github.com/dotenvx/dotenvx/pull/501))
|
|
18
|
+
|
|
19
|
+
### Changed
|
|
20
|
+
|
|
21
|
+
* modify `ext precommit` to check git modified state as well as git staged state - useful for using `dotenvx ext precommit` without the `--install` flag in automated scripts and ci. ([#499](https://github.com/dotenvx/dotenvx/pull/499))
|
|
22
|
+
|
|
23
|
+
### Removed
|
|
24
|
+
|
|
25
|
+
* remove internal logger methods `errorvp, errorvpb, warnv, warnvp, warnvpb, successvp, successvpb, help2` ([#501](https://github.com/dotenvx/dotenvx/pull/501))
|
|
6
26
|
|
|
7
27
|
## [1.31.3](https://github.com/dotenvx/dotenvx/compare/v1.31.2...v1.31.3)
|
|
8
28
|
|
package/README.md
CHANGED
|
@@ -80,7 +80,7 @@ tar -xzf dotenvx.tar.gz
|
|
|
80
80
|
</details>
|
|
81
81
|
|
|
82
82
|
|
|
83
|
-
<details><summary>or
|
|
83
|
+
<details><summary>or windows 🪟</summary><br>
|
|
84
84
|
|
|
85
85
|
```sh
|
|
86
86
|
winget install dotenvx
|
|
@@ -427,7 +427,7 @@ More examples
|
|
|
427
427
|
> start
|
|
428
428
|
> ./node_modules/.bin/dotenvx run -- node index.js
|
|
429
429
|
|
|
430
|
-
[dotenvx]
|
|
430
|
+
[dotenvx@1.X.X] injecting env (1) from .env.production
|
|
431
431
|
Hello World
|
|
432
432
|
```
|
|
433
433
|
|
|
@@ -504,7 +504,7 @@ $ echo "HELLO=production" > .env.production
|
|
|
504
504
|
$ echo "console.log('Hello ' + process.env.HELLO)" > index.js
|
|
505
505
|
|
|
506
506
|
$ dotenvx run -f .env.production -- node index.js
|
|
507
|
-
[dotenvx]
|
|
507
|
+
[dotenvx@1.X.X] injecting env (1) from .env.production
|
|
508
508
|
Hello production
|
|
509
509
|
> ^^
|
|
510
510
|
```
|
|
@@ -519,7 +519,7 @@ More examples
|
|
|
519
519
|
$ echo "HELLO=World" > .env
|
|
520
520
|
|
|
521
521
|
$ dotenvx run -f .env.local -f .env -- node index.js
|
|
522
|
-
[dotenvx]
|
|
522
|
+
[dotenvx@1.X.X] injecting env (1) from .env.local,.env
|
|
523
523
|
Hello local
|
|
524
524
|
```
|
|
525
525
|
|
|
@@ -533,7 +533,7 @@ More examples
|
|
|
533
533
|
$ echo "HELLO=World" > .env
|
|
534
534
|
|
|
535
535
|
$ dotenvx run -f .env.local -f .env --overload -- node index.js
|
|
536
|
-
[dotenvx]
|
|
536
|
+
[dotenvx@1.X.X] injecting env (1) from .env.local,.env
|
|
537
537
|
Hello World
|
|
538
538
|
```
|
|
539
539
|
|
|
@@ -545,7 +545,7 @@ More examples
|
|
|
545
545
|
$ dotenvx run -f .env.production --verbose -- node index.js
|
|
546
546
|
[dotenvx][verbose] injecting env from /path/to/.env.production
|
|
547
547
|
[dotenvx][verbose] HELLO set
|
|
548
|
-
[dotenvx]
|
|
548
|
+
[dotenvx@1.X.X] injecting env (1) from .env.production
|
|
549
549
|
Hello production
|
|
550
550
|
```
|
|
551
551
|
|
|
@@ -564,7 +564,7 @@ More examples
|
|
|
564
564
|
[dotenvx][debug] writing env from /path/to/.env.production
|
|
565
565
|
[dotenvx][verbose] HELLO set
|
|
566
566
|
[dotenvx][debug] HELLO set to production
|
|
567
|
-
[dotenvx]
|
|
567
|
+
[dotenvx@1.X.X] injecting env (1) from .env.production
|
|
568
568
|
Hello production
|
|
569
569
|
```
|
|
570
570
|
|
|
@@ -638,7 +638,7 @@ More examples
|
|
|
638
638
|
$ echo "console.log('Hello ' + process.env.HELLO)" > index.js
|
|
639
639
|
|
|
640
640
|
$ dotenvx run -- node index.js
|
|
641
|
-
[dotenvx] injecting env (2) from .env
|
|
641
|
+
[dotenvx@1.X.X] injecting env (2) from .env
|
|
642
642
|
Hello World
|
|
643
643
|
```
|
|
644
644
|
|
|
@@ -651,7 +651,7 @@ More examples
|
|
|
651
651
|
$ echo "console.log('Hello ' + process.env.HELLO)" > index.js
|
|
652
652
|
|
|
653
653
|
$ DOTENV_PRIVATE_KEY_PRODUCTION="<.env.production private key>" dotenvx run -- node index.js
|
|
654
|
-
[dotenvx] injecting env (2) from .env.production
|
|
654
|
+
[dotenvx@1.X.X] injecting env (2) from .env.production
|
|
655
655
|
Hello Production
|
|
656
656
|
```
|
|
657
657
|
|
|
@@ -666,7 +666,7 @@ More examples
|
|
|
666
666
|
$ echo "console.log('Hello ' + process.env.HELLO)" > index.js
|
|
667
667
|
|
|
668
668
|
$ DOTENV_PRIVATE_KEY_CI="<.env.ci private key>" dotenvx run -- node index.js
|
|
669
|
-
[dotenvx] injecting env (2) from .env.ci
|
|
669
|
+
[dotenvx@1.X.X] injecting env (2) from .env.ci
|
|
670
670
|
Hello Ci
|
|
671
671
|
```
|
|
672
672
|
|
|
@@ -681,7 +681,7 @@ More examples
|
|
|
681
681
|
$ echo "console.log('Hello ' + process.env.HELLO)" > index.js
|
|
682
682
|
|
|
683
683
|
$ DOTENV_PRIVATE_KEY="<.env private key>" DOTENV_PRIVATE_KEY_PRODUCTION="<.env.production private key>" dotenvx run -- node index.js
|
|
684
|
-
[dotenvx] injecting env (3) from .env, .env.production
|
|
684
|
+
[dotenvx@1.X.X] injecting env (3) from .env, .env.production
|
|
685
685
|
Hello World
|
|
686
686
|
```
|
|
687
687
|
|
|
@@ -698,11 +698,11 @@ More examples
|
|
|
698
698
|
$ echo "console.log('Hello ' + process.env.HELLO)" > index.js
|
|
699
699
|
|
|
700
700
|
$ DOTENV_PRIVATE_KEY_CI="<app1/privat ci key>,<app2/private ci key>" dotenvx run -f app1/.env.ci -f app2/.env.ci -- node index.js
|
|
701
|
-
[dotenvx] injecting env (2) from app1/.env.ci,app2/.env.ci
|
|
701
|
+
[dotenvx@1.X.X] injecting env (2) from app1/.env.ci,app2/.env.ci
|
|
702
702
|
Hello app1
|
|
703
703
|
|
|
704
704
|
$ DOTENV_PRIVATE_KEY_CI="<app1/privat ci key>,<app2/private ci key>" dotenvx run -f app1/.env.ci -f app2/.env.ci --overload -- node index.js
|
|
705
|
-
[dotenvx] injecting env (2) from app1/.env.ci,app2/.env.ci
|
|
705
|
+
[dotenvx@1.X.X] injecting env (2) from app1/.env.ci,app2/.env.ci
|
|
706
706
|
Hello app2
|
|
707
707
|
```
|
|
708
708
|
|
|
@@ -749,7 +749,7 @@ More examples
|
|
|
749
749
|
```
|
|
750
750
|
```sh
|
|
751
751
|
$ dotenvx run --debug -- node index.js
|
|
752
|
-
[dotenvx] injecting env (2) from .env
|
|
752
|
+
[dotenvx@1.X.X] injecting env (2) from .env
|
|
753
753
|
DATABASE_URL postgres://username@localhost/my_database
|
|
754
754
|
```
|
|
755
755
|
|
|
@@ -768,7 +768,7 @@ More examples
|
|
|
768
768
|
```
|
|
769
769
|
```sh
|
|
770
770
|
$ dotenvx run --debug -- node index.js
|
|
771
|
-
[dotenvx] injecting env (1) from .env
|
|
771
|
+
[dotenvx@1.X.X] injecting env (1) from .env
|
|
772
772
|
DATABASE_URL postgres://yourusername@localhost/my_database
|
|
773
773
|
```
|
|
774
774
|
|
|
@@ -793,7 +793,7 @@ More examples
|
|
|
793
793
|
$ echo "console.log('Hello ' + process.env.HELLO)" > index.js
|
|
794
794
|
|
|
795
795
|
$ dotenvx run -f .env.local -f .env -- node index.js
|
|
796
|
-
[dotenvx] injecting env (1) from .env.local, .env
|
|
796
|
+
[dotenvx@1.X.X] injecting env (1) from .env.local, .env
|
|
797
797
|
Hello local
|
|
798
798
|
```
|
|
799
799
|
|
|
@@ -807,7 +807,7 @@ More examples
|
|
|
807
807
|
$ echo "console.log('Hello ' + process.env.HELLO)" > index.js
|
|
808
808
|
|
|
809
809
|
$ dotenvx run --env HELLO=String -f .env -- node index.js
|
|
810
|
-
[dotenvx] injecting env (1) from .env, and --env flag
|
|
810
|
+
[dotenvx@1.X.X] injecting env (1) from .env, and --env flag
|
|
811
811
|
Hello String
|
|
812
812
|
```
|
|
813
813
|
|
|
@@ -822,7 +822,7 @@ More examples
|
|
|
822
822
|
$ echo "console.log('Hello ' + process.env.HELLO)" > index.js
|
|
823
823
|
|
|
824
824
|
$ dotenvx run -f .env.local -f .env --overload -- node index.js
|
|
825
|
-
[dotenvx] injecting env (1) from .env.local, .env
|
|
825
|
+
[dotenvx@1.X.X] injecting env (1) from .env.local, .env
|
|
826
826
|
Hello World
|
|
827
827
|
```
|
|
828
828
|
|
|
@@ -838,7 +838,7 @@ More examples
|
|
|
838
838
|
|
|
839
839
|
# check your .env.keys files for your privateKey
|
|
840
840
|
$ DOTENV_PRIVATE_KEY="122...0b8" dotenvx run -- node index.js
|
|
841
|
-
[dotenvx] injecting env (2) from .env
|
|
841
|
+
[dotenvx@1.X.X] injecting env (2) from .env
|
|
842
842
|
Hello encrypted
|
|
843
843
|
```
|
|
844
844
|
|
|
@@ -854,7 +854,7 @@ More examples
|
|
|
854
854
|
|
|
855
855
|
# check .env.keys for your privateKey
|
|
856
856
|
$ DOTENV_PRIVATE_KEY_PRODUCTION="122...0b8" dotenvx run -- node index.js
|
|
857
|
-
[dotenvx] injecting env (2) from .env.production
|
|
857
|
+
[dotenvx@1.X.X] injecting env (2) from .env.production
|
|
858
858
|
Hello production encrypted
|
|
859
859
|
```
|
|
860
860
|
|
|
@@ -872,7 +872,7 @@ More examples
|
|
|
872
872
|
|
|
873
873
|
# check .env.keys for your privateKey
|
|
874
874
|
$ DOTENV_PRIVATE_KEY_CI="122...0b8" dotenvx run -- node index.js
|
|
875
|
-
[dotenvx] injecting env (2) from .env.ci
|
|
875
|
+
[dotenvx@1.X.X] injecting env (2) from .env.ci
|
|
876
876
|
Hello ci encrypted
|
|
877
877
|
```
|
|
878
878
|
|
|
@@ -892,11 +892,11 @@ More examples
|
|
|
892
892
|
|
|
893
893
|
# check .env.keys for your privateKeys
|
|
894
894
|
$ DOTENV_PRIVATE_KEY="122...0b8" DOTENV_PRIVATE_KEY_PRODUCTION="122...0b8" dotenvx run -- node index.js
|
|
895
|
-
[dotenvx] injecting env (3) from .env, .env.production
|
|
895
|
+
[dotenvx@1.X.X] injecting env (3) from .env, .env.production
|
|
896
896
|
Hello encrypted
|
|
897
897
|
|
|
898
898
|
$ DOTENV_PRIVATE_KEY_PRODUCTION="122...0b8" DOTENV_PRIVATE_KEY="122...0b8" dotenvx run -- node index.js
|
|
899
|
-
[dotenvx] injecting env (3) from .env.production, .env
|
|
899
|
+
[dotenvx@1.X.X] injecting env (3) from .env.production, .env
|
|
900
900
|
Hello production encrypted
|
|
901
901
|
```
|
|
902
902
|
|
|
@@ -914,7 +914,7 @@ More examples
|
|
|
914
914
|
$ dotenvx run -f .env.production --verbose -- node index.js
|
|
915
915
|
loading env from .env.production (/path/to/.env.production)
|
|
916
916
|
HELLO set
|
|
917
|
-
[dotenvx] injecting env (1) from .env.production
|
|
917
|
+
[dotenvx@1.X.X] injecting env (1) from .env.production
|
|
918
918
|
Hello production
|
|
919
919
|
```
|
|
920
920
|
|
|
@@ -934,7 +934,7 @@ More examples
|
|
|
934
934
|
{"HELLO":"production"}
|
|
935
935
|
HELLO set
|
|
936
936
|
HELLO set to production
|
|
937
|
-
[dotenvx] injecting env (1) from .env.production
|
|
937
|
+
[dotenvx@1.X.X] injecting env (1) from .env.production
|
|
938
938
|
executing process command [node index.js]
|
|
939
939
|
expanding process command to [/opt/homebrew/bin/node index.js]
|
|
940
940
|
Hello production
|
|
@@ -1008,7 +1008,7 @@ More examples
|
|
|
1008
1008
|
$ echo "console.log('Hello ' + process.env.HELLO)" > index.js
|
|
1009
1009
|
|
|
1010
1010
|
$ dotenvx run --convention=nextjs -- node index.js
|
|
1011
|
-
[dotenvx] injecting env (1) from .env.development.local, .env.local, .env.development, .env
|
|
1011
|
+
[dotenvx@1.X.X] injecting env (1) from .env.development.local, .env.local, .env.development, .env
|
|
1012
1012
|
Hello development local
|
|
1013
1013
|
```
|
|
1014
1014
|
|
|
@@ -1736,7 +1736,7 @@ More examples
|
|
|
1736
1736
|
$ echo "console.log('Hello ' + process.env.HELLO)" > index.js
|
|
1737
1737
|
|
|
1738
1738
|
$ dotenvx run -- node index.js
|
|
1739
|
-
[dotenvx] injecting env (1) from .env
|
|
1739
|
+
[dotenvx@1.X.X] injecting env (1) from .env
|
|
1740
1740
|
Hello World
|
|
1741
1741
|
```
|
|
1742
1742
|
|
|
@@ -1905,7 +1905,7 @@ More examples
|
|
|
1905
1905
|
|
|
1906
1906
|
```sh
|
|
1907
1907
|
$ node index.js
|
|
1908
|
-
[dotenvx@1.
|
|
1908
|
+
[dotenvx@1.X.X] injecting env (1) from .env
|
|
1909
1909
|
Hello World
|
|
1910
1910
|
```
|
|
1911
1911
|
|
|
@@ -1935,7 +1935,7 @@ More examples
|
|
|
1935
1935
|
|
|
1936
1936
|
```sh
|
|
1937
1937
|
$ node index.js
|
|
1938
|
-
[dotenvx@1.
|
|
1938
|
+
[dotenvx@1.X.X] injecting env (1) from .env.local, .env
|
|
1939
1939
|
Hello Me
|
|
1940
1940
|
```
|
|
1941
1941
|
|
|
@@ -1963,7 +1963,7 @@ More examples
|
|
|
1963
1963
|
|
|
1964
1964
|
```sh
|
|
1965
1965
|
$ node index.js
|
|
1966
|
-
[dotenvx@1.
|
|
1966
|
+
[dotenvx@1.X.X] injecting env (1) from .env.local, .env
|
|
1967
1967
|
Hello World
|
|
1968
1968
|
```
|
|
1969
1969
|
|
|
@@ -2008,7 +2008,7 @@ More examples
|
|
|
2008
2008
|
|
|
2009
2009
|
```sh
|
|
2010
2010
|
$ node index.js
|
|
2011
|
-
[dotenvx@1.
|
|
2011
|
+
[dotenvx@1.X.X] injecting env (1) from .env
|
|
2012
2012
|
Hello World
|
|
2013
2013
|
```
|
|
2014
2014
|
|
package/package.json
CHANGED
|
@@ -1,64 +1,32 @@
|
|
|
1
|
-
const fsx = require('./../../../lib/helpers/fsx')
|
|
2
|
-
|
|
3
|
-
const ignore = require('ignore')
|
|
4
|
-
|
|
5
1
|
const { logger } = require('./../../../shared/logger')
|
|
6
|
-
|
|
2
|
+
|
|
3
|
+
const Prebuild = require('./../../../lib/services/prebuild')
|
|
7
4
|
|
|
8
5
|
function prebuild () {
|
|
9
6
|
const options = this.opts()
|
|
10
7
|
logger.debug(`options: ${JSON.stringify(options)}`)
|
|
11
8
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
return
|
|
18
|
-
}
|
|
9
|
+
try {
|
|
10
|
+
const {
|
|
11
|
+
successMessage,
|
|
12
|
+
warnings
|
|
13
|
+
} = new Prebuild(options).run()
|
|
19
14
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const dotenvFiles = files.filter(file => file.match(/^\.env(\..+)?$/))
|
|
25
|
-
dotenvFiles.forEach(file => {
|
|
26
|
-
// check if that file is being ignored
|
|
27
|
-
if (ig.ignores(file)) {
|
|
28
|
-
switch (file) {
|
|
29
|
-
case '.env.example':
|
|
30
|
-
warningCount += 1
|
|
31
|
-
logger.warnv(`${file} (currently ignored but should not be)`)
|
|
32
|
-
logger.help2(`? add !${file} to .dockerignore with [echo "!${file}" >> .dockerignore]`)
|
|
33
|
-
break
|
|
34
|
-
case '.env.vault':
|
|
35
|
-
warningCount += 1
|
|
36
|
-
logger.warnv(`${file} (currently ignored but should not be)`)
|
|
37
|
-
logger.help2(`? add !${file} to .dockerignore with [echo "!${file}" >> .dockerignore]`)
|
|
38
|
-
break
|
|
39
|
-
default:
|
|
40
|
-
break
|
|
41
|
-
}
|
|
42
|
-
} else {
|
|
43
|
-
switch (file) {
|
|
44
|
-
case '.env.example':
|
|
45
|
-
break
|
|
46
|
-
case '.env.vault':
|
|
47
|
-
break
|
|
48
|
-
default:
|
|
49
|
-
logger.errorvpb(`${file} not properly dockerignored`)
|
|
50
|
-
logger.help2(`? add ${file} to .dockerignore with [echo ".env*" >> .dockerignore]`)
|
|
51
|
-
process.exit(1) // 3.1 exit early with error code
|
|
52
|
-
break
|
|
15
|
+
for (const warning of warnings) {
|
|
16
|
+
logger.warn(warning.message)
|
|
17
|
+
if (warning.help) {
|
|
18
|
+
logger.help(warning.help)
|
|
53
19
|
}
|
|
54
20
|
}
|
|
55
|
-
})
|
|
56
21
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
logger.
|
|
60
|
-
|
|
61
|
-
|
|
22
|
+
logger.success(successMessage)
|
|
23
|
+
} catch (error) {
|
|
24
|
+
logger.error(error.message)
|
|
25
|
+
if (error.help) {
|
|
26
|
+
logger.help(error.help)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
process.exit(1)
|
|
62
30
|
}
|
|
63
31
|
}
|
|
64
32
|
|
|
@@ -13,15 +13,15 @@ function precommit () {
|
|
|
13
13
|
} = new Precommit(options).run()
|
|
14
14
|
|
|
15
15
|
for (const warning of warnings) {
|
|
16
|
-
logger.
|
|
16
|
+
logger.warn(warning.message)
|
|
17
17
|
if (warning.help) {
|
|
18
18
|
logger.help(warning.help)
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
logger.
|
|
22
|
+
logger.success(successMessage)
|
|
23
23
|
} catch (error) {
|
|
24
|
-
logger.
|
|
24
|
+
logger.error(error.message)
|
|
25
25
|
if (error.help) {
|
|
26
26
|
logger.help(error.help)
|
|
27
27
|
}
|
|
@@ -12,7 +12,7 @@ function scan () {
|
|
|
12
12
|
} catch (error) {
|
|
13
13
|
console.error('gitleaks: command not found')
|
|
14
14
|
logger.help('? install gitleaks: [brew install gitleaks]')
|
|
15
|
-
logger.
|
|
15
|
+
logger.help('? other install options: [https://github.com/gitleaks/gitleaks]')
|
|
16
16
|
process.exit(1)
|
|
17
17
|
return
|
|
18
18
|
}
|
package/src/cli/dotenvx.js
CHANGED
|
@@ -59,7 +59,7 @@ program.command('run')
|
|
|
59
59
|
.option('-fk, --env-keys-file <path>', 'path to your .env.keys file (default: same path as your env file)')
|
|
60
60
|
.option('-fv, --env-vault-file <paths...>', 'path(s) to your .env.vault file(s)', collectEnvs('envVaultFile'), [])
|
|
61
61
|
.option('-o, --overload', 'override existing env variables')
|
|
62
|
-
.option('--strict', 'process.exit(1) on any errors
|
|
62
|
+
.option('--strict', 'process.exit(1) on any errors', false)
|
|
63
63
|
.option('--convention <name>', 'load a .env convention (available conventions: [\'nextjs\'])')
|
|
64
64
|
.option('--ignore <errorCodes...>', 'error code(s) to ignore (example: --ignore=MISSING_ENV_FILE)')
|
|
65
65
|
.action(function (...args) {
|
|
@@ -78,7 +78,7 @@ program.command('get')
|
|
|
78
78
|
.option('-fk, --env-keys-file <path>', 'path to your .env.keys file (default: same path as your env file)')
|
|
79
79
|
.option('-fv, --env-vault-file <paths...>', 'path(s) to your .env.vault file(s)', collectEnvs('envVaultFile'), [])
|
|
80
80
|
.option('-o, --overload', 'override existing env variables')
|
|
81
|
-
.option('--strict', 'process.exit(1) on any errors
|
|
81
|
+
.option('--strict', 'process.exit(1) on any errors', false)
|
|
82
82
|
.option('--convention <name>', 'load a .env convention (available conventions: [\'nextjs\'])')
|
|
83
83
|
.option('--ignore <errorCodes...>', 'error code(s) to ignore (example: --ignore=MISSING_ENV_FILE)')
|
|
84
84
|
.option('-a, --all', 'include all machine envs as well')
|
|
@@ -100,7 +100,7 @@ program.command('set')
|
|
|
100
100
|
.argument('value', 'value')
|
|
101
101
|
.option('-f, --env-file <paths...>', 'path(s) to your env file(s)', collectEnvs('envFile'), [])
|
|
102
102
|
.option('-fk, --env-keys-file <path>', 'path to your .env.keys file (default: same path as your env file)')
|
|
103
|
-
.option('-c, --encrypt', 'encrypt value
|
|
103
|
+
.option('-c, --encrypt', 'encrypt value', true)
|
|
104
104
|
.option('-p, --plain', 'store value as plain text', false)
|
|
105
105
|
.action(function (...args) {
|
|
106
106
|
this.envs = envs
|
package/src/lib/main.d.ts
CHANGED
|
@@ -140,20 +140,12 @@ export interface DotenvConfigOptions {
|
|
|
140
140
|
logLevel?:
|
|
141
141
|
| 'error'
|
|
142
142
|
| 'errorv'
|
|
143
|
-
| 'errorvp'
|
|
144
|
-
| 'errorvpb'
|
|
145
143
|
| 'errornocolor'
|
|
146
144
|
| 'warn'
|
|
147
|
-
| 'warnv'
|
|
148
|
-
| 'warnvp'
|
|
149
|
-
| 'warnvpb'
|
|
150
145
|
| 'success'
|
|
151
146
|
| 'successv'
|
|
152
|
-
| 'successvp'
|
|
153
|
-
| 'successvpb'
|
|
154
147
|
| 'info'
|
|
155
148
|
| 'help'
|
|
156
|
-
| 'help2'
|
|
157
149
|
| 'http'
|
|
158
150
|
| 'verbose'
|
|
159
151
|
| 'debug'
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/* istanbul ignore file */
|
|
2
|
+
const fsx = require('./../helpers/fsx')
|
|
3
|
+
const ignore = require('ignore')
|
|
4
|
+
|
|
5
|
+
const Ls = require('../services/ls')
|
|
6
|
+
|
|
7
|
+
const isFullyEncrypted = require('./../helpers/isFullyEncrypted')
|
|
8
|
+
const packageJson = require('./../helpers/packageJson')
|
|
9
|
+
const MISSING_DOCKERIGNORE = '.env.keys' // by default only ignore .env.keys. all other .env* files COULD be included - as long as they are encrypted
|
|
10
|
+
|
|
11
|
+
class Prebuild {
|
|
12
|
+
constructor () {
|
|
13
|
+
this.excludeEnvFile = ['test/**', 'tests/**', 'spec/**', 'specs/**', 'pytest/**', 'test_suite/**']
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
run () {
|
|
17
|
+
let count = 0
|
|
18
|
+
const warnings = []
|
|
19
|
+
let dockerignore = MISSING_DOCKERIGNORE
|
|
20
|
+
|
|
21
|
+
// 1. check for .dockerignore file
|
|
22
|
+
if (!fsx.existsSync('.dockerignore')) {
|
|
23
|
+
const warning = new Error(`[dotenvx@${packageJson.version}][prebuild] .dockerignore missing`)
|
|
24
|
+
warnings.push(warning)
|
|
25
|
+
} else {
|
|
26
|
+
dockerignore = fsx.readFileX('.dockerignore')
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// 2. check .env* files against .dockerignore file
|
|
30
|
+
const ig = ignore().add(dockerignore)
|
|
31
|
+
const lsService = new Ls(process.cwd(), undefined, this.excludeEnvFile)
|
|
32
|
+
const dotenvFiles = lsService.run()
|
|
33
|
+
dotenvFiles.forEach(file => {
|
|
34
|
+
count += 1
|
|
35
|
+
|
|
36
|
+
// check if that file is being ignored
|
|
37
|
+
if (ig.ignores(file)) {
|
|
38
|
+
if (file === '.env.example' || file === '.env.vault') {
|
|
39
|
+
const warning = new Error(`[dotenvx@${packageJson.version}][prebuild] ${file} (currently ignored but should not be)`)
|
|
40
|
+
warning.help = `[dotenvx@${packageJson.version}][prebuild] ⮕ run [dotenvx ext gitignore --pattern !${file}]`
|
|
41
|
+
warnings.push(warning)
|
|
42
|
+
}
|
|
43
|
+
} else {
|
|
44
|
+
if (file !== '.env.example' && file !== '.env.vault') {
|
|
45
|
+
const src = fsx.readFileX(file)
|
|
46
|
+
const encrypted = isFullyEncrypted(src)
|
|
47
|
+
|
|
48
|
+
// if contents are encrypted don't raise an error
|
|
49
|
+
if (!encrypted) {
|
|
50
|
+
let errorMsg = `[dotenvx@${packageJson.version}][prebuild] ${file} not protected (encrypted or dockerignored)`
|
|
51
|
+
let errorHelp = `[dotenvx@${packageJson.version}][prebuild] ⮕ run [dotenvx encrypt -f ${file}] or [dotenvx ext gitignore --pattern ${file}]`
|
|
52
|
+
if (file.includes('.env.keys')) {
|
|
53
|
+
errorMsg = `[dotenvx@${packageJson.version}][prebuild] ${file} not protected (dockerignored)`
|
|
54
|
+
errorHelp = `[dotenvx@${packageJson.version}][prebuild] ⮕ run [dotenvx ext gitignore --pattern ${file}]`
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const error = new Error(errorMsg)
|
|
58
|
+
error.help = errorHelp
|
|
59
|
+
throw error
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
let successMessage = `[dotenvx@${packageJson.version}][prebuild] .env files (${count}) protected (encrypted or dockerignored)`
|
|
66
|
+
|
|
67
|
+
if (count === 0) {
|
|
68
|
+
successMessage = `[dotenvx@${packageJson.version}][prebuild] zero .env files`
|
|
69
|
+
}
|
|
70
|
+
if (warnings.length > 0) {
|
|
71
|
+
successMessage += ` with warnings (${warnings.length})`
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return {
|
|
75
|
+
successMessage,
|
|
76
|
+
warnings
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
module.exports = Prebuild
|
|
@@ -5,6 +5,7 @@ const ignore = require('ignore')
|
|
|
5
5
|
const Ls = require('../services/ls')
|
|
6
6
|
|
|
7
7
|
const isFullyEncrypted = require('./../helpers/isFullyEncrypted')
|
|
8
|
+
const packageJson = require('./../helpers/packageJson')
|
|
8
9
|
const InstallPrecommitHook = require('./../helpers/installPrecommitHook')
|
|
9
10
|
const childProcess = require('child_process')
|
|
10
11
|
const MISSING_GITIGNORE = '.env.keys' // by default only ignore .env.keys. all other .env* files COULD be included - as long as they are encrypted
|
|
@@ -32,8 +33,7 @@ class Precommit {
|
|
|
32
33
|
|
|
33
34
|
// 1. check for .gitignore file
|
|
34
35
|
if (!fsx.existsSync('.gitignore')) {
|
|
35
|
-
const warning = new Error(
|
|
36
|
-
warning.help = '? add it with [touch .gitignore]'
|
|
36
|
+
const warning = new Error(`[dotenvx@${packageJson.version}][precommit] .gitignore missing`)
|
|
37
37
|
warnings.push(warning)
|
|
38
38
|
} else {
|
|
39
39
|
gitignore = fsx.readFileX('.gitignore')
|
|
@@ -51,8 +51,8 @@ class Precommit {
|
|
|
51
51
|
// check if that file is being ignored
|
|
52
52
|
if (ig.ignores(file)) {
|
|
53
53
|
if (file === '.env.example' || file === '.env.vault') {
|
|
54
|
-
const warning = new Error(
|
|
55
|
-
warning.help =
|
|
54
|
+
const warning = new Error(`[dotenvx@${packageJson.version}][precommit] ${file} (currently ignored but should not be)`)
|
|
55
|
+
warning.help = `[dotenvx@${packageJson.version}][precommit] ⮕ run [dotenvx ext gitignore --pattern !${file}]`
|
|
56
56
|
warnings.push(warning)
|
|
57
57
|
}
|
|
58
58
|
} else {
|
|
@@ -62,8 +62,15 @@ class Precommit {
|
|
|
62
62
|
|
|
63
63
|
// if contents are encrypted don't raise an error
|
|
64
64
|
if (!encrypted) {
|
|
65
|
-
|
|
66
|
-
|
|
65
|
+
let errorMsg = `[dotenvx@${packageJson.version}][precommit] ${file} not protected (encrypted or gitignored)`
|
|
66
|
+
let errorHelp = `[dotenvx@${packageJson.version}][precommit] ⮕ run [dotenvx encrypt -f ${file}] or [dotenvx ext gitignore --pattern ${file}]`
|
|
67
|
+
if (file.includes('.env.keys')) {
|
|
68
|
+
errorMsg = `[dotenvx@${packageJson.version}][precommit] ${file} not protected (gitignored)`
|
|
69
|
+
errorHelp = `[dotenvx@${packageJson.version}][precommit] ⮕ run [dotenvx ext gitignore --pattern ${file}]`
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const error = new Error(errorMsg)
|
|
73
|
+
error.help = errorHelp
|
|
67
74
|
throw error
|
|
68
75
|
}
|
|
69
76
|
}
|
|
@@ -71,9 +78,9 @@ class Precommit {
|
|
|
71
78
|
}
|
|
72
79
|
})
|
|
73
80
|
|
|
74
|
-
let successMessage =
|
|
81
|
+
let successMessage = `[dotenvx@${packageJson.version}][precommit] .env files (${count}) protected (encrypted or gitignored)`
|
|
75
82
|
if (count === 0) {
|
|
76
|
-
successMessage =
|
|
83
|
+
successMessage = `[dotenvx@${packageJson.version}][precommit] zero .env files`
|
|
77
84
|
}
|
|
78
85
|
if (warnings.length > 0) {
|
|
79
86
|
successMessage += ` with warnings (${warnings.length})`
|
|
@@ -88,7 +95,7 @@ class Precommit {
|
|
|
88
95
|
|
|
89
96
|
_isFileToBeCommitted (filePath) {
|
|
90
97
|
try {
|
|
91
|
-
const output = childProcess.execSync('git diff
|
|
98
|
+
const output = childProcess.execSync('git diff HEAD --name-only').toString()
|
|
92
99
|
const files = output.split('\n')
|
|
93
100
|
|
|
94
101
|
return files.includes(filePath)
|
package/src/shared/logger.js
CHANGED
|
@@ -4,20 +4,12 @@ const { getColor, bold } = require('./colors')
|
|
|
4
4
|
const levels = {
|
|
5
5
|
error: 0,
|
|
6
6
|
errorv: 0,
|
|
7
|
-
errorvp: 0,
|
|
8
|
-
errorvpb: 0,
|
|
9
7
|
errornocolor: 0,
|
|
10
8
|
warn: 1,
|
|
11
|
-
warnv: 1,
|
|
12
|
-
warnvp: 1,
|
|
13
|
-
warnvpb: 1,
|
|
14
9
|
success: 2,
|
|
15
10
|
successv: 2,
|
|
16
|
-
successvp: 2,
|
|
17
|
-
successvpb: 2,
|
|
18
11
|
info: 2,
|
|
19
12
|
help: 2,
|
|
20
|
-
help2: 2,
|
|
21
13
|
blank: 2,
|
|
22
14
|
verbose: 4,
|
|
23
15
|
debug: 5,
|
|
@@ -29,7 +21,6 @@ const warn = getColor('orangered')
|
|
|
29
21
|
const success = getColor('green')
|
|
30
22
|
const successv = getColor('olive') // yellow-ish tint that 'looks' like dotenv
|
|
31
23
|
const help = getColor('dodgerblue')
|
|
32
|
-
const help2 = getColor('gray')
|
|
33
24
|
const verbose = getColor('plum')
|
|
34
25
|
const debug = getColor('plum')
|
|
35
26
|
|
|
@@ -55,38 +46,22 @@ function formatMessage (level, message) {
|
|
|
55
46
|
return error(formattedMessage)
|
|
56
47
|
case 'errorv':
|
|
57
48
|
return error(`[dotenvx@${packageJson.version}] ${formattedMessage}`)
|
|
58
|
-
case 'errorvp':
|
|
59
|
-
return error(`[dotenvx@${packageJson.version}][precommit] ${formattedMessage}`)
|
|
60
|
-
case 'errorvpb':
|
|
61
|
-
return error(`[dotenvx@${packageJson.version}][prebuild] ${formattedMessage}`)
|
|
62
49
|
case 'errornocolor':
|
|
63
50
|
return formattedMessage
|
|
64
51
|
// warns
|
|
65
52
|
case 'warn':
|
|
66
53
|
return warn(formattedMessage)
|
|
67
|
-
case 'warnv':
|
|
68
|
-
return warn(`[dotenvx@${packageJson.version}] ${formattedMessage}`)
|
|
69
|
-
case 'warnvp':
|
|
70
|
-
return warn(`[dotenvx@${packageJson.version}][precommit] ${formattedMessage}`)
|
|
71
|
-
case 'warnvpb':
|
|
72
|
-
return warn(`[dotenvx@${packageJson.version}][prebuild] ${formattedMessage}`)
|
|
73
54
|
// successes
|
|
74
55
|
case 'success':
|
|
75
56
|
return success(formattedMessage)
|
|
76
57
|
case 'successv': // success with 'version'
|
|
77
58
|
return successv(`[dotenvx@${packageJson.version}] ${formattedMessage}`)
|
|
78
|
-
case 'successvp': // success with 'version' and precommit
|
|
79
|
-
return success(`[dotenvx@${packageJson.version}][precommit] ${formattedMessage}`)
|
|
80
|
-
case 'successvpb': // success with 'version' and precommit
|
|
81
|
-
return success(`[dotenvx@${packageJson.version}][prebuild] ${formattedMessage}`)
|
|
82
59
|
// info
|
|
83
60
|
case 'info':
|
|
84
61
|
return formattedMessage
|
|
85
62
|
// help
|
|
86
63
|
case 'help':
|
|
87
64
|
return help(formattedMessage)
|
|
88
|
-
case 'help2':
|
|
89
|
-
return help2(formattedMessage)
|
|
90
65
|
// verbose
|
|
91
66
|
case 'verbose':
|
|
92
67
|
return verbose(formattedMessage)
|
|
@@ -106,24 +81,16 @@ const logger = {
|
|
|
106
81
|
// errors
|
|
107
82
|
error: (msg) => log('error', msg),
|
|
108
83
|
errorv: (msg) => log('errorv', msg),
|
|
109
|
-
errorvp: (msg) => log('errorvp', msg),
|
|
110
|
-
errorvpb: (msg) => log('errorvpb', msg),
|
|
111
84
|
errornocolor: (msg) => log('errornocolor', msg),
|
|
112
85
|
// warns
|
|
113
86
|
warn: (msg) => log('warn', msg),
|
|
114
|
-
warnv: (msg) => log('warnv', msg),
|
|
115
|
-
warnvp: (msg) => log('warnvp', msg),
|
|
116
|
-
warnvpb: (msg) => log('warnvpb', msg),
|
|
117
87
|
// success
|
|
118
88
|
success: (msg) => log('success', msg),
|
|
119
89
|
successv: (msg) => log('successv', msg),
|
|
120
|
-
successvp: (msg) => log('successvp', msg),
|
|
121
|
-
successvpb: (msg) => log('successvpb', msg),
|
|
122
90
|
// info
|
|
123
91
|
info: (msg) => log('info', msg),
|
|
124
92
|
// help
|
|
125
93
|
help: (msg) => log('help', msg),
|
|
126
|
-
help2: (msg) => log('help2', msg),
|
|
127
94
|
// verbose
|
|
128
95
|
verbose: (msg) => log('verbose', msg),
|
|
129
96
|
// debug
|