@lvce-editor/shared-process 0.17.0 → 0.17.2

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.17.0",
3
+ "version": "0.17.2",
4
4
  "description": "Utility package for @lvce-editor/server",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -16,12 +16,12 @@
16
16
  "node": ">=16"
17
17
  },
18
18
  "dependencies": {
19
- "@babel/code-frame": "^7.22.5",
20
- "@lvce-editor/extension-host": "0.17.0",
21
- "@lvce-editor/extension-host-helper-process": "0.17.0",
22
- "@lvce-editor/pty-host": "0.17.0",
19
+ "@babel/code-frame": "^7.22.10",
20
+ "@lvce-editor/extension-host": "0.17.2",
21
+ "@lvce-editor/extension-host-helper-process": "0.17.2",
22
+ "@lvce-editor/pty-host": "0.17.2",
23
23
  "debug": "^4.3.4",
24
- "execa": "^7.1.1",
24
+ "execa": "^7.2.0",
25
25
  "exit-hook": "^3.2.0",
26
26
  "got": "^13.0.0",
27
27
  "is-object": "^1.0.2",
@@ -1,19 +1,18 @@
1
1
  import { spawn } from 'node:child_process'
2
- import { tmpdir } from 'node:os'
3
- import { join } from 'node:path'
4
2
  import * as Assert from '../Assert/Assert.js'
5
3
  import * as Download from '../Download/Download.js'
4
+ import * as FirstNodeWorkerEventType from '../FirstNodeWorkerEventType/FirstNodeWorkerEventType.js'
5
+ import * as GetFirstSpawnedProcessEvent from '../GetFirstSpawnedProcessEvent/GetFirstSpawnedProcessEvent.js'
6
+ import * as GetNsisUpdateArgs from '../GetNsisUpdateArgs/GetNsisUpdateArgs.js'
7
+ import * as GetNsisDownloadPath from '../GetNsisUpdateDownloadPath/GetNsisUpdateDownloadPath.js'
6
8
  import * as GetWindowsNsisDownloadUrl from '../GetWindowsNsisDownloadUrl/GetWindowsNsisDownloadUrl.js'
7
9
  import * as Logger from '../Logger/Logger.js'
8
10
  import * as Platform from '../Platform/Platform.js'
11
+ import * as UpdateState from '../UpdateState/UpdateState.js'
12
+ import * as UpdateStateType from '../UpdateStateType/UpdateStateType.js'
9
13
  import { VError } from '../VError/VError.js'
10
14
 
11
- const getOutfilePath = (version) => {
12
- Assert.string(version)
13
- const outFile = join(tmpdir(), `nsis-update-${version}`)
14
- return outFile
15
- }
16
-
15
+ // TODO make it possible to cancel downloading updates
17
16
  export const downloadUpdate = async (version) => {
18
17
  try {
19
18
  Assert.string(version)
@@ -21,9 +20,11 @@ export const downloadUpdate = async (version) => {
21
20
  const setupName = Platform.getSetupName()
22
21
  const fileName = `${setupName}-v${version}.exe`
23
22
  const downLoadUrl = GetWindowsNsisDownloadUrl.getDownloadUrl(repository, version, fileName)
24
- const outFile = getOutfilePath(version)
23
+ const outFile = GetNsisDownloadPath.getNsisUpdateDownloadPath(version)
25
24
  Logger.info(`[shared-process] downloading nsis update: ${downLoadUrl} -> ${outFile}`)
25
+ UpdateState.set(UpdateStateType.Downloading)
26
26
  await Download.download(downLoadUrl, outFile)
27
+ UpdateState.set(UpdateStateType.Downloaded)
27
28
  Logger.info(`[shared-process] downloaded nsis update: ${outFile}`)
28
29
  return outFile
29
30
  } catch (error) {
@@ -31,44 +32,18 @@ export const downloadUpdate = async (version) => {
31
32
  }
32
33
  }
33
34
 
34
- const getNsisUpdateArgs = () => {
35
- const args = []
36
- args.push('--updated')
37
- args.push('/S')
38
- args.push('--force-run')
39
- return args
40
- }
41
-
42
- const getFirstNsisProcessEvent = async (childProcess) => {
43
- const { type, event } = await new Promise((resolve) => {
44
- const cleanup = (value) => {
45
- childProcess.off('error', handleError)
46
- childProcess.off('exit', handleExit)
47
- resolve(value)
48
- }
49
- const handleError = (event) => {
50
- cleanup({ type: 'error', event })
51
- }
52
- const handleExit = (event) => {
53
- cleanup({ type: 'exit', event })
54
- }
55
- childProcess.on('error', handleError)
56
- childProcess.on('exit', handleExit)
57
- })
58
- return {
59
- type,
60
- event,
61
- }
62
- }
63
-
64
35
  export const installAndRestart = async (downloadPath) => {
65
36
  try {
66
37
  Assert.string(downloadPath)
67
- const args = getNsisUpdateArgs()
38
+ const args = GetNsisUpdateArgs.getNsisUpdateArgs()
68
39
  Logger.info(`[shared-process] spawning nsis update: ${downloadPath}`)
69
- const child = spawn(downloadPath, args, { stdio: 'inherit' })
70
- const { type, event } = await getFirstNsisProcessEvent(child)
71
- if (type === 'error') {
40
+ UpdateState.set(UpdateStateType.Updating)
41
+ const child = spawn(downloadPath, args, {
42
+ stdio: 'inherit',
43
+ detached: true,
44
+ })
45
+ const { type, event } = await GetFirstSpawnedProcessEvent.getFirstSpawnedProcessEvent(child)
46
+ if (type === FirstNodeWorkerEventType.Error) {
72
47
  throw new Error(`Child process error: ${event}`)
73
48
  }
74
49
  Logger.info(`[shared-process] finished nsis update`)
@@ -0,0 +1,9 @@
1
+ import * as GetFirstEvent from '../GetFirstEvent/GetFirstEvent.js'
2
+ import * as FirstNodeWorkerEventType from '../FirstNodeWorkerEventType/FirstNodeWorkerEventType.js'
3
+
4
+ export const getFirstSpawnedProcessEvent = (childProcess) => {
5
+ return GetFirstEvent.getFirstEvent(childProcess, {
6
+ error: FirstNodeWorkerEventType.Error,
7
+ exit: FirstNodeWorkerEventType.Exit,
8
+ })
9
+ }
@@ -0,0 +1,7 @@
1
+ export const getNsisUpdateArgs = () => {
2
+ const args = []
3
+ args.push('--updated')
4
+ args.push('/S')
5
+ args.push('--force-run')
6
+ return args
7
+ }
@@ -0,0 +1,11 @@
1
+ import { tmpdir } from 'node:os'
2
+ import { join } from 'node:path'
3
+ import * as Assert from '../Assert/Assert.js'
4
+ import * as Platform from '../Platform/Platform.js'
5
+
6
+ export const getNsisUpdateDownloadPath = (version) => {
7
+ Assert.string(version)
8
+ const name = Platform.applicationName
9
+ const outFile = join(tmpdir(), `${name}-update-${version}.exe`)
10
+ return outFile
11
+ }
@@ -1,6 +1,8 @@
1
1
  import * as Assert from '../Assert/Assert.js'
2
2
 
3
3
  export const getDownloadUrl = (repository, version, fileName) => {
4
+ Assert.string(repository)
4
5
  Assert.string(version)
6
+ Assert.string(fileName)
5
7
  return `https://github.com/${repository}/releases/download/v${version}/${fileName}`
6
8
  }
@@ -169,11 +169,11 @@ export const getSetupName = () => {
169
169
  return 'Lvce-Setup'
170
170
  }
171
171
 
172
- export const version = '0.17.0'
172
+ export const version = '0.17.2'
173
173
 
174
- export const commit = '4a17b31'
174
+ export const commit = 'e83e740'
175
175
 
176
- export const date = '2023-08-05T17:17:49.000Z'
176
+ export const date = '2023-08-12T10:04:22.000Z'
177
177
 
178
178
  export const getVersion = () => {
179
179
  return version
@@ -0,0 +1,13 @@
1
+ import * as UpdateStateType from '../UpdateStateType/UpdateStateType.js'
2
+
3
+ export const state = {
4
+ updateState: UpdateStateType.Uninitialized,
5
+ }
6
+
7
+ export const get = () => {
8
+ return state.updateState
9
+ }
10
+
11
+ export const set = (value) => {
12
+ state.updateState = value
13
+ }
@@ -0,0 +1,9 @@
1
+ export const Uninitialized = 1
2
+ export const Idle = 2
3
+ export const Disabled = 3
4
+ export const CheckingForUpdates = 3
5
+ export const AvailableForDownload = 4
6
+ export const Downloading = 5
7
+ export const Downloaded = 6
8
+ export const Updating = 7
9
+ export const Ready = 8