@lvce-editor/search-process 5.0.0 → 5.2.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 +14 -43
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,11 +1,11 @@
1
1
  import { object, string, array, number } from '@lvce-editor/assert';
2
2
  import { NodeWebSocketRpcClient, ElectronMessagePortRpcClient, ElectronUtilityProcessRpcClient, NodeWorkerRpcClient, NodeForkedProcessRpcClient } from '@lvce-editor/rpc';
3
+ import { rgPath } from '@lvce-editor/ripgrep';
3
4
  import { Console } from 'node:console';
4
5
  import { createWriteStream } from 'node:fs';
5
6
  import { tmpdir } from 'node:os';
6
7
  import * as NodeChildProcess from 'node:child_process';
7
8
  import { execa } from 'execa';
8
- import { rgPath } from '@lvce-editor/ripgrep';
9
9
  import { VError } from '@lvce-editor/verror';
10
10
  import { Writable } from 'node:stream';
11
11
  import { pipeline } from 'node:stream/promises';
@@ -15,10 +15,7 @@ const NodeForkedProcess = 2;
15
15
  const ElectronUtilityProcess = 3;
16
16
  const ElectronMessagePort = 4;
17
17
  const WebSocket = 6;
18
- const Auto = () => {
19
- const {
20
- argv
21
- } = process;
18
+ const Auto = argv => {
22
19
  if (argv.includes('--ipc-type=node-worker')) {
23
20
  return NodeWorker;
24
21
  }
@@ -28,7 +25,7 @@ const Auto = () => {
28
25
  if (argv.includes('--ipc-type=electron-utility-process')) {
29
26
  return ElectronUtilityProcess;
30
27
  }
31
- throw new Error(`[shared-process] unknown ipc type`);
28
+ throw new Error(`[search-process] unknown ipc type`);
32
29
  };
33
30
 
34
31
  const getModule = method => {
@@ -76,6 +73,12 @@ const handleWebSocket = async (handle, request) => {
76
73
  });
77
74
  };
78
75
 
76
+ const getRipGrepPath = () => {
77
+ return process.env.RIP_GREP_PATH;
78
+ };
79
+
80
+ const ripGrepPath = getRipGrepPath() || rgPath;
81
+
79
82
  const EmptyString = '';
80
83
  const NewLine = '\n';
81
84
 
@@ -144,17 +147,6 @@ const error = (...args) => {
144
147
  console.error(...args);
145
148
  };
146
149
 
147
- const getRipGrepPath = () => {
148
- return process.env.RIP_GREP_PATH;
149
- };
150
-
151
- /**
152
- *
153
- * @param {string} command
154
- * @param {string[]} args
155
- * @param {import('execa').Options} options
156
- * @returns
157
- */
158
150
  const exec$1 = async (command, args, options) => {
159
151
  string(command);
160
152
  array(args);
@@ -169,10 +161,9 @@ const exec$1 = async (command, args, options) => {
169
161
  };
170
162
  };
171
163
 
172
- const ripGrepPath = getRipGrepPath() || rgPath;
173
164
  const spawn = (args, options) => {
174
165
  try {
175
- const childProcess = NodeChildProcess.spawn(rgPath, args, options);
166
+ const childProcess = NodeChildProcess.spawn(ripGrepPath, args, options);
176
167
  return {
177
168
  childProcess,
178
169
  on(event, listener) {
@@ -392,31 +383,11 @@ class TextSearchError extends Error {
392
383
  }
393
384
  }
394
385
 
395
- const withResolvers = () => {
396
- /**
397
- * @type {any}
398
- */
399
- let _resolve;
400
- /**
401
- * @type {any}
402
- */
403
- let _reject;
404
- const promise = new Promise((resolve, reject) => {
405
- _resolve = resolve;
406
- _reject = reject;
407
- });
408
- return {
409
- resolve: _resolve,
410
- reject: _reject,
411
- promise
412
- };
413
- };
414
-
415
386
  const getFirstEvent = (eventEmitter, eventMap) => {
416
387
  const {
417
388
  resolve,
418
389
  promise
419
- } = withResolvers();
390
+ } = Promise.withResolvers();
420
391
  const listenerMap = Object.create(null);
421
392
  const cleanup = value => {
422
393
  for (const event of Object.keys(eventMap)) {
@@ -481,15 +452,15 @@ const commandMap = {
481
452
  'TextSearch.search': search
482
453
  };
483
454
 
484
- const listen = async () => {
455
+ const listen = async argv => {
485
456
  await listen$1({
486
- method: Auto(),
457
+ method: Auto(argv),
487
458
  commandMap: commandMap
488
459
  });
489
460
  };
490
461
 
491
462
  const main = async () => {
492
- await listen();
463
+ await listen(process.argv);
493
464
  };
494
465
 
495
466
  main();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/search-process",
3
- "version": "5.0.0",
3
+ "version": "5.2.0",
4
4
  "description": "Search Process",
5
5
  "keywords": [
6
6
  "Lvce Editor",