@lvce-editor/pty-host 8.7.0 → 8.8.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/ptyHostMain.js +117 -55
- package/package.json +1 -1
package/dist/ptyHostMain.js
CHANGED
|
@@ -270,7 +270,6 @@ const walkValue = (value, transferrables, isTransferrable) => {
|
|
|
270
270
|
for (const property of Object.values(value)) {
|
|
271
271
|
walkValue(property, transferrables, isTransferrable);
|
|
272
272
|
}
|
|
273
|
-
return;
|
|
274
273
|
}
|
|
275
274
|
};
|
|
276
275
|
const getTransferrables = value => {
|
|
@@ -473,7 +472,14 @@ class IpcError extends VError {
|
|
|
473
472
|
const cause = new Error(message);
|
|
474
473
|
// @ts-ignore
|
|
475
474
|
cause.code = code;
|
|
476
|
-
|
|
475
|
+
if (stack) {
|
|
476
|
+
Object.defineProperty(cause, 'stack', {
|
|
477
|
+
configurable: true,
|
|
478
|
+
enumerable: false,
|
|
479
|
+
value: stack,
|
|
480
|
+
writable: true
|
|
481
|
+
});
|
|
482
|
+
}
|
|
477
483
|
super(cause, betterMessage);
|
|
478
484
|
} else {
|
|
479
485
|
super(betterMessage);
|
|
@@ -764,13 +770,13 @@ const signal$4 = webSocket => {
|
|
|
764
770
|
webSocket.resume();
|
|
765
771
|
};
|
|
766
772
|
const wrap$9 = webSocket => {
|
|
767
|
-
|
|
773
|
+
const wrap = {
|
|
768
774
|
dispose() {
|
|
769
|
-
|
|
775
|
+
wrap.webSocket.close();
|
|
770
776
|
},
|
|
771
777
|
// @ts-ignore
|
|
772
778
|
off(event, listener) {
|
|
773
|
-
|
|
779
|
+
wrap.webSocket.off(event, listener);
|
|
774
780
|
},
|
|
775
781
|
// @ts-ignore
|
|
776
782
|
on(event, listener) {
|
|
@@ -784,7 +790,7 @@ const wrap$9 = webSocket => {
|
|
|
784
790
|
const data = deserialize(message);
|
|
785
791
|
const event = {
|
|
786
792
|
data,
|
|
787
|
-
target:
|
|
793
|
+
target: wrap
|
|
788
794
|
};
|
|
789
795
|
listener(event);
|
|
790
796
|
};
|
|
@@ -797,7 +803,7 @@ const wrap$9 = webSocket => {
|
|
|
797
803
|
// @ts-ignore
|
|
798
804
|
send(message) {
|
|
799
805
|
const stringifiedMessage = serialize(message);
|
|
800
|
-
|
|
806
|
+
wrap.webSocket.send(stringifiedMessage);
|
|
801
807
|
},
|
|
802
808
|
start() {
|
|
803
809
|
throw new Error('start method is deprecated');
|
|
@@ -808,6 +814,7 @@ const wrap$9 = webSocket => {
|
|
|
808
814
|
*/
|
|
809
815
|
wrappedListener: undefined
|
|
810
816
|
};
|
|
817
|
+
return wrap;
|
|
811
818
|
};
|
|
812
819
|
const IpcChildWithWebSocket = {
|
|
813
820
|
__proto__: null,
|
|
@@ -869,7 +876,10 @@ const constructError = (message, type, name) => {
|
|
|
869
876
|
if (ErrorConstructor === Error) {
|
|
870
877
|
const error = new Error(message);
|
|
871
878
|
if (name && name !== 'VError') {
|
|
872
|
-
error
|
|
879
|
+
Object.defineProperty(error, 'name', {
|
|
880
|
+
configurable: true,
|
|
881
|
+
value: name
|
|
882
|
+
});
|
|
873
883
|
}
|
|
874
884
|
return error;
|
|
875
885
|
}
|
|
@@ -886,8 +896,10 @@ const getCurrentStack = () => {
|
|
|
886
896
|
const currentStack = joinLines$1(splitLines$1(new Error().stack || '').slice(stackLinesToSkip));
|
|
887
897
|
return currentStack;
|
|
888
898
|
};
|
|
889
|
-
const getNewLineIndex$1 = (string, startIndex
|
|
890
|
-
|
|
899
|
+
const getNewLineIndex$1 = (string, startIndex) => {
|
|
900
|
+
{
|
|
901
|
+
return string.indexOf(NewLine$2);
|
|
902
|
+
}
|
|
891
903
|
};
|
|
892
904
|
const getParentStack = error => {
|
|
893
905
|
let parentStack = error.stack || error.data || error.message || '';
|
|
@@ -898,55 +910,91 @@ const getParentStack = error => {
|
|
|
898
910
|
};
|
|
899
911
|
const MethodNotFound = -32601;
|
|
900
912
|
const Custom = -32001;
|
|
913
|
+
const setStack = (error, stack) => {
|
|
914
|
+
const descriptor = Object.getOwnPropertyDescriptor(error, 'stack');
|
|
915
|
+
if (descriptor) {
|
|
916
|
+
if (!descriptor.configurable && !descriptor.writable) {
|
|
917
|
+
return;
|
|
918
|
+
}
|
|
919
|
+
if (!descriptor.configurable && descriptor.writable) {
|
|
920
|
+
error.stack = stack;
|
|
921
|
+
return;
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
Object.defineProperty(error, 'stack', {
|
|
925
|
+
configurable: true,
|
|
926
|
+
value: stack,
|
|
927
|
+
writable: true
|
|
928
|
+
});
|
|
929
|
+
};
|
|
930
|
+
const restoreExistingError = (error, currentStack) => {
|
|
931
|
+
if (typeof error.stack === 'string') {
|
|
932
|
+
setStack(error, `${error.stack}${NewLine$2}${currentStack}`);
|
|
933
|
+
}
|
|
934
|
+
return error;
|
|
935
|
+
};
|
|
936
|
+
const restoreMethodNotFoundError = (error, currentStack) => {
|
|
937
|
+
const restoredError = new JsonRpcError(error.message);
|
|
938
|
+
const parentStack = getParentStack(error);
|
|
939
|
+
setStack(restoredError, `${parentStack}${NewLine$2}${currentStack}`);
|
|
940
|
+
return restoredError;
|
|
941
|
+
};
|
|
942
|
+
const restoreStackFromData = (restoredError, error, currentStack) => {
|
|
943
|
+
if (error.data.stack && error.data.type && error.message) {
|
|
944
|
+
setStack(restoredError, `${error.data.type}: ${error.message}${NewLine$2}${error.data.stack}${NewLine$2}${currentStack}`);
|
|
945
|
+
return;
|
|
946
|
+
}
|
|
947
|
+
if (error.data.stack) {
|
|
948
|
+
setStack(restoredError, error.data.stack);
|
|
949
|
+
}
|
|
950
|
+
};
|
|
951
|
+
const applyDataProperties = (restoredError, error) => {
|
|
952
|
+
restoreStackFromData(restoredError, error, getCurrentStack());
|
|
953
|
+
if (error.data.codeFrame) {
|
|
954
|
+
// @ts-ignore
|
|
955
|
+
restoredError.codeFrame = error.data.codeFrame;
|
|
956
|
+
}
|
|
957
|
+
if (error.data.code) {
|
|
958
|
+
// @ts-ignore
|
|
959
|
+
restoredError.code = error.data.code;
|
|
960
|
+
}
|
|
961
|
+
if (error.data.type) {
|
|
962
|
+
// @ts-ignore
|
|
963
|
+
restoredError.name = error.data.type;
|
|
964
|
+
}
|
|
965
|
+
};
|
|
966
|
+
const applyDirectProperties = (restoredError, error) => {
|
|
967
|
+
if (error.stack) {
|
|
968
|
+
const lowerStack = restoredError.stack || '';
|
|
969
|
+
const indexNewLine = getNewLineIndex$1(lowerStack);
|
|
970
|
+
const parentStack = getParentStack(error);
|
|
971
|
+
// @ts-ignore
|
|
972
|
+
setStack(restoredError, `${parentStack}${lowerStack.slice(indexNewLine)}`);
|
|
973
|
+
}
|
|
974
|
+
if (error.codeFrame) {
|
|
975
|
+
// @ts-ignore
|
|
976
|
+
restoredError.codeFrame = error.codeFrame;
|
|
977
|
+
}
|
|
978
|
+
};
|
|
979
|
+
const restoreMessageError = (error, _currentStack) => {
|
|
980
|
+
const restoredError = constructError(error.message, error.type, error.name);
|
|
981
|
+
if (error.data) {
|
|
982
|
+
applyDataProperties(restoredError, error);
|
|
983
|
+
} else {
|
|
984
|
+
applyDirectProperties(restoredError, error);
|
|
985
|
+
}
|
|
986
|
+
return restoredError;
|
|
987
|
+
};
|
|
901
988
|
const restoreJsonRpcError = error => {
|
|
902
989
|
const currentStack = getCurrentStack();
|
|
903
990
|
if (error && error instanceof Error) {
|
|
904
|
-
|
|
905
|
-
error.stack = error.stack + NewLine$2 + currentStack;
|
|
906
|
-
}
|
|
907
|
-
return error;
|
|
991
|
+
return restoreExistingError(error, currentStack);
|
|
908
992
|
}
|
|
909
993
|
if (error && error.code && error.code === MethodNotFound) {
|
|
910
|
-
|
|
911
|
-
const parentStack = getParentStack(error);
|
|
912
|
-
restoredError.stack = parentStack + NewLine$2 + currentStack;
|
|
913
|
-
return restoredError;
|
|
994
|
+
return restoreMethodNotFoundError(error, currentStack);
|
|
914
995
|
}
|
|
915
996
|
if (error && error.message) {
|
|
916
|
-
|
|
917
|
-
if (error.data) {
|
|
918
|
-
if (error.data.stack && error.data.type && error.message) {
|
|
919
|
-
restoredError.stack = error.data.type + ': ' + error.message + NewLine$2 + error.data.stack + NewLine$2 + currentStack;
|
|
920
|
-
} else if (error.data.stack) {
|
|
921
|
-
restoredError.stack = error.data.stack;
|
|
922
|
-
}
|
|
923
|
-
if (error.data.codeFrame) {
|
|
924
|
-
// @ts-ignore
|
|
925
|
-
restoredError.codeFrame = error.data.codeFrame;
|
|
926
|
-
}
|
|
927
|
-
if (error.data.code) {
|
|
928
|
-
// @ts-ignore
|
|
929
|
-
restoredError.code = error.data.code;
|
|
930
|
-
}
|
|
931
|
-
if (error.data.type) {
|
|
932
|
-
// @ts-ignore
|
|
933
|
-
restoredError.name = error.data.type;
|
|
934
|
-
}
|
|
935
|
-
} else {
|
|
936
|
-
if (error.stack) {
|
|
937
|
-
const lowerStack = restoredError.stack || '';
|
|
938
|
-
// @ts-ignore
|
|
939
|
-
const indexNewLine = getNewLineIndex$1(lowerStack);
|
|
940
|
-
const parentStack = getParentStack(error);
|
|
941
|
-
// @ts-ignore
|
|
942
|
-
restoredError.stack = parentStack + lowerStack.slice(indexNewLine);
|
|
943
|
-
}
|
|
944
|
-
if (error.codeFrame) {
|
|
945
|
-
// @ts-ignore
|
|
946
|
-
restoredError.codeFrame = error.codeFrame;
|
|
947
|
-
}
|
|
948
|
-
}
|
|
949
|
-
return restoredError;
|
|
997
|
+
return restoreMessageError(error);
|
|
950
998
|
}
|
|
951
999
|
if (typeof error === 'string') {
|
|
952
1000
|
return new Error(`JsonRpc Error: ${error}`);
|
|
@@ -1505,14 +1553,14 @@ const remove = id => {
|
|
|
1505
1553
|
};
|
|
1506
1554
|
|
|
1507
1555
|
// TODO maybe merge pty and pty controller
|
|
1508
|
-
const
|
|
1556
|
+
const createWithDependencies = async (ipc, id, cwd, command, args, createPty) => {
|
|
1509
1557
|
number(id);
|
|
1510
1558
|
string(cwd);
|
|
1511
1559
|
string(command);
|
|
1512
1560
|
array(args);
|
|
1513
1561
|
object(ipc);
|
|
1514
1562
|
// @ts-ignore
|
|
1515
|
-
const pty = await
|
|
1563
|
+
const pty = await createPty({
|
|
1516
1564
|
args,
|
|
1517
1565
|
command,
|
|
1518
1566
|
cwd
|
|
@@ -1524,9 +1572,23 @@ const create = async (ipc, id, cwd, command, args) => {
|
|
|
1524
1572
|
params: [id, 'handleData', event.data]
|
|
1525
1573
|
});
|
|
1526
1574
|
};
|
|
1575
|
+
const handleExit = event => {
|
|
1576
|
+
remove(id);
|
|
1577
|
+
ipc.send({
|
|
1578
|
+
jsonrpc: '2.0',
|
|
1579
|
+
method: 'Viewlet.send',
|
|
1580
|
+
params: [id, 'handleExit', event.data]
|
|
1581
|
+
});
|
|
1582
|
+
};
|
|
1527
1583
|
pty.addEventListener('data', handleData);
|
|
1584
|
+
pty.addEventListener('exit', handleExit, {
|
|
1585
|
+
once: true
|
|
1586
|
+
});
|
|
1528
1587
|
set(id, pty);
|
|
1529
1588
|
};
|
|
1589
|
+
const create = (ipc, id, cwd, command, args) => {
|
|
1590
|
+
return createWithDependencies(ipc, id, cwd, command, args, create$1);
|
|
1591
|
+
};
|
|
1530
1592
|
const write = (id, data) => {
|
|
1531
1593
|
const pty = get(id);
|
|
1532
1594
|
if (!pty) {
|
|
@@ -1544,7 +1606,7 @@ const resize = (id, columns, rows) => {
|
|
|
1544
1606
|
const dispose = id => {
|
|
1545
1607
|
const pty = get(id);
|
|
1546
1608
|
if (!pty) {
|
|
1547
|
-
|
|
1609
|
+
return;
|
|
1548
1610
|
}
|
|
1549
1611
|
pty.dispose();
|
|
1550
1612
|
remove(id);
|