@lvce-editor/search-process 13.0.0 → 14.0.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/index.js +228 -253
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -10,35 +10,35 @@ import { pipeline } from 'node:stream/promises';
|
|
|
10
10
|
import { Buffer as Buffer$1 } from 'node:buffer';
|
|
11
11
|
|
|
12
12
|
const searches$1 = Object.create(null);
|
|
13
|
-
const get$
|
|
13
|
+
const get$2 = id => {
|
|
14
14
|
return searches$1[id];
|
|
15
15
|
};
|
|
16
|
-
const set$
|
|
16
|
+
const set$1 = (id, search) => {
|
|
17
17
|
searches$1[id] = search;
|
|
18
18
|
};
|
|
19
19
|
|
|
20
20
|
// @deprecated use TextSearch.getPullResults instead
|
|
21
21
|
const getIncrementalResults = (id, minLineY, maxLineY) => {
|
|
22
|
-
const item = get$
|
|
22
|
+
const item = get$2(id);
|
|
23
23
|
const visibleItems = item.getItems(minLineY, maxLineY);
|
|
24
24
|
return visibleItems;
|
|
25
25
|
};
|
|
26
26
|
|
|
27
27
|
const searches = Object.create(null);
|
|
28
|
-
const get$
|
|
28
|
+
const get$1 = id => {
|
|
29
29
|
return searches[id];
|
|
30
30
|
};
|
|
31
|
-
const set
|
|
31
|
+
const set = (id, search) => {
|
|
32
32
|
searches[id] = search;
|
|
33
33
|
};
|
|
34
34
|
|
|
35
35
|
const getPullProgress = id => {
|
|
36
|
-
const item = get$
|
|
36
|
+
const item = get$1(id);
|
|
37
37
|
return item.getProgress();
|
|
38
38
|
};
|
|
39
39
|
|
|
40
40
|
const getPullResults = id => {
|
|
41
|
-
const item = get$
|
|
41
|
+
const item = get$1(id);
|
|
42
42
|
const newItems = item.getNewItems();
|
|
43
43
|
return newItems;
|
|
44
44
|
};
|
|
@@ -337,8 +337,8 @@ const getModuleNotFoundError = stderr => {
|
|
|
337
337
|
const messageIndex = lines.findIndex(isModuleNotFoundMessage);
|
|
338
338
|
const message = lines[messageIndex];
|
|
339
339
|
return {
|
|
340
|
-
|
|
341
|
-
|
|
340
|
+
code: ERR_MODULE_NOT_FOUND,
|
|
341
|
+
message
|
|
342
342
|
};
|
|
343
343
|
};
|
|
344
344
|
const isModuleNotFoundError = stderr => {
|
|
@@ -361,14 +361,14 @@ const isUnhelpfulNativeModuleError = stderr => {
|
|
|
361
361
|
const getNativeModuleErrorMessage = stderr => {
|
|
362
362
|
const message = getMessageCodeBlock(stderr);
|
|
363
363
|
return {
|
|
364
|
-
|
|
365
|
-
|
|
364
|
+
code: E_INCOMPATIBLE_NATIVE_MODULE,
|
|
365
|
+
message: `Incompatible native node module: ${message}`
|
|
366
366
|
};
|
|
367
367
|
};
|
|
368
368
|
const getModuleSyntaxError = () => {
|
|
369
369
|
return {
|
|
370
|
-
|
|
371
|
-
|
|
370
|
+
code: E_MODULES_NOT_SUPPORTED_IN_ELECTRON,
|
|
371
|
+
message: `ES Modules are not supported in electron`
|
|
372
372
|
};
|
|
373
373
|
};
|
|
374
374
|
const getHelpfulChildProcessError = (stdout, stderr) => {
|
|
@@ -387,8 +387,8 @@ const getHelpfulChildProcessError = (stdout, stderr) => {
|
|
|
387
387
|
rest
|
|
388
388
|
} = getDetails(lines);
|
|
389
389
|
return {
|
|
390
|
-
message: actualMessage,
|
|
391
390
|
code: '',
|
|
391
|
+
message: actualMessage,
|
|
392
392
|
stack: rest
|
|
393
393
|
};
|
|
394
394
|
};
|
|
@@ -398,8 +398,8 @@ class IpcError extends VError {
|
|
|
398
398
|
if (stdout || stderr) {
|
|
399
399
|
// @ts-ignore
|
|
400
400
|
const {
|
|
401
|
-
message,
|
|
402
401
|
code,
|
|
402
|
+
message,
|
|
403
403
|
stack
|
|
404
404
|
} = getHelpfulChildProcessError(stdout, stderr);
|
|
405
405
|
const cause = new Error(message);
|
|
@@ -637,8 +637,8 @@ const removeListener = (emitter, type, callback) => {
|
|
|
637
637
|
};
|
|
638
638
|
const getFirstEvent$1 = (eventEmitter, eventMap) => {
|
|
639
639
|
const {
|
|
640
|
-
|
|
641
|
-
|
|
640
|
+
promise,
|
|
641
|
+
resolve
|
|
642
642
|
} = Promise.withResolvers();
|
|
643
643
|
const listenerMap = Object.create(null);
|
|
644
644
|
const cleanup = value => {
|
|
@@ -650,8 +650,8 @@ const getFirstEvent$1 = (eventEmitter, eventMap) => {
|
|
|
650
650
|
for (const [event, type] of Object.entries(eventMap)) {
|
|
651
651
|
const listener = event => {
|
|
652
652
|
cleanup({
|
|
653
|
-
|
|
654
|
-
|
|
653
|
+
event,
|
|
654
|
+
type
|
|
655
655
|
});
|
|
656
656
|
};
|
|
657
657
|
addListener(eventEmitter, event, listener);
|
|
@@ -667,28 +667,28 @@ const getFirstWebSocketEvent = async webSocket => {
|
|
|
667
667
|
WebSocket
|
|
668
668
|
} = await import('ws');
|
|
669
669
|
switch (webSocket.readyState) {
|
|
670
|
-
case WebSocket.
|
|
670
|
+
case WebSocket.CLOSED:
|
|
671
671
|
return {
|
|
672
|
-
|
|
673
|
-
|
|
672
|
+
event: undefined,
|
|
673
|
+
type: Close
|
|
674
674
|
};
|
|
675
|
-
case WebSocket.
|
|
675
|
+
case WebSocket.OPEN:
|
|
676
676
|
return {
|
|
677
|
-
|
|
678
|
-
|
|
677
|
+
event: undefined,
|
|
678
|
+
type: Open
|
|
679
679
|
};
|
|
680
680
|
}
|
|
681
681
|
// @ts-ignore
|
|
682
682
|
const {
|
|
683
|
-
|
|
684
|
-
|
|
683
|
+
event,
|
|
684
|
+
type
|
|
685
685
|
} = await getFirstEvent$1(webSocket, {
|
|
686
|
-
|
|
687
|
-
|
|
686
|
+
close: Close,
|
|
687
|
+
open: Open
|
|
688
688
|
});
|
|
689
689
|
return {
|
|
690
|
-
|
|
691
|
-
|
|
690
|
+
event,
|
|
691
|
+
type
|
|
692
692
|
};
|
|
693
693
|
};
|
|
694
694
|
|
|
@@ -718,8 +718,8 @@ const handleUpgrade$1 = async (...args) => {
|
|
|
718
718
|
return module.handleUpgrade(...args);
|
|
719
719
|
};
|
|
720
720
|
const listen$1$1 = async ({
|
|
721
|
-
|
|
722
|
-
|
|
721
|
+
handle,
|
|
722
|
+
request
|
|
723
723
|
}) => {
|
|
724
724
|
if (!request) {
|
|
725
725
|
throw new IpcError('request must be defined');
|
|
@@ -739,14 +739,19 @@ const signal$4 = webSocket => {
|
|
|
739
739
|
};
|
|
740
740
|
const wrap$9 = webSocket => {
|
|
741
741
|
return {
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
742
|
+
dispose() {
|
|
743
|
+
this.webSocket.close();
|
|
744
|
+
},
|
|
745
|
+
// @ts-ignore
|
|
746
|
+
off(event, listener) {
|
|
747
|
+
this.webSocket.off(event, listener);
|
|
748
|
+
},
|
|
747
749
|
// @ts-ignore
|
|
748
750
|
on(event, listener) {
|
|
749
751
|
switch (event) {
|
|
752
|
+
case 'close':
|
|
753
|
+
webSocket.on('close', listener);
|
|
754
|
+
break;
|
|
750
755
|
case 'message':
|
|
751
756
|
// @ts-ignore
|
|
752
757
|
const wrappedListener = message => {
|
|
@@ -759,28 +764,23 @@ const wrap$9 = webSocket => {
|
|
|
759
764
|
};
|
|
760
765
|
webSocket.on('message', wrappedListener);
|
|
761
766
|
break;
|
|
762
|
-
case 'close':
|
|
763
|
-
webSocket.on('close', listener);
|
|
764
|
-
break;
|
|
765
767
|
default:
|
|
766
768
|
throw new Error('unknown event listener type');
|
|
767
769
|
}
|
|
768
770
|
},
|
|
769
771
|
// @ts-ignore
|
|
770
|
-
off(event, listener) {
|
|
771
|
-
this.webSocket.off(event, listener);
|
|
772
|
-
},
|
|
773
|
-
// @ts-ignore
|
|
774
772
|
send(message) {
|
|
775
773
|
const stringifiedMessage = serialize(message);
|
|
776
774
|
this.webSocket.send(stringifiedMessage);
|
|
777
775
|
},
|
|
778
|
-
dispose() {
|
|
779
|
-
this.webSocket.close();
|
|
780
|
-
},
|
|
781
776
|
start() {
|
|
782
777
|
throw new Error('start method is deprecated');
|
|
783
|
-
}
|
|
778
|
+
},
|
|
779
|
+
webSocket,
|
|
780
|
+
/**
|
|
781
|
+
* @type {any}
|
|
782
|
+
*/
|
|
783
|
+
wrappedListener: undefined
|
|
784
784
|
};
|
|
785
785
|
};
|
|
786
786
|
const IpcChildWithWebSocket = {
|
|
@@ -790,56 +790,35 @@ const IpcChildWithWebSocket = {
|
|
|
790
790
|
wrap: wrap$9
|
|
791
791
|
};
|
|
792
792
|
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
793
|
+
class CommandNotFoundError extends Error {
|
|
794
|
+
constructor(command) {
|
|
795
|
+
super(`Command not found ${command}`);
|
|
796
|
+
this.name = 'CommandNotFoundError';
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
const commands = Object.create(null);
|
|
800
|
+
const register = commandMap => {
|
|
801
|
+
Object.assign(commands, commandMap);
|
|
800
802
|
};
|
|
801
|
-
const
|
|
802
|
-
|
|
803
|
-
callbacks[id] = fn;
|
|
803
|
+
const getCommand = key => {
|
|
804
|
+
return commands[key];
|
|
804
805
|
};
|
|
805
|
-
const
|
|
806
|
+
const execute = (command, ...args) => {
|
|
807
|
+
const fn = getCommand(command);
|
|
808
|
+
if (!fn) {
|
|
809
|
+
throw new CommandNotFoundError(command);
|
|
810
|
+
}
|
|
811
|
+
return fn(...args);
|
|
812
|
+
};
|
|
813
|
+
|
|
814
|
+
const Two$1 = '2.0';
|
|
815
|
+
const callbacks = Object.create(null);
|
|
816
|
+
const get = id => {
|
|
806
817
|
return callbacks[id];
|
|
807
818
|
};
|
|
808
819
|
const remove = id => {
|
|
809
820
|
delete callbacks[id];
|
|
810
821
|
};
|
|
811
|
-
let id = 0;
|
|
812
|
-
const create$3 = () => {
|
|
813
|
-
return ++id;
|
|
814
|
-
};
|
|
815
|
-
const registerPromise = () => {
|
|
816
|
-
const id = create$3();
|
|
817
|
-
const {
|
|
818
|
-
resolve,
|
|
819
|
-
promise
|
|
820
|
-
} = Promise.withResolvers();
|
|
821
|
-
set$1(id, resolve);
|
|
822
|
-
return {
|
|
823
|
-
id,
|
|
824
|
-
promise
|
|
825
|
-
};
|
|
826
|
-
};
|
|
827
|
-
const create$2 = (method, params) => {
|
|
828
|
-
const {
|
|
829
|
-
id,
|
|
830
|
-
promise
|
|
831
|
-
} = registerPromise();
|
|
832
|
-
const message = {
|
|
833
|
-
jsonrpc: Two,
|
|
834
|
-
method,
|
|
835
|
-
params,
|
|
836
|
-
id
|
|
837
|
-
};
|
|
838
|
-
return {
|
|
839
|
-
message,
|
|
840
|
-
promise
|
|
841
|
-
};
|
|
842
|
-
};
|
|
843
822
|
class JsonRpcError extends Error {
|
|
844
823
|
constructor(message) {
|
|
845
824
|
super(message);
|
|
@@ -856,12 +835,12 @@ const getErrorConstructor = (message, type) => {
|
|
|
856
835
|
switch (type) {
|
|
857
836
|
case DomException:
|
|
858
837
|
return DOMException;
|
|
859
|
-
case TypeError$1:
|
|
860
|
-
return TypeError;
|
|
861
|
-
case SyntaxError$1:
|
|
862
|
-
return SyntaxError;
|
|
863
838
|
case ReferenceError$1:
|
|
864
839
|
return ReferenceError;
|
|
840
|
+
case SyntaxError$1:
|
|
841
|
+
return SyntaxError;
|
|
842
|
+
case TypeError$1:
|
|
843
|
+
return TypeError;
|
|
865
844
|
default:
|
|
866
845
|
return Error;
|
|
867
846
|
}
|
|
@@ -983,7 +962,7 @@ const warn = (...args) => {
|
|
|
983
962
|
console.warn(...args);
|
|
984
963
|
};
|
|
985
964
|
const resolve = (id, response) => {
|
|
986
|
-
const fn = get
|
|
965
|
+
const fn = get(id);
|
|
987
966
|
if (!fn) {
|
|
988
967
|
console.log(response);
|
|
989
968
|
warn(`callback ${id} may already be disposed`);
|
|
@@ -1017,56 +996,56 @@ const getErrorProperty = (error, prettyError) => {
|
|
|
1017
996
|
if (error && error.code === E_COMMAND_NOT_FOUND) {
|
|
1018
997
|
return {
|
|
1019
998
|
code: MethodNotFound,
|
|
1020
|
-
|
|
1021
|
-
|
|
999
|
+
data: error.stack,
|
|
1000
|
+
message: error.message
|
|
1022
1001
|
};
|
|
1023
1002
|
}
|
|
1024
1003
|
return {
|
|
1025
1004
|
code: Custom,
|
|
1026
|
-
message: prettyError.message,
|
|
1027
1005
|
data: {
|
|
1028
|
-
stack: getStack(prettyError),
|
|
1029
|
-
codeFrame: prettyError.codeFrame,
|
|
1030
|
-
type: getErrorType(prettyError),
|
|
1031
1006
|
code: prettyError.code,
|
|
1032
|
-
|
|
1033
|
-
|
|
1007
|
+
codeFrame: prettyError.codeFrame,
|
|
1008
|
+
name: prettyError.name,
|
|
1009
|
+
stack: getStack(prettyError),
|
|
1010
|
+
type: getErrorType(prettyError)
|
|
1011
|
+
},
|
|
1012
|
+
message: prettyError.message
|
|
1034
1013
|
};
|
|
1035
1014
|
};
|
|
1036
|
-
const create$1 = (id, error) => {
|
|
1015
|
+
const create$1$1 = (id, error) => {
|
|
1037
1016
|
return {
|
|
1038
|
-
|
|
1017
|
+
error,
|
|
1039
1018
|
id,
|
|
1040
|
-
|
|
1019
|
+
jsonrpc: Two$1
|
|
1041
1020
|
};
|
|
1042
1021
|
};
|
|
1043
1022
|
const getErrorResponse = (id, error, preparePrettyError, logError) => {
|
|
1044
1023
|
const prettyError = preparePrettyError(error);
|
|
1045
1024
|
logError(error, prettyError);
|
|
1046
1025
|
const errorProperty = getErrorProperty(error, prettyError);
|
|
1047
|
-
return create$1(id, errorProperty);
|
|
1026
|
+
return create$1$1(id, errorProperty);
|
|
1048
1027
|
};
|
|
1049
|
-
const create = (message, result) => {
|
|
1028
|
+
const create$8 = (message, result) => {
|
|
1050
1029
|
return {
|
|
1051
|
-
jsonrpc: Two,
|
|
1052
1030
|
id: message.id,
|
|
1031
|
+
jsonrpc: Two$1,
|
|
1053
1032
|
result: result ?? null
|
|
1054
1033
|
};
|
|
1055
1034
|
};
|
|
1056
1035
|
const getSuccessResponse = (message, result) => {
|
|
1057
1036
|
const resultProperty = result ?? null;
|
|
1058
|
-
return create(message, resultProperty);
|
|
1037
|
+
return create$8(message, resultProperty);
|
|
1059
1038
|
};
|
|
1060
1039
|
const getErrorResponseSimple = (id, error) => {
|
|
1061
1040
|
return {
|
|
1062
|
-
jsonrpc: Two,
|
|
1063
|
-
id,
|
|
1064
1041
|
error: {
|
|
1065
1042
|
code: Custom,
|
|
1043
|
+
data: error,
|
|
1066
1044
|
// @ts-ignore
|
|
1067
|
-
message: error.message
|
|
1068
|
-
|
|
1069
|
-
|
|
1045
|
+
message: error.message
|
|
1046
|
+
},
|
|
1047
|
+
id,
|
|
1048
|
+
jsonrpc: Two$1
|
|
1070
1049
|
};
|
|
1071
1050
|
};
|
|
1072
1051
|
const getResponse = async (message, ipc, execute, preparePrettyError, logError, requiresSocket) => {
|
|
@@ -1096,35 +1075,35 @@ const normalizeParams = args => {
|
|
|
1096
1075
|
if (args.length === 1) {
|
|
1097
1076
|
const options = args[0];
|
|
1098
1077
|
return {
|
|
1078
|
+
execute: options.execute,
|
|
1099
1079
|
ipc: options.ipc,
|
|
1080
|
+
logError: options.logError || defaultLogError,
|
|
1100
1081
|
message: options.message,
|
|
1101
|
-
execute: options.execute,
|
|
1102
|
-
resolve: options.resolve || defaultResolve,
|
|
1103
1082
|
preparePrettyError: options.preparePrettyError || defaultPreparePrettyError,
|
|
1104
|
-
|
|
1105
|
-
|
|
1083
|
+
requiresSocket: options.requiresSocket || defaultRequiresSocket,
|
|
1084
|
+
resolve: options.resolve || defaultResolve
|
|
1106
1085
|
};
|
|
1107
1086
|
}
|
|
1108
1087
|
return {
|
|
1088
|
+
execute: args[2],
|
|
1109
1089
|
ipc: args[0],
|
|
1090
|
+
logError: args[5],
|
|
1110
1091
|
message: args[1],
|
|
1111
|
-
execute: args[2],
|
|
1112
|
-
resolve: args[3],
|
|
1113
1092
|
preparePrettyError: args[4],
|
|
1114
|
-
|
|
1115
|
-
|
|
1093
|
+
requiresSocket: args[6],
|
|
1094
|
+
resolve: args[3]
|
|
1116
1095
|
};
|
|
1117
1096
|
};
|
|
1118
1097
|
const handleJsonRpcMessage = async (...args) => {
|
|
1119
1098
|
const options = normalizeParams(args);
|
|
1120
1099
|
const {
|
|
1121
|
-
message,
|
|
1122
|
-
ipc,
|
|
1123
1100
|
execute,
|
|
1124
|
-
|
|
1125
|
-
preparePrettyError,
|
|
1101
|
+
ipc,
|
|
1126
1102
|
logError,
|
|
1127
|
-
|
|
1103
|
+
message,
|
|
1104
|
+
preparePrettyError,
|
|
1105
|
+
requiresSocket,
|
|
1106
|
+
resolve
|
|
1128
1107
|
} = options;
|
|
1129
1108
|
if ('id' in message) {
|
|
1130
1109
|
if ('method' in message) {
|
|
@@ -1146,11 +1125,51 @@ const handleJsonRpcMessage = async (...args) => {
|
|
|
1146
1125
|
}
|
|
1147
1126
|
throw new JsonRpcError('unexpected message');
|
|
1148
1127
|
};
|
|
1149
|
-
|
|
1128
|
+
|
|
1129
|
+
const Two = '2.0';
|
|
1130
|
+
|
|
1131
|
+
const create$7 = (method, params) => {
|
|
1132
|
+
return {
|
|
1133
|
+
jsonrpc: Two,
|
|
1134
|
+
method,
|
|
1135
|
+
params
|
|
1136
|
+
};
|
|
1137
|
+
};
|
|
1138
|
+
|
|
1139
|
+
const create$6 = (id, method, params) => {
|
|
1140
|
+
const message = {
|
|
1141
|
+
id,
|
|
1142
|
+
jsonrpc: Two,
|
|
1143
|
+
method,
|
|
1144
|
+
params
|
|
1145
|
+
};
|
|
1146
|
+
return message;
|
|
1147
|
+
};
|
|
1148
|
+
|
|
1149
|
+
let id = 0;
|
|
1150
|
+
const create$5 = () => {
|
|
1151
|
+
return ++id;
|
|
1152
|
+
};
|
|
1153
|
+
|
|
1154
|
+
const registerPromise = map => {
|
|
1155
|
+
const id = create$5();
|
|
1150
1156
|
const {
|
|
1151
|
-
|
|
1157
|
+
promise,
|
|
1158
|
+
resolve
|
|
1159
|
+
} = Promise.withResolvers();
|
|
1160
|
+
map[id] = resolve;
|
|
1161
|
+
return {
|
|
1162
|
+
id,
|
|
1163
|
+
promise
|
|
1164
|
+
};
|
|
1165
|
+
};
|
|
1166
|
+
|
|
1167
|
+
const invokeHelper = async (callbacks, ipc, method, params, useSendAndTransfer) => {
|
|
1168
|
+
const {
|
|
1169
|
+
id,
|
|
1152
1170
|
promise
|
|
1153
|
-
} =
|
|
1171
|
+
} = registerPromise(callbacks);
|
|
1172
|
+
const message = create$6(id, method, params);
|
|
1154
1173
|
if (useSendAndTransfer && ipc.sendAndTransfer) {
|
|
1155
1174
|
ipc.sendAndTransfer(message);
|
|
1156
1175
|
} else {
|
|
@@ -1159,61 +1178,41 @@ const invokeHelper = async (ipc, method, params, useSendAndTransfer) => {
|
|
|
1159
1178
|
const responseMessage = await promise;
|
|
1160
1179
|
return unwrapJsonRpcResult(responseMessage);
|
|
1161
1180
|
};
|
|
1162
|
-
const send = (transport, method, ...params) => {
|
|
1163
|
-
const message = create$4(method, params);
|
|
1164
|
-
transport.send(message);
|
|
1165
|
-
};
|
|
1166
|
-
const invoke = (ipc, method, ...params) => {
|
|
1167
|
-
return invokeHelper(ipc, method, params, false);
|
|
1168
|
-
};
|
|
1169
|
-
const invokeAndTransfer = (ipc, method, ...params) => {
|
|
1170
|
-
return invokeHelper(ipc, method, params, true);
|
|
1171
|
-
};
|
|
1172
|
-
|
|
1173
|
-
class CommandNotFoundError extends Error {
|
|
1174
|
-
constructor(command) {
|
|
1175
|
-
super(`Command not found ${command}`);
|
|
1176
|
-
this.name = 'CommandNotFoundError';
|
|
1177
|
-
}
|
|
1178
|
-
}
|
|
1179
|
-
const commands = Object.create(null);
|
|
1180
|
-
const register = commandMap => {
|
|
1181
|
-
Object.assign(commands, commandMap);
|
|
1182
|
-
};
|
|
1183
|
-
const getCommand = key => {
|
|
1184
|
-
return commands[key];
|
|
1185
|
-
};
|
|
1186
|
-
const execute = (command, ...args) => {
|
|
1187
|
-
const fn = getCommand(command);
|
|
1188
|
-
if (!fn) {
|
|
1189
|
-
throw new CommandNotFoundError(command);
|
|
1190
|
-
}
|
|
1191
|
-
return fn(...args);
|
|
1192
|
-
};
|
|
1193
|
-
|
|
1194
1181
|
const createRpc = ipc => {
|
|
1182
|
+
const callbacks = Object.create(null);
|
|
1183
|
+
ipc._resolve = (id, response) => {
|
|
1184
|
+
const fn = callbacks[id];
|
|
1185
|
+
if (!fn) {
|
|
1186
|
+
console.warn(`callback ${id} may already be disposed`);
|
|
1187
|
+
return;
|
|
1188
|
+
}
|
|
1189
|
+
fn(response);
|
|
1190
|
+
delete callbacks[id];
|
|
1191
|
+
};
|
|
1195
1192
|
const rpc = {
|
|
1193
|
+
async dispose() {
|
|
1194
|
+
await ipc?.dispose();
|
|
1195
|
+
},
|
|
1196
|
+
invoke(method, ...params) {
|
|
1197
|
+
return invokeHelper(callbacks, ipc, method, params, false);
|
|
1198
|
+
},
|
|
1199
|
+
invokeAndTransfer(method, ...params) {
|
|
1200
|
+
return invokeHelper(callbacks, ipc, method, params, true);
|
|
1201
|
+
},
|
|
1196
1202
|
// @ts-ignore
|
|
1197
1203
|
ipc,
|
|
1198
1204
|
/**
|
|
1199
1205
|
* @deprecated
|
|
1200
1206
|
*/
|
|
1201
1207
|
send(method, ...params) {
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
invoke(method, ...params) {
|
|
1205
|
-
return invoke(ipc, method, ...params);
|
|
1206
|
-
},
|
|
1207
|
-
invokeAndTransfer(method, ...params) {
|
|
1208
|
-
return invokeAndTransfer(ipc, method, ...params);
|
|
1209
|
-
},
|
|
1210
|
-
async dispose() {
|
|
1211
|
-
await ipc?.dispose();
|
|
1208
|
+
const message = create$7(method, params);
|
|
1209
|
+
ipc.send(message);
|
|
1212
1210
|
}
|
|
1213
1211
|
};
|
|
1214
1212
|
return rpc;
|
|
1215
1213
|
};
|
|
1216
|
-
|
|
1214
|
+
|
|
1215
|
+
const requiresSocket$1 = () => {
|
|
1217
1216
|
return false;
|
|
1218
1217
|
};
|
|
1219
1218
|
const preparePrettyError = error => {
|
|
@@ -1223,10 +1222,11 @@ const logError = () => {
|
|
|
1223
1222
|
// handled by renderer worker
|
|
1224
1223
|
};
|
|
1225
1224
|
const handleMessage = event => {
|
|
1226
|
-
const actualRequiresSocket = event?.target?.requiresSocket || requiresSocket;
|
|
1225
|
+
const actualRequiresSocket = event?.target?.requiresSocket || requiresSocket$1;
|
|
1227
1226
|
const actualExecute = event?.target?.execute || execute;
|
|
1228
|
-
return handleJsonRpcMessage(event.target, event.data, actualExecute,
|
|
1227
|
+
return handleJsonRpcMessage(event.target, event.data, actualExecute, event.target._resolve, preparePrettyError, logError, actualRequiresSocket);
|
|
1229
1228
|
};
|
|
1229
|
+
|
|
1230
1230
|
const handleIpc = ipc => {
|
|
1231
1231
|
if ('addEventListener' in ipc) {
|
|
1232
1232
|
ipc.addEventListener('message', handleMessage);
|
|
@@ -1235,6 +1235,7 @@ const handleIpc = ipc => {
|
|
|
1235
1235
|
ipc.on('message', handleMessage);
|
|
1236
1236
|
}
|
|
1237
1237
|
};
|
|
1238
|
+
|
|
1238
1239
|
const listen$1 = async (module, options) => {
|
|
1239
1240
|
const rawIpc = await module.listen(options);
|
|
1240
1241
|
if (module.signal) {
|
|
@@ -1243,7 +1244,8 @@ const listen$1 = async (module, options) => {
|
|
|
1243
1244
|
const ipc = module.wrap(rawIpc);
|
|
1244
1245
|
return ipc;
|
|
1245
1246
|
};
|
|
1246
|
-
|
|
1247
|
+
|
|
1248
|
+
const create$4 = async ({
|
|
1247
1249
|
commandMap,
|
|
1248
1250
|
messagePort,
|
|
1249
1251
|
requiresSocket
|
|
@@ -1260,11 +1262,8 @@ const create$k = async ({
|
|
|
1260
1262
|
const rpc = createRpc(ipc);
|
|
1261
1263
|
return rpc;
|
|
1262
1264
|
};
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
create: create$k
|
|
1266
|
-
};
|
|
1267
|
-
const create$j = async ({
|
|
1265
|
+
|
|
1266
|
+
const create$3 = async ({
|
|
1268
1267
|
commandMap
|
|
1269
1268
|
}) => {
|
|
1270
1269
|
// TODO create a commandMap per rpc instance
|
|
@@ -1274,11 +1273,8 @@ const create$j = async ({
|
|
|
1274
1273
|
const rpc = createRpc(ipc);
|
|
1275
1274
|
return rpc;
|
|
1276
1275
|
};
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
create: create$j
|
|
1280
|
-
};
|
|
1281
|
-
const create$a = async ({
|
|
1276
|
+
|
|
1277
|
+
const create$2 = async ({
|
|
1282
1278
|
commandMap
|
|
1283
1279
|
}) => {
|
|
1284
1280
|
// TODO create a commandMap per rpc instance
|
|
@@ -1288,21 +1284,18 @@ const create$a = async ({
|
|
|
1288
1284
|
const rpc = createRpc(ipc);
|
|
1289
1285
|
return rpc;
|
|
1290
1286
|
};
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
create: create$a
|
|
1294
|
-
};
|
|
1295
|
-
const create$8 = async ({
|
|
1287
|
+
|
|
1288
|
+
const create$1 = async ({
|
|
1296
1289
|
commandMap,
|
|
1297
|
-
request,
|
|
1298
1290
|
handle,
|
|
1291
|
+
request,
|
|
1299
1292
|
requiresSocket
|
|
1300
1293
|
}) => {
|
|
1301
1294
|
// TODO create a commandMap per rpc instance
|
|
1302
1295
|
register(commandMap);
|
|
1303
1296
|
const ipc = await listen$1(IpcChildWithWebSocket, {
|
|
1304
|
-
|
|
1305
|
-
|
|
1297
|
+
handle,
|
|
1298
|
+
request
|
|
1306
1299
|
});
|
|
1307
1300
|
if (requiresSocket) {
|
|
1308
1301
|
ipc.requiresSocket = requiresSocket;
|
|
@@ -1311,11 +1304,8 @@ const create$8 = async ({
|
|
|
1311
1304
|
const rpc = createRpc(ipc);
|
|
1312
1305
|
return rpc;
|
|
1313
1306
|
};
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
create: create$8
|
|
1317
|
-
};
|
|
1318
|
-
const create$7 = async ({
|
|
1307
|
+
|
|
1308
|
+
const create = async ({
|
|
1319
1309
|
commandMap
|
|
1320
1310
|
}) => {
|
|
1321
1311
|
// TODO create a commandMap per rpc instance
|
|
@@ -1325,16 +1315,17 @@ const create$7 = async ({
|
|
|
1325
1315
|
const rpc = createRpc(ipc);
|
|
1326
1316
|
return rpc;
|
|
1327
1317
|
};
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1318
|
+
|
|
1319
|
+
const requiresSocket = method => {
|
|
1320
|
+
return method === 'TextSearch.searchPull';
|
|
1331
1321
|
};
|
|
1332
1322
|
|
|
1333
1323
|
const handleElectronMessagePort = async messagePort => {
|
|
1334
1324
|
object(messagePort);
|
|
1335
|
-
await
|
|
1325
|
+
await create$4({
|
|
1336
1326
|
commandMap: {},
|
|
1337
|
-
messagePort
|
|
1327
|
+
messagePort,
|
|
1328
|
+
requiresSocket
|
|
1338
1329
|
});
|
|
1339
1330
|
};
|
|
1340
1331
|
|
|
@@ -1345,10 +1336,11 @@ const handleWebSocket = async (handle, request) => {
|
|
|
1345
1336
|
}
|
|
1346
1337
|
object(handle);
|
|
1347
1338
|
object(request);
|
|
1348
|
-
await
|
|
1339
|
+
await create$1({
|
|
1349
1340
|
commandMap: {},
|
|
1350
1341
|
handle,
|
|
1351
|
-
request
|
|
1342
|
+
request,
|
|
1343
|
+
requiresSocket
|
|
1352
1344
|
});
|
|
1353
1345
|
};
|
|
1354
1346
|
|
|
@@ -1387,7 +1379,7 @@ const isEnoentError = error => {
|
|
|
1387
1379
|
return isEnoentErrorLinux(error) || isEnoentErrorWindows(error);
|
|
1388
1380
|
};
|
|
1389
1381
|
|
|
1390
|
-
const getNewLineIndex = (string, startIndex =
|
|
1382
|
+
const getNewLineIndex = (string, startIndex = 0) => {
|
|
1391
1383
|
return string.indexOf(NewLine, startIndex);
|
|
1392
1384
|
};
|
|
1393
1385
|
|
|
@@ -1773,7 +1765,7 @@ const collectStdoutIncremental = async (id, stdout, kill, maxSearchResults, char
|
|
|
1773
1765
|
return numberOfResults;
|
|
1774
1766
|
}
|
|
1775
1767
|
};
|
|
1776
|
-
set$
|
|
1768
|
+
set$1(id, search);
|
|
1777
1769
|
stdout.setEncoding(Utf8);
|
|
1778
1770
|
const handleLine = line => {
|
|
1779
1771
|
const parsedLine = JSON.parse(line);
|
|
@@ -1860,13 +1852,12 @@ const textSearchIncremental = async ({
|
|
|
1860
1852
|
return pipeLineResult;
|
|
1861
1853
|
};
|
|
1862
1854
|
|
|
1863
|
-
const collectStdoutPull = async (
|
|
1864
|
-
|
|
1855
|
+
const collectStdoutPull = async (searchId, stdout, kill, maxSearchResults, charsBefore, charsAfter, notifyResultsFound) => {
|
|
1856
|
+
let allSearchResults = [];
|
|
1865
1857
|
let buffer = '';
|
|
1866
1858
|
let stats = {};
|
|
1867
1859
|
let limitHit = false;
|
|
1868
1860
|
let done = false;
|
|
1869
|
-
let nextResultIndex = 0;
|
|
1870
1861
|
let hasUnfetchedResults = false;
|
|
1871
1862
|
let numberOfResults = 0;
|
|
1872
1863
|
const maybeNotifyResultsFound = () => {
|
|
@@ -1881,8 +1872,8 @@ const collectStdoutPull = async (id, stdout, kill, maxSearchResults, charsBefore
|
|
|
1881
1872
|
kill();
|
|
1882
1873
|
},
|
|
1883
1874
|
getNewItems() {
|
|
1884
|
-
const newItems = allSearchResults
|
|
1885
|
-
|
|
1875
|
+
const newItems = allSearchResults;
|
|
1876
|
+
allSearchResults = [];
|
|
1886
1877
|
hasUnfetchedResults = false;
|
|
1887
1878
|
return newItems;
|
|
1888
1879
|
},
|
|
@@ -1895,7 +1886,7 @@ const collectStdoutPull = async (id, stdout, kill, maxSearchResults, charsBefore
|
|
|
1895
1886
|
};
|
|
1896
1887
|
}
|
|
1897
1888
|
};
|
|
1898
|
-
set
|
|
1889
|
+
set(searchId, search);
|
|
1899
1890
|
stdout.setEncoding(Utf8);
|
|
1900
1891
|
const handleLine = line => {
|
|
1901
1892
|
const parsedLine = JSON.parse(line);
|
|
@@ -1957,49 +1948,34 @@ const collectStdoutPull = async (id, stdout, kill, maxSearchResults, charsBefore
|
|
|
1957
1948
|
};
|
|
1958
1949
|
};
|
|
1959
1950
|
|
|
1960
|
-
let rpc = undefined;
|
|
1961
1951
|
const rpcMap = new Map();
|
|
1962
|
-
const get = () => {
|
|
1963
|
-
return rpc;
|
|
1964
|
-
};
|
|
1965
|
-
const set = value => {
|
|
1966
|
-
rpc = value;
|
|
1967
|
-
};
|
|
1968
|
-
const getById = id => {
|
|
1969
|
-
return rpcMap.get(id);
|
|
1970
|
-
};
|
|
1971
|
-
const setById = (id, value) => {
|
|
1972
|
-
rpcMap.set(id, value);
|
|
1973
|
-
};
|
|
1974
1952
|
const removeById = id => {
|
|
1975
1953
|
rpcMap.delete(id);
|
|
1976
1954
|
};
|
|
1977
1955
|
|
|
1978
|
-
const textSearchPull = async ({
|
|
1956
|
+
const textSearchPull = async (rpc, {
|
|
1957
|
+
charsAfter,
|
|
1958
|
+
charsBefore,
|
|
1979
1959
|
id,
|
|
1980
1960
|
maxSearchResults = 20_000,
|
|
1981
|
-
resultsFoundMethod,
|
|
1982
1961
|
ripGrepArgs = [],
|
|
1983
|
-
searchDir = ''
|
|
1962
|
+
searchDir = '',
|
|
1963
|
+
searchId,
|
|
1964
|
+
uid
|
|
1984
1965
|
}) => {
|
|
1985
|
-
const charsBefore = 26;
|
|
1986
|
-
const charsAfter = 50;
|
|
1987
|
-
const initialRpc = get();
|
|
1988
|
-
if (initialRpc) {
|
|
1989
|
-
setById(id, initialRpc);
|
|
1990
|
-
}
|
|
1991
1966
|
const childProcess = spawn(ripGrepArgs, {
|
|
1992
1967
|
cwd: searchDir
|
|
1993
1968
|
});
|
|
1994
1969
|
const notifyResultsFound = () => {
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
1970
|
+
// @ts-ignore
|
|
1971
|
+
rpc.send({
|
|
1972
|
+
jsonrpc: '2.0',
|
|
1973
|
+
method: 'TextSearch.handlePullResultsFound',
|
|
1974
|
+
params: [uid, searchId]
|
|
1975
|
+
});
|
|
2000
1976
|
};
|
|
2001
1977
|
try {
|
|
2002
|
-
const pipeLinePromise = collectStdoutPull(
|
|
1978
|
+
const pipeLinePromise = collectStdoutPull(searchId, childProcess.stdout, childProcess.kill, maxSearchResults, charsBefore, charsAfter, notifyResultsFound);
|
|
2003
1979
|
const closePromise = waitForProcessToExit(childProcess);
|
|
2004
1980
|
const [pipeLineResult, exitResult] = await Promise.all([pipeLinePromise, closePromise]);
|
|
2005
1981
|
if (exitResult.type === Error$1) {
|
|
@@ -2010,7 +1986,7 @@ const textSearchPull = async ({
|
|
|
2010
1986
|
}
|
|
2011
1987
|
return pipeLineResult;
|
|
2012
1988
|
} finally {
|
|
2013
|
-
removeById(
|
|
1989
|
+
removeById(searchId);
|
|
2014
1990
|
}
|
|
2015
1991
|
};
|
|
2016
1992
|
|
|
@@ -2047,15 +2023,15 @@ const Auto = argv => {
|
|
|
2047
2023
|
const getModule = method => {
|
|
2048
2024
|
switch (method) {
|
|
2049
2025
|
case ElectronMessagePort:
|
|
2050
|
-
return
|
|
2026
|
+
return create$4;
|
|
2051
2027
|
case ElectronUtilityProcess:
|
|
2052
|
-
return
|
|
2028
|
+
return create$3;
|
|
2053
2029
|
case NodeForkedProcess:
|
|
2054
|
-
return
|
|
2030
|
+
return create$2;
|
|
2055
2031
|
case NodeWorker:
|
|
2056
|
-
return
|
|
2032
|
+
return create;
|
|
2057
2033
|
case WebSocket:
|
|
2058
|
-
return
|
|
2034
|
+
return create$1;
|
|
2059
2035
|
default:
|
|
2060
2036
|
throw new Error('unexpected ipc type');
|
|
2061
2037
|
}
|
|
@@ -2064,10 +2040,9 @@ const getModule = method => {
|
|
|
2064
2040
|
const listen = async argv => {
|
|
2065
2041
|
const method = Auto(argv);
|
|
2066
2042
|
const create = getModule(method);
|
|
2067
|
-
|
|
2043
|
+
await create({
|
|
2068
2044
|
commandMap: commandMap
|
|
2069
2045
|
});
|
|
2070
|
-
set(rpc);
|
|
2071
2046
|
};
|
|
2072
2047
|
|
|
2073
2048
|
const main = async () => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lvce-editor/search-process",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "14.0.0",
|
|
4
4
|
"description": "Search Process",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Lvce Editor",
|
|
@@ -18,12 +18,12 @@
|
|
|
18
18
|
"search-process": "bin/searchProcess.js"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@lvce-editor/constants": "^
|
|
22
|
-
"execa": "^9.6.
|
|
23
|
-
"ws": "^8.
|
|
21
|
+
"@lvce-editor/constants": "^5.14.0",
|
|
22
|
+
"execa": "^9.6.1",
|
|
23
|
+
"ws": "^8.21.0"
|
|
24
24
|
},
|
|
25
25
|
"optionalDependencies": {
|
|
26
|
-
"@lvce-editor/ripgrep": "^4.
|
|
26
|
+
"@lvce-editor/ripgrep": "^4.1.0"
|
|
27
27
|
},
|
|
28
28
|
"engines": {
|
|
29
29
|
"node": ">=24"
|