fsUtils.d.ts 1.1 KB

12345678910111213141516171819202122
  1. /// <reference types="node" />
  2. import { Context } from '../server';
  3. import { Readable } from 'stream';
  4. import { HMRWatcher } from '../server/serverPluginHmr';
  5. /**
  6. * Read a file with in-memory cache.
  7. * Also sets appropriate headers and body on the Koa context.
  8. * This is exposed on middleware context as `ctx.read` with the `ctx` already
  9. * bound, so it can be used as `ctx.read(file)`.
  10. */
  11. export declare function cachedRead(ctx: Context | null, file: string): Promise<Buffer>;
  12. /**
  13. * Read already set body on a Koa context and normalize it into a string.
  14. * Useful in post-processing middlewares.
  15. */
  16. export declare function readBody(stream: Readable | Buffer | string | null): Promise<string | null>;
  17. export declare function lookupFile(dir: string, formats: string[], pathOnly?: boolean): string | undefined;
  18. /**
  19. * Files under root are watched by default, but with user aliases we can still
  20. * serve files out of root. Add such files to the watcher (if not node_modules)
  21. */
  22. export declare function watchFileIfOutOfRoot(watcher: HMRWatcher, root: string, file: string): void;