@lvce-editor/search-process 15.11.0 → 15.13.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 +76 -41
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -109,7 +109,7 @@ class AssertionError extends Error {
|
|
|
109
109
|
const Object$1 = 1;
|
|
110
110
|
const Number = 2;
|
|
111
111
|
const Array$1 = 3;
|
|
112
|
-
const String = 4;
|
|
112
|
+
const String$1 = 4;
|
|
113
113
|
const Boolean = 5;
|
|
114
114
|
const Function = 6;
|
|
115
115
|
const Null = 7;
|
|
@@ -121,7 +121,7 @@ const getType = value => {
|
|
|
121
121
|
case 'function':
|
|
122
122
|
return Function;
|
|
123
123
|
case 'string':
|
|
124
|
-
return String;
|
|
124
|
+
return String$1;
|
|
125
125
|
case 'object':
|
|
126
126
|
if (value === null) {
|
|
127
127
|
return Null;
|
|
@@ -156,7 +156,7 @@ const array = value => {
|
|
|
156
156
|
};
|
|
157
157
|
const string = value => {
|
|
158
158
|
const type = getType(value);
|
|
159
|
-
if (type !== String) {
|
|
159
|
+
if (type !== String$1) {
|
|
160
160
|
throw new AssertionError('expected value to be of type string');
|
|
161
161
|
}
|
|
162
162
|
};
|
|
@@ -931,6 +931,9 @@ const restoreExistingError = (error, currentStack) => {
|
|
|
931
931
|
};
|
|
932
932
|
const restoreMethodNotFoundError = (error, currentStack) => {
|
|
933
933
|
const restoredError = new JsonRpcError(error.message);
|
|
934
|
+
Object.assign(restoredError, {
|
|
935
|
+
code: error.code
|
|
936
|
+
});
|
|
934
937
|
const parentStack = getParentStack(error);
|
|
935
938
|
setStack(restoredError, `${parentStack}${NewLine$1}${currentStack}`);
|
|
936
939
|
return restoredError;
|
|
@@ -950,9 +953,13 @@ const applyDataProperties = (restoredError, error) => {
|
|
|
950
953
|
// @ts-ignore
|
|
951
954
|
restoredError.codeFrame = error.data.codeFrame;
|
|
952
955
|
}
|
|
953
|
-
if (error.data.code) {
|
|
956
|
+
if (typeof error.data.code === 'string' || typeof error.data.code === 'number') {
|
|
954
957
|
// @ts-ignore
|
|
955
|
-
restoredError
|
|
958
|
+
Object.defineProperty(restoredError, 'code', {
|
|
959
|
+
configurable: true,
|
|
960
|
+
value: error.data.code,
|
|
961
|
+
writable: true
|
|
962
|
+
});
|
|
956
963
|
}
|
|
957
964
|
if (error.data.type) {
|
|
958
965
|
// @ts-ignore
|
|
@@ -973,7 +980,14 @@ const applyDirectProperties = (restoredError, error) => {
|
|
|
973
980
|
}
|
|
974
981
|
};
|
|
975
982
|
const restoreMessageError = (error, _currentStack) => {
|
|
976
|
-
const restoredError = constructError(error.message, error.type, error.name);
|
|
983
|
+
const restoredError = constructError(error.message, error.type || error.data?.type, error.name);
|
|
984
|
+
if (typeof error.code === 'string' || typeof error.code === 'number') {
|
|
985
|
+
Object.defineProperty(restoredError, 'code', {
|
|
986
|
+
configurable: true,
|
|
987
|
+
value: error.code,
|
|
988
|
+
writable: true
|
|
989
|
+
});
|
|
990
|
+
}
|
|
977
991
|
if (error.data) {
|
|
978
992
|
applyDataProperties(restoredError, error);
|
|
979
993
|
} else {
|
|
@@ -981,6 +995,23 @@ const restoreMessageError = (error, _currentStack) => {
|
|
|
981
995
|
}
|
|
982
996
|
return restoredError;
|
|
983
997
|
};
|
|
998
|
+
const getFallbackMessage = error => {
|
|
999
|
+
if (error && typeof error.message === 'string' && error.message) {
|
|
1000
|
+
return error.message;
|
|
1001
|
+
}
|
|
1002
|
+
if (error && error.data) {
|
|
1003
|
+
return getFallbackMessage(error.data);
|
|
1004
|
+
}
|
|
1005
|
+
const stringified = String(error);
|
|
1006
|
+
if (stringified !== '[object Object]') {
|
|
1007
|
+
return stringified;
|
|
1008
|
+
}
|
|
1009
|
+
try {
|
|
1010
|
+
return JSON.stringify(error);
|
|
1011
|
+
} catch {
|
|
1012
|
+
return stringified;
|
|
1013
|
+
}
|
|
1014
|
+
};
|
|
984
1015
|
const restoreJsonRpcError = error => {
|
|
985
1016
|
const currentStack = getCurrentStack();
|
|
986
1017
|
if (error && error instanceof Error) {
|
|
@@ -989,13 +1020,13 @@ const restoreJsonRpcError = error => {
|
|
|
989
1020
|
if (error && error.code && error.code === MethodNotFound) {
|
|
990
1021
|
return restoreMethodNotFoundError(error, currentStack);
|
|
991
1022
|
}
|
|
1023
|
+
if (error && error.error) {
|
|
1024
|
+
return restoreJsonRpcError(error.error);
|
|
1025
|
+
}
|
|
992
1026
|
if (error && error.message) {
|
|
993
1027
|
return restoreMessageError(error);
|
|
994
1028
|
}
|
|
995
|
-
|
|
996
|
-
return new Error(`JsonRpc Error: ${error}`);
|
|
997
|
-
}
|
|
998
|
-
return new Error(`JsonRpc Error: ${error}`);
|
|
1029
|
+
return new Error(`JsonRpc Error: ${getFallbackMessage(error)}`);
|
|
999
1030
|
};
|
|
1000
1031
|
const unwrapJsonRpcResult = responseMessage => {
|
|
1001
1032
|
if ('error' in responseMessage) {
|
|
@@ -1052,9 +1083,9 @@ const getErrorProperty = (error, prettyError) => {
|
|
|
1052
1083
|
return {
|
|
1053
1084
|
code: Custom,
|
|
1054
1085
|
data: {
|
|
1055
|
-
code: prettyError.code,
|
|
1086
|
+
code: prettyError.code ?? error?.code,
|
|
1056
1087
|
codeFrame: prettyError.codeFrame,
|
|
1057
|
-
name: prettyError.name,
|
|
1088
|
+
name: prettyError.name ?? error?.name,
|
|
1058
1089
|
stack: getStack(prettyError),
|
|
1059
1090
|
type: getErrorType(prettyError)
|
|
1060
1091
|
},
|
|
@@ -1089,7 +1120,12 @@ const getErrorResponseSimple = (id, error) => {
|
|
|
1089
1120
|
return {
|
|
1090
1121
|
error: {
|
|
1091
1122
|
code: Custom,
|
|
1092
|
-
data: error
|
|
1123
|
+
data: error instanceof Error ? {
|
|
1124
|
+
...error,
|
|
1125
|
+
code: 'code' in error ? error.code : undefined,
|
|
1126
|
+
stack: error.stack,
|
|
1127
|
+
type: error.name
|
|
1128
|
+
} : error,
|
|
1093
1129
|
// @ts-ignore
|
|
1094
1130
|
message: error.message
|
|
1095
1131
|
},
|
|
@@ -1271,6 +1307,9 @@ const logError = () => {
|
|
|
1271
1307
|
// handled by renderer worker
|
|
1272
1308
|
};
|
|
1273
1309
|
const handleMessage = event => {
|
|
1310
|
+
if (event.data === 'ready') {
|
|
1311
|
+
return Promise.resolve();
|
|
1312
|
+
}
|
|
1274
1313
|
const actualRequiresSocket = event?.target?.requiresSocket || requiresSocket$1;
|
|
1275
1314
|
const actualExecute = event?.target?.execute || execute;
|
|
1276
1315
|
return handleJsonRpcMessage(event.target, event.data, actualExecute, event.target._resolve, preparePrettyError, logError, actualRequiresSocket);
|
|
@@ -1418,14 +1457,13 @@ const isEnoentErrorLinux = error => {
|
|
|
1418
1457
|
};
|
|
1419
1458
|
|
|
1420
1459
|
const isEnoentErrorWindows = error => {
|
|
1421
|
-
|
|
1460
|
+
const candidate = error;
|
|
1461
|
+
const message = candidate?.message;
|
|
1462
|
+
return message && message.includes('The system cannot find the path specified.');
|
|
1422
1463
|
};
|
|
1423
1464
|
|
|
1424
1465
|
const isEnoentError = error => {
|
|
1425
|
-
|
|
1426
|
-
return false;
|
|
1427
|
-
}
|
|
1428
|
-
return isEnoentErrorLinux(error) || isEnoentErrorWindows(error);
|
|
1466
|
+
return !!error && (isEnoentErrorLinux(error) || isEnoentErrorWindows(error));
|
|
1429
1467
|
};
|
|
1430
1468
|
|
|
1431
1469
|
const getNewLineIndex = (string, startIndex = 0) => {
|
|
@@ -1568,7 +1606,6 @@ const searchFile = async ({
|
|
|
1568
1606
|
info(`[search-process] ripgrep could not be found at "${ripGrepPath}"`);
|
|
1569
1607
|
return EmptyString;
|
|
1570
1608
|
}
|
|
1571
|
-
// @ts-ignore
|
|
1572
1609
|
if (error$1 && error$1.stderr === EmptyString) {
|
|
1573
1610
|
return EmptyString;
|
|
1574
1611
|
}
|
|
@@ -1664,7 +1701,7 @@ const getPreviewStart = (text, matchStart, charsBefore) => {
|
|
|
1664
1701
|
}
|
|
1665
1702
|
return preferredStart;
|
|
1666
1703
|
};
|
|
1667
|
-
const toTextSearchResult = (parsedLine,
|
|
1704
|
+
const toTextSearchResult = (parsedLine, charsBefore, charsAfter) => {
|
|
1668
1705
|
const results = [];
|
|
1669
1706
|
const parsedLineData = parsedLine.data;
|
|
1670
1707
|
const lines = parseRipGrepLines(parsedLineData);
|
|
@@ -1731,8 +1768,7 @@ const collectStdout = async (stdout, kill, maxSearchResults, charsBefore, charsA
|
|
|
1731
1768
|
allSearchResults[data.path.text].push(toTextSearchContext(parsedLine));
|
|
1732
1769
|
break;
|
|
1733
1770
|
case Match$1:
|
|
1734
|
-
const
|
|
1735
|
-
const matches = toTextSearchResult(parsedLine, remaining, charsBefore, charsAfter);
|
|
1771
|
+
const matches = toTextSearchResult(parsedLine, charsBefore, charsAfter);
|
|
1736
1772
|
numberOfResults += matches.length;
|
|
1737
1773
|
allSearchResults[data.path.text].push(...matches);
|
|
1738
1774
|
break;
|
|
@@ -1757,10 +1793,12 @@ const collectStdout = async (stdout, kill, maxSearchResults, charsBefore, charsA
|
|
|
1757
1793
|
newLineIndex = getNewLineIndex(dataString, previousIndex);
|
|
1758
1794
|
}
|
|
1759
1795
|
buffer = dataString.slice(previousIndex);
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1796
|
+
const overLimit = numberOfResults > maxSearchResults;
|
|
1797
|
+
if (!overLimit) {
|
|
1798
|
+
return;
|
|
1763
1799
|
}
|
|
1800
|
+
limitHit = true;
|
|
1801
|
+
kill();
|
|
1764
1802
|
};
|
|
1765
1803
|
await processData(stdout, handleData);
|
|
1766
1804
|
const results = Object.values(allSearchResults).flat();
|
|
@@ -1894,8 +1932,7 @@ const collectStdoutIncremental = async (id, stdout, kill, maxSearchResults, char
|
|
|
1894
1932
|
allSearchResults[data.path.text].push(toTextSearchContext(parsedLine));
|
|
1895
1933
|
break;
|
|
1896
1934
|
case Match$1:
|
|
1897
|
-
const
|
|
1898
|
-
const matches = toTextSearchResult(parsedLine, remaining, charsBefore, charsAfter);
|
|
1935
|
+
const matches = toTextSearchResult(parsedLine, charsBefore, charsAfter);
|
|
1899
1936
|
numberOfResults += matches.length;
|
|
1900
1937
|
allSearchResults[data.path.text].push(...matches);
|
|
1901
1938
|
break;
|
|
@@ -1920,10 +1957,12 @@ const collectStdoutIncremental = async (id, stdout, kill, maxSearchResults, char
|
|
|
1920
1957
|
newLineIndex = getNewLineIndex(dataString, previousIndex);
|
|
1921
1958
|
}
|
|
1922
1959
|
buffer = dataString.slice(previousIndex);
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1960
|
+
const overLimit = numberOfResults > maxSearchResults;
|
|
1961
|
+
if (!overLimit) {
|
|
1962
|
+
return;
|
|
1926
1963
|
}
|
|
1964
|
+
limitHit = true;
|
|
1965
|
+
kill();
|
|
1927
1966
|
};
|
|
1928
1967
|
await processData(stdout, handleData);
|
|
1929
1968
|
return {
|
|
@@ -2018,8 +2057,7 @@ const collectStdoutPull = async (searchId, stdout, kill, maxSearchResults, chars
|
|
|
2018
2057
|
maybeNotifyResultsFound();
|
|
2019
2058
|
break;
|
|
2020
2059
|
case Match$1:
|
|
2021
|
-
const
|
|
2022
|
-
const matches = toTextSearchResult(parsedLine, remaining, charsBefore, charsAfter);
|
|
2060
|
+
const matches = toTextSearchResult(parsedLine, charsBefore, charsAfter);
|
|
2023
2061
|
numberOfResults += matches.length;
|
|
2024
2062
|
if (matches.length > 0) {
|
|
2025
2063
|
allSearchResults.push(...matches);
|
|
@@ -2047,10 +2085,12 @@ const collectStdoutPull = async (searchId, stdout, kill, maxSearchResults, chars
|
|
|
2047
2085
|
newLineIndex = getNewLineIndex(dataString, previousIndex);
|
|
2048
2086
|
}
|
|
2049
2087
|
buffer = dataString.slice(previousIndex);
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2088
|
+
const overLimit = numberOfResults > maxSearchResults;
|
|
2089
|
+
if (!overLimit) {
|
|
2090
|
+
return;
|
|
2053
2091
|
}
|
|
2092
|
+
limitHit = true;
|
|
2093
|
+
kill();
|
|
2054
2094
|
};
|
|
2055
2095
|
await processData(stdout, handleData);
|
|
2056
2096
|
done = true;
|
|
@@ -2074,12 +2114,7 @@ const textSearchPull = async (rpc, {
|
|
|
2074
2114
|
cwd: ensurePath(searchDir)
|
|
2075
2115
|
});
|
|
2076
2116
|
const notifyResultsFound = () => {
|
|
2077
|
-
|
|
2078
|
-
rpc.send({
|
|
2079
|
-
jsonrpc: '2.0',
|
|
2080
|
-
method: 'TextSearch.handlePullResultsFound',
|
|
2081
|
-
params: [uid, searchId]
|
|
2082
|
-
});
|
|
2117
|
+
rpc.send('TextSearch.handlePullResultsFound', uid, searchId);
|
|
2083
2118
|
};
|
|
2084
2119
|
const pipeLinePromise = collectStdoutPull(searchId, childProcess.stdout, childProcess.kill, maxSearchResults, charsBefore, charsAfter, notifyResultsFound);
|
|
2085
2120
|
const closePromise = waitForProcessToExit(childProcess);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lvce-editor/search-process",
|
|
3
|
-
"version": "15.
|
|
3
|
+
"version": "15.13.0",
|
|
4
4
|
"description": "Search Process",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Lvce Editor",
|
|
@@ -18,11 +18,11 @@
|
|
|
18
18
|
"search-process": "bin/searchProcess.js"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"execa": "^
|
|
22
|
-
"ws": "^8.
|
|
21
|
+
"execa": "^10.0.1",
|
|
22
|
+
"ws": "^8.22.0"
|
|
23
23
|
},
|
|
24
24
|
"optionalDependencies": {
|
|
25
|
-
"@lvce-editor/ripgrep": "^5.
|
|
25
|
+
"@lvce-editor/ripgrep": "^5.7.0"
|
|
26
26
|
},
|
|
27
27
|
"engines": {
|
|
28
28
|
"node": ">=24"
|