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

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
@@ -45,6 +45,7 @@ export type BeamBootOptions = {
45
45
  /** VM environment variables. */
46
46
  env?: Record<string, string>;
47
47
  ttySize: TtySize;
48
+ noshell: boolean;
48
49
  createModule: CreateModuleFn<EmscriptenModule>;
49
50
  emit: (event: BeamEvent) => void;
50
51
  };
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
  }),
@@ -577,8 +590,10 @@ function toPopcornError(error) {
577
590
  const message = error instanceof Error ? error.message : String(error);
578
591
  return err("worker:load", { message });
579
592
  }
580
- function buildArgs({ appNames, entrypoint, emulator, extra, }) {
593
+ function buildArgs({ appNames, entrypoint, noshell, emulator, extra, }) {
581
594
  const args = [...emulator, "--", ...BASE_ARGS, "-boot", BOOT_NAME];
595
+ if (noshell)
596
+ args.push("-noshell");
582
597
  for (const app of CORE_APPS) {
583
598
  args.push("-pa", `/lib/${app}/ebin`);
584
599
  }
@@ -775,6 +790,7 @@ self.onmessage = async (event) => {
775
790
  extraArgs: data.payload.extraArgs,
776
791
  env: data.payload.env,
777
792
  ttySize: data.payload.ttySize,
793
+ noshell: data.payload.noshell,
778
794
  createModule,
779
795
  emit: toMain,
780
796
  });
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.3",
4
4
  "description": "JS bindings for BEAM/OTP in WebAssembly",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",