load-dotenv
Advanced tools
| /** | ||
| * @param fileName (_optional_) The name of the `.env` file to find. Defaults to `.env`. | ||
| * @returns the absolute file path of the closest `.env` file. | ||
| */ | ||
| export function findEnv(fileName?: string): string | undefined |
+112
| 'use strict'; | ||
| var path = require('node:path'); | ||
| var node_url = require('node:url'); | ||
| var process$1 = require('node:process'); | ||
| var fs = require('node:fs'); | ||
| const typeMappings = { | ||
| directory: 'isDirectory', | ||
| file: 'isFile', | ||
| }; | ||
| function checkType(type) { | ||
| if (Object.hasOwnProperty.call(typeMappings, type)) { | ||
| return; | ||
| } | ||
| throw new Error(`Invalid type specified: ${type}`); | ||
| } | ||
| const matchType = (type, stat) => stat[typeMappings[type]](); | ||
| const toPath$1 = urlOrPath => urlOrPath instanceof URL ? node_url.fileURLToPath(urlOrPath) : urlOrPath; | ||
| function locatePathSync( | ||
| paths, | ||
| { | ||
| cwd = process$1.cwd(), | ||
| type = 'file', | ||
| allowSymlinks = true, | ||
| } = {}, | ||
| ) { | ||
| checkType(type); | ||
| cwd = toPath$1(cwd); | ||
| const statFunction = allowSymlinks ? fs.statSync : fs.lstatSync; | ||
| for (const path_ of paths) { | ||
| try { | ||
| const stat = statFunction(path.resolve(cwd, path_), { | ||
| throwIfNoEntry: false, | ||
| }); | ||
| if (!stat) { | ||
| continue; | ||
| } | ||
| if (matchType(type, stat)) { | ||
| return path_; | ||
| } | ||
| } catch {} | ||
| } | ||
| } | ||
| const toPath = urlOrPath => urlOrPath instanceof URL ? node_url.fileURLToPath(urlOrPath) : urlOrPath; | ||
| const findUpStop = Symbol('findUpStop'); | ||
| function findUpMultipleSync(name, options = {}) { | ||
| let directory = path.resolve(toPath(options.cwd) || ''); | ||
| const {root} = path.parse(directory); | ||
| const stopAt = options.stopAt || root; | ||
| const limit = options.limit || Number.POSITIVE_INFINITY; | ||
| const paths = [name].flat(); | ||
| const runMatcher = locateOptions => { | ||
| if (typeof name !== 'function') { | ||
| return locatePathSync(paths, locateOptions); | ||
| } | ||
| const foundPath = name(locateOptions.cwd); | ||
| if (typeof foundPath === 'string') { | ||
| return locatePathSync([foundPath], locateOptions); | ||
| } | ||
| return foundPath; | ||
| }; | ||
| const matches = []; | ||
| // eslint-disable-next-line no-constant-condition | ||
| while (true) { | ||
| const foundPath = runMatcher({...options, cwd: directory}); | ||
| if (foundPath === findUpStop) { | ||
| break; | ||
| } | ||
| if (foundPath) { | ||
| matches.push(path.resolve(directory, foundPath)); | ||
| } | ||
| if (directory === stopAt || matches.length >= limit) { | ||
| break; | ||
| } | ||
| directory = path.dirname(directory); | ||
| } | ||
| return matches; | ||
| } | ||
| function findUpSync(name, options = {}) { | ||
| const matches = findUpMultipleSync(name, {...options, limit: 1}); | ||
| return matches[0]; | ||
| } | ||
| function findEnv(fileName = '') { | ||
| return findUpSync(fileName || process.env.ENV_FILE || '.env') | ||
| } | ||
| exports.findEnv = findEnv; | ||
| //# sourceMappingURL=find.js.map |
| {"version":3,"file":"find.js","sources":["../node_modules/.pnpm/locate-path@7.2.0/node_modules/locate-path/index.js","../node_modules/.pnpm/find-up@6.3.0/node_modules/find-up/index.js","../lib/find.js"],"sourcesContent":["import process from 'node:process';\nimport path from 'node:path';\nimport fs, {promises as fsPromises} from 'node:fs';\nimport {fileURLToPath} from 'node:url';\nimport pLocate from 'p-locate';\n\nconst typeMappings = {\n\tdirectory: 'isDirectory',\n\tfile: 'isFile',\n};\n\nfunction checkType(type) {\n\tif (Object.hasOwnProperty.call(typeMappings, type)) {\n\t\treturn;\n\t}\n\n\tthrow new Error(`Invalid type specified: ${type}`);\n}\n\nconst matchType = (type, stat) => stat[typeMappings[type]]();\n\nconst toPath = urlOrPath => urlOrPath instanceof URL ? fileURLToPath(urlOrPath) : urlOrPath;\n\nexport async function locatePath(\n\tpaths,\n\t{\n\t\tcwd = process.cwd(),\n\t\ttype = 'file',\n\t\tallowSymlinks = true,\n\t\tconcurrency,\n\t\tpreserveOrder,\n\t} = {},\n) {\n\tcheckType(type);\n\tcwd = toPath(cwd);\n\n\tconst statFunction = allowSymlinks ? fsPromises.stat : fsPromises.lstat;\n\n\treturn pLocate(paths, async path_ => {\n\t\ttry {\n\t\t\tconst stat = await statFunction(path.resolve(cwd, path_));\n\t\t\treturn matchType(type, stat);\n\t\t} catch {\n\t\t\treturn false;\n\t\t}\n\t}, {concurrency, preserveOrder});\n}\n\nexport function locatePathSync(\n\tpaths,\n\t{\n\t\tcwd = process.cwd(),\n\t\ttype = 'file',\n\t\tallowSymlinks = true,\n\t} = {},\n) {\n\tcheckType(type);\n\tcwd = toPath(cwd);\n\n\tconst statFunction = allowSymlinks ? fs.statSync : fs.lstatSync;\n\n\tfor (const path_ of paths) {\n\t\ttry {\n\t\t\tconst stat = statFunction(path.resolve(cwd, path_), {\n\t\t\t\tthrowIfNoEntry: false,\n\t\t\t});\n\n\t\t\tif (!stat) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (matchType(type, stat)) {\n\t\t\t\treturn path_;\n\t\t\t}\n\t\t} catch {}\n\t}\n}\n","import path from 'node:path';\nimport {fileURLToPath} from 'node:url';\nimport {locatePath, locatePathSync} from 'locate-path';\n\nconst toPath = urlOrPath => urlOrPath instanceof URL ? fileURLToPath(urlOrPath) : urlOrPath;\n\nexport const findUpStop = Symbol('findUpStop');\n\nexport async function findUpMultiple(name, options = {}) {\n\tlet directory = path.resolve(toPath(options.cwd) || '');\n\tconst {root} = path.parse(directory);\n\tconst stopAt = path.resolve(directory, options.stopAt || root);\n\tconst limit = options.limit || Number.POSITIVE_INFINITY;\n\tconst paths = [name].flat();\n\n\tconst runMatcher = async locateOptions => {\n\t\tif (typeof name !== 'function') {\n\t\t\treturn locatePath(paths, locateOptions);\n\t\t}\n\n\t\tconst foundPath = await name(locateOptions.cwd);\n\t\tif (typeof foundPath === 'string') {\n\t\t\treturn locatePath([foundPath], locateOptions);\n\t\t}\n\n\t\treturn foundPath;\n\t};\n\n\tconst matches = [];\n\t// eslint-disable-next-line no-constant-condition\n\twhile (true) {\n\t\t// eslint-disable-next-line no-await-in-loop\n\t\tconst foundPath = await runMatcher({...options, cwd: directory});\n\n\t\tif (foundPath === findUpStop) {\n\t\t\tbreak;\n\t\t}\n\n\t\tif (foundPath) {\n\t\t\tmatches.push(path.resolve(directory, foundPath));\n\t\t}\n\n\t\tif (directory === stopAt || matches.length >= limit) {\n\t\t\tbreak;\n\t\t}\n\n\t\tdirectory = path.dirname(directory);\n\t}\n\n\treturn matches;\n}\n\nexport function findUpMultipleSync(name, options = {}) {\n\tlet directory = path.resolve(toPath(options.cwd) || '');\n\tconst {root} = path.parse(directory);\n\tconst stopAt = options.stopAt || root;\n\tconst limit = options.limit || Number.POSITIVE_INFINITY;\n\tconst paths = [name].flat();\n\n\tconst runMatcher = locateOptions => {\n\t\tif (typeof name !== 'function') {\n\t\t\treturn locatePathSync(paths, locateOptions);\n\t\t}\n\n\t\tconst foundPath = name(locateOptions.cwd);\n\t\tif (typeof foundPath === 'string') {\n\t\t\treturn locatePathSync([foundPath], locateOptions);\n\t\t}\n\n\t\treturn foundPath;\n\t};\n\n\tconst matches = [];\n\t// eslint-disable-next-line no-constant-condition\n\twhile (true) {\n\t\tconst foundPath = runMatcher({...options, cwd: directory});\n\n\t\tif (foundPath === findUpStop) {\n\t\t\tbreak;\n\t\t}\n\n\t\tif (foundPath) {\n\t\t\tmatches.push(path.resolve(directory, foundPath));\n\t\t}\n\n\t\tif (directory === stopAt || matches.length >= limit) {\n\t\t\tbreak;\n\t\t}\n\n\t\tdirectory = path.dirname(directory);\n\t}\n\n\treturn matches;\n}\n\nexport async function findUp(name, options = {}) {\n\tconst matches = await findUpMultiple(name, {...options, limit: 1});\n\treturn matches[0];\n}\n\nexport function findUpSync(name, options = {}) {\n\tconst matches = findUpMultipleSync(name, {...options, limit: 1});\n\treturn matches[0];\n}\n\nexport {\n\tpathExists,\n\tpathExistsSync,\n} from 'path-exists';\n","import {findUpSync} from 'find-up'\n\nexport function findEnv(fileName = '') {\n return findUpSync(fileName || process.env.ENV_FILE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,EAAE,aAAa,CAAC,CAAC;AACrD,GAAG;AACH;AACA,EAAE,OAAO,SAAS,CAAC;AACnB,EAAE,CAAC;AACH;AACA,CAAC,MAAM,OAAO,GAAG,EAAE,CAAC;AACpB;AACA,CAAC,OAAO,IAAI,EAAE;AACd,EAAE,MAAM,SAAS,GAAG,UAAU,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,SAAS,CAAC,CAAC,CAAC;AAC7D;AACA,EAAE,IAAI,SAAS,KAAK,UAAU,EAAE;AAChC,GAAG,MAAM;AACT,GAAG;AACH;AACA,EAAE,IAAI,SAAS,EAAE;AACjB,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC;AACpD,GAAG;AACH;AACA,EAAE,IAAI,SAAS,KAAK,MAAM,IAAI,OAAO,CAAC,MAAM,IAAI,KAAK,EAAE;AACvD,GAAG,MAAM;AACT,GAAG;AACH;AACA,EAAE,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;AACtC,EAAE;AACF;AACA,CAAC,OAAO,OAAO,CAAC;AAChB,CAAC;AAMD;AACO,SAAS,UAAU,CAAC,IAAI,EAAE,OAAO,GAAG,EAAE,EAAE;AAC/C,CAAC,MAAM,OAAO,GAAG,kBAAkB,CAAC,IAAI,EAAE,CAAC,GAAG,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC;AAClE,CAAC,OAAO,OAAO,CAAC,CAAC,CAAC,CAAC;AACnB;;ACrGO,SAAS,OAAO,CAAC,QAAQ,GAAG,EAAE,EAAE;AACvC,EAAE,OAAO,UAAU,CAAC,QAAQ,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,IAAI,MAAM,CAAC;AAC/D;;;;","x_google_ignoreList":[0,1]} |
| 'use strict'; | ||
| var find = require('../find.js'); | ||
| require('node:path'); | ||
| require('node:url'); | ||
| require('node:process'); | ||
| require('node:fs'); | ||
| const envFilePath = find.findEnv(); | ||
| if (envFilePath) { | ||
| require('dotenv').config({path: envFilePath}); | ||
| } else { | ||
| throw new Error('[load-dotenv] No .env file found') | ||
| } | ||
| //# sourceMappingURL=index.js.map |
| {"version":3,"file":"index.js","sources":["../../lib/load/index.js"],"sourcesContent":["import {findEnv} from '../find'\n\nconst envFilePath = findEnv()\n\nif (envFilePath) {\n require('dotenv').config({path: envFilePath})\n} else {\n throw new Error('[load-dotenv] No .env file found')\n}\n"],"names":["findEnv"],"mappings":";;;;;;;;AAEA,MAAM,WAAW,GAAGA,YAAO,GAAE;AAC7B;AACA,IAAI,WAAW,EAAE;AACjB,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,WAAW,CAAC,EAAC;AAC/C,CAAC,MAAM;AACP,EAAE,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC;AACrD;;"} |
| 'use strict'; | ||
| var find = require('../find.js'); | ||
| require('node:path'); | ||
| require('node:url'); | ||
| require('node:process'); | ||
| require('node:fs'); | ||
| const envFilePath = find.findEnv(); | ||
| if (envFilePath) { | ||
| require('dotenv').config({path: envFilePath}); | ||
| } else { | ||
| console.error('[load-dotenv] No .env file found'); | ||
| } | ||
| //# sourceMappingURL=optional.js.map |
| {"version":3,"file":"optional.js","sources":["../../lib/load/optional.js"],"sourcesContent":["import {findEnv} from '../find'\n\nconst envFilePath = findEnv()\n\nif (envFilePath) {\n require('dotenv').config({path: envFilePath})\n} else {\n console.error('[load-dotenv] No .env file found')\n}\n"],"names":["findEnv"],"mappings":";;;;;;;;AAEA,MAAM,WAAW,GAAGA,YAAO,GAAE;AAC7B;AACA,IAAI,WAAW,EAAE;AACjB,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,WAAW,CAAC,EAAC;AAC/C,CAAC,MAAM;AACP,EAAE,OAAO,CAAC,KAAK,CAAC,kCAAkC,EAAC;AACnD;;"} |
+3
-5
| { | ||
| "name": "load-dotenv", | ||
| "version": "0.0.9", | ||
| "version": "0.0.10", | ||
| "description": "Automatically load the closest .env file", | ||
@@ -8,6 +8,3 @@ "author": "Zach Olivare <https://github.com/0livare>", | ||
| "repository": "https://github.com/0livare/load-dotenv", | ||
| "main": "lib/find.js", | ||
| "files": [ | ||
| "dist" | ||
| ], | ||
| "main": "./find.js", | ||
| "peerDependencies": { | ||
@@ -43,2 +40,3 @@ "dotenv": "16" | ||
| ], | ||
| "types": "./find.d.ts", | ||
| "scripts": { | ||
@@ -45,0 +43,0 @@ "build": "rm -rf dist && rollup -c", |
| /** | ||
| * @param fileName (_optional_) The name of the `.env` file to find. Defaults to `.env`. | ||
| * @returns the absolute file path of the closest `.env` file. | ||
| */ | ||
| export function findEnv(fileName?: string): string | undefined |
-112
| 'use strict'; | ||
| var path = require('node:path'); | ||
| var node_url = require('node:url'); | ||
| var process$1 = require('node:process'); | ||
| var fs = require('node:fs'); | ||
| const typeMappings = { | ||
| directory: 'isDirectory', | ||
| file: 'isFile', | ||
| }; | ||
| function checkType(type) { | ||
| if (Object.hasOwnProperty.call(typeMappings, type)) { | ||
| return; | ||
| } | ||
| throw new Error(`Invalid type specified: ${type}`); | ||
| } | ||
| const matchType = (type, stat) => stat[typeMappings[type]](); | ||
| const toPath$1 = urlOrPath => urlOrPath instanceof URL ? node_url.fileURLToPath(urlOrPath) : urlOrPath; | ||
| function locatePathSync( | ||
| paths, | ||
| { | ||
| cwd = process$1.cwd(), | ||
| type = 'file', | ||
| allowSymlinks = true, | ||
| } = {}, | ||
| ) { | ||
| checkType(type); | ||
| cwd = toPath$1(cwd); | ||
| const statFunction = allowSymlinks ? fs.statSync : fs.lstatSync; | ||
| for (const path_ of paths) { | ||
| try { | ||
| const stat = statFunction(path.resolve(cwd, path_), { | ||
| throwIfNoEntry: false, | ||
| }); | ||
| if (!stat) { | ||
| continue; | ||
| } | ||
| if (matchType(type, stat)) { | ||
| return path_; | ||
| } | ||
| } catch {} | ||
| } | ||
| } | ||
| const toPath = urlOrPath => urlOrPath instanceof URL ? node_url.fileURLToPath(urlOrPath) : urlOrPath; | ||
| const findUpStop = Symbol('findUpStop'); | ||
| function findUpMultipleSync(name, options = {}) { | ||
| let directory = path.resolve(toPath(options.cwd) || ''); | ||
| const {root} = path.parse(directory); | ||
| const stopAt = options.stopAt || root; | ||
| const limit = options.limit || Number.POSITIVE_INFINITY; | ||
| const paths = [name].flat(); | ||
| const runMatcher = locateOptions => { | ||
| if (typeof name !== 'function') { | ||
| return locatePathSync(paths, locateOptions); | ||
| } | ||
| const foundPath = name(locateOptions.cwd); | ||
| if (typeof foundPath === 'string') { | ||
| return locatePathSync([foundPath], locateOptions); | ||
| } | ||
| return foundPath; | ||
| }; | ||
| const matches = []; | ||
| // eslint-disable-next-line no-constant-condition | ||
| while (true) { | ||
| const foundPath = runMatcher({...options, cwd: directory}); | ||
| if (foundPath === findUpStop) { | ||
| break; | ||
| } | ||
| if (foundPath) { | ||
| matches.push(path.resolve(directory, foundPath)); | ||
| } | ||
| if (directory === stopAt || matches.length >= limit) { | ||
| break; | ||
| } | ||
| directory = path.dirname(directory); | ||
| } | ||
| return matches; | ||
| } | ||
| function findUpSync(name, options = {}) { | ||
| const matches = findUpMultipleSync(name, {...options, limit: 1}); | ||
| return matches[0]; | ||
| } | ||
| function findEnv(fileName = '') { | ||
| return findUpSync(fileName || process.env.ENV_FILE || '.env') | ||
| } | ||
| exports.findEnv = findEnv; | ||
| //# sourceMappingURL=find.js.map |
| {"version":3,"file":"find.js","sources":["../node_modules/.pnpm/locate-path@7.2.0/node_modules/locate-path/index.js","../node_modules/.pnpm/find-up@6.3.0/node_modules/find-up/index.js","../lib/find.js"],"sourcesContent":["import process from 'node:process';\nimport path from 'node:path';\nimport fs, {promises as fsPromises} from 'node:fs';\nimport {fileURLToPath} from 'node:url';\nimport pLocate from 'p-locate';\n\nconst typeMappings = {\n\tdirectory: 'isDirectory',\n\tfile: 'isFile',\n};\n\nfunction checkType(type) {\n\tif (Object.hasOwnProperty.call(typeMappings, type)) {\n\t\treturn;\n\t}\n\n\tthrow new Error(`Invalid type specified: ${type}`);\n}\n\nconst matchType = (type, stat) => stat[typeMappings[type]]();\n\nconst toPath = urlOrPath => urlOrPath instanceof URL ? fileURLToPath(urlOrPath) : urlOrPath;\n\nexport async function locatePath(\n\tpaths,\n\t{\n\t\tcwd = process.cwd(),\n\t\ttype = 'file',\n\t\tallowSymlinks = true,\n\t\tconcurrency,\n\t\tpreserveOrder,\n\t} = {},\n) {\n\tcheckType(type);\n\tcwd = toPath(cwd);\n\n\tconst statFunction = allowSymlinks ? fsPromises.stat : fsPromises.lstat;\n\n\treturn pLocate(paths, async path_ => {\n\t\ttry {\n\t\t\tconst stat = await statFunction(path.resolve(cwd, path_));\n\t\t\treturn matchType(type, stat);\n\t\t} catch {\n\t\t\treturn false;\n\t\t}\n\t}, {concurrency, preserveOrder});\n}\n\nexport function locatePathSync(\n\tpaths,\n\t{\n\t\tcwd = process.cwd(),\n\t\ttype = 'file',\n\t\tallowSymlinks = true,\n\t} = {},\n) {\n\tcheckType(type);\n\tcwd = toPath(cwd);\n\n\tconst statFunction = allowSymlinks ? fs.statSync : fs.lstatSync;\n\n\tfor (const path_ of paths) {\n\t\ttry {\n\t\t\tconst stat = statFunction(path.resolve(cwd, path_), {\n\t\t\t\tthrowIfNoEntry: false,\n\t\t\t});\n\n\t\t\tif (!stat) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (matchType(type, stat)) {\n\t\t\t\treturn path_;\n\t\t\t}\n\t\t} catch {}\n\t}\n}\n","import path from 'node:path';\nimport {fileURLToPath} from 'node:url';\nimport {locatePath, locatePathSync} from 'locate-path';\n\nconst toPath = urlOrPath => urlOrPath instanceof URL ? fileURLToPath(urlOrPath) : urlOrPath;\n\nexport const findUpStop = Symbol('findUpStop');\n\nexport async function findUpMultiple(name, options = {}) {\n\tlet directory = path.resolve(toPath(options.cwd) || '');\n\tconst {root} = path.parse(directory);\n\tconst stopAt = path.resolve(directory, options.stopAt || root);\n\tconst limit = options.limit || Number.POSITIVE_INFINITY;\n\tconst paths = [name].flat();\n\n\tconst runMatcher = async locateOptions => {\n\t\tif (typeof name !== 'function') {\n\t\t\treturn locatePath(paths, locateOptions);\n\t\t}\n\n\t\tconst foundPath = await name(locateOptions.cwd);\n\t\tif (typeof foundPath === 'string') {\n\t\t\treturn locatePath([foundPath], locateOptions);\n\t\t}\n\n\t\treturn foundPath;\n\t};\n\n\tconst matches = [];\n\t// eslint-disable-next-line no-constant-condition\n\twhile (true) {\n\t\t// eslint-disable-next-line no-await-in-loop\n\t\tconst foundPath = await runMatcher({...options, cwd: directory});\n\n\t\tif (foundPath === findUpStop) {\n\t\t\tbreak;\n\t\t}\n\n\t\tif (foundPath) {\n\t\t\tmatches.push(path.resolve(directory, foundPath));\n\t\t}\n\n\t\tif (directory === stopAt || matches.length >= limit) {\n\t\t\tbreak;\n\t\t}\n\n\t\tdirectory = path.dirname(directory);\n\t}\n\n\treturn matches;\n}\n\nexport function findUpMultipleSync(name, options = {}) {\n\tlet directory = path.resolve(toPath(options.cwd) || '');\n\tconst {root} = path.parse(directory);\n\tconst stopAt = options.stopAt || root;\n\tconst limit = options.limit || Number.POSITIVE_INFINITY;\n\tconst paths = [name].flat();\n\n\tconst runMatcher = locateOptions => {\n\t\tif (typeof name !== 'function') {\n\t\t\treturn locatePathSync(paths, locateOptions);\n\t\t}\n\n\t\tconst foundPath = name(locateOptions.cwd);\n\t\tif (typeof foundPath === 'string') {\n\t\t\treturn locatePathSync([foundPath], locateOptions);\n\t\t}\n\n\t\treturn foundPath;\n\t};\n\n\tconst matches = [];\n\t// eslint-disable-next-line no-constant-condition\n\twhile (true) {\n\t\tconst foundPath = runMatcher({...options, cwd: directory});\n\n\t\tif (foundPath === findUpStop) {\n\t\t\tbreak;\n\t\t}\n\n\t\tif (foundPath) {\n\t\t\tmatches.push(path.resolve(directory, foundPath));\n\t\t}\n\n\t\tif (directory === stopAt || matches.length >= limit) {\n\t\t\tbreak;\n\t\t}\n\n\t\tdirectory = path.dirname(directory);\n\t}\n\n\treturn matches;\n}\n\nexport async function findUp(name, options = {}) {\n\tconst matches = await findUpMultiple(name, {...options, limit: 1});\n\treturn matches[0];\n}\n\nexport function findUpSync(name, options = {}) {\n\tconst matches = findUpMultipleSync(name, {...options, limit: 1});\n\treturn matches[0];\n}\n\nexport {\n\tpathExists,\n\tpathExistsSync,\n} from 'path-exists';\n","import {findUpSync} from 'find-up'\n\nexport function findEnv(fileName = '') {\n return findUpSync(fileName || process.env.ENV_FILE || '.env')\n}\n"],"names":["toPath","fileURLToPath","process"],"mappings":";;;;;;;AAMA,MAAM,YAAY,GAAG;AACrB,CAAC,SAAS,EAAE,aAAa;AACzB,CAAC,IAAI,EAAE,QAAQ;AACf,CAAC,CAAC;AACF;AACA,SAAS,SAAS,CAAC,IAAI,EAAE;AACzB,CAAC,IAAI,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,EAAE;AACrD,EAAE,OAAO;AACT,EAAE;AACF;AACA,CAAC,MAAM,IAAI,KAAK,CAAC,CAAC,wBAAwB,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;AACpD,CAAC;AACD;AACA,MAAM,SAAS,GAAG,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC;AAC7D;AACA,MAAMA,QAAM,GAAG,SAAS,IAAI,SAAS,YAAY,GAAG,GAAGC,sBAAa,CAAC,SAAS,CAAC,GAAG,SAAS,CAAC;AA0B5F;AACO,SAAS,cAAc;AAC9B,CAAC,KAAK;AACN,CAAC;AACD,EAAE,GAAG,GAAGC,SAAO,CAAC,GAAG,EAAE;AACrB,EAAE,IAAI,GAAG,MAAM;AACf,EAAE,aAAa,GAAG,IAAI;AACtB,EAAE,GAAG,EAAE;AACP,EAAE;AACF,CAAC,SAAS,CAAC,IAAI,CAAC,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AO,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC;AAClE,CAAC,OAAO,OAAO,CAAC,CAAC,CAAC,CAAC;AACnB;;ACrGO,SAAS,OAAO,CAAC,QAAQ,GAAG,EAAE,EAAE;AACvC,EAAE,OAAO,UAAU,CAAC,QAAQ,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,IAAI,MAAM,CAAC;AAC/D;;;;","x_google_ignoreList":[0,1]} |
| 'use strict'; | ||
| var find = require('../find.js'); | ||
| require('node:path'); | ||
| require('node:url'); | ||
| require('node:process'); | ||
| require('node:fs'); | ||
| const envFilePath = find.findEnv(); | ||
| if (envFilePath) { | ||
| require('dotenv').config({path: envFilePath}); | ||
| } else { | ||
| throw new Error('[load-dotenv] No .env file found') | ||
| } | ||
| //# sourceMappingURL=index.js.map |
| {"version":3,"file":"index.js","sources":["../../lib/load/index.js"],"sourcesContent":["import {findEnv} from '../find'\n\nconst envFilePath = findEnv()\n\nif (envFilePath) {\n require('dotenv').config({path: envFilePath})\n} else {\n throw new Error('[load-dotenv] No .env file found')\n}\n"],"names":["findEnv"],"mappings":";;;;;;;;AAEA,MAAM,WAAW,GAAGA,YAAO,GAAE;AAC7B;AACA,IAAI,WAAW,EAAE;AACjB,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,WAAW,CAAC,EAAC;AAC/C,CAAC,MAAM;AACP,EAAE,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC;AACrD;;"} |
| 'use strict'; | ||
| var find = require('../find.js'); | ||
| require('node:path'); | ||
| require('node:url'); | ||
| require('node:process'); | ||
| require('node:fs'); | ||
| const envFilePath = find.findEnv(); | ||
| if (envFilePath) { | ||
| require('dotenv').config({path: envFilePath}); | ||
| } else { | ||
| console.error('[load-dotenv] No .env file found'); | ||
| } | ||
| //# sourceMappingURL=optional.js.map |
| {"version":3,"file":"optional.js","sources":["../../lib/load/optional.js"],"sourcesContent":["import {findEnv} from '../find'\n\nconst envFilePath = findEnv()\n\nif (envFilePath) {\n require('dotenv').config({path: envFilePath})\n} else {\n console.error('[load-dotenv] No .env file found')\n}\n"],"names":["findEnv"],"mappings":";;;;;;;;AAEA,MAAM,WAAW,GAAGA,YAAO,GAAE;AAC7B;AACA,IAAI,WAAW,EAAE;AACjB,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,WAAW,CAAC,EAAC;AAC/C,CAAC,MAAM;AACP,EAAE,OAAO,CAAC,KAAK,CAAC,kCAAkC,EAAC;AACnD;;"} |
| { | ||
| "name": "load-dotenv", | ||
| "version": "0.0.8", | ||
| "description": "Automatically load the closest .env file", | ||
| "author": "Zach Olivare <https://github.com/0livare>", | ||
| "license": "MIT", | ||
| "repository": "https://github.com/0livare/load-dotenv", | ||
| "main": "./find.js", | ||
| "scripts": { | ||
| "build": "rm -rf dist && rollup -c", | ||
| "pub": "pnpm run build && node prepublish.mjs && cd dist && pnpm publish", | ||
| "pubyalc": "pnpm run build && node prepublish.mjs && cd dist && yalc publish" | ||
| }, | ||
| "peerDependencies": { | ||
| "dotenv": "16" | ||
| }, | ||
| "dependencies": { | ||
| "find-up": "^6.3.0" | ||
| }, | ||
| "devDependencies": { | ||
| "@rollup/plugin-commonjs": "^24.1.0", | ||
| "@rollup/plugin-node-resolve": "^15.0.2", | ||
| "rollup": "^3.21.0", | ||
| "tsup": "^6.7.0", | ||
| "typescript": "^4.9.5" | ||
| }, | ||
| "keywords": [ | ||
| "dotenv", | ||
| "load", | ||
| "find", | ||
| "env", | ||
| "file", | ||
| "environment", | ||
| "config", | ||
| "dot", | ||
| "automatic", | ||
| "automatically", | ||
| "configure", | ||
| "parent", | ||
| "directory", | ||
| "search", | ||
| "monorepo" | ||
| ], | ||
| "types": "./find.d.ts" | ||
| } |
| # Load Dot ENV | ||
| Automatically find the closest `.env` file in any parent directory of the [cwd], and then load those environment variables into [`process.env`](https://nodejs.org/docs/latest/api/process.html#process_process_env). | ||
| ## Why? | ||
| By default the `dotenv` package only looks in the [current working directory][cwd] of the Node.js process for a `.env` file. And if you use the [path] option, that path must be identical both when running locally and when running in production. | ||
| Monorepos are a common example when it may be convenient to have a `.env` file that is not in your cwd. `load-dotenv` allows you to have a single `.env` file used by every package, regardless of file structure. | ||
| `load-dotenv` provides a simple interface to load your environment variables, only requiring you to add a single `import` statement. That avoids the hassle of wanting to load your environment vars before any other code runs, but also having to place all the `import`s at the top of your file before any other code. | ||
| [cwd]: https://nodejs.org/api/process.html#processcwd | ||
| [path]: https://github.com/motdotla/dotenv#path | ||
| ## Install | ||
| Make sure you also install `dotenv`, which is a peer dependency of this package. | ||
| ```bash | ||
| npm i dotenv load-dotenv # With npm | ||
| pnpm i dotenv load-dotenv # With pnpm | ||
| yarn add dotenv load-dotenv # With yarn | ||
| ``` | ||
| ## Find and load the closest .env file | ||
| As early as possible in your application, import `load-dotenv/load`: | ||
| ```js | ||
| import 'load-dotenv/load' | ||
| ``` | ||
| Or in Common JS: | ||
| ```js | ||
| require('load-dotenv/load') | ||
| ``` | ||
| > This will by default throw an error if it can't find a `.env` file in any parent directory. To not throw an error, import `load-dotenv/load/optional` instead. | ||
| ## Or load it yourself | ||
| ```js | ||
| import {findEnv} from 'load-dotenv' | ||
| import * as dotenv from 'dotenv' | ||
| const envFilePath = findEnv() | ||
| dotenv.config({path: envFilePath}) | ||
| ``` | ||
| Or in Common JS: | ||
| ```js | ||
| const {findEnv} = require('load-dotenv') | ||
| const dotEnv = require('dotenv') | ||
| const envFilePath = findEnv() | ||
| dotEnv.config({path: envFilePath}) | ||
| ``` | ||
| Or with a custom name: | ||
| ```js | ||
| const envFilePath = findEnv('.env.local') | ||
| dotenv.config({path: envFilePath}) | ||
| ``` |
| import {findUpSync} from 'find-up' | ||
| export function findEnv(fileName = '') { | ||
| return findUpSync(fileName || process.env.ENV_FILE || '.env') | ||
| } |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
2
-33.33%15695
-17.6%9
-25%117
-3.31%