@@ -6,8 +6,13 @@ import {
66} from "@webcontainer/api" ;
77
88export class WebContainer {
9+ /** @internal */
910 private _instancePromise ?: WebContainerApi ;
11+
12+ /** @internal */
1013 private _isReady : Promise < void > ;
14+
15+ /** @internal */
1116 private _onExit : ( ( ) => Promise < unknown > ) [ ] = [ ] ;
1217
1318 constructor ( ) {
@@ -26,18 +31,20 @@ export class WebContainer {
2631 return this . _instancePromise ;
2732 }
2833
34+ /** @internal */
2935 async wait ( ) {
3036 await this . _isReady ;
3137 }
3238
39+ /** @internal */
3340 onServerReady ( callback : ( options : { port : number ; url : string } ) => void ) {
3441 this . _instance . on ( "server-ready" , ( port , url ) => {
3542 callback ( { port, url } ) ;
3643 } ) ;
3744 }
3845
3946 /**
40- * Mount file directory into webcontainer .
47+ * Mount file directory into WebContainer .
4148 * `string` arguments are considered paths that are relative to [`root`](https://vitest.dev/config/#root)
4249 */
4350 async mount ( filesOrPath : string | FileSystemTree ) {
@@ -48,6 +55,7 @@ export class WebContainer {
4855 return await this . _instance . mount ( filesOrPath as FileSystemTree ) ;
4956 }
5057
58+ /** @internal */
5159 async teardown ( ) {
5260 await Promise . all ( this . _onExit . map ( ( fn ) => fn ( ) ) ) ;
5361
@@ -58,6 +66,10 @@ export class WebContainer {
5866 this . _instancePromise = undefined ;
5967 }
6068
69+ /**
70+ * Run command inside WebContainer.
71+ * Returns the output of the command.
72+ */
6173 async runCommand ( command : string , args : string [ ] = [ ] ) {
6274 let output = "" ;
6375
@@ -86,26 +98,44 @@ export class WebContainer {
8698 return output . trim ( ) ;
8799 }
88100
101+ /**
102+ * WebContainer's [`readFile`](https://webcontainers.io/guides/working-with-the-file-system#readfile) method.
103+ */
89104 async readFile ( path : string , encoding : BufferEncoding = "utf8" ) {
90105 return this . _instance . fs . readFile ( path , encoding ) ;
91106 }
92107
108+ /**
109+ * WebContainer's [`writeFile`](https://webcontainers.io/guides/working-with-the-file-system#writefile) method.
110+ */
93111 async writeFile ( path : string , data : string , encoding = "utf8" ) {
94112 return this . _instance . fs . writeFile ( path , data , { encoding } ) ;
95113 }
96114
115+ /**
116+ * WebContainer's [`rename`](https://webcontainers.io/guides/working-with-the-file-system#rename) method.
117+ */
97118 async rename ( oldPath : string , newPath : string ) {
98119 return this . _instance . fs . rename ( oldPath , newPath ) ;
99120 }
100121
122+ /**
123+ * WebContainer's [`mkdir`](https://webcontainers.io/guides/working-with-the-file-system#mkdir) method.
124+ */
101125 async mkdir ( path : string ) {
102126 return this . _instance . fs . mkdir ( path ) ;
103127 }
104128
129+ /**
130+ * WebContainer's [`readdir`](https://webcontainers.io/guides/working-with-the-file-system#readdir) method.
131+ */
105132 async readdir ( path : string ) {
106133 return this . _instance . fs . readdir ( path ) ;
107134 }
108135
136+ /**
137+ * WebContainer's [`rm`](https://webcontainers.io/guides/working-with-the-file-system#rm) method.
138+ */
109139 async rm ( path : string ) {
110140 return this . _instance . fs . rm ( path ) ;
111141 }
0 commit comments