Skip to content

Commit d1d2362

Browse files
docs(api): document export method (#86)
1 parent 81645b4 commit d1d2362

File tree

2 files changed

+98
-2
lines changed

2 files changed

+98
-2
lines changed

docs/api.md

Lines changed: 94 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,37 @@ Spawns a process with additional arguments.
310310

311311
Spawns a process without additional arguments.
312312

313+
### `export`
314+
315+
Added in version `1.4.0`.
316+
317+
Exports the filesystem.
318+
319+
<h4 id="wc-export-signature">
320+
<a id="wc-export-signature">Signature</a>
321+
<a href="#wc-export-signature" class="header-anchor" aria-hidden="true">#</a>
322+
</h4>
323+
324+
<code>export(path: string, options?: <a href="#exportoptions">ExportOptions</a>): Promise<Uint8Array | <a href="#filesystemtree">FileSystemTree</a>></code>
325+
326+
<h4 id="wc-export-example">
327+
<a id="wc-export-example">Example</a>
328+
<a href="#wc-export-example" class="header-anchor" aria-hidden="true">#</a>
329+
</h4>
330+
331+
```js
332+
const data = await webcontainerInstance.export('dist', { format: 'zip' });
333+
334+
const zip = new Blob([data]);
335+
```
336+
337+
<h4 id="wc-export-returns">
338+
<a id="wc-export-returns">Returns</a>
339+
<a href="#wc-spawn-returns" class="header-anchor" aria-hidden="true">#</a>
340+
</h4>
341+
342+
Returns a [`FileSystemTree`](#filesystemtree) when the format is `json`, otherwise a `Uint8Array`.
343+
313344
### `teardown`
314345

315346
Destroys the WebContainer instance, turning it unusable, and releases its resources. After this, a new WebContainer instance can be obtained by calling [`boot`](#▸-boot).
@@ -895,11 +926,11 @@ A tree-like structure to describe the contents of a folder to be mounted.
895926

896927
```ts
897928
interface FileSystemTree {
898-
[name: string]: FileNode | DirectoryNode;
929+
[name: string]: FileNode | SymlinkNode | DirectoryNode;
899930
}
900931
```
901932

902-
Also see [`FileNode`](#filenode) and [`DirectoryNode`](#directorynode).
933+
Also see [`FileNode`](#filenode), [`SymlinkNode`](#symlinknode), and [`DirectoryNode`](#directorynode).
903934

904935
<h4 id="filesystemtree-example">
905936
<a id="filesystemtree-example">Example</a>
@@ -915,6 +946,11 @@ const tree = {
915946
contents: 'const x = 1;',
916947
},
917948
},
949+
'bar.js': {
950+
file: {
951+
symlink: './foo.js',
952+
},
953+
},
918954
'.envrc': {
919955
file: {
920956
contents: 'ENVIRONMENT=staging'
@@ -950,6 +986,26 @@ Represents a file with contents. Also see [`FileSystemTree`](#filesystemtree).
950986

951987
---
952988

989+
## `SymlinkNode`
990+
991+
```ts
992+
interface SymlinkNode {
993+
file: {
994+
symlink: string;
995+
};
996+
}
997+
```
998+
999+
### `SymlinkNode` Properties
1000+
1001+
<br />
1002+
1003+
#### `file: { symlink: string }`
1004+
1005+
Represents a symlink pointing to another location. Also see [`FileSystemTree`](#filesystemtree).
1006+
1007+
---
1008+
9531009
## `DirectoryNode`
9541010

9551011
```ts
@@ -1011,6 +1067,42 @@ The size of the attached terminal.
10111067

10121068
---
10131069

1070+
## `ExportOptions`
1071+
1072+
Options that control exporting data.
1073+
1074+
```ts
1075+
export interface ExportOptions {
1076+
format?: 'json' | 'binary' | 'zip',
1077+
includes?: string[];
1078+
excludes?: string[];
1079+
}
1080+
```
1081+
1082+
### `ExportOptions` Properties
1083+
1084+
<br />
1085+
1086+
#### `format?: 'json' | 'binary' | 'zip'`
1087+
1088+
The format of the exported data. The `json` and `binary` format can be used as `tree` when calling [`mount`](#▸-mount).
1089+
1090+
The default value is `json`.
1091+
1092+
<br />
1093+
1094+
#### `includes?: string[]`
1095+
1096+
Globbing patterns to include files from within excluded folders.
1097+
1098+
<br />
1099+
1100+
#### `excludes?: string[]`
1101+
1102+
Globbing patterns to exclude files from the export.
1103+
1104+
---
1105+
10141106
## `WebContainerProcess`
10151107

10161108
A running process spawned in a [WebContainer](#webcontainer) instance.

docs/changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ head:
1010

1111
# Changelog
1212

13+
## 1.4.0
14+
15+
* Add support for exporting the file system with [`export`](api#▸-export).
16+
1317
## 1.3.0
1418

1519
* Breaking change: we now throw if [`auth.init`](api#▸-init) is called after [`WebContainer.boot`](api#▸-boot)

0 commit comments

Comments
 (0)