dotenv-webpack 1.8.0 → 2.0.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 (2) hide show
  1. package/dist/index.js +53 -64
  2. package/package.json +12 -19
package/dist/index.js CHANGED
@@ -1,42 +1,37 @@
1
- 'use strict';
1
+ "use strict";
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports["default"] = void 0;
6
7
 
7
- var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
8
+ var _dotenvDefaults = _interopRequireDefault(require("dotenv-defaults"));
8
9
 
9
- var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
10
+ var _fs = _interopRequireDefault(require("fs"));
10
11
 
11
- var _dotenvDefaults = require('dotenv-defaults');
12
+ var _webpack = require("webpack");
12
13
 
13
- var _dotenvDefaults2 = _interopRequireDefault(_dotenvDefaults);
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
14
15
 
15
- var _fs = require('fs');
16
-
17
- var _fs2 = _interopRequireDefault(_fs);
18
-
19
- var _webpack = require('webpack');
16
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
20
17
 
21
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
18
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
22
19
 
23
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
20
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
24
21
 
25
22
  // Mostly taken from here: https://github.com/motdotla/dotenv-expand/blob/master/lib/main.js#L4
26
23
  var interpolate = function interpolate(env, vars) {
27
24
  var matches = env.match(/\$([a-zA-Z0-9_]+)|\${([a-zA-Z0-9_]+)}/g) || [];
28
-
29
25
  matches.forEach(function (match) {
30
26
  var key = match.replace(/\$|{|}/g, '');
31
27
  var variable = vars[key] || '';
32
28
  variable = interpolate(variable, vars);
33
29
  env = env.replace(match, variable);
34
30
  });
35
-
36
31
  return env;
37
32
  };
38
33
 
