dotenv-webpack
Advanced tools
Comparing version 1.8.0 to 2.0.0
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -6,25 +6,21 @@ Object.defineProperty(exports, "__esModule", { | ||
}); | ||
exports["default"] = void 0; | ||
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; }; | ||
var _dotenvDefaults = _interopRequireDefault(require("dotenv-defaults")); | ||
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; }; }(); | ||
var _fs = _interopRequireDefault(require("fs")); | ||
var _dotenvDefaults = require('dotenv-defaults'); | ||
var _webpack = require("webpack"); | ||
var _dotenvDefaults2 = _interopRequireDefault(_dotenvDefaults); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
var _fs = require('fs'); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
var _fs2 = _interopRequireDefault(_fs); | ||
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); } } | ||
var _webpack = require('webpack'); | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
// Mostly taken from here: https://github.com/motdotla/dotenv-expand/blob/master/lib/main.js#L4 | ||
var interpolate = function interpolate(env, vars) { | ||
var matches = env.match(/\$([a-zA-Z0-9_]+)|\${([a-zA-Z0-9_]+)}/g) || []; | ||
matches.forEach(function (match) { | ||
@@ -36,7 +32,6 @@ var key = match.replace(/\$|{|}/g, ''); | ||
}); | ||
return env; | ||
}; | ||
var Dotenv = function () { | ||
var Dotenv = /*#__PURE__*/function () { | ||
/** | ||
@@ -56,8 +51,6 @@ * The dotenv-webpack plugin. | ||
this.config = _extends({}, { | ||
this.config = Object.assign({}, { | ||
path: './.env' | ||
}, config); | ||
this.checkDeprecation(); | ||
return new _webpack.DefinePlugin(this.formatData(this.gatherVariables())); | ||
@@ -67,9 +60,8 @@ } | ||
_createClass(Dotenv, [{ | ||
key: 'checkDeprecation', | ||
key: "checkDeprecation", | ||
value: function checkDeprecation() { | ||
var _config = this.config, | ||
sample = _config.sample, | ||
safe = _config.safe, | ||
silent = _config.silent; | ||
// Catch older packages, but hold their hand (just for a bit) | ||
var _this$config = this.config, | ||
sample = _this$config.sample, | ||
safe = _this$config.safe, | ||
silent = _this$config.silent; // Catch older packages, but hold their hand (just for a bit) | ||
@@ -80,2 +72,3 @@ if (sample) { | ||
} | ||
this.warn('dotenv-webpack: "options.sample" is a deprecated property. Please update your configuration to use "options.safe" instead.', silent); | ||
@@ -85,29 +78,26 @@ } | ||
}, { | ||
key: 'gatherVariables', | ||
key: "gatherVariables", | ||
value: function gatherVariables() { | ||
var _config2 = this.config, | ||
safe = _config2.safe, | ||
allowEmptyValues = _config2.allowEmptyValues; | ||
var _this$config2 = this.config, | ||
safe = _this$config2.safe, | ||
allowEmptyValues = _this$config2.allowEmptyValues; | ||
var vars = this.initializeVars(); | ||
var _getEnvs = this.getEnvs(), | ||
env = _getEnvs.env, | ||
blueprint = _getEnvs.blueprint; | ||
var _this$getEnvs = this.getEnvs(), | ||
env = _this$getEnvs.env, | ||
blueprint = _this$getEnvs.blueprint; | ||
Object.keys(blueprint).map(function (key) { | ||
var value = Object.prototype.hasOwnProperty.call(vars, key) ? vars[key] : env[key]; | ||
var isMissing = typeof value === 'undefined' || value === null || !allowEmptyValues && value === ''; | ||
if (safe && isMissing) { | ||
throw new Error('Missing environment variable: ' + key); | ||
throw new Error("Missing environment variable: ".concat(key)); | ||
} else { | ||
vars[key] = value; | ||
} | ||
}); | ||
}); // add the leftovers | ||
// add the leftovers | ||
if (safe) { | ||
_extends(vars, env); | ||
Object.assign(vars, env); | ||
} | ||
@@ -118,16 +108,15 @@ | ||
}, { | ||
key: 'initializeVars', | ||
key: "initializeVars", | ||
value: function initializeVars() { | ||
return this.config.systemvars ? _extends({}, process.env) : {}; | ||
return this.config.systemvars ? Object.assign({}, process.env) : {}; | ||
} | ||
}, { | ||
key: 'getEnvs', | ||
key: "getEnvs", | ||
value: function getEnvs() { | ||
var _config3 = this.config, | ||
path = _config3.path, | ||
silent = _config3.silent, | ||
safe = _config3.safe; | ||
var _this$config3 = this.config, | ||
path = _this$config3.path, | ||
silent = _this$config3.silent, | ||
safe = _this$config3.safe; | ||
var env = _dotenvDefaults2.default.parse(this.loadFile({ | ||
var env = _dotenvDefaults["default"].parse(this.loadFile({ | ||
file: path, | ||
@@ -138,8 +127,11 @@ silent: silent | ||
var blueprint = env; | ||
if (safe) { | ||
var file = './.env.example'; | ||
if (safe !== true) { | ||
file = safe; | ||
} | ||
blueprint = _dotenvDefaults2.default.parse(this.loadFile({ | ||
blueprint = _dotenvDefaults["default"].parse(this.loadFile({ | ||
file: file, | ||
@@ -156,9 +148,8 @@ silent: silent | ||
}, { | ||
key: 'getDefaults', | ||
key: "getDefaults", | ||
value: function getDefaults() { | ||
var _config4 = this.config, | ||
silent = _config4.silent, | ||
defaults = _config4.defaults; | ||
var _this$config4 = this.config, | ||
silent = _this$config4.silent, | ||
defaults = _this$config4.defaults; | ||
if (defaults) { | ||
@@ -174,11 +165,11 @@ return this.loadFile({ | ||
}, { | ||
key: 'formatData', | ||
key: "formatData", | ||
value: function formatData() { | ||
var vars = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var expand = this.config.expand; | ||
return Object.keys(vars).reduce(function (obj, key) { | ||
var v = vars[key]; | ||
var vKey = 'process.env.' + key; | ||
var vValue = void 0; | ||
var vKey = "process.env.".concat(key); | ||
var vValue; | ||
if (expand) { | ||
@@ -197,7 +188,5 @@ if (v.substring(0, 2) === '\\$') { | ||
obj[vKey] = JSON.stringify(vValue); | ||
return obj; | ||
}, {}); | ||
} | ||
/** | ||
@@ -211,3 +200,3 @@ * Load a file. | ||
}, { | ||
key: 'loadFile', | ||
key: "loadFile", | ||
value: function loadFile(_ref) { | ||
@@ -218,9 +207,8 @@ var file = _ref.file, | ||
try { | ||
return _fs2.default.readFileSync(file, 'utf8'); | ||
return _fs["default"].readFileSync(file, 'utf8'); | ||
} catch (err) { | ||
this.warn('Failed to load ' + file + '.', silent); | ||
this.warn("Failed to load ".concat(file, "."), silent); | ||
return {}; | ||
} | ||
} | ||
/** | ||
@@ -233,3 +221,3 @@ * Displays a console message if 'silent' is falsey | ||
}, { | ||
key: 'warn', | ||
key: "warn", | ||
value: function warn(msg, silent) { | ||
@@ -243,2 +231,3 @@ !silent && console.warn(msg); | ||
exports.default = Dotenv; | ||
var _default = Dotenv; | ||
exports["default"] = _default; |
{ | ||
"name": "dotenv-webpack", | ||
"description": "A simple webpack plugin to support dotenv.", | ||
"version": "1.8.0", | ||
"version": "2.0.0", | ||
"main": "index.js", | ||
@@ -13,3 +13,3 @@ "scripts": { | ||
"pretest": "npm run build", | ||
"test": "nyc _mocha --require babel-core/register", | ||
"test": "nyc mocha --require @babel/register", | ||
"posttest": "nyc report --reporter=lcov", | ||
@@ -46,18 +46,17 @@ "prebuild": "rimraf dist", | ||
"dependencies": { | ||
"dotenv-defaults": "^1.0.2" | ||
"dotenv-defaults": "^2.0.0" | ||
}, | ||
"devDependencies": { | ||
"babel-cli": "^6.26.0", | ||
"babel-eslint": "^10.0.1", | ||
"babel-plugin-transform-object-assign": "^6.22.0", | ||
"babel-preset-env": "^1.6.1", | ||
"babel-register": "^6.26.0", | ||
"@babel/cli": "^7.10.4", | ||
"@babel/core": "^7.10.4", | ||
"@babel/preset-env": "^7.10.4", | ||
"@babel/register": "^7.10.4", | ||
"chai": "^4.1.2", | ||
"esdoc": "^1.0.4", | ||
"esdoc-standard-plugin": "^1.0.0", | ||
"husky": "^3.0.0", | ||
"mocha": "^6.0.0", | ||
"nyc": "^14.0.0", | ||
"husky": "^4.2.5", | ||
"mocha": "^6.2.3", | ||
"nyc": "^15.1.0", | ||
"rimraf": "^3.0.0", | ||
"sinon": "^7.0.0", | ||
"sinon": "^9.0.2", | ||
"standard": "^14.0.0", | ||
@@ -69,12 +68,6 @@ "webpack": "^4.6.0" | ||
], | ||
"standard": { | ||
"parser": "babel-eslint" | ||
}, | ||
"browser": "browser.js", | ||
"babel": { | ||
"presets": [ | ||
"env" | ||
], | ||
"plugins": [ | ||
"transform-object-assign" | ||
"@babel/preset-env" | ||
] | ||
@@ -81,0 +74,0 @@ }, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
14
14615
199
+ Addeddotenv@8.6.0(transitive)
+ Addeddotenv-defaults@2.0.2(transitive)
- Removeddotenv@6.2.0(transitive)
- Removeddotenv-defaults@1.1.1(transitive)
Updateddotenv-defaults@^2.0.0