1 | /// <reference types="node" />
|
2 | /**
|
3 | * `DetectorFilesystem` is an abstract class that represents a virtual filesystem
|
4 | * to perform read-only operations on in order to detect which framework is being
|
5 | * used.
|
6 | *
|
7 | * Its abstract methods must be implemented by a subclass that perform the actual
|
8 | * FS operations. Example subclasses could be implemented as:
|
9 | *
|
10 | * - Local filesystem, which proxies the FS operations to the equivalent `fs`
|
11 | * module functions.
|
12 | * - HTTP filesystem, which implements the FS operations over an HTTP server
|
13 | * and does not require a local copy of the files.
|
14 | * - `Files` filesystem, which operates on a virtual `Files` object (i.e. from
|
15 | * the `glob()` function) which could include `FileFsRef`, `FileBlob`, etc.
|
16 | *
|
17 | * This base class implements various helper functions for common tasks (i.e.
|
18 | * read and parse a JSON file). It also includes caching for all FS operations
|
19 | * so that multiple detector functions de-dup read operations on the same file
|
20 | * to reduce network/filesystem overhead.
|
21 | *
|
22 | * **NOTE:** It's important that all instance methods in this base class are
|
23 | * bound to `this` so that the `fs` object may be destructured in the detector
|
24 | * functions. The easiest way to do this is to use the `=` syntax when defining
|
25 | * methods in this class definition.
|
26 | */
|
27 | export declare abstract class DetectorFilesystem {
|
28 | protected abstract _hasPath(name: string): Promise<boolean>;
|
29 | protected abstract _readFile(name: string): Promise<Buffer>;
|
30 | protected abstract _isFile(name: string): Promise<boolean>;
|
31 | private pathCache;
|
32 | private fileCache;
|
33 | private readFileCache;
|
34 | constructor();
|
35 | hasPath: (path: string) => Promise<boolean>;
|
36 | isFile: (name: string) => Promise<boolean>;
|
37 | readFile: (name: string) => Promise<Buffer>;
|
38 | }
|