The best way to control Claude Code, Codex and more from any computer or phone

main
ts 18 lines 749 Bytes
Raw
1 import * as Effect from "effect/Effect";
2 import * as FileSystem from "effect/FileSystem";
3 import * as Path from "effect/Path";
4
5 /**
6 * Resolves a Vite Worker's `main` against the Vite root when it is a path
7 * or names a file there. Any other specifier (a package export, a virtual
8 * module) is handed to Vite unchanged, as `@cloudflare/vite-plugin` does.
9 */
10 export const resolveViteMain = Effect.fn(function* (root: string, main: string) {
11 const fs = yield* FileSystem.FileSystem;
12 const path = yield* Path.Path;
13 const resolved = path.resolve(root, main);
14 if (path.isAbsolute(main) || /^\.\.?[\\/]/.test(main)) {
15 return resolved;
16 }
17 return (yield* fs.exists(resolved).pipe(Effect.orElseSucceed(() => false))) ? resolved : main;
18 });