dotenv-webpack 1.7.0 → 1.8.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.
Files changed (3) hide show
  1. package/README.md +4 -2
  2. package/dist/index.js +15 -10
  3. package/package.json +7 -7
package/README.md CHANGED
@@ -25,7 +25,7 @@ A secure webpack plugin that supports dotenv and other environment variables and
25
25
 
26
26
  Include the package locally in your repository.
27
27
 
28
- `npm install dotenv-webpack --save`
28
+ `npm install dotenv-webpack --save-dev`
29
29
 
30
30
  ### Description
31
31
 
@@ -91,7 +91,8 @@ Add `.env` to your `.gitignore` file
91
91
  Use the following properties to configure your instance.
92
92
 
93
93
  * **path** (`'./.env'`) - The path to your environment variables.
94
- * **safe** (`false`) - If false ignore safe-mode, if true load `'./.env.example'`, if a string load that file as the sample.
94
+ * **safe** (`false`) - If true, load '.env.example' to verify the '.env' variables are all set. Can also be a string to a different file.
95
+ * **allowEmptyValues** (`false`) - Whether to allow empty strings in safe mode. If false, will throw an error if any env variables are empty (but only if safe mode is enabled).
95
96
  * **systemvars** (`false`) - Set to true if you would rather load all system variables as well (useful for CI purposes).
96
97
  * **silent** (`false`) - If true, all warnings will be suppressed.
97
98
  * **expand** (`false`) - Allows your variables to be "expanded" for reusability within your `.env` file.
@@ -106,6 +107,7 @@ module.exports = {
106
107
  new Dotenv({
107
108
  path: './some.other.env', // load this now instead of the ones in '.env'
108
109
  safe: true, // load '.env.example' to verify the '.env' variables are all set. Can also be a string to a different file.
110
+ allowEmptyValues: true, // allow empty variables (e.g. `FOO=`) (treat it as empty string, rather than missing)
109
111
  systemvars: true, // load all the predefined 'process.env' variables which will trump anything local per dotenv specs.
110
112
  silent: true, // hide any errors
111
113
  defaults: false // load '.env.defaults' as the default values if empty.
package/dist/index.js CHANGED
@@ -79,7 +79,9 @@ var Dotenv = function () {
79
79
  }, {
80
80
  key: 'gatherVariables',
81
81
  value: function gatherVariables() {
82
- var safe = this.config.safe;
82
+ var _config2 = this.config,
83
+ safe = _config2.safe,
84
+ allowEmptyValues = _config2.allowEmptyValues;
83
85
 
84
86
  var vars = this.initializeVars();
85
87
 
@@ -88,8 +90,11 @@ var Dotenv = function () {
88
90
  blueprint = _getEnvs.blueprint;
89
91
 
90
92
  Object.keys(blueprint).map(function (key) {
91
- var value = vars.hasOwnProperty(key) ? vars[key] : env[key];
92
- if (!value && safe) {
93
+ var value = Object.prototype.hasOwnProperty.call(vars, key) ? vars[key] : env[key];
94
+
95
+ var isMissing = typeof value === 'undefined' || value === null || !allowEmptyValues && value === '';
96
+
97
+ if (safe && isMissing) {
93
98
  throw new Error('Missing environment variable: ' + key);
94
99
  } else {
95
100
  vars[key] = value;
@@ -111,10 +116,10 @@ var Dotenv = function () {
111
116
  }, {
112
117
  key: 'getEnvs',
113
118
  value: function getEnvs() {
114
- var _config2 = this.config,
115
- path = _config2.path,
116
- silent = _config2.silent,
117
- safe = _config2.safe;
119
+ var _config3 = this.config,
120
+ path = _config3.path,
121
+ silent = _config3.silent,
122
+ safe = _config3.safe;
118
123
 
119
124
 
120
125
  var env = _dotenvDefaults2.default.parse(this.loadFile({
@@ -142,9 +147,9 @@ var Dotenv = function () {
142
147
  }, {
143
148
  key: 'getDefaults',
144
149
  value: function getDefaults() {
145
- var _config3 = this.config,
146
- silent = _config3.silent,
147
- defaults = _config3.defaults;
150
+ var _config4 = this.config,
151
+ silent = _config4.silent,
152
+ defaults = _config4.defaults;
148
153
 
149
154
 
150
155
  if (defaults) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dotenv-webpack",
3
3
  "description": "A simple webpack plugin to support dotenv.",
4
- "version": "1.7.0",
4
+ "version": "1.8.0",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
7
  "precommit": "npm run lint",
@@ -10,7 +10,7 @@
10
10
  "predoc": "rimraf docs",
11
11
  "doc": "esdoc -c config/doc.json",
12
12
  "pretest": "npm run build",
13
- "test": "nyc _mocha --compilers js:babel-register",
13
+ "test": "nyc _mocha --require babel-core/register",
14
14
  "posttest": "nyc report --reporter=lcov",
15
15
  "prebuild": "rimraf dist",
16
16
  "build": "babel --copy-files --out-dir dist src",
@@ -53,12 +53,12 @@
53
53
  "chai": "^4.1.2",
54
54
  "esdoc": "^1.0.4",
55
55
  "esdoc-standard-plugin": "^1.0.0",
56
- "husky": "^1.1.2",
57
- "mocha": "^5.0.1",
58
- "nyc": "^13.1.0",
59
- "rimraf": "^2.6.2",
56
+ "husky": "^3.0.0",
57
+ "mocha": "^6.0.0",
58
+ "nyc": "^14.0.0",
59
+ "rimraf": "^3.0.0",
60
60
  "sinon": "^7.0.0",
61
- "standard": "^12.0.0",
61
+ "standard": "^14.0.0",
62
62
  "webpack": "^4.6.0"
63
63
  },
64
64
  "files": [