| 35 | // Each directory holds the file `x.ts`. Listings report every entry as |
| 36 | // `"Unknown"`, so `glob` learns entry types from `stat` and `readLink`. |
| 37 | const makeFileSystem = (overrides: { |
| 38 | readonly directories?: Record<string, ReadonlyArray<string>> |
| 39 | readonly readDirectory?: (path: string) => Effect.Effect<Array<string>, PlatformError.PlatformError> | undefined |
| 40 | readonly stat?: (path: string) => Effect.Effect<FileSystem.File.Info, PlatformError.PlatformError> | undefined |
| 41 | readonly readLink?: (path: string) => Effect.Effect<string, PlatformError.PlatformError> |
| 42 | }) => { |
| 43 | const directories = overrides.directories ?? { ".": ["a"], "a": ["x.ts"] } |
| 44 | const readDirectory = (path: string) => |
| 45 | overrides.readDirectory?.(path) ?? |
| 46 | (path in directories |
| 47 | ? Effect.succeed([...directories[path]]) |
| 48 | : Effect.fail(failure("NotFound", "readDirectory", path))) |
| 49 | return FileSystem.make({ |
| 50 | ...FileSystem.makeNoop({}), |
| 51 | readDirectory, |
| 52 | readDirectoryEntries: (path) => |
| 53 | Effect.map(readDirectory(path), (names) => names.map((name) => ({ name, type: "Unknown" as const }))), |
| 54 | stat: (path) => |
| 55 | overrides.stat?.(path) ?? |
| 56 | (path in directories |
| 57 | ? Effect.succeed(info("Directory")) |
| 58 | : path.endsWith("/x.ts") && path.slice(0, -5) in directories |
| 59 | ? Effect.succeed(info("File")) |
| 60 | : Effect.fail(failure("NotFound", "stat", path))), |
| 61 | // Node and Deno report EINVAL as "Unknown" for a path that is not a link |
| 62 | readLink: overrides.readLink ?? ((path) => Effect.fail(failure("Unknown", "readLink", path))) |
| 63 | }) |
| 64 | } |
| 65 | |
| 66 | // `secret` and `src` are named by literal pattern segments below, and `open` |
| 67 | // is only reached through wildcards |