@lvce-editor/search-process 5.3.0 → 6.1.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.
Files changed (2) hide show
  1. package/dist/index.js +34 -26
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -50,7 +50,6 @@ const listen$1 = async ({
50
50
  ...params
51
51
  }) => {
52
52
  const module = getModule(method);
53
- // @ts-ignore
54
53
  const rpc = await module.create(params);
55
54
  return rpc;
56
55
  };
@@ -73,6 +72,7 @@ const handleWebSocket = async (handle, request) => {
73
72
  });
74
73
  };
75
74
 
75
+ // TODO avoid using env variable, use argv argument instead
76
76
  const getRipGrepPath = () => {
77
77
  return process.env.RIP_GREP_PATH;
78
78
  };
@@ -85,13 +85,14 @@ const NewLine = '\n';
85
85
  const ENOENT = 'ENOENT';
86
86
  const E_RIP_GREP_NOT_FOUND = 'E_RIP_GREP_NOT_FOUND';
87
87
 
88
+ const isEnoentErrorLinux = error => {
89
+ return error.code === ENOENT;
90
+ };
91
+
88
92
  const isEnoentErrorWindows = error => {
89
93
  return error && error.message && error.message.includes('The system cannot find the path specified.');
90
94
  };
91
95
 
92
- const isEnoentErrorLinux = error => {
93
- return error.code === ENOENT;
94
- };
95
96
  const isEnoentError = error => {
96
97
  if (!error) {
97
98
  return false;
@@ -161,6 +162,19 @@ const exec$1 = async (command, args, options) => {
161
162
  };
162
163
  };
163
164
 
165
+ const execRipGrep = async (args, options) => {
166
+ array(args);
167
+ object(options);
168
+ const {
169
+ stdout,
170
+ stderr
171
+ } = await exec$1(ripGrepPath, args, options);
172
+ return {
173
+ stdout,
174
+ stderr
175
+ };
176
+ };
177
+
164
178
  const spawn = (args, options) => {
165
179
  try {
166
180
  const childProcess = NodeChildProcess.spawn(ripGrepPath, args, options);
@@ -185,18 +199,7 @@ const spawn = (args, options) => {
185
199
  throw new VError(error, `Failed to spawn ripgrep`);
186
200
  }
187
201
  };
188
- const exec = async (args, options) => {
189
- array(args);
190
- object(options);
191
- const {
192
- stdout,
193
- stderr
194
- } = await exec$1(ripGrepPath, args, options);
195
- return {
196
- stdout,
197
- stderr
198
- };
199
- };
202
+ const exec = execRipGrep;
200
203
 
201
204
  // TODO don't necessarily need ripgrep to list all the files,
202
205
  // maybe also a faster c program can do it
@@ -214,15 +217,14 @@ const searchFile = async ({
214
217
  array(ripGrepArgs);
215
218
  number(limit);
216
219
  const {
217
- stdout,
218
- stderr
220
+ stdout
219
221
  } = await exec(ripGrepArgs, {
220
222
  cwd: searchPath
221
223
  });
222
224
  return limitString(stdout, limit);
223
225
  } catch (error$1) {
224
226
  if (isEnoentError(error$1)) {
225
- info(`[shared-process] ripgrep could not be found at "${ripGrepPath}"`);
227
+ info(`[search-process] ripgrep could not be found at "${ripGrepPath}"`);
226
228
  return EmptyString;
227
229
  }
228
230
  // @ts-ignore
@@ -370,15 +372,18 @@ const collectStdout = async (childProcess, maxSearchResults, charsBefore, charsA
370
372
  const Error$1 = 1;
371
373
  const Exit = 2;
372
374
 
375
+ class RipGrepNotFoundError extends Error {
376
+ constructor(cause) {
377
+ super(`ripgrep path not found: ${cause}`);
378
+ this.code = E_RIP_GREP_NOT_FOUND;
379
+ this.name = 'RipGrepNotFoundError';
380
+ }
381
+ }
382
+
373
383
  class TextSearchError extends Error {
374
384
  constructor(cause) {
375
- if (isEnoentError(cause)) {
376
- super(`ripgrep path not found: ${cause}`);
377
- this.code = E_RIP_GREP_NOT_FOUND;
378
- } else {
379
- super(`ripgrep process error: ${cause}`);
380
- this.code = cause.code;
381
- }
385
+ super(`ripgrep process error: ${cause}`);
386
+ this.code = cause.code;
382
387
  this.name = 'TextSearchError';
383
388
  }
384
389
  }
@@ -440,6 +445,9 @@ const search = async ({
440
445
  const closePromise = waitForProcessToExit(childProcess);
441
446
  const [pipeLineResult, exitResult] = await Promise.all([pipeLinePromise, closePromise]);
442
447
  if (exitResult.type === Error$1) {
448
+ if (isEnoentError(exitResult.event)) {
449
+ throw new RipGrepNotFoundError(exitResult.event);
450
+ }
443
451
  throw new TextSearchError(exitResult.event);
444
452
  }
445
453
  return pipeLineResult;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/search-process",
3
- "version": "5.3.0",
3
+ "version": "6.1.0",
4
4
  "description": "Search Process",
5
5
  "keywords": [
6
6
  "Lvce Editor",
@@ -19,12 +19,12 @@
19
19
  },
20
20
  "dependencies": {
21
21
  "@lvce-editor/assert": "^1.3.0",
22
- "@lvce-editor/rpc": "^1.22.0",
22
+ "@lvce-editor/rpc": "^1.27.0",
23
23
  "@lvce-editor/verror": "^1.6.0",
24
24
  "execa": "^9.5.2"
25
25
  },
26
26
  "optionalDependencies": {
27
- "@lvce-editor/ripgrep": "^1.6.0"
27
+ "@lvce-editor/ripgrep": "^2.1.0"
28
28
  },
29
29
  "engines": {
30
30
  "node": ">=22"