@poe-platform/safe-bash 0.1.112 → 0.1.114

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.
@@ -7677,11 +7677,15 @@ var InvocationScope = class _InvocationScope {
7677
7677
  close() {
7678
7678
  if (!this.#drain) {
7679
7679
  this.#drain = Promise.resolve().then(async () => {
7680
- await Promise.all([
7681
- ...this.#callbacks.map((cleanup) => this.cleanup(cleanup)),
7682
- ...[...this.#children].map((child) => child.close()),
7683
- ...this.#work
7684
- ]);
7680
+ try {
7681
+ await Promise.all([
7682
+ ...this.#callbacks.splice(0).map((cleanup) => this.cleanup(cleanup)),
7683
+ ...[...this.#children].map((child) => child.close()),
7684
+ ...this.#work
7685
+ ]);
7686
+ } finally {
7687
+ if (this.parent) this.parent.#children.delete(this);
7688
+ }
7685
7689
  });
7686
7690
  this.#seal();
7687
7691
  }
@@ -9470,7 +9474,8 @@ var StateMonitor = class {
9470
9474
  this.proxy = this.wrap(raw, "state");
9471
9475
  monitors.set(raw, this);
9472
9476
  monitors.set(this.proxy, this);
9473
- session.scope.register(async () => {
9477
+ if (session.monitors) session.monitors.add(this);
9478
+ else session.scope.register(async () => {
9474
9479
  await session.scope.drainWork();
9475
9480
  this.closeValues();
9476
9481
  });
@@ -9726,14 +9731,29 @@ var Restoration = class {
9726
9731
  this.holding?.release();
9727
9732
  }
9728
9733
  };
9729
- async function snapshotState(state, clone, signal, prepare) {
9734
+ async function snapshotState(state, clone, signal, prepare, scope) {
9730
9735
  const monitor = stateMonitor(state);
9731
9736
  if (!monitor) return clone();
9732
- if (!monitor.store && !monitor.session.ledger.active) return new StateMonitor(clone(), monitor.session, monitor).proxy;
9737
+ const session = scope ? { ...monitor.session, scope, owner: void 0, guestOwner: void 0, monitors: /* @__PURE__ */ new Set() } : monitor.session;
9738
+ if (scope) scope.register(async () => {
9739
+ await scope.drainWork();
9740
+ for (const owned of session.monitors) {
9741
+ owned.closeValues();
9742
+ if (owned.store) for (const [name2] of owned.store.bindings) {
9743
+ await scope.cleanup(async () => {
9744
+ await owned.store.remove(name2, { generation: 0, version: 0, epoch: 0 });
9745
+ });
9746
+ }
9747
+ }
9748
+ session.monitors.clear();
9749
+ await session.owner?.close();
9750
+ });
9751
+ if (!monitor.store && !monitor.session.ledger.active) return new StateMonitor(clone(), session, monitor).proxy;
9733
9752
  const store = monitor.store ?? monitor.activate();
9734
9753
  const internal = store.owner.ledger === monitor.session.internal;
9735
9754
  const epoch = monitor.epoch;
9736
- const owner = ArrayOwner.create(store.owner.ledger, store.owner);
9755
+ const parent = scope ? session.owner ??= ArrayOwner.create(session.internal) : store.owner;
9756
+ const owner = ArrayOwner.create(store.owner.ledger, parent);
9737
9757
  const holding = store.owner.hold();
9738
9758
  const check = () => {
9739
9759
  signal.throwIfAborted();
@@ -9789,7 +9809,7 @@ async function snapshotState(state, clone, signal, prepare) {
9789
9809
  }
9790
9810
  }
9791
9811
  check();
9792
- result = new StateMonitor(clone(), monitor.session, monitor);
9812
+ result = new StateMonitor(clone(), session, monitor);
9793
9813
  const destination = result.activate(internal);
9794
9814
  for (const [name2, entry] of store.bindings) {
9795
9815
  check();
@@ -10825,7 +10845,7 @@ function signalSink(sink, signal) {
10825
10845
  if (owned) budgetedSinks.set(output2, { budget: owned.budget, write: output2.write });
10826
10846
  return output2;
10827
10847
  }
10828
- async function cloneState(state, signal) {
10848
+ async function cloneState(state, signal, scope) {
10829
10849
  const destination = await snapshotState(state, () => ({
10830
10850
  ...state,
10831
10851
  variables: Object.assign(/* @__PURE__ */ Object.create(null), state.variables),
@@ -10835,10 +10855,10 @@ async function cloneState(state, signal) {
10835
10855
  readonlyVariables: new Set(state.readonlyVariables),
10836
10856
  getopts: cloneGetoptsBinding(state),
10837
10857
  directoryStack: { entries: [...state.directoryStack?.entries ?? []], bytes: state.directoryStack?.bytes ?? 0 },
10838
- locals: state.locals.map((scope) => new Map([...scope].map(([name2, saved]) => [name2, { ...saved, ...saved.getopts ? { getopts: { integer: saved.getopts.integer, cursor: cloneGetoptsState(saved.getopts.cursor) } } : {} }])))
10858
+ locals: scope ? [] : state.locals.map((scope2) => new Map([...scope2].map(([name2, saved]) => [name2, { ...saved, ...saved.getopts ? { getopts: { integer: saved.getopts.integer, cursor: cloneGetoptsState(saved.getopts.cursor) } } : {} }])))
10839
10859
  }), signal, async (destination2, owner) => {
10840
10860
  const store = arrayStore(destination2) ?? requireArrays(destination2);
10841
- for (let index = 0; index < state.locals.length; index++) {
10861
+ for (let index = 0; index < destination2.locals.length; index++) {
10842
10862
  const sourceFrame = state.locals[index];
10843
10863
  const copiedFrame = destination2.locals[index];
10844
10864
  for (const [name2, saved] of sourceFrame) {
@@ -10867,7 +10887,7 @@ async function cloneState(state, signal) {
10867
10887
  await owner.ledger.checkpoint(signal);
10868
10888
  }
10869
10889
  }
10870
- });
10890
+ }, scope);
10871
10891
  try {
10872
10892
  for (const frame of destination.locals) for (const saved of frame.values()) {
10873
10893
  if (saved.heldValue) saved.heldValue = stateMonitor(destination).values.scope.hold(saved.heldValue.value);
@@ -13993,7 +14013,7 @@ ${prefix2} line ${offset + line}: \`${source.split("\n")[line - 1] ?? ""}'
13993
14013
  const allocation = this.budget.values.scope();
13994
14014
  scope.register(() => allocation.close());
13995
14015
  const carrier = this.admitArguments(getCommandArguments({ args, ...options3.argumentValues ? { argumentValues: options3.argumentValues } : {} }).values, allocation);
13996
- const child = await cloneState(state, this.signal);
14016
+ const child = await cloneState(state, this.signal, scope);
13997
14017
  child.cwd = resolvePath(context.cwd, options3.cwd ?? ".");
13998
14018
  const env = options3.replaceEnv ? { ...options3.env } : { ...context.env, ...options3.env, PWD: child.cwd };
13999
14019
  if (guestArrays(child) || Object.keys(env).some((key) => arrayStore(child)?.get(key))) await this.indexedEnvironment(child, env);