@swmansion/popcorn 0.3.2 → 0.4.0-next.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.
Files changed (47) hide show
  1. package/LICENSE +1 -1
  2. package/NOTICE +12 -0
  3. package/README.md +78 -2
  4. package/dist/beam.d.ts +10 -0
  5. package/dist/errors.d.ts +96 -39
  6. package/dist/etf.d.ts +38 -0
  7. package/dist/events.d.ts +82 -0
  8. package/dist/index.d.ts +7 -3
  9. package/dist/index.mjs +1287 -2
  10. package/dist/plugins/beam_tools/lib/popcorn/beam_tools/beam_patcher.ex +184 -0
  11. package/dist/plugins/beam_tools/lib/popcorn/beam_tools/cli.ex +74 -0
  12. package/dist/plugins/beam_tools/lib/popcorn/beam_tools/packager.ex +540 -0
  13. package/dist/plugins/beam_tools/mix.exs +16 -0
  14. package/dist/plugins/beam_tools/patches/kernel/prim_tty.erl +13 -0
  15. package/dist/plugins/beam_tools/patches/stdlib/beam_lib.erl +27 -0
  16. package/dist/plugins/esbuild.d.ts +10 -2
  17. package/dist/plugins/esbuild.mjs +39 -34
  18. package/dist/plugins/rollup.d.ts +10 -2
  19. package/dist/plugins/rollup.mjs +46 -25
  20. package/dist/plugins/shared.d.ts +54 -4
  21. package/dist/plugins/shared.mjs +207 -0
  22. package/dist/plugins/vite.d.ts +17 -2
  23. package/dist/plugins/vite.mjs +201 -75
  24. package/dist/popcorn.d.ts +237 -110
  25. package/dist/runtimes/core/beam.emu.mjs +141 -0
  26. package/dist/runtimes/core/beam.mjs +141 -0
  27. package/dist/runtimes/core/beam.wasm +0 -0
  28. package/dist/runtimes/core/manifest.json +1 -0
  29. package/dist/runtimes/crypto/beam.emu.mjs +520 -0
  30. package/dist/runtimes/crypto/beam.mjs +520 -0
  31. package/dist/runtimes/crypto/beam.wasm +0 -0
  32. package/dist/runtimes/crypto/manifest.json +1 -0
  33. package/dist/tar.d.ts +4 -0
  34. package/dist/types.d.ts +108 -63
  35. package/dist/utils.d.ts +7 -0
  36. package/dist/worker.d.ts +1 -0
  37. package/dist/worker.mjs +765 -0
  38. package/package.json +20 -28
  39. package/dist/AtomVM.mjs +0 -7992
  40. package/dist/AtomVM.wasm +0 -0
  41. package/dist/bridge.d.ts +0 -22
  42. package/dist/bridge.mjs +0 -66
  43. package/dist/errors.mjs +0 -55
  44. package/dist/iframe.d.ts +0 -1
  45. package/dist/iframe.mjs +0 -215
  46. package/dist/popcorn.mjs +0 -381
  47. package/dist/types.mjs +0 -25
