/** * Filesystem helpers for compiler hosts that read from disk: the CLI's, * zenadoc's and the test hosts. The compiler itself reads only through * `CompilerHost` and does not import this module. */ import { readFile, isDirectory, listDir } from 'zena:fs'; import { CompilerHost } from './library-loader.zena'; /** * `CompilerHost.listDir` on disk: the names of the entries in the * directory at `path`, or null when `path` is not a directory. */ export async function directoryNames(path: String): Future | null> { if (!(await isDirectory(path))) { return null; } let names = new Array(); for (let entry in await listDir(path)) { names.push(entry.name); } return names; } /** * A compiler host that reads every path directly from disk. * * It does not map standard library ids or synthesize WIT-backed * modules. It is for reading WIT roots with `readWitSource` and * passing to `synthesizeWitModule`. */ export class DiskHost implements CompilerHost { async readFile(path: String): Future { return await readFile(path); } async listDir(path: String): Future | null> { return await directoryNames(path); } }