@lvce-editor/shared-process 0.15.31 → 0.15.32

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/shared-process",
3
- "version": "0.15.31",
3
+ "version": "0.15.32",
4
4
  "description": "Utility package for @lvce-editor/server",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -17,9 +17,9 @@
17
17
  },
18
18
  "dependencies": {
19
19
  "@babel/code-frame": "^7.22.5",
20
- "@lvce-editor/extension-host": "0.15.31",
21
- "@lvce-editor/extension-host-helper-process": "0.15.31",
22
- "@lvce-editor/pty-host": "0.15.31",
20
+ "@lvce-editor/extension-host": "0.15.32",
21
+ "@lvce-editor/extension-host-helper-process": "0.15.32",
22
+ "@lvce-editor/pty-host": "0.15.32",
23
23
  "debug": "^4.3.4",
24
24
  "execa": "^7.1.1",
25
25
  "exit-hook": "^3.2.0",
@@ -28,7 +28,7 @@
28
28
  "lines-and-columns": "^2.0.3",
29
29
  "p-queue": "^7.3.4",
30
30
  "parse-json": "^7.0.0",
31
- "tar-fs": "^2.1.1",
31
+ "tar-fs": "^3.0.3",
32
32
  "ws": "^8.13.0",
33
33
  "xdg-basedir": "^5.1.0"
34
34
  },
@@ -1,3 +1,19 @@
1
1
  export const getFolder = () => {
2
2
  return process.env.FOLDER || process.cwd()
3
3
  }
4
+
5
+ export const getAppImagePath = () => {
6
+ return process.env.APPIMAGE
7
+ }
8
+
9
+ export const getElectronRunAsNode = () => {
10
+ return process.env.ELECTRON_RUN_AS_NODE
11
+ }
12
+
13
+ export const getNodeEnv = () => {
14
+ return process.env.NODE_ENV
15
+ }
16
+
17
+ export const getRipGrepPath = () => {
18
+ return process.env.RIP_GREP_PATH
19
+ }
@@ -19,3 +19,4 @@ export const ERR_MODULE_NOT_FOUND = 'ERR_MODULE_NOT_FOUND'
19
19
  export const EXDEV = 'EXDEV'
20
20
  export const ERR_DLOPEN_FAILED = 'ERR_DLOPEN_FAILED'
21
21
  export const ESRCH = 'ESRCH'
22
+ export const E_RIP_GREP_NOT_FOUND = 'E_RIP_GREP_NOT_FOUND'
@@ -1,3 +1,5 @@
1
+ import * as Env from '../Env/Env.js'
2
+
1
3
  export const getAppImagePath = () => {
2
- return process.env.APPIMAGE
4
+ return Env.getAppImagePath()
3
5
  }
@@ -4,13 +4,7 @@ import * as JsonRpcErrorCode from '../JsonRpcErrorCode/JsonRpcErrorCode.js'
4
4
  import * as JsonRpcErrorResponse from '../JsonRpcErrorResponse/JsonRpcErrorResponse.js'
5
5
  import * as PrettyError from '../PrettyError/PrettyError.js'
6
6
  import * as PrintPrettyError from '../PrintPrettyError/PrintPrettyError.js'
7
-
8
- const shouldLogError = (error) => {
9
- if (error && error.code === ErrorCodes.ENOENT) {
10
- return false
11
- }
12
- return true
13
- }
7
+ import * as ShouldLogError from '../ShouldLogError/ShouldLogError.js'
14
8
 
