@poe-platform/safe-bash 0.1.43 → 0.1.44
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 +108 -12
- package/dist/safe-bash/browser.js.map +2 -2
- package/dist/safe-bash/commands/network/fetch-transport.d.ts.map +1 -1
- package/dist/safe-bash/commands/network/fetch-transport.js +2 -0
- package/dist/safe-bash/commands/network/fetch-transport.js.map +1 -1
- package/dist/safe-bash/commands/streams.d.ts.map +1 -1
- package/dist/safe-bash/commands/streams.js +114 -13
- package/dist/safe-bash/commands/streams.js.map +1 -1
- package/package.json +2 -2
|
@@ -4025,32 +4025,128 @@ function streamCommands() {
|
|
|
4025
4025
|
}),
|
|
4026
4026
|
define("tee", async (context) => {
|
|
4027
4027
|
const parsed = options(context.args, "a", { append: "a" });
|
|
4028
|
-
const
|
|
4028
|
+
const paths = [];
|
|
4029
|
+
const streams = [];
|
|
4029
4030
|
let exitCode = 0;
|
|
4031
|
+
let closed = false;
|
|
4032
|
+
let cleanup;
|
|
4033
|
+
const closeStreams = () => {
|
|
4034
|
+
closed = true;
|
|
4035
|
+
return cleanup ??= Promise.allSettled(streams.map(async (target) => {
|
|
4036
|
+
await target.pipe.abort(context.signal.aborted ? context.signal.reason : void 0);
|
|
4037
|
+
await target.task;
|
|
4038
|
+
})).then(() => {
|
|
4039
|
+
});
|
|
4040
|
+
};
|
|
4041
|
+
context.registerCleanup?.(closeStreams);
|
|
4042
|
+
const report = async (target, error) => {
|
|
4043
|
+
target.active = false;
|
|
4044
|
+
if (target.reported) return;
|
|
4045
|
+
target.reported = true;
|
|
4046
|
+
await diagnostic(context, error);
|
|
4047
|
+
exitCode = 1;
|
|
4048
|
+
};
|
|
4049
|
+
const fallback = async (target) => {
|
|
4050
|
+
if (context.fs.capabilities.append === false || target.accepted || !(target.failure instanceof FsError) || target.failure.code !== "ENOTSUP") return false;
|
|
4051
|
+
await context.fs.writeFile(target.path, new Uint8Array(), { flag: target.flag, signal: context.signal });
|
|
4052
|
+
target.active = false;
|
|
4053
|
+
paths.push(target.path);
|
|
4054
|
+
return true;
|
|
4055
|
+
};
|
|
4056
|
+
const recover = async (target, error) => {
|
|
4057
|
+
try {
|
|
4058
|
+
if (await fallback(target)) return;
|
|
4059
|
+
} catch (fallbackError) {
|
|
4060
|
+
context.signal.throwIfAborted();
|
|
4061
|
+
await report(target, fallbackError);
|
|
4062
|
+
return;
|
|
4063
|
+
}
|
|
4064
|
+
await report(target, error);
|
|
4065
|
+
};
|
|
4066
|
+
const streaming = context.fs.capabilities.streamingWrite !== false && typeof context.fs.writeStream === "function";
|
|
4030
4067
|
for (const operand of parsed.operands) {
|
|
4031
4068
|
try {
|
|
4032
4069
|
const path = pathOf(context, operand);
|
|
4033
|
-
|
|
4034
|
-
|
|
4070
|
+
if (closed) throw new FsError("ECANCELED", { syscall: "tee", path });
|
|
4071
|
+
const flag = parsed.flags.has("a") ? "a" : "w";
|
|
4072
|
+
if (streaming) {
|
|
4073
|
+
const pipe = createBytePipe({ signal: context.signal });
|
|
4074
|
+
const target = {
|
|
4075
|
+
path,
|
|
4076
|
+
flag,
|
|
4077
|
+
pipe,
|
|
4078
|
+
task: Promise.resolve(),
|
|
4079
|
+
failed: false,
|
|
4080
|
+
accepted: false,
|
|
4081
|
+
reported: false,
|
|
4082
|
+
active: true
|
|
4083
|
+
};
|
|
4084
|
+
const source = (async function* () {
|
|
4085
|
+
for await (const chunk of pipe.readable) {
|
|
4086
|
+
target.accepted = true;
|
|
4087
|
+
yield chunk;
|
|
4088
|
+
}
|
|
4089
|
+
})();
|
|
4090
|
+
target.task = context.fs.writeStream(path, source, { flag, signal: context.signal }).catch(async (error) => {
|
|
4091
|
+
target.failed = true;
|
|
4092
|
+
target.failure = error;
|
|
4093
|
+
await pipe.abort(error);
|
|
4094
|
+
});
|
|
4095
|
+
streams.push(target);
|
|
4096
|
+
} else {
|
|
4097
|
+
if (context.fs.capabilities.append === false) {
|
|
4098
|
+
throw new FsError(context.fs.capabilities.readOnly === true ? "EROFS" : "ENOTSUP", { syscall: "tee", path });
|
|
4099
|
+
}
|
|
4100
|
+
await context.fs.writeFile(path, new Uint8Array(), { flag, signal: context.signal });
|
|
4101
|
+
paths.push(path);
|
|
4102
|
+
}
|
|
4035
4103
|
} catch (error) {
|
|
4104
|
+
context.signal.throwIfAborted();
|
|
4036
4105
|
await diagnostic(context, error);
|
|
4037
4106
|
exitCode = 1;
|
|
4038
4107
|
}
|
|
4039
4108
|
}
|
|
4040
|
-
|
|
4041
|
-
await
|
|
4042
|
-
|
|
4109
|
+
try {
|
|
4110
|
+
for await (const chunk of input(context)) {
|
|
4111
|
+
await output(context, chunk);
|
|
4112
|
+
for (const target of streams) {
|
|
4113
|
+
if (!target.active) continue;
|
|
4114
|
+
try {
|
|
4115
|
+
await target.pipe.writable.write(chunk);
|
|
4116
|
+
} catch (error) {
|
|
4117
|
+
context.signal.throwIfAborted();
|
|
4118
|
+
await target.task;
|
|
4119
|
+
await recover(target, target.failed ? target.failure : error);
|
|
4120
|
+
}
|
|
4121
|
+
}
|
|
4122
|
+
for (let index = 0; index < paths.length; ) {
|
|
4123
|
+
try {
|
|
4124
|
+
await context.fs.appendFile(paths[index], chunk, { signal: context.signal });
|
|
4125
|
+
index++;
|
|
4126
|
+
} catch (error) {
|
|
4127
|
+
context.signal.throwIfAborted();
|
|
4128
|
+
await diagnostic(context, error);
|
|
4129
|
+
paths.splice(index, 1);
|
|
4130
|
+
exitCode = 1;
|
|
4131
|
+
}
|
|
4132
|
+
}
|
|
4133
|
+
}
|
|
4134
|
+
for (const target of streams) {
|
|
4135
|
+
if (!target.active) continue;
|
|
4043
4136
|
try {
|
|
4044
|
-
await
|
|
4045
|
-
|
|
4137
|
+
await target.pipe.close();
|
|
4138
|
+
await target.task;
|
|
4139
|
+
if (target.failed) await recover(target, target.failure);
|
|
4046
4140
|
} catch (error) {
|
|
4047
|
-
|
|
4048
|
-
|
|
4049
|
-
|
|
4141
|
+
context.signal.throwIfAborted();
|
|
4142
|
+
await target.task;
|
|
4143
|
+
await recover(target, target.failed ? target.failure : error);
|
|
4050
4144
|
}
|
|
4051
4145
|
}
|
|
4146
|
+
return { exitCode };
|
|
4147
|
+
} finally {
|
|
4148
|
+
await closeStreams();
|
|
4052
4149
|
}
|
|
4053
|
-
return { exitCode };
|
|
4054
4150
|
}),
|
|
4055
4151
|
define("tr", async (context) => {
|
|
4056
4152
|
const parsed = options(context.args, "dscC", { delete: "d", "squeeze-repeats": "s", complement: "c" });
|