@swmansion/popcorn 0.4.0-next.4 → 0.4.0-next.5
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 +4 -4
- package/dist/index.mjs +3 -1
- package/dist/plugins/vite.mjs +6 -1
- package/dist/popcorn.d.ts +4 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@ Run Elixir in a browser with OTP/BEAM compiled to WebAssembly.
|
|
|
4
4
|
This prerelease replaces the AtomVM runtime used by Popcorn 0.3.x.
|
|
5
5
|
|
|
6
6
|
Start with the
|
|
7
|
-
[versioned Popcorn guide](https://popcorn.hexdocs.pm/0.4.0-next.
|
|
7
|
+
[versioned Popcorn guide](https://popcorn.hexdocs.pm/0.4.0-next.5/introduction.html).
|
|
8
8
|
It includes a complete Mix and Vite tutorial.
|
|
9
9
|
|
|
10
10
|
## Install
|
|
@@ -13,12 +13,12 @@ It includes a complete Mix and Vite tutorial.
|
|
|
13
13
|
npm install @swmansion/popcorn@next
|
|
14
14
|
```
|
|
15
15
|
|
|
16
|
-
Add `{:popcorn, "0.4.0-next.
|
|
16
|
+
Add `{:popcorn, "0.4.0-next.5"}` to your Elixir application's dependencies.
|
|
17
17
|
Run `mix deps.get` before building the JavaScript application. The bundler
|
|
18
18
|
plugins invoke Mix locally to compile and package application and
|
|
19
19
|
standard-library code.
|
|
20
20
|
|
|
21
|
-
Use the toolchain pinned in [mise.toml](https://github.com/software-mansion/popcorn/blob/v0.4.0-next.
|
|
21
|
+
Use the toolchain pinned in [mise.toml](https://github.com/software-mansion/popcorn/blob/v0.4.0-next.5/mise.toml).
|
|
22
22
|
The packager checks host OTP compatibility against the selected runtime's manifest.
|
|
23
23
|
|
|
24
24
|
## Configure Vite
|
|
@@ -94,4 +94,4 @@ Serve `.wasm` as `application/wasm`. Serve compressed `.tar.gz` files with `Cont
|
|
|
94
94
|
The package also emits uncompressed tar files and Brotli variants. Brotli uses standard effort by default. Set `brotliEffort: "max"` for maximum compression in release builds.
|
|
95
95
|
|
|
96
96
|
The JavaScript bridge currently requires a Content Security Policy that permits `unsafe-eval`.
|
|
97
|
-
See the [versioned Elixir API](https://popcorn.hexdocs.pm/0.4.0-next.
|
|
97
|
+
See the [versioned Elixir API](https://popcorn.hexdocs.pm/0.4.0-next.5/) for interoperability details.
|
package/dist/index.mjs
CHANGED
|
@@ -636,6 +636,8 @@ class Popcorn {
|
|
|
636
636
|
};
|
|
637
637
|
this.ttySize = { ...ttySize };
|
|
638
638
|
this.output = resolveOutputHandlers(opts);
|
|
639
|
+
if (opts.onEvent)
|
|
640
|
+
this.onEvent(opts.onEvent);
|
|
639
641
|
this.spawnWorker();
|
|
640
642
|
}
|
|
641
643
|
spawnWorker() {
|
|
@@ -650,7 +652,7 @@ class Popcorn {
|
|
|
650
652
|
/**
|
|
651
653
|
* Creates an instance and waits for {@link boot}.
|
|
652
654
|
*
|
|
653
|
-
*
|
|
655
|
+
* Use `opts.onEvent` to receive messages sent during startup.
|
|
654
656
|
*
|
|
655
657
|
* @returns Ok tuple or `runtime:eval-unavailable` if the page blocks JavaScript evaluation.
|
|
656
658
|
*/
|
package/dist/plugins/vite.mjs
CHANGED
|
@@ -43,6 +43,7 @@ function popcorn(options) {
|
|
|
43
43
|
let dirty = false;
|
|
44
44
|
let outDir;
|
|
45
45
|
let assetsDir = "assets";
|
|
46
|
+
let workerDerivedOtpRoot = `/@fs${distDir}/otp/`;
|
|
46
47
|
// Dev/preview: pack once at server startup, then re-pack lazily after the
|
|
47
48
|
// app's compiled beams change. A single in-flight promise dedupes concurrent
|
|
48
49
|
// requests; a change during a re-pack re-sets `dirty` so it isn't lost.
|
|
@@ -78,7 +79,7 @@ function popcorn(options) {
|
|
|
78
79
|
return;
|
|
79
80
|
}
|
|
80
81
|
const requestPath = decodeURIComponent(new URL(url, "http://localhost").pathname);
|
|
81
|
-
const requestRoot = [`/${assetsDir}/otp/`,
|
|
82
|
+
const requestRoot = [`/${assetsDir}/otp/`, workerDerivedOtpRoot].find((root) => requestPath.startsWith(root));
|
|
82
83
|
if (requestRoot === undefined) {
|
|
83
84
|
next();
|
|
84
85
|
return;
|
|
@@ -146,6 +147,10 @@ function popcorn(options) {
|
|
|
146
147
|
config.server.fs.allow.push(distDir);
|
|
147
148
|
outDir = resolve(config.root, config.build.outDir);
|
|
148
149
|
assetsDir = config.build.assetsDir;
|
|
150
|
+
const servedDistDir = isUnder(config.root, distDir)
|
|
151
|
+
? `/${relative(config.root, distDir)}`
|
|
152
|
+
: `/@fs${distDir}`;
|
|
153
|
+
workerDerivedOtpRoot = `${servedDistDir}/otp/`;
|
|
149
154
|
},
|
|
150
155
|
async configureServer(server) {
|
|
151
156
|
const rootDir = resolve(options.rootDir);
|
package/dist/popcorn.d.ts
CHANGED
|
@@ -70,6 +70,8 @@ export type PopcornOpts<Output extends TtyOutput = "text"> = {
|
|
|
70
70
|
* Defaults to console output.
|
|
71
71
|
*/
|
|
72
72
|
onError?: (event: OtpErrorPayload) => void;
|
|
73
|
+
/** Receives BEAM message payloads, including messages sent during startup. */
|
|
74
|
+
onEvent?: (event: PopcornEvent) => void;
|
|
73
75
|
/**
|
|
74
76
|
* Module worker URL.
|
|
75
77
|
*
|
|
@@ -97,9 +99,7 @@ export type GenServer = {
|
|
|
97
99
|
/**
|
|
98
100
|
* Calls a GenServer by registered name or {@link Pid} and waits for its reply.
|
|
99
101
|
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
* @param opts - `timeoutMs` defaults to 5 000 ms. `proxy` allows to select another registered proxy.
|
|
102
|
+
* @param opts - `timeoutMs` defaults to 5 000 ms. `proxy` allows to select another registered proxy (see `Popcorn.Proxy`).
|
|
103
103
|
* @returns A {@link Result} with the reply or a bridge, VM, timeout, or GenServer error.
|
|
104
104
|
*
|
|
105
105
|
* GenServer failures use `genserver:noproc`, `genserver:exit`, or `genserver:unserializable`.
|
|
@@ -154,7 +154,7 @@ export declare class Popcorn<Output extends TtyOutput = "text"> {
|
|
|
154
154
|
/**
|
|
155
155
|
* Creates an instance and waits for {@link boot}.
|
|
156
156
|
*
|
|
157
|
-
*
|
|
157
|
+
* Use `opts.onEvent` to receive messages sent during startup.
|
|
158
158
|
*
|
|
159
159
|
* @returns Ok tuple or `runtime:eval-unavailable` if the page blocks JavaScript evaluation.
|
|
160
160
|
*/
|