@expo/env 0.4.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/index.d.ts +111 -15
- package/build/index.js +342 -26
- package/build/index.js.map +1 -1
- package/package.json +2 -2
- package/build/env.d.ts +0 -19
- package/build/env.js +0 -238
- package/build/env.js.map +0 -1
package/build/index.d.ts
CHANGED
|
@@ -1,19 +1,115 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
/** Determine if the `.env` files are enabled or not, through `EXPO_NO_DOTENV` */
|
|
3
|
+
export declare function isEnabled(): boolean;
|
|
4
|
+
/** All conventional modes that should not cause warnings */
|
|
5
|
+
export declare const KNOWN_MODES: string[];
|
|
6
|
+
/** The environment variable name to use when marking the environment as loaded */
|
|
7
|
+
export declare const LOADED_ENV_NAME = "__EXPO_ENV_LOADED";
|
|
2
8
|
/**
|
|
3
|
-
*
|
|
9
|
+
* Get a list of all `.env*` files based on the `NODE_ENV` mode.
|
|
10
|
+
* This returns a list of files, in order of highest priority to lowest priority.
|
|
4
11
|
*
|
|
5
|
-
*
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
})
|
|
13
|
-
|
|
12
|
+
* @see https://github.com/bkeepers/dotenv/tree/v3.1.4#customizing-rails
|
|
13
|
+
*/
|
|
14
|
+
export declare function getEnvFiles({ mode, silent, }?: {
|
|
15
|
+
/** The mode to use when creating the list of `.env*` files, defaults to `NODE_ENV` */
|
|
16
|
+
mode?: string;
|
|
17
|
+
/** If possible misconfiguration warnings should be logged, or only logged as debug log */
|
|
18
|
+
silent?: boolean;
|
|
19
|
+
}): string[];
|
|
20
|
+
/**
|
|
21
|
+
* Parse all environment variables using the list of `.env*` files, in order of higest priority to lowest priority.
|
|
22
|
+
* This does not check for collisions of existing system environment variables, or mutates the system environment variables.
|
|
23
|
+
*/
|
|
24
|
+
export declare function parseEnvFiles(envFiles: string[], { systemEnv, }?: {
|
|
25
|
+
/** The system environment to use when expanding environment variables, defaults to `process.env` */
|
|
26
|
+
systemEnv?: NodeJS.ProcessEnv;
|
|
27
|
+
}): {
|
|
28
|
+
env: Record<string, string>;
|
|
29
|
+
files: string[];
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Parse all environment variables using the list of `.env*` files, and mutate the system environment with these variables.
|
|
33
|
+
* This won't override existing environment variables defined in the system environment.
|
|
34
|
+
* Once the mutations are done, this will also set a propert `__EXPO_ENV=true` on the system env to avoid multiple mutations.
|
|
35
|
+
* This check can be disabled through `{ force: true }`.
|
|
36
|
+
*/
|
|
37
|
+
export declare function loadEnvFiles(envFiles: string[], { force, silent, systemEnv, }?: Parameters<typeof parseEnvFiles>[1] & {
|
|
38
|
+
/** If the environment variables should be applied to the system environment, regardless of previous mutations */
|
|
39
|
+
force?: boolean;
|
|
40
|
+
/** If possible misconfiguration warnings should be logged, or only logged as debug log */
|
|
41
|
+
silent?: boolean;
|
|
42
|
+
}): {
|
|
43
|
+
result: "skipped";
|
|
44
|
+
loaded: any;
|
|
45
|
+
} | {
|
|
46
|
+
loaded: string[];
|
|
47
|
+
env: Record<string, string>;
|
|
48
|
+
files: string[];
|
|
49
|
+
result: "loaded";
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Parse all environment variables using the detected list of `.env*` files from a project.
|
|
53
|
+
* This does not check for collisions of existing system environment variables, or mutates the system environment variables.
|
|
54
|
+
*/
|
|
55
|
+
export declare function parseProjectEnv(projectRoot: string, options?: Parameters<typeof getEnvFiles>[0] & Parameters<typeof parseEnvFiles>[1]): {
|
|
56
|
+
env: Record<string, string>;
|
|
57
|
+
files: string[];
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Parse all environment variables using the detected list of `.env*` files from a project.
|
|
61
|
+
* This won't override existing environment variables defined in the system environment.
|
|
62
|
+
* Once the mutations are done, this will also set a propert `__EXPO_ENV=true` on the system env to avoid multiple mutations.
|
|
63
|
+
* This check can be disabled through `{ force: true }`.
|
|
64
|
+
*/
|
|
65
|
+
export declare function loadProjectEnv(projectRoot: string, options?: Parameters<typeof getEnvFiles>[0] & Parameters<typeof loadEnvFiles>[1]): {
|
|
66
|
+
result: "skipped";
|
|
67
|
+
loaded: any;
|
|
68
|
+
} | {
|
|
69
|
+
loaded: string[];
|
|
70
|
+
env: Record<string, string>;
|
|
14
71
|
files: string[];
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
72
|
+
result: "loaded";
|
|
73
|
+
};
|
|
74
|
+
/** Log the loaded environment info from the loaded results */
|
|
75
|
+
export declare function logLoadedEnv(envInfo: ReturnType<typeof loadEnvFiles>, options?: Parameters<typeof loadEnvFiles>[1]): {
|
|
76
|
+
result: "skipped";
|
|
77
|
+
loaded: any;
|
|
78
|
+
} | {
|
|
79
|
+
loaded: string[];
|
|
80
|
+
env: Record<string, string>;
|
|
81
|
+
files: string[];
|
|
82
|
+
result: "loaded";
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* Get the environment variables without mutating the environment.
|
|
86
|
+
* This returns memoized values unless the `force` property is provided.
|
|
87
|
+
*
|
|
88
|
+
* @deprecated use {@link parseProjectEnv} instead
|
|
89
|
+
*/
|
|
90
|
+
export declare function get(projectRoot: string, { force, silent, }?: {
|
|
91
|
+
force?: boolean;
|
|
92
|
+
silent?: boolean;
|
|
93
|
+
}): {
|
|
94
|
+
env: Record<string, string>;
|
|
95
|
+
files: string[];
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* Load environment variables from .env files and mutate the current `process.env` with the results.
|
|
99
|
+
*
|
|
100
|
+
* @deprecated use {@link loadProjectEnv} instead
|
|
101
|
+
*/
|
|
102
|
+
export declare function load(projectRoot: string, options?: {
|
|
103
|
+
force?: boolean;
|
|
104
|
+
silent?: boolean;
|
|
105
|
+
}): NodeJS.ProcessEnv;
|
|
106
|
+
/**
|
|
107
|
+
* Get a list of all `.env*` files based on the `NODE_ENV` mode.
|
|
108
|
+
* This returns a list of files, in order of highest priority to lowest priority.
|
|
109
|
+
*
|
|
110
|
+
* @deprecated use {@link getEnvFiles} instead
|
|
111
|
+
* @see https://github.com/bkeepers/dotenv/tree/v3.1.4#customizing-rails
|
|
112
|
+
*/
|
|
113
|
+
export declare function getFiles(mode: string | undefined, { silent }?: {
|
|
114
|
+
silent?: boolean;
|
|
115
|
+
}): string[];
|
package/build/index.js
CHANGED
|
@@ -3,38 +3,354 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
6
|
+
exports.LOADED_ENV_NAME = exports.KNOWN_MODES = void 0;
|
|
7
|
+
exports.get = get;
|
|
8
|
+
exports.getEnvFiles = getEnvFiles;
|
|
9
|
+
exports.getFiles = getFiles;
|
|
10
|
+
exports.isEnabled = isEnabled;
|
|
11
|
+
exports.load = load;
|
|
12
|
+
exports.loadEnvFiles = loadEnvFiles;
|
|
13
|
+
exports.loadProjectEnv = loadProjectEnv;
|
|
14
|
+
exports.logLoadedEnv = logLoadedEnv;
|
|
15
|
+
exports.parseEnvFiles = parseEnvFiles;
|
|
16
|
+
exports.parseProjectEnv = parseProjectEnv;
|
|
17
|
+
function _chalk() {
|
|
18
|
+
const data = _interopRequireDefault(require("chalk"));
|
|
19
|
+
_chalk = function () {
|
|
20
|
+
return data;
|
|
21
|
+
};
|
|
22
|
+
return data;
|
|
23
|
+
}
|
|
24
|
+
function dotenv() {
|
|
25
|
+
const data = _interopRequireWildcard(require("dotenv"));
|
|
26
|
+
dotenv = function () {
|
|
27
|
+
return data;
|
|
28
|
+
};
|
|
29
|
+
return data;
|
|
30
|
+
}
|
|
31
|
+
function _dotenvExpand() {
|
|
32
|
+
const data = require("dotenv-expand");
|
|
33
|
+
_dotenvExpand = function () {
|
|
34
|
+
return data;
|
|
35
|
+
};
|
|
36
|
+
return data;
|
|
37
|
+
}
|
|
38
|
+
function _getenv() {
|
|
39
|
+
const data = require("getenv");
|
|
40
|
+
_getenv = function () {
|
|
41
|
+
return data;
|
|
42
|
+
};
|
|
43
|
+
return data;
|
|
44
|
+
}
|
|
45
|
+
function _nodeConsole() {
|
|
46
|
+
const data = _interopRequireDefault(require("node:console"));
|
|
47
|
+
_nodeConsole = function () {
|
|
48
|
+
return data;
|
|
49
|
+
};
|
|
50
|
+
return data;
|
|
51
|
+
}
|
|
52
|
+
function _nodeFs() {
|
|
53
|
+
const data = _interopRequireDefault(require("node:fs"));
|
|
54
|
+
_nodeFs = function () {
|
|
23
55
|
return data;
|
|
24
56
|
};
|
|
25
57
|
return data;
|
|
26
58
|
}
|
|
59
|
+
function _nodePath() {
|
|
60
|
+
const data = _interopRequireDefault(require("node:path"));
|
|
61
|
+
_nodePath = function () {
|
|
62
|
+
return data;
|
|
63
|
+
};
|
|
64
|
+
return data;
|
|
65
|
+
}
|
|
66
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
67
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
68
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
69
|
+
const debug = require('debug')('expo:env');
|
|
70
|
+
|
|
71
|
+
/** Determine if the `.env` files are enabled or not, through `EXPO_NO_DOTENV` */
|
|
72
|
+
function isEnabled() {
|
|
73
|
+
return !(0, _getenv().boolish)('EXPO_NO_DOTENV', false);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** All conventional modes that should not cause warnings */
|
|
77
|
+
const KNOWN_MODES = exports.KNOWN_MODES = ['development', 'test', 'production'];
|
|
78
|
+
|
|
79
|
+
/** The environment variable name to use when marking the environment as loaded */
|
|
80
|
+
const LOADED_ENV_NAME = exports.LOADED_ENV_NAME = '__EXPO_ENV_LOADED';
|
|
81
|
+
|
|
27
82
|
/**
|
|
28
|
-
*
|
|
83
|
+
* Get a list of all `.env*` files based on the `NODE_ENV` mode.
|
|
84
|
+
* This returns a list of files, in order of highest priority to lowest priority.
|
|
29
85
|
*
|
|
30
|
-
*
|
|
31
|
-
* LICENSE file in the root directory of this source tree.
|
|
86
|
+
* @see https://github.com/bkeepers/dotenv/tree/v3.1.4#customizing-rails
|
|
32
87
|
*/
|
|
88
|
+
function getEnvFiles({
|
|
89
|
+
mode = process.env.NODE_ENV,
|
|
90
|
+
silent
|
|
91
|
+
} = {}) {
|
|
92
|
+
if (!isEnabled()) {
|
|
93
|
+
debug(`Skipping .env files because EXPO_NO_DOTENV is defined`);
|
|
94
|
+
return [];
|
|
95
|
+
}
|
|
96
|
+
const logError = silent ? debug : _nodeConsole().default.error;
|
|
97
|
+
const logWarning = silent ? debug : _nodeConsole().default.warn;
|
|
98
|
+
if (!mode) {
|
|
99
|
+
logError(`The NODE_ENV environment variable is required but was not specified. Ensure the project is bundled with Expo CLI or NODE_ENV is set. Using only .env.local and .env`);
|
|
100
|
+
return ['.env.local', '.env'];
|
|
101
|
+
}
|
|
102
|
+
if (!KNOWN_MODES.includes(mode)) {
|
|
103
|
+
logWarning(`NODE_ENV="${mode}" is non-conventional and might cause development code to run in production. Use "development", "test", or "production" instead. Continuing with non-conventional mode`);
|
|
104
|
+
}
|
|
33
105
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
106
|
+
// see: https://github.com/bkeepers/dotenv/tree/v3.1.4#customizing-rails
|
|
107
|
+
return [`.env.${mode}.local`,
|
|
108
|
+
// Don't include `.env.local` for `test` environment
|
|
109
|
+
// since normally you expect tests to produce the same
|
|
110
|
+
// results for everyone
|
|
111
|
+
mode !== 'test' && `.env.local`, `.env.${mode}`, `.env`].filter(Boolean);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Parse all environment variables using the list of `.env*` files, in order of higest priority to lowest priority.
|
|
116
|
+
* This does not check for collisions of existing system environment variables, or mutates the system environment variables.
|
|
117
|
+
*/
|
|
118
|
+
function parseEnvFiles(envFiles, {
|
|
119
|
+
systemEnv = process.env
|
|
120
|
+
} = {}) {
|
|
121
|
+
if (!isEnabled()) {
|
|
122
|
+
debug(`Skipping .env files because EXPO_NO_DOTENV is defined`);
|
|
123
|
+
return {
|
|
124
|
+
env: {},
|
|
125
|
+
files: []
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// Load environment variables from .env* files. Suppress warnings using silent
|
|
130
|
+
// if this file is missing. Dotenv will only parse the environment variables,
|
|
131
|
+
// `@expo/env` will set the resulting variables to the current process.
|
|
132
|
+
// Variable expansion is supported in .env files, and executed as final step.
|
|
133
|
+
// https://github.com/motdotla/dotenv
|
|
134
|
+
// https://github.com/motdotla/dotenv-expand
|
|
135
|
+
const loadedEnvVars = {};
|
|
136
|
+
const loadedEnvFiles = [];
|
|
137
|
+
|
|
138
|
+
// Iterate over each dotenv file in lowest prio to highest prio order.
|
|
139
|
+
// This step won't write to the process.env, but will overwrite the parsed envs.
|
|
140
|
+
[...envFiles].reverse().forEach(envFile => {
|
|
141
|
+
try {
|
|
142
|
+
const envFileContent = _nodeFs().default.readFileSync(envFile, 'utf8');
|
|
143
|
+
const envFileParsed = dotenv().parse(envFileContent);
|
|
144
|
+
|
|
145
|
+
// If there are parsing issues, mark the file as not-parsed
|
|
146
|
+
if (!envFileParsed) {
|
|
147
|
+
return debug(`Failed to load environment variables from: ${envFile}%s`);
|
|
148
|
+
}
|
|
149
|
+
loadedEnvFiles.push(envFile);
|
|
150
|
+
debug(`Loaded environment variables from: ${envFile}`);
|
|
151
|
+
for (const key of Object.keys(envFileParsed)) {
|
|
152
|
+
if (typeof loadedEnvVars[key] !== 'undefined') {
|
|
153
|
+
debug(`"${key}" is already defined and overwritten by: ${envFile}`);
|
|
154
|
+
}
|
|
155
|
+
loadedEnvVars[key] = envFileParsed[key];
|
|
156
|
+
}
|
|
157
|
+
} catch (error) {
|
|
158
|
+
if ('code' in error && error.code === 'ENOENT') {
|
|
159
|
+
return debug(`${envFile} does not exist, skipping this env file`);
|
|
160
|
+
}
|
|
161
|
+
if ('code' in error && error.code === 'EISDIR') {
|
|
162
|
+
return debug(`${envFile} is a directory, skipping this env file`);
|
|
163
|
+
}
|
|
164
|
+
if ('code' in error && error.code === 'EACCES') {
|
|
165
|
+
return debug(`No permission to read ${envFile}, skipping this env file`);
|
|
166
|
+
}
|
|
167
|
+
throw error;
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
return {
|
|
171
|
+
env: expandEnvFromSystem(loadedEnvVars, systemEnv),
|
|
172
|
+
files: loadedEnvFiles.reverse()
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Parse all environment variables using the list of `.env*` files, and mutate the system environment with these variables.
|
|
178
|
+
* This won't override existing environment variables defined in the system environment.
|
|
179
|
+
* Once the mutations are done, this will also set a propert `__EXPO_ENV=true` on the system env to avoid multiple mutations.
|
|
180
|
+
* This check can be disabled through `{ force: true }`.
|
|
181
|
+
*/
|
|
182
|
+
function loadEnvFiles(envFiles, {
|
|
183
|
+
force,
|
|
184
|
+
silent = false,
|
|
185
|
+
systemEnv = process.env
|
|
186
|
+
} = {}) {
|
|
187
|
+
if (!force && systemEnv[LOADED_ENV_NAME]) {
|
|
188
|
+
return {
|
|
189
|
+
result: 'skipped',
|
|
190
|
+
loaded: JSON.parse(systemEnv[LOADED_ENV_NAME])
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
const parsed = parseEnvFiles(envFiles, {
|
|
194
|
+
systemEnv
|
|
195
|
+
});
|
|
196
|
+
const loadedEnvKeys = [];
|
|
197
|
+
for (const key in parsed.env) {
|
|
198
|
+
if (typeof systemEnv[key] !== 'undefined') {
|
|
199
|
+
debug(`"${key}" is already defined and IS NOT overwritten`);
|
|
200
|
+
} else {
|
|
201
|
+
systemEnv[key] = parsed.env[key];
|
|
202
|
+
loadedEnvKeys.push(key);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// Mark the environment as loaded
|
|
207
|
+
systemEnv[LOADED_ENV_NAME] = JSON.stringify(loadedEnvKeys);
|
|
208
|
+
return {
|
|
209
|
+
result: 'loaded',
|
|
210
|
+
...parsed,
|
|
211
|
+
loaded: loadedEnvKeys
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Expand the parsed environment variables using the existing system environment variables.
|
|
217
|
+
* This does not mutate the existing system environment variables, and only returns the expanded variables.
|
|
218
|
+
*/
|
|
219
|
+
function expandEnvFromSystem(parsedEnv, systemEnv = process.env) {
|
|
220
|
+
const expandedEnv = {};
|
|
221
|
+
|
|
222
|
+
// Pass a clone of the system environment variables to avoid mutating the original environment.
|
|
223
|
+
// When the expansion is done, we only store the environment variables that were initially parsed from `parsedEnv`.
|
|
224
|
+
const allExpandedEnv = (0, _dotenvExpand().expand)({
|
|
225
|
+
parsed: parsedEnv,
|
|
226
|
+
processEnv: {
|
|
227
|
+
...systemEnv
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
if (allExpandedEnv.error) {
|
|
231
|
+
_nodeConsole().default.error(`Failed to expand environment variables, using non-expanded environment variables: ${allExpandedEnv.error}`);
|
|
232
|
+
return parsedEnv;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// Only store the values that were initially parsed, from `parsedEnv`.
|
|
236
|
+
for (const key of Object.keys(parsedEnv)) {
|
|
237
|
+
if (allExpandedEnv.parsed?.[key]) {
|
|
238
|
+
expandedEnv[key] = allExpandedEnv.parsed[key];
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
return expandedEnv;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Parse all environment variables using the detected list of `.env*` files from a project.
|
|
246
|
+
* This does not check for collisions of existing system environment variables, or mutates the system environment variables.
|
|
247
|
+
*/
|
|
248
|
+
function parseProjectEnv(projectRoot, options) {
|
|
249
|
+
return parseEnvFiles(getEnvFiles(options).map(envFile => _nodePath().default.join(projectRoot, envFile)), options);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Parse all environment variables using the detected list of `.env*` files from a project.
|
|
254
|
+
* This won't override existing environment variables defined in the system environment.
|
|
255
|
+
* Once the mutations are done, this will also set a propert `__EXPO_ENV=true` on the system env to avoid multiple mutations.
|
|
256
|
+
* This check can be disabled through `{ force: true }`.
|
|
257
|
+
*/
|
|
258
|
+
function loadProjectEnv(projectRoot, options) {
|
|
259
|
+
return loadEnvFiles(getEnvFiles(options).map(envFile => _nodePath().default.join(projectRoot, envFile)), options);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/** Log the loaded environment info from the loaded results */
|
|
263
|
+
function logLoadedEnv(envInfo, options = {}) {
|
|
264
|
+
// Skip when running in force mode, or no environment variables are loaded
|
|
265
|
+
if (options.force || options.silent || !envInfo.loaded.length) return envInfo;
|
|
266
|
+
|
|
267
|
+
// Log the loaded environment files, when not skipped
|
|
268
|
+
if (envInfo.result === 'loaded') {
|
|
269
|
+
_nodeConsole().default.log(_chalk().default.gray('env: load', envInfo.files.map(file => _nodePath().default.basename(file)).join(' ')));
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// Log the loaded environment variables
|
|
273
|
+
_nodeConsole().default.log(_chalk().default.gray('env: export', envInfo.loaded.join(' ')));
|
|
274
|
+
return envInfo;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
// Legacy API - for backwards compatibility
|
|
278
|
+
|
|
279
|
+
let memo = null;
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* Get the environment variables without mutating the environment.
|
|
283
|
+
* This returns memoized values unless the `force` property is provided.
|
|
284
|
+
*
|
|
285
|
+
* @deprecated use {@link parseProjectEnv} instead
|
|
286
|
+
*/
|
|
287
|
+
function get(projectRoot, {
|
|
288
|
+
force,
|
|
289
|
+
silent
|
|
290
|
+
} = {}) {
|
|
291
|
+
if (!isEnabled()) {
|
|
292
|
+
debug(`Skipping .env files because EXPO_NO_DOTENV is defined`);
|
|
293
|
+
return {
|
|
294
|
+
env: {},
|
|
295
|
+
files: []
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
if (force || !memo) {
|
|
299
|
+
memo = parseProjectEnv(projectRoot, {
|
|
300
|
+
silent
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
return memo;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* Load environment variables from .env files and mutate the current `process.env` with the results.
|
|
308
|
+
*
|
|
309
|
+
* @deprecated use {@link loadProjectEnv} instead
|
|
310
|
+
*/
|
|
311
|
+
function load(projectRoot, options = {}) {
|
|
312
|
+
if (!isEnabled()) {
|
|
313
|
+
debug(`Skipping .env files because EXPO_NO_DOTENV is defined`);
|
|
314
|
+
return process.env;
|
|
315
|
+
}
|
|
316
|
+
const envInfo = get(projectRoot, options);
|
|
317
|
+
const loadedEnvKeys = [];
|
|
318
|
+
for (const key in envInfo.env) {
|
|
319
|
+
if (typeof process.env[key] !== 'undefined') {
|
|
320
|
+
debug(`"${key}" is already defined and IS NOT overwritten`);
|
|
321
|
+
} else {
|
|
322
|
+
// Avoid creating a new object, mutate it instead as this causes problems in Bun
|
|
323
|
+
process.env[key] = envInfo.env[key];
|
|
324
|
+
loadedEnvKeys.push(key);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
// Port the result of `get` to the newer result object
|
|
329
|
+
logLoadedEnv({
|
|
330
|
+
...envInfo,
|
|
331
|
+
result: 'loaded',
|
|
332
|
+
loaded: loadedEnvKeys
|
|
333
|
+
}, options);
|
|
334
|
+
return process.env;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* Get a list of all `.env*` files based on the `NODE_ENV` mode.
|
|
339
|
+
* This returns a list of files, in order of highest priority to lowest priority.
|
|
340
|
+
*
|
|
341
|
+
* @deprecated use {@link getEnvFiles} instead
|
|
342
|
+
* @see https://github.com/bkeepers/dotenv/tree/v3.1.4#customizing-rails
|
|
343
|
+
*/
|
|
344
|
+
function getFiles(mode, {
|
|
345
|
+
silent = false
|
|
346
|
+
} = {}) {
|
|
347
|
+
if (!isEnabled()) {
|
|
348
|
+
debug(`Skipping .env files because EXPO_NO_DOTENV is defined`);
|
|
349
|
+
return [];
|
|
350
|
+
}
|
|
351
|
+
return getEnvFiles({
|
|
352
|
+
mode,
|
|
353
|
+
silent
|
|
354
|
+
});
|
|
355
|
+
}
|
|
40
356
|
//# sourceMappingURL=index.js.map
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["_env","data","require","get","load","createControlledEnvironment","exports"],"sources":["../src/index.ts"],"sourcesContent":["/**\n * Copyright © 2023 650 Industries.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nimport { createControlledEnvironment, getFiles, isEnabled } from './env';\n\nconst { get, load } = createControlledEnvironment();\n\nexport { getFiles, get, load, isEnabled };\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAMA,SAAAA,KAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,IAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AANA;AACA;AACA;AACA;AACA;AACA;;AAGA,MAAM;EAAEE,GAAG;EAAEC;AAAK,CAAC,GAAG,IAAAC,kCAA2B,EAAC,CAAC;AAACC,OAAA,CAAAF,IAAA,GAAAA,IAAA;AAAAE,OAAA,CAAAH,GAAA,GAAAA,GAAA","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":["_chalk","data","_interopRequireDefault","require","dotenv","_interopRequireWildcard","_dotenvExpand","_getenv","_nodeConsole","_nodeFs","_nodePath","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","debug","isEnabled","boolish","KNOWN_MODES","exports","LOADED_ENV_NAME","getEnvFiles","mode","process","env","NODE_ENV","silent","logError","console","error","logWarning","warn","includes","filter","Boolean","parseEnvFiles","envFiles","systemEnv","files","loadedEnvVars","loadedEnvFiles","reverse","forEach","envFile","envFileContent","fs","readFileSync","envFileParsed","parse","push","key","keys","code","expandEnvFromSystem","loadEnvFiles","force","result","loaded","JSON","parsed","loadedEnvKeys","stringify","parsedEnv","expandedEnv","allExpandedEnv","dotenvExpand","processEnv","parseProjectEnv","projectRoot","options","map","path","join","loadProjectEnv","logLoadedEnv","envInfo","length","log","chalk","gray","file","basename","memo","load","getFiles"],"sources":["../src/index.ts"],"sourcesContent":["import chalk from 'chalk';\nimport * as dotenv from 'dotenv';\nimport { expand as dotenvExpand } from 'dotenv-expand';\nimport { boolish } from 'getenv';\nimport console from 'node:console';\nimport fs from 'node:fs';\nimport path from 'node:path';\n\nconst debug = require('debug')('expo:env') as typeof console.log;\n\n/** Determine if the `.env` files are enabled or not, through `EXPO_NO_DOTENV` */\nexport function isEnabled() {\n return !boolish('EXPO_NO_DOTENV', false);\n}\n\n/** All conventional modes that should not cause warnings */\nexport const KNOWN_MODES = ['development', 'test', 'production'];\n\n/** The environment variable name to use when marking the environment as loaded */\nexport const LOADED_ENV_NAME = '__EXPO_ENV_LOADED';\n\n/**\n * Get a list of all `.env*` files based on the `NODE_ENV` mode.\n * This returns a list of files, in order of highest priority to lowest priority.\n *\n * @see https://github.com/bkeepers/dotenv/tree/v3.1.4#customizing-rails\n */\nexport function getEnvFiles({\n mode = process.env.NODE_ENV,\n silent,\n}: {\n /** The mode to use when creating the list of `.env*` files, defaults to `NODE_ENV` */\n mode?: string;\n /** If possible misconfiguration warnings should be logged, or only logged as debug log */\n silent?: boolean;\n} = {}) {\n if (!isEnabled()) {\n debug(`Skipping .env files because EXPO_NO_DOTENV is defined`);\n return [];\n }\n\n const logError = silent ? debug : console.error;\n const logWarning = silent ? debug : console.warn;\n\n if (!mode) {\n logError(\n `The NODE_ENV environment variable is required but was not specified. Ensure the project is bundled with Expo CLI or NODE_ENV is set. Using only .env.local and .env`\n );\n return ['.env.local', '.env'];\n }\n\n if (!KNOWN_MODES.includes(mode)) {\n logWarning(\n `NODE_ENV=\"${mode}\" is non-conventional and might cause development code to run in production. Use \"development\", \"test\", or \"production\" instead. Continuing with non-conventional mode`\n );\n }\n\n // see: https://github.com/bkeepers/dotenv/tree/v3.1.4#customizing-rails\n return [\n `.env.${mode}.local`,\n // Don't include `.env.local` for `test` environment\n // since normally you expect tests to produce the same\n // results for everyone\n mode !== 'test' && `.env.local`,\n `.env.${mode}`,\n `.env`,\n ].filter(Boolean) as string[];\n}\n\n/**\n * Parse all environment variables using the list of `.env*` files, in order of higest priority to lowest priority.\n * This does not check for collisions of existing system environment variables, or mutates the system environment variables.\n */\nexport function parseEnvFiles(\n envFiles: string[],\n {\n systemEnv = process.env,\n }: {\n /** The system environment to use when expanding environment variables, defaults to `process.env` */\n systemEnv?: NodeJS.ProcessEnv;\n } = {}\n) {\n if (!isEnabled()) {\n debug(`Skipping .env files because EXPO_NO_DOTENV is defined`);\n return { env: {}, files: [] };\n }\n\n // Load environment variables from .env* files. Suppress warnings using silent\n // if this file is missing. Dotenv will only parse the environment variables,\n // `@expo/env` will set the resulting variables to the current process.\n // Variable expansion is supported in .env files, and executed as final step.\n // https://github.com/motdotla/dotenv\n // https://github.com/motdotla/dotenv-expand\n const loadedEnvVars: dotenv.DotenvParseOutput = {};\n const loadedEnvFiles: string[] = [];\n\n // Iterate over each dotenv file in lowest prio to highest prio order.\n // This step won't write to the process.env, but will overwrite the parsed envs.\n [...envFiles].reverse().forEach((envFile) => {\n try {\n const envFileContent = fs.readFileSync(envFile, 'utf8');\n const envFileParsed = dotenv.parse(envFileContent);\n\n // If there are parsing issues, mark the file as not-parsed\n if (!envFileParsed) {\n return debug(`Failed to load environment variables from: ${envFile}%s`);\n }\n\n loadedEnvFiles.push(envFile);\n debug(`Loaded environment variables from: ${envFile}`);\n\n for (const key of Object.keys(envFileParsed)) {\n if (typeof loadedEnvVars[key] !== 'undefined') {\n debug(`\"${key}\" is already defined and overwritten by: ${envFile}`);\n }\n\n loadedEnvVars[key] = envFileParsed[key];\n }\n } catch (error: any) {\n if ('code' in error && error.code === 'ENOENT') {\n return debug(`${envFile} does not exist, skipping this env file`);\n }\n if ('code' in error && error.code === 'EISDIR') {\n return debug(`${envFile} is a directory, skipping this env file`);\n }\n if ('code' in error && error.code === 'EACCES') {\n return debug(`No permission to read ${envFile}, skipping this env file`);\n }\n\n throw error;\n }\n });\n\n return {\n env: expandEnvFromSystem(loadedEnvVars, systemEnv),\n files: loadedEnvFiles.reverse(),\n };\n}\n\n/**\n * Parse all environment variables using the list of `.env*` files, and mutate the system environment with these variables.\n * This won't override existing environment variables defined in the system environment.\n * Once the mutations are done, this will also set a propert `__EXPO_ENV=true` on the system env to avoid multiple mutations.\n * This check can be disabled through `{ force: true }`.\n */\nexport function loadEnvFiles(\n envFiles: string[],\n {\n force,\n silent = false,\n systemEnv = process.env,\n }: Parameters<typeof parseEnvFiles>[1] & {\n /** If the environment variables should be applied to the system environment, regardless of previous mutations */\n force?: boolean;\n /** If possible misconfiguration warnings should be logged, or only logged as debug log */\n silent?: boolean;\n } = {}\n) {\n if (!force && systemEnv[LOADED_ENV_NAME]) {\n return { result: 'skipped' as const, loaded: JSON.parse(systemEnv[LOADED_ENV_NAME]) };\n }\n\n const parsed = parseEnvFiles(envFiles, { systemEnv });\n const loadedEnvKeys: string[] = [];\n\n for (const key in parsed.env) {\n if (typeof systemEnv[key] !== 'undefined') {\n debug(`\"${key}\" is already defined and IS NOT overwritten`);\n } else {\n systemEnv[key] = parsed.env[key];\n loadedEnvKeys.push(key);\n }\n }\n\n // Mark the environment as loaded\n systemEnv[LOADED_ENV_NAME] = JSON.stringify(loadedEnvKeys);\n\n return { result: 'loaded' as const, ...parsed, loaded: loadedEnvKeys };\n}\n\n/**\n * Expand the parsed environment variables using the existing system environment variables.\n * This does not mutate the existing system environment variables, and only returns the expanded variables.\n */\nfunction expandEnvFromSystem(\n parsedEnv: Record<string, string>,\n systemEnv: NodeJS.ProcessEnv = process.env\n) {\n const expandedEnv: Record<string, string> = {};\n\n // Pass a clone of the system environment variables to avoid mutating the original environment.\n // When the expansion is done, we only store the environment variables that were initially parsed from `parsedEnv`.\n const allExpandedEnv = dotenvExpand({\n parsed: parsedEnv,\n processEnv: { ...systemEnv } as Record<string, string>,\n });\n\n if (allExpandedEnv.error) {\n console.error(\n `Failed to expand environment variables, using non-expanded environment variables: ${allExpandedEnv.error}`\n );\n return parsedEnv;\n }\n\n // Only store the values that were initially parsed, from `parsedEnv`.\n for (const key of Object.keys(parsedEnv)) {\n if (allExpandedEnv.parsed?.[key]) {\n expandedEnv[key] = allExpandedEnv.parsed[key];\n }\n }\n\n return expandedEnv;\n}\n\n/**\n * Parse all environment variables using the detected list of `.env*` files from a project.\n * This does not check for collisions of existing system environment variables, or mutates the system environment variables.\n */\nexport function parseProjectEnv(\n projectRoot: string,\n options?: Parameters<typeof getEnvFiles>[0] & Parameters<typeof parseEnvFiles>[1]\n) {\n return parseEnvFiles(\n getEnvFiles(options).map((envFile) => path.join(projectRoot, envFile)),\n options\n );\n}\n\n/**\n * Parse all environment variables using the detected list of `.env*` files from a project.\n * This won't override existing environment variables defined in the system environment.\n * Once the mutations are done, this will also set a propert `__EXPO_ENV=true` on the system env to avoid multiple mutations.\n * This check can be disabled through `{ force: true }`.\n */\nexport function loadProjectEnv(\n projectRoot: string,\n options?: Parameters<typeof getEnvFiles>[0] & Parameters<typeof loadEnvFiles>[1]\n) {\n return loadEnvFiles(\n getEnvFiles(options).map((envFile) => path.join(projectRoot, envFile)),\n options\n );\n}\n\n/** Log the loaded environment info from the loaded results */\nexport function logLoadedEnv(\n envInfo: ReturnType<typeof loadEnvFiles>,\n options: Parameters<typeof loadEnvFiles>[1] = {}\n) {\n // Skip when running in force mode, or no environment variables are loaded\n if (options.force || options.silent || !envInfo.loaded.length) return envInfo;\n\n // Log the loaded environment files, when not skipped\n if (envInfo.result === 'loaded') {\n console.log(\n chalk.gray('env: load', envInfo.files.map((file) => path.basename(file)).join(' '))\n );\n }\n\n // Log the loaded environment variables\n console.log(chalk.gray('env: export', envInfo.loaded.join(' ')));\n\n return envInfo;\n}\n\n// Legacy API - for backwards compatibility\n\nlet memo: ReturnType<typeof parseEnvFiles> | null = null;\n\n/**\n * Get the environment variables without mutating the environment.\n * This returns memoized values unless the `force` property is provided.\n *\n * @deprecated use {@link parseProjectEnv} instead\n */\nexport function get(\n projectRoot: string,\n {\n force,\n silent,\n }: {\n force?: boolean;\n silent?: boolean;\n } = {}\n) {\n if (!isEnabled()) {\n debug(`Skipping .env files because EXPO_NO_DOTENV is defined`);\n return { env: {}, files: [] };\n }\n if (force || !memo) {\n memo = parseProjectEnv(projectRoot, { silent });\n }\n return memo;\n}\n\n/**\n * Load environment variables from .env files and mutate the current `process.env` with the results.\n *\n * @deprecated use {@link loadProjectEnv} instead\n */\nexport function load(\n projectRoot: string,\n options: {\n force?: boolean;\n silent?: boolean;\n } = {}\n) {\n if (!isEnabled()) {\n debug(`Skipping .env files because EXPO_NO_DOTENV is defined`);\n return process.env;\n }\n\n const envInfo = get(projectRoot, options);\n const loadedEnvKeys: string[] = [];\n\n for (const key in envInfo.env) {\n if (typeof process.env[key] !== 'undefined') {\n debug(`\"${key}\" is already defined and IS NOT overwritten`);\n } else {\n // Avoid creating a new object, mutate it instead as this causes problems in Bun\n process.env[key] = envInfo.env[key];\n loadedEnvKeys.push(key);\n }\n }\n\n // Port the result of `get` to the newer result object\n logLoadedEnv({ ...envInfo, result: 'loaded', loaded: loadedEnvKeys }, options);\n\n return process.env;\n}\n\n/**\n * Get a list of all `.env*` files based on the `NODE_ENV` mode.\n * This returns a list of files, in order of highest priority to lowest priority.\n *\n * @deprecated use {@link getEnvFiles} instead\n * @see https://github.com/bkeepers/dotenv/tree/v3.1.4#customizing-rails\n */\nexport function getFiles(mode: string | undefined, { silent = false }: { silent?: boolean } = {}) {\n if (!isEnabled()) {\n debug(`Skipping .env files because EXPO_NO_DOTENV is defined`);\n return [];\n }\n\n return getEnvFiles({ mode, silent });\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAAA,SAAAA,OAAA;EAAA,MAAAC,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAH,MAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAG,OAAA;EAAA,MAAAH,IAAA,GAAAI,uBAAA,CAAAF,OAAA;EAAAC,MAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAK,cAAA;EAAA,MAAAL,IAAA,GAAAE,OAAA;EAAAG,aAAA,YAAAA,CAAA;IAAA,OAAAL,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAM,QAAA;EAAA,MAAAN,IAAA,GAAAE,OAAA;EAAAI,OAAA,YAAAA,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;EAAc,CAAC,EAAES,OAAO,CAAC;EAE9E,OAAO9C,OAAO,CAACC,GAAG;AACpB;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS4D,QAAQA,CAAC9D,IAAwB,EAAE;EAAEI,MAAM,GAAG;AAA4B,CAAC,GAAG,CAAC,CAAC,EAAE;EAChG,IAAI,CAACV,SAAS,CAAC,CAAC,EAAE;IAChBD,KAAK,CAAC,uDAAuD,CAAC;IAC9D,OAAO,EAAE;EACX;EAEA,OAAOM,WAAW,CAAC;IAAEC,IAAI;IAAEI;EAAO,CAAC,CAAC;AACtC","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@expo/env",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "hydrate environment variables from .env files into process.env",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -41,5 +41,5 @@
|
|
|
41
41
|
"publishConfig": {
|
|
42
42
|
"access": "public"
|
|
43
43
|
},
|
|
44
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "6b8febdc8075b9ea31120f02aca11595c116dc1d"
|
|
45
45
|
}
|
package/build/env.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
type LoadOptions = {
|
|
3
|
-
silent?: boolean;
|
|
4
|
-
force?: boolean;
|
|
5
|
-
};
|
|
6
|
-
export declare function isEnabled(): boolean;
|
|
7
|
-
export declare function createControlledEnvironment(): {
|
|
8
|
-
load: (projectRoot: string, options?: LoadOptions) => NodeJS.ProcessEnv;
|
|
9
|
-
get: (projectRoot: string, options?: LoadOptions) => {
|
|
10
|
-
env: Record<string, string | undefined>;
|
|
11
|
-
files: string[];
|
|
12
|
-
};
|
|
13
|
-
_getForce: (projectRoot: string, options?: LoadOptions) => {
|
|
14
|
-
env: Record<string, string | undefined>;
|
|
15
|
-
files: string[];
|
|
16
|
-
};
|
|
17
|
-
};
|
|
18
|
-
export declare function getFiles(mode: string | undefined, { silent }?: Pick<LoadOptions, 'silent'>): string[];
|
|
19
|
-
export {};
|
package/build/env.js
DELETED
|
@@ -1,238 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.createControlledEnvironment = createControlledEnvironment;
|
|
7
|
-
exports.getFiles = getFiles;
|
|
8
|
-
exports.isEnabled = isEnabled;
|
|
9
|
-
function _chalk() {
|
|
10
|
-
const data = _interopRequireDefault(require("chalk"));
|
|
11
|
-
_chalk = function () {
|
|
12
|
-
return data;
|
|
13
|
-
};
|
|
14
|
-
return data;
|
|
15
|
-
}
|
|
16
|
-
function dotenv() {
|
|
17
|
-
const data = _interopRequireWildcard(require("dotenv"));
|
|
18
|
-
dotenv = function () {
|
|
19
|
-
return data;
|
|
20
|
-
};
|
|
21
|
-
return data;
|
|
22
|
-
}
|
|
23
|
-
function _dotenvExpand() {
|
|
24
|
-
const data = require("dotenv-expand");
|
|
25
|
-
_dotenvExpand = function () {
|
|
26
|
-
return data;
|
|
27
|
-
};
|
|
28
|
-
return data;
|
|
29
|
-
}
|
|
30
|
-
function fs() {
|
|
31
|
-
const data = _interopRequireWildcard(require("fs"));
|
|
32
|
-
fs = function () {
|
|
33
|
-
return data;
|
|
34
|
-
};
|
|
35
|
-
return data;
|
|
36
|
-
}
|
|
37
|
-
function _getenv() {
|
|
38
|
-
const data = require("getenv");
|
|
39
|
-
_getenv = function () {
|
|
40
|
-
return data;
|
|
41
|
-
};
|
|
42
|
-
return data;
|
|
43
|
-
}
|
|
44
|
-
function path() {
|
|
45
|
-
const data = _interopRequireWildcard(require("path"));
|
|
46
|
-
path = function () {
|
|
47
|
-
return data;
|
|
48
|
-
};
|
|
49
|
-
return data;
|
|
50
|
-
}
|
|
51
|
-
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
52
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
53
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
54
|
-
/**
|
|
55
|
-
* Copyright © 2023 650 Industries.
|
|
56
|
-
*
|
|
57
|
-
* This source code is licensed under the MIT license found in the
|
|
58
|
-
* LICENSE file in the root directory of this source tree.
|
|
59
|
-
*/
|
|
60
|
-
|
|
61
|
-
const debug = require('debug')('expo:env');
|
|
62
|
-
function isEnabled() {
|
|
63
|
-
return !(0, _getenv().boolish)('EXPO_NO_DOTENV', false);
|
|
64
|
-
}
|
|
65
|
-
function createControlledEnvironment() {
|
|
66
|
-
let userDefinedEnvironment = undefined;
|
|
67
|
-
let memo = undefined;
|
|
68
|
-
function _getForce(projectRoot, options = {}) {
|
|
69
|
-
if (!isEnabled()) {
|
|
70
|
-
debug(`Skipping .env files because EXPO_NO_DOTENV is defined`);
|
|
71
|
-
return {
|
|
72
|
-
env: {},
|
|
73
|
-
files: []
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
if (!userDefinedEnvironment) {
|
|
77
|
-
userDefinedEnvironment = {
|
|
78
|
-
...process.env
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// https://github.com/bkeepers/dotenv#what-other-env-files-can-i-use
|
|
83
|
-
const dotenvFiles = getFiles(process.env.NODE_ENV, options);
|
|
84
|
-
|
|
85
|
-
// Load environment variables from .env* files. Suppress warnings using silent
|
|
86
|
-
// if this file is missing. Dotenv will only parse the environment variables,
|
|
87
|
-
// `@expo/env` will set the resulting variables to the current process.
|
|
88
|
-
// Variable expansion is supported in .env files, and executed as final step.
|
|
89
|
-
// https://github.com/motdotla/dotenv
|
|
90
|
-
// https://github.com/motdotla/dotenv-expand
|
|
91
|
-
const parsedEnv = {};
|
|
92
|
-
const loadedEnvFiles = [];
|
|
93
|
-
|
|
94
|
-
// Iterate over each dotenv file in lowest prio to highest prio order.
|
|
95
|
-
// This step won't write to the process.env, but will overwrite the parsed envs.
|
|
96
|
-
dotenvFiles.reverse().forEach(dotenvFile => {
|
|
97
|
-
const absoluteDotenvFile = path().resolve(projectRoot, dotenvFile);
|
|
98
|
-
if (!fs().existsSync(absoluteDotenvFile)) {
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
try {
|
|
102
|
-
const result = dotenv().parse(fs().readFileSync(absoluteDotenvFile, 'utf-8'));
|
|
103
|
-
if (!result) {
|
|
104
|
-
debug(`Failed to load environment variables from: ${absoluteDotenvFile}%s`);
|
|
105
|
-
} else {
|
|
106
|
-
loadedEnvFiles.push(absoluteDotenvFile);
|
|
107
|
-
debug(`Loaded environment variables from: ${absoluteDotenvFile}`);
|
|
108
|
-
for (const key of Object.keys(result)) {
|
|
109
|
-
if (typeof userDefinedEnvironment?.[key] !== 'undefined') {
|
|
110
|
-
debug(`"${key}" is already defined and IS NOT overwritten by: ${absoluteDotenvFile}`);
|
|
111
|
-
} else {
|
|
112
|
-
if (typeof parsedEnv[key] !== 'undefined') {
|
|
113
|
-
debug(`"${key}" is already defined and overwritten by: ${absoluteDotenvFile}`);
|
|
114
|
-
}
|
|
115
|
-
parsedEnv[key] = result[key];
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
} catch (error) {
|
|
120
|
-
if (error instanceof Error) {
|
|
121
|
-
console.error(`Failed to load environment variables from ${absoluteDotenvFile}: ${error.message}`);
|
|
122
|
-
} else {
|
|
123
|
-
throw error;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
|
-
if (!loadedEnvFiles.length) {
|
|
128
|
-
debug(`No environment variables loaded from .env files.`);
|
|
129
|
-
}
|
|
130
|
-
return {
|
|
131
|
-
env: _expandEnv(parsedEnv),
|
|
132
|
-
files: loadedEnvFiles.reverse()
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
/** Expand environment variables based on the current and parsed envs */
|
|
137
|
-
function _expandEnv(parsedEnv) {
|
|
138
|
-
const expandedEnv = {};
|
|
139
|
-
|
|
140
|
-
// Pass a clone of `process.env` to avoid mutating the original environment.
|
|
141
|
-
// When the expansion is done, we only store the environment variables that were initially parsed from `parsedEnv`.
|
|
142
|
-
const allExpandedEnv = (0, _dotenvExpand().expand)({
|
|
143
|
-
parsed: parsedEnv,
|
|
144
|
-
processEnv: {
|
|
145
|
-
...process.env
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
if (allExpandedEnv.error) {
|
|
149
|
-
console.error(`Failed to expand environment variables, using non-expanded environment variables: ${allExpandedEnv.error}`);
|
|
150
|
-
return parsedEnv;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// Only store the values that were initially parsed, from `parsedEnv`.
|
|
154
|
-
for (const key of Object.keys(parsedEnv)) {
|
|
155
|
-
if (allExpandedEnv.parsed?.[key]) {
|
|
156
|
-
expandedEnv[key] = allExpandedEnv.parsed[key];
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
return expandedEnv;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
/** Get the environment variables without mutating the environment. This returns memoized values unless the `force` property is provided. */
|
|
163
|
-
function get(projectRoot, options = {}) {
|
|
164
|
-
if (!isEnabled()) {
|
|
165
|
-
debug(`Skipping .env files because EXPO_NO_DOTENV is defined`);
|
|
166
|
-
return {
|
|
167
|
-
env: {},
|
|
168
|
-
files: []
|
|
169
|
-
};
|
|
170
|
-
}
|
|
171
|
-
if (!options.force && memo) {
|
|
172
|
-
return memo;
|
|
173
|
-
}
|
|
174
|
-
memo = _getForce(projectRoot, options);
|
|
175
|
-
return memo;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
/** Load environment variables from .env files and mutate the current `process.env` with the results. */
|
|
179
|
-
function load(projectRoot, options = {}) {
|
|
180
|
-
if (!isEnabled()) {
|
|
181
|
-
debug(`Skipping .env files because EXPO_NO_DOTENV is defined`);
|
|
182
|
-
return process.env;
|
|
183
|
-
}
|
|
184
|
-
const envInfo = get(projectRoot, options);
|
|
185
|
-
if (!options.force) {
|
|
186
|
-
const keys = Object.keys(envInfo.env);
|
|
187
|
-
if (keys.length) {
|
|
188
|
-
console.log(_chalk().default.gray('env: load', envInfo.files.map(file => path().basename(file)).join(' ')));
|
|
189
|
-
console.log(_chalk().default.gray('env: export', keys.join(' ')));
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
for (const key of Object.keys(envInfo.env)) {
|
|
193
|
-
// Avoid creating a new object, mutate it instead as this causes problems in Bun
|
|
194
|
-
process.env[key] = envInfo.env[key];
|
|
195
|
-
}
|
|
196
|
-
return process.env;
|
|
197
|
-
}
|
|
198
|
-
return {
|
|
199
|
-
load,
|
|
200
|
-
get,
|
|
201
|
-
_getForce
|
|
202
|
-
};
|
|
203
|
-
}
|
|
204
|
-
function getFiles(mode, {
|
|
205
|
-
silent = false
|
|
206
|
-
} = {}) {
|
|
207
|
-
if (!isEnabled()) {
|
|
208
|
-
debug(`Skipping .env files because EXPO_NO_DOTENV is defined`);
|
|
209
|
-
return [];
|
|
210
|
-
}
|
|
211
|
-
if (!mode) {
|
|
212
|
-
if (silent) {
|
|
213
|
-
debug('NODE_ENV is not defined, proceeding without mode-specific .env');
|
|
214
|
-
} else {
|
|
215
|
-
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.'));
|
|
216
|
-
console.error(_chalk().default.red('Proceeding without mode-specific .env'));
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
if (mode && !['development', 'test', 'production'].includes(mode)) {
|
|
220
|
-
if (silent) {
|
|
221
|
-
debug(`NODE_ENV="${mode}" is non-conventional and might cause development code to run in production. Use "development", "test", or "production" instead.`);
|
|
222
|
-
} else {
|
|
223
|
-
console.warn(_chalk().default.yellow(`"NODE_ENV=${mode}" is non-conventional and might cause development code to run in production. Use "development", "test", or "production" instead`));
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
if (!mode) {
|
|
227
|
-
// Support environments that don't respect NODE_ENV
|
|
228
|
-
return [`.env.local`, '.env'];
|
|
229
|
-
}
|
|
230
|
-
// https://github.com/bkeepers/dotenv#what-other-env-files-can-i-use
|
|
231
|
-
const dotenvFiles = [`.env.${mode}.local`,
|
|
232
|
-
// Don't include `.env.local` for `test` environment
|
|
233
|
-
// since normally you expect tests to produce the same
|
|
234
|
-
// results for everyone
|
|
235
|
-
mode !== 'test' && `.env.local`, `.env.${mode}`, '.env'].filter(Boolean);
|
|
236
|
-
return dotenvFiles;
|
|
237
|
-
}
|
|
238
|
-
//# sourceMappingURL=env.js.map
|
package/build/env.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"env.js","names":["_chalk","data","_interopRequireDefault","require","dotenv","_interopRequireWildcard","_dotenvExpand","fs","_getenv","path","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","debug","isEnabled","boolish","createControlledEnvironment","userDefinedEnvironment","undefined","memo","_getForce","projectRoot","options","env","files","process","dotenvFiles","getFiles","NODE_ENV","parsedEnv","loadedEnvFiles","reverse","forEach","dotenvFile","absoluteDotenvFile","resolve","existsSync","result","parse","readFileSync","push","key","keys","error","Error","console","message","length","_expandEnv","expandedEnv","allExpandedEnv","dotenvExpand","parsed","processEnv","force","load","envInfo","log","chalk","gray","map","file","basename","join","mode","silent","red","includes","warn","yellow","filter","Boolean"],"sources":["../src/env.ts"],"sourcesContent":["/**\n * Copyright © 2023 650 Industries.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nimport chalk from 'chalk';\nimport * as dotenv from 'dotenv';\nimport { expand as dotenvExpand } from 'dotenv-expand';\nimport * as fs from 'fs';\nimport { boolish } from 'getenv';\nimport * as path from 'path';\n\ntype LoadOptions = {\n silent?: boolean;\n force?: boolean;\n};\n\nconst debug = require('debug')('expo:env') as typeof console.log;\n\nexport function isEnabled(): boolean {\n return !boolish('EXPO_NO_DOTENV', false);\n}\n\nexport function createControlledEnvironment() {\n let userDefinedEnvironment: NodeJS.ProcessEnv | undefined = undefined;\n let memo: { env: NodeJS.ProcessEnv; files: string[] } | undefined = undefined;\n\n function _getForce(\n projectRoot: string,\n options: LoadOptions = {}\n ): { env: Record<string, string | undefined>; files: string[] } {\n if (!isEnabled()) {\n debug(`Skipping .env files because EXPO_NO_DOTENV is defined`);\n return { env: {}, files: [] };\n }\n\n if (!userDefinedEnvironment) {\n userDefinedEnvironment = { ...process.env };\n }\n\n // https://github.com/bkeepers/dotenv#what-other-env-files-can-i-use\n const dotenvFiles = getFiles(process.env.NODE_ENV, options);\n\n // Load environment variables from .env* files. Suppress warnings using silent\n // if this file is missing. Dotenv will only parse the environment variables,\n // `@expo/env` will set the resulting variables to the current process.\n // Variable expansion is supported in .env files, and executed as final step.\n // https://github.com/motdotla/dotenv\n // https://github.com/motdotla/dotenv-expand\n const parsedEnv: dotenv.DotenvParseOutput = {};\n const loadedEnvFiles: string[] = [];\n\n // Iterate over each dotenv file in lowest prio to highest prio order.\n // This step won't write to the process.env, but will overwrite the parsed envs.\n dotenvFiles.reverse().forEach((dotenvFile) => {\n const absoluteDotenvFile = path.resolve(projectRoot, dotenvFile);\n if (!fs.existsSync(absoluteDotenvFile)) {\n return;\n }\n\n try {\n const result = dotenv.parse(fs.readFileSync(absoluteDotenvFile, 'utf-8'));\n\n if (!result) {\n debug(`Failed to load environment variables from: ${absoluteDotenvFile}%s`);\n } else {\n loadedEnvFiles.push(absoluteDotenvFile);\n debug(`Loaded environment variables from: ${absoluteDotenvFile}`);\n\n for (const key of Object.keys(result)) {\n if (typeof userDefinedEnvironment?.[key] !== 'undefined') {\n debug(`\"${key}\" is already defined and IS NOT overwritten by: ${absoluteDotenvFile}`);\n } else {\n if (typeof parsedEnv[key] !== 'undefined') {\n debug(`\"${key}\" is already defined and overwritten by: ${absoluteDotenvFile}`);\n }\n\n parsedEnv[key] = result[key];\n }\n }\n }\n } catch (error: unknown) {\n if (error instanceof Error) {\n console.error(\n `Failed to load environment variables from ${absoluteDotenvFile}: ${error.message}`\n );\n } else {\n throw error;\n }\n }\n });\n\n if (!loadedEnvFiles.length) {\n debug(`No environment variables loaded from .env files.`);\n }\n\n return { env: _expandEnv(parsedEnv), files: loadedEnvFiles.reverse() };\n }\n\n /** Expand environment variables based on the current and parsed envs */\n function _expandEnv(parsedEnv: Record<string, string>) {\n const expandedEnv: Record<string, string> = {};\n\n // Pass a clone of `process.env` to avoid mutating the original environment.\n // When the expansion is done, we only store the environment variables that were initially parsed from `parsedEnv`.\n const allExpandedEnv = dotenvExpand({\n parsed: parsedEnv,\n processEnv: { ...process.env } as Record<string, string>,\n });\n\n if (allExpandedEnv.error) {\n console.error(\n `Failed to expand environment variables, using non-expanded environment variables: ${allExpandedEnv.error}`\n );\n return parsedEnv;\n }\n\n // Only store the values that were initially parsed, from `parsedEnv`.\n for (const key of Object.keys(parsedEnv)) {\n if (allExpandedEnv.parsed?.[key]) {\n expandedEnv[key] = allExpandedEnv.parsed[key];\n }\n }\n\n return expandedEnv;\n }\n\n /** Get the environment variables without mutating the environment. This returns memoized values unless the `force` property is provided. */\n function get(\n projectRoot: string,\n options: LoadOptions = {}\n ): { env: Record<string, string | undefined>; files: string[] } {\n if (!isEnabled()) {\n debug(`Skipping .env files because EXPO_NO_DOTENV is defined`);\n return { env: {}, files: [] };\n }\n if (!options.force && memo) {\n return memo;\n }\n memo = _getForce(projectRoot, options);\n return memo;\n }\n\n /** Load environment variables from .env files and mutate the current `process.env` with the results. */\n function load(projectRoot: string, options: LoadOptions = {}) {\n if (!isEnabled()) {\n debug(`Skipping .env files because EXPO_NO_DOTENV is defined`);\n return process.env;\n }\n\n const envInfo = get(projectRoot, options);\n\n if (!options.force) {\n const keys = Object.keys(envInfo.env);\n if (keys.length) {\n console.log(\n chalk.gray('env: load', envInfo.files.map((file) => path.basename(file)).join(' '))\n );\n console.log(chalk.gray('env: export', keys.join(' ')));\n }\n }\n\n for (const key of Object.keys(envInfo.env)) {\n // Avoid creating a new object, mutate it instead as this causes problems in Bun\n process.env[key] = envInfo.env[key];\n }\n\n return process.env;\n }\n\n return {\n load,\n get,\n _getForce,\n };\n}\n\nexport function getFiles(\n mode: string | undefined,\n { silent = false }: Pick<LoadOptions, 'silent'> = {}\n): string[] {\n if (!isEnabled()) {\n debug(`Skipping .env files because EXPO_NO_DOTENV is defined`);\n return [];\n }\n\n if (!mode) {\n if (silent) {\n debug('NODE_ENV is not defined, proceeding without mode-specific .env');\n } else {\n console.error(\n chalk.red(\n 'The NODE_ENV environment variable is required but was not specified. Ensure the project is bundled with Expo CLI or NODE_ENV is set.'\n )\n );\n console.error(chalk.red('Proceeding without mode-specific .env'));\n }\n }\n\n if (mode && !['development', 'test', 'production'].includes(mode)) {\n if (silent) {\n debug(\n `NODE_ENV=\"${mode}\" is non-conventional and might cause development code to run in production. Use \"development\", \"test\", or \"production\" instead.`\n );\n } else {\n console.warn(\n chalk.yellow(\n `\"NODE_ENV=${mode}\" is non-conventional and might cause development code to run in production. Use \"development\", \"test\", or \"production\" instead`\n )\n );\n }\n }\n\n if (!mode) {\n // Support environments that don't respect NODE_ENV\n return [`.env.local`, '.env'];\n }\n // https://github.com/bkeepers/dotenv#what-other-env-files-can-i-use\n const dotenvFiles = [\n `.env.${mode}.local`,\n // Don't include `.env.local` for `test` environment\n // since normally you expect tests to produce the same\n // results for everyone\n mode !== 'test' && `.env.local`,\n `.env.${mode}`,\n '.env',\n ].filter(Boolean) as string[];\n\n return dotenvFiles;\n}\n"],"mappings":";;;;;;;;AAMA,SAAAA,OAAA;EAAA,MAAAC,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAH,MAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAG,OAAA;EAAA,MAAAH,IAAA,GAAAI,uBAAA,CAAAF,OAAA;EAAAC,MAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAK,cAAA;EAAA,MAAAL,IAAA,GAAAE,OAAA;EAAAG,aAAA,YAAAA,CAAA;IAAA,OAAAL,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAM,GAAA;EAAA,MAAAN,IAAA,GAAAI,uBAAA,CAAAF,OAAA;EAAAI,EAAA,YAAAA,CAAA;IAAA,OAAAN,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAO,QAAA;EAAA,MAAAP,IAAA,GAAAE,OAAA;EAAAK,OAAA,YAAAA,CAAA;IAAA,OAAAP,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAQ,KAAA;EAAA,MAAAR,IAAA,GAAAI,uBAAA,CAAAF,OAAA;EAAAM,IAAA,YAAAA,CAAA;IAAA,OAAAR,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAA6B,SAAAS,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAN,wBAAAM,CAAA,EAAAE,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