Binary file
@@ -0,0 +1 @@
1
+ {"vm":{"version":"29.0.6","capabilities":{"crypto":true},"preloaded":["atomics","counters","erl_init","erl_prim_loader","erl_tracer","erlang","erts_code_purger","erts_dirty_process_signal_handler","erts_internal","erts_literal_area_collector","erts_trace_cleaner","init","persistent_term","prim_buffer","prim_eval","prim_file","prim_inet","prim_net","prim_socket","prim_zip","socket_registry","wasm","zlib"]}}
package/dist/tar.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ type OnDir = (path: string) => void;
2
+ type OnFile = (path: string, data: Uint8Array<ArrayBuffer>) => void;
3
+ export declare function extractTar(data: Uint8Array, onDir: OnDir, onFile: OnFile): void;
4
+ export {};
package/dist/types.d.ts CHANGED
@@ -1,77 +1,122 @@
1
- export declare const INIT_VM_TIMEOUT_MS = 30000;
2
- export declare const CALL_TIMEOUT_MS = 60000;
3
- export declare const HEARTBEAT_TIMEOUT_MS = 60000;
4
- export declare const HEARTBEAT_INTERVAL_MS = 500;
5
- export declare const MAX_RELOAD_N = 3;
6
- export type AnySerializable = any;
7
- export type ElixirEvent = {
8
- eventName: string;
9
- payload: AnySerializable;
1
+ type CreateModuleFn<Mod> = (overrides?: Partial<Mod>) => Promise<Mod>;
2
+ /**
3
+ * A message value. JavaScript sends use these BEAM conversions:
4
+ *
5
+ * - Strings become UTF-8 binaries. Booleans become `true` and `false` atoms.
6
+ * - Integers become integers. Other finite numbers become floats.
7
+ * - Arrays become lists.
8
+ * - Plain objects become maps with binary string keys.
9
+ * - `null` and `undefined` become the `nil` atom.
10
+ * - `atom()` and `tuple()` create atoms and tuples. PIDs retain their BEAM identity.
11
+ *
12
+ * Cycles, class instances, functions, symbols, bigints, unsafe integers, and non-finite numbers cause `bridge:unserializable`.
13
+ */
14
+ export type AnyValue = unknown;
15
+ declare const pidBrand: unique symbol;
16
+ /**
17
+ * An opaque BEAM process identifier received from the VM.
18
+ *
19
+ * Valid only with the Popcorn instance and boot that produced it.
20
+ */
21
+ export type Pid = {
22
+ readonly [pidBrand]: true;
10
23
  };
11
- export type CallRequest = {
12
- requestId: number;
13
- process: string;
14
- args: AnySerializable;
15
- };
16
- export type CastRequest = {
17
- requestId: number;
18
- process: string;
19
- args: AnySerializable;
20
- };
21
- /** Messages sent from parent window to iframe */
22
- export type IframeRequest = {
23
- type: "popcorn-call";
24
- value: CallRequest;
24
+ /** Internal wire target. The public `send` accepts `string | Pid` instead. */
25
+ export type BeamTarget = {
26
+ name: string;
25
27
  } | {
26
- type: "popcorn-cast";
27
- value: CastRequest;
28
+ pid: Uint8Array;
28
29
  };
29
- export type CallResponse = {
30
- requestId: number;
31
- error?: AnySerializable;
32
- data?: AnySerializable;
30
+ export type BeamSendPayload = {
31
+ target: BeamTarget;
32
+ etf: Uint8Array<ArrayBuffer>;
33
33
  };
34
- export type CallAck = {
35
- requestId: number;
34
+ export type BeamBootOptions = {
35
+ otpAssetsRoot: string;
36
+ /**
37
+ * Emulator flags before `--`.
38
+ *
39
+ * Overrides the default scheduler flags.
40
+ * Use `schedulers()` to set thread counts.
41
+ */
42
+ emulatorArgs?: string[];
43
+ /** Erlang arguments after the boot arguments, such as `-eval` expressions. */
44
+ extraArgs?: string[];
45
+ /** VM environment variables. */
46
+ env?: Record<string, string>;
47
+ ttySize: TtySize;
48
+ createModule: CreateModuleFn<EmscriptenModule>;
49
+ emit: (event: BeamEvent) => void;
36
50
  };
37
- /** Messages sent from iframe to parent window */
38
- export type IframeResponse = {
39
- type: "popcorn-event";
40
- value: ElixirEvent;
51
+ export type BeamEvent = {
52
+ type: "otp:stdout";
53
+ payload: Uint8Array;
54
+ } | {
55
+ type: "otp:stderr";
56
+ payload: Uint8Array;
41
57
  } | {
42
- type: "popcorn-call";
43
- value: CallResponse;
58
+ type: "otp:stdin-consumed";
59
+ payload: number;
44
60
  } | {
45
- type: "popcorn-callAck";
46
- value: CallAck;
61
+ type: "otp:error";
62
+ payload: OtpErrorPayload;
47
63
  } | {
48
- type: "popcorn-stdout";
49
- value: string;
64
+ type: "otp:message";
65
+ payload: AnyValue;
50
66
  } | {
51
- type: "popcorn-stderr";
52
- value: string;
67
+ type: "otp:run_js";
68
+ payload: RunJsRequest;
69
+ } | {
70
+ type: "otp:tracked-value-delete";
71
+ payload: number;
72
+ };
73
+ export type RunJsRequest = {
74
+ code: string;
75
+ args: AnyValue;
76
+ replyTo: Uint8Array;
77
+ return: "value" | "ref";
78
+ };
79
+ /**
80
+ * VM shutdown notification.
81
+ *
82
+ * An `exit` carries a status code, including zero for a normal exit.
83
+ */
84
+ export type OtpErrorPayload = {
85
+ kind: "abort";
86
+ data: string;
53
87
  } | {
54
- type: "popcorn-heartbeat";
55
- value: null;
88
+ kind: "error";
89
+ data: string;
56
90
  } | {
57
- type: "popcorn-reload";
58
- value: string | null;
91
+ kind: "exit";
92
+ data: number;
59
93
  };
60
- /** Union of all messages (requests and responses) */
61
- export type Message = IframeRequest | IframeResponse;
62
- export declare const MESSAGES: {
63
- readonly EVENT: "popcorn-event";
64
- readonly CALL: "popcorn-call";
65
- readonly CAST: "popcorn-cast";
66
- readonly CALL_ACK: "popcorn-callAck";
67
- readonly STDOUT: "popcorn-stdout";
68
- readonly STDERR: "popcorn-stderr";
69
- readonly HEARTBEAT: "popcorn-heartbeat";
70
- readonly RELOAD: "popcorn-reload";
94
+ /** Terminal dimensions in character cells, from 1 to 65,535 per dimension. */
95
+ export type TtySize = {
96
+ columns: number;
97
+ rows: number;
71
98
  };
72
- export declare const EVENT_NAMES: {
73
- readonly ELIXIR_READY: "popcorn_elixir_ready";
74
- readonly APP_READY: "popcorn_app_ready";
75
- readonly SET_DEFAULT_RECEIVER: "popcorn_set_default_receiver";
99
+ /** Emscripten Module interface (subset exposed after instantiation). */
100
+ export type EmscriptenModule = {
101
+ ENV: Record<string, string>;
102
+ FS_mkdirTree: (path: string) => void;
103
+ FS_createDataFile: (parent: string, name: string | null, data: Uint8Array, canRead: boolean, canWrite: boolean, canOwn: boolean) => void;
104
+ HEAPU8: Uint8Array;
105
+ ccall: (ident: string, returnType: string | null, argTypes: string[], args: unknown[]) => AnyValue;
106
+ print: (text: string) => void;
107
+ printErr: (text: string) => void;
108
+ onExit: (code: number) => void;
109
+ onAbort: (text: string) => void;
110
+ arguments: string[];
111
+ preRun: ((mod: EmscriptenModule) => void)[];
112
+ _malloc: (size: number) => number;
113
+ _free: (ptr: number) => void;
114
+ onBeamMessage?: (text: string) => void | Promise<void>;
115
+ onError?: (text: string) => void | Promise<void>;
116
+ onStdinConsumed?: (size: number) => void;
117
+ onTrackedValueDelete?: (key: number) => void;
118
+ onTtyChunk?: (fd: number, chunk: Uint8Array) => void;
119
+ addRunDependency: (id: string) => void;
120
+ removeRunDependency: (id: string) => void;
76
121
  };
77
- export declare function isMessageType(type: string): type is Message["type"];
122
+ export {};
@@ -0,0 +1,7 @@
1
+ export declare function dirname(path: string): string;
2
+ export declare function fetchBinary(url: string): Promise<Uint8Array | null>;
3
+ export declare function fetchJson<T>(url: string): Promise<T | null>;
4
+ export declare function base64ToBytes(b64: string): Uint8Array;
5
+ export declare function check(ok: boolean, msg?: string): asserts ok;
6
+ export declare function unreachable(): never;
7
+ export declare function objectWithKeys<K extends string>(value: unknown, keys: K[]): null | Record<K, unknown>;
@@ -0,0 +1 @@
1
+ export {};