@fossil-lang/wasm 0.3.0-alpha.2 → 0.3.0-alpha.20

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/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,kGAAkG;AAClG,wGAAwG;AACxG,uFAAuF;AACvF,OAAO,EACL,gBAAgB,IAAI,mBAAmB,EACvC,UAAU,IAAI,aAAa,EAC3B,QAAQ,IAAI,WAAW,EACvB,eAAe,IAAI,iBAAiB,EACpC,gBAAgB,IAAI,iBAAiB,GACtC,MAAM,uBAAuB,CAAC;AAG/B,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAG3C;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,gBAAgB;IAC9B,iBAAiB,EAAE,CAAC;AACtB,CAAC;AAYD;;;;;;;;GAQG;AACH,MAAM,UAAU,QAAQ,CAAC,IAAY;IACnC,6EAA6E;IAC7E,sEAAsE;IACtE,8EAA8E;IAC9E,6EAA6E;IAC7E,OAAO,WAAW,CAAC,IAAI,CAAe,CAAC;AACzC,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,cAAc;IAC5B,OAAO,iBAAiB,EAA0B,CAAC;AACrD,CAAC;AA8ED;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,OAAO,gBAAgB;IACnB,MAAM,CAAsB;IAEpC;QACE,IAAI,CAAC,MAAM,GAAG,IAAI,mBAAmB,EAAE,CAAC;IAC1C,CAAC;IAED;;;;OAIG;IACH,IAAI;QACF,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;IACrB,CAAC;IAED;;;;OAIG;IACH,cAAc;QACZ,OAAO,IAAI,CAAC,MAAM,CAAC,cAAc,EAAmB,CAAC;IACvD,CAAC;IAED;;;;;;;;OAQG;I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ED
@@ -1,27 +1,21 @@
1
- /** Options for {@link initFossilWasm}. */
2
- export interface InitFossilWasmOpts {
3
- /**
4
- * URL or path to `fossil_wasm_bg.wasm`. Consumers control resolution:
5
- * - Vite: `import wasmUrl from '@fossil-lang/wasm/pkg/fossil_wasm_bg.wasm?url'`
6
- * - Next.js: serve from `public/` and pass the static URL (e.g. `'/wasm/fossil_wasm_bg.wasm'`)
7
- * - Web Worker: `new URL('@fossil-lang/wasm/pkg/fossil_wasm_bg.wasm', import.meta.url)`
8
- * - Node test: a `file://` URL resolved from `import.meta.url`
9
- *
10
- * Accepts `string` (a URL string), `URL`, a `Request`, or a `Response` —
11
- * matching `wasm-bindgen --target web`'s init signature.
12
- */
13
- wasmUrl: string | URL | Request | Response;
14
- }
1
+ import type { InitInput } from '../pkg/fossil_wasm.js';
2
+ export type { InitInput };
15
3
  /**
16
4
  * Boot the fossil-wasm module. MUST be awaited before calling any of
17
- * {@link tokenize}, {@link semanticLegend}, or instantiating
18
- * {@link FossilPlayground}. Memoised — subsequent calls return the same promise.
5
+ * {@link tokenize}, {@link tokenKinds}, or instantiating
6
+ * {@link FossilWorkspace}. A boot that succeeded is kept; one that failed is
7
+ * not, so the next call tries again — `module/unreachable` for a module that could not be
8
+ * fetched within 60 s, `internal/bug` for one that would not instantiate.
19
9
  *
20
- * Per 08-RESEARCH.md Pattern 3 (wasm-bindgen --target web), consumers control
21
- * the `.wasm` URL — this avoids tying library users to a specific bundler's
22
- * `.wasm` import magic. See `packages/wasm/README.md` for consumer patterns.
10
+ * **Called with nothing, the module finds its own `.wasm`.** The glue resolves
11
+ * `new URL('fossil_wasm_bg.wasm', import.meta.url)`, which is the pattern Vite,
12
+ * webpack 5 and Turbopack all recognise and emit as an asset — so a bundled host
13
+ * writes `await initFossilWasm()` and copies nothing.
14
+ *
15
+ * `wasm` is for the host with no bundler to do that: Node, whose `fetch` rejects
16
+ * `file://`, hands the bytes (`BufferSource`) or a `Response`.
23
17
  */
