Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dotenv-webpack

Package Overview
Dependencies
Maintainers
1
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dotenv-webpack - npm Package Compare versions

Comparing version 1.6.0 to 1.7.0

196

dist/index.js

@@ -7,7 +7,9 @@ 'use strict';

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 _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 _dotenv = require('dotenv');
var _dotenvDefaults = require('dotenv-defaults');
var _dotenv2 = _interopRequireDefault(_dotenv);
var _dotenvDefaults2 = _interopRequireDefault(_dotenvDefaults);

@@ -49,86 +51,154 @@ var _fs = require('fs');

function Dotenv() {
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
_ref$path = _ref.path,
path = _ref$path === undefined ? './.env' : _ref$path,
safe = _ref.safe,
systemvars = _ref.systemvars,
silent = _ref.silent,
sample = _ref.sample,
_ref$expand = _ref.expand,
expand = _ref$expand === undefined ? false : _ref$expand;
var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
_classCallCheck(this, Dotenv);
// Catch older packages, but hold their hand (just for a bit)
if (sample) {
if (safe) {
safe = sample;
this.config = _extends({}, {
path: './.env'
}, config);
this.checkDeprecation();
return new _webpack.DefinePlugin(this.formatData(this.gatherVariables()));
}
_createClass(Dotenv, [{
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)
if (sample) {
if (safe) {
this.config.safe = sample;
}
this.warn('dotenv-webpack: "options.sample" is a deprecated property. Please update your configuration to use "options.safe" instead.', silent);
}
this.warn('dotenv-webpack: "options.sample" is a deprecated property. Please update your configuration to use "options.safe" instead.', silent);
}
}, {
key: 'gatherVariables',
value: function gatherVariables() {
var safe = this.config.safe;
var vars = {};
if (systemvars) {
Object.keys(process.env).map(function (key) {
vars[key] = process.env[key];
var vars = this.initializeVars();
var _getEnvs = this.getEnvs(),
env = _getEnvs.env,
blueprint = _getEnvs.blueprint;
Object.keys(blueprint).map(function (key) {
var value = vars.hasOwnProperty(key) ? vars[key] : env[key];
if (!value && safe) {
throw new Error('Missing environment variable: ' + key);
} else {
vars[key] = value;
}
});
// add the leftovers
if (safe) {
_extends(vars, env);
}
return vars;
}
}, {
key: 'initializeVars',
value: function initializeVars() {
return this.config.systemvars ? _extends({}, process.env) : {};
}
}, {
key: 'getEnvs',
value: function getEnvs() {
var _config2 = this.config,
path = _config2.path,
silent = _config2.silent,
safe = _config2.safe;
var env = this.loadFile(path, silent);
var blueprint = env;
if (safe) {
var file = './.env.example';
if (safe !== true) {
file = safe;
var env = _dotenvDefaults2.default.parse(this.loadFile({
file: path,
silent: silent
}), this.getDefaults());
var blueprint = env;
if (safe) {
var file = './.env.example';
if (safe !== true) {
file = safe;
}
blueprint = _dotenvDefaults2.default.parse(this.loadFile({
file: file,
silent: silent
}));
}
blueprint = this.loadFile(file, silent);
return {
env: env,
blueprint: blueprint
};
}
}, {
key: 'getDefaults',
value: function getDefaults() {
var _config3 = this.config,
silent = _config3.silent,
defaults = _config3.defaults;
Object.keys(blueprint).map(function (key) {
var value = vars.hasOwnProperty(key) ? vars[key] : env[key];
if (!value && safe) {
throw new Error('Missing environment variable: ' + key);
} else {
vars[key] = value;
if (defaults) {
return this.loadFile({
file: defaults === true ? './.env.defaults' : defaults,
silent: silent
});
}
});
var formatData = Object.keys(vars).reduce(function (obj, key) {
var v = vars[key];
var vKey = 'process.env.' + key;
var vValue = void 0;
if (expand) {
if (v.substring(0, 2) === '\\$') {
vValue = v.substring(1);
} else if (v.indexOf('\\$') > 0) {
vValue = v.replace(/\\\$/g, '$');
return '';
}
}, {
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;
if (expand) {
if (v.substring(0, 2) === '\\$') {
vValue = v.substring(1);
} else if (v.indexOf('\\$') > 0) {
vValue = v.replace(/\\\$/g, '$');
} else {
vValue = interpolate(v, vars);
}
} else {
vValue = interpolate(v, vars);
vValue = v;
}
} else {
vValue = v;
}
obj[vKey] = JSON.stringify(vValue);
obj[vKey] = JSON.stringify(vValue);
return obj;
}, {});
return obj;
}, {});
}
return new _webpack.DefinePlugin(formatData);
}
/**
* Load a file.
* @param {String} config.file - The file to load.
* @param {Boolean} config.silent - If true, suppress warnings, if false, display warnings.
* @returns {Object}
*/
/**
* Load and parses a file.
* @param {String} file - The file to load.
* @param {Boolean} silent - If true, suppress warnings, if false, display warnings.
* @returns {Object}
*/
}, {
key: 'loadFile',
value: function loadFile(_ref) {
var file = _ref.file,
silent = _ref.silent;
_createClass(Dotenv, [{
key: 'loadFile',
value: function loadFile(file, silent) {
try {
return _dotenv2.default.parse(_fs2.default.readFileSync(file));
return _fs2.default.readFileSync(file, 'utf8');
} catch (err) {

@@ -135,0 +205,0 @@ this.warn('Failed to load ' + file + '.', silent);

{
"name": "dotenv-webpack",
"description": "A simple webpack plugin to support dotenv.",
"version": "1.6.0",
"version": "1.7.0",
"main": "index.js",

@@ -45,4 +45,3 @@ "scripts": {

"dependencies": {
"dotenv": "^5.0.1",
"dotenv-expand": "^4.0.1"
"dotenv-defaults": "^1.0.2"
},

@@ -49,0 +48,0 @@ "devDependencies": {

@@ -83,3 +83,3 @@ A secure webpack plugin that supports dotenv and other environment variables and **only exposes what you choose and use**.

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.
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.

@@ -97,4 +97,5 @@ ###### Recommended

* **systemvars** (`false`) - Set to true if you would rather load all system variables as well (useful for CI purposes).
* **silent** (`false`) - If true, all warnings will be surpressed.
* **silent** (`false`) - If true, all warnings will be suppressed.
* **expand** (`false`) - Allows your variables to be "expanded" for reusability within your `.env` file.
* **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.

@@ -111,3 +112,4 @@ The following example shows how to set any/all arguments.

systemvars: true, // load all the predefined 'process.env' variables which will trump anything local per dotenv specs.
silent: true // hide any errors
silent: true, // hide any errors
defaults: false // load '.env.defaults' as the default values if empty.
})

@@ -114,0 +116,0 @@ ]

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc