MCPcopy Index your code
hub / github.com/anomalyco/opencode / withEnv

Function withEnv

packages/core/test/plugin/provider-opencode.test.ts:47–66  ·  view source on GitHub ↗
(vars: Record<string, string | undefined>, effect: () => Effect.Effect<A, E, R>)

Source from the content-addressed store, hash-verified

45}
46
47function withEnv<A, E, R>(vars: Record<string, string | undefined>, effect: () => Effect.Effect<A, E, R>) {
48 return Effect.acquireUseRelease(
49 Effect.sync(() => {
50 const previous = Object.fromEntries(Object.keys(vars).map((key) => [key, process.env[key]]))
51 Object.entries(vars).forEach(([key, value]) => {
52 if (value === undefined) delete process.env[key]
53 else process.env[key] = value
54 })
55 return previous
56 }),
57 effect,
58 (previous) =>
59 Effect.sync(() =>
60 Object.entries(previous).forEach(([key, value]) => {
61 if (value === undefined) delete process.env[key]
62 else process.env[key] = value
63 }),
64 ),
65 )
66}
67
68const cost = (input: number, output = 0) => [{ input, output, cache: { read: 0, write: 0 } }]
69

Callers 1

Calls 1

syncMethod · 0.80

Tested by

no test coverage detected