24
- export declare function initFossilWasm(opts: InitFossilWasmOpts): Promise<unknown>;
18
+ export declare function initFossilWasm(wasm?: InitInput): Promise<unknown>;
25
19
  /**
26
20
  * For tests + hot-reload — reset the memoised promise. NOT exported from the
27
21
  * package index (test-internal helper).
@@ -1 +1 @@
1
- {"version":3,"file":"load.d.ts","sourceRoot":"","sources":["../src/load.ts"],"names":[],"mappings":"AAMA,0CAA0C;AAC1C,MAAM,WAAW,kBAAkB;IACjC;;;;;;;;;OASG;IACH,OAAO,EAAE,MAAM,GAAG,GAAG,GAAG,OAAO,GAAG,QAAQ,CAAC;CAC5C;AAID;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,kBAAkB,GAAG,OAAO,CAAC,OAAO,CAAC,CASzE;AAED;;;GAGG;AACH,wBAAgB,eAAe,IAAI,IAAI,CAEtC"}
1
+ {"version":3,"file":"load.d.ts","sourceRoot":"","sources":["../src/load.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAIvD,YAAY,EAAE,SAAS,EAAE,CAAC;AAI1B;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,cAAc,CAAC,IAAI,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC,OAAO,CAAC,CAUjE;AAED;;;GAGG;AACH,wBAAgB,eAAe,IAAI,IAAI,CAEtC"}
package/dist/load.js CHANGED
@@ -1,25 +1,33 @@
1
1
  // '../pkg/fossil_wasm.js' is a wasm-bindgen --target web output emitted by `pnpm run build:wasm`.
2
- // It is gitignored (per 08-01 .gitignore + repo .gitignore `packages/wasm/pkg/`) but always present at build time.
3
- // The accompanying fossil_wasm.d.ts is consumed via the file's `/* @ts-self-types="./fossil_wasm.d.ts" */` pragma —
4
- // TS 5.6 resolves the `import` to that side-channel `.d.ts` automatically (no `@ts-expect-error` needed).
2
+ // It is gitignored (repo .gitignore `packages/wasm/pkg/`) but always present at build time and in
3
+ // the published tarball. Its `.d.ts` is consumed via the file's `/* @ts-self-types */` pragma.
5
4
  import init from '../pkg/fossil_wasm.js';
5
+ import { boot } from '@fossil-lang/types';
6
6
  let _initPromise = null;
7
7
  /**
8
8
  * Boot the fossil-wasm module. MUST be awaited before calling any of
9
- * {@link tokenize}, {@link semanticLegend}, or instantiating
10
- * {@link FossilPlayground}. Memoised — subsequent calls return the same promise.
9
+ * {@link tokenize}, {@link tokenKinds}, or instantiating
10
+ * {@link FossilWorkspace}. A boot that succeeded is kept; one that failed is
11
+ * not, so the next call tries again — `module/unreachable` for a module that could not be
12
+ * fetched within 60 s, `internal/bug` for one that would not instantiate.
11
13
  *
12
- * Per 08-RESEARCH.md Pattern 3 (wasm-bindgen --target web), consumers control
13
- * the `.wasm` URL — this avoids tying library users to a specific bundler's
14
- * `.wasm` import magic. See `packages/wasm/README.md` for consumer patterns.
14
+ * **Called with nothing, the module finds its own `.wasm`.** The glue resolves
15
+ * `new URL('fossil_wasm_bg.wasm', import.meta.url)`, which is the pattern Vite,
16
+ * webpack 5 and Turbopack all recognise and emit as an asset — so a bundled host
17
+ * writes `await initFossilWasm()` and copies nothing.
18
+ *
19
+ * `wasm` is for the host with no bundler to do that: Node, whose `fetch` rejects
20
+ * `file://`, hands the bytes (`BufferSource`) or a `Response`.
15
21
  */
