@run0/jiki 0.1.0 → 0.1.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/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ MIT License
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,37 @@
1
+ <div align="center">
2
+ <a href="https://jiki.sh">
3
+ <img src="../../apps/website/public/favicon.svg" alt="Jiki" width="120" />
4
+ </a>
5
+
6
+ <a href="https://jiki.sh"><img alt="jiki logo" src="https://img.shields.io/badge/MADE%20For%20the%20browser-000000.svg?style=for-the-badge"></a>
7
+ <a href="https://www.npmjs.com/package/@run0/jiki"><img alt="NPM version" src="https://img.shields.io/npm/v/@run0/jiki.svg?style=for-the-badge&labelColor=000000"></a>
8
+ <a href="https://github.com/run0/jiki/blob/main/LICENSE"><img alt="License" src="https://img.shields.io/npm/l/@run0/jiki.svg?style=for-the-badge&labelColor=000000"></a>
9
+ <a href="https://jiki.sh/docs"><img alt="jiki logo" src="https://img.shields.io/badge/docs-000000.svg?style=for-the-badge"></a>
10
+
11
+ </div>
12
+
13
+ ---
14
+
15
+ A sandboxed Node.js runtime that runs entirely client-side. Filesystem, shell, npm / pnpm, and dev servers. No backend required.
16
+
17
+ ## A few lines is all it takes
18
+
19
+ ```ts
20
+ import { boot } from "@run0/jiki";
21
+
22
+ const container = boot();
23
+ container.writeFile("/index.js", 'console.log("Hello from the browser!")');
24
+ await container.run("node index.js");
25
+ // → Hello from the browser!
26
+ ```
27
+
28
+ ## Learn more
29
+
30
+ - [Website](https://jiki.sh)
31
+ - [Documentation](https://jiki.sh/docs)
32
+ - [API Reference](http://localhost:4321/docs/api/boot)
33
+ - [Examples](./examples)
34
+
35
+ ## License
36
+
37
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@run0/jiki",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Lightweight browser-based Node.js runtime with virtual filesystem, npm support, and dev servers.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -33,6 +33,9 @@
33
33
  "src",
34
34
  "dist"
35
35
  ],
36
+ "publishConfig": {
37
+ "access": "public"
38
+ },
36
39
  "sideEffects": false,
37
40
  "dependencies": {
38
41
  "acorn": "^8.14.0",
@@ -7,7 +7,13 @@
7
7
  * in ServerBridge.initServiceWorker() (default: /__sw__.js).
8
8
  */
9
9
 
10
- declare const self: ServiceWorkerGlobalScope;
10
+ // Service Worker global — typed as `any` because TypeScript's standard libs
11
+ // don't include ServiceWorkerGlobalScope without a dedicated tsconfig.
12
+ const sw = self as unknown as {
13
+ skipWaiting(): Promise<void>;
14
+ clients: { claim(): Promise<void>; matchAll(): Promise<Client[]> };
15
+ addEventListener(type: string, listener: (event: any) => void): void;
16
+ };
11
17
 
12
18
  let mainPort: MessagePort | null = null;
13
19
  let requestId = 0;
@@ -29,15 +35,15 @@ function base64ToUint8(base64: string): Uint8Array {
29
35
  return bytes;
30
36
  }
31
37
 
32
- self.addEventListener("install", () => {
33
- (self as unknown as { skipWaiting(): Promise<void> }).skipWaiting();
38
+ sw.addEventListener("install", () => {
39
+ sw.skipWaiting();
34
40
  });
35
41
 
36
- self.addEventListener("activate", event => {
37
- event.waitUntil((self as unknown as { clients: Clients }).clients.claim());
42
+ sw.addEventListener("activate", (event: { waitUntil(p: Promise<void>): void }) => {
43
+ event.waitUntil(sw.clients.claim());
38
44
  });
39
45
 
40
- self.addEventListener("message", (event: ExtendableMessageEvent) => {
46
+ sw.addEventListener("message", (event: MessageEvent) => {
41
47
  if (event.data?.type === "init" && event.data.port) {
42
48
  mainPort = event.data.port as MessagePort;
43
49
  mainPort.onmessage = handleMainMessage;
@@ -62,7 +68,7 @@ function handleMainMessage(event: MessageEvent): void {
62
68
  const { statusCode, statusMessage, headers, bodyBase64 } = data;
63
69
  const body = bodyBase64 ? base64ToUint8(bodyBase64) : new Uint8Array(0);
64
70
  pending.resolve(
65
- new Response(body, {
71
+ new Response(body as unknown as BodyInit, {
66
72
  status: statusCode,
67
73
  statusText: statusMessage,
68
74
  headers,
@@ -92,18 +98,21 @@ function handleMainMessage(event: MessageEvent): void {
92
98
  }
93
99
  }
94
100
 
95
- self.addEventListener("fetch", (event: FetchEvent) => {
101
+ interface SWFetchEvent {
102
+ request: Request;
103
+ respondWith(response: Response | Promise<Response>): void;
104
+ }
105
+
106
+ sw.addEventListener("fetch", (event: SWFetchEvent) => {
96
107
  const url = new URL(event.request.url);
97
108
  if (!url.pathname.startsWith(VIRTUAL_PREFIX)) return;
98
109
 
99
110
  if (!mainPort) {
100
- (self as unknown as { clients: Clients }).clients
101
- .matchAll()
102
- .then((clients: readonly Client[]) => {
103
- for (const client of clients) {
104
- client.postMessage({ type: "sw-needs-init" });
105
- }
106
- });
111
+ sw.clients.matchAll().then((clients: Client[]) => {
112
+ for (const client of clients) {
113
+ client.postMessage({ type: "sw-needs-init" });
114
+ }
115
+ });
107
116
  event.respondWith(
108
117
  new Response("Service Worker not connected", { status: 503 }),
109
118
  );