39
- var Dotenv = function () {
34
+ var Dotenv = /*#__PURE__*/function () {
40
35
  /**
41
36
  * The dotenv-webpack plugin.
42
37
  * @param {Object} options - The parameters.
@@ -51,89 +46,86 @@ var Dotenv = function () {
51
46
 
52
47
  _classCallCheck(this, Dotenv);
53
48
 
54
- this.config = _extends({}, {
49
+ this.config = Object.assign({}, {
55
50
  path: './.env'
56
51
  }, config);
57
-
58
52
  this.checkDeprecation();
59
-
60
53
  return new _webpack.DefinePlugin(this.formatData(this.gatherVariables()));
61
54
  }
62
55
 
63
56
  _createClass(Dotenv, [{
64
- key: 'checkDeprecation',
57
+ key: "checkDeprecation",
65
58
  value: function checkDeprecation() {
66
- var _config = this.config,
67
- sample = _config.sample,
68
- safe = _config.safe,
69
- silent = _config.silent;
70
- // Catch older packages, but hold their hand (just for a bit)
59
+ var _this$config = this.config,
60
+ sample = _this$config.sample,
61
+ safe = _this$config.safe,
62
+ silent = _this$config.silent; // Catch older packages, but hold their hand (just for a bit)
71
63
 
72
64
  if (sample) {
73
65
  if (safe) {
74
66
  this.config.safe = sample;
75
67
  }
68
+
76
69
  this.warn('dotenv-webpack: "options.sample" is a deprecated property. Please update your configuration to use "options.safe" instead.', silent);
77
70
  }
78
71
  }
79
72
  }, {
80
- key: 'gatherVariables',
73
+ key: "gatherVariables",
81
74
  value: function gatherVariables() {
82
- var _config2 = this.config,
83
- safe = _config2.safe,
84
- allowEmptyValues = _config2.allowEmptyValues;
85
-
75
+ var _this$config2 = this.config,
76
+ safe = _this$config2.safe,
77
+ allowEmptyValues = _this$config2.allowEmptyValues;
86
78
  var vars = this.initializeVars();
87
79
 
88
- var _getEnvs = this.getEnvs(),
89
- env = _getEnvs.env,
90
- blueprint = _getEnvs.blueprint;
80
+ var _this$getEnvs = this.getEnvs(),
81
+ env = _this$getEnvs.env,
82
+ blueprint = _this$getEnvs.blueprint;
91
83
 
92
84
  Object.keys(blueprint).map(function (key) {
93
85
  var value = Object.prototype.hasOwnProperty.call(vars, key) ? vars[key] : env[key];
94
-
95
86
  var isMissing = typeof value === 'undefined' || value === null || !allowEmptyValues && value === '';
96
87
 
97
88
  if (safe && isMissing) {
98
- throw new Error('Missing environment variable: ' + key);
89
+ throw new Error("Missing environment variable: ".concat(key));
99
90
  } else {
100
91
  vars[key] = value;
101
92
  }
102
- });
93
+ }); // add the leftovers
103
94
 
104
- // add the leftovers
105
95
  if (safe) {
106
- _extends(vars, env);
96
+ Object.assign(vars, env);
107
97
  }
108
98
 
109
99
  return vars;
110
100
  }
111
101
  }, {
112
- key: 'initializeVars',
102
+ key: "initializeVars",
113
103
  value: function initializeVars() {
114
- return this.config.systemvars ? _extends({}, process.env) : {};
104
+ return this.config.systemvars ? Object.assign({}, process.env) : {};
115
105
  }
116
106
  }, {
117
- key: 'getEnvs',
107
+ key: "getEnvs",
118
108
  value: function getEnvs() {
119
- var _config3 = this.config,
120
- path = _config3.path,
121
- silent = _config3.silent,
122
- safe = _config3.safe;
109
+ var _this$config3 = this.config,
110
+ path = _this$config3.path,
111
+ silent = _this$config3.silent,
112
+ safe = _this$config3.safe;
123
113
 
124
-
125
- var env = _dotenvDefaults2.default.parse(this.loadFile({
114
+ var env = _dotenvDefaults["default"].parse(this.loadFile({
126
115
  file: path,
127
116
  silent: silent
128
117
  }), this.getDefaults());
129
118
 
130
119
  var blueprint = env;
120
+
131
121
  if (safe) {
132
122
  var file = './.env.example';
123
+
133
124
  if (safe !== true) {
134
125
  file = safe;
135
126
  }
136
- blueprint = _dotenvDefaults2.default.parse(this.loadFile({
127
+
128
+ blueprint = _dotenvDefaults["default"].parse(this.loadFile({
137
129
  file: file,
138
130
  silent: silent
139
131
  }));
@@ -145,12 +137,11 @@ var Dotenv = function () {
145
137
  };
146
138
  }
147
139
  }, {
148
- key: 'getDefaults',
140
+ key: "getDefaults",
149
141
  value: function getDefaults() {
150
- var _config4 = this.config,
151
- silent = _config4.silent,
152
- defaults = _config4.defaults;
153
-
142
+ var _this$config4 = this.config,
143
+ silent = _this$config4.silent,
144
+ defaults = _this$config4.defaults;
154
145
 
155
146
  if (defaults) {
156
147
  return this.loadFile({
@@ -162,15 +153,15 @@ var Dotenv = function () {
162
153
  return '';
163
154
  }
164
155
  }, {
165
- key: 'formatData',
156
+ key: "formatData",
166
157
  value: function formatData() {
167
158
  var vars = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
168
159
  var expand = this.config.expand;
169
-
170
160
  return Object.keys(vars).reduce(function (obj, key) {
171
161
  var v = vars[key];
172
- var vKey = 'process.env.' + key;
173
- var vValue = void 0;
162
+ var vKey = "process.env.".concat(key);
163
+ var vValue;
164
+
174
165
  if (expand) {
175
166
  if (v.substring(0, 2) === '\\$') {
176
167
  vValue = v.substring(1);
@@ -184,11 +175,9 @@ var Dotenv = function () {
184
175
  }
185
176
 
186
177
  obj[vKey] = JSON.stringify(vValue);
187
-
188
178
  return obj;
189
179
  }, {});
190
180
  }
191
-
192
181
  /**
193
182
  * Load a file.
194
183
  * @param {String} config.file - The file to load.
@@ -197,19 +186,18 @@ var Dotenv = function () {
197
186
  */
198
187
 
199
188
  }, {
200
- key: 'loadFile',
189
+ key: "loadFile",
201
190
  value: function loadFile(_ref) {
202
191
  var file = _ref.file,
203
192
  silent = _ref.silent;
204
193
 
205
194
  try {
206
- return _fs2.default.readFileSync(file, 'utf8');
195
+ return _fs["default"].readFileSync(file, 'utf8');
207
196
  } catch (err) {
208
- this.warn('Failed to load ' + file + '.', silent);
197
+ this.warn("Failed to load ".concat(file, "."), silent);
209
198
  return {};
210
199
  }
211
200
  }
212
-
213
201
  /**
214
202
  * Displays a console message if 'silent' is falsey
215
203
  * @param {String} msg - The message.
@@ -217,7 +205,7 @@ var Dotenv = function () {
217
205
  */
218
206
 
219
207
  }, {
220
- key: 'warn',
208
+ key: "warn",
221
209
  value: function warn(msg, silent) {
222
210
  !silent && console.warn(msg);
223
211
  }
@@ -226,4 +214,5 @@ var Dotenv = function () {
226
214
  return Dotenv;
227
215
  }();
228
216
 
229
- exports.default = Dotenv;
217
+ var _default = Dotenv;
218
+ exports["default"] = _default;
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.8.0",
4
+ "version": "2.0.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 --require babel-core/register",
13
+ "test": "nyc mocha --require @babel/register",
14
14
  "posttest": "nyc report --reporter=lcov",
15
15
  "prebuild": "rimraf dist",
16
16
  "build": "babel --copy-files --out-dir dist src",
@@ -42,38 +42,31 @@
42
42
  "webpack": "^1 || ^2 || ^3 || ^4"
43
43
  },
44
44
  "dependencies": {
45
- "dotenv-defaults": "^1.0.2"
45
+ "dotenv-defaults": "^2.0.0"
46
46
  },
47
47
  "devDependencies": {
48
- "babel-cli": "^6.26.0",
49
- "babel-eslint": "^10.0.1",
50
- "babel-plugin-transform-object-assign": "^6.22.0",
51
- "babel-preset-env": "^1.6.1",
52
- "babel-register": "^6.26.0",
48
+ "@babel/cli": "^7.10.4",
49
+ "@babel/core": "^7.10.4",
50
+ "@babel/preset-env": "^7.10.4",
51
+ "@babel/register": "^7.10.4",
53
52
  "chai": "^4.1.2",
54
53
  "esdoc": "^1.0.4",
55
54
  "esdoc-standard-plugin": "^1.0.0",
56
- "husky": "^3.0.0",
57
- "mocha": "^6.0.0",
58
- "nyc": "^14.0.0",
55
+ "husky": "^4.2.5",
56
+ "mocha": "^6.2.3",
57
+ "nyc": "^15.1.0",
59
58
  "rimraf": "^3.0.0",
60
- "sinon": "^7.0.0",
59
+ "sinon": "^9.0.2",
61
60
  "standard": "^14.0.0",
62
61
  "webpack": "^4.6.0"
63
62
  },
64
63
  "files": [
65
64
  "dist"
66
65
  ],
67
- "standard": {
68
- "parser": "babel-eslint"
69
- },
70
66
  "browser": "browser.js",
71
67
  "babel": {
72
68
  "presets": [
73
- "env"
74
- ],
75
- "plugins": [
76
- "transform-object-assign"
69
+ "@babel/preset-env"
77
70
  ]
78
71
  },
79
72
  "nyc": {