xit-wasm 0.1.0
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 +156 -0
- package/dist/archive.d.ts +118 -0
- package/dist/archive.d.ts.map +1 -0
- package/dist/archive.js +363 -0
- package/dist/archive.js.map +1 -0
- package/dist/host-memory.d.ts +109 -0
- package/dist/host-memory.d.ts.map +1 -0
- package/dist/host-memory.js +432 -0
- package/dist/host-memory.js.map +1 -0
- package/dist/host-node.d.ts +102 -0
- package/dist/host-node.d.ts.map +1 -0
- package/dist/host-node.js +376 -0
- package/dist/host-node.js.map +1 -0
- package/dist/host.d.ts +160 -0
- package/dist/host.d.ts.map +1 -0
- package/dist/host.js +164 -0
- package/dist/host.js.map +1 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +83 -0
- package/dist/index.js.map +1 -0
- package/package.json +36 -0
- package/src/archive.ts +515 -0
- package/src/host-memory.ts +458 -0
- package/src/host-node.ts +388 -0
- package/src/host.ts +262 -0
- package/src/index.ts +100 -0
- package/xit.wasm +0 -0
package/dist/host.js
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host import surface. The wasm module declares 24 `host.*` extern functions;
|
|
3
|
+
* a Host implementation provides their JS-side bodies. This module defines:
|
|
4
|
+
*
|
|
5
|
+
* - The Host interface (signatures matching src/host_io.zig).
|
|
6
|
+
* - HostStat: byte-layout helper that mirrors the Zig HostStat extern struct.
|
|
7
|
+
* - hostImports(): converts a Host into the WebAssembly imports object the
|
|
8
|
+
* wasm module expects.
|
|
9
|
+
*
|
|
10
|
+
* The wasm passes pointers + lengths into linear memory; Host implementations
|
|
11
|
+
* take a `WebAssembly.Memory` reference at construction time so they can read
|
|
12
|
+
* and write into wasm memory directly.
|
|
13
|
+
*/
|
|
14
|
+
/** Wire layout matches `HostStat` in src/host_io.zig — 48 bytes, 8-aligned. */
|
|
15
|
+
export const HOST_STAT_BYTES = 48;
|
|
16
|
+
export const KIND_FILE = 0;
|
|
17
|
+
export const KIND_DIR = 1;
|
|
18
|
+
export const KIND_SYMLINK = 2;
|
|
19
|
+
export const KIND_OTHER = 3;
|
|
20
|
+
export const LOCK_NONE = 0;
|
|
21
|
+
export const LOCK_SHARED = 1;
|
|
22
|
+
export const LOCK_EXCLUSIVE = 2;
|
|
23
|
+
/** Status codes the Host returns. 0 = success; non-zero values are passed
|
|
24
|
+
* through to xit and surface as errors there. Keeping this enum loose for
|
|
25
|
+
* now — finer-grained error mapping is a follow-up. */
|
|
26
|
+
export const OK = 0;
|
|
27
|
+
export const ERR_GENERIC = 1;
|
|
28
|
+
export const ERR_NOT_FOUND = 2;
|
|
29
|
+
/**
|
|
30
|
+
* Build the WebAssembly imports object expected by the wasm module. Pointer-
|
|
31
|
+
* decoding lives here (centralized) so individual Host implementations can stay
|
|
32
|
+
* focused on their own backing store.
|
|
33
|
+
*/
|
|
34
|
+
export function hostImports(host, getMemory) {
|
|
35
|
+
const dec = new TextDecoder();
|
|
36
|
+
const memU8 = () => new Uint8Array(getMemory().buffer);
|
|
37
|
+
const memDV = () => new DataView(getMemory().buffer);
|
|
38
|
+
const readStr = (ptr, len) => dec.decode(memU8().slice(ptr, ptr + len));
|
|
39
|
+
const writeStat = (ptr, s) => {
|
|
40
|
+
const dv = memDV();
|
|
41
|
+
dv.setBigUint64(ptr + 0, s.size, true);
|
|
42
|
+
dv.setBigInt64(ptr + 8, s.mtimeNs, true);
|
|
43
|
+
dv.setBigInt64(ptr + 16, s.atimeNs, true);
|
|
44
|
+
dv.setBigInt64(ptr + 24, s.ctimeNs, true);
|
|
45
|
+
dv.setBigUint64(ptr + 32, s.inode, true);
|
|
46
|
+
dv.setUint32(ptr + 40, s.kind, true);
|
|
47
|
+
dv.setUint32(ptr + 44, s.modeBits, true);
|
|
48
|
+
};
|
|
49
|
+
return {
|
|
50
|
+
host: {
|
|
51
|
+
host_dir_create_file: (dirH, p, plen, outH) => {
|
|
52
|
+
const r = host.dirCreateFile(dirH, readStr(p, plen));
|
|
53
|
+
if (r.code === OK)
|
|
54
|
+
memDV().setInt32(outH, r.handle, true);
|
|
55
|
+
return r.code;
|
|
56
|
+
},
|
|
57
|
+
host_dir_open_file: (dirH, p, plen, outH) => {
|
|
58
|
+
const r = host.dirOpenFile(dirH, readStr(p, plen));
|
|
59
|
+
if (r.code === OK)
|
|
60
|
+
memDV().setInt32(outH, r.handle, true);
|
|
61
|
+
return r.code;
|
|
62
|
+
},
|
|
63
|
+
host_dir_create_dir: (dirH, p, plen) => host.dirCreateDir(dirH, readStr(p, plen)),
|
|
64
|
+
host_dir_create_dir_path: (dirH, p, plen, outExisted) => {
|
|
65
|
+
const r = host.dirCreateDirPath(dirH, readStr(p, plen));
|
|
66
|
+
if (r.code === OK)
|
|
67
|
+
memU8()[outExisted] = r.existed ? 1 : 0;
|
|
68
|
+
return r.code;
|
|
69
|
+
},
|
|
70
|
+
host_dir_create_dir_path_open: (dirH, p, plen, outH) => {
|
|
71
|
+
const r = host.dirCreateDirPathOpen(dirH, readStr(p, plen));
|
|
72
|
+
if (r.code === OK)
|
|
73
|
+
memDV().setInt32(outH, r.handle, true);
|
|
74
|
+
return r.code;
|
|
75
|
+
},
|
|
76
|
+
host_dir_open_dir: (dirH, p, plen, outH) => {
|
|
77
|
+
const r = host.dirOpenDir(dirH, readStr(p, plen));
|
|
78
|
+
if (r.code === OK)
|
|
79
|
+
memDV().setInt32(outH, r.handle, true);
|
|
80
|
+
return r.code;
|
|
81
|
+
},
|
|
82
|
+
host_dir_close: (h) => host.dirClose(h),
|
|
83
|
+
host_dir_delete_file: (dirH, p, plen) => host.dirDeleteFile(dirH, readStr(p, plen)),
|
|
84
|
+
host_dir_rename: (oldDir, op, olen, newDir, np, nlen) => host.dirRename(oldDir, readStr(op, olen), newDir, readStr(np, nlen)),
|
|
85
|
+
host_dir_stat_file: (dirH, p, plen, outStat) => {
|
|
86
|
+
const r = host.dirStatFile(dirH, readStr(p, plen));
|
|
87
|
+
if (r.code === OK && r.stat)
|
|
88
|
+
writeStat(outStat, r.stat);
|
|
89
|
+
return r.code;
|
|
90
|
+
},
|
|
91
|
+
host_dir_access: (dirH, p, plen) => host.dirAccess(dirH, readStr(p, plen)),
|
|
92
|
+
host_dir_read_link: (dirH, p, plen, bufPtr, bufLen, outSize) => {
|
|
93
|
+
const r = host.dirReadLink(dirH, readStr(p, plen));
|
|
94
|
+
if (r.code > 0 && r.target !== undefined) {
|
|
95
|
+
const bytes = new TextEncoder().encode(r.target);
|
|
96
|
+
if (bytes.length > bufLen)
|
|
97
|
+
return -1;
|
|
98
|
+
memU8().set(bytes, bufPtr);
|
|
99
|
+
memDV().setUint32(outSize, bytes.length, true);
|
|
100
|
+
return bytes.length;
|
|
101
|
+
}
|
|
102
|
+
return r.code;
|
|
103
|
+
},
|
|
104
|
+
host_file_close: (h) => host.fileClose(h),
|
|
105
|
+
host_file_read: (h, offset, bufPtr, bufLen, outRead) => {
|
|
106
|
+
const r = host.fileRead(h, offset, bufLen);
|
|
107
|
+
if (r.code === OK) {
|
|
108
|
+
memU8().set(r.data, bufPtr);
|
|
109
|
+
// out_read is `*usize` which on wasm32 is 4 bytes
|
|
110
|
+
memDV().setUint32(outRead, r.data.length, true);
|
|
111
|
+
}
|
|
112
|
+
return r.code;
|
|
113
|
+
},
|
|
114
|
+
host_file_write: (h, offset, bufPtr, bufLen, outWritten) => {
|
|
115
|
+
const data = memU8().slice(bufPtr, bufPtr + bufLen);
|
|
116
|
+
const r = host.fileWrite(h, offset, data);
|
|
117
|
+
if (r.code === OK)
|
|
118
|
+
memDV().setUint32(outWritten, r.written, true);
|
|
119
|
+
return r.code;
|
|
120
|
+
},
|
|
121
|
+
host_file_stat: (h, outStat) => {
|
|
122
|
+
const r = host.fileStat(h);
|
|
123
|
+
if (r.code === OK && r.stat)
|
|
124
|
+
writeStat(outStat, r.stat);
|
|
125
|
+
return r.code;
|
|
126
|
+
},
|
|
127
|
+
host_file_length: (h, outLen) => {
|
|
128
|
+
const r = host.fileLength(h);
|
|
129
|
+
if (r.code === OK)
|
|
130
|
+
memDV().setBigUint64(outLen, r.length, true);
|
|
131
|
+
return r.code;
|
|
132
|
+
},
|
|
133
|
+
host_file_write_stream: (h, bufPtr, bufLen, outWritten) => {
|
|
134
|
+
const data = memU8().slice(bufPtr, bufPtr + bufLen);
|
|
135
|
+
const r = host.fileWriteStream(h, data);
|
|
136
|
+
if (r.code === OK)
|
|
137
|
+
memDV().setUint32(outWritten, r.written, true);
|
|
138
|
+
return r.code;
|
|
139
|
+
},
|
|
140
|
+
host_file_read_stream: (h, bufPtr, bufLen, outRead) => {
|
|
141
|
+
const r = host.fileReadStream(h, bufLen);
|
|
142
|
+
if (r.code === OK) {
|
|
143
|
+
memU8().set(r.data, bufPtr);
|
|
144
|
+
memDV().setUint32(outRead, r.data.length, true);
|
|
145
|
+
}
|
|
146
|
+
return r.code;
|
|
147
|
+
},
|
|
148
|
+
host_file_seek_to: (h, offset) => host.fileSeekTo(h, offset),
|
|
149
|
+
host_file_seek_by: (h, relative) => host.fileSeekBy(h, relative),
|
|
150
|
+
host_file_lock: (h, kind) => host.fileLock(h, kind),
|
|
151
|
+
host_file_try_lock: (h, kind) => host.fileTryLock(h, kind),
|
|
152
|
+
host_file_unlock: (h) => host.fileUnlock(h),
|
|
153
|
+
host_file_sync: (h) => host.fileSync(h),
|
|
154
|
+
host_file_set_length: (h, len) => host.fileSetLength(h, len),
|
|
155
|
+
host_now_nanos: () => host.nowNanos(),
|
|
156
|
+
host_random: (bufPtr, bufLen) => {
|
|
157
|
+
const buf = new Uint8Array(bufLen);
|
|
158
|
+
host.random(buf);
|
|
159
|
+
memU8().set(buf, bufPtr);
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
//# sourceMappingURL=host.js.map
|
package/dist/host.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"host.js","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AAS,EAAE,IAAY,EAAE,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,EAAE,IAAI,CAAC;YAC1E,gBAAgB,EAAE,CAAC,CAAS,EAAE,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;YACnD,cAAc,EAAE,CAAC,CAAS,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;YAC/C,oBAAoB,EAAE,CAAC,CAAS,EAAE,GAAW,EAAE,EAAE,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,EAAE,GAAG,CAAC;YAE5E,cAAc,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,QAAQ,EAAE;YACrC,WAAW,EAAE,CAAC,MAAc,EAAE,MAAc,EAAE,EAAE;gBAC9C,MAAM,GAAG,GAAG,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC;gBACnC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;gBACjB,KAAK,EAAE,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;YAC3B,CAAC;SACF;KACF,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public entry point.
|
|
3
|
+
*
|
|
4
|
+
* The headline API is the `Archive` class — a pure in-memory, browser-safe
|
|
5
|
+
* wrapper that hides every wasm/host/file detail. It's what plastron uses.
|
|
6
|
+
*
|
|
7
|
+
* The lower-level loader below (`load`) is kept for the existing smoke tests
|
|
8
|
+
* and any consumer who wants to drive the wasm directly. Most users want
|
|
9
|
+
* `Archive`.
|
|
10
|
+
*/
|
|
11
|
+
export { Archive, setDefaultWasmSource } from "./archive.ts";
|
|
12
|
+
export type { CommitOptions, LoadOptions, WasmSource } from "./archive.ts";
|
|
13
|
+
import type { Host } from "./host.ts";
|
|
14
|
+
export interface XitInstance {
|
|
15
|
+
memory: WebAssembly.Memory;
|
|
16
|
+
abiVersion(): number;
|
|
17
|
+
initRepo(absPath: string): number;
|
|
18
|
+
smokeInitAddCommit(absPath: string): number;
|
|
19
|
+
smokeXitInitAddCommit(absPath: string): number;
|
|
20
|
+
}
|
|
21
|
+
export declare function load(wasmPath: string, host: Host): Promise<XitInstance>;
|
|
22
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAC7D,YAAY,EAAE,aAAa,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAG3E,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEtC,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC;IAC3B,UAAU,IAAI,MAAM,CAAC;IACrB,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC;IAClC,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC;IAC5C,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC;CAChD;AA+BD,wBAAsB,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,WAAW,CAAC,CA6C7E"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public entry point.
|
|
3
|
+
*
|
|
4
|
+
* The headline API is the `Archive` class — a pure in-memory, browser-safe
|
|
5
|
+
* wrapper that hides every wasm/host/file detail. It's what plastron uses.
|
|
6
|
+
*
|
|
7
|
+
* The lower-level loader below (`load`) is kept for the existing smoke tests
|
|
8
|
+
* and any consumer who wants to drive the wasm directly. Most users want
|
|
9
|
+
* `Archive`.
|
|
10
|
+
*/
|
|
11
|
+
var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
|
|
12
|
+
if (typeof path === "string" && /^\.\.?\//.test(path)) {
|
|
13
|
+
return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
|
|
14
|
+
return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
return path;
|
|
18
|
+
};
|
|
19
|
+
export { Archive, setDefaultWasmSource } from "./archive.js";
|
|
20
|
+
import { hostImports } from "./host.js";
|
|
21
|
+
/**
|
|
22
|
+
* Load and instantiate the xit wasm module against a host implementation.
|
|
23
|
+
* The host provides the 24 backing functions the wasm imports — see
|
|
24
|
+
* src/host.ts for the surface.
|
|
25
|
+
*
|
|
26
|
+
* Note: the wasm module currently has no host-side allocation hook. Every
|
|
27
|
+
* call that takes a path/buffer needs to copy the bytes into wasm linear
|
|
28
|
+
* memory before invoking. This is fine for a spike but a real binding
|
|
29
|
+
* would expose `xit_alloc` and `xit_free` from the wasm side and stage
|
|
30
|
+
* arguments through them.
|
|
31
|
+
*
|
|
32
|
+
* For now we sneak path bytes into a fixed scratch region inside the
|
|
33
|
+
* wasm's memory. Wasm pages are 64 KiB; the linker reserves the first
|
|
34
|
+
* page for stack + globals. We borrow the second page (offset 65536+)
|
|
35
|
+
* for path scratch — outside any compile-time-allocated symbols. This is
|
|
36
|
+
* a HACK for spike testing only.
|
|
37
|
+
*/
|
|
38
|
+
const SCRATCH_OFFSET = 1 << 16; // start of page 1
|
|
39
|
+
const SCRATCH_SIZE = 4096;
|
|
40
|
+
export async function load(wasmPath, host) {
|
|
41
|
+
// Dynamic import keeps the entry module browser-clean. `load()` is a
|
|
42
|
+
// Node-only smoke-test helper; bundlers that statically analyze a top-
|
|
43
|
+
// level `node:fs/promises` import would mark the whole module as
|
|
44
|
+
// node-only and fail to ship a browser build of the headline `Archive`
|
|
45
|
+
// API alongside it. The runtime-built specifier + @vite-ignore also
|
|
46
|
+
// suppresses Vite's "externalized for browser compatibility" warning
|
|
47
|
+
// for downstream consumers — `load()` is never reachable from a
|
|
48
|
+
// browser build path so the warning would be noise.
|
|
49
|
+
const nodeFsSpecifier = "node:fs/promises";
|
|
50
|
+
const fs = await import(__rewriteRelativeImportExtension(/* @vite-ignore */ nodeFsSpecifier));
|
|
51
|
+
const bytes = await fs.readFile(wasmPath);
|
|
52
|
+
const mod = await WebAssembly.compile(bytes);
|
|
53
|
+
let memory;
|
|
54
|
+
const imports = hostImports(host, () => memory);
|
|
55
|
+
const inst = await WebAssembly.instantiate(mod, imports);
|
|
56
|
+
const exp = inst.exports;
|
|
57
|
+
memory = exp.memory;
|
|
58
|
+
const enc = new TextEncoder();
|
|
59
|
+
const writeScratch = (s) => {
|
|
60
|
+
const bytes = enc.encode(s);
|
|
61
|
+
if (bytes.length > SCRATCH_SIZE)
|
|
62
|
+
throw new Error("path too long for scratch buffer");
|
|
63
|
+
new Uint8Array(memory.buffer, SCRATCH_OFFSET, bytes.length).set(bytes);
|
|
64
|
+
return { ptr: SCRATCH_OFFSET, len: bytes.length };
|
|
65
|
+
};
|
|
66
|
+
return {
|
|
67
|
+
memory,
|
|
68
|
+
abiVersion: () => exp.xit_abi_version(),
|
|
69
|
+
initRepo(absPath) {
|
|
70
|
+
const { ptr, len } = writeScratch(absPath);
|
|
71
|
+
return exp.xit_init_repo(ptr, len);
|
|
72
|
+
},
|
|
73
|
+
smokeInitAddCommit(absPath) {
|
|
74
|
+
const { ptr, len } = writeScratch(absPath);
|
|
75
|
+
return exp.xit_smoke_init_add_commit(ptr, len);
|
|
76
|
+
},
|
|
77
|
+
smokeXitInitAddCommit(absPath) {
|
|
78
|
+
const { ptr, len } = writeScratch(absPath);
|
|
79
|
+
return exp.xit_smoke_xit_init_add_commit(ptr, len);
|
|
80
|
+
},
|
|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C,CAAS,EAAgC,EAAE;QAC/D,MAAM,KAAK,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QAC5B,IAAI,KAAK,CAAC,MAAM,GAAG,YAAY;YAAE,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;QACrF,IAAI,UAAU,CAAC,MAAM,CAAC,MAAM,EAAE,cAAc,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACvE,OAAO,EAAE,GAAG,EAAE,cAAc,EAAE,GAAG,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC;IACpD,CAAC,CAAC;IAEF,OAAO;QACL,MAAM;QACN,UAAU,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,eAAe,EAAE;QACvC,QAAQ,CAAC,OAAe;YACtB,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,YAAY,CAAC,OAAO,CAAC,CAAC;YAC3C,OAAO,GAAG,CAAC,aAAa,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QACrC,CAAC;QACD,kBAAkB,CAAC,OAAe;YAChC,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,YAAY,CAAC,OAAO,CAAC,CAAC;YAC3C,OAAO,GAAG,CAAC,yBAAyB,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QACjD,CAAC;QACD,qBAAqB,CAAC,OAAe;YACnC,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,YAAY,CAAC,OAAO,CAAC,CAAC;YAC3C,OAAO,GAAG,CAAC,6BAA6B,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QACrD,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "xit-wasm",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Versioned in-memory archives via xit (Zig VCS) compiled to WebAssembly. Browser-friendly.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "dist/index.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./node": {
|
|
15
|
+
"types": "./dist/host-node.d.ts",
|
|
16
|
+
"default": "./dist/host-node.js"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"files": ["dist", "src", "xit.wasm"],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build:wasm": "cp ../xit/zig-out/bin/xit.wasm xit.wasm",
|
|
22
|
+
"build:tsc": "tsc",
|
|
23
|
+
"build": "npm run build:wasm && npm run build:tsc",
|
|
24
|
+
"prepublishOnly": "npm run build",
|
|
25
|
+
"smoke": "node example/run-smoke.ts",
|
|
26
|
+
"smoke:archive": "node example/run-archive.ts",
|
|
27
|
+
"typecheck": "tsc --noEmit"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"fflate": "^0.8.2"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@types/node": "^22.0.0",
|
|
34
|
+
"typescript": "^5.5.0"
|
|
35
|
+
}
|
|
36
|
+
}
|