@vivari/react 0.0.1 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +471 -0
- package/dist/Vivari.d.ts +58 -0
- package/dist/Vivari.d.ts.map +1 -0
- package/dist/VivariPreview.d.ts +27 -0
- package/dist/VivariPreview.d.ts.map +1 -0
- package/dist/context.d.ts +28 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +814 -0
- package/dist/useSpawn.d.ts +46 -0
- package/dist/useSpawn.d.ts.map +1 -0
- package/dist/useVivari.d.ts +64 -0
- package/dist/useVivari.d.ts.map +1 -0
- package/dist/useVivariDir.d.ts +30 -0
- package/dist/useVivariDir.d.ts.map +1 -0
- package/dist/useVivariFile.d.ts +29 -0
- package/dist/useVivariFile.d.ts.map +1 -0
- package/package.json +55 -7
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { SpawnOptions, Vivari as VivariInstance, VivariProcess } from "@vivari/core";
|
|
2
|
+
export type SpawnStatus = "idle" | "running" | "exited" | "error";
|
|
3
|
+
export interface UseSpawnOptions extends SpawnOptions {
|
|
4
|
+
/** Run once as soon as an instance is ready, instead of waiting for `run()`. */
|
|
5
|
+
auto?: boolean;
|
|
6
|
+
/**
|
|
7
|
+
* Accumulate output into `output`. Off by default, deliberately: `npm install`
|
|
8
|
+
* emits thousands of chunks and a re-render per chunk is a perf disaster. Use
|
|
9
|
+
* `onOutput` (zero re-renders) to feed a terminal; turn this on for a `<pre>`.
|
|
10
|
+
*/
|
|
11
|
+
collect?: boolean;
|
|
12
|
+
/** Every stdout/stderr chunk, as it arrives. The fast path — no re-render. */
|
|
13
|
+
onOutput?: (chunk: string) => void;
|
|
14
|
+
onExit?: (code: number) => void;
|
|
15
|
+
onError?: (error: Error) => void;
|
|
16
|
+
/** Act on this instance instead of the nearest `<VivariProvider>`'s. */
|
|
17
|
+
vivari?: VivariInstance | null;
|
|
18
|
+
}
|
|
19
|
+
export interface UseSpawnResult {
|
|
20
|
+
status: SpawnStatus;
|
|
21
|
+
/** Accumulated output — always `""` unless you passed `collect: true`. */
|
|
22
|
+
output: string;
|
|
23
|
+
exitCode: number | null;
|
|
24
|
+
error: Error | null;
|
|
25
|
+
/** The live process while running, for anything this hook doesn't cover. */
|
|
26
|
+
process: VivariProcess | null;
|
|
27
|
+
/** Start (or restart) the command. Resolves with the exit code. */
|
|
28
|
+
run: (overrides?: {
|
|
29
|
+
command?: string;
|
|
30
|
+
args?: string[];
|
|
31
|
+
options?: SpawnOptions;
|
|
32
|
+
}) => Promise<number | null>;
|
|
33
|
+
/** Terminate the process. Its `exit` still resolves, so `status` reaches "exited". */
|
|
34
|
+
kill: () => void;
|
|
35
|
+
/** Write to the process's stdin. No-op when nothing is running. */
|
|
36
|
+
write: (chunk: string) => void;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Spawn `command` in the VM.
|
|
40
|
+
*
|
|
41
|
+
* `command`/`args` are read when a run starts, so an inline array is fine and
|
|
42
|
+
* changing them does not restart anything — call `run()` for that. Any running
|
|
43
|
+
* process is killed on unmount, which is the leak `<Vivari>` used to have.
|
|
44
|
+
*/
|
|
45
|
+
export declare function useSpawn(command: string, args?: string[], options?: UseSpawnOptions): UseSpawnResult;
|
|
46
|
+
//# sourceMappingURL=useSpawn.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSpawn.d.ts","sourceRoot":"","sources":["../src/useSpawn.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,IAAI,cAAc,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAG1F,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,SAAS,GAAG,QAAQ,GAAG,OAAO,CAAC;AAElE,MAAM,WAAW,eAAgB,SAAQ,YAAY;IACnD,gFAAgF;IAChF,IAAI,CAAC,EAAE,OAAO,CAAC;IACf;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,8EAA8E;IAC9E,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAChC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACjC,wEAAwE;IACxE,MAAM,CAAC,EAAE,cAAc,GAAG,IAAI,CAAC;CAChC;AAED,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,WAAW,CAAC;IACpB,0EAA0E;IAC1E,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB,4EAA4E;IAC5E,OAAO,EAAE,aAAa,GAAG,IAAI,CAAC;IAC9B,mEAAmE;IACnE,GAAG,EAAE,CAAC,SAAS,CAAC,EAAE;QAChB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;QAChB,OAAO,CAAC,EAAE,YAAY,CAAC;KACxB,KAAK,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAC7B,sFAAsF;IACtF,IAAI,EAAE,MAAM,IAAI,CAAC;IACjB,mEAAmE;IACnE,KAAK,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CAChC;AAID;;;;;;GAMG;AACH,wBAAgB,QAAQ,CACtB,OAAO,EAAE,MAAM,EACf,IAAI,GAAE,MAAM,EAAY,EACxB,OAAO,GAAE,eAAoB,GAC5B,cAAc,CAoLhB"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { Vivari, type BootOptions } from "@vivari/core";
|
|
2
|
+
/**
|
|
3
|
+
* Why Vivari cannot run here at all. Distinct from `error` on purpose: an
|
|
4
|
+
* `error` might clear on retry, an `unsupported` page needs a server-config fix
|
|
5
|
+
* the consumer has to make, so an embedder should render the header recipe
|
|
6
|
+
* instead of a generic "something went wrong".
|
|
7
|
+
*/
|
|
8
|
+
export type VivariUnsupportedReason = "not-cross-origin-isolated" | "no-web-workers";
|
|
9
|
+
/** The boot lifecycle as a discriminated union — `status` narrows `vivari`. */
|
|
10
|
+
export type VivariState = {
|
|
11
|
+
status: "idle";
|
|
12
|
+
vivari: null;
|
|
13
|
+
error: null;
|
|
14
|
+
} | {
|
|
15
|
+
status: "booting";
|
|
16
|
+
vivari: null;
|
|
17
|
+
error: null;
|
|
18
|
+
} | {
|
|
19
|
+
status: "ready";
|
|
20
|
+
vivari: Vivari;
|
|
21
|
+
error: null;
|
|
22
|
+
} | {
|
|
23
|
+
status: "error";
|
|
24
|
+
vivari: null;
|
|
25
|
+
error: Error;
|
|
26
|
+
} | {
|
|
27
|
+
status: "unsupported";
|
|
28
|
+
vivari: null;
|
|
29
|
+
error: Error;
|
|
30
|
+
reason: VivariUnsupportedReason;
|
|
31
|
+
};
|
|
32
|
+
export type VivariStatus = VivariState["status"];
|
|
33
|
+
export type UseVivariResult = VivariState & {
|
|
34
|
+
/** The registry key this result is bound to. */
|
|
35
|
+
instanceKey: string;
|
|
36
|
+
/** Start booting. No-op while already booting or ready. */
|
|
37
|
+
boot: () => void;
|
|
38
|
+
/** Tear the instance down and boot a fresh one with the latest options. */
|
|
39
|
+
restart: () => void;
|
|
40
|
+
};
|
|
41
|
+
export interface UseVivariOptions extends BootOptions {
|
|
42
|
+
/**
|
|
43
|
+
* Instances are shared and ref-counted per key. Two components with the same
|
|
44
|
+
* key share one kernel; a second key boots a second kernel (rarely what you
|
|
45
|
+
* want — each one costs a full worker tree). Default `"default"`.
|
|
46
|
+
*/
|
|
47
|
+
instanceKey?: string;
|
|
48
|
+
/**
|
|
49
|
+
* Boot on mount (default). Pass `false` to defer until you call `boot()` —
|
|
50
|
+
* use it for a playground below the fold, so a visitor who never scrolls
|
|
51
|
+
* never pays for a kernel.
|
|
52
|
+
*/
|
|
53
|
+
autoBoot?: boolean;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Boot (or join) a Vivari instance for the lifetime of the component.
|
|
57
|
+
*
|
|
58
|
+
* The instance is shared and ref-counted per `instanceKey`, so StrictMode's
|
|
59
|
+
* double-mount, an `<Activity>` toggle and sibling components all reuse one
|
|
60
|
+
* kernel. Boot options are read when the boot actually starts; later changes
|
|
61
|
+
* apply on the next `restart()`.
|
|
62
|
+
*/
|
|
63
|
+
export declare function useVivari(options?: UseVivariOptions): UseVivariResult;
|
|
64
|
+
//# sourceMappingURL=useVivari.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useVivari.d.ts","sourceRoot":"","sources":["../src/useVivari.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,MAAM,EAAyB,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAE/E;;;;;GAKG;AACH,MAAM,MAAM,uBAAuB,GAAG,2BAA2B,GAAG,gBAAgB,CAAC;AAErF,+EAA+E;AAC/E,MAAM,MAAM,WAAW,GACnB;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,IAAI,CAAA;CAAE,GAC7C;IAAE,MAAM,EAAE,SAAS,CAAC;IAAC,MAAM,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,IAAI,CAAA;CAAE,GAChD;IAAE,MAAM,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,IAAI,CAAA;CAAE,GAChD;IAAE,MAAM,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,KAAK,CAAA;CAAE,GAC/C;IAAE,MAAM,EAAE,aAAa,CAAC;IAAC,MAAM,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,uBAAuB,CAAA;CAAE,CAAC;AAE3F,MAAM,MAAM,YAAY,GAAG,WAAW,CAAC,QAAQ,CAAC,CAAC;AAEjD,MAAM,MAAM,eAAe,GAAG,WAAW,GAAG;IAC1C,gDAAgD;IAChD,WAAW,EAAE,MAAM,CAAC;IACpB,2DAA2D;IAC3D,IAAI,EAAE,MAAM,IAAI,CAAC;IACjB,2EAA2E;IAC3E,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB,CAAC;AAEF,MAAM,WAAW,gBAAiB,SAAQ,WAAW;IACnD;;;;OAIG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAsGD;;;;;;;GAOG;AACH,wBAAgB,SAAS,CAAC,OAAO,GAAE,gBAAqB,GAAG,eAAe,CAqEzE"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { DirEnt, Vivari as VivariInstance } from "@vivari/core";
|
|
2
|
+
export type VivariDirStatus = "idle" | "loading" | "ready" | "error";
|
|
3
|
+
export interface UseVivariDirOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Coalesce filesystem events before re-reading, in ms. Core reports every
|
|
6
|
+
* change with no coalescing — a single `npm install` fires thousands — so this
|
|
7
|
+
* is what keeps an install from re-rendering the tree thousands of times.
|
|
8
|
+
*/
|
|
9
|
+
debounce?: number;
|
|
10
|
+
/** Act on this instance instead of the nearest `<VivariProvider>`'s. */
|
|
11
|
+
vivari?: VivariInstance | null;
|
|
12
|
+
onError?: (error: Error) => void;
|
|
13
|
+
}
|
|
14
|
+
export interface UseVivariDirResult {
|
|
15
|
+
entries: DirEnt[];
|
|
16
|
+
status: VivariDirStatus;
|
|
17
|
+
error: Error | null;
|
|
18
|
+
/** Re-read now, ignoring the debounce. */
|
|
19
|
+
refresh: () => Promise<void>;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* List `path`, and keep the listing current as the VFS changes underneath it.
|
|
23
|
+
*
|
|
24
|
+
* const { entries, status } = useVivariDir("/src");
|
|
25
|
+
*
|
|
26
|
+
* The watch is non-recursive: only entries appearing, disappearing or changing
|
|
27
|
+
* directly inside `path` can alter this listing, so a deep write doesn't wake it.
|
|
28
|
+
*/
|
|
29
|
+
export declare function useVivariDir(path: string, options?: UseVivariDirOptions): UseVivariDirResult;
|
|
30
|
+
//# sourceMappingURL=useVivariDir.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useVivariDir.d.ts","sourceRoot":"","sources":["../src/useVivariDir.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,IAAI,cAAc,EAAE,MAAM,cAAc,CAAC;AAGrE,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,SAAS,GAAG,OAAO,GAAG,OAAO,CAAC;AAErE,MAAM,WAAW,mBAAmB;IAClC;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,wEAAwE;IACxE,MAAM,CAAC,EAAE,cAAc,GAAG,IAAI,CAAC;IAC/B,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CAClC;AAED,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,MAAM,EAAE,eAAe,CAAC;IACxB,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB,0CAA0C;IAC1C,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9B;AAID;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAC1B,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,mBAAwB,GAChC,kBAAkB,CA+EpB"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Vivari as VivariInstance } from "@vivari/core";
|
|
2
|
+
export type VivariFileStatus = "idle" | "loading" | "saving" | "saved" | "error";
|
|
3
|
+
export interface UseVivariFileOptions {
|
|
4
|
+
/** Write-behind delay in ms. `0` writes on every change. Default `250`. */
|
|
5
|
+
debounce?: number;
|
|
6
|
+
/** Written to the VFS when the file doesn't exist yet. */
|
|
7
|
+
initialContents?: string;
|
|
8
|
+
/** Act on this instance instead of the nearest `<VivariProvider>`'s. */
|
|
9
|
+
vivari?: VivariInstance | null;
|
|
10
|
+
onError?: (error: Error) => void;
|
|
11
|
+
}
|
|
12
|
+
export interface UseVivariFileHandle {
|
|
13
|
+
status: VivariFileStatus;
|
|
14
|
+
error: Error | null;
|
|
15
|
+
/** Write now, cancelling any pending debounced write — the Cmd+S path. */
|
|
16
|
+
save: () => Promise<void>;
|
|
17
|
+
/** Re-read from the VFS, discarding unsaved local edits. */
|
|
18
|
+
reload: () => Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Read/write a UTF-8 file as React state.
|
|
22
|
+
*
|
|
23
|
+
* const [source, setSource, { status, save }] = useVivariFile("/src/App.jsx");
|
|
24
|
+
*
|
|
25
|
+
* Text only, on purpose: binary content isn't editable as a React value, so read
|
|
26
|
+
* it with `vivari.fs.readFile(path)` (no encoding) instead.
|
|
27
|
+
*/
|
|
28
|
+
export declare function useVivariFile(path: string, options?: UseVivariFileOptions): [string, (next: string) => void, UseVivariFileHandle];
|
|
29
|
+
//# sourceMappingURL=useVivariFile.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useVivariFile.d.ts","sourceRoot":"","sources":["../src/useVivariFile.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,MAAM,IAAI,cAAc,EAAE,MAAM,cAAc,CAAC;AAG7D,MAAM,MAAM,gBAAgB,GAAG,MAAM,GAAG,SAAS,GAAG,QAAQ,GAAG,OAAO,GAAG,OAAO,CAAC;AAEjF,MAAM,WAAW,oBAAoB;IACnC,2EAA2E;IAC3E,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,0DAA0D;IAC1D,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,wEAAwE;IACxE,MAAM,CAAC,EAAE,cAAc,GAAG,IAAI,CAAC;IAC/B,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CAClC;AAED,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,gBAAgB,CAAC;IACzB,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB,0EAA0E;IAC1E,IAAI,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1B,4DAA4D;IAC5D,MAAM,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC7B;AAED;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAC3B,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,oBAAyB,GACjC,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,EAAE,mBAAmB,CAAC,CA0IvD"}
|
package/package.json
CHANGED
|
@@ -1,12 +1,60 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vivari/react",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "",
|
|
5
|
-
"
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "React bindings for Vivari. Run Node, Bun and Python projects fully client-side in the browser, embedded in your React app.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"webcontainer",
|
|
7
|
+
"vivari",
|
|
8
|
+
"react",
|
|
9
|
+
"browser",
|
|
10
|
+
"nodejs",
|
|
11
|
+
"bun",
|
|
12
|
+
"python",
|
|
13
|
+
"sandbox"
|
|
14
|
+
],
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"author": "Duc Trung Mai <maitrungduc1410@gmail.com>",
|
|
17
|
+
"homepage": "https://vivari.run",
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git+https://github.com/maitrungduc1410/vivari.git",
|
|
21
|
+
"directory": "packages/react"
|
|
22
|
+
},
|
|
23
|
+
"bugs": {
|
|
24
|
+
"url": "https://github.com/maitrungduc1410/vivari/issues"
|
|
25
|
+
},
|
|
26
|
+
"type": "module",
|
|
27
|
+
"sideEffects": false,
|
|
28
|
+
"files": [
|
|
29
|
+
"dist",
|
|
30
|
+
"README.md"
|
|
31
|
+
],
|
|
32
|
+
"main": "./dist/index.js",
|
|
33
|
+
"module": "./dist/index.js",
|
|
34
|
+
"types": "./dist/index.d.ts",
|
|
35
|
+
"exports": {
|
|
36
|
+
".": {
|
|
37
|
+
"types": "./dist/index.d.ts",
|
|
38
|
+
"default": "./dist/index.js"
|
|
39
|
+
},
|
|
40
|
+
"./package.json": "./package.json"
|
|
41
|
+
},
|
|
6
42
|
"scripts": {
|
|
7
|
-
"
|
|
43
|
+
"build": "vite build && tsc -p tsconfig.build.json",
|
|
44
|
+
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
45
|
+
},
|
|
46
|
+
"peerDependencies": {
|
|
47
|
+
"@vivari/core": "^1.0.1",
|
|
48
|
+
"react": "^18.0.0 || ^19.0.0"
|
|
49
|
+
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"@types/react": "^19.2.18",
|
|
52
|
+
"@vivari/core": "^1.0.1",
|
|
53
|
+
"react": "^19.2.8",
|
|
54
|
+
"typescript": "~6.0.2",
|
|
55
|
+
"vite": "^8.2.0"
|
|
8
56
|
},
|
|
9
|
-
"
|
|
10
|
-
|
|
11
|
-
|
|
57
|
+
"publishConfig": {
|
|
58
|
+
"access": "public"
|
|
59
|
+
}
|
|
12
60
|
}
|