@poe-platform/safe-bash 0.1.434 → 0.1.436
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/safe-bash/browser.js +350 -113
- package/dist/safe-bash/browser.js.map +3 -3
- package/dist/safe-bash/commands/stream-format/nl.js +1 -1
- package/dist/safe-bash/commands/stream-format/nl.js.map +1 -1
- package/dist/safe-bash/commands/structured/interpreter.js +10 -10
- package/dist/safe-bash/commands/structured/interpreter.js.map +1 -1
- package/dist/safe-bash/commands/structured/limits.d.ts +3 -1
- package/dist/safe-bash/commands/structured/limits.d.ts.map +1 -1
- package/dist/safe-bash/commands/structured/limits.js +16 -5
- package/dist/safe-bash/commands/structured/limits.js.map +1 -1
- package/dist/safe-bash/commands/structured/values.d.ts +5 -3
- package/dist/safe-bash/commands/structured/values.d.ts.map +1 -1
- package/dist/safe-bash/commands/structured/values.js +73 -21
- package/dist/safe-bash/commands/structured/values.js.map +1 -1
- package/dist/safe-bash/commands/text-programs/awk-runtime.js +4 -4
- package/dist/safe-bash/commands/text-programs/awk-runtime.js.map +1 -1
- package/dist/safe-bash/commands/text-programs/regex.d.ts +2 -1
- package/dist/safe-bash/commands/text-programs/regex.d.ts.map +1 -1
- package/dist/safe-bash/commands/text-programs/regex.js +230 -93
- package/dist/safe-bash/commands/text-programs/regex.js.map +1 -1
- package/dist/safe-bash/commands/text-programs/sed.js +1 -1
- package/dist/safe-bash/commands/text-programs/sed.js.map +1 -1
- package/dist/safe-bash/portable.js +439 -148
- package/dist/safe-bash/portable.js.map +3 -3
- package/dist/safe-bash/shell/arrays/state.d.ts +6 -1
- package/dist/safe-bash/shell/arrays/state.d.ts.map +1 -1
- package/dist/safe-bash/shell/arrays/state.js +30 -3
- package/dist/safe-bash/shell/arrays/state.js.map +1 -1
- package/dist/safe-bash/shell/cleanup.d.ts +1 -1
- package/dist/safe-bash/shell/cleanup.d.ts.map +1 -1
- package/dist/safe-bash/shell/cleanup.js +7 -3
- package/dist/safe-bash/shell/cleanup.js.map +1 -1
- package/dist/safe-bash/shell/getopts.d.ts +10 -1
- package/dist/safe-bash/shell/getopts.d.ts.map +1 -1
- package/dist/safe-bash/shell/getopts.js +55 -6
- package/dist/safe-bash/shell/getopts.js.map +1 -1
- package/dist/safe-bash/shell/runtime.d.ts.map +1 -1
- package/dist/safe-bash/shell/runtime.js +69 -27
- package/dist/safe-bash/shell/runtime.js.map +1 -1
- package/package.json +2 -2
|
@@ -24,7 +24,7 @@ import { outputFailure } from "../contracts/io.js";
|
|
|
24
24
|
import { executionCommands } from "../commands/execution.js";
|
|
25
25
|
import { formatPrintf, printfCommand } from "../commands/basic.js";
|
|
26
26
|
import { UsageError } from "../commands/internal.js";
|
|
27
|
-
import { cloneGetoptsState, createGetoptsState, GetoptsError, scanGetopts, withGetoptsIndex } from "./getopts.js";
|
|
27
|
+
import { cloneGetoptsState, createGetoptsInput, createGetoptsState, GetoptsError, getoptsInputAllocationSize, scanGetopts, withGetoptsIndex } from "./getopts.js";
|
|
28
28
|
import { activateChildCancellation, prepareChildCancellation, selectRuntimeCancellationOutcome, subscribeCancellation, } from "./cancellation.js";
|
|
29
29
|
import { getArrayAssignment, getArraySelector, copyArraySelector, numericIndex, literalIndex, isQuoteMarker } from "./arrays/syntax.js";
|
|
30
30
|
import { ArrayFailure, ArrayOwner, exactSum } from "./arrays/ledger.js";
|
|
@@ -899,6 +899,7 @@ class InvocationCancellationOwner {
|
|
|
899
899
|
#failures;
|
|
900
900
|
#outcomes;
|
|
901
901
|
#publicPromise;
|
|
902
|
+
#retireCleanup;
|
|
902
903
|
#resolveFinalized;
|
|
903
904
|
#admissionOpen = true;
|
|
904
905
|
#boundary;
|
|
@@ -914,7 +915,7 @@ class InvocationCancellationOwner {
|
|
|
914
915
|
this.#outcomes = outcomes;
|
|
915
916
|
this.#publicPromise = publicPromise;
|
|
916
917
|
this.finalized = new Promise(resolve => { this.#resolveFinalized = resolve; });
|
|
917
|
-
parent.register(async () => {
|
|
918
|
+
this.#retireCleanup = parent.register(async () => {
|
|
918
919
|
this.requestClose();
|
|
919
920
|
await this.finalized;
|
|
920
921
|
});
|
|
@@ -990,6 +991,7 @@ class InvocationCancellationOwner {
|
|
|
990
991
|
this.#outcomes.discard(this.#record);
|
|
991
992
|
this.#closeBoundary();
|
|
992
993
|
this.#resolveFinalized();
|
|
994
|
+
this.#retireCleanup();
|
|
993
995
|
}
|
|
994
996
|
}
|
|
995
997
|
async #finishOnce(barrier, captured) {
|
|
@@ -1004,6 +1006,7 @@ class InvocationCancellationOwner {
|
|
|
1004
1006
|
}
|
|
1005
1007
|
finally {
|
|
1006
1008
|
this.#resolveFinalized();
|
|
1009
|
+
this.#retireCleanup();
|
|
1007
1010
|
}
|
|
1008
1011
|
}
|
|
1009
1012
|
#closeBoundary() {
|
|
@@ -2525,11 +2528,18 @@ export class Runtime {
|
|
|
2525
2528
|
this.outputFiles.delete(path);
|
|
2526
2529
|
};
|
|
2527
2530
|
let target;
|
|
2531
|
+
let outputScope;
|
|
2528
2532
|
try {
|
|
2529
|
-
|
|
2533
|
+
outputScope = io[invocationScope].child();
|
|
2534
|
+
target = await openFileOutput({ fs: this.fs, signal: this.signal, registerCleanup: cleanup => { outputScope.register(cleanup); } }, path, append ? "a" : "w", random ? incremental : undefined);
|
|
2530
2535
|
}
|
|
2531
2536
|
catch (error) {
|
|
2532
|
-
|
|
2537
|
+
try {
|
|
2538
|
+
await outputScope?.close();
|
|
2539
|
+
}
|
|
2540
|
+
finally {
|
|
2541
|
+
release();
|
|
2542
|
+
}
|
|
2533
2543
|
throw error;
|
|
2534
2544
|
}
|
|
2535
2545
|
outputs.add(async (completion) => {
|
|
@@ -2550,7 +2560,12 @@ export class Runtime {
|
|
|
2550
2560
|
}
|
|
2551
2561
|
}
|
|
2552
2562
|
finally {
|
|
2553
|
-
|
|
2563
|
+
try {
|
|
2564
|
+
await outputScope?.close();
|
|
2565
|
+
}
|
|
2566
|
+
finally {
|
|
2567
|
+
release();
|
|
2568
|
+
}
|
|
2554
2569
|
}
|
|
2555
2570
|
});
|
|
2556
2571
|
const output = this.budget.sink(target.sink, this.signal);
|
|
@@ -2807,7 +2822,7 @@ export class Runtime {
|
|
|
2807
2822
|
const context = {
|
|
2808
2823
|
...publicIO, command: name, args: argumentValues.args, argumentValues, env, cwd: state.cwd, fs: this.fs, signal: this.commandSignal,
|
|
2809
2824
|
executionScope: this.budget.executionScope,
|
|
2810
|
-
registerCleanup: (cleanup) => scope.register(cleanup),
|
|
2825
|
+
registerCleanup: (cleanup) => { scope.register(cleanup); },
|
|
2811
2826
|
invoke: (name, args, options) => {
|
|
2812
2827
|
const invocation = this.invoke(name, args, options, context, state, scope);
|
|
2813
2828
|
void invocation.catch(() => undefined);
|
|
@@ -3467,7 +3482,7 @@ export class Runtime {
|
|
|
3467
3482
|
env: Object.assign(Object.create(null), incoming.env),
|
|
3468
3483
|
stdin: input ?? incoming.stdin,
|
|
3469
3484
|
stdout: this.budget.sink(incoming.stdout, runtime.signal), stderr: this.budget.sink(incoming.stderr, runtime.signal),
|
|
3470
|
-
signal: this.commandSignal, registerCleanup: cleanup => scope.register(cleanup),
|
|
3485
|
+
signal: this.commandSignal, registerCleanup: cleanup => { scope.register(cleanup); },
|
|
3471
3486
|
invoke: (name, args, options) => {
|
|
3472
3487
|
const invocation = invocationOverride.current ? invocationOverride.current(name, args, options) : runtime.invoke(name, args, options, context, child, scope);
|
|
3473
3488
|
void invocation.catch(() => undefined);
|
|
@@ -4127,30 +4142,57 @@ export class Runtime {
|
|
|
4127
4142
|
}
|
|
4128
4143
|
const optstring = context.args[offset];
|
|
4129
4144
|
const name = context.args[offset + 1];
|
|
4130
|
-
const
|
|
4131
|
-
|
|
4145
|
+
const explicit = context.args.length > offset + 2;
|
|
4146
|
+
const monitor = explicit ? undefined : stateMonitor(state);
|
|
4147
|
+
const revision = monitor?.positionalRevision;
|
|
4148
|
+
const supplied = explicit ? context.args.slice(offset + 2) : state.positional;
|
|
4149
|
+
if (supplied.length > fields)
|
|
4132
4150
|
this.budget.fail("maxExpansionFields");
|
|
4133
|
-
|
|
4134
|
-
|
|
4135
|
-
|
|
4136
|
-
|
|
4137
|
-
|
|
4138
|
-
}
|
|
4139
|
-
const maxBytes = saturatedProduct(bytes, saturatedSum(args.length, 1));
|
|
4140
|
-
const maxSteps = saturatedSum(saturatedProduct(maxBytes, 2), saturatedSum(args.length, 2));
|
|
4141
|
-
state.getopts ??= cloneGetoptsBinding(state);
|
|
4151
|
+
const maxBytes = saturatedProduct(bytes, saturatedSum(supplied.length, 1));
|
|
4152
|
+
const maxSteps = saturatedSum(saturatedProduct(maxBytes, 2), saturatedSum(supplied.length, 2));
|
|
4153
|
+
const work = { maxArguments: fields, maxBytes, maxSteps, yieldEvery: 128, signal: this.signal, checkpoint };
|
|
4154
|
+
let input = monitor?.getoptsInput;
|
|
4155
|
+
let allocation;
|
|
4142
4156
|
let result;
|
|
4143
4157
|
try {
|
|
4144
|
-
|
|
4145
|
-
|
|
4146
|
-
|
|
4147
|
-
|
|
4148
|
-
|
|
4149
|
-
|
|
4158
|
+
if (!input && monitor) {
|
|
4159
|
+
const size = getoptsInputAllocationSize(supplied.length);
|
|
4160
|
+
const arena = this.budget.values;
|
|
4161
|
+
const usage = arena.usage;
|
|
4162
|
+
if (size.bytes + 64 <= arena.maximumBytes - usage.bytes && size.slots + 1 <= arena.maximumSlots - usage.slots) {
|
|
4163
|
+
allocation = arena.scope();
|
|
4164
|
+
input = await createGetoptsInput(supplied, allocation, work);
|
|
4165
|
+
}
|
|
4166
|
+
}
|
|
4167
|
+
const args = input?.args ?? supplied;
|
|
4168
|
+
if (!input || allocation)
|
|
4169
|
+
for (let index = 0; index < args.length; index++) {
|
|
4170
|
+
this.signal.throwIfAborted();
|
|
4171
|
+
admit(args[index]);
|
|
4172
|
+
if ((index + 1) % 128 === 0)
|
|
4173
|
+
await checkpoint();
|
|
4174
|
+
}
|
|
4175
|
+
state.getopts ??= cloneGetoptsBinding(state);
|
|
4176
|
+
try {
|
|
4177
|
+
result = await scanGetopts(state.getopts.cursor, optstring, input ?? args, {
|
|
4178
|
+
reportErrors: state.variables.OPTERR === undefined || state.variables.OPTERR === "" || decimalIndex(state.variables.OPTERR) !== 0,
|
|
4179
|
+
work,
|
|
4180
|
+
});
|
|
4181
|
+
}
|
|
4182
|
+
catch (error) {
|
|
4183
|
+
this.signal.throwIfAborted();
|
|
4184
|
+
if (error instanceof GetoptsError && (error.code === "NON_ASCII_OPTION" || error.code === "INVALID_INPUT"))
|
|
4185
|
+
throw new CommandFailure(`getopts: ${error.message}`, 2);
|
|
4186
|
+
throw error;
|
|
4187
|
+
}
|
|
4150
4188
|
this.signal.throwIfAborted();
|
|
4151
|
-
if (
|
|
4152
|
-
throw new CommandFailure(
|
|
4153
|
-
|
|
4189
|
+
if (monitor && monitor.positionalRevision !== revision)
|
|
4190
|
+
throw new CommandFailure("getopts: positional arguments changed during validation", 2);
|
|
4191
|
+
if (allocation && monitor.retainGetoptsInput(revision, input, allocation))
|
|
4192
|
+
allocation = undefined;
|
|
4193
|
+
}
|
|
4194
|
+
finally {
|
|
4195
|
+
allocation?.close();
|
|
4154
4196
|
}
|
|
4155
4197
|
this.signal.throwIfAborted();
|
|
4156
4198
|
state.getopts.cursor = result.state;
|