@ai-ecoverse/slicc-kernel 1.22.0 → 1.22.1

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/node.js CHANGED
@@ -2557,6 +2557,7 @@ var MountTable = class {
2557
2557
  mounts = /* @__PURE__ */ new Map();
2558
2558
  devices = 0;
2559
2559
  pending = /* @__PURE__ */ new Set();
2560
+ notes = /* @__PURE__ */ new Map();
2560
2561
  deps;
2561
2562
  constructor(deps) {
2562
2563
  this.deps = deps;
@@ -2565,7 +2566,7 @@ var MountTable = class {
2565
2566
  return this.mounts.get(target);
2566
2567
  }
2567
2568
  list() {
2568
- return [...this.mounts.values()].map(
2569
+ const mounted = [...this.mounts.values()].map(
2569
2570
  ({ type, source, target, options, state, error, present }) => ({
2570
2571
  type,
2571
2572
  source,
@@ -2575,6 +2576,19 @@ var MountTable = class {
2575
2576
  ...error ? { error } : {}
2576
2577
  })
2577
2578
  );
2579
+ const noted = [...this.notes.values()].filter((note) => !this.mounts.has(note.target));
2580
+ return [...mounted, ...noted.map((note) => ({ ...note, options: { ...note.options } }))];
2581
+ }
2582
+ note(spec, state, error) {
2583
+ const target = normalizePath(spec.target);
2584
+ this.notes.set(target, {
2585
+ type: spec.type,
2586
+ source: spec.source,
2587
+ target,
2588
+ options: { ...spec.options },
2589
+ state,
2590
+ ...error ? { error } : {}
2591
+ });
2578
2592
  }
2579
2593
  locate(path) {
2580
2594
  let best;
@@ -2651,13 +2665,19 @@ var MountTable = class {
2651
2665
  };
2652
2666
  mounted = mount;
2653
2667
  this.mounts.set(target, mount);
2668
+ this.notes.delete(target);
2654
2669
  return this.list().find((m) => m.target === target);
2655
2670
  }
2671
+ unnote(target) {
2672
+ this.notes.delete(normalizePath(target));
2673
+ }
2656
2674
  umount(target, detach = false) {
2657
2675
  const at = normalizePath(target);
2658
2676
  const mount = this.mounts.get(at);
2677
+ if (!mount && this.notes.delete(at)) return;
2659
2678
  if (!mount) throw errnoError("EINVAL", `${at} is not mounted`);
2660
2679
  if (!detach && this.deps.busy(at)) throw errnoError("EBUSY", `${at} has open files`);
2680
+ this.notes.delete(at);
2661
2681
  this.mounts.delete(at);
2662
2682
  mount.conn.close();
2663
2683
  mount.dispose();
@@ -7468,28 +7488,34 @@ function wait(ms, signal) {
7468
7488
  });
7469
7489
  }
7470
7490
  async function mountFstab(lines, mount, signal, retries = FSTAB_RETRIES, discard = () => {
7491
+ }, settled = () => {
7471
7492
  }) {
7472
7493
  return Promise.all(
7473
- lines.map(async ({ line, spec, invalid }) => {
7474
- let failed = invalid;
7475
- for (let attempt = 0; !invalid && attempt <= retries.length && !signal.aborted; attempt++) {
7476
- try {
7477
- const entry = await mount(spec);
7478
- if (!signal.aborted) return { line, target: spec.target, entry };
7479
- discard(entry);
7480
- failed = Object.assign(new Error("the kernel stopped"), { code: "ECANCELED" });
7481
- break;
7482
- } catch (err) {
7483
- failed = err;
7484
- if (FINAL.has(codeOf3(err)) || attempt === retries.length) break;
7485
- await wait(retries[attempt], signal);
7486
- }
7487
- }
7488
- const code = codeOf3(failed);
7489
- return { line, target: spec.target, code, error: String(failed?.message ?? code) };
7494
+ lines.map(async (each) => {
7495
+ const result = await mountLine(each, mount, signal, retries, discard);
7496
+ settled(each, result);
7497
+ return result;
7490
7498
  })
7491
7499
  );
7492
7500
  }
7501
+ async function mountLine({ line, spec, invalid }, mount, signal, retries, discard) {
7502
+ let failed = invalid;
7503
+ for (let attempt = 0; !invalid && attempt <= retries.length && !signal.aborted; attempt++) {
7504
+ try {
7505
+ const entry = await mount(spec);
7506
+ if (!signal.aborted) return { line, target: spec.target, entry };
7507
+ discard(entry);
7508
+ failed = Object.assign(new Error("the kernel stopped"), { code: "ECANCELED" });
7509
+ break;
7510
+ } catch (err) {
7511
+ failed = err;
7512
+ if (FINAL.has(codeOf3(err)) || attempt === retries.length) break;
7513
+ await wait(retries[attempt], signal);
7514
+ }
7515
+ }
7516
+ const code = codeOf3(failed);
7517
+ return { line, target: spec.target, code, error: String(failed?.message ?? code) };
7518
+ }
7493
7519
 
7494
7520
  // src/mount/hostfs.ts
7495
7521
  var HOSTFS_IO = 16 * 1024 * 1024;
@@ -8301,6 +8327,7 @@ var Launcher = class {
8301
8327
  onMountPending;
8302
8328
  removable = /* @__PURE__ */ new Map();
8303
8329
  hostfs;
8330
+ fstabRetries;
8304
8331
  inserted = /* @__PURE__ */ new Map();
8305
8332
  openFiles = /* @__PURE__ */ new Set();
8306
8333
  held = /* @__PURE__ */ new Set();
@@ -8322,6 +8349,7 @@ var Launcher = class {
8322
8349
  this.media = options.media ?? memoryMedia();
8323
8350
  this.onMountPending = options.onMountPending;
8324
8351
  this.hostfs = options;
8352
+ this.fstabRetries = options.fstabRetries ?? FSTAB_RETRIES;
8325
8353
  this.processMounts = options.processMounts ?? true;
8326
8354
  this.pnpmHome = options.env?.PNPM_HOME ?? PNPM_HOME;
8327
8355
  this.modulesDir = options.modules ?? "/node_modules";
@@ -8755,12 +8783,22 @@ var Launcher = class {
8755
8783
  }
8756
8784
  async mountFstab() {
8757
8785
  const text = await this.base.readFile(FSTAB_PATH).catch(() => "");
8786
+ const lines = parseFstab(text);
8787
+ for (const { spec } of lines) this.mounts.note(spec, "pending");
8758
8788
  return mountFstab(
8759
- parseFstab(text),
8760
- (spec) => this.mount(spec),
8789
+ lines,
8790
+ (spec) => this.mount(spec).catch((err) => {
8791
+ this.mounts.note(spec, "pending", err?.message ?? String(err));
8792
+ throw err;
8793
+ }),
8761
8794
  this.booting.signal,
8762
- FSTAB_RETRIES,
8763
- (entry) => this.umount(entry.target, true)
8795
+ this.fstabRetries,
8796
+ (entry) => this.umount(entry.target, true),
8797
+ ({ spec }, result) => {
8798
+ if (!result.code || result.code === "ECANCELED" || this.booting.signal.aborted) {
8799
+ this.mounts.unnote(spec.target);
8800
+ } else this.mounts.note(spec, "failed", result.error);
8801
+ }
8764
8802
  );
8765
8803
  }
8766
8804
  environment(cwd, extra) {
@@ -9731,7 +9769,8 @@ async function createNodeKernel(options = {}) {
9731
9769
  ...options.modules ? { modules: options.modules } : {},
9732
9770
  ...options.env ? { env: options.env } : {},
9733
9771
  ...transport ? { transport } : {},
9734
- ...options.processMounts !== void 0 ? { processMounts: options.processMounts } : {}
9772
+ ...options.processMounts !== void 0 ? { processMounts: options.processMounts } : {},
9773
+ ...options.fstabRetries ? { fstabRetries: options.fstabRetries } : {}
9735
9774
  });
9736
9775
  await launcher.prepare();
9737
9776
  const guard = (work) => new Promise((resolve, reject) => {