@expo/env
Advanced tools
Comparing version 0.0.3 to 0.0.4
@@ -1,17 +0,13 @@ | ||
/** | ||
* Copyright © 2023 650 Industries. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
/// <reference types="node" /> | ||
type LoadOptions = { | ||
silent?: boolean; | ||
force?: boolean; | ||
}; | ||
export declare function isEnabled(): boolean; | ||
export declare function createControlledEnvironment(): { | ||
load: (projectRoot: string, { force }?: { | ||
force?: boolean | undefined; | ||
}) => NodeJS.ProcessEnv; | ||
get: (projectRoot: string, { force }?: { | ||
force?: boolean | undefined; | ||
}) => Record<string, string | undefined>; | ||
_getForce: (projectRoot: string) => Record<string, string | undefined>; | ||
load: (projectRoot: string, options?: LoadOptions) => NodeJS.ProcessEnv; | ||
get: (projectRoot: string, options?: LoadOptions) => Record<string, string | undefined>; | ||
_getForce: (projectRoot: string, options?: LoadOptions) => Record<string, string | undefined>; | ||
}; | ||
export declare function getFiles(mode: string | undefined): string[]; | ||
export declare function getFiles(mode: string | undefined, { silent }?: Pick<LoadOptions, 'silent'>): string[]; | ||
export {}; |
@@ -8,2 +8,3 @@ "use strict"; | ||
exports.getFiles = getFiles; | ||
exports.isEnabled = isEnabled; | ||
function _chalk() { | ||
@@ -37,2 +38,9 @@ const data = _interopRequireDefault(require("chalk")); | ||
} | ||
function _getenv() { | ||
const data = require("getenv"); | ||
_getenv = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function path() { | ||
@@ -56,2 +64,5 @@ const data = _interopRequireWildcard(require("path")); | ||
const debug = require('debug')('expo:env'); | ||
function isEnabled() { | ||
return !(0, _getenv().boolish)('EXPO_NO_DOTENV', false); | ||
} | ||
function createControlledEnvironment() { | ||
@@ -61,3 +72,7 @@ const IS_DEBUG = require('debug').enabled('expo:env'); | ||
let memoEnvironment = undefined; | ||
function _getForce(projectRoot) { | ||
function _getForce(projectRoot, options = {}) { | ||
if (!isEnabled()) { | ||
debug(`Skipping .env files because EXPO_NO_DOTENV is defined`); | ||
return {}; | ||
} | ||
if (!userDefinedEnvironment) { | ||
@@ -70,3 +85,3 @@ userDefinedEnvironment = { | ||
// https://github.com/bkeepers/dotenv#what-other-env-files-can-i-use | ||
const dotenvFiles = getFiles(process.env.NODE_ENV); | ||
const dotenvFiles = getFiles(process.env.NODE_ENV, options); | ||
const loadedEnvFiles = []; | ||
@@ -122,9 +137,11 @@ const parsed = {}; | ||
/** Get the environment variables without mutating the environment. This returns memoized values unless the `force` property is provided. */ | ||
function get(projectRoot, { | ||
force | ||
} = {}) { | ||
if (!force && memoEnvironment) { | ||
function get(projectRoot, options = {}) { | ||
if (!isEnabled()) { | ||
debug(`Skipping .env files because EXPO_NO_DOTENV is defined`); | ||
return {}; | ||
} | ||
if (!options.force && memoEnvironment) { | ||
return memoEnvironment; | ||
} | ||
memoEnvironment = _getForce(projectRoot); | ||
memoEnvironment = _getForce(projectRoot, options); | ||
return memoEnvironment; | ||
@@ -134,8 +151,8 @@ } | ||
/** Load environment variables from .env files and mutate the current `process.env` with the results. */ | ||
function load(projectRoot, { | ||
force | ||
} = {}) { | ||
const env = get(projectRoot, { | ||
force | ||
}); | ||
function load(projectRoot, options = {}) { | ||
if (!isEnabled()) { | ||
debug(`Skipping .env files because EXPO_NO_DOTENV is defined`); | ||
return process.env; | ||
} | ||
const env = get(projectRoot, options); | ||
process.env = { | ||
@@ -153,6 +170,16 @@ ...process.env, | ||
} | ||
function getFiles(mode) { | ||
function getFiles(mode, { | ||
silent = false | ||
} = {}) { | ||
if (!isEnabled()) { | ||
debug(`Skipping .env files because EXPO_NO_DOTENV is defined`); | ||
return []; | ||
} | ||
if (!mode) { | ||
console.error(_chalk().default.red('The NODE_ENV environment variable is required but was not specified. Ensure the project is bundled with Expo CLI or NODE_ENV is set.')); | ||
console.error(_chalk().default.red('Proceeding without mode-specific .env')); | ||
if (silent) { | ||
debug('NODE_ENV is not defined, proceeding without mode-specific .env'); | ||
} else { | ||
console.error(_chalk().default.red('The NODE_ENV environment variable is required but was not specified. Ensure the project is bundled with Expo CLI or NODE_ENV is set.')); | ||
console.error(_chalk().default.red('Proceeding without mode-specific .env')); | ||
} | ||
} | ||
@@ -159,0 +186,0 @@ if (mode && !['development', 'test', 'production'].includes(mode)) { |
@@ -8,8 +8,10 @@ /// <reference types="node" /> | ||
*/ | ||
import { getFiles } from './env'; | ||
declare const get: (projectRoot: string, { force }?: { | ||
import { getFiles, isEnabled } from './env'; | ||
declare const get: (projectRoot: string, options?: { | ||
silent?: boolean | undefined; | ||
force?: boolean | undefined; | ||
}) => Record<string, string | undefined>, load: (projectRoot: string, { force }?: { | ||
}) => Record<string, string | undefined>, load: (projectRoot: string, options?: { | ||
silent?: boolean | undefined; | ||
force?: boolean | undefined; | ||
}) => NodeJS.ProcessEnv; | ||
export { getFiles, get, load }; | ||
export { getFiles, get, load, isEnabled }; |
@@ -13,2 +13,8 @@ "use strict"; | ||
}); | ||
Object.defineProperty(exports, "isEnabled", { | ||
enumerable: true, | ||
get: function () { | ||
return _env().isEnabled; | ||
} | ||
}); | ||
exports.load = void 0; | ||
@@ -15,0 +21,0 @@ function _env() { |
{ | ||
"name": "@expo/env", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "hydrate environment variables from .env files into process.env", | ||
@@ -32,6 +32,8 @@ "main": "build/index.js", | ||
"chalk": "^4.0.0", | ||
"debug": "^4.3.4" | ||
"debug": "^4.3.4", | ||
"getenv": "^1.0.0" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "^7.15.5" | ||
"@babel/core": "^7.15.5", | ||
"@types/getenv": "^1.0.0" | ||
}, | ||
@@ -41,3 +43,3 @@ "publishConfig": { | ||
}, | ||
"gitHead": "4ba50c428c8369bb6b3a51a860d4898ad4ccbe78" | ||
"gitHead": "dce1880a2dc156f551847c78ac8bb4d2420e7ff3" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
24561
255
5
2
7
+ Addedgetenv@^1.0.0
+ Addedgetenv@1.0.0(transitive)