@lvce-editor/search-process 9.3.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 +31 -14
- package/package.json +1 -1
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';
|
|
@@ -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) {
|
|
@@ -1696,8 +1712,9 @@ const search = async ({
|
|
|
1696
1712
|
} = {}) => {
|
|
1697
1713
|
const charsBefore = 26;
|
|
1698
1714
|
const charsAfter = 50;
|
|
1715
|
+
const cwd = ensurePath(searchDir);
|
|
1699
1716
|
const childProcess = spawn(ripGrepArgs, {
|
|
1700
|
-
cwd
|
|
1717
|
+
cwd
|
|
1701
1718
|
});
|
|
1702
1719
|
const pipeLinePromise = collectStdout(childProcess.stdout, childProcess.kill, maxSearchResults, charsBefore, charsAfter);
|
|
1703
1720
|
const closePromise = waitForProcessToExit(childProcess);
|