@lvce-editor/search-process 5.2.0 → 6.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.
Files changed (2) hide show
  1. package/dist/index.js +33 -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
  };
@@ -85,13 +84,14 @@ const NewLine = '\n';
85
84
  const ENOENT = 'ENOENT';
86
85
  const E_RIP_GREP_NOT_FOUND = 'E_RIP_GREP_NOT_FOUND';
87
86
 
87
+ const isEnoentErrorLinux = error => {
88
+ return error.code === ENOENT;
89
+ };
90
+
88
91
  const isEnoentErrorWindows = error => {
89
92
  return error && error.message && error.message.includes('The system cannot find the path specified.');
90
93
  };
91
94
 
92
- const isEnoentErrorLinux = error => {
93
- return error.code === ENOENT;
94
- };
95
95
  const isEnoentError = error => {
96
96
  if (!error) {
97
97
  return false;
@@ -161,6 +161,19 @@ const exec$1 = async (command, args, options) => {
161
161
  };
162
162
  };
163
163
 
164
+ const execRipGrep = async (args, options) => {
165
+ array(args);
166
+ object(options);
167
+ const {
168
+ stdout,
169
+ stderr
170
+ } = await exec$1(ripGrepPath, args, options);
171
+ return {
172
+ stdout,
173
+ stderr
174
+ };
175
+ };
176
+
164
177
  const spawn = (args, options) => {
165
178
  try {
166
179
  const childProcess = NodeChildProcess.spawn(ripGrepPath, args, options);
@@ -185,18 +198,7 @@ const spawn = (args, options) => {
185
198
  throw new VError(error, `Failed to spawn ripgrep`);
186
199
  }
187
200
  };
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
- };
201
+ const exec = execRipGrep;
200
202
 
201
203
  // TODO don't necessarily need ripgrep to list all the files,
202
204
  // maybe also a faster c program can do it
@@ -214,15 +216,14 @@ const searchFile = async ({
214
216
  array(ripGrepArgs);
215
217
  number(limit);
216
218
  const {
217
- stdout,
218
- stderr
219
+ stdout
219
220
  } = await exec(ripGrepArgs, {
220
221
  cwd: searchPath
221
222
  });
222
223
  return limitString(stdout, limit);
223
224
  } catch (error$1) {
224
225
  if (isEnoentError(error$1)) {
225
- info(`[shared-process] ripgrep could not be found at "${ripGrepPath}"`);
226
+ info(`[search-process] ripgrep could not be found at "${ripGrepPath}"`);
226
227
  return EmptyString;
227
228
  }
228
229
  // @ts-ignore
@@ -370,15 +371,18 @@ const collectStdout = async (childProcess, maxSearchResults, charsBefore, charsA
370
371
  const Error$1 = 1;
371
372
  const Exit = 2;
372
373
 
374
+ class RipGrepNotFoundError extends Error {
375
+ constructor(cause) {
376
+ super(`ripgrep path not found: ${cause}`);
377
+ this.code = E_RIP_GREP_NOT_FOUND;
378
+ this.name = 'RipGrepNotFoundError';
379
+ }
380
+ }
381
+
373
382
  class TextSearchError extends Error {
374
383
  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
- }
384
+ super(`ripgrep process error: ${cause}`);
385
+ this.code = cause.code;
382
386
  this.name = 'TextSearchError';
383
387
  }
384
388
  }
@@ -440,6 +444,9 @@ const search = async ({
440
444
  const closePromise = waitForProcessToExit(childProcess);
441
445
  const [pipeLineResult, exitResult] = await Promise.all([pipeLinePromise, closePromise]);
442
446
  if (exitResult.type === Error$1) {
447
+ if (isEnoentError(exitResult.event)) {
448
+ throw new RipGrepNotFoundError(exitResult.event);
449
+ }
443
450
  throw new TextSearchError(exitResult.event);
444
451
  }
445
452
  return pipeLineResult;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/search-process",
3
- "version": "5.2.0",
3
+ "version": "6.0.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.21.0",
22
+ "@lvce-editor/rpc": "^1.23.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"