@lvce-editor/search-process 9.2.0 → 9.4.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 +75 -35
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { rgPath } from '@lvce-editor/ripgrep';
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
2
3
|
import { Console } from 'node:console';
|
|
3
4
|
import { createWriteStream } from 'node:fs';
|
|
4
5
|
import { tmpdir } from 'node:os';
|
|
@@ -84,49 +85,57 @@ class AssertionError extends Error {
|
|
|
84
85
|
this.name = 'AssertionError';
|
|
85
86
|
}
|
|
86
87
|
}
|
|
88
|
+
const Object$1 = 1;
|
|
89
|
+
const Number = 2;
|
|
90
|
+
const Array$1 = 3;
|
|
91
|
+
const String = 4;
|
|
92
|
+
const Boolean = 5;
|
|
93
|
+
const Function = 6;
|
|
94
|
+
const Null = 7;
|
|
95
|
+
const Unknown = 8;
|
|
87
96
|
const getType = value => {
|
|
88
97
|
switch (typeof value) {
|
|
89
98
|
case 'number':
|
|
90
|
-
return
|
|
99
|
+
return Number;
|
|
91
100
|
case 'function':
|
|
92
|
-
return
|
|
101
|
+
return Function;
|
|
93
102
|
case 'string':
|
|
94
|
-
return
|
|
103
|
+
return String;
|
|
95
104
|
case 'object':
|
|
96
105
|
if (value === null) {
|
|
97
|
-
return
|
|
106
|
+
return Null;
|
|
98
107
|
}
|
|
99
108
|
if (Array.isArray(value)) {
|
|
100
|
-
return
|
|
109
|
+
return Array$1;
|
|
101
110
|
}
|
|
102
|
-
return
|
|
111
|
+
return Object$1;
|
|
103
112
|
case 'boolean':
|
|
104
|
-
return
|
|
113
|
+
return Boolean;
|
|
105
114
|
default:
|
|
106
|
-
return
|
|
115
|
+
return Unknown;
|
|
107
116
|
}
|
|
108
117
|
};
|
|
109
118
|
const object = value => {
|
|
110
119
|
const type = getType(value);
|
|
111
|
-
if (type !==
|
|
120
|
+
if (type !== Object$1) {
|
|
112
121
|
throw new AssertionError('expected value to be of type object');
|
|
113
122
|
}
|
|
114
123
|
};
|
|
115
124
|
const number = value => {
|
|
116
125
|
const type = getType(value);
|
|
117
|
-
if (type !==
|
|
126
|
+
if (type !== Number) {
|
|
118
127
|
throw new AssertionError('expected value to be of type number');
|
|
119
128
|
}
|
|
120
129
|
};
|
|
121
130
|
const array = value => {
|
|
122
131
|
const type = getType(value);
|
|
123
|
-
if (type !==
|
|
132
|
+
if (type !== Array$1) {
|
|
124
133
|
throw new AssertionError('expected value to be of type array');
|
|
125
134
|
}
|
|
126
135
|
};
|
|
127
136
|
const string = value => {
|
|
128
137
|
const type = getType(value);
|
|
129
|
-
if (type !==
|
|
138
|
+
if (type !== String) {
|
|
130
139
|
throw new AssertionError('expected value to be of type string');
|
|
131
140
|
}
|
|
132
141
|
};
|
|
@@ -553,7 +562,7 @@ const listen$3 = async () => {
|
|
|
553
562
|
parentPort
|
|
554
563
|
} = await import('node:worker_threads');
|
|
555
564
|
if (!parentPort) {
|
|
556
|
-
throw new IpcError('parentPort is required');
|
|
565
|
+
throw new IpcError('parentPort is required for node worker threads ipc');
|
|
557
566
|
}
|
|
558
567
|
return parentPort;
|
|
559
568
|
};
|
|
@@ -762,7 +771,7 @@ const IpcChildWithWebSocket = {
|
|
|
762
771
|
};
|
|
763
772
|
|
|
764
773
|
const Two = '2.0';
|
|
765
|
-
const create$4
|
|
774
|
+
const create$4 = (method, params) => {
|
|
766
775
|
return {
|
|
767
776
|
jsonrpc: Two,
|
|
768
777
|
method,
|
|
@@ -869,7 +878,8 @@ const splitLines = lines => {
|
|
|
869
878
|
return lines.split(NewLine$1);
|
|
870
879
|
};
|
|
871
880
|
const getCurrentStack = () => {
|
|
872
|
-
const
|
|
881
|
+
const stackLinesToSkip = 3;
|
|
882
|
+
const currentStack = joinLines(splitLines(new Error().stack || '').slice(stackLinesToSkip));
|
|
873
883
|
return currentStack;
|
|
874
884
|
};
|
|
875
885
|
const getNewLineIndex$1 = (string, startIndex = undefined) => {
|
|
@@ -1003,18 +1013,18 @@ const getErrorProperty = (error, prettyError) => {
|
|
|
1003
1013
|
}
|
|
1004
1014
|
};
|
|
1005
1015
|
};
|
|
1006
|
-
const create$1 = (
|
|
1016
|
+
const create$1 = (id, error) => {
|
|
1007
1017
|
return {
|
|
1008
1018
|
jsonrpc: Two,
|
|
1009
|
-
id
|
|
1019
|
+
id,
|
|
1010
1020
|
error
|
|
1011
1021
|
};
|
|
1012
1022
|
};
|
|
1013
|
-
const getErrorResponse = (
|
|
1023
|
+
const getErrorResponse = (id, error, preparePrettyError, logError) => {
|
|
1014
1024
|
const prettyError = preparePrettyError(error);
|
|
1015
1025
|
logError(error, prettyError);
|
|
1016
1026
|
const errorProperty = getErrorProperty(error, prettyError);
|
|
1017
|
-
return create$1(
|
|
1027
|
+
return create$1(id, errorProperty);
|
|
1018
1028
|
};
|
|
1019
1029
|
const create = (message, result) => {
|
|
1020
1030
|
return {
|
|
@@ -1027,12 +1037,27 @@ const getSuccessResponse = (message, result) => {
|
|
|
1027
1037
|
const resultProperty = result ?? null;
|
|
1028
1038
|
return create(message, resultProperty);
|
|
1029
1039
|
};
|
|
1040
|
+
const getErrorResponseSimple = (id, error) => {
|
|
1041
|
+
return {
|
|
1042
|
+
jsonrpc: Two,
|
|
1043
|
+
id,
|
|
1044
|
+
error: {
|
|
1045
|
+
code: Custom,
|
|
1046
|
+
// @ts-ignore
|
|
1047
|
+
message: error.message,
|
|
1048
|
+
data: error
|
|
1049
|
+
}
|
|
1050
|
+
};
|
|
1051
|
+
};
|
|
1030
1052
|
const getResponse = async (message, ipc, execute, preparePrettyError, logError, requiresSocket) => {
|
|
1031
1053
|
try {
|
|
1032
1054
|
const result = requiresSocket(message.method) ? await execute(message.method, ipc, ...message.params) : await execute(message.method, ...message.params);
|
|
1033
1055
|
return getSuccessResponse(message, result);
|
|
1034
1056
|
} catch (error) {
|
|
1035
|
-
|
|
1057
|
+
if (ipc.canUseSimpleErrorResponse) {
|
|
1058
|
+
return getErrorResponseSimple(message.id, error);
|
|
1059
|
+
}
|
|
1060
|
+
return getErrorResponse(message.id, error, preparePrettyError, logError);
|
|
1036
1061
|
}
|
|
1037
1062
|
};
|
|
1038
1063
|
const defaultPreparePrettyError = error => {
|
|
@@ -1087,7 +1112,7 @@ const handleJsonRpcMessage = async (...args) => {
|
|
|
1087
1112
|
try {
|
|
1088
1113
|
ipc.send(response);
|
|
1089
1114
|
} catch (error) {
|
|
1090
|
-
const errorResponse = getErrorResponse(message, error, preparePrettyError, logError);
|
|
1115
|
+
const errorResponse = getErrorResponse(message.id, error, preparePrettyError, logError);
|
|
1091
1116
|
ipc.send(errorResponse);
|
|
1092
1117
|
}
|
|
1093
1118
|
return;
|
|
@@ -1115,7 +1140,7 @@ const invokeHelper = async (ipc, method, params, useSendAndTransfer) => {
|
|
|
1115
1140
|
return unwrapJsonRpcResult(responseMessage);
|
|
1116
1141
|
};
|
|
1117
1142
|
const send = (transport, method, ...params) => {
|
|
1118
|
-
const message = create$4
|
|
1143
|
+
const message = create$4(method, params);
|
|
1119
1144
|
transport.send(message);
|
|
1120
1145
|
};
|
|
1121
1146
|
const invoke = (ipc, method, ...params) => {
|
|
@@ -1125,6 +1150,12 @@ const invokeAndTransfer = (ipc, method, ...params) => {
|
|
|
1125
1150
|
return invokeHelper(ipc, method, params, true);
|
|
1126
1151
|
};
|
|
1127
1152
|
|
|
1153
|
+
class CommandNotFoundError extends Error {
|
|
1154
|
+
constructor(command) {
|
|
1155
|
+
super(`Command not found ${command}`);
|
|
1156
|
+
this.name = 'CommandNotFoundError';
|
|
1157
|
+
}
|
|
1158
|
+
}
|
|
1128
1159
|
const commands = Object.create(null);
|
|
1129
1160
|
const register = commandMap => {
|
|
1130
1161
|
Object.assign(commands, commandMap);
|
|
@@ -1135,7 +1166,7 @@ const getCommand = key => {
|
|
|
1135
1166
|
const execute = (command, ...args) => {
|
|
1136
1167
|
const fn = getCommand(command);
|
|
1137
1168
|
if (!fn) {
|
|
1138
|
-
throw new
|
|
1169
|
+
throw new CommandNotFoundError(command);
|
|
1139
1170
|
}
|
|
1140
1171
|
return fn(...args);
|
|
1141
1172
|
};
|
|
@@ -1192,7 +1223,7 @@ const listen$1 = async (module, options) => {
|
|
|
1192
1223
|
const ipc = module.wrap(rawIpc);
|
|
1193
1224
|
return ipc;
|
|
1194
1225
|
};
|
|
1195
|
-
const create$
|
|
1226
|
+
const create$k = async ({
|
|
1196
1227
|
commandMap,
|
|
1197
1228
|
messagePort,
|
|
1198
1229
|
requiresSocket
|
|
@@ -1211,9 +1242,9 @@ const create$e = async ({
|
|
|
1211
1242
|
};
|
|
1212
1243
|
const ElectronMessagePortRpcClient = {
|
|
1213
1244
|
__proto__: null,
|
|
1214
|
-
create: create$
|
|
1245
|
+
create: create$k
|
|
1215
1246
|
};
|
|
1216
|
-
const create$
|
|
1247
|
+
const create$j = async ({
|
|
1217
1248
|
commandMap
|
|
1218
1249
|
}) => {
|
|
1219
1250
|
// TODO create a commandMap per rpc instance
|
|
@@ -1225,9 +1256,9 @@ const create$d = async ({
|
|
|
1225
1256
|
};
|
|
1226
1257
|
const ElectronUtilityProcessRpcClient = {
|
|
1227
1258
|
__proto__: null,
|
|
1228
|
-
create: create$
|
|
1259
|
+
create: create$j
|
|
1229
1260
|
};
|
|
1230
|
-
const create$
|
|
1261
|
+
const create$a = async ({
|
|
1231
1262
|
commandMap
|
|
1232
1263
|
}) => {
|
|
1233
1264
|
// TODO create a commandMap per rpc instance
|
|
@@ -1239,9 +1270,9 @@ const create$7 = async ({
|
|
|
1239
1270
|
};
|
|
1240
1271
|
const NodeForkedProcessRpcClient = {
|
|
1241
1272
|
__proto__: null,
|
|
1242
|
-
create: create$
|
|
1273
|
+
create: create$a
|
|
1243
1274
|
};
|
|
1244
|
-
const create$
|
|
1275
|
+
const create$8 = async ({
|
|
1245
1276
|
commandMap,
|
|
1246
1277
|
request,
|
|
1247
1278
|
handle,
|
|
@@ -1262,9 +1293,9 @@ const create$5 = async ({
|
|
|
1262
1293
|
};
|
|
1263
1294
|
const NodeWebSocketRpcClient = {
|
|
1264
1295
|
__proto__: null,
|
|
1265
|
-
create: create$
|
|
1296
|
+
create: create$8
|
|
1266
1297
|
};
|
|
1267
|
-
const create$
|
|
1298
|
+
const create$7 = async ({
|
|
1268
1299
|
commandMap
|
|
1269
1300
|
}) => {
|
|
1270
1301
|
// TODO create a commandMap per rpc instance
|
|
@@ -1276,7 +1307,7 @@ const create$4 = async ({
|
|
|
1276
1307
|
};
|
|
1277
1308
|
const NodeWorkerRpcClient = {
|
|
1278
1309
|
__proto__: null,
|
|
1279
|
-
create: create$
|
|
1310
|
+
create: create$7
|
|
1280
1311
|
};
|
|
1281
1312
|
|
|
1282
1313
|
const handleElectronMessagePort = async messagePort => {
|
|
@@ -1311,6 +1342,13 @@ const ripGrepPath = getRipGrepPath() || rgPath;
|
|
|
1311
1342
|
const EmptyString = '';
|
|
1312
1343
|
const NewLine = '\n';
|
|
1313
1344
|
|
|
1345
|
+
const ensurePath = searchDir => {
|
|
1346
|
+
if (searchDir.startsWith('file://')) {
|
|
1347
|
+
return fileURLToPath(searchDir);
|
|
1348
|
+
}
|
|
1349
|
+
return searchDir;
|
|
1350
|
+
};
|
|
1351
|
+
|
|
1314
1352
|
const ENOENT = 'ENOENT';
|
|
1315
1353
|
const E_RIP_GREP_NOT_FOUND = 'E_RIP_GREP_NOT_FOUND';
|
|
1316
1354
|
|
|
@@ -1447,10 +1485,11 @@ const searchFile = async ({
|
|
|
1447
1485
|
string(searchPath);
|
|
1448
1486
|
array(ripGrepArgs);
|
|
1449
1487
|
number(limit);
|
|
1488
|
+
const cwd = ensurePath(searchPath);
|
|
1450
1489
|
const {
|
|
1451
1490
|
stdout
|
|
1452
1491
|
} = await exec(ripGrepArgs, {
|
|
1453
|
-
cwd
|
|
1492
|
+
cwd
|
|
1454
1493
|
});
|
|
1455
1494
|
return limitString(stdout, limit);
|
|
1456
1495
|
} catch (error$1) {
|
|
@@ -1673,8 +1712,9 @@ const search = async ({
|
|
|
1673
1712
|
} = {}) => {
|
|
1674
1713
|
const charsBefore = 26;
|
|
1675
1714
|
const charsAfter = 50;
|
|
1715
|
+
const cwd = ensurePath(searchDir);
|
|
1676
1716
|
const childProcess = spawn(ripGrepArgs, {
|
|
1677
|
-
cwd
|
|
1717
|
+
cwd
|
|
1678
1718
|
});
|
|
1679
1719
|
const pipeLinePromise = collectStdout(childProcess.stdout, childProcess.kill, maxSearchResults, charsBefore, charsAfter);
|
|
1680
1720
|
const closePromise = waitForProcessToExit(childProcess);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lvce-editor/search-process",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.4.0",
|
|
4
4
|
"description": "Search Process",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Lvce Editor",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"execa": "^9.6.0",
|
|
22
|
-
"ws": "^8.18.
|
|
22
|
+
"ws": "^8.18.3"
|
|
23
23
|
},
|
|
24
24
|
"optionalDependencies": {
|
|
25
25
|
"@lvce-editor/ripgrep": "^2.1.0"
|