@swmansion/popcorn 0.4.0-next.2 → 0.4.0-next.4

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.
Binary file
package/dist/types.d.ts CHANGED
@@ -44,7 +44,10 @@ export type BeamBootOptions = {
44
44
  extraArgs?: string[];
45
45
  /** VM environment variables. */
46
46
  env?: Record<string, string>;
47
+ /** Resolved maximum Wasm linear memory in bytes. */
48
+ maxMemoryBytes?: number;
47
49
  ttySize: TtySize;
50
+ noshell: boolean;
48
51
  createModule: CreateModuleFn<EmscriptenModule>;
49
52
  emit: (event: BeamEvent) => void;
50
53
  };
@@ -104,6 +107,7 @@ export type TtySize = {
104
107
  };
105
108
  /** Emscripten Module interface (subset exposed after instantiation). */
106
109
  export type EmscriptenModule = {
110
+ wasmMemory?: WebAssembly.Memory;
107
111
  ENV: Record<string, string>;
108
112
  FS_mkdirTree: (path: string) => void;
109
113
  FS_createDataFile: (parent: string, name: string | null, data: Uint8Array, canRead: boolean, canWrite: boolean, canOwn: boolean) => void;
package/dist/worker.mjs CHANGED
@@ -466,7 +466,7 @@ function start(options) {
466
466
  };
467
467
  }
468
468
  async function boot(opts, state, vm) {
469
- const { otpAssetsRoot, emulatorArgs, extraArgs, env, ttySize, createModule, emit, } = opts;
469
+ const { otpAssetsRoot, emulatorArgs, extraArgs, env, ttySize, noshell, createModule, emit, } = opts;
470
470
  const loadedFsData = await loadFsData(otpAssetsRoot);
471
471
  if (!loadedFsData.ok) {
472
472
  return { ok: false, error: loadedFsData.error };
@@ -485,22 +485,34 @@ async function boot(opts, state, vm) {
485
485
  LINES: String(ttySize.rows),
486
486
  ERL_INETRC: INETRC_PATH,
487
487
  };
488
+ let emitError = function (payload) {
489
+ emitError = null;
490
+ state.isVmReady = false;
491
+ emit({ type: "otp:error", payload });
492
+ };
488
493
  const moduleConfig = {
489
494
  print: (text) => emit({ type: "otp:stdout", payload: UTF8.encode(text) }),
490
495
  printErr: (text) => emit({ type: "otp:stderr", payload: UTF8.encode(text) }),
491
- onExit: (code) => emit({ type: "otp:error", payload: { kind: "exit", data: code } }),
492
- onAbort: (text) => emit({ type: "otp:error", payload: { kind: "abort", data: text } }),
496
+ onExit: (code) => emitError?.({ kind: "exit", data: code }),
497
+ onAbort: (text) => emitError?.({ kind: "abort", data: text }),
493
498
  onBeamMessage: (text) => {
499
+ if (emitError === null) {
500
+ return;
501
+ }
494
502
  const event = deserializeBridgeMessage(text);
495
503
  if (event === null)
496
504
  return;
505
+ if (event.type === "otp:error") {
506
+ emitError(event.payload);
507
+ return;
508
+ }
497
509
  if (handleVmReady(event))
498
510
  return;
499
511
  if (handleAppReady(event))
500
512
  return;
501
513
  emit(event);
502
514
  },
503
- onError: (text) => emit({ type: "otp:error", payload: { kind: "error", data: text } }),
515
+ onError: (text) => emitError?.({ kind: "error", data: text }),
504
516
  onStdinConsumed: (size) => emit({ type: "otp:stdin-consumed", payload: size }),
505
517
  onTrackedValueDelete: (key) => emit({ type: "otp:tracked-value-delete", payload: key }),
506
518
  onTtyChunk: (fd, chunk) => emit({
@@ -510,6 +522,7 @@ async function boot(opts, state, vm) {
510
522
  arguments: buildArgs({
511
523
  appNames: fsData.appNames,
512
524
  entrypoint: fsData.entrypoint,
525
+ noshell,
513
526
  emulator: emulatorArgs ?? [],
514
527
  extra: extraArgs ?? [],
515
528
  }),
@@ -524,6 +537,13 @@ async function boot(opts, state, vm) {
524
537
  ],
525
538
  };
526
539
  try {
540
+ if (opts.maxMemoryBytes !== undefined) {
541
+ moduleConfig.wasmMemory = new WebAssembly.Memory({
542
+ initial: 1024,
543
+ maximum: opts.maxMemoryBytes / 65536,
544
+ shared: true,
545
+ });
546
+ }
527
547
  const ready = Promise.all([vmReady, appReady]);
528
548
  const module = await createModule(moduleConfig);
529
549
  check(state.module === module);
@@ -577,8 +597,10 @@ function toPopcornError(error) {
577
597
  const message = error instanceof Error ? error.message : String(error);
578
598
  return err("worker:load", { message });
579
599
  }
580
- function buildArgs({ appNames, entrypoint, emulator, extra, }) {
600
+ function buildArgs({ appNames, entrypoint, noshell, emulator, extra, }) {
581
601
  const args = [...emulator, "--", ...BASE_ARGS, "-boot", BOOT_NAME];
602
+ if (noshell)
603
+ args.push("-noshell");
582
604
  for (const app of CORE_APPS) {
583
605
  args.push("-pa", `/lib/${app}/ebin`);
584
606
  }
@@ -774,7 +796,9 @@ self.onmessage = async (event) => {
774
796
  emulatorArgs: data.payload.emulatorArgs,
775
797
  extraArgs: data.payload.extraArgs,
776
798
  env: data.payload.env,
799
+ maxMemoryBytes: data.payload.maxMemoryBytes,
777
800
  ttySize: data.payload.ttySize,
801
+ noshell: data.payload.noshell,
778
802
  createModule,
779
803
  emit: toMain,
780
804
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@swmansion/popcorn",
3
- "version": "0.4.0-next.2",
3
+ "version": "0.4.0-next.4",
4
4
  "description": "JS bindings for BEAM/OTP in WebAssembly",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",