@phpsandbox/sdk 0.0.27 → 0.0.29
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/browser/phpsandbox-sdk.esm.js +84 -4
- package/dist/browser/phpsandbox-sdk.esm.js.map +2 -2
- package/dist/browser/phpsandbox-sdk.esm.min.js +2 -2
- package/dist/browser/phpsandbox-sdk.esm.min.js.map +3 -3
- package/dist/browser/phpsandbox-sdk.iife.js +84 -4
- package/dist/browser/phpsandbox-sdk.iife.js.map +2 -2
- package/dist/browser/phpsandbox-sdk.iife.min.js +2 -2
- package/dist/browser/phpsandbox-sdk.iife.min.js.map +3 -3
- package/dist/filesystem.d.ts +1 -1
- package/dist/filesystem.d.ts.map +1 -1
- package/dist/filesystem.js +1 -2
- package/dist/filesystem.js.map +1 -1
- package/dist/shell.d.ts +27 -6
- package/dist/shell.d.ts.map +1 -1
- package/dist/shell.js +82 -2
- package/dist/shell.js.map +1 -1
- package/package.json +1 -1
|
@@ -574,8 +574,7 @@ var PHPSandbox = (() => {
|
|
|
574
574
|
};
|
|
575
575
|
const subscription = new FilesystemSubscription(path, this.okra, wrappedDisposable);
|
|
576
576
|
this.watches.set(path, { options, path, onDidChange });
|
|
577
|
-
this.okra.invoke("fs.watch", { path, options });
|
|
578
|
-
return subscription;
|
|
577
|
+
return this.okra.invoke("fs.watch", { path, options }).then(() => subscription);
|
|
579
578
|
}
|
|
580
579
|
exists(path) {
|
|
581
580
|
return this.stat(path).then(() => true).catch(() => false);
|
|
@@ -952,6 +951,14 @@ var PHPSandbox = (() => {
|
|
|
952
951
|
};
|
|
953
952
|
|
|
954
953
|
// src/shell.ts
|
|
954
|
+
function resolveExecInput(command, argsOrOpts = [], opts) {
|
|
955
|
+
const args = Array.isArray(argsOrOpts) ? argsOrOpts : [];
|
|
956
|
+
const resolvedOpts = Array.isArray(argsOrOpts) ? opts : argsOrOpts;
|
|
957
|
+
return {
|
|
958
|
+
command: Array.isArray(command) ? command : args.length > 0 ? [command, ...args] : command,
|
|
959
|
+
opts: resolvedOpts
|
|
960
|
+
};
|
|
961
|
+
}
|
|
955
962
|
var CommandError = class extends Error {
|
|
956
963
|
constructor(output, exitCode) {
|
|
957
964
|
super(output);
|
|
@@ -975,10 +982,83 @@ var PHPSandbox = (() => {
|
|
|
975
982
|
constructor(okra) {
|
|
976
983
|
this.okra = okra;
|
|
977
984
|
}
|
|
978
|
-
|
|
979
|
-
|
|
985
|
+
onOutput(id, handler) {
|
|
986
|
+
this.okra.listen(`shell.output.${id}`, handler);
|
|
987
|
+
}
|
|
988
|
+
listen(event, handler) {
|
|
989
|
+
return this.okra.listen(event, handler);
|
|
990
|
+
}
|
|
991
|
+
async exec(command, argsOrOpts = [], opts) {
|
|
992
|
+
const input = resolveExecInput(command, argsOrOpts, opts);
|
|
993
|
+
const { abortSignal, ...payloadOpts } = input.opts ?? {};
|
|
994
|
+
const result = await this.okra.invoke(
|
|
995
|
+
"shell.exec",
|
|
996
|
+
{
|
|
997
|
+
command: input.command,
|
|
998
|
+
opts: Object.keys(payloadOpts).length > 0 ? payloadOpts : void 0
|
|
999
|
+
},
|
|
1000
|
+
{ abortSignal }
|
|
1001
|
+
);
|
|
980
1002
|
return new Result(result.output, result.exitCode);
|
|
981
1003
|
}
|
|
1004
|
+
execStream(command, argsOrOpts = [], opts) {
|
|
1005
|
+
const input = resolveExecInput(command, argsOrOpts, opts);
|
|
1006
|
+
const id = input.opts?.id || nanoid();
|
|
1007
|
+
const disposables = /* @__PURE__ */ new Set();
|
|
1008
|
+
let controller = null;
|
|
1009
|
+
let closed = false;
|
|
1010
|
+
const dispose = () => {
|
|
1011
|
+
for (const disposable of disposables) {
|
|
1012
|
+
disposable.dispose();
|
|
1013
|
+
}
|
|
1014
|
+
disposables.clear();
|
|
1015
|
+
};
|
|
1016
|
+
const close = () => {
|
|
1017
|
+
if (closed) {
|
|
1018
|
+
return;
|
|
1019
|
+
}
|
|
1020
|
+
closed = true;
|
|
1021
|
+
dispose();
|
|
1022
|
+
if (controller) {
|
|
1023
|
+
try {
|
|
1024
|
+
controller.close();
|
|
1025
|
+
} catch {
|
|
1026
|
+
}
|
|
1027
|
+
}
|
|
1028
|
+
};
|
|
1029
|
+
const fail = (error) => {
|
|
1030
|
+
if (closed) {
|
|
1031
|
+
return;
|
|
1032
|
+
}
|
|
1033
|
+
closed = true;
|
|
1034
|
+
dispose();
|
|
1035
|
+
if (controller) {
|
|
1036
|
+
controller.error(error);
|
|
1037
|
+
}
|
|
1038
|
+
};
|
|
1039
|
+
const output = new ReadableStream({
|
|
1040
|
+
start: (_controller) => {
|
|
1041
|
+
controller = _controller;
|
|
1042
|
+
disposables.add(
|
|
1043
|
+
this.listen(`shell.output.${id}`, (data) => {
|
|
1044
|
+
controller?.enqueue(data.output);
|
|
1045
|
+
})
|
|
1046
|
+
);
|
|
1047
|
+
},
|
|
1048
|
+
cancel: () => {
|
|
1049
|
+
closed = true;
|
|
1050
|
+
dispose();
|
|
1051
|
+
}
|
|
1052
|
+
});
|
|
1053
|
+
const result = this.exec(input.command, { ...input.opts, id }).then((response) => {
|
|
1054
|
+
close();
|
|
1055
|
+
return response;
|
|
1056
|
+
}).catch((error) => {
|
|
1057
|
+
fail(error);
|
|
1058
|
+
throw error;
|
|
1059
|
+
});
|
|
1060
|
+
return { output, result };
|
|
1061
|
+
}
|
|
982
1062
|
};
|
|
983
1063
|
|
|
984
1064
|
// node_modules/@msgpack/msgpack/dist.esm/utils/utf8.mjs
|