@swmansion/popcorn 0.3.0-rc1 → 0.3.0-rc4

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 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.AJqcoEu/atomvm/src/platforms/emscripten/src/atomvm.pre.js
59
+ // include: /tmp/atomvm-build-swm.uZpbzAG/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.AJqcoEu/atomvm/src/platforms/emscripten/src/atomvm.pre.js
131
+ // end include: /tmp/atomvm-build-swm.uZpbzAG/atomvm/src/platforms/emscripten/src/atomvm.pre.js
132
132
  var arguments_ = [];
133
133
 
134
134
  var thisProgram = "./this.program";
@@ -968,8 +968,8 @@ async function createWasm() {
968
968
  wasmBinaryFile ??= findWasmBinary();
969
969
  try {
970
970
  var result = await instantiateAsync(wasmBinary, wasmBinaryFile, info);
971
- var exports$1 = receiveInstantiationResult(result);
972
- return exports$1;
971
+ var exports = receiveInstantiationResult(result);
972
+ return exports;
973
973
  } catch (e) {
974
974
  // If instantiation fails, reject the module ready promise.
975
975
  readyPromiseReject(e);
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 metaElement = document.querySelector('meta[name="bundle-path"]');
36
- if (!metaElement) {
37
- throw new Error("Missing meta[name='bundle-path'] element");
38
- }
39
- const bundlePath = metaElement.content;
40
- const bundleBuffer = await fetch(bundlePath).then((resp) => resp.arrayBuffer());
41
- const bundle = new Int8Array(bundleBuffer);
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(avmBundle) {
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
- FS.writeFile("/data/bundle.avm", avmBundle);
59
+ avmBundles.forEach((bundle, i) => {
60
+ FS.writeFile(bundleFilePaths[i], bundle);
61
+ });
60
62
  },
61
63
  ],
62
- arguments: ["/data/bundle.avm"],
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
- /** Path to compiled Elixir bundle (`.avm` file). */
11
- bundlePath?: string;
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 bundleURL;
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
- bundleURL;
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 bundlePath = params.bundlePath ?? "/bundle.avm";
34
- const bundleURL = new URL(bundlePath, import.meta.url);
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: { "bundle-path": this.bundleURL },
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 bundlePath = constructorParams.bundlePath
65
- ? constructorParams.bundlePath
66
- : await resolveBundleURL("/bundle.avm", "/assets/bundle.avm");
67
- const popcorn = new Popcorn({ ...constructorParams, bundlePath, container: containerWithDefault }, INIT_TOKEN);
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@swmansion/popcorn",
3
- "version": "0.3.0-rc1",
3
+ "version": "0.3.0-rc4",
4
4
  "description": "JS bindings for Popcorn",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",