dotenv
Version:
Loads environment variables from .env file
7 lines (6 loc) • 5.34 kB
JavaScript
var j=(e,n)=>()=>{try{return n||e((n={exports:{}}).exports,n),n.exports}catch(t){throw n=0,t}};var R=j((Z,N)=>{function T(e){return typeof e=="string"?!["false","0","no","off",""].includes(e.toLowerCase()):!!e}function U(e=process.env){let n={};for(let t of["ENCODING","PATH","QUIET","DEBUG","OVERRIDE","FAST"]){let r=e[`DOTENV_${t}`]!=null?e[`DOTENV_${t}`]:e[`DOTENV_CONFIG_${t}`];r!=null&&(n[t.toLowerCase()]=t==="ENCODING"||t==="PATH"?r:T(r))}return n}N.exports={parseBoolean:T,optionsFromEnv:U}});var P=j((ee,b)=>{var F=require("fs"),_=require("path"),B=require("os"),{URL:L,fileURLToPath:Q}=require("url"),{parseBoolean:$,optionsFromEnv:I}=R(),G=/(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/mg,y=new Uint8Array(256);for(let e=48;e<=57;e++)y[e]=1;for(let e=65;e<=90;e++)y[e]=1;for(let e=97;e<=122;e++)y[e]=1;y[45]=1;y[46]=1;y[95]=1;function H(e){let n={},t=e.toString();t=t.replace(/\r\n?/mg,`
`);let r;for(;(r=G.exec(t))!=null;){let o=r[1],i=r[2]||"";i=i.trim();let c=i[0];i=i.replace(/^(['"`])([\s\S]*)\1$/mg,"$2"),c==='"'&&(i=i.replace(/\\n/g,`
`),i=i.replace(/\\r/g,"\r")),n[o]=i}return n}function g(e){return e<=32?e===32||e>=9&&e<=13:e>=160&&(e===160||e===5760||e>=8192&&e<=8202||e===8232||e===8233||e===8239||e===8287||e===12288||e===65279)}function O(e){return e===10||e===8232||e===8233}function V(e){let n={},t=typeof e=="string"?e:e.toString();t.indexOf("\r")!==-1&&(t=t.replace(/\r\n?/g,`
`));let r=t.length,o=0;for(;o<r;){let i=t.charCodeAt(o);for(;o<r&&g(i);)o++,i=t.charCodeAt(o);if(o>=r)break;if(i===35){for(;o<r&&!O(t.charCodeAt(o));)o++;continue}let c=-1;if(i===101&&o+6<r&&t.charCodeAt(o+1)===120&&t.charCodeAt(o+2)===112&&t.charCodeAt(o+3)===111&&t.charCodeAt(o+4)===114&&t.charCodeAt(o+5)===116){let u=t.charCodeAt(o+6);if(g(u)){let s=o+7;for(;s<r&&g(t.charCodeAt(s));)s++;y[t.charCodeAt(s)]&&(c=o+6,o=s)}else i=t.charCodeAt(o)}let E=o,p=0;for(;o<r&&(p=t.charCodeAt(o),y[p]);)o++;if(o===E){for(;o<r&&!O(t.charCodeAt(o));)o++;continue}let k=t.slice(E,o),D=o;if(o>=r&&(p=0),g(p))do o++,p=o<r?t.charCodeAt(o):0;while(g(p));if(p===61)o++;else if(p===58&&o===D&&o+1<r&&g(t.charCodeAt(o+1)))o+=2;else{for(o=c===-1?D:c;o<r&&!O(t.charCodeAt(o));)o++;continue}let d=o,l=o;for(;l<r&&g(t.charCodeAt(l));)l++;let C=t.charCodeAt(l),a,q=!1;if(C===39||C===34||C===96){let u=t[l],s=t.indexOf(u,l+1),f=-1,h=-1;for(;s!==-1;){let x=t.charCodeAt(s-1)===92,w=s+1;for(;w<r&&!O(t.charCodeAt(w))&&g(t.charCodeAt(w));)w++;if((w===r||O(t.charCodeAt(w))||t.charCodeAt(w)===35)&&(f=s,h=w),!x)break;s=t.indexOf(u,s+1)}if(f!==-1){if(a=t.slice(l+1,f),o=h,t.charCodeAt(o)===35)for(;o<r&&!O(t.charCodeAt(o));)o++;q=!0}}if(!q){let u=t.indexOf(`
`,d);u===-1&&(u=r);let s;if(r<4096)s=t.indexOf("#",d),(s===-1||s>u)&&(s=u);else for(s=d;s<u&&t.charCodeAt(s)!==35;)s++;let f=d,h=s;for(;f<h&&g(t.charCodeAt(f));)f++;for(;h>f&&g(t.charCodeAt(h-1));)h--;let x=t.charCodeAt(f);if(a=t.slice(f,h),a.includes("\u2028")||a.includes("\u2029")?a=a.replace(/^(['"`])([\s\S]*)\1$/mg,"$2"):h-f>=2&&(x===39||x===34||x===96)&&t.charCodeAt(h-1)===x&&(a=t.slice(f+1,h-1)),o=s,s<u)for(;o<r&&!O(t.charCodeAt(o));)o++}C===34&&(q||l<o)&&a.indexOf("\\")!==-1&&(a=a.replace(/\\n/g,`
`).replace(/\\r/g,"\r")),n[k]=a}return n}function J(e,n){return n&&$(n.fast)?V(e):H(e)}function v(e){console.log(`\u2506 ${e}`)}function W(e){console.error(`\u25C7 ${e}`)}function S(e){return e[0]==="~"?_.join(B.homedir(),e.slice(1)):e}function K(e={}){let n={...e};for(let t of Object.keys(n))n[t]===void 0&&delete n[t];return{...I(),...n}}function M(e){e=K(e);let n=_.resolve(process.cwd(),".env"),t="utf8",r=process.env;e&&e.processEnv!=null&&(r=e.processEnv);let o=$(e&&e.debug);e&&e.encoding?t=e.encoding:o&&v("no encoding is specified (UTF-8 is used by default)");let i=[n];if(e&&e.path)if(!Array.isArray(e.path))i=[S(e.path)];else{i=[];for(let d of e.path)i.push(S(d))}let c,E={},p={fast:e.fast};for(let d of i)try{let l=A.parse(F.readFileSync(d,{encoding:t}),p);A.populate(E,l,e)}catch(l){o&&v(`failed to load ${d} ${l.message}`),c=l}let k=A.populate(r,E,e),D=$(Object.prototype.hasOwnProperty.call(e,"quiet")?e.quiet:I(r).quiet);if(o||!D){let d=Object.keys(k).length,l=[];for(let C of i)try{let a=_.relative(process.cwd(),C instanceof L?Q(C):C);l.push(a)}catch(a){o&&v(`failed to load ${C} ${a.message}`),c=a}W(`injected env (${d}) from ${l.join(",")}`)}return c?{parsed:E,error:c}:{parsed:E}}function Y(e){return A.configDotenv(e)}function z(e,n,t={}){let r=$(t&&t.debug),o=$(t&&t.override),i={};if(e===null||typeof e!="object"||n===null||typeof n!="object"){let c=new Error("OBJECT_REQUIRED: Please check the processEnv argument being passed to populate");throw c.code="OBJECT_REQUIRED",c}for(let c of Object.keys(n))Object.prototype.hasOwnProperty.call(e,c)?(o===!0&&(e[c]=n[c],i[c]=n[c]),r&&v(o===!0?`"${c}" is already defined and WAS overwritten`:`"${c}" is already defined and was NOT overwritten`)):(e[c]=n[c],i[c]=n[c]);return i}var A={configDotenv:M,config:Y,parse:J,populate:z};b.exports.configDotenv=A.configDotenv;b.exports.config=A.config;b.exports.parse=A.parse;b.exports.populate=A.populate;b.exports=A});var m=P();module.exports=m;module.exports.config=m.config;module.exports.configDotenv=m.configDotenv;module.exports.parse=m.parse;module.exports.populate=m.populate;