@swmansion/popcorn 0.3.0-rc1 → 0.3.0-rc2
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/AtomVM.mjs +2 -2
- package/dist/AtomVM.wasm +0 -0
- package/dist/iframe.mjs +13 -11
- package/dist/popcorn.d.ts +3 -3
- package/dist/popcorn.mjs +8 -9
- package/package.json +1 -1
package/dist/AtomVM.mjs
CHANGED
|
@@ -56,7 +56,7 @@ if (ENVIRONMENT_IS_PTHREAD) {
|
|
|
56
56
|
|
|
57
57
|
// --pre-jses are emitted after the Module integration code, so that they can
|
|
58
58
|
// refer to Module (if they choose; they can also define Module)
|
|
59
|
-
// include: /tmp/atomvm-build-swm.
|
|
59
|
+
// include: /tmp/atomvm-build-swm.2gQpIGg/atomvm/src/platforms/emscripten/src/atomvm.pre.js
|
|
60
60
|
/*
|
|
61
61
|
* This file is part of AtomVM.
|
|
62
62
|
*
|
|
@@ -128,7 +128,7 @@ function ensureValidResult(result) {
|
|
|
128
128
|
throw new Error(message);
|
|
129
129
|
}
|
|
130
130
|
|
|
131
|
-
// end include: /tmp/atomvm-build-swm.
|
|
131
|
+
// end include: /tmp/atomvm-build-swm.2gQpIGg/atomvm/src/platforms/emscripten/src/atomvm.pre.js
|
|
132
132
|
var arguments_ = [];
|
|
133
133
|
|
|
134
134
|
var thisProgram = "./this.program";
|
package/dist/AtomVM.wasm
CHANGED
|
Binary file
|
package/dist/iframe.mjs
CHANGED
|
@@ -32,14 +32,13 @@ class TrackedValue {
|
|
|
32
32
|
}
|
|
33
33
|
globalThis.TrackedValue = TrackedValue;
|
|
34
34
|
async function initVm() {
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
await startVm(bundle);
|
|
35
|
+
const bundlePaths = Array.from(document.querySelectorAll('meta[name^="bundle-path-"]'), (el) => el.content);
|
|
36
|
+
const bundles = await Promise.all(bundlePaths.map(async (p) => {
|
|
37
|
+
const resp = await fetch(p);
|
|
38
|
+
const buf = await resp.arrayBuffer();
|
|
39
|
+
return new Int8Array(buf);
|
|
40
|
+
}));
|
|
41
|
+
await startVm(bundles);
|
|
43
42
|
window.addEventListener("message", async ({ data }) => {
|
|
44
43
|
const type = data.type;
|
|
45
44
|
if (type === MESSAGES.CALL) {
|
|
@@ -51,15 +50,18 @@ async function initVm() {
|
|
|
51
50
|
});
|
|
52
51
|
setInterval(() => sendIframeResponse(MESSAGES.HEARTBEAT, null), HEARTBEAT_INTERVAL_MS);
|
|
53
52
|
}
|
|
54
|
-
async function startVm(
|
|
53
|
+
async function startVm(avmBundles) {
|
|
54
|
+
const bundleFilePaths = avmBundles.map((_, i) => `/data/bundle-${i}.avm`);
|
|
55
55
|
const moduleInstance = await init({
|
|
56
56
|
preRun: [
|
|
57
57
|
function ({ FS }) {
|
|
58
58
|
FS.mkdir("/data");
|
|
59
|
-
|
|
59
|
+
avmBundles.forEach((bundle, i) => {
|
|
60
|
+
FS.writeFile(bundleFilePaths[i], bundle);
|
|
61
|
+
});
|
|
60
62
|
},
|
|
61
63
|
],
|
|
62
|
-
arguments:
|
|
64
|
+
arguments: bundleFilePaths,
|
|
63
65
|
print(text) {
|
|
64
66
|
sendIframeResponse(MESSAGES.STDOUT, text);
|
|
65
67
|
},
|
package/dist/popcorn.d.ts
CHANGED
|
@@ -7,8 +7,8 @@ export type { PopcornErrorCode, PopcornInternalErrorCode };
|
|
|
7
7
|
export type PopcornInitOptions = {
|
|
8
8
|
/** DOM element to mount an iframe */
|
|
9
9
|
container?: HTMLElement;
|
|
10
|
-
/**
|
|
11
|
-
|
|
10
|
+
/** Paths to compiled Elixir bundles (`.avm` files). */
|
|
11
|
+
bundlePaths?: string[];
|
|
12
12
|
/** Handler for stderr messages. */
|
|
13
13
|
onStderr?: (message: string) => void;
|
|
14
14
|
/** Handler for stdout messages. */
|
|
@@ -59,7 +59,7 @@ export declare class Popcorn {
|
|
|
59
59
|
private bridge;
|
|
60
60
|
private bridgeConfig;
|
|
61
61
|
private debug;
|
|
62
|
-
private
|
|
62
|
+
private bundleURLs;
|
|
63
63
|
private state;
|
|
64
64
|
private defaultReceiver;
|
|
65
65
|
private requestId;
|
package/dist/popcorn.mjs
CHANGED
|
@@ -14,7 +14,7 @@ class Popcorn {
|
|
|
14
14
|
bridge = null;
|
|
15
15
|
bridgeConfig;
|
|
16
16
|
debug = false;
|
|
17
|
-
|
|
17
|
+
bundleURLs;
|
|
18
18
|
state = { status: "uninitialized" };
|
|
19
19
|
defaultReceiver = null;
|
|
20
20
|
requestId = 0;
|
|
@@ -30,15 +30,14 @@ class Popcorn {
|
|
|
30
30
|
constructor(params, token) {
|
|
31
31
|
if (token !== INIT_TOKEN)
|
|
32
32
|
throwError({ t: "private_constructor" });
|
|
33
|
-
const
|
|
34
|
-
|
|
33
|
+
const bundlePaths = params.bundlePaths ?? ["/bundle.avm"];
|
|
34
|
+
this.bundleURLs = bundlePaths.map((p) => new URL(p, import.meta.url).href);
|
|
35
35
|
this.onReloadCallback = params.onReload ?? noop;
|
|
36
36
|
this.debug = params.debug ?? false;
|
|
37
|
-
this.bundleURL = bundleURL.href;
|
|
38
37
|
this.bridgeConfig = {
|
|
39
38
|
container: params.container,
|
|
40
39
|
script: { url: IFRAME_URL, entrypoint: "initVm" },
|
|
41
|
-
config:
|
|
40
|
+
config: Object.fromEntries(this.bundleURLs.map((url, i) => [`bundle-path-${i}`, url])),
|
|
42
41
|
debug: true,
|
|
43
42
|
onMessage: this.iframeHandler.bind(this),
|
|
44
43
|
};
|
|
@@ -61,10 +60,10 @@ class Popcorn {
|
|
|
61
60
|
static async init(options) {
|
|
62
61
|
const { container, ...constructorParams } = options;
|
|
63
62
|
const containerWithDefault = container ?? document.documentElement;
|
|
64
|
-
const
|
|
65
|
-
? constructorParams.
|
|
66
|
-
: await resolveBundleURL("/bundle.avm", "/assets/bundle.avm");
|
|
67
|
-
const popcorn = new Popcorn({ ...constructorParams,
|
|
63
|
+
const bundlePaths = constructorParams.bundlePaths && constructorParams.bundlePaths.length > 0
|
|
64
|
+
? constructorParams.bundlePaths
|
|
65
|
+
: [await resolveBundleURL("/bundle.avm", "/assets/bundle.avm")];
|
|
66
|
+
const popcorn = new Popcorn({ ...constructorParams, bundlePaths, container: containerWithDefault }, INIT_TOKEN);
|
|
68
67
|
popcorn.trace("Main: init, params: ", { container, ...constructorParams });
|
|
69
68
|
await popcorn.mount();
|
|
70
69
|
return popcorn;
|