@lvce-editor/search-process 15.10.0 → 15.12.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 +64 -14
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
1
2
|
import { rgPath } from '@lvce-editor/ripgrep';
|
|
2
3
|
import { fileURLToPath } from 'node:url';
|
|
3
4
|
import { Console } from 'node:console';
|
|
@@ -108,7 +109,7 @@ class AssertionError extends Error {
|
|
|
108
109
|
const Object$1 = 1;
|
|
109
110
|
const Number = 2;
|
|
110
111
|
const Array$1 = 3;
|
|
111
|
-
const String = 4;
|
|
112
|
+
const String$1 = 4;
|
|
112
113
|
const Boolean = 5;
|
|
113
114
|
const Function = 6;
|
|
114
115
|
const Null = 7;
|
|
@@ -120,7 +121,7 @@ const getType = value => {
|
|
|
120
121
|
case 'function':
|
|
121
122
|
return Function;
|
|
122
123
|
case 'string':
|
|
123
|
-
return String;
|
|
124
|
+
return String$1;
|
|
124
125
|
case 'object':
|
|
125
126
|
if (value === null) {
|
|
126
127
|
return Null;
|
|
@@ -155,7 +156,7 @@ const array = value => {
|
|
|
155
156
|
};
|
|
156
157
|
const string = value => {
|
|
157
158
|
const type = getType(value);
|
|
158
|
-
if (type !== String) {
|
|
159
|
+
if (type !== String$1) {
|
|
159
160
|
throw new AssertionError('expected value to be of type string');
|
|
160
161
|
}
|
|
161
162
|
};
|
|
@@ -930,6 +931,9 @@ const restoreExistingError = (error, currentStack) => {
|
|
|
930
931
|
};
|
|
931
932
|
const restoreMethodNotFoundError = (error, currentStack) => {
|
|
932
933
|
const restoredError = new JsonRpcError(error.message);
|
|
934
|
+
Object.assign(restoredError, {
|
|
935
|
+
code: error.code
|
|
936
|
+
});
|
|
933
937
|
const parentStack = getParentStack(error);
|
|
934
938
|
setStack(restoredError, `${parentStack}${NewLine$1}${currentStack}`);
|
|
935
939
|
return restoredError;
|
|
@@ -949,9 +953,13 @@ const applyDataProperties = (restoredError, error) => {
|
|
|
949
953
|
// @ts-ignore
|
|
950
954
|
restoredError.codeFrame = error.data.codeFrame;
|
|
951
955
|
}
|
|
952
|
-
if (error.data.code) {
|
|
956
|
+
if (typeof error.data.code === 'string' || typeof error.data.code === 'number') {
|
|
953
957
|
// @ts-ignore
|
|
954
|
-
restoredError
|
|
958
|
+
Object.defineProperty(restoredError, 'code', {
|
|
959
|
+
configurable: true,
|
|
960
|
+
value: error.data.code,
|
|
961
|
+
writable: true
|
|
962
|
+
});
|
|
955
963
|
}
|
|
956
964
|
if (error.data.type) {
|
|
957
965
|
// @ts-ignore
|
|
@@ -972,7 +980,14 @@ const applyDirectProperties = (restoredError, error) => {
|
|
|
972
980
|
}
|
|
973
981
|
};
|
|
974
982
|
const restoreMessageError = (error, _currentStack) => {
|
|
975
|
-
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
|
+
}
|
|
976
991
|
if (error.data) {
|
|
977
992
|
applyDataProperties(restoredError, error);
|
|
978
993
|
} else {
|
|
@@ -980,6 +995,23 @@ const restoreMessageError = (error, _currentStack) => {
|
|
|
980
995
|
}
|
|
981
996
|
return restoredError;
|
|
982
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
|
+
};
|
|
983
1015
|
const restoreJsonRpcError = error => {
|
|
984
1016
|
const currentStack = getCurrentStack();
|
|
985
1017
|
if (error && error instanceof Error) {
|
|
@@ -988,13 +1020,13 @@ const restoreJsonRpcError = error => {
|
|
|
988
1020
|
if (error && error.code && error.code === MethodNotFound) {
|
|
989
1021
|
return restoreMethodNotFoundError(error, currentStack);
|
|
990
1022
|
}
|
|
1023
|
+
if (error && error.error) {
|
|
1024
|
+
return restoreJsonRpcError(error.error);
|
|
1025
|
+
}
|
|
991
1026
|
if (error && error.message) {
|
|
992
1027
|
return restoreMessageError(error);
|
|
993
1028
|
}
|
|
994
|
-
|
|
995
|
-
return new Error(`JsonRpc Error: ${error}`);
|
|
996
|
-
}
|
|
997
|
-
return new Error(`JsonRpc Error: ${error}`);
|
|
1029
|
+
return new Error(`JsonRpc Error: ${getFallbackMessage(error)}`);
|
|
998
1030
|
};
|
|
999
1031
|
const unwrapJsonRpcResult = responseMessage => {
|
|
1000
1032
|
if ('error' in responseMessage) {
|
|
@@ -1051,9 +1083,9 @@ const getErrorProperty = (error, prettyError) => {
|
|
|
1051
1083
|
return {
|
|
1052
1084
|
code: Custom,
|
|
1053
1085
|
data: {
|
|
1054
|
-
code: prettyError.code,
|
|
1086
|
+
code: prettyError.code ?? error?.code,
|
|
1055
1087
|
codeFrame: prettyError.codeFrame,
|
|
1056
|
-
name: prettyError.name,
|
|
1088
|
+
name: prettyError.name ?? error?.name,
|
|
1057
1089
|
stack: getStack(prettyError),
|
|
1058
1090
|
type: getErrorType(prettyError)
|
|
1059
1091
|
},
|
|
@@ -1088,7 +1120,12 @@ const getErrorResponseSimple = (id, error) => {
|
|
|
1088
1120
|
return {
|
|
1089
1121
|
error: {
|
|
1090
1122
|
code: Custom,
|
|
1091
|
-
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,
|
|
1092
1129
|
// @ts-ignore
|
|
1093
1130
|
message: error.message
|
|
1094
1131
|
},
|
|
@@ -1270,6 +1307,9 @@ const logError = () => {
|
|
|
1270
1307
|
// handled by renderer worker
|
|
1271
1308
|
};
|
|
1272
1309
|
const handleMessage = event => {
|
|
1310
|
+
if (event.data === 'ready') {
|
|
1311
|
+
return Promise.resolve();
|
|
1312
|
+
}
|
|
1273
1313
|
const actualRequiresSocket = event?.target?.requiresSocket || requiresSocket$1;
|
|
1274
1314
|
const actualExecute = event?.target?.execute || execute;
|
|
1275
1315
|
return handleJsonRpcMessage(event.target, event.data, actualExecute, event.target._resolve, preparePrettyError, logError, actualRequiresSocket);
|
|
@@ -1537,6 +1577,7 @@ const exec = execRipGrep;
|
|
|
1537
1577
|
// but the second time only a few hundred bytes of changes
|
|
1538
1578
|
|
|
1539
1579
|
const searchFile = async ({
|
|
1580
|
+
ifNonMatch,
|
|
1540
1581
|
limit = 100,
|
|
1541
1582
|
ripGrepArgs = [],
|
|
1542
1583
|
searchPath = ''
|
|
@@ -1551,7 +1592,16 @@ const searchFile = async ({
|
|
|
1551
1592
|
} = await exec(ripGrepArgs, {
|
|
1552
1593
|
cwd
|
|
1553
1594
|
});
|
|
1554
|
-
|
|
1595
|
+
const results = limitString(stdout, limit);
|
|
1596
|
+
if (ifNonMatch === undefined) {
|
|
1597
|
+
return results;
|
|
1598
|
+
}
|
|
1599
|
+
const hash = createHash('sha256').update(searchPath).update('\0').update(JSON.stringify(ripGrepArgs)).update('\0').update(results).digest('hex');
|
|
1600
|
+
return {
|
|
1601
|
+
hash,
|
|
1602
|
+
matchesCache: hash === ifNonMatch,
|
|
1603
|
+
results: hash === ifNonMatch ? '' : results
|
|
1604
|
+
};
|
|
1555
1605
|
} catch (error$1) {
|
|
1556
1606
|
if (isEnoentError(error$1)) {
|
|
1557
1607
|
info(`[search-process] ripgrep could not be found at "${ripGrepPath}"`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lvce-editor/search-process",
|
|
3
|
-
"version": "15.
|
|
3
|
+
"version": "15.12.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"
|