@lvce-editor/extension-management-worker 2.3.0 → 3.1.0
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/extensionManagementWorkerMain.js +263 -226
- package/package.json +1 -1
|
@@ -540,7 +540,7 @@ const waitForWebSocketToBeOpen = webSocket => {
|
|
|
540
540
|
open: Open
|
|
541
541
|
});
|
|
542
542
|
};
|
|
543
|
-
const create$
|
|
543
|
+
const create$c = async ({
|
|
544
544
|
webSocket
|
|
545
545
|
}) => {
|
|
546
546
|
const firstWebSocketEvent = await waitForWebSocketToBeOpen(webSocket);
|
|
@@ -577,60 +577,39 @@ const wrap = webSocket => {
|
|
|
577
577
|
};
|
|
578
578
|
const IpcParentWithWebSocket$1 = {
|
|
579
579
|
__proto__: null,
|
|
580
|
-
create: create$
|
|
580
|
+
create: create$c,
|
|
581
581
|
wrap
|
|
582
582
|
};
|
|
583
583
|
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
584
|
+
class CommandNotFoundError extends Error {
|
|
585
|
+
constructor(command) {
|
|
586
|
+
super(`Command not found ${command}`);
|
|
587
|
+
this.name = 'CommandNotFoundError';
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
const commands = Object.create(null);
|
|
591
|
+
const register = commandMap => {
|
|
592
|
+
Object.assign(commands, commandMap);
|
|
591
593
|
};
|
|
592
|
-
const
|
|
593
|
-
|
|
594
|
-
callbacks[id] = fn;
|
|
594
|
+
const getCommand = key => {
|
|
595
|
+
return commands[key];
|
|
595
596
|
};
|
|
596
|
-
const
|
|
597
|
+
const execute = (command, ...args) => {
|
|
598
|
+
const fn = getCommand(command);
|
|
599
|
+
if (!fn) {
|
|
600
|
+
throw new CommandNotFoundError(command);
|
|
601
|
+
}
|
|
602
|
+
return fn(...args);
|
|
603
|
+
};
|
|
604
|
+
|
|
605
|
+
const Two$1 = '2.0';
|
|
606
|
+
const callbacks = Object.create(null);
|
|
607
|
+
const get$6 = id => {
|
|
597
608
|
return callbacks[id];
|
|
598
609
|
};
|
|
599
|
-
const remove = id => {
|
|
610
|
+
const remove$1 = id => {
|
|
600
611
|
delete callbacks[id];
|
|
601
612
|
};
|
|
602
|
-
let id$1 = 0;
|
|
603
|
-
const create$3$1 = () => {
|
|
604
|
-
return ++id$1;
|
|
605
|
-
};
|
|
606
|
-
const registerPromise = () => {
|
|
607
|
-
const id = create$3$1();
|
|
608
|
-
const {
|
|
609
|
-
resolve,
|
|
610
|
-
promise
|
|
611
|
-
} = Promise.withResolvers();
|
|
612
|
-
set$8(id, resolve);
|
|
613
|
-
return {
|
|
614
|
-
id,
|
|
615
|
-
promise
|
|
616
|
-
};
|
|
617
|
-
};
|
|
618
|
-
const create$2$1 = (method, params) => {
|
|
619
|
-
const {
|
|
620
|
-
id,
|
|
621
|
-
promise
|
|
622
|
-
} = registerPromise();
|
|
623
|
-
const message = {
|
|
624
|
-
jsonrpc: Two,
|
|
625
|
-
method,
|
|
626
|
-
params,
|
|
627
|
-
id
|
|
628
|
-
};
|
|
629
|
-
return {
|
|
630
|
-
message,
|
|
631
|
-
promise
|
|
632
|
-
};
|
|
633
|
-
};
|
|
634
613
|
class JsonRpcError extends Error {
|
|
635
614
|
constructor(message) {
|
|
636
615
|
super(message);
|
|
@@ -647,12 +626,12 @@ const getErrorConstructor = (message, type) => {
|
|
|
647
626
|
switch (type) {
|
|
648
627
|
case DomException:
|
|
649
628
|
return DOMException;
|
|
650
|
-
case TypeError$1:
|
|
651
|
-
return TypeError;
|
|
652
|
-
case SyntaxError$1:
|
|
653
|
-
return SyntaxError;
|
|
654
629
|
case ReferenceError$1:
|
|
655
630
|
return ReferenceError;
|
|
631
|
+
case SyntaxError$1:
|
|
632
|
+
return SyntaxError;
|
|
633
|
+
case TypeError$1:
|
|
634
|
+
return TypeError;
|
|
656
635
|
default:
|
|
657
636
|
return Error;
|
|
658
637
|
}
|
|
@@ -774,14 +753,14 @@ const warn$1 = (...args) => {
|
|
|
774
753
|
console.warn(...args);
|
|
775
754
|
};
|
|
776
755
|
const resolve = (id, response) => {
|
|
777
|
-
const fn = get$
|
|
756
|
+
const fn = get$6(id);
|
|
778
757
|
if (!fn) {
|
|
779
758
|
console.log(response);
|
|
780
759
|
warn$1(`callback ${id} may already be disposed`);
|
|
781
760
|
return;
|
|
782
761
|
}
|
|
783
762
|
fn(response);
|
|
784
|
-
remove(id);
|
|
763
|
+
remove$1(id);
|
|
785
764
|
};
|
|
786
765
|
const E_COMMAND_NOT_FOUND = 'E_COMMAND_NOT_FOUND';
|
|
787
766
|
const getErrorType = prettyError => {
|
|
@@ -808,56 +787,56 @@ const getErrorProperty = (error, prettyError) => {
|
|
|
808
787
|
if (error && error.code === E_COMMAND_NOT_FOUND) {
|
|
809
788
|
return {
|
|
810
789
|
code: MethodNotFound,
|
|
811
|
-
|
|
812
|
-
|
|
790
|
+
data: error.stack,
|
|
791
|
+
message: error.message
|
|
813
792
|
};
|
|
814
793
|
}
|
|
815
794
|
return {
|
|
816
795
|
code: Custom,
|
|
817
|
-
message: prettyError.message,
|
|
818
796
|
data: {
|
|
819
|
-
stack: getStack(prettyError),
|
|
820
|
-
codeFrame: prettyError.codeFrame,
|
|
821
|
-
type: getErrorType(prettyError),
|
|
822
797
|
code: prettyError.code,
|
|
823
|
-
|
|
824
|
-
|
|
798
|
+
codeFrame: prettyError.codeFrame,
|
|
799
|
+
name: prettyError.name,
|
|
800
|
+
stack: getStack(prettyError),
|
|
801
|
+
type: getErrorType(prettyError)
|
|
802
|
+
},
|
|
803
|
+
message: prettyError.message
|
|
825
804
|
};
|
|
826
805
|
};
|
|
827
|
-
const create$1$
|
|
806
|
+
const create$1$1 = (id, error) => {
|
|
828
807
|
return {
|
|
829
|
-
|
|
808
|
+
error,
|
|
830
809
|
id,
|
|
831
|
-
|
|
810
|
+
jsonrpc: Two$1
|
|
832
811
|
};
|
|
833
812
|
};
|
|
834
813
|
const getErrorResponse = (id, error, preparePrettyError, logError) => {
|
|
835
814
|
const prettyError = preparePrettyError(error);
|
|
836
815
|
logError(error, prettyError);
|
|
837
816
|
const errorProperty = getErrorProperty(error, prettyError);
|
|
838
|
-
return create$1$
|
|
817
|
+
return create$1$1(id, errorProperty);
|
|
839
818
|
};
|
|
840
|
-
const create$
|
|
819
|
+
const create$b = (message, result) => {
|
|
841
820
|
return {
|
|
842
|
-
jsonrpc: Two,
|
|
843
821
|
id: message.id,
|
|
822
|
+
jsonrpc: Two$1,
|
|
844
823
|
result: result ?? null
|
|
845
824
|
};
|
|
846
825
|
};
|
|
847
826
|
const getSuccessResponse = (message, result) => {
|
|
848
827
|
const resultProperty = result ?? null;
|
|
849
|
-
return create$
|
|
828
|
+
return create$b(message, resultProperty);
|
|
850
829
|
};
|
|
851
830
|
const getErrorResponseSimple = (id, error) => {
|
|
852
831
|
return {
|
|
853
|
-
jsonrpc: Two,
|
|
854
|
-
id,
|
|
855
832
|
error: {
|
|
856
833
|
code: Custom,
|
|
834
|
+
data: error,
|
|
857
835
|
// @ts-ignore
|
|
858
|
-
message: error.message
|
|
859
|
-
|
|
860
|
-
|
|
836
|
+
message: error.message
|
|
837
|
+
},
|
|
838
|
+
id,
|
|
839
|
+
jsonrpc: Two$1
|
|
861
840
|
};
|
|
862
841
|
};
|
|
863
842
|
const getResponse = async (message, ipc, execute, preparePrettyError, logError, requiresSocket) => {
|
|
@@ -887,35 +866,35 @@ const normalizeParams = args => {
|
|
|
887
866
|
if (args.length === 1) {
|
|
888
867
|
const options = args[0];
|
|
889
868
|
return {
|
|
869
|
+
execute: options.execute,
|
|
890
870
|
ipc: options.ipc,
|
|
871
|
+
logError: options.logError || defaultLogError,
|
|
891
872
|
message: options.message,
|
|
892
|
-
execute: options.execute,
|
|
893
|
-
resolve: options.resolve || defaultResolve,
|
|
894
873
|
preparePrettyError: options.preparePrettyError || defaultPreparePrettyError,
|
|
895
|
-
|
|
896
|
-
|
|
874
|
+
requiresSocket: options.requiresSocket || defaultRequiresSocket,
|
|
875
|
+
resolve: options.resolve || defaultResolve
|
|
897
876
|
};
|
|
898
877
|
}
|
|
899
878
|
return {
|
|
879
|
+
execute: args[2],
|
|
900
880
|
ipc: args[0],
|
|
881
|
+
logError: args[5],
|
|
901
882
|
message: args[1],
|
|
902
|
-
execute: args[2],
|
|
903
|
-
resolve: args[3],
|
|
904
883
|
preparePrettyError: args[4],
|
|
905
|
-
|
|
906
|
-
|
|
884
|
+
requiresSocket: args[6],
|
|
885
|
+
resolve: args[3]
|
|
907
886
|
};
|
|
908
887
|
};
|
|
909
888
|
const handleJsonRpcMessage = async (...args) => {
|
|
910
889
|
const options = normalizeParams(args);
|
|
911
890
|
const {
|
|
912
|
-
message,
|
|
913
|
-
ipc,
|
|
914
891
|
execute,
|
|
915
|
-
|
|
916
|
-
preparePrettyError,
|
|
892
|
+
ipc,
|
|
917
893
|
logError,
|
|
918
|
-
|
|
894
|
+
message,
|
|
895
|
+
preparePrettyError,
|
|
896
|
+
requiresSocket,
|
|
897
|
+
resolve
|
|
919
898
|
} = options;
|
|
920
899
|
if ('id' in message) {
|
|
921
900
|
if ('method' in message) {
|
|
@@ -937,11 +916,51 @@ const handleJsonRpcMessage = async (...args) => {
|
|
|
937
916
|
}
|
|
938
917
|
throw new JsonRpcError('unexpected message');
|
|
939
918
|
};
|
|
940
|
-
|
|
919
|
+
|
|
920
|
+
const Two = '2.0';
|
|
921
|
+
|
|
922
|
+
const create$a = (method, params) => {
|
|
923
|
+
return {
|
|
924
|
+
jsonrpc: Two,
|
|
925
|
+
method,
|
|
926
|
+
params
|
|
927
|
+
};
|
|
928
|
+
};
|
|
929
|
+
|
|
930
|
+
const create$9 = (id, method, params) => {
|
|
931
|
+
const message = {
|
|
932
|
+
id,
|
|
933
|
+
jsonrpc: Two,
|
|
934
|
+
method,
|
|
935
|
+
params
|
|
936
|
+
};
|
|
937
|
+
return message;
|
|
938
|
+
};
|
|
939
|
+
|
|
940
|
+
let id$1 = 0;
|
|
941
|
+
const create$8 = () => {
|
|
942
|
+
return ++id$1;
|
|
943
|
+
};
|
|
944
|
+
|
|
945
|
+
const registerPromise = map => {
|
|
946
|
+
const id = create$8();
|
|
941
947
|
const {
|
|
942
|
-
|
|
948
|
+
promise,
|
|
949
|
+
resolve
|
|
950
|
+
} = Promise.withResolvers();
|
|
951
|
+
map[id] = resolve;
|
|
952
|
+
return {
|
|
953
|
+
id,
|
|
954
|
+
promise
|
|
955
|
+
};
|
|
956
|
+
};
|
|
957
|
+
|
|
958
|
+
const invokeHelper = async (callbacks, ipc, method, params, useSendAndTransfer) => {
|
|
959
|
+
const {
|
|
960
|
+
id,
|
|
943
961
|
promise
|
|
944
|
-
} =
|
|
962
|
+
} = registerPromise(callbacks);
|
|
963
|
+
const message = create$9(id, method, params);
|
|
945
964
|
if (useSendAndTransfer && ipc.sendAndTransfer) {
|
|
946
965
|
ipc.sendAndTransfer(message);
|
|
947
966
|
} else {
|
|
@@ -950,60 +969,40 @@ const invokeHelper = async (ipc, method, params, useSendAndTransfer) => {
|
|
|
950
969
|
const responseMessage = await promise;
|
|
951
970
|
return unwrapJsonRpcResult(responseMessage);
|
|
952
971
|
};
|
|
953
|
-
const send = (transport, method, ...params) => {
|
|
954
|
-
const message = create$4$1(method, params);
|
|
955
|
-
transport.send(message);
|
|
956
|
-
};
|
|
957
|
-
const invoke$5 = (ipc, method, ...params) => {
|
|
958
|
-
return invokeHelper(ipc, method, params, false);
|
|
959
|
-
};
|
|
960
|
-
const invokeAndTransfer$2 = (ipc, method, ...params) => {
|
|
961
|
-
return invokeHelper(ipc, method, params, true);
|
|
962
|
-
};
|
|
963
|
-
|
|
964
|
-
class CommandNotFoundError extends Error {
|
|
965
|
-
constructor(command) {
|
|
966
|
-
super(`Command not found ${command}`);
|
|
967
|
-
this.name = 'CommandNotFoundError';
|
|
968
|
-
}
|
|
969
|
-
}
|
|
970
|
-
const commands = Object.create(null);
|
|
971
|
-
const register = commandMap => {
|
|
972
|
-
Object.assign(commands, commandMap);
|
|
973
|
-
};
|
|
974
|
-
const getCommand = key => {
|
|
975
|
-
return commands[key];
|
|
976
|
-
};
|
|
977
|
-
const execute = (command, ...args) => {
|
|
978
|
-
const fn = getCommand(command);
|
|
979
|
-
if (!fn) {
|
|
980
|
-
throw new CommandNotFoundError(command);
|
|
981
|
-
}
|
|
982
|
-
return fn(...args);
|
|
983
|
-
};
|
|
984
|
-
|
|
985
972
|
const createRpc = ipc => {
|
|
973
|
+
const callbacks = Object.create(null);
|
|
974
|
+
ipc._resolve = (id, response) => {
|
|
975
|
+
const fn = callbacks[id];
|
|
976
|
+
if (!fn) {
|
|
977
|
+
console.warn(`callback ${id} may already be disposed`);
|
|
978
|
+
return;
|
|
979
|
+
}
|
|
980
|
+
fn(response);
|
|
981
|
+
delete callbacks[id];
|
|
982
|
+
};
|
|
986
983
|
const rpc = {
|
|
984
|
+
async dispose() {
|
|
985
|
+
await ipc?.dispose();
|
|
986
|
+
},
|
|
987
|
+
invoke(method, ...params) {
|
|
988
|
+
return invokeHelper(callbacks, ipc, method, params, false);
|
|
989
|
+
},
|
|
990
|
+
invokeAndTransfer(method, ...params) {
|
|
991
|
+
return invokeHelper(callbacks, ipc, method, params, true);
|
|
992
|
+
},
|
|
987
993
|
// @ts-ignore
|
|
988
994
|
ipc,
|
|
989
995
|
/**
|
|
990
996
|
* @deprecated
|
|
991
997
|
*/
|
|
992
998
|
send(method, ...params) {
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
invoke(method, ...params) {
|
|
996
|
-
return invoke$5(ipc, method, ...params);
|
|
997
|
-
},
|
|
998
|
-
invokeAndTransfer(method, ...params) {
|
|
999
|
-
return invokeAndTransfer$2(ipc, method, ...params);
|
|
1000
|
-
},
|
|
1001
|
-
async dispose() {
|
|
1002
|
-
await ipc?.dispose();
|
|
999
|
+
const message = create$a(method, params);
|
|
1000
|
+
ipc.send(message);
|
|
1003
1001
|
}
|
|
1004
1002
|
};
|
|
1005
1003
|
return rpc;
|
|
1006
1004
|
};
|
|
1005
|
+
|
|
1007
1006
|
const requiresSocket = () => {
|
|
1008
1007
|
return false;
|
|
1009
1008
|
};
|
|
@@ -1016,8 +1015,9 @@ const logError = () => {
|
|
|
1016
1015
|
const handleMessage = event => {
|
|
1017
1016
|
const actualRequiresSocket = event?.target?.requiresSocket || requiresSocket;
|
|
1018
1017
|
const actualExecute = event?.target?.execute || execute;
|
|
1019
|
-
return handleJsonRpcMessage(event.target, event.data, actualExecute,
|
|
1018
|
+
return handleJsonRpcMessage(event.target, event.data, actualExecute, event.target._resolve, preparePrettyError, logError, actualRequiresSocket);
|
|
1020
1019
|
};
|
|
1020
|
+
|
|
1021
1021
|
const handleIpc = ipc => {
|
|
1022
1022
|
if ('addEventListener' in ipc) {
|
|
1023
1023
|
ipc.addEventListener('message', handleMessage);
|
|
@@ -1026,6 +1026,7 @@ const handleIpc = ipc => {
|
|
|
1026
1026
|
ipc.on('message', handleMessage);
|
|
1027
1027
|
}
|
|
1028
1028
|
};
|
|
1029
|
+
|
|
1029
1030
|
const listen$1 = async (module, options) => {
|
|
1030
1031
|
const rawIpc = await module.listen(options);
|
|
1031
1032
|
if (module.signal) {
|
|
@@ -1034,35 +1035,17 @@ const listen$1 = async (module, options) => {
|
|
|
1034
1035
|
const ipc = module.wrap(rawIpc);
|
|
1035
1036
|
return ipc;
|
|
1036
1037
|
};
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
messagePort,
|
|
1040
|
-
isMessagePortOpen
|
|
1041
|
-
}) => {
|
|
1042
|
-
// TODO create a commandMap per rpc instance
|
|
1043
|
-
register(commandMap);
|
|
1044
|
-
const rawIpc = await IpcParentWithMessagePort$1.create({
|
|
1045
|
-
messagePort,
|
|
1046
|
-
isMessagePortOpen
|
|
1047
|
-
});
|
|
1048
|
-
const ipc = IpcParentWithMessagePort$1.wrap(rawIpc);
|
|
1049
|
-
handleIpc(ipc);
|
|
1050
|
-
const rpc = createRpc(ipc);
|
|
1051
|
-
return rpc;
|
|
1052
|
-
};
|
|
1053
|
-
const MessagePortRpcParent = {
|
|
1054
|
-
__proto__: null,
|
|
1055
|
-
create: create$e
|
|
1056
|
-
};
|
|
1057
|
-
const create$5 = async ({
|
|
1038
|
+
|
|
1039
|
+
const create$7 = async ({
|
|
1058
1040
|
commandMap,
|
|
1041
|
+
isMessagePortOpen = true,
|
|
1059
1042
|
messagePort
|
|
1060
1043
|
}) => {
|
|
1061
1044
|
// TODO create a commandMap per rpc instance
|
|
1062
1045
|
register(commandMap);
|
|
1063
1046
|
const rawIpc = await IpcParentWithMessagePort$1.create({
|
|
1064
|
-
|
|
1065
|
-
|
|
1047
|
+
isMessagePortOpen,
|
|
1048
|
+
messagePort
|
|
1066
1049
|
});
|
|
1067
1050
|
const ipc = IpcParentWithMessagePort$1.wrap(rawIpc);
|
|
1068
1051
|
handleIpc(ipc);
|
|
@@ -1070,12 +1053,10 @@ const create$5 = async ({
|
|
|
1070
1053
|
messagePort.start();
|
|
1071
1054
|
return rpc;
|
|
1072
1055
|
};
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
create: create$5
|
|
1076
|
-
};
|
|
1077
|
-
const create$3 = async ({
|
|
1056
|
+
|
|
1057
|
+
const create$6 = async ({
|
|
1078
1058
|
commandMap,
|
|
1059
|
+
isMessagePortOpen,
|
|
1079
1060
|
send
|
|
1080
1061
|
}) => {
|
|
1081
1062
|
const {
|
|
@@ -1083,46 +1064,49 @@ const create$3 = async ({
|
|
|
1083
1064
|
port2
|
|
1084
1065
|
} = new MessageChannel();
|
|
1085
1066
|
await send(port1);
|
|
1086
|
-
return create$
|
|
1067
|
+
return create$7({
|
|
1087
1068
|
commandMap,
|
|
1069
|
+
isMessagePortOpen,
|
|
1088
1070
|
messagePort: port2
|
|
1089
1071
|
});
|
|
1090
1072
|
};
|
|
1091
|
-
|
|
1092
|
-
__proto__: null,
|
|
1093
|
-
create: create$3
|
|
1094
|
-
};
|
|
1095
|
-
const create$2 = async ({
|
|
1096
|
-
commandMap,
|
|
1097
|
-
webSocket
|
|
1098
|
-
}) => {
|
|
1099
|
-
// TODO create a commandMap per rpc instance
|
|
1100
|
-
register(commandMap);
|
|
1101
|
-
const rawIpc = await IpcParentWithWebSocket$1.create({
|
|
1102
|
-
webSocket
|
|
1103
|
-
});
|
|
1104
|
-
const ipc = IpcParentWithWebSocket$1.wrap(rawIpc);
|
|
1105
|
-
handleIpc(ipc);
|
|
1106
|
-
const rpc = createRpc(ipc);
|
|
1107
|
-
return rpc;
|
|
1108
|
-
};
|
|
1073
|
+
|
|
1109
1074
|
const Https = 'https:';
|
|
1110
1075
|
const Ws = 'ws:';
|
|
1111
1076
|
const Wss = 'wss:';
|
|
1077
|
+
|
|
1112
1078
|
const getWebSocketProtocol = locationProtocol => {
|
|
1113
1079
|
return locationProtocol === Https ? Wss : Ws;
|
|
1114
1080
|
};
|
|
1081
|
+
|
|
1115
1082
|
const getWebSocketUrl = (type, host, locationProtocol) => {
|
|
1116
1083
|
const wsProtocol = getWebSocketProtocol(locationProtocol);
|
|
1117
1084
|
return `${wsProtocol}//${host}/websocket/${type}`;
|
|
1118
1085
|
};
|
|
1086
|
+
|
|
1119
1087
|
const getHost = () => {
|
|
1120
1088
|
return location.host;
|
|
1121
1089
|
};
|
|
1122
1090
|
const getProtocol = () => {
|
|
1123
1091
|
return location.protocol;
|
|
1124
1092
|
};
|
|
1125
|
-
|
|
1093
|
+
|
|
1094
|
+
const create$5 = async ({
|
|
1095
|
+
commandMap,
|
|
1096
|
+
webSocket
|
|
1097
|
+
}) => {
|
|
1098
|
+
// TODO create a commandMap per rpc instance
|
|
1099
|
+
register(commandMap);
|
|
1100
|
+
const rawIpc = await IpcParentWithWebSocket$1.create({
|
|
1101
|
+
webSocket
|
|
1102
|
+
});
|
|
1103
|
+
const ipc = IpcParentWithWebSocket$1.wrap(rawIpc);
|
|
1104
|
+
handleIpc(ipc);
|
|
1105
|
+
const rpc = createRpc(ipc);
|
|
1106
|
+
return rpc;
|
|
1107
|
+
};
|
|
1108
|
+
|
|
1109
|
+
const create$4 = async ({
|
|
1126
1110
|
commandMap,
|
|
1127
1111
|
type
|
|
1128
1112
|
}) => {
|
|
@@ -1130,17 +1114,31 @@ const create$1$1 = async ({
|
|
|
1130
1114
|
const protocol = getProtocol();
|
|
1131
1115
|
const wsUrl = getWebSocketUrl(type, host, protocol);
|
|
1132
1116
|
const webSocket = new WebSocket(wsUrl);
|
|
1133
|
-
const rpc = await create$
|
|
1134
|
-
|
|
1135
|
-
|
|
1117
|
+
const rpc = await create$5({
|
|
1118
|
+
commandMap,
|
|
1119
|
+
webSocket
|
|
1136
1120
|
});
|
|
1137
1121
|
return rpc;
|
|
1138
1122
|
};
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1123
|
+
|
|
1124
|
+
const create$3 = async ({
|
|
1125
|
+
commandMap,
|
|
1126
|
+
isMessagePortOpen,
|
|
1127
|
+
messagePort
|
|
1128
|
+
}) => {
|
|
1129
|
+
// TODO create a commandMap per rpc instance
|
|
1130
|
+
register(commandMap);
|
|
1131
|
+
const rawIpc = await IpcParentWithMessagePort$1.create({
|
|
1132
|
+
isMessagePortOpen,
|
|
1133
|
+
messagePort
|
|
1134
|
+
});
|
|
1135
|
+
const ipc = IpcParentWithMessagePort$1.wrap(rawIpc);
|
|
1136
|
+
handleIpc(ipc);
|
|
1137
|
+
const rpc = createRpc(ipc);
|
|
1138
|
+
return rpc;
|
|
1142
1139
|
};
|
|
1143
|
-
|
|
1140
|
+
|
|
1141
|
+
const create$2 = async ({
|
|
1144
1142
|
commandMap
|
|
1145
1143
|
}) => {
|
|
1146
1144
|
// TODO create a commandMap per rpc instance
|
|
@@ -1150,53 +1148,85 @@ const create$4 = async ({
|
|
|
1150
1148
|
const rpc = createRpc(ipc);
|
|
1151
1149
|
return rpc;
|
|
1152
1150
|
};
|
|
1153
|
-
const WebWorkerRpcClient = {
|
|
1154
|
-
__proto__: null,
|
|
1155
|
-
create: create$4
|
|
1156
|
-
};
|
|
1157
1151
|
|
|
1158
|
-
const
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
const
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
const
|
|
1165
|
-
|
|
1166
|
-
|
|
1152
|
+
const createMockRpc = ({
|
|
1153
|
+
commandMap
|
|
1154
|
+
}) => {
|
|
1155
|
+
const invocations = [];
|
|
1156
|
+
const invoke = (method, ...params) => {
|
|
1157
|
+
invocations.push([method, ...params]);
|
|
1158
|
+
const command = commandMap[method];
|
|
1159
|
+
if (!command) {
|
|
1160
|
+
throw new Error(`command ${method} not found`);
|
|
1161
|
+
}
|
|
1162
|
+
return command(...params);
|
|
1163
|
+
};
|
|
1164
|
+
const mockRpc = {
|
|
1165
|
+
invocations,
|
|
1166
|
+
invoke,
|
|
1167
|
+
invokeAndTransfer: invoke
|
|
1168
|
+
};
|
|
1169
|
+
return mockRpc;
|
|
1170
|
+
};
|
|
1167
1171
|
|
|
1168
1172
|
const rpcs$1 = Object.create(null);
|
|
1169
1173
|
const set$7 = (id, rpc) => {
|
|
1170
1174
|
rpcs$1[id] = rpc;
|
|
1171
1175
|
};
|
|
1172
|
-
const get$
|
|
1176
|
+
const get$5 = id => {
|
|
1173
1177
|
return rpcs$1[id];
|
|
1174
1178
|
};
|
|
1179
|
+
const remove = id => {
|
|
1180
|
+
delete rpcs$1[id];
|
|
1181
|
+
};
|
|
1175
1182
|
|
|
1183
|
+
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
|
1176
1184
|
const create$1 = rpcId => {
|
|
1177
1185
|
return {
|
|
1178
1186
|
async dispose() {
|
|
1179
|
-
const rpc = get$
|
|
1187
|
+
const rpc = get$5(rpcId);
|
|
1180
1188
|
await rpc.dispose();
|
|
1181
1189
|
},
|
|
1182
1190
|
// @ts-ignore
|
|
1183
1191
|
invoke(method, ...params) {
|
|
1184
|
-
const rpc = get$
|
|
1192
|
+
const rpc = get$5(rpcId);
|
|
1185
1193
|
// @ts-ignore
|
|
1186
1194
|
return rpc.invoke(method, ...params);
|
|
1187
1195
|
},
|
|
1188
1196
|
// @ts-ignore
|
|
1189
1197
|
invokeAndTransfer(method, ...params) {
|
|
1190
|
-
const rpc = get$
|
|
1198
|
+
const rpc = get$5(rpcId);
|
|
1191
1199
|
// @ts-ignore
|
|
1192
1200
|
return rpc.invokeAndTransfer(method, ...params);
|
|
1193
1201
|
},
|
|
1202
|
+
registerMockRpc(commandMap) {
|
|
1203
|
+
const mockRpc = createMockRpc({
|
|
1204
|
+
commandMap
|
|
1205
|
+
});
|
|
1206
|
+
set$7(rpcId, mockRpc);
|
|
1207
|
+
// @ts-ignore
|
|
1208
|
+
mockRpc[Symbol.dispose] = () => {
|
|
1209
|
+
remove(rpcId);
|
|
1210
|
+
};
|
|
1211
|
+
// @ts-ignore
|
|
1212
|
+
return mockRpc;
|
|
1213
|
+
},
|
|
1194
1214
|
set(rpc) {
|
|
1195
1215
|
set$7(rpcId, rpc);
|
|
1196
1216
|
}
|
|
1197
1217
|
};
|
|
1198
1218
|
};
|
|
1199
1219
|
|
|
1220
|
+
const Web = 1;
|
|
1221
|
+
const Electron = 2;
|
|
1222
|
+
const Remote = 3;
|
|
1223
|
+
const Test = 4;
|
|
1224
|
+
|
|
1225
|
+
const ExtensionHostWorker = 44;
|
|
1226
|
+
const FileSystemWorker = 209;
|
|
1227
|
+
const RendererWorker = 1;
|
|
1228
|
+
const SharedProcess = 1492;
|
|
1229
|
+
|
|
1200
1230
|
const {
|
|
1201
1231
|
invoke: invoke$4,
|
|
1202
1232
|
set: set$6
|
|
@@ -1213,7 +1243,6 @@ const writeFile = async (uri, content) => {
|
|
|
1213
1243
|
return invoke$3('FileSystem.writeFile', uri, content);
|
|
1214
1244
|
};
|
|
1215
1245
|
const exists = async uri => {
|
|
1216
|
-
// @ts-ignore
|
|
1217
1246
|
return invoke$3('FileSystem.exists', uri);
|
|
1218
1247
|
};
|
|
1219
1248
|
|
|
@@ -1224,7 +1253,6 @@ const {
|
|
|
1224
1253
|
} = create$1(RendererWorker);
|
|
1225
1254
|
const sendMessagePortToFileSystemWorker = async (port, rpcId) => {
|
|
1226
1255
|
const command = 'FileSystem.handleMessagePort';
|
|
1227
|
-
// @ts-ignore
|
|
1228
1256
|
await invokeAndTransfer$1('SendMessagePortToExtensionHostWorker.sendMessagePortToFileSystemWorker', port, command, rpcId);
|
|
1229
1257
|
};
|
|
1230
1258
|
const sendMessagePortToExtensionHostWorker = async (port, rpcId = 0) => {
|
|
@@ -1233,7 +1261,6 @@ const sendMessagePortToExtensionHostWorker = async (port, rpcId = 0) => {
|
|
|
1233
1261
|
};
|
|
1234
1262
|
const sendMessagePortToSharedProcess = async port => {
|
|
1235
1263
|
const command = 'HandleElectronMessagePort.handleElectronMessagePort';
|
|
1236
|
-
// @ts-ignore
|
|
1237
1264
|
await invokeAndTransfer$1('SendMessagePortToExtensionHostWorker.sendMessagePortToSharedProcess', port, command, 0);
|
|
1238
1265
|
};
|
|
1239
1266
|
|
|
@@ -1288,7 +1315,7 @@ const states = Object.create(null);
|
|
|
1288
1315
|
const set$2 = status => {
|
|
1289
1316
|
states[status.id] = status;
|
|
1290
1317
|
};
|
|
1291
|
-
const get$
|
|
1318
|
+
const get$4 = extensionId => {
|
|
1292
1319
|
return states[extensionId];
|
|
1293
1320
|
};
|
|
1294
1321
|
const update$1 = (id, update) => {
|
|
@@ -1369,7 +1396,9 @@ const activateExtension2 = async (extensionId, extension, absolutePath) => {
|
|
|
1369
1396
|
const id = getExtensionId(extension);
|
|
1370
1397
|
if (isImportError(error)) {
|
|
1371
1398
|
const actualErrorMessage = await tryToGetActualImportErrorMessage(absolutePath, error);
|
|
1372
|
-
throw new Error(`Failed to activate extension ${id}: ${actualErrorMessage}
|
|
1399
|
+
throw new Error(`Failed to activate extension ${id}: ${actualErrorMessage}`, {
|
|
1400
|
+
cause: error
|
|
1401
|
+
});
|
|
1373
1402
|
}
|
|
1374
1403
|
update$1(extensionId, {
|
|
1375
1404
|
status: Error$1 // TODO maybe store error also in runtime status state
|
|
@@ -1384,7 +1413,7 @@ const rpcs = Object.create(null);
|
|
|
1384
1413
|
const add = (id, rpc) => {
|
|
1385
1414
|
rpcs[id] = rpc;
|
|
1386
1415
|
};
|
|
1387
|
-
const get$
|
|
1416
|
+
const get$3 = id => {
|
|
1388
1417
|
return rpcs[id];
|
|
1389
1418
|
};
|
|
1390
1419
|
|
|
@@ -1452,7 +1481,9 @@ const importExtension = async (extensionId, absolutePath, activationEvent) => {
|
|
|
1452
1481
|
});
|
|
1453
1482
|
if (isImportError(error)) {
|
|
1454
1483
|
const actualErrorMessage = await tryToGetActualImportErrorMessage(absolutePath, error);
|
|
1455
|
-
throw new Error(actualErrorMessage
|
|
1484
|
+
throw new Error(actualErrorMessage, {
|
|
1485
|
+
cause: error
|
|
1486
|
+
});
|
|
1456
1487
|
}
|
|
1457
1488
|
throw error;
|
|
1458
1489
|
}
|
|
@@ -1479,6 +1510,12 @@ const activateExtension3 = async (extension, absolutePath, activationEvent, plat
|
|
|
1479
1510
|
const state$1 = {
|
|
1480
1511
|
webExtensions: []
|
|
1481
1512
|
};
|
|
1513
|
+
const push = extension => {
|
|
1514
|
+
state$1.webExtensions.push(extension);
|
|
1515
|
+
};
|
|
1516
|
+
const get$2 = () => {
|
|
1517
|
+
return state$1.webExtensions;
|
|
1518
|
+
};
|
|
1482
1519
|
|
|
1483
1520
|
const cache = Object.create(null);
|
|
1484
1521
|
const id = 1;
|
|
@@ -1522,7 +1559,7 @@ const addWebExtension = async path => {
|
|
|
1522
1559
|
const manifestPath = getWebManifestPath(path);
|
|
1523
1560
|
const manifest = await getWebExtensionManifest(path, manifestPath);
|
|
1524
1561
|
// TODO avoid mutation if possible
|
|
1525
|
-
|
|
1562
|
+
push(manifest);
|
|
1526
1563
|
clear();
|
|
1527
1564
|
return manifest;
|
|
1528
1565
|
};
|
|
@@ -1545,7 +1582,7 @@ const createWebViewWorkerRpc2 = async (rpcInfo, port) => {
|
|
|
1545
1582
|
// the two message ports
|
|
1546
1583
|
|
|
1547
1584
|
// TODO have a way so that the worker already includes the webview api and the extension
|
|
1548
|
-
// host
|
|
1585
|
+
// host sub-worker doesn't need to import the other file
|
|
1549
1586
|
await invokeAndTransfer('IpcParent.create', {
|
|
1550
1587
|
method: ModuleWorkerAndWorkaroundForChromeDevtoolsBug,
|
|
1551
1588
|
name: rpcInfo.name,
|
|
@@ -1575,7 +1612,7 @@ const createWebViewWorkerRpc = async (rpcInfo, port) => {
|
|
|
1575
1612
|
// the two message ports
|
|
1576
1613
|
|
|
1577
1614
|
// TODO have a way so that the worker already includes the webview api and the extension
|
|
1578
|
-
// host
|
|
1615
|
+
// host sub-worker doesn't need to import the other file
|
|
1579
1616
|
await invokeAndTransfer$1('IpcParent.create', {
|
|
1580
1617
|
method: ModuleWorkerAndWorkaroundForChromeDevtoolsBug,
|
|
1581
1618
|
name: rpcInfo.name,
|
|
@@ -1901,7 +1938,7 @@ const getColorThemeUri = (extensions, colorThemeId) => {
|
|
|
1901
1938
|
};
|
|
1902
1939
|
|
|
1903
1940
|
const getDynamicWebExtensions = () => {
|
|
1904
|
-
return
|
|
1941
|
+
return get$2();
|
|
1905
1942
|
};
|
|
1906
1943
|
|
|
1907
1944
|
const getWebExtensionsUrl = assetDir => {
|
|
@@ -1917,7 +1954,7 @@ const getWebExtensions = async assetDir => {
|
|
|
1917
1954
|
};
|
|
1918
1955
|
|
|
1919
1956
|
const getAllExtensions = async (assetDir, platform) => {
|
|
1920
|
-
if (
|
|
1957
|
+
if (typeof assetDir !== 'string') {
|
|
1921
1958
|
assetDir = await invoke$2('Layout.getAssetDir');
|
|
1922
1959
|
}
|
|
1923
1960
|
if (!platform) {
|
|
@@ -2026,7 +2063,7 @@ const createWebViewIpc = async webView => {
|
|
|
2026
2063
|
port1,
|
|
2027
2064
|
port2
|
|
2028
2065
|
} = getPortTuple();
|
|
2029
|
-
const rpcPromise =
|
|
2066
|
+
const rpcPromise = create$3({
|
|
2030
2067
|
commandMap: {},
|
|
2031
2068
|
isMessagePortOpen: false,
|
|
2032
2069
|
messagePort: port2
|
|
@@ -2047,8 +2084,8 @@ const getWebView = id => {
|
|
|
2047
2084
|
// TODO if webViewId is provided,
|
|
2048
2085
|
// 1. read file as blob
|
|
2049
2086
|
// 2. send blob to webview
|
|
2050
|
-
// 3. create
|
|
2051
|
-
// 4. send back
|
|
2087
|
+
// 3. create object URL in webview
|
|
2088
|
+
// 4. send back object URL to extension host worker
|
|
2052
2089
|
// 5. provide objectUrl to extension
|
|
2053
2090
|
|
|
2054
2091
|
const getRemoteUrlForWebView = async (uri, options = {}) => {
|
|
@@ -2063,7 +2100,7 @@ const getRemoteUrlForWebView = async (uri, options = {}) => {
|
|
|
2063
2100
|
};
|
|
2064
2101
|
|
|
2065
2102
|
const getRpcInfo = rpcId => {
|
|
2066
|
-
const info = get$
|
|
2103
|
+
const info = get$3(rpcId);
|
|
2067
2104
|
if (!info) {
|
|
2068
2105
|
throw new Error(`Rpc not found ${rpcId}`);
|
|
2069
2106
|
}
|
|
@@ -2082,20 +2119,20 @@ const emptyStatus = {
|
|
|
2082
2119
|
status: None
|
|
2083
2120
|
};
|
|
2084
2121
|
const getRuntimeStatus = extensionId => {
|
|
2085
|
-
return get$
|
|
2122
|
+
return get$4(extensionId) || emptyStatus;
|
|
2086
2123
|
};
|
|
2087
2124
|
|
|
2088
2125
|
const commandMapRef = {};
|
|
2089
2126
|
|
|
2090
2127
|
const handleMessagePort = async port => {
|
|
2091
|
-
await
|
|
2128
|
+
await create$7({
|
|
2092
2129
|
commandMap: commandMapRef,
|
|
2093
2130
|
messagePort: port
|
|
2094
2131
|
});
|
|
2095
2132
|
};
|
|
2096
2133
|
|
|
2097
2134
|
const initializeExtensionHostWorker = async () => {
|
|
2098
|
-
const rpc = await
|
|
2135
|
+
const rpc = await create$6({
|
|
2099
2136
|
commandMap: commandMapRef,
|
|
2100
2137
|
async send(port) {
|
|
2101
2138
|
await sendMessagePortToExtensionHostWorker(port, 0);
|
|
@@ -2105,7 +2142,7 @@ const initializeExtensionHostWorker = async () => {
|
|
|
2105
2142
|
};
|
|
2106
2143
|
|
|
2107
2144
|
const initializeFileSystemWorker = async () => {
|
|
2108
|
-
const rpc = await
|
|
2145
|
+
const rpc = await create$6({
|
|
2109
2146
|
commandMap: commandMapRef,
|
|
2110
2147
|
async send(port) {
|
|
2111
2148
|
await sendMessagePortToFileSystemWorker(port, 0);
|
|
@@ -2117,14 +2154,14 @@ const initializeFileSystemWorker = async () => {
|
|
|
2117
2154
|
const getRpc = async platform => {
|
|
2118
2155
|
// TODO create connection to shared process
|
|
2119
2156
|
if (platform === Remote) {
|
|
2120
|
-
const rpc = await
|
|
2157
|
+
const rpc = await create$4({
|
|
2121
2158
|
commandMap: commandMapRef,
|
|
2122
2159
|
type: 'shared-process'
|
|
2123
2160
|
});
|
|
2124
2161
|
return rpc;
|
|
2125
2162
|
}
|
|
2126
2163
|
if (platform === Electron) {
|
|
2127
|
-
const rpc =
|
|
2164
|
+
const rpc = create$6({
|
|
2128
2165
|
commandMap: commandMapRef,
|
|
2129
2166
|
async send(port) {
|
|
2130
2167
|
await sendMessagePortToSharedProcess(port);
|
|
@@ -2240,7 +2277,7 @@ const commandMap = {
|
|
|
2240
2277
|
|
|
2241
2278
|
const listen = async () => {
|
|
2242
2279
|
Object.assign(commandMapRef, commandMap);
|
|
2243
|
-
const rpc = await
|
|
2280
|
+
const rpc = await create$2({
|
|
2244
2281
|
commandMap: commandMap
|
|
2245
2282
|
});
|
|
2246
2283
|
set$4(rpc);
|