Socket
Socket
Sign inDemoInstall

@percy/env

Package Overview
Dependencies
Maintainers
6
Versions
238
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@percy/env - npm Package Compare versions

Comparing version 1.0.0-beta.58 to 1.0.0-beta.59

76

dist/dotenv.js

@@ -6,23 +6,73 @@ "use strict";

});
exports.config = config;
exports.load = load;
const dotenv = require('dotenv'); // mimic dotenv-rails file hierarchy
// https://github.com/bkeepers/dotenv#what-other-env-files-can-i-use
var _fs = _interopRequireDefault(require("fs"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function config() {
// Heavily inspired by dotenv-rails
// https://github.com/bkeepers/dotenv
// matches each valid line of a dotenv file
const LINE_REG = new RegExp([// key with optional export
'^\\s*(?:export\\s+)?(?<key>[\\w.]+)', // separator
'(?:\\s*=\\s*?|:\\s+?)(?:', // single quoted value or
'\\s*(?<squote>\')(?<sval>(?:\\\\\'|[^\'])*)\'|', // double quoted value or
'\\s*(?<dquote>")(?<dval>(?:\\\\"|[^"])*)"|', // unquoted value
'(?<uval>[^#\\r\\n]+))?', // optional comment
'\\s*(?:#.*)?$'].join(''), 'gm'); // interpolate variable substitutions
const INTERPOLATE_REG = /(.?)(\${?([a-zA-Z0-9_]+)?}?)/g; // expand newlines
const EXPAND_CRLF_REG = /\\(?:(r)|n)/g; // unescape characters
const UNESC_CHAR_REG = /\\([^$])/g;
function load() {
// don't load dotenv files when disabled
if (process.env.PERCY_DISABLE_DOTENV) return;
let {
NODE_ENV: env,
PERCY_DISABLE_DOTENV: disable
} = process.env; // don't load dotenv files when disabled
NODE_ENV
} = process.env; // dotenv filepaths ordered by priority
if (disable) return;
let paths = [env && `.env.${env}.local`, // .env.local is not loaded in test environments
env === 'test' ? null : '.env.local', env && `.env.${env}`, '.env'].filter(Boolean);
let paths = [NODE_ENV && `.env.${NODE_ENV}.local`, NODE_ENV !== 'test' && '.env.local', NODE_ENV && `.env.${NODE_ENV}`, '.env']; // load each dotenv file synchronously
for (let path of paths) {
dotenv.config({
path
});
try {
let src = _fs.default.readFileSync(path, {
encoding: 'utf-8'
}); // iterate over each matching line
for (let {
groups: match
} of src.matchAll(LINE_REG)) {
var _ref, _ref2, _match$sval;
let value = (_ref = (_ref2 = (_match$sval = match.sval) !== null && _match$sval !== void 0 ? _match$sval : match.dval) !== null && _ref2 !== void 0 ? _ref2 : match.uval) !== null && _ref !== void 0 ? _ref : ''; // if double quoted, expand newlines
if (match.dquote) {
value = value.replace(EXPAND_CRLF_REG, (_, r) => r ? '\r' : '\n');
} // unescape characters
value = value.replace(UNESC_CHAR_REG, '$1'); // if not single quoted, interpolate substitutions
if (!match.squote) {
value = value.replace(INTERPOLATE_REG, (_, pre, ref, key) => {
var _process$env$key;
if (pre === '\\') return ref; // escaped reference
return pre + ((_process$env$key = process.env[key]) !== null && _process$env$key !== void 0 ? _process$env$key : '');
});
} // set process.env if not already
if (!Object.prototype.hasOwnProperty.call(process.env, match.key)) {
process.env[match.key] = value;
}
}
} catch (e) {// silent error
}
}
}

2

dist/index.js

@@ -17,2 +17,2 @@ "use strict";

require('./dotenv').config();
require('./dotenv').load();
{
"name": "@percy/env",
"version": "1.0.0-beta.58",
"version": "1.0.0-beta.59",
"license": "MIT",

@@ -24,6 +24,3 @@ "main": "dist/index.js",

},
"dependencies": {
"dotenv": "^10.0.0"
},
"gitHead": "8da6a7bc9cad64b3a2f905a38b1488f5816b5e21"
"gitHead": "bcc5b6da44aef8927cc3acb9406f5ee54ba4dde0"
}
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