dotenv-webpack 1.5.7 → 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.
- package/README.md +11 -9
- package/browser.js +3 -0
- package/dist/index.js +164 -68
- package/package.json +15 -21
package/README.md
CHANGED
|
@@ -7,16 +7,13 @@ A secure webpack plugin that supports dotenv and other environment variables and
|
|
|
7
7
|
<a href="https://travis-ci.org/mrsteele/dotenv-webpack" target="_blank">
|
|
8
8
|
<img alt="Travis" src="https://travis-ci.org/mrsteele/dotenv-webpack.svg?branch=master" />
|
|
9
9
|
</a>
|
|
10
|
-
<a href="https://codecov.io/gh/mrsteele/dotenv-webpack" target="_blank">
|
|
11
|
-
<img alt="codecov" src="https://codecov.io/gh/mrsteele/dotenv-webpack/branch/master/graph/badge.svg" />
|
|
12
|
-
</a>
|
|
13
10
|
<a href="https://david-dm.org/mrsteele/dotenv-webpack" target="_blank">
|
|
14
11
|
<img alt="Dependency Status" src="https://david-dm.org/mrsteele/dotenv-webpack.svg" />
|
|
15
12
|
</a>
|
|
16
13
|
<a href="https://david-dm.org/mrsteele/dotenv-webpack?type=dev" target="_blank">
|
|
17
14
|
<img alt="devDependency Status" src="https://david-dm.org/mrsteele/dotenv-webpack/dev-status.svg" />
|
|
18
15
|
</a>
|
|
19
|
-
|
|
16
|
+
|
|
20
17
|
<h1>
|
|
21
18
|
<img width="30" heigth="30" src="https://raw.githubusercontent.com/motdotla/dotenv/master/dotenv.png" alt="dotenv" />
|
|
22
19
|
<img width="30" heigth="30" src="https://webpack.js.org/assets/icon-square-big.svg" alt="webpack">
|
|
@@ -28,7 +25,7 @@ A secure webpack plugin that supports dotenv and other environment variables and
|
|
|
28
25
|
|
|
29
26
|
Include the package locally in your repository.
|
|
30
27
|
|
|
31
|
-
`npm install dotenv-webpack --save`
|
|
28
|
+
`npm install dotenv-webpack --save-dev`
|
|
32
29
|
|
|
33
30
|
### Description
|
|
34
31
|
|
|
@@ -83,7 +80,7 @@ Note: the `.env` values for `DB_PASS` and `S3_API` are **NOT** present in our b
|
|
|
83
80
|
|
|
84
81
|
### How Secure?
|
|
85
82
|
|
|
86
|
-
|
|
83
|
+
By allowing you to define exactly where you are loading environment variables from and bundling only variables in your project that are explicitly referenced in your code, you can be sure that only what you need is included and you do not accidentally leak anything sensitive.
|
|
87
84
|
|
|
88
85
|
###### Recommended
|
|
89
86
|
|
|
@@ -94,9 +91,12 @@ Add `.env` to your `.gitignore` file
|
|
|
94
91
|
Use the following properties to configure your instance.
|
|
95
92
|
|
|
96
93
|
* **path** (`'./.env'`) - The path to your environment variables.
|
|
97
|
-
* **safe** (`false`) - If
|
|
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).
|
|
98
96
|
* **systemvars** (`false`) - Set to true if you would rather load all system variables as well (useful for CI purposes).
|
|
99
|
-
* **silent** (`false`) - If true, all warnings will be
|
|
97
|
+
* **silent** (`false`) - If true, all warnings will be suppressed.
|
|
98
|
+
* **expand** (`false`) - Allows your variables to be "expanded" for reusability within your `.env` file.
|
|
99
|
+
* **defaults** (`false`) - Adds support for `dotenv-defaults`. If set to `true`, uses `./.env.defaults`. If a string, uses that location for a defaults file. Read more at https://www.npmjs.com/package/dotenv-defaults.
|
|
100
100
|
|
|
101
101
|
The following example shows how to set any/all arguments.
|
|
102
102
|
|
|
@@ -107,8 +107,10 @@ module.exports = {
|
|
|
107
107
|
new Dotenv({
|
|
108
108
|
path: './some.other.env', // load this now instead of the ones in '.env'
|
|
109
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)
|
|
110
111
|
systemvars: true, // load all the predefined 'process.env' variables which will trump anything local per dotenv specs.
|
|
111
|
-
silent: true // hide any errors
|
|
112
|
+
silent: true, // hide any errors
|
|
113
|
+
defaults: false // load '.env.defaults' as the default values if empty.
|
|
112
114
|
})
|
|
113
115
|
]
|
|
114
116
|
...
|
package/browser.js
ADDED
package/dist/index.js
CHANGED
|
@@ -1,116 +1,211 @@
|
|
|
1
|
-
|
|
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
|
|
8
|
+
var _dotenvDefaults = _interopRequireDefault(require("dotenv-defaults"));
|
|
8
9
|
|
|
9
|
-
var
|
|
10
|
+
var _fs = _interopRequireDefault(require("fs"));
|
|
10
11
|
|
|
11
|
-
var
|
|
12
|
+
var _webpack = require("webpack");
|
|
12
13
|
|
|
13
|
-
|
|
14
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
14
15
|
|
|
15
|
-
|
|
16
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
16
17
|
|
|
17
|
-
var
|
|
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); } }
|
|
18
19
|
|
|
19
|
-
function
|
|
20
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
20
21
|
|
|
21
|
-
|
|
22
|
+
// Mostly taken from here: https://github.com/motdotla/dotenv-expand/blob/master/lib/main.js#L4
|
|
23
|
+
var interpolate = function interpolate(env, vars) {
|
|
24
|
+
var matches = env.match(/\$([a-zA-Z0-9_]+)|\${([a-zA-Z0-9_]+)}/g) || [];
|
|
25
|
+
matches.forEach(function (match) {
|
|
26
|
+
var key = match.replace(/\$|{|}/g, '');
|
|
27
|
+
var variable = vars[key] || '';
|
|
28
|
+
variable = interpolate(variable, vars);
|
|
29
|
+
env = env.replace(match, variable);
|
|
30
|
+
});
|
|
31
|
+
return env;
|
|
32
|
+
};
|
|
22
33
|
|
|
23
|
-
var Dotenv = function () {
|
|
34
|
+
var Dotenv = /*#__PURE__*/function () {
|
|
24
35
|
/**
|
|
25
36
|
* The dotenv-webpack plugin.
|
|
26
37
|
* @param {Object} options - The parameters.
|
|
27
38
|
* @param {String} [options.path=./.env] - The location of the environment variable.
|
|
28
|
-
* @param {
|
|
29
|
-
* @param {
|
|
30
|
-
* @param {
|
|
39
|
+
* @param {Boolean|String} [options.safe=false] - If false ignore safe-mode, if true load `'./.env.example'`, if a string load that file as the sample.
|
|
40
|
+
* @param {Boolean} [options.systemvars=false] - If true, load system environment variables.
|
|
41
|
+
* @param {Boolean} [options.silent=false] - If true, suppress warnings, if false, display warnings.
|
|
31
42
|
* @returns {webpack.DefinePlugin}
|
|
32
43
|
*/
|
|
33
44
|
function Dotenv() {
|
|
34
|
-
var
|
|
35
|
-
_ref$path = _ref.path,
|
|
36
|
-
path = _ref$path === undefined ? './.env' : _ref$path,
|
|
37
|
-
safe = _ref.safe,
|
|
38
|
-
systemvars = _ref.systemvars,
|
|
39
|
-
silent = _ref.silent,
|
|
40
|
-
sample = _ref.sample;
|
|
45
|
+
var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
41
46
|
|
|
42
47
|
_classCallCheck(this, Dotenv);
|
|
43
48
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
49
|
+
this.config = Object.assign({}, {
|
|
50
|
+
path: './.env'
|
|
51
|
+
}, config);
|
|
52
|
+
this.checkDeprecation();
|
|
53
|
+
return new _webpack.DefinePlugin(this.formatData(this.gatherVariables()));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
_createClass(Dotenv, [{
|
|
57
|
+
key: "checkDeprecation",
|
|
58
|
+
value: function checkDeprecation() {
|
|
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)
|
|
63
|
+
|
|
64
|
+
if (sample) {
|
|
65
|
+
if (safe) {
|
|
66
|
+
this.config.safe = sample;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
this.warn('dotenv-webpack: "options.sample" is a deprecated property. Please update your configuration to use "options.safe" instead.', silent);
|
|
48
70
|
}
|
|
49
|
-
this.warn('dotenv-webpack: "options.sample" is a deprecated property. Please update your configuration to use "options.safe" instead.', silent);
|
|
50
71
|
}
|
|
72
|
+
}, {
|
|
73
|
+
key: "gatherVariables",
|
|
74
|
+
value: function gatherVariables() {
|
|
75
|
+
var _this$config2 = this.config,
|
|
76
|
+
safe = _this$config2.safe,
|
|
77
|
+
allowEmptyValues = _this$config2.allowEmptyValues;
|
|
78
|
+
var vars = this.initializeVars();
|
|
79
|
+
|
|
80
|
+
var _this$getEnvs = this.getEnvs(),
|
|
81
|
+
env = _this$getEnvs.env,
|
|
82
|
+
blueprint = _this$getEnvs.blueprint;
|
|
83
|
+
|
|
84
|
+
Object.keys(blueprint).map(function (key) {
|
|
85
|
+
var value = Object.prototype.hasOwnProperty.call(vars, key) ? vars[key] : env[key];
|
|
86
|
+
var isMissing = typeof value === 'undefined' || value === null || !allowEmptyValues && value === '';
|
|
87
|
+
|
|
88
|
+
if (safe && isMissing) {
|
|
89
|
+
throw new Error("Missing environment variable: ".concat(key));
|
|
90
|
+
} else {
|
|
91
|
+
vars[key] = value;
|
|
92
|
+
}
|
|
93
|
+
}); // add the leftovers
|
|
51
94
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
95
|
+
if (safe) {
|
|
96
|
+
Object.assign(vars, env);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return vars;
|
|
100
|
+
}
|
|
101
|
+
}, {
|
|
102
|
+
key: "initializeVars",
|
|
103
|
+
value: function initializeVars() {
|
|
104
|
+
return this.config.systemvars ? Object.assign({}, process.env) : {};
|
|
57
105
|
}
|
|
106
|
+
}, {
|
|
107
|
+
key: "getEnvs",
|
|
108
|
+
value: function getEnvs() {
|
|
109
|
+
var _this$config3 = this.config,
|
|
110
|
+
path = _this$config3.path,
|
|
111
|
+
silent = _this$config3.silent,
|
|
112
|
+
safe = _this$config3.safe;
|
|
58
113
|
|
|
59
|
-
|
|
114
|
+
var env = _dotenvDefaults["default"].parse(this.loadFile({
|
|
115
|
+
file: path,
|
|
116
|
+
silent: silent
|
|
117
|
+
}), this.getDefaults());
|
|
60
118
|
|
|
61
|
-
|
|
62
|
-
if (safe) {
|
|
63
|
-
var file = './.env.example';
|
|
64
|
-
if (safe !== true) {
|
|
65
|
-
file = safe;
|
|
66
|
-
}
|
|
67
|
-
blueprint = this.loadFile(file, silent);
|
|
68
|
-
}
|
|
119
|
+
var blueprint = env;
|
|
69
120
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
if (!value && safe) {
|
|
73
|
-
throw new Error('Missing environment variable: ' + key);
|
|
74
|
-
} else {
|
|
75
|
-
vars[key] = value;
|
|
76
|
-
}
|
|
77
|
-
});
|
|
121
|
+
if (safe) {
|
|
122
|
+
var file = './.env.example';
|
|
78
123
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}, {});
|
|
124
|
+
if (safe !== true) {
|
|
125
|
+
file = safe;
|
|
126
|
+
}
|
|
83
127
|
|
|
84
|
-
|
|
85
|
-
|
|
128
|
+
blueprint = _dotenvDefaults["default"].parse(this.loadFile({
|
|
129
|
+
file: file,
|
|
130
|
+
silent: silent
|
|
131
|
+
}));
|
|
132
|
+
}
|
|
86
133
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
134
|
+
return {
|
|
135
|
+
env: env,
|
|
136
|
+
blueprint: blueprint
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
}, {
|
|
140
|
+
key: "getDefaults",
|
|
141
|
+
value: function getDefaults() {
|
|
142
|
+
var _this$config4 = this.config,
|
|
143
|
+
silent = _this$config4.silent,
|
|
144
|
+
defaults = _this$config4.defaults;
|
|
145
|
+
|
|
146
|
+
if (defaults) {
|
|
147
|
+
return this.loadFile({
|
|
148
|
+
file: defaults === true ? './.env.defaults' : defaults,
|
|
149
|
+
silent: silent
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return '';
|
|
154
|
+
}
|
|
155
|
+
}, {
|
|
156
|
+
key: "formatData",
|
|
157
|
+
value: function formatData() {
|
|
158
|
+
var vars = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
159
|
+
var expand = this.config.expand;
|
|
160
|
+
return Object.keys(vars).reduce(function (obj, key) {
|
|
161
|
+
var v = vars[key];
|
|
162
|
+
var vKey = "process.env.".concat(key);
|
|
163
|
+
var vValue;
|
|
164
|
+
|
|
165
|
+
if (expand) {
|
|
166
|
+
if (v.substring(0, 2) === '\\$') {
|
|
167
|
+
vValue = v.substring(1);
|
|
168
|
+
} else if (v.indexOf('\\$') > 0) {
|
|
169
|
+
vValue = v.replace(/\\\$/g, '$');
|
|
170
|
+
} else {
|
|
171
|
+
vValue = interpolate(v, vars);
|
|
172
|
+
}
|
|
173
|
+
} else {
|
|
174
|
+
vValue = v;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
obj[vKey] = JSON.stringify(vValue);
|
|
178
|
+
return obj;
|
|
179
|
+
}, {});
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Load a file.
|
|
183
|
+
* @param {String} config.file - The file to load.
|
|
184
|
+
* @param {Boolean} config.silent - If true, suppress warnings, if false, display warnings.
|
|
185
|
+
* @returns {Object}
|
|
186
|
+
*/
|
|
93
187
|
|
|
188
|
+
}, {
|
|
189
|
+
key: "loadFile",
|
|
190
|
+
value: function loadFile(_ref) {
|
|
191
|
+
var file = _ref.file,
|
|
192
|
+
silent = _ref.silent;
|
|
94
193
|
|
|
95
|
-
_createClass(Dotenv, [{
|
|
96
|
-
key: 'loadFile',
|
|
97
|
-
value: function loadFile(file, silent) {
|
|
98
194
|
try {
|
|
99
|
-
return
|
|
195
|
+
return _fs["default"].readFileSync(file, 'utf8');
|
|
100
196
|
} catch (err) {
|
|
101
|
-
this.warn(
|
|
197
|
+
this.warn("Failed to load ".concat(file, "."), silent);
|
|
102
198
|
return {};
|
|
103
199
|
}
|
|
104
200
|
}
|
|
105
|
-
|
|
106
201
|
/**
|
|
107
202
|
* Displays a console message if 'silent' is falsey
|
|
108
203
|
* @param {String} msg - The message.
|
|
109
|
-
* @param {
|
|
204
|
+
* @param {Boolean} silent - If true, display the message, if false, suppress the message.
|
|
110
205
|
*/
|
|
111
206
|
|
|
112
207
|
}, {
|
|
113
|
-
key:
|
|
208
|
+
key: "warn",
|
|
114
209
|
value: function warn(msg, silent) {
|
|
115
210
|
!silent && console.warn(msg);
|
|
116
211
|
}
|
|
@@ -119,4 +214,5 @@ var Dotenv = function () {
|
|
|
119
214
|
return Dotenv;
|
|
120
215
|
}();
|
|
121
216
|
|
|
122
|
-
|
|
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": "
|
|
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
|
|
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,37 +42,31 @@
|
|
|
42
42
|
"webpack": "^1 || ^2 || ^3 || ^4"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"dotenv": "^
|
|
45
|
+
"dotenv-defaults": "^2.0.0"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"babel
|
|
49
|
-
"babel
|
|
50
|
-
"babel-
|
|
51
|
-
"babel
|
|
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
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"
|
|
54
|
+
"esdoc-standard-plugin": "^1.0.0",
|
|
55
|
+
"husky": "^4.2.5",
|
|
56
|
+
"mocha": "^6.2.3",
|
|
57
|
+
"nyc": "^15.1.0",
|
|
58
|
+
"rimraf": "^3.0.0",
|
|
59
|
+
"sinon": "^9.0.2",
|
|
60
|
+
"standard": "^14.0.0",
|
|
61
61
|
"webpack": "^4.6.0"
|
|
62
62
|
},
|
|
63
63
|
"files": [
|
|
64
64
|
"dist"
|
|
65
65
|
],
|
|
66
|
-
"standard": {
|
|
67
|
-
"parser": "babel-eslint"
|
|
68
|
-
},
|
|
69
66
|
"browser": "browser.js",
|
|
70
67
|
"babel": {
|
|
71
68
|
"presets": [
|
|
72
|
-
"env"
|
|
73
|
-
],
|
|
74
|
-
"plugins": [
|
|
75
|
-
"transform-object-assign"
|
|
69
|
+
"@babel/preset-env"
|
|
76
70
|
]
|
|
77
71
|
},
|
|
78
72
|
"nyc": {
|