@lvce-editor/search-process 9.3.0 → 10.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 +42 -18
- 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';
|
|
@@ -461,7 +462,7 @@ const listen$a = () => {
|
|
|
461
462
|
parentPort
|
|
462
463
|
} = process;
|
|
463
464
|
if (!parentPort) {
|
|
464
|
-
throw new
|
|
465
|
+
throw new IpcError('parent port must be defined');
|
|
465
466
|
}
|
|
466
467
|
return parentPort;
|
|
467
468
|
};
|
|
@@ -519,7 +520,7 @@ const getTransferrablesNode = value => {
|
|
|
519
520
|
};
|
|
520
521
|
const listen$5 = async () => {
|
|
521
522
|
if (!process.send) {
|
|
522
|
-
throw new
|
|
523
|
+
throw new IpcError('process.send must be defined');
|
|
523
524
|
}
|
|
524
525
|
return process;
|
|
525
526
|
};
|
|
@@ -877,7 +878,8 @@ const splitLines = lines => {
|
|
|
877
878
|
return lines.split(NewLine$1);
|
|
878
879
|
};
|
|
879
880
|
const getCurrentStack = () => {
|
|
880
|
-
const
|
|
881
|
+
const stackLinesToSkip = 3;
|
|
882
|
+
const currentStack = joinLines(splitLines(new Error().stack || '').slice(stackLinesToSkip));
|
|
881
883
|
return currentStack;
|
|
882
884
|
};
|
|
883
885
|
const getNewLineIndex$1 = (string, startIndex = undefined) => {
|
|
@@ -1148,6 +1150,12 @@ const invokeAndTransfer = (ipc, method, ...params) => {
|
|
|
1148
1150
|
return invokeHelper(ipc, method, params, true);
|
|
1149
1151
|
};
|
|
1150
1152
|
|
|
1153
|
+
class CommandNotFoundError extends Error {
|
|
1154
|
+
constructor(command) {
|
|
1155
|
+
super(`Command not found ${command}`);
|
|
1156
|
+
this.name = 'CommandNotFoundError';
|
|
1157
|
+
}
|
|
1158
|
+
}
|
|
1151
1159
|
const commands = Object.create(null);
|
|
1152
1160
|
const register = commandMap => {
|
|
1153
1161
|
Object.assign(commands, commandMap);
|
|
@@ -1158,7 +1166,7 @@ const getCommand = key => {
|
|
|
1158
1166
|
const execute = (command, ...args) => {
|
|
1159
1167
|
const fn = getCommand(command);
|
|
1160
1168
|
if (!fn) {
|
|
1161
|
-
throw new
|
|
1169
|
+
throw new CommandNotFoundError(command);
|
|
1162
1170
|
}
|
|
1163
1171
|
return fn(...args);
|
|
1164
1172
|
};
|
|
@@ -1215,7 +1223,7 @@ const listen$1 = async (module, options) => {
|
|
|
1215
1223
|
const ipc = module.wrap(rawIpc);
|
|
1216
1224
|
return ipc;
|
|
1217
1225
|
};
|
|
1218
|
-
const create$
|
|
1226
|
+
const create$k = async ({
|
|
1219
1227
|
commandMap,
|
|
1220
1228
|
messagePort,
|
|
1221
1229
|
requiresSocket
|
|
@@ -1234,9 +1242,9 @@ const create$j = async ({
|
|
|
1234
1242
|
};
|
|
1235
1243
|
const ElectronMessagePortRpcClient = {
|
|
1236
1244
|
__proto__: null,
|
|
1237
|
-
create: create$
|
|
1245
|
+
create: create$k
|
|
1238
1246
|
};
|
|
1239
|
-
const create$
|
|
1247
|
+
const create$j = async ({
|
|
1240
1248
|
commandMap
|
|
1241
1249
|
}) => {
|
|
1242
1250
|
// TODO create a commandMap per rpc instance
|
|
@@ -1248,9 +1256,9 @@ const create$i = async ({
|
|
|
1248
1256
|
};
|
|
1249
1257
|
const ElectronUtilityProcessRpcClient = {
|
|
1250
1258
|
__proto__: null,
|
|
1251
|
-
create: create$
|
|
1259
|
+
create: create$j
|
|
1252
1260
|
};
|
|
1253
|
-
const create$
|
|
1261
|
+
const create$a = async ({
|
|
1254
1262
|
commandMap
|
|
1255
1263
|
}) => {
|
|
1256
1264
|
// TODO create a commandMap per rpc instance
|
|
@@ -1262,9 +1270,9 @@ const create$9 = async ({
|
|
|
1262
1270
|
};
|
|
1263
1271
|
const NodeForkedProcessRpcClient = {
|
|
1264
1272
|
__proto__: null,
|
|
1265
|
-
create: create$
|
|
1273
|
+
create: create$a
|
|
1266
1274
|
};
|
|
1267
|
-
const create$
|
|
1275
|
+
const create$8 = async ({
|
|
1268
1276
|
commandMap,
|
|
1269
1277
|
request,
|
|
1270
1278
|
handle,
|
|
@@ -1285,9 +1293,9 @@ const create$7 = async ({
|
|
|
1285
1293
|
};
|
|
1286
1294
|
const NodeWebSocketRpcClient = {
|
|
1287
1295
|
__proto__: null,
|
|
1288
|
-
create: create$
|
|
1296
|
+
create: create$8
|
|
1289
1297
|
};
|
|
1290
|
-
const create$
|
|
1298
|
+
const create$7 = async ({
|
|
1291
1299
|
commandMap
|
|
1292
1300
|
}) => {
|
|
1293
1301
|
// TODO create a commandMap per rpc instance
|
|
@@ -1299,7 +1307,7 @@ const create$6 = async ({
|
|
|
1299
1307
|
};
|
|
1300
1308
|
const NodeWorkerRpcClient = {
|
|
1301
1309
|
__proto__: null,
|
|
1302
|
-
create: create$
|
|
1310
|
+
create: create$7
|
|
1303
1311
|
};
|
|
1304
1312
|
|
|
1305
1313
|
const handleElectronMessagePort = async messagePort => {
|
|
@@ -1334,6 +1342,13 @@ const ripGrepPath = getRipGrepPath() || rgPath;
|
|
|
1334
1342
|
const EmptyString = '';
|
|
1335
1343
|
const NewLine = '\n';
|
|
1336
1344
|
|
|
1345
|
+
const ensurePath = searchDir => {
|
|
1346
|
+
if (searchDir.startsWith('file://')) {
|
|
1347
|
+
return fileURLToPath(searchDir);
|
|
1348
|
+
}
|
|
1349
|
+
return searchDir;
|
|
1350
|
+
};
|
|
1351
|
+
|
|
1337
1352
|
const ENOENT = 'ENOENT';
|
|
1338
1353
|
const E_RIP_GREP_NOT_FOUND = 'E_RIP_GREP_NOT_FOUND';
|
|
1339
1354
|
|
|
@@ -1470,10 +1485,11 @@ const searchFile = async ({
|
|
|
1470
1485
|
string(searchPath);
|
|
1471
1486
|
array(ripGrepArgs);
|
|
1472
1487
|
number(limit);
|
|
1488
|
+
const cwd = ensurePath(searchPath);
|
|
1473
1489
|
const {
|
|
1474
1490
|
stdout
|
|
1475
1491
|
} = await exec(ripGrepArgs, {
|
|
1476
|
-
cwd
|
|
1492
|
+
cwd
|
|
1477
1493
|
});
|
|
1478
1494
|
return limitString(stdout, limit);
|
|
1479
1495
|
} catch (error$1) {
|
|
@@ -1493,6 +1509,13 @@ const searchFile = async ({
|
|
|
1493
1509
|
const Utf8 = 'utf8';
|
|
1494
1510
|
const Base64 = 'base64';
|
|
1495
1511
|
|
|
1512
|
+
const formatFile = text => {
|
|
1513
|
+
if (text.startsWith('./') || text.startsWith('.\\')) {
|
|
1514
|
+
return text.slice(2);
|
|
1515
|
+
}
|
|
1516
|
+
return text;
|
|
1517
|
+
};
|
|
1518
|
+
|
|
1496
1519
|
const processData = async (stdout, handleData) => {
|
|
1497
1520
|
await pipeline(stdout, new Writable({
|
|
1498
1521
|
decodeStrings: false,
|
|
@@ -1583,7 +1606,7 @@ const collectStdout = async (stdout, kill, maxSearchResults, charsBefore, charsA
|
|
|
1583
1606
|
start: 0,
|
|
1584
1607
|
end: 0,
|
|
1585
1608
|
lineNumber: 0,
|
|
1586
|
-
text: data.path.text
|
|
1609
|
+
text: formatFile(data.path.text)
|
|
1587
1610
|
}];
|
|
1588
1611
|
break;
|
|
1589
1612
|
case Match$1:
|
|
@@ -1695,9 +1718,10 @@ const search = async ({
|
|
|
1695
1718
|
ripGrepArgs = []
|
|
1696
1719
|
} = {}) => {
|
|
1697
1720
|
const charsBefore = 26;
|
|
1698
|
-
const charsAfter = 50;
|
|
1721
|
+
const charsAfter = 50; // TODO pass these also in as parameters
|
|
1722
|
+
const cwd = ensurePath(searchDir);
|
|
1699
1723
|
const childProcess = spawn(ripGrepArgs, {
|
|
1700
|
-
cwd
|
|
1724
|
+
cwd
|
|
1701
1725
|
});
|
|
1702
1726
|
const pipeLinePromise = collectStdout(childProcess.stdout, childProcess.kill, maxSearchResults, charsBefore, charsAfter);
|
|
1703
1727
|
const closePromise = waitForProcessToExit(childProcess);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lvce-editor/search-process",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "10.0.0",
|
|
4
4
|
"description": "Search Process",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Lvce Editor",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"ws": "^8.18.3"
|
|
23
23
|
},
|
|
24
24
|
"optionalDependencies": {
|
|
25
|
-
"@lvce-editor/ripgrep": "^2.
|
|
25
|
+
"@lvce-editor/ripgrep": "^2.4.0"
|
|
26
26
|
},
|
|
27
27
|
"engines": {
|
|
28
28
|
"node": ">=22"
|