import * as Z from '@effect/io/Effect'; import { pipe } from '@fp-ts/data/Function'; import { makeAppRuntime, makeDataFunction, RemixEffectAppRuntime, } from 'remix-effect'; import { AppLayer, appLayerLive } from './layer'; let runtime: Promise>; declare global { var __runtime: Promise> | undefined; } function make() { const runtime = Z.unsafeRunPromise(makeAppRuntime(appLayerLive)); process.on('beforeExit', () => Z.unsafeRunPromise( pipe( Z.promise(() => runtime), Z.flatMap(_ => _.clean), ), ), ); return runtime; } if (process.env.NODE_ENV === 'production') { runtime = make(); } else { if (!global.__runtime) { global.__runtime = make(); } runtime = global.__runtime; } const run = makeDataFunction(runtime); export { run };