@swmansion/popcorn 0.2.0-rc.4 → 0.2.0-rc.6

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/popcorn-swm.tJ64R0d/atomvm/src/platforms/emscripten/src/atomvm.pre.js
59
+ // include: /tmp/atomvm-build-swm.etp6TAu/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/popcorn-swm.tJ64R0d/atomvm/src/platforms/emscripten/src/atomvm.pre.js
131
+ // end include: /tmp/atomvm-build-swm.etp6TAu/atomvm/src/platforms/emscripten/src/atomvm.pre.js
132
132
  var arguments_ = [];
133
133
 
134
134
  var thisProgram = "./this.program";
@@ -7366,19 +7366,19 @@ function checkIncomingModuleAPI() {
7366
7366
  }
7367
7367
 
7368
7368
  var ASM_CONSTS = {
7369
- 77455: ($0, $1) => {
7369
+ 78463: ($0, $1) => {
7370
7370
  promiseMap.get($0).resolve($1);
7371
7371
  },
7372
- 77491: ($0, $1) => {
7372
+ 78499: ($0, $1) => {
7373
7373
  promiseMap.get($0).reject($1);
7374
7374
  },
7375
- 77526: ($0, $1) => {
7375
+ 78534: ($0, $1) => {
7376
7376
  promiseMap.get($0).resolve(UTF8ToString($1));
7377
7377
  },
7378
- 77576: ($0, $1) => {
7378
+ 78584: ($0, $1) => {
7379
7379
  promiseMap.get($0).reject(UTF8ToString($1));
7380
7380
  },
7381
- 77625: $0 => {
7381
+ 78633: $0 => {
7382
7382
  Module["onTrackedObjectDelete"]($0);
7383
7383
  }
7384
7384
  };
package/dist/AtomVM.wasm CHANGED
Binary file
package/dist/errors.d.ts CHANGED
@@ -6,7 +6,7 @@ export declare class PopcornError extends Error {
6
6
  constructor(code: PopcornErrorCode, message?: string);
7
7
  }
8
8
  /** Error codes for internal errors that indicate bugs or misuse */
9
- export type PopcornInternalErrorCode = "assert" | "private_constructor" | "bad_call" | "no_acked_call" | "bad_ack" | "already_awaited" | "already_mounted" | "unmounted" | "bad_target" | "bad_status";
9
+ export type PopcornInternalErrorCode = "assert" | "private_constructor" | "bad_call" | "no_acked_call" | "bad_ack" | "already_awaited" | "already_mounted" | "unmounted" | "bad_target" | "bad_status" | "bundle_not_found";
10
10
  /** Non-recoverable error indicating a bug or library misuse (always thrown) */
11
11
  export declare class PopcornInternalError extends Error {
12
12
  readonly code: PopcornInternalErrorCode;
@@ -37,6 +37,10 @@ type ErrorData = {
37
37
  t: "bad_status";
38
38
  status: string;
39
39
  expectedStatus: string;
40
+ } | {
41
+ t: "bundle_not_found";
42
+ primary: string;
43
+ fallback: string;
40
44
  };
41
45
  export declare function throwError(error: ErrorData): never;
42
46
  export {};
package/dist/errors.mjs CHANGED
@@ -43,6 +43,8 @@ function throwError(error) {
43
43
  throw new PopcornInternalError("bad_target", "Unspecified target process");
44
44
  case "bad_status":
45
45
  throw new PopcornInternalError("bad_status", `Operation not allowed: instance in "${error.status}" state, expected "${error.expectedStatus}"`);
46
+ case "bundle_not_found":
47
+ throw new PopcornInternalError("bundle_not_found", `Could not find a valid .avm bundle at "${error.primary}" or fallback "${error.fallback}"`);
46
48
  }
47
49
  }
48
50
 
package/dist/popcorn.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { IframeBridge } from './bridge.mjs';
2
- import { HEARTBEAT_TIMEOUT_MS, MESSAGES, MAX_RELOAD_N, INIT_VM_TIMEOUT_MS, CALL_TIMEOUT_MS } from './types.mjs';
2
+ import { HEARTBEAT_TIMEOUT_MS, MESSAGES, INIT_VM_TIMEOUT_MS, MAX_RELOAD_N, CALL_TIMEOUT_MS } from './types.mjs';
3
3
  import { throwError, PopcornError } from './errors.mjs';
4
4
  export { PopcornInternalError } from './errors.mjs';
5
5
 
@@ -60,7 +60,8 @@ class Popcorn {
60
60
  static async init(options) {
61
61
  const { container, ...constructorParams } = options;
62
62
  const containerWithDefault = container ?? document.documentElement;
63
- const popcorn = new Popcorn({ ...constructorParams, container: containerWithDefault }, INIT_TOKEN);
63
+ const bundlePath = await resolveBundleURL(constructorParams.bundlePath ?? "/bundle.avm", "/assets/bundle.avm");
64
+ const popcorn = new Popcorn({ ...constructorParams, bundlePath, container: containerWithDefault }, INIT_TOKEN);
64
65
  popcorn.trace("Main: init, params: ", { container, ...constructorParams });
65
66
  await popcorn.mount();
66
67
  return popcorn;
@@ -72,21 +73,27 @@ class Popcorn {
72
73
  this.transition({ status: "mount" });
73
74
  this.trace("Main: mount, container: ", this.bridgeConfig.container);
74
75
  this.bridge = new IframeBridge(this.bridgeConfig);
75
- await this.awaitMessage(MESSAGES.INIT);
76
- this.transition({ status: "await_vm" });
77
- this.trace("Main: iframe loaded");
78
- const startTime = performance.now();
79
- const startVmResult = await withTimeout(this.awaitMessage(MESSAGES.START_VM).then((data) => ({
80
- ok: true,
81
- data,
82
- durationMs: performance.now() - startTime,
83
- })), INIT_VM_TIMEOUT_MS);
84
- if (!startVmResult.ok)
85
- throwError({ t: "assert" });
86
- this.initProcess = startVmResult.data;
87
- this.transition({ status: "ready" });
88
- this.trace("Main: mounted, main process: ", this.initProcess);
89
- this.onHeartbeat();
76
+ try {
77
+ await this.awaitMessage(MESSAGES.INIT);
78
+ this.transition({ status: "await_vm" });
79
+ this.trace("Main: iframe loaded");
80
+ const startTime = performance.now();
81
+ const startVmResult = await withTimeout(this.awaitMessage(MESSAGES.START_VM).then((data) => ({
82
+ ok: true,
83
+ data,
84
+ durationMs: performance.now() - startTime,
85
+ })), INIT_VM_TIMEOUT_MS);
86
+ if (!startVmResult.ok)
87
+ throwError({ t: "assert" });
88
+ this.initProcess = startVmResult.data;
89
+ this.transition({ status: "ready" });
90
+ this.trace("Main: mounted, main process: ", this.initProcess);
91
+ this.onHeartbeat();
92
+ }
93
+ catch (error) {
94
+ this.deinit();
95
+ throw error;
96
+ }
90
97
  }
91
98
  /**
92
99
  * Sends a message to an Elixir process and awaits for the response.
@@ -348,5 +355,22 @@ async function withTimeout(promise, ms) {
348
355
  function noop() {
349
356
  /* noop */
350
357
  }
358
+ async function resolveBundleURL(primary, fallback) {
359
+ const fetchBundle = async (path) => {
360
+ const url = new URL(path, import.meta.url).href;
361
+ const response = await fetch(url, { method: "HEAD" });
362
+ const contentType = response.headers.get("Content-Type") ?? "";
363
+ if (!response.ok || contentType.includes("text/html")) {
364
+ throw new Error(`Bundle not found at "${path}"`);
365
+ }
366
+ return path;
367
+ };
368
+ try {
369
+ return await Promise.any([fetchBundle(primary), fetchBundle(fallback)]);
370
+ }
371
+ catch {
372
+ throwError({ t: "bundle_not_found", primary, fallback });
373
+ }
374
+ }
351
375
 
352
376
  export { Popcorn, PopcornError };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@swmansion/popcorn",
3
- "version": "0.2.0-rc.4",
3
+ "version": "0.2.0-rc.6",
4
4
  "description": "JS bindings for Popcorn",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
@@ -77,7 +77,7 @@
77
77
  "test": "vitest",
78
78
  "test:e2e": "playwright test --config e2e/playwright.config.ts",
79
79
  "build:prod": "pnpm run lint && (rm -rf assets || true) && (rm -rf dist || true) && pnpm run assets:prod && rollup -c",
80
- "assets:dev": "./scripts/get_atomvm.sh assets/",
81
- "assets:prod": "RUNTIME_SOURCE='https://github.com/software-mansion-labs/FissionVM.git#swm' ./scripts/get_atomvm.sh assets/"
80
+ "assets:dev": "../../scripts/build-atomvm.sh --outdir assets/ debug-wasm",
81
+ "assets:prod": "../../scripts/build-atomvm.sh --source 'https://github.com/software-mansion-labs/FissionVM.git#swm' --outdir assets/ debug-wasm"
82
82
  }
83
83
  }