UNPKG

@now/build-utils

Version:
39 lines (38 loc) 1.8 kB
/// <reference types="node" /> /** * `DetectorFilesystem` is an abstract class that represents a virtual filesystem * to perform read-only operations on in order to detect which framework is being * used. * * Its abstract methods must be implemented by a subclass that perform the actual * FS operations. Example subclasses could be implemented as: * * - Local filesystem, which proxies the FS operations to the equivalent `fs` * module functions. * - HTTP filesystem, which implements the FS operations over an HTTP server * and does not require a local copy of the files. * - `Files` filesystem, which operates on a virtual `Files` object (i.e. from * the `glob()` function) which could include `FileFsRef`, `FileBlob`, etc. * * This base class implements various helper functions for common tasks (i.e. * read and parse a JSON file). It also includes caching for all FS operations * so that multiple detector functions de-dup read operations on the same file * to reduce network/filesystem overhead. * * **NOTE:** It's important that all instance methods in this base class are * bound to `this` so that the `fs` object may be destructured in the detector * functions. The easiest way to do this is to use the `=` syntax when defining * methods in this class definition. */ export declare abstract class DetectorFilesystem { protected abstract _hasPath(name: string): Promise<boolean>; protected abstract _readFile(name: string): Promise<Buffer>; protected abstract _isFile(name: string): Promise<boolean>; private pathCache; private fileCache; private readFileCache; constructor(); hasPath: (path: string) => Promise<boolean>; isFile: (name: string) => Promise<boolean>; readFile: (name: string) => Promise<Buffer>; }