-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
53 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
const _envShim = Object.create(null); | ||
|
||
const _getEnv = (useShim?: boolean) => | ||
globalThis.__env__ || | ||
globalThis.process?.env || | ||
(useShim ? _envShim : globalThis); | ||
|
||
export const env = new Proxy(_envShim, { | ||
get(_, prop) { | ||
const env = _getEnv(); | ||
return env[prop as any] ?? _envShim[prop]; | ||
}, | ||
has(_, prop) { | ||
const env = _getEnv(); | ||
return prop in env || prop in _envShim; | ||
}, | ||
set(_, prop, value) { | ||
const env = _getEnv(true); | ||
env[prop as any] = value; | ||
return true; | ||
}, | ||
deleteProperty(_, prop) { | ||
if (!prop) { | ||
return false; | ||
} | ||
const env = _getEnv(true); | ||
delete env[prop as any]; | ||
return true; | ||
}, | ||
ownKeys() { | ||
const env = _getEnv(); | ||
return Object.keys(env); | ||
}, | ||
}); | ||
|
||
export const nodeENV = | ||
(typeof process !== "undefined" && process.env && process.env.NODE_ENV) || | ||
env.NODE_ENV || | ||
""; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters