Comments (6)
Haven't tried, but something like this should work:
diff --git a/src/internal/configProvider.ts b/src/internal/configProvider.ts
index 44af3ae58..6de804e54 100644
--- a/src/internal/configProvider.ts
+++ b/src/internal/configProvider.ts
@@ -95,6 +95,37 @@ export const fromFlat = (flat: ConfigProvider.ConfigProvider.Flat): ConfigProvid
flattened: flat
})
+interface Environment {
+ getVariable(name: string): string | undefined;
+ getAllVariables(): { [key: string]: string | undefined; }
+}
+
+interface DenoRuntime {
+ Deno: {
+ env: {
+ get(key: string): string | undefined;
+ toObject(): { [index: string]: string; };
+ }
+ }
+}
+
+const isDenoRuntime = (runtime: {}): runtime is DenoRuntime => 'Deno' in runtime
+
+const getEnvironment = (): Environment => {
+ const runtime = globalThis;
+ if (isDenoRuntime(runtime)) {
+ return {
+ getVariable: (name) => runtime.Deno.env.get(name),
+ getAllVariables: () => runtime.Deno.env.toObject(),
+ }
+ }
+
+ return {
+ getVariable: (name) => process.env[name],
+ getAllVariables: () => process.env,
+ }
+}
+
/** @internal */
export const fromEnv = (
config: Partial<ConfigProvider.ConfigProvider.FromEnvConfig> = {}
@@ -103,17 +134,14 @@ export const fromEnv = (
const makePathString = (path: ReadonlyArray<string>): string => pipe(path, RA.join(pathDelim))
const unmakePathString = (pathString: string): ReadonlyArray<string> => pathString.split(pathDelim)
- const getEnv = () =>
- typeof process !== "undefined" && "env" in process && typeof process.env === "object" ? process.env : {}
-
const load = <A>(
path: ReadonlyArray<string>,
primitive: Config.Config.Primitive<A>,
split = true
): Effect.Effect<never, ConfigError.ConfigError, ReadonlyArray<A>> => {
const pathString = makePathString(path)
- const current = getEnv()
- const valueOpt = pathString in current ? Option.some(current[pathString]!) : Option.none()
+ const current = getEnvironment()
+ const valueOpt = Option.fromNullable(current.getVariable(pathString)) // this is doing a different thing, but otherwise you have to grant access to all env in Deno
return pipe(
valueOpt,
core.mapError(() => configError.MissingData(path, `Expected ${pathString} to exist in the process context`)),
@@ -125,8 +153,8 @@ export const fromEnv = (
path: ReadonlyArray<string>
): Effect.Effect<never, ConfigError.ConfigError, HashSet.HashSet<string>> =>
core.sync(() => {
- const current = getEnv()
- const keys = Object.keys(current)
+ const current = getEnvironment()
+ const keys = Object.keys(current.getAllVariables())
const keyPaths = Array.from(keys).map((value) => unmakePathString(value.toUpperCase()))
const filteredKeyPaths = keyPaths.filter((keyPath) => {
for (let i = 0; i < path.length; i++) {
from effect.
I'm glad you are open to support Deno. I'll submit a PR then, just have to figure out some things. For example how to test the project with Deno.
from effect.
cc @fubhy who's proposing a multi-runtime test matrix
from effect.
How would supporting Deno look like?
from effect.
If you want to open a PR I'd be happy to review & merge
from effect.
I can add a PR for the test matrix later today.
from effect.
Related Issues (20)
- ReadonlyArray refinement tacid usage, odd behavior or limitation? HOT 1
- Code documentation doesn't reflect actual changes in the code ("provideContext" was renamed to "provide")
- CLI: `Options.repeated` causes CLI to hang in certain senarios HOT 4
- Schema: Allow non-async Effects to be used with `*Sync` combinators
- CLI: nesting args/options within objects causes stack overflow at `reconstructConfigTree`
- From Discord: Unexpected Logs from Test and AnotherTest
- Schema: default class field constructors HOT 6
- CLI: Enable prompt commands to be able to have `Options` and `Args` HOT 1
- Type error when using `S.literal` and `S.optional` with `default` HOT 2
- Add option to preserve excess properties from S.decode, S.parse
- Tree shaking question HOT 3
- Schema: expose `literals` and `fields` HOT 15
- From Discord: Adding a Service to an Existing Runtime
- Regression: Allow specifying empty object in Data.TaggedEnum HOT 5
- Persisted Cache for preheating on startup HOT 2
- ReadOnly Array flatMap stack overflow HOT 3
- When using SchemaTaggedError with Match, I got an Effect.Effect<unknow, unknown, unknown> HOT 3
- JSONSchema not working as expected with `S.optional` HOT 4
- From Discord: Bug with Rpc API: Suppressed Transport Level Errors HOT 1
- CLI: Transform JS object of CLI options to a string HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from effect.