| 18 | */ |
| 19 | @injectable() |
| 20 | export class FileSystem extends FileSystemBase implements IFileSystemNode { |
| 21 | private async globFiles(pat: string, options?: { cwd: string; dot?: boolean }): Promise<string[]> { |
| 22 | return glob(pat, options || {}); |
| 23 | } |
| 24 | |
| 25 | public createLocalWriteStream(path: string): fs.WriteStream { |
| 26 | return fs.createWriteStream(path); |
| 27 | } |
| 28 | |
| 29 | public async createTemporaryLocalFile( |
| 30 | options: string | { fileExtension: string; prefix: string } |
| 31 | ): Promise<TemporaryFile> { |
| 32 | const suffix = typeof options === 'string' ? options : options.fileExtension; |
| 33 | const prefix = options && typeof options === 'object' ? options.prefix : undefined; |
| 34 | const opts: tmp.FileOptions = { |
| 35 | postfix: suffix, |
| 36 | prefix |
| 37 | }; |
| 38 | return new Promise<TemporaryFile>((resolve, reject) => { |
| 39 | tmp.file(opts, (err, filename, _fd, cleanUp) => { |
| 40 | if (err) { |
| 41 | return reject(err); |
| 42 | } |
| 43 | resolve({ |
| 44 | filePath: filename, |
| 45 | dispose: cleanUp |
| 46 | }); |
| 47 | }); |
| 48 | }); |
| 49 | } |
| 50 | |
| 51 | public async searchLocal(globPattern: string, cwd?: string, dot?: boolean): Promise<string[]> { |
| 52 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 53 | let options: any; |
| 54 | if (cwd) { |
| 55 | options = { ...options, cwd }; |
| 56 | } |
| 57 | if (dot) { |
| 58 | options = { ...options, dot }; |
| 59 | } |
| 60 | |
| 61 | const found = await this.globFiles(globPattern, options); |
| 62 | return Array.isArray(found) ? found : []; |
| 63 | } |
| 64 | |
| 65 | async writeLocalFile(filename: string, text: string | Buffer): Promise<void> { |
| 66 | await fs.ensureDir(path.dirname(filename)); |
| 67 | return fs.writeFile(filename, text); |
| 68 | } |
| 69 | |
| 70 | override async readFile(uri: Uri): Promise<string> { |
| 71 | if (isLocalFile(uri)) { |
| 72 | const result = await fs.readFile(getFilePath(uri)); |
| 73 | const data = Buffer.from(result); |
| 74 | return data.toString(ENCODING); |
| 75 | } else { |
| 76 | return super.readFile(uri); |
| 77 | } |
nothing calls this directly
no outgoing calls
no test coverage detected