16
- export function initFossilWasm(opts) {
17
- if (!_initPromise) {
18
- // wasm-bindgen 0.2.120 init() prefers the `{ module_or_path }` object form;
19
- // passing the URL/Request/Response/BufferSource as a positional argument
20
- // still works but logs a deprecation warning ("pass a single object
21
- // instead"). We use the object form to stay on the maintained path.
22
- _initPromise = init({ module_or_path: opts.wasmUrl });
22
+ export function initFossilWasm(wasm) {
23
+ if (_initPromise === null) {
24
+ // The object form: the positional one still works but logs a deprecation warning.
25
+ const pending = boot('fossil_wasm_bg.wasm', () => init(wasm === undefined ? undefined : { module_or_path: wasm }));
26
+ _initPromise = pending;
27
+ pending.catch(() => {
28
+ if (_initPromise === pending)
29
+ _initPromise = null; // forgotten, so the next call boots again
30
+ });
23
31
  }
24
32
  return _initPromise;
25
33
  }
package/dist/load.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"load.js","sourceRoot":"","sources":["../src/load.ts"],"names":[],"mappings":"AAAA,kGAAkG;AAClG,mHAAmH;AACnH,oHAAoH;AACpH,0GAA0G;AAC1G,OAAO,IAAI,MAAM,uBAAuB,CAAC;AAiBzC,IAAI,YAAY,GAA4B,IAAI,CAAC;AAEjD;;;;;;;;GAQG;AACH,MAAM,UAAU,cAAc,CAAC,IAAwB;IACrD,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,4EAA4E;QAC5E,yEAAyE;QACzE,oEAAoE;QACpE,oEAAoE;QACpE,YAAY,GAAG,IAAI,CAAC,EAAE,cAAc,EAAE,IAAI,CAAC,OAAgB,EAAE,CAAC,CAAC;IACjE,CAAC;IACD,OAAO,YAAY,CAAC;AACtB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,eAAe;IAC7B,YAAY,GAAG,IAAI,CAAC;AACtB,CAAC"}
1
+ {"version":3,"file":"load.js","sourceRoot":"","sources":["../src/load.ts"],"names":[],"mappings":"AAAA,kGAAkG;AAClG,kGAAkG;AAClG,+FAA+F;AAC/F,OAAO,IAAI,MAAM,uBAAuB,CAAC;AAGzC,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAI1C,IAAI,YAAY,GAA4B,IAAI,CAAC;AAEjD;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,cAAc,CAAC,IAAgB;IAC7C,IAAI,YAAY,KAAK,IAAI,EAAE,CAAC;QAC1B,kFAAkF;QAClF,MAAM,OAAO,GAAG,IAAI,CAAC,qBAAqB,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,cAAc,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;QACnH,YAAY,GAAG,OAAO,CAAC;QACvB,OAAO,CAAC,KAAK,CAAC,GAAG,EAAE;YACjB,IAAI,YAAY,KAAK,OAAO;gBAAE,YAAY,GAAG,IAAI,CAAC,CAAC,0CAA0C;QAC/F,CAAC,CAAC,CAAC;IACL,CAAC;IACD,OAAO,YAAY,CAAC;AACtB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,eAAe;IAC7B,YAAY,GAAG,IAAI,CAAC;AACtB,CAAC"}
@@ -0,0 +1,68 @@
1
+ import { type Host, type ProgramSource } from '@fossil-lang/types';
2
+ import { FossilWorkspace, tokenize, tokenKinds } from './client.js';
3
+ import type { CheckRow, CompletionRow, DefinitionRow, HoverRow, InferredDescriptorJson, SemanticTokenRow } from './index.js';
4
+ import { type InitInput } from './load.js';
5
+ /** What {@link openProgram} takes beside the key. */
6
+ export interface OpenProgramOptions {
7
+ /** The connection map, and the credentials a document the program names is read with. */
8
+ host: Host;
9
+ /** The buffer's text at open. Defaults to empty; every entry point takes the text anyway. */
10
+ text?: string;
11
+ /** The module's `.wasm`, for a host with no bundler — see {@link initFossilWasm}. */
12
+ wasm?: InitInput;
13
+ /** Stops the open — the boot and the first read of the documents — rejecting with its reason. */
14
+ signal?: AbortSignal;
15
+ }
16
+ /**
17
+ * A program open in its own workspace. Every member that answers about the program takes the
18
+ * current text, and pushes it first — see the module header for why that repetition is the design.
19
+ */
20
+ export interface FossilProgram {
21
+ /** The key the program is open under — `CheckRow.uri` and `DefinitionRow.uri` carry it. */
22
+ readonly uri: string;
23
+ /** The compiler's lexer, for highlighting. Needs no workspace, and is here so the spread works. */
24
+ readonly tokenize: typeof tokenize;
25
+ /** The legend for a token's `kind`. */
26
+ readonly tokenKinds: typeof tokenKinds;
27
+ /** What the compiler knows about each name and reference — shapes, declarations, connections —
28
+ * laid over {@link tokenize}'s lexical highlighting. */
29
+ semanticTokens(text: string): SemanticTokenRow[];
30
+ /**
31
+ * Push the text, read every document it names that the workspace lacks, and check. No debounce:
32
+ * `fossil()`'s linter waits out its own delay AND waits for this to return before it schedules
33
+ * again, which is what an LSP client does with `didChange`.
34
+ *
35
+ * A document that could not be read is a row of its own at the top of the program, under the code
36
+ * of its read — `storage/host-silent`, `storage/unreachable`, … — beside the checker's rows, which
37
+ * see it only as missing.
38
+ */
39
+ check(text: string): Promise<CheckRow[]>;
40
+ /** The type under the cursor, and the type the target shape demands of it — or `null`. */
41
+ hover(text: string, line: number, character: number): HoverRow | null;
42
+ /** The candidates at the cursor, narrowed by the receiver's type. */
43
+ complete(text: string, line: number, character: number): CompletionRow[];
44
+ /** Where the name under the cursor is defined. Often in the shape document: read `uri`. */
45
+ definition(text: string, line: number, character: number): DefinitionRow[];
46
+ /**
47
+ * The data sources the program reads, as fossil resolved them — what introspection DESCRIBEs.
48
+ * Resolves the documents first, because a source's locator goes through the connection map.
49
+ */
50
+ sources(text: string): Promise<ProgramSource[]>;
51
+ /**
52
+ * A host-introspected input schema, registered under the URI the program wrote. The compiler
53
+ * never introspects a source itself; push this before the check that should see it.
54
+ */
55
+ registerDescriptor(descriptor: InferredDescriptorJson): void;
56
+ /** The workspace underneath, for the rare question this surface does not ask. */
57
+ readonly workspace: FossilWorkspace;
58
+ /** Free the workspace. Every member fails after it. */
59
+ close(): void;
60
+ }
61
+ /**
62
+ * Boot the module, open `uri` in a fresh workspace, and read the documents its text names.
63
+ *
64
+ * One call and the answer goes straight into `fossil()`. A boot that succeeded is kept, so a second
65
+ * program in the same tab costs a workspace and nothing else.
66
+ */
67
+ export declare function openProgram(uri: string, options: OpenProgramOptions): Promise<FossilProgram>;
68
+ //# sourceMappingURL=program.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"program.d.ts","sourceRoot":"","sources":["../src/program.ts"],"names":[],"mappings":"AAkCA,OAAO,EAAS,KAAK,IAAI,EAAE,KAAK,aAAa,EAAuB,MAAM,oBAAoB,CAAC;AAE/F,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACpE,OAAO,KAAK,EACV,QAAQ,EACR,aAAa,EACb,a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,CAAC;IAChD;;;OAGG;IACH,kBAAkB,CAAC,UAAU,EAAE,sBAAsB,GAAG,IAAI,CAAC;IAC7D,iFAAiF;IACjF,QAAQ,CAAC,SAAS,EAAE,eAAe,CAAC;IACpC,uDAAuD;IACvD,KAAK,IAAI,IAAI,CAAC;CACf;AAED;;;;;GAKG;AACH,wBAAsB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,aAAa,CAAC,CA6ElG"}
@@ -0,0 +1,117 @@
1
+ /**
2
+ * One program, open in a workspace, answering an editor — what every host of the checker wrote by
3
+ * hand before this existed.
4
+ *
5
+ * `FossilWorkspace` is the workspace and it is right that it stays general: it holds any number
6
+ * of files and answers about each. What a host with ONE program in ONE editor needs on top of it
7
+ * is always the same protocol, and two copies of it had already diverged in their comments:
8
+ *
9
+ * 1. **Push before you ask.** Four callers at four rates — the debounced linter, hover on pointer
10
+ * rest, completion on nearly every keystroke, goto-def on a key — share one workspace, and all
11
+ * four answer about the text of the last `updateFile`. So every entry point takes the text and
12
+ * pushes it first, and a string comparison against what was last pushed makes that free in the
13
+ * common case. `updateFile` is the one call that bumps the Salsa revision; calling it per
14
+ * mouse-move would invalidate the memoised check the squiggles came from for nothing.
15
+ * 2. **Read what the program names before you check it.** The compiler performs no IO. An edit
16
+ * can name a shape document the workspace has not read, so a check first runs
17
+ * `resolveDocuments` over the host's {@link Host} — which reads nothing when nothing is
18
+ * missing.
19
+ *
20
+ * The result is shaped for `@fossil-lang/codemirror-fossil`'s `fossil()`: `tokenize`,
21
+ * `tokenKinds`, `semanticTokens`, `uri`, `check`, `hover`, `complete` and `definition` are exactly
22
+ * its option names, so a host spreads it and adds what is its own to decide:
23
+ *
24
+ * ```ts
25
+ * const program = await openProgram('job.fossil', { host, text });
26
+ * const extensions = fossil({ ...program, onNavigate });
27
+ * ```
28
+ *
29
+ * One workspace rather than one per rate, for the reason `fossil()`'s own header gives: a second
30
+ * workspace for the position queries would answer from a different revision than the squiggles on
31
+ * screen. The position methods take a SHARED borrow on the Rust side, so they nest inside a live
32
+ * check rather than poisoning it.
33
+ */
34
+ import { resolveDocuments } from '@fossil-lang/storage';
35
+ import { until } from '@fossil-lang/types';
36
+ import { FossilWorkspace, tokenize, tokenKinds } from './client.js';
37
+ import { initFossilWasm } from './load.js';
38
+ /**
39
+ * Boot the module, open `uri` in a fresh workspace, and read the documents its text names.
40
+ *
41
+ * One call and the answer goes straight into `fossil()`. A boot that succeeded is kept, so a second
42
+ * program in the same tab costs a workspace and nothing else.
43
+ */
44
+ export async function openProgram(uri, options) {
45
+ const { host, text = '', wasm, signal } = options;
46
+ await until(initFossilWasm(wasm), signal);
47
+ const workspace = new FossilWorkspace();
48
+ const handle = workspace.openFile(uri, text);
49
+ let pushed = text;
50
+ const sync = (next) => {
51
+ if (next === pushed)
52
+ return;
53
+ workspace.updateFile(handle, next);
54
+ pushed = next;
55
+ };
56
+ // What the last read of the documents could not read; every settle reads what is missing again.
57
+ let unread = [];
58
+ const settle = async (next, stop) => {
59
+ sync(next);
60
+ ({ unread } = await resolveDocuments(workspace.workspace(handle), host, { signal: stop }));
61
+ };
62
+ try {
63
+ await settle(text, signal);
64
+ }
65
+ catch (cause) {
66
+ workspace.free();
67
+ throw cause;
68
+ }
69
+ return {
70
+ uri,
71
+ tokenize,
72
+ tokenKinds,
73
+ async check(next) {
74
+ await settle(next);
75
+ const rows = workspace.check();
76
+ const failed = unread.map(({ key, problem }) => ({
77
+ uri,
78
+ range: { start: { line: 0, character: 0 }, end: { line: 0, character: 0 } },
79
+ severity: 1,
80
+ code: problem.code,
81
+ data: problem.data,
82
+ title: problem.title,
83
+ message: `${key}: ${problem.detail}`,
84
+ ...(problem.help === undefined ? {} : { help: problem.help }),
85
+ }));
86
+ return [...failed, ...rows];
87
+ },
88
+ semanticTokens(next) {
89
+ sync(next);
90
+ return workspace.semanticTokens(handle);
91
+ },
92
+ hover(next, line, character) {
93
+ sync(next);
94
+ return workspace.hover(handle, line, character);
95
+ },
96
+ complete(next, line, character) {
97
+ sync(next);
98
+ return workspace.completions(handle, line, character);
99
+ },
100
+ definition(next, line, character) {
101
+ sync(next);
102
+ return workspace.gotoDefinition(handle, line, character);
103
+ },
104
+ async sources(next) {
105
+ await settle(next);
106
+ return workspace.sources(handle);
107
+ },
108
+ registerDescriptor(descriptor) {
109
+ workspace.registerInferredDescriptor(descriptor);
110
+ },
111
+ workspace,
112
+ close() {
113
+ workspace.free();
114
+ },
115
+ };
116
+ }
117
+ //# sourceMappingURL=program.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"program.js","sourceRoot":"","sources":["../src/program.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,KAAK,EAAsD,MAAM,oBAAoB,CAAC;AAE/F,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AASpE,OAAO,EAAE,cAAc,EAAkB,MAAM,WAAW,CAAC;AA4D3D;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,GAAW,EAAE,OAA2B;IACxE,MAAM,EAAE,IAAI,EAAE,IAAI,GAAG,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IAClD,MAAM,KAAK,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,CAAC;IAE1C,MAAM,SAAS,GAAG,IAAI,eAAe,EAAE,CAAC;IACxC,MAAM,MAAM,GAAG,SAAS,CAAC,QAAQ,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IAC7C,IAAI,MAAM,GAAG,IAAI,CAAC;IAElB,MAAM,IAAI,GAAG,CAAC,IAAY,EAAQ,EAAE;QAClC,IAAI,IAAI,KAAK,MAAM;YAAE,OAAO;QAC5B,SAAS,CAAC,UAAU,CAA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AAC"}
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@fossil-lang/wasm",
3
- "version": "0.3.0-alpha.2",
4
- "description": "JS/TS wrapper around the fossil-wasm wasm-bindgen artifacts (--target web). Exposes initFossilWasm + tokenize + semanticLegend + FossilPlayground class for downstream @fossil-lang/* packages.",
3
+ "version": "0.3.0-alpha.20",
4
+ "description": "JS/TS wrapper around the fossil-wasm wasm-bindgen artifacts (--target web). Exposes initFossilWasm + tokenize + openProgram + FossilWorkspace class for downstream @fossil-lang/* packages.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
7
7
  "type": "git",
8
- "url": "https://github.com/kanzo-tech/fossil.git",
8
+ "url": "git+https://github.com/Kanzo-Tech/fossil-lang.git",
9
9
  "directory": "packages/wasm"
10
10
  },
11
11
  "publishConfig": {
@@ -33,11 +33,12 @@
33
33
  ],
34
34
  "sideEffects": false,
35
35
  "dependencies": {
36
- "@fossil-lang/types": "0.3.0-alpha.2"
36
+ "@fossil-lang/storage": "0.3.0-alpha.20",
37
+ "@fossil-lang/types": "0.3.0-alpha.20"
37
38
  },
38
39
  "devDependencies": {
39
40
  "typescript": "^5.6.0",
40
- "vitest": "^2.0.0"
41
+ "vitest": "^4.1.11"
41
42
  },
42
43
  "scripts": {
43
44
  "build:wasm": "bash scripts/build-wasm.sh",