|
1 | 1 | import { commands } from "@vitest/browser/context"; |
2 | 2 | import { |
| 3 | + type BufferEncoding, |
3 | 4 | type FileSystemTree, |
4 | 5 | WebContainer as WebContainerApi, |
5 | 6 | } from "@webcontainer/api"; |
@@ -50,6 +51,9 @@ export class WebContainer { |
50 | 51 | async teardown() { |
51 | 52 | await Promise.all(this._onExit.map((fn) => fn())); |
52 | 53 |
|
| 54 | + // @ts-ignore -- internal |
| 55 | + await this._instance._instance.teardown(); |
| 56 | + |
53 | 57 | this._instance.teardown(); |
54 | 58 | this._instancePromise = undefined; |
55 | 59 | } |
@@ -81,4 +85,28 @@ export class WebContainer { |
81 | 85 |
|
82 | 86 | return output.trim(); |
83 | 87 | } |
| 88 | + |
| 89 | + async readFile(path: string, encoding: BufferEncoding = "utf8") { |
| 90 | + return this._instance.fs.readFile(path, encoding); |
| 91 | + } |
| 92 | + |
| 93 | + async writeFile(path: string, data: string, encoding = "utf8") { |
| 94 | + return this._instance.fs.writeFile(path, data, { encoding }); |
| 95 | + } |
| 96 | + |
| 97 | + async rename(oldPath: string, newPath: string) { |
| 98 | + return this._instance.fs.rename(oldPath, newPath); |
| 99 | + } |
| 100 | + |
| 101 | + async mkdir(path: string) { |
| 102 | + return this._instance.fs.mkdir(path); |
| 103 | + } |
| 104 | + |
| 105 | + async readdir(path: string) { |
| 106 | + return this._instance.fs.readdir(path); |
| 107 | + } |
| 108 | + |
| 109 | + async rm(path: string) { |
| 110 | + return this._instance.fs.rm(path); |
| 111 | + } |
84 | 112 | } |
0 commit comments