@fossil-lang/wasm 0.3.0-alpha.7 → 0.3.0-alpha.8
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 +33 -29
- package/dist/index.d.ts +3 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -3
- package/dist/index.js.map +1 -1
- package/dist/load.d.ts +10 -18
- package/dist/load.d.ts.map +1 -1
- package/dist/load.js +12 -12
- package/dist/load.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
JS/TS wrapper around the `fossil-wasm` Rust crate's wasm-bindgen artefacts. Provides:
|
|
4
4
|
|
|
5
|
-
- `initFossilWasm(
|
|
5
|
+
- `initFossilWasm()` — boots the module (memoised). Its `.wasm` ships in this
|
|
6
|
+
package and the host's bundler emits it as an asset; the host copies nothing.
|
|
6
7
|
- `tokenize(text)` — calls the Rust lexer, returns `TokenRow[]`. The Rust lexer
|
|
7
8
|
is the only lexer: no host reimplements one and drifts from the grammar.
|
|
8
9
|
- `semanticLegend()` — returns the LSP semantic-tokens legend.
|
|
@@ -41,47 +42,50 @@ const rows = pg.check();
|
|
|
41
42
|
locator, catalogue row, reader option. Introspection DESCRIBEs these and
|
|
42
43
|
registers each descriptor under `key` with `registerInferredDescriptor`.
|
|
43
44
|
|
|
44
|
-
##
|
|
45
|
-
|
|
46
|
-
We use `wasm-bindgen --target web` (NOT `--target bundler`). This means consumers
|
|
47
|
-
control the `.wasm` URL resolution — works in Vite, Next.js, Webpack, Rspack, or
|
|
48
|
-
plain `new URL(...)` in a Web Worker context. `--target bundler` was rejected
|
|
49
|
-
because its output assumes the consumer's bundler resolves `.wasm` ESM imports,
|
|
50
|
-
which a republished library cannot assume of a host's Vite/Next/Webpack config.
|
|
51
|
-
|
|
52
|
-
## Consumer patterns
|
|
53
|
-
|
|
54
|
-
### Vite host
|
|
45
|
+
## Loading: the `.wasm` is an asset of this package
|
|
55
46
|
|
|
56
47
|
```typescript
|
|
57
48
|
import { initFossilWasm, tokenize } from '@fossil-lang/wasm';
|
|
58
|
-
import wasmUrl from '@fossil-lang/wasm/pkg/fossil_wasm_bg.wasm?url';
|
|
59
49
|
|
|
60
|
-
await initFossilWasm(
|
|
50
|
+
await initFossilWasm();
|
|
61
51
|
const tokens = tokenize('User := io.csv("data/people.csv")');
|
|
62
52
|
```
|
|
63
53
|
|
|
64
|
-
|
|
54
|
+
That is the whole host flow, in Vite, Next.js (webpack or Turbopack), a Web
|
|
55
|
+
Worker or any bundler that understands `new URL('…', import.meta.url)`. The glue
|
|
56
|
+
(`wasm-bindgen --target web`) locates `fossil_wasm_bg.wasm` with exactly that
|
|
57
|
+
expression, the bundler copies the file into its output under a hashed name and
|
|
58
|
+
rewrites the URL, and the browser fetches it from there. No copy script, no
|
|
59
|
+
`public/` directory, no URL to keep in sync with a version.
|
|
60
|
+
|
|
61
|
+
**Vite dev server, package installed from npm:** Vite's dependency optimizer
|
|
62
|
+
pre-bundles the package into `node_modules/.vite/deps/` without its `.wasm`, and
|
|
63
|
+
the URL then answers with `index.html`. Keep the three packages out of it —
|
|
64
|
+
`vite build` needs nothing:
|
|
65
|
+
|
|
66
|
+
```js
|
|
67
|
+
// vite.config.js
|
|
68
|
+
export default { optimizeDeps: { exclude: ['@fossil-lang/wasm', '@fossil-lang/executor', '@fossil-lang/corpus'] } };
|
|
69
|
+
```
|
|
65
70
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
71
|
+
A workspace-linked package is never pre-bundled, which is why the playground needs
|
|
72
|
+
no such line. Next.js needs none in either `next dev` or `next build`, webpack or
|
|
73
|
+
Turbopack.
|
|
69
74
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}, []);
|
|
74
|
-
```
|
|
75
|
+
`--target bundler` was rejected because it emits `import … from '*.wasm'` (the
|
|
76
|
+
ESM-integration proposal), which each bundler gates behind its own experimental
|
|
77
|
+
flag. `new URL(…, import.meta.url)` is the pattern they all support by default.
|
|
75
78
|
|
|
76
|
-
|
|
79
|
+
**Without a bundler**, pass the module yourself — `initFossilWasm(wasm)` takes the
|
|
80
|
+
glue's `InitInput` (`BufferSource`, `Response`, `URL`, `WebAssembly.Module`). Node
|
|
81
|
+
is the case: its `fetch` rejects `file://`, so hand it the bytes:
|
|
77
82
|
|
|
78
83
|
```typescript
|
|
79
|
-
|
|
80
|
-
import {
|
|
81
|
-
import wasmUrl from '@fossil-lang/wasm/pkg/fossil_wasm_bg.wasm?url';
|
|
84
|
+
import { readFile } from 'node:fs/promises';
|
|
85
|
+
import { createRequire } from 'node:module';
|
|
82
86
|
|
|
83
|
-
|
|
84
|
-
|
|
87
|
+
const path = createRequire(import.meta.url).resolve('@fossil-lang/wasm/pkg/fossil_wasm_bg.wasm');
|
|
88
|
+
await initFossilWasm(await readFile(path));
|
|
85
89
|
```
|
|
86
90
|
|
|
87
91
|
## Build
|
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Public API (one of the @fossil-lang/* packages; `git ls-files packages` is
|
|
5
5
|
* the list):
|
|
6
|
-
* - {@link initFossilWasm} —
|
|
6
|
+
* - {@link initFossilWasm} — boots the module; its `.wasm` is a bundler asset (memoised).
|
|
7
7
|
* - {@link tokenize} — calls the Rust lexer, returns TokenRow[].
|
|
8
8
|
* - {@link tokenKinds} — the legend for TokenRow.kind: variant names by index.
|
|
9
9
|
* - {@link semanticLegend} — returns the LSP SemanticTokensLegend.
|
|
@@ -16,13 +16,12 @@
|
|
|
16
16
|
* Consumer pattern (wasm-bindgen --target web):
|
|
17
17
|
*
|
|
18
18
|
* import { initFossilWasm, tokenize } from '@fossil-lang/wasm';
|
|
19
|
-
* import wasmUrl from '@fossil-lang/wasm/pkg/fossil_wasm_bg.wasm?url'; // Vite
|
|
20
19
|
*
|
|
21
|
-
* await initFossilWasm(
|
|
20
|
+
* await initFossilWasm();
|
|
22
21
|
* const tokens = tokenize('User := io.csv("data/people.csv")');
|
|
23
22
|
*/
|
|
24
23
|
export { initFossilWasm } from './load.js';
|
|
25
|
-
export type {
|
|
24
|
+
export type { InitInput } from './load.js';
|
|
26
25
|
export { start_lsp_worker, tokenize, tokenKinds, semanticLegend, FossilPlayground, refs, providers, } from './client.js';
|
|
27
26
|
export type { FileHandle } from './client.js';
|
|
28
27
|
/** One external reference a program makes — the typed lineage returned by
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAQH,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAC3C,YAAY,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAE3C,OAAO,EACL,gBAAgB,EAChB,QAAQ,EACR,UAAU,EACV,cAAc,EACd,gBAAgB,EAChB,IAAI,EACJ,SAAS,GACV,MAAM,aAAa,CAAC;AACrB,YAAY,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C;;;;4EAI4E;AAC5E,MAAM,WAAW,aAAa;IAC5B,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,GAAG,QAAQ,CAAC;CACzB;AAED;;oEAEoE;AACpE,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,IAAI,EAAE,QAAQ,GAAG,MAAM,GAAG,MAAM,CAAC;CAClC;AAED;;;;GAIG;AACH,MAAM,WAAW,QAAQ;IACvB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,QAAQ,CAAC;IAChB,QAA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B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Public API (one of the @fossil-lang/* packages; `git ls-files packages` is
|
|
5
5
|
* the list):
|
|
6
|
-
* - {@link initFossilWasm} —
|
|
6
|
+
* - {@link initFossilWasm} — boots the module; its `.wasm` is a bundler asset (memoised).
|
|
7
7
|
* - {@link tokenize} — calls the Rust lexer, returns TokenRow[].
|
|
8
8
|
* - {@link tokenKinds} — the legend for TokenRow.kind: variant names by index.
|
|
9
9
|
* - {@link semanticLegend} — returns the LSP SemanticTokensLegend.
|
|
@@ -16,9 +16,8 @@
|
|
|
16
16
|
* Consumer pattern (wasm-bindgen --target web):
|
|
17
17
|
*
|
|
18
18
|
* import { initFossilWasm, tokenize } from '@fossil-lang/wasm';
|
|
19
|
-
* import wasmUrl from '@fossil-lang/wasm/pkg/fossil_wasm_bg.wasm?url'; // Vite
|
|
20
19
|
*
|
|
21
|
-
* await initFossilWasm(
|
|
20
|
+
* await initFossilWasm();
|
|
22
21
|
* const tokens = tokenize('User := io.csv("data/people.csv")');
|
|
23
22
|
*/
|
|
24
23
|
// The wasm-bindgen glue (`../pkg/fossil_wasm.js`) is imported ONLY from leaf
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,6EAA6E;AAC7E,iFAAiF;AACjF,iFAAiF;AACjF,2EAA2E;AAC3E,yEAAyE;AACzE,4EAA4E;AAC5E,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAG3C,OAAO,EACL,gBAAgB,EAChB,QAAQ,EACR,UAAU,EACV,cAAc,EACd,gBAAgB,EAChB,IAAI,EACJ,SAAS,GACV,MAAM,aAAa,CAAC"}
|
package/dist/load.d.ts
CHANGED
|
@@ -1,27 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
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
5
|
* {@link tokenize}, {@link semanticLegend}, or instantiating
|
|
18
6
|
* {@link FossilPlayground}. Memoised — subsequent calls return the same promise.
|
|
19
7
|
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
8
|
+
* **Called with nothing, the module finds its own `.wasm`.** The glue resolves
|
|
9
|
+
* `new URL('fossil_wasm_bg.wasm', import.meta.url)`, which is the pattern Vite,
|
|
10
|
+
* webpack 5 and Turbopack all recognise and emit as an asset — so a bundled host
|
|
11
|
+
* writes `await initFossilWasm()` and copies nothing.
|
|
12
|
+
*
|
|
13
|
+
* `wasm` is for the host with no bundler to do that: Node, whose `fetch` rejects
|
|
14
|
+
* `file://`, hands the bytes (`BufferSource`) or a `Response`.
|
|
23
15
|
*/
|
|
24
|
-
export declare function initFossilWasm(
|
|
16
|
+
export declare function initFossilWasm(wasm?: InitInput): Promise<unknown>;
|
|
25
17
|
/**
|
|
26
18
|
* For tests + hot-reload — reset the memoised promise. NOT exported from the
|
|
27
19
|
* package index (test-internal helper).
|
package/dist/load.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"load.d.ts","sourceRoot":"","sources":["../src/load.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"load.d.ts","sourceRoot":"","sources":["../src/load.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAEvD,YAAY,EAAE,SAAS,EAAE,CAAC;AAI1B;;;;;;;;;;;;GAYG;AACH,wBAAgB,cAAc,CAAC,IAAI,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC,OAAO,CAAC,CAMjE;AAED;;;GAGG;AACH,wBAAgB,eAAe,IAAI,IAAI,CAEtC"}
|
package/dist/load.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
// '../pkg/fossil_wasm.js' is a wasm-bindgen --target web output emitted by `pnpm run build:wasm`.
|
|
2
|
-
// It is gitignored (
|
|
3
|
-
//
|
|
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';
|
|
6
5
|
let _initPromise = null;
|
|
7
6
|
/**
|
|
@@ -9,17 +8,18 @@ let _initPromise = null;
|
|
|
9
8
|
* {@link tokenize}, {@link semanticLegend}, or instantiating
|
|
10
9
|
* {@link FossilPlayground}. Memoised — subsequent calls return the same promise.
|
|
11
10
|
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
11
|
+
* **Called with nothing, the module finds its own `.wasm`.** The glue resolves
|
|
12
|
+
* `new URL('fossil_wasm_bg.wasm', import.meta.url)`, which is the pattern Vite,
|
|
13
|
+
* webpack 5 and Turbopack all recognise and emit as an asset — so a bundled host
|
|
14
|
+
* writes `await initFossilWasm()` and copies nothing.
|
|
15
|
+
*
|
|
16
|
+
* `wasm` is for the host with no bundler to do that: Node, whose `fetch` rejects
|
|
17
|
+
* `file://`, hands the bytes (`BufferSource`) or a `Response`.
|
|
15
18
|
*/
|
|
16
|
-
export function initFossilWasm(
|
|
19
|
+
export function initFossilWasm(wasm) {
|
|
17
20
|
if (!_initPromise) {
|
|
18
|
-
//
|
|
19
|
-
|
|
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 });
|
|
21
|
+
// The object form: the positional one still works but logs a deprecation warning.
|
|
22
|
+
_initPromise = init(wasm === undefined ? undefined : { module_or_path: wasm });
|
|
23
23
|
}
|
|
24
24
|
return _initPromise;
|
|
25
25
|
}
|
package/dist/load.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"load.js","sourceRoot":"","sources":["../src/load.ts"],"names":[],"mappings":"AAAA,kGAAkG;AAClG,
|
|
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;AAKzC,IAAI,YAAY,GAA4B,IAAI,CAAC;AAEjD;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,cAAc,CAAC,IAAgB;IAC7C,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,kFAAkF;QAClF,YAAY,GAAG,IAAI,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,cAAc,EAAE,IAAI,EAAE,CAAC,CAAC;IACjF,CAAC;IACD,OAAO,YAAY,CAAC;AACtB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,eAAe;IAC7B,YAAY,GAAG,IAAI,CAAC;AACtB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fossil-lang/wasm",
|
|
3
|
-
"version": "0.3.0-alpha.
|
|
3
|
+
"version": "0.3.0-alpha.8",
|
|
4
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.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
],
|
|
34
34
|
"sideEffects": false,
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@fossil-lang/types": "0.3.0-alpha.
|
|
36
|
+
"@fossil-lang/types": "0.3.0-alpha.8"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"typescript": "^5.6.0",
|