15
9
  const getErrorProperty = (error, prettyError) => {
16
10
  if (error && error instanceof CommandNotFoundError) {
@@ -20,7 +14,7 @@ const getErrorProperty = (error, prettyError) => {
20
14
  data: error.stack,
21
15
  }
22
16
  }
23
- if (!shouldLogError(error)) {
17
+ if (!ShouldLogError.shouldLogError(error)) {
24
18
  return {
25
19
  code: JsonRpcErrorCode.Custom,
26
20
  message: `${error}`,
@@ -43,7 +37,7 @@ const getErrorProperty = (error, prettyError) => {
43
37
 
44
38
  export const getErrorResponse = (message, error, ipc) => {
45
39
  const prettyError = PrettyError.prepare(error)
46
- if (shouldLogError(error)) {
40
+ if (ShouldLogError.shouldLogError(error)) {
47
41
  PrintPrettyError.printPrettyError(prettyError, `[shared-process] `)
48
42
  }
49
43
  const errorProperty = getErrorProperty(error, prettyError)
@@ -1,3 +1,5 @@
1
+ import * as Env from '../Env/Env.js'
2
+
1
3
  export const isElectron = () => {
2
- return Boolean(process.env.ELECTRON_RUN_AS_NODE)
4
+ return Boolean(Env.getElectronRunAsNode())
3
5
  }
@@ -146,6 +146,7 @@ export const getModuleId = (commandId) => {
146
146
  case 'Platform.setEnvironmentVariables':
147
147
  case 'Platform.getCommit':
148
148
  case 'Platform.getVersion':
149
+ case 'Platform.getDate':
149
150
  return ModuleId.Platform
150
151
  case 'Preferences.getAll':
151
152
  return ModuleId.Preferences
@@ -23,4 +23,5 @@ export const Commands = {
23
23
  getUserSettingsPath: Platform.getUserSettingsPath,
24
24
  getVersion: Platform.getVersion,
25
25
  setEnvironmentVariables: Platform.setEnvironmentVariables,
26
+ getDate: Platform.getDate,
26
27
  }
@@ -165,9 +165,11 @@ export const getSetupName = () => {
165
165
  return 'Lvce-Setup'
166
166
  }
167
167
 
168
- export const version = '0.15.31'
168
+ export const version = '0.15.32'
169
169
 
170
- export const commit = '85343c2'
170
+ export const commit = '4913b6f'
171
+
172
+ export const date = '2023-06-21T10:02:09.000Z'
171
173
 
172
174
  export const getVersion = () => {
173
175
  return version
@@ -176,3 +178,7 @@ export const getVersion = () => {
176
178
  export const getCommit = () => {
177
179
  return commit
178
180
  }
181
+
182
+ export const getDate = () => {
183
+ return date
184
+ }
@@ -0,0 +1,2 @@
1
+ export const Error = 1
2
+ export const Exit = 2
@@ -1,24 +1,34 @@
1
1
  import * as NodeChildProcess from 'node:child_process'
2
2
  import * as Assert from '../Assert/Assert.js'
3
+ import * as Env from '../Env/Env.js'
3
4
  import * as Exec from '../Exec/Exec.js'
4
5
  import * as RgPath from '../RipGrepPath/RipGrepPath.js'
6
+ import { VError } from '../VError/VError.js'
5
7
 
6
- export const ripGrepPath = process.env.RIP_GREP_PATH || RgPath.rgPath
8
+ export const ripGrepPath = Env.getRipGrepPath() || RgPath.rgPath
7
9
 
8
10
  export const spawn = (args, options) => {
9
- const childProcess = NodeChildProcess.spawn(RgPath.rgPath, args, options)
10
- return {
11
- on(event, listener) {
12
- childProcess.on(event, listener)
13
- },
14
- once(event, listener) {
15
- childProcess.once(event, listener)
16
- },
17
- stdout: childProcess.stdout,
18
- stderr: childProcess.stderr,
19
- kill() {
20
- childProcess.kill()
21
- },
11
+ try {
12
+ const childProcess = NodeChildProcess.spawn(RgPath.rgPath, args, options)
13
+ return {
14
+ childProcess,
15
+ on(event, listener) {
16
+ this.childProcess.on(event, listener)
17
+ },
18
+ off(event, listener) {
19
+ this.childProcess.off(event, listener)
20
+ },
21
+ once(event, listener) {
22
+ this.childProcess.once(event, listener)
23
+ },
24
+ stdout: childProcess.stdout,
25
+ stderr: childProcess.stderr,
26
+ kill() {
27
+ this.childProcess.kill()
28
+ },
29
+ }
30
+ } catch (error) {
31
+ throw new VError(error, `Failed to spawn ripgrep`)
22
32
  }
23
33
  }
24
34
 
@@ -1,4 +1,5 @@
1
1
  import * as Assert from '../Assert/Assert.js'
2
+ import * as Character from '../Character/Character.js'
2
3
  import * as IsEnoentError from '../IsEnoentError/IsEnoentError.js'
3
4
  import * as LimitString from '../LimitString/LimitString.js'
4
5
  import * as Logger from '../Logger/Logger.js'
@@ -10,25 +11,25 @@ import * as RipGrep from '../RipGrep/RipGrep.js'
10
11
  // do a delta comparison, so the first time it would send 100kB
11
12
  // but the second time only a few hundred bytes of changes
12
13
 
13
- export const searchFile = async (path, searchTerm, limit) => {
14
+ export const searchFile = async ({ searchPath = '', limit = 100, ripGrepArgs = [] }) => {
14
15
  try {
15
- Assert.string(path)
16
- Assert.string(searchTerm)
16
+ Assert.string(searchPath)
17
+ Assert.array(ripGrepArgs)
17
18
  Assert.number(limit)
18
- const { stdout, stderr } = await RipGrep.exec(['--files', '--sort-files'], {
19
- cwd: path,
19
+ const { stdout, stderr } = await RipGrep.exec(ripGrepArgs, {
20
+ cwd: searchPath,
20
21
  })
21
22
  return LimitString.limitString(stdout, limit)
22
23
  } catch (error) {
23
24
  if (IsEnoentError.isEnoentError(error)) {
24
25
  Logger.info(`[shared-process] ripgrep could not be found at "${RipGrep.ripGrepPath}"`)
25
- return ``
26
+ return Character.EmptyString
26
27
  }
27
28
  // @ts-ignore
28
- if (error && error.stderr === '') {
29
- return ``
29
+ if (error && error.stderr === Character.EmptyString) {
30
+ return Character.EmptyString
30
31
  }
31
32
  Logger.error(error)
32
- return ``
33
+ return Character.EmptyString
33
34
  }
34
35
  }
@@ -0,0 +1,8 @@
1
+ import * as ErrorCodes from '../ErrorCodes/ErrorCodes.js'
2
+
3
+ export const shouldLogError = (error) => {
4
+ if (error && error.code === ErrorCodes.ENOENT) {
5
+ return false
6
+ }
7
+ return true
8
+ }
@@ -2,11 +2,13 @@ import { Writable } from 'node:stream'
2
2
  import { pipeline } from 'node:stream/promises'
3
3
  import * as EncodingType from '../EncodingType/EncodingType.js'
4
4
  import * as GetNewLineIndex from '../GetNewLineIndex/GetNewLineIndex.js'
5
- import * as GetTextSearchRipGrepArgs from '../GetTextSearchRipGrepArgs/GetTextSearchRipGrepArgs.js'
5
+ import * as ProcessExitEventType from '../ProcessExitEventType/ProcessExitEventType.js'
6
6
  import * as RipGrep from '../RipGrep/RipGrep.js'
7
7
  import * as RipGrepParsedLineType from '../RipGrepParsedLineType/RipGrepParsedLineType.js'
8
+ import { TextSearchError } from '../TextSearchError/TextSearchError.js'
8
9
  import * as TextSearchResultType from '../TextSearchResultType/TextSearchResultType.js'
9
10
  import * as ToTextSearchResult from '../ToTextSearchResult/ToTextSearchResult.js'
11
+ import * as WaitForProcessToExit from '../WaitForProcessToExit/WaitForProcessToExit.js'
10
12
  // TODO update vscode-ripgrep when https://github.com/mhinz/vim-grepper/issues/244, https://github.com/BurntSushi/ripgrep/issues/1892 is fixed
11
13
 
12
14
  // need to use '.' as last argument for ripgrep
@@ -103,32 +105,17 @@ const collectStdout = async (childProcess, maxSearchResults, charsBefore, charsA
103
105
  }
104
106
  }
105
107
 
106
- export const search = async (searchDir, searchString, { threads = 1, maxSearchResults = 20_000, isCaseSensitive = false } = {}) => {
108
+ export const search = async ({ searchDir = '', maxSearchResults = 20_000, ripGrepArgs = [] } = {}) => {
107
109
  const charsBefore = 26
108
110
  const charsAfter = 50
109
- const ripGrepArgs = GetTextSearchRipGrepArgs.getRipGrepArgs({
110
- threads,
111
- isCaseSensitive,
112
- searchString,
113
- })
114
111
  const childProcess = RipGrep.spawn(ripGrepArgs, {
115
112
  cwd: searchDir,
116
113
  })
117
114
  const pipeLinePromise = collectStdout(childProcess, maxSearchResults, charsBefore, charsAfter)
118
- const closePromise = new Promise((resolve, reject) => {
119
- // TODO use pipeline / transform stream maybe
120
- const handleClose = () => {
121
- resolve(undefined)
122
- }
123
- const handleError = (error) => {
124
- // TODO check type of error
125
- console.error(error)
126
- resolve(undefined)
127
- }
128
-
129
- childProcess.once('close', handleClose)
130
- childProcess.once('error', handleError)
131
- })
132
- await Promise.all([pipeLinePromise, closePromise])
133
- return await pipeLinePromise
115
+ const closePromise = WaitForProcessToExit.waitForProcessToExit(childProcess)
116
+ const [pipeLineResult, exitResult] = await Promise.all([pipeLinePromise, closePromise])
117
+ if (exitResult.type === ProcessExitEventType.Error) {
118
+ throw new TextSearchError(exitResult.event)
119
+ }
120
+ return pipeLineResult
134
121
  }
@@ -0,0 +1,15 @@
1
+ import * as ErrorCodes from '../ErrorCodes/ErrorCodes.js'
2
+ import * as IsEnoentError from '../IsEnoentError/IsEnoentError.js'
3
+
4
+ export class TextSearchError extends Error {
5
+ constructor(cause) {
6
+ if (IsEnoentError.isEnoentError(cause)) {
7
+ super(`ripgrep path not found: ${cause}`)
8
+ this.code = ErrorCodes.E_RIP_GREP_NOT_FOUND
9
+ } else {
10
+ super(`ripgrep process error: ${cause}`)
11
+ this.code = cause.code
12
+ }
13
+ this.name = 'TextSearchError'
14
+ }
15
+ }
@@ -1,3 +1,5 @@
1
+ import * as Env from '../Env/Env.js'
2
+
1
3
  export const LEVEL = {
2
4
  DEFAULT: 1,
3
5
  VERBOSE: 2,
@@ -8,7 +10,7 @@ export const state = {
8
10
  }
9
11
 
10
12
  export const trace =
11
- process.env.NODE_ENV === 'test'
13
+ Env.getNodeEnv() === 'test'
12
14
  ? () => {}
13
15
  : (...args) => {
14
16
  console.info('[Trace]', ...args)
@@ -0,0 +1,29 @@
1
+ import * as ProcessExitEventType from '../ProcessExitEventType/ProcessExitEventType.js'
2
+
3
+ export const waitForProcessToExit = async (childProcess) => {
4
+ const { type, event } = await new Promise((resolve, reject) => {
5
+ const cleanup = (value) => {
6
+ childProcess.off('close', handleClose)
7
+ childProcess.off('error', handleError)
8
+ resolve(value)
9
+ }
10
+ const handleClose = (event) => {
11
+ cleanup({
12
+ type: ProcessExitEventType.Exit,
13
+ event,
14
+ })
15
+ }
16
+ const handleError = (event) => {
17
+ cleanup({
18
+ type: ProcessExitEventType.Error,
19
+ event,
20
+ })
21
+ }
22
+ childProcess.on('close', handleClose)
23
+ childProcess.on('error', handleError)
24
+ })
25
+ return {
26
+ type,
27
+ event,
28
+ }
29
+ }
@@ -1,14 +0,0 @@
1
- export const getRipGrepArgs = ({ threads, isCaseSensitive, searchString }) => {
2
- const ripGrepArgs = ['--smart-case', '--stats', '--json']
3
- ripGrepArgs.push('--threads', `${threads}`)
4
- if (isCaseSensitive) {
5
- ripGrepArgs.push('--case-sensitive')
6
- } else {
7
- ripGrepArgs.push('--ignore-case')
8
- }
9
- ripGrepArgs.push('--fixed-strings')
10
- ripGrepArgs.push('--')
11
- ripGrepArgs.push(searchString)
12
- ripGrepArgs.push('.')
13
- return ripGrepArgs
14
- }