@lvce-editor/shared-process 0.45.9 → 0.45.10

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.45.9",
3
+ "version": "0.45.10",
4
4
  "main": "index.js",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -18,7 +18,7 @@
18
18
  },
19
19
  "dependencies": {
20
20
  "@lvce-editor/assert": "1.3.0",
21
- "@lvce-editor/extension-host-helper-process": "0.45.9",
21
+ "@lvce-editor/extension-host-helper-process": "0.45.10",
22
22
  "@lvce-editor/ipc": "13.7.0",
23
23
  "@lvce-editor/json-rpc": "5.4.0",
24
24
  "@lvce-editor/jsonc-parser": "1.5.0",
@@ -35,6 +35,7 @@
35
35
  "@lvce-editor/preview-process": "7.22.0",
36
36
  "@lvce-editor/pty-host": "3.1.0",
37
37
  "@lvce-editor/search-process": "4.1.0",
38
+ "@lvce-editor/file-watcher-process": "1.4.0",
38
39
  "@lvce-editor/typescript-compile-process": "2.3.0",
39
40
  "open": "^10.1.0",
40
41
  "tail": "^2.2.6",
@@ -2,6 +2,6 @@ import { join } from 'path';
2
2
  import { fileURLToPath } from 'url';
3
3
  export const getBuiltinExtensionsPath = () => {
4
4
  const staticServerPath = fileURLToPath(import.meta.resolve('@lvce-editor/static-server'));
5
- const builtinExtensionsPath = join(staticServerPath, '..', '..', 'static', '06fb1fd', 'extensions');
5
+ const builtinExtensionsPath = join(staticServerPath, '..', '..', 'static', 'b53ee00', 'extensions');
6
6
  return builtinExtensionsPath;
7
7
  };
@@ -2,4 +2,5 @@ import * as FileWatcher from '../FileWatcher/FileWatcher.js';
2
2
  export const name = 'FileWatcher';
3
3
  export const Commands = {
4
4
  watch: FileWatcher.watch,
5
+ handleChange: FileWatcher.handleChange,
5
6
  };
@@ -1,27 +1,22 @@
1
- import * as fs from 'node:fs/promises';
1
+ import * as FileWatcherProcess from '../FileWatcherProcess/FileWatcherProcess.js';
2
+ import * as Id from '../Id/Id.js';
2
3
  import * as JsonRpc from '../JsonRpc/JsonRpc.js';
3
- const handleEvents = async (watcher, id, ipc) => {
4
- try {
5
- for await (const event of watcher) {
6
- JsonRpc.send(ipc, 'FileWatcher.handleEvent', id, event);
7
- // ipc.send('FileWatcher.handleEvent', id, event)
8
- }
9
- }
10
- catch (error) {
11
- console.log('event error', error);
12
- }
4
+ const handleEvents = (id, ipc, event) => {
5
+ JsonRpc.send(ipc, 'FileWatcher.handleEvent', id, event);
13
6
  };
14
- // TODO run file watcher in a separate process to not crash application when file watcher crashes
7
+ // handle the case when multiple windows create a file watcher with same id, ids should not collide
8
+ // TODO remove ipc and dispose file watcher when socket / messageport closes
9
+ const internalIdMap = Object.create(null);
15
10
  export const watch = async (ipc, id, { roots, exclude }) => {
16
- try {
17
- for (const root of roots) {
18
- const watcher = fs.watch(root, {
19
- recursive: true,
20
- });
21
- handleEvents(watcher, id, ipc);
22
- }
23
- }
24
- catch (error) {
25
- console.error(error);
26
- }
11
+ const internalId = Id.create();
12
+ internalIdMap[internalId] = { id, ipc };
13
+ await FileWatcherProcess.invoke('FileWatcher.watchFolders', {
14
+ id: internalId,
15
+ roots,
16
+ exclude,
17
+ });
18
+ };
19
+ export const handleChange = (event) => {
20
+ const ref = internalIdMap[event.id];
21
+ handleEvents(ref.id, ref.ipc, event);
27
22
  };
@@ -0,0 +1,18 @@
1
+ import * as JsonRpc from '../JsonRpc/JsonRpc.js';
2
+ import * as LaunchFileWatcherProcess from '../LaunchFileWatcherProcess/LaunchFileWatcherProcess.js';
3
+ export const state = {
4
+ /**
5
+ * @type {any}
6
+ */
7
+ ipc: undefined,
8
+ };
9
+ export const getOrCreate = async () => {
10
+ if (!state.ipc) {
11
+ state.ipc = LaunchFileWatcherProcess.launchFileWatcherProcess();
12
+ }
13
+ return state.ipc;
14
+ };
15
+ export const invoke = async (method, ...params) => {
16
+ const ipc = await getOrCreate();
17
+ return JsonRpc.invoke(ipc, method, ...params);
18
+ };
@@ -0,0 +1,3 @@
1
+ import * as Path from '../Path/Path.js';
2
+ import * as Root from '../Root/Root.js';
3
+ export const fileWatcherProcessPath = Path.join(Root.root, 'packages', 'shared-process', 'node_modules', '@lvce-editor', 'file-watcher-process', 'dist', 'index.js');
@@ -0,0 +1,17 @@
1
+ import * as FileWatcherProcessPath from '../FileWatcherProcessPath/FileWatcherProcessPath.js';
2
+ import * as HandleIpc from '../HandleIpc/HandleIpc.js';
3
+ import * as IpcParent from '../IpcParent/IpcParent.js';
4
+ import * as IpcParentType from '../IpcParentType/IpcParentType.js';
5
+ import * as IsElectron from '../IsElectron/IsElectron.js';
6
+ export const launchFileWatcherProcess = async () => {
7
+ const method = IsElectron.isElectron ? IpcParentType.ElectronUtilityProcess : IpcParentType.NodeForkedProcess;
8
+ const ipc = await IpcParent.create({
9
+ method,
10
+ path: FileWatcherProcessPath.fileWatcherProcessPath,
11
+ argv: [],
12
+ stdio: 'inherit',
13
+ name: 'File Watcher Process',
14
+ });
15
+ HandleIpc.handleIpc(ipc);
16
+ return ipc;
17
+ };
@@ -192,6 +192,7 @@ export const getModuleId = (commandId) => {
192
192
  case 'Platform.getCacheDir':
193
193
  case 'Platform.getCommit':
194
194
  case 'Platform.getRoot':
195
+ case 'Platform.getRootUri':
195
196
  case 'Platform.getConfigDir':
196
197
  case 'Platform.getDataDir':
197
198
  case 'Platform.getDate':
@@ -281,6 +282,7 @@ export const getModuleId = (commandId) => {
281
282
  case 'HandleMessagePortForSearchProcess.handleMessagePortForSearchProcess':
282
283
  return ModuleId.HandleMessagePortForSearchProcess;
283
284
  case 'FileWatcher.watch':
285
+ case 'FileWatcher.handleChange':
284
286
  return ModuleId.FileWatcher;
285
287
  case 'Transferrable.transfer':
286
288
  return ModuleId.Transferrable;
@@ -12,6 +12,7 @@ export const Commands = {
12
12
  getDataDir: PlatformPaths.getDataDir,
13
13
  getDate: Platform.getDate,
14
14
  getRoot: PlatformPaths.getRoot,
15
+ getRootUri: PlatformPaths.getRootUri,
15
16
  getDisabledExtensionsPath: PlatformPaths.getDisabledExtensionsPath,
16
17
  getDownloadDir: PlatformPaths.getDownloadDir,
17
18
  getExtensionsPath: PlatformPaths.getExtensionsPath,
@@ -41,9 +41,9 @@ export const getAppImageName = () => {
41
41
  export const getSetupName = () => {
42
42
  return 'Lvce-Setup';
43
43
  };
44
- export const version = '0.45.9';
45
- export const commit = '06fb1fd';
46
- export const date = '2025-02-01T09:39:12.000Z';
44
+ export const version = '0.45.10';
45
+ export const commit = 'b53ee00';
46
+ export const date = '2025-02-05T18:37:35.000Z';
47
47
  export const getVersion = () => {
48
48
  return version;
49
49
  };
@@ -107,6 +107,12 @@ export const getDownloadDir = () => {
107
107
  export const getRepository = () => {
108
108
  return `lvce-editor/lvce-editor`;
109
109
  };
110
+ /**
111
+ * @deprecated use getRootUri instead
112
+ */
110
113
  export const getRoot = () => {
111
114
  return Root.root;
112
115
  };
116
+ export const getRootUri = () => {
117
+ return pathToFileURL(Root.root).toString();
118
+ };