@lvce-editor/file-watcher-process 1.4.0 → 1.5.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 +55 -47
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,9 +1,62 @@
1
+ import { ElectronMessagePortRpcClient, ElectronUtilityProcessRpcClient, NodeWorkerRpcClient, NodeForkedProcessRpcClient } from '@lvce-editor/rpc';
1
2
  import { get, set } from '@lvce-editor/rpc-registry';
2
3
  import { VError } from '@lvce-editor/verror';
3
4
  import * as fs from 'node:fs/promises';
4
5
  import { watch } from 'chokidar';
5
6
  import { pathToFileURL, fileURLToPath } from 'node:url';
6
- import { ElectronMessagePortRpcClient, ElectronUtilityProcessRpcClient, NodeWorkerRpcClient, NodeForkedProcessRpcClient } from '@lvce-editor/rpc';
7
+
8
+ const NodeWorker = 1;
9
+ const NodeForkedProcess = 2;
10
+ const ElectronUtilityProcess = 3;
11
+ const ElectronMessagePort = 4;
12
+ const Auto = () => {
13
+ const {
14
+ argv
15
+ } = process;
16
+ if (argv.includes('--ipc-type=node-worker')) {
17
+ return NodeWorker;
18
+ }
19
+ if (argv.includes('--ipc-type=node-forked-process')) {
20
+ return NodeForkedProcess;
21
+ }
22
+ if (argv.includes('--ipc-type=electron-utility-process')) {
23
+ return ElectronUtilityProcess;
24
+ }
25
+ throw new Error('[preview-process] unknown ipc type');
26
+ };
27
+
28
+ const getModule = method => {
29
+ switch (method) {
30
+ case NodeForkedProcess:
31
+ return NodeForkedProcessRpcClient;
32
+ case NodeWorker:
33
+ return NodeWorkerRpcClient;
34
+ case ElectronUtilityProcess:
35
+ return ElectronUtilityProcessRpcClient;
36
+ case ElectronMessagePort:
37
+ return ElectronMessagePortRpcClient;
38
+ default:
39
+ throw new Error('unexpected ipc type');
40
+ }
41
+ };
42
+
43
+ const listen$1 = async ({
44
+ method,
45
+ ...params
46
+ }) => {
47
+ const module = getModule(method);
48
+ // @ts-ignore
49
+ const rpc = await module.create(params);
50
+ // @ts-ignore
51
+ return rpc;
52
+ };
53
+
54
+ const handleElectronMessagePort = async messagePort => {
55
+ await listen$1({
56
+ method: ElectronMessagePort,
57
+ messagePort
58
+ });
59
+ };
7
60
 
8
61
  const SharedProcess = 1;
9
62
 
@@ -102,57 +155,12 @@ const watchFolders = async ({
102
155
  };
103
156
 
104
157
  const commandMap = {
158
+ 'HandleElectronMessagePort.handleElectronMessagePort': handleElectronMessagePort,
105
159
  'FileWatcher.watchFile': watchFile,
106
160
  'FileWatcher.watchFolder': watchFolder,
107
161
  'FileWatcher.watchFolders': watchFolders
108
162
  };
109
163
 
110
- const NodeWorker = 1;
111
- const NodeForkedProcess = 2;
112
- const ElectronUtilityProcess = 3;
113
- const ElectronMessagePort = 4;
114
- const Auto = () => {
115
- const {
116
- argv
117
- } = process;
118
- if (argv.includes('--ipc-type=node-worker')) {
119
- return NodeWorker;
120
- }
121
- if (argv.includes('--ipc-type=node-forked-process')) {
122
- return NodeForkedProcess;
123
- }
124
- if (argv.includes('--ipc-type=electron-utility-process')) {
125
- return ElectronUtilityProcess;
126
- }
127
- throw new Error('[preview-process] unknown ipc type');
128
- };
129
-
130
- const getModule = method => {
131
- switch (method) {
132
- case NodeForkedProcess:
133
- return NodeForkedProcessRpcClient;
134
- case NodeWorker:
135
- return NodeWorkerRpcClient;
136
- case ElectronUtilityProcess:
137
- return ElectronUtilityProcessRpcClient;
138
- case ElectronMessagePort:
139
- return ElectronMessagePortRpcClient;
140
- default:
141
- throw new Error('unexpected ipc type');
142
- }
143
- };
144
-
145
- const listen$1 = async ({
146
- method,
147
- ...params
148
- }) => {
149
- const module = getModule(method);
150
- // @ts-ignore
151
- const rpc = await module.create(params);
152
- // @ts-ignore
153
- return rpc;
154
- };
155
-
156
164
  const listen = async () => {
157
165
  const rpc = await listen$1({
158
166
  method: Auto(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/file-watcher-process",
3
- "version": "1.4.0",
3
+ "version": "1.5.0",
4
4
  "description": "File Watcher Process",
5
5
  "keywords": [
6
6
  "Lvce Editor",