@glassly/jspolyfill 0.4.3 → 0.4.4-beta.1319
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 +36 -17
- package/package.json +1 -1
- package/src/startup.ts +2 -1
- package/src/types.ts +2 -1
package/README.md
CHANGED
|
@@ -2,30 +2,49 @@
|
|
|
2
2
|
|
|
3
3
|
The GlasslyJS polyfill bundle. Glassly runs each miniapp in its own bare JS
|
|
4
4
|
context (JavaScriptCore on iOS, QuickJS on Android); this package provides the
|
|
5
|
-
browser-like standard library those contexts lack
|
|
6
|
-
`
|
|
7
|
-
`
|
|
8
|
-
|
|
9
|
-
`crypto.
|
|
5
|
+
browser-like standard library those contexts lack: `console`, timers
|
|
6
|
+
(`setTimeout`, `setInterval`, `queueMicrotask`), `fetch`, `WebSocket`,
|
|
7
|
+
`localStorage`, `AbortController` and `AbortSignal`, `TextEncoder` and
|
|
8
|
+
`TextDecoder`, `atob` and `btoa`, `crypto.getRandomValues` and
|
|
9
|
+
`crypto.randomUUID`, implemented over a single `__dispatch` native bridge, plus
|
|
10
|
+
the `__deliver` hook and the `ready` signal the host runtime relies on.
|
|
11
|
+
`crypto.subtle` is a stub: every call throws an error saying it is not
|
|
12
|
+
implemented.
|
|
13
|
+
|
|
14
|
+
You don't import or install this package yourself: it's installed with
|
|
15
|
+
[`@glassly/crust`](https://www.npmjs.com/package/@glassly/crust), which
|
|
16
|
+
[`@glassly/engine`](https://www.npmjs.com/package/@glassly/engine) depends on.
|
|
17
|
+
Crust's Android build reads the bundle from `../../jspolyfill/assets`, relative
|
|
18
|
+
to crust's `android/` folder, so this package has to sit next to crust in
|
|
19
|
+
`node_modules/@glassly/`. Crust's iOS pod ships a mirror of the bundle, and the
|
|
20
|
+
engine passes it to each miniapp context at spawn.
|
|
21
|
+
|
|
22
|
+
## Build
|
|
23
|
+
|
|
24
|
+
`assets/startup.js` is generated from `src/startup.ts` and committed. After
|
|
25
|
+
editing `src/startup.ts`, install dependencies and run this from
|
|
26
|
+
`mobile/modules/jspolyfill`:
|
|
10
27
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
and the engine injects it into each miniapp context at spawn.
|
|
28
|
+
```sh
|
|
29
|
+
bun run build
|
|
30
|
+
```
|
|
15
31
|
|
|
16
|
-
|
|
32
|
+
The build bundles `src/startup.ts` with esbuild into `dist/startup.js`, copies
|
|
33
|
+
it to `assets/startup.js` (commit this file), and mirrors it to
|
|
34
|
+
`../crust/ios/Resources/startup.js` (gitignored; the crust podspec reads it).
|
|
35
|
+
The `prepare` script runs the same build.
|
|
17
36
|
|
|
18
|
-
|
|
19
|
-
[`@glassly/engine`](https://www.npmjs.com/package/@glassly/engine) /
|
|
20
|
-
`@glassly/crust`. For direct use:
|
|
37
|
+
## Test
|
|
21
38
|
|
|
22
39
|
```sh
|
|
23
|
-
|
|
40
|
+
bun run test
|
|
24
41
|
```
|
|
25
42
|
|
|
26
|
-
|
|
43
|
+
The suite (`src/startup.test.ts`) loads `dist/startup.js` into a Node `vm`
|
|
44
|
+
context, so run `bun run build` first. `bun run check` at the repo root runs
|
|
45
|
+
the suite when a branch changes this module, and it does not build first, so
|
|
46
|
+
build before you run it. Jest in `mobile/` ignores this module.
|
|
27
47
|
|
|
28
48
|
## Part of Glassly
|
|
29
49
|
|
|
30
|
-
Source lives in the
|
|
31
|
-
under `mobile/modules/jspolyfill`. Issues and contributions welcome there.
|
|
50
|
+
Source lives in the Glassly repository under `mobile/modules/jspolyfill`.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@glassly/jspolyfill",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.4-beta.1319",
|
|
4
4
|
"description": "JSRuntime polyfill bundle — installed into each per-miniapp JSContext (iOS-JSC, Android-QuickJS) at spawn time. Provides browser-like globals (console, timers, fetch, WebSocket, localStorage, crypto.subtle) over a single __dispatch native bridge, plus the __deliver / signalReady plumbing the host runtime relies on.",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"types": "src/index.ts",
|
package/src/startup.ts
CHANGED
|
@@ -433,7 +433,8 @@ declare const __nativeClearTimer: (token: number) => void
|
|
|
433
433
|
}
|
|
434
434
|
if (env.kind === "ws-event") {
|
|
435
435
|
const wsHook = (g as Record<string, unknown>).__deliverWebSocketEvent as
|
|
436
|
-
((sid: string, type: string, payload: Record<string, unknown>) => void)
|
|
436
|
+
| ((sid: string, type: string, payload: Record<string, unknown>) => void)
|
|
437
|
+
| undefined
|
|
437
438
|
const sid = (env as {sid?: string}).sid
|
|
438
439
|
const wsType = (env as {wsType?: string}).wsType
|
|
439
440
|
if (typeof wsHook === "function" && typeof sid === "string" && typeof wsType === "string") {
|
package/src/types.ts
CHANGED
|
@@ -35,7 +35,8 @@ export interface DispatchError {
|
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
export type DispatchResponse =
|
|
38
|
-
{reqId: string; ok: true; result: unknown}
|
|
38
|
+
| {reqId: string; ok: true; result: unknown}
|
|
39
|
+
| {reqId: string; ok: false; error: DispatchError}
|
|
39
40
|
|
|
40
41
|
export type DeliverEnvelope =
|
|
41
42
|
| {kind: "init"; sessionId: string}
|