@lvce-editor/file-watcher-process 3.5.0 → 4.0.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.
- package/dist/index.js +291 -231
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,11 +1,84 @@
|
|
|
1
1
|
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
2
2
|
import * as fs from 'node:fs/promises';
|
|
3
|
-
import {
|
|
3
|
+
import { FSWatcher } from 'chokidar';
|
|
4
4
|
|
|
5
5
|
const handleUncaughtExceptionMonitor = error => {
|
|
6
6
|
console.error(`[file-watcher-process] Uncaught Exception: ${error}`);
|
|
7
7
|
};
|
|
8
8
|
|
|
9
|
+
class AssertionError extends Error {
|
|
10
|
+
constructor(message) {
|
|
11
|
+
super(message);
|
|
12
|
+
this.name = 'AssertionError';
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
const Object$1 = 1;
|
|
16
|
+
const Number = 2;
|
|
17
|
+
const Array$1 = 3;
|
|
18
|
+
const String = 4;
|
|
19
|
+
const Boolean = 5;
|
|
20
|
+
const Function = 6;
|
|
21
|
+
const Null = 7;
|
|
22
|
+
const Unknown = 8;
|
|
23
|
+
const getType = value => {
|
|
24
|
+
switch (typeof value) {
|
|
25
|
+
case 'number':
|
|
26
|
+
return Number;
|
|
27
|
+
case 'function':
|
|
28
|
+
return Function;
|
|
29
|
+
case 'string':
|
|
30
|
+
return String;
|
|
31
|
+
case 'object':
|
|
32
|
+
if (value === null) {
|
|
33
|
+
return Null;
|
|
34
|
+
}
|
|
35
|
+
if (Array.isArray(value)) {
|
|
36
|
+
return Array$1;
|
|
37
|
+
}
|
|
38
|
+
return Object$1;
|
|
39
|
+
case 'boolean':
|
|
40
|
+
return Boolean;
|
|
41
|
+
default:
|
|
42
|
+
return Unknown;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
const number = value => {
|
|
46
|
+
const type = getType(value);
|
|
47
|
+
if (type !== Number) {
|
|
48
|
+
throw new AssertionError('expected value to be of type number');
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
const string = value => {
|
|
52
|
+
const type = getType(value);
|
|
53
|
+
if (type !== String) {
|
|
54
|
+
throw new AssertionError('expected value to be of type string');
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const watchers = Object.create(null);
|
|
59
|
+
const add = (id, controller) => {
|
|
60
|
+
watchers[id] = controller;
|
|
61
|
+
};
|
|
62
|
+
const get$2 = id => {
|
|
63
|
+
return watchers[id];
|
|
64
|
+
};
|
|
65
|
+
const has = id => {
|
|
66
|
+
return id in watchers;
|
|
67
|
+
};
|
|
68
|
+
const remove$1 = id => {
|
|
69
|
+
delete watchers[id];
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const disposeWatcher = id => {
|
|
73
|
+
number(id);
|
|
74
|
+
if (!has(id)) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const controller = get$2(id);
|
|
78
|
+
controller.abort();
|
|
79
|
+
remove$1(id);
|
|
80
|
+
};
|
|
81
|
+
|
|
9
82
|
const normalizeLine = line => {
|
|
10
83
|
if (line.startsWith('Error: ')) {
|
|
11
84
|
return line.slice('Error: '.length);
|
|
@@ -62,55 +135,6 @@ class VError extends Error {
|
|
|
62
135
|
}
|
|
63
136
|
}
|
|
64
137
|
|
|
65
|
-
class AssertionError extends Error {
|
|
66
|
-
constructor(message) {
|
|
67
|
-
super(message);
|
|
68
|
-
this.name = 'AssertionError';
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
const Object$1 = 1;
|
|
72
|
-
const Number = 2;
|
|
73
|
-
const Array$1 = 3;
|
|
74
|
-
const String = 4;
|
|
75
|
-
const Boolean = 5;
|
|
76
|
-
const Function = 6;
|
|
77
|
-
const Null = 7;
|
|
78
|
-
const Unknown = 8;
|
|
79
|
-
const getType = value => {
|
|
80
|
-
switch (typeof value) {
|
|
81
|
-
case 'number':
|
|
82
|
-
return Number;
|
|
83
|
-
case 'function':
|
|
84
|
-
return Function;
|
|
85
|
-
case 'string':
|
|
86
|
-
return String;
|
|
87
|
-
case 'object':
|
|
88
|
-
if (value === null) {
|
|
89
|
-
return Null;
|
|
90
|
-
}
|
|
91
|
-
if (Array.isArray(value)) {
|
|
92
|
-
return Array$1;
|
|
93
|
-
}
|
|
94
|
-
return Object$1;
|
|
95
|
-
case 'boolean':
|
|
96
|
-
return Boolean;
|
|
97
|
-
default:
|
|
98
|
-
return Unknown;
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
const number = value => {
|
|
102
|
-
const type = getType(value);
|
|
103
|
-
if (type !== Number) {
|
|
104
|
-
throw new AssertionError('expected value to be of type number');
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
const string = value => {
|
|
108
|
-
const type = getType(value);
|
|
109
|
-
if (type !== String) {
|
|
110
|
-
throw new AssertionError('expected value to be of type string');
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
|
|
114
138
|
const isMessagePort = value => {
|
|
115
139
|
return value && value instanceof MessagePort;
|
|
116
140
|
};
|
|
@@ -288,8 +312,8 @@ const getModuleNotFoundError = stderr => {
|
|
|
288
312
|
const messageIndex = lines.findIndex(isModuleNotFoundMessage);
|
|
289
313
|
const message = lines[messageIndex];
|
|
290
314
|
return {
|
|
291
|
-
|
|
292
|
-
|
|
315
|
+
code: ERR_MODULE_NOT_FOUND,
|
|
316
|
+
message
|
|
293
317
|
};
|
|
294
318
|
};
|
|
295
319
|
const isModuleNotFoundError = stderr => {
|
|
@@ -312,14 +336,14 @@ const isUnhelpfulNativeModuleError = stderr => {
|
|
|
312
336
|
const getNativeModuleErrorMessage = stderr => {
|
|
313
337
|
const message = getMessageCodeBlock(stderr);
|
|
314
338
|
return {
|
|
315
|
-
|
|
316
|
-
|
|
339
|
+
code: E_INCOMPATIBLE_NATIVE_MODULE,
|
|
340
|
+
message: `Incompatible native node module: ${message}`
|
|
317
341
|
};
|
|
318
342
|
};
|
|
319
343
|
const getModuleSyntaxError = () => {
|
|
320
344
|
return {
|
|
321
|
-
|
|
322
|
-
|
|
345
|
+
code: E_MODULES_NOT_SUPPORTED_IN_ELECTRON,
|
|
346
|
+
message: `ES Modules are not supported in electron`
|
|
323
347
|
};
|
|
324
348
|
};
|
|
325
349
|
const getHelpfulChildProcessError = (stdout, stderr) => {
|
|
@@ -338,8 +362,8 @@ const getHelpfulChildProcessError = (stdout, stderr) => {
|
|
|
338
362
|
rest
|
|
339
363
|
} = getDetails(lines);
|
|
340
364
|
return {
|
|
341
|
-
message: actualMessage,
|
|
342
365
|
code: '',
|
|
366
|
+
message: actualMessage,
|
|
343
367
|
stack: rest
|
|
344
368
|
};
|
|
345
369
|
};
|
|
@@ -349,8 +373,8 @@ class IpcError extends VError {
|
|
|
349
373
|
if (stdout || stderr) {
|
|
350
374
|
// @ts-ignore
|
|
351
375
|
const {
|
|
352
|
-
message,
|
|
353
376
|
code,
|
|
377
|
+
message,
|
|
354
378
|
stack
|
|
355
379
|
} = getHelpfulChildProcessError(stdout, stderr);
|
|
356
380
|
const cause = new Error(message);
|
|
@@ -433,7 +457,7 @@ const listen$a = () => {
|
|
|
433
457
|
parentPort
|
|
434
458
|
} = process;
|
|
435
459
|
if (!parentPort) {
|
|
436
|
-
throw new
|
|
460
|
+
throw new IpcError('parent port must be defined');
|
|
437
461
|
}
|
|
438
462
|
return parentPort;
|
|
439
463
|
};
|
|
@@ -491,7 +515,7 @@ const getTransferrablesNode = value => {
|
|
|
491
515
|
};
|
|
492
516
|
const listen$5 = async () => {
|
|
493
517
|
if (!process.send) {
|
|
494
|
-
throw new
|
|
518
|
+
throw new IpcError('process.send must be defined');
|
|
495
519
|
}
|
|
496
520
|
return process;
|
|
497
521
|
};
|
|
@@ -571,56 +595,35 @@ const IpcChildWithNodeWorker$1 = {
|
|
|
571
595
|
wrap: wrap$b
|
|
572
596
|
};
|
|
573
597
|
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
598
|
+
class CommandNotFoundError extends Error {
|
|
599
|
+
constructor(command) {
|
|
600
|
+
super(`Command not found ${command}`);
|
|
601
|
+
this.name = 'CommandNotFoundError';
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
const commands = Object.create(null);
|
|
605
|
+
const register = commandMap => {
|
|
606
|
+
Object.assign(commands, commandMap);
|
|
581
607
|
};
|
|
582
|
-
const
|
|
583
|
-
|
|
584
|
-
callbacks[id] = fn;
|
|
608
|
+
const getCommand = key => {
|
|
609
|
+
return commands[key];
|
|
585
610
|
};
|
|
611
|
+
const execute = (command, ...args) => {
|
|
612
|
+
const fn = getCommand(command);
|
|
613
|
+
if (!fn) {
|
|
614
|
+
throw new CommandNotFoundError(command);
|
|
615
|
+
}
|
|
616
|
+
return fn(...args);
|
|
617
|
+
};
|
|
618
|
+
|
|
619
|
+
const Two$1 = '2.0';
|
|
620
|
+
const callbacks = Object.create(null);
|
|
586
621
|
const get$1 = id => {
|
|
587
622
|
return callbacks[id];
|
|
588
623
|
};
|
|
589
624
|
const remove = id => {
|
|
590
625
|
delete callbacks[id];
|
|
591
626
|
};
|
|
592
|
-
let id = 0;
|
|
593
|
-
const create$3 = () => {
|
|
594
|
-
return ++id;
|
|
595
|
-
};
|
|
596
|
-
const registerPromise = () => {
|
|
597
|
-
const id = create$3();
|
|
598
|
-
const {
|
|
599
|
-
resolve,
|
|
600
|
-
promise
|
|
601
|
-
} = Promise.withResolvers();
|
|
602
|
-
set(id, resolve);
|
|
603
|
-
return {
|
|
604
|
-
id,
|
|
605
|
-
promise
|
|
606
|
-
};
|
|
607
|
-
};
|
|
608
|
-
const create$2 = (method, params) => {
|
|
609
|
-
const {
|
|
610
|
-
id,
|
|
611
|
-
promise
|
|
612
|
-
} = registerPromise();
|
|
613
|
-
const message = {
|
|
614
|
-
jsonrpc: Two,
|
|
615
|
-
method,
|
|
616
|
-
params,
|
|
617
|
-
id
|
|
618
|
-
};
|
|
619
|
-
return {
|
|
620
|
-
message,
|
|
621
|
-
promise
|
|
622
|
-
};
|
|
623
|
-
};
|
|
624
627
|
class JsonRpcError extends Error {
|
|
625
628
|
constructor(message) {
|
|
626
629
|
super(message);
|
|
@@ -637,12 +640,12 @@ const getErrorConstructor = (message, type) => {
|
|
|
637
640
|
switch (type) {
|
|
638
641
|
case DomException:
|
|
639
642
|
return DOMException;
|
|
640
|
-
case TypeError$1:
|
|
641
|
-
return TypeError;
|
|
642
|
-
case SyntaxError$1:
|
|
643
|
-
return SyntaxError;
|
|
644
643
|
case ReferenceError$1:
|
|
645
644
|
return ReferenceError;
|
|
645
|
+
case SyntaxError$1:
|
|
646
|
+
return SyntaxError;
|
|
647
|
+
case TypeError$1:
|
|
648
|
+
return TypeError;
|
|
646
649
|
default:
|
|
647
650
|
return Error;
|
|
648
651
|
}
|
|
@@ -679,7 +682,8 @@ const splitLines = lines => {
|
|
|
679
682
|
return lines.split(NewLine);
|
|
680
683
|
};
|
|
681
684
|
const getCurrentStack = () => {
|
|
682
|
-
const
|
|
685
|
+
const stackLinesToSkip = 3;
|
|
686
|
+
const currentStack = joinLines(splitLines(new Error().stack || '').slice(stackLinesToSkip));
|
|
683
687
|
return currentStack;
|
|
684
688
|
};
|
|
685
689
|
const getNewLineIndex = (string, startIndex = undefined) => {
|
|
@@ -797,56 +801,56 @@ const getErrorProperty = (error, prettyError) => {
|
|
|
797
801
|
if (error && error.code === E_COMMAND_NOT_FOUND) {
|
|
798
802
|
return {
|
|
799
803
|
code: MethodNotFound,
|
|
800
|
-
|
|
801
|
-
|
|
804
|
+
data: error.stack,
|
|
805
|
+
message: error.message
|
|
802
806
|
};
|
|
803
807
|
}
|
|
804
808
|
return {
|
|
805
809
|
code: Custom,
|
|
806
|
-
message: prettyError.message,
|
|
807
810
|
data: {
|
|
808
|
-
stack: getStack(prettyError),
|
|
809
|
-
codeFrame: prettyError.codeFrame,
|
|
810
|
-
type: getErrorType(prettyError),
|
|
811
811
|
code: prettyError.code,
|
|
812
|
-
|
|
813
|
-
|
|
812
|
+
codeFrame: prettyError.codeFrame,
|
|
813
|
+
name: prettyError.name,
|
|
814
|
+
stack: getStack(prettyError),
|
|
815
|
+
type: getErrorType(prettyError)
|
|
816
|
+
},
|
|
817
|
+
message: prettyError.message
|
|
814
818
|
};
|
|
815
819
|
};
|
|
816
|
-
const create$1 = (id, error) => {
|
|
820
|
+
const create$1$1 = (id, error) => {
|
|
817
821
|
return {
|
|
818
|
-
|
|
822
|
+
error,
|
|
819
823
|
id,
|
|
820
|
-
|
|
824
|
+
jsonrpc: Two$1
|
|
821
825
|
};
|
|
822
826
|
};
|
|
823
827
|
const getErrorResponse = (id, error, preparePrettyError, logError) => {
|
|
824
828
|
const prettyError = preparePrettyError(error);
|
|
825
829
|
logError(error, prettyError);
|
|
826
830
|
const errorProperty = getErrorProperty(error, prettyError);
|
|
827
|
-
return create$1(id, errorProperty);
|
|
831
|
+
return create$1$1(id, errorProperty);
|
|
828
832
|
};
|
|
829
|
-
const create = (message, result) => {
|
|
833
|
+
const create$7 = (message, result) => {
|
|
830
834
|
return {
|
|
831
|
-
jsonrpc: Two,
|
|
832
835
|
id: message.id,
|
|
836
|
+
jsonrpc: Two$1,
|
|
833
837
|
result: result ?? null
|
|
834
838
|
};
|
|
835
839
|
};
|
|
836
840
|
const getSuccessResponse = (message, result) => {
|
|
837
841
|
const resultProperty = result ?? null;
|
|
838
|
-
return create(message, resultProperty);
|
|
842
|
+
return create$7(message, resultProperty);
|
|
839
843
|
};
|
|
840
844
|
const getErrorResponseSimple = (id, error) => {
|
|
841
845
|
return {
|
|
842
|
-
jsonrpc: Two,
|
|
843
|
-
id,
|
|
844
846
|
error: {
|
|
845
847
|
code: Custom,
|
|
848
|
+
data: error,
|
|
846
849
|
// @ts-ignore
|
|
847
|
-
message: error.message
|
|
848
|
-
|
|
849
|
-
|
|
850
|
+
message: error.message
|
|
851
|
+
},
|
|
852
|
+
id,
|
|
853
|
+
jsonrpc: Two$1
|
|
850
854
|
};
|
|
851
855
|
};
|
|
852
856
|
const getResponse = async (message, ipc, execute, preparePrettyError, logError, requiresSocket) => {
|
|
@@ -876,35 +880,35 @@ const normalizeParams = args => {
|
|
|
876
880
|
if (args.length === 1) {
|
|
877
881
|
const options = args[0];
|
|
878
882
|
return {
|
|
883
|
+
execute: options.execute,
|
|
879
884
|
ipc: options.ipc,
|
|
885
|
+
logError: options.logError || defaultLogError,
|
|
880
886
|
message: options.message,
|
|
881
|
-
execute: options.execute,
|
|
882
|
-
resolve: options.resolve || defaultResolve,
|
|
883
887
|
preparePrettyError: options.preparePrettyError || defaultPreparePrettyError,
|
|
884
|
-
|
|
885
|
-
|
|
888
|
+
requiresSocket: options.requiresSocket || defaultRequiresSocket,
|
|
889
|
+
resolve: options.resolve || defaultResolve
|
|
886
890
|
};
|
|
887
891
|
}
|
|
888
892
|
return {
|
|
893
|
+
execute: args[2],
|
|
889
894
|
ipc: args[0],
|
|
895
|
+
logError: args[5],
|
|
890
896
|
message: args[1],
|
|
891
|
-
execute: args[2],
|
|
892
|
-
resolve: args[3],
|
|
893
897
|
preparePrettyError: args[4],
|
|
894
|
-
|
|
895
|
-
|
|
898
|
+
requiresSocket: args[6],
|
|
899
|
+
resolve: args[3]
|
|
896
900
|
};
|
|
897
901
|
};
|
|
898
902
|
const handleJsonRpcMessage = async (...args) => {
|
|
899
903
|
const options = normalizeParams(args);
|
|
900
904
|
const {
|
|
901
|
-
message,
|
|
902
|
-
ipc,
|
|
903
905
|
execute,
|
|
904
|
-
|
|
905
|
-
preparePrettyError,
|
|
906
|
+
ipc,
|
|
906
907
|
logError,
|
|
907
|
-
|
|
908
|
+
message,
|
|
909
|
+
preparePrettyError,
|
|
910
|
+
requiresSocket,
|
|
911
|
+
resolve
|
|
908
912
|
} = options;
|
|
909
913
|
if ('id' in message) {
|
|
910
914
|
if ('method' in message) {
|
|
@@ -926,11 +930,51 @@ const handleJsonRpcMessage = async (...args) => {
|
|
|
926
930
|
}
|
|
927
931
|
throw new JsonRpcError('unexpected message');
|
|
928
932
|
};
|
|
929
|
-
|
|
933
|
+
|
|
934
|
+
const Two = '2.0';
|
|
935
|
+
|
|
936
|
+
const create$6 = (method, params) => {
|
|
937
|
+
return {
|
|
938
|
+
jsonrpc: Two,
|
|
939
|
+
method,
|
|
940
|
+
params
|
|
941
|
+
};
|
|
942
|
+
};
|
|
943
|
+
|
|
944
|
+
const create$5 = (id, method, params) => {
|
|
945
|
+
const message = {
|
|
946
|
+
id,
|
|
947
|
+
jsonrpc: Two,
|
|
948
|
+
method,
|
|
949
|
+
params
|
|
950
|
+
};
|
|
951
|
+
return message;
|
|
952
|
+
};
|
|
953
|
+
|
|
954
|
+
let id = 0;
|
|
955
|
+
const create$4 = () => {
|
|
956
|
+
return ++id;
|
|
957
|
+
};
|
|
958
|
+
|
|
959
|
+
const registerPromise = map => {
|
|
960
|
+
const id = create$4();
|
|
930
961
|
const {
|
|
931
|
-
|
|
962
|
+
promise,
|
|
963
|
+
resolve
|
|
964
|
+
} = Promise.withResolvers();
|
|
965
|
+
map[id] = resolve;
|
|
966
|
+
return {
|
|
967
|
+
id,
|
|
932
968
|
promise
|
|
933
|
-
}
|
|
969
|
+
};
|
|
970
|
+
};
|
|
971
|
+
|
|
972
|
+
const invokeHelper = async (callbacks, ipc, method, params, useSendAndTransfer) => {
|
|
973
|
+
const {
|
|
974
|
+
id,
|
|
975
|
+
promise
|
|
976
|
+
} = registerPromise(callbacks);
|
|
977
|
+
const message = create$5(id, method, params);
|
|
934
978
|
if (useSendAndTransfer && ipc.sendAndTransfer) {
|
|
935
979
|
ipc.sendAndTransfer(message);
|
|
936
980
|
} else {
|
|
@@ -939,54 +983,40 @@ const invokeHelper = async (ipc, method, params, useSendAndTransfer) => {
|
|
|
939
983
|
const responseMessage = await promise;
|
|
940
984
|
return unwrapJsonRpcResult(responseMessage);
|
|
941
985
|
};
|
|
942
|
-
const send = (transport, method, ...params) => {
|
|
943
|
-
const message = create$4(method, params);
|
|
944
|
-
transport.send(message);
|
|
945
|
-
};
|
|
946
|
-
const invoke$1 = (ipc, method, ...params) => {
|
|
947
|
-
return invokeHelper(ipc, method, params, false);
|
|
948
|
-
};
|
|
949
|
-
const invokeAndTransfer = (ipc, method, ...params) => {
|
|
950
|
-
return invokeHelper(ipc, method, params, true);
|
|
951
|
-
};
|
|
952
|
-
|
|
953
|
-
const commands = Object.create(null);
|
|
954
|
-
const register = commandMap => {
|
|
955
|
-
Object.assign(commands, commandMap);
|
|
956
|
-
};
|
|
957
|
-
const getCommand = key => {
|
|
958
|
-
return commands[key];
|
|
959
|
-
};
|
|
960
|
-
const execute = (command, ...args) => {
|
|
961
|
-
const fn = getCommand(command);
|
|
962
|
-
if (!fn) {
|
|
963
|
-
throw new Error(`command not found ${command}`);
|
|
964
|
-
}
|
|
965
|
-
return fn(...args);
|
|
966
|
-
};
|
|
967
|
-
|
|
968
986
|
const createRpc = ipc => {
|
|
987
|
+
const callbacks = Object.create(null);
|
|
988
|
+
ipc._resolve = (id, response) => {
|
|
989
|
+
const fn = callbacks[id];
|
|
990
|
+
if (!fn) {
|
|
991
|
+
console.warn(`callback ${id} may already be disposed`);
|
|
992
|
+
return;
|
|
993
|
+
}
|
|
994
|
+
fn(response);
|
|
995
|
+
delete callbacks[id];
|
|
996
|
+
};
|
|
969
997
|
const rpc = {
|
|
998
|
+
async dispose() {
|
|
999
|
+
await ipc?.dispose();
|
|
1000
|
+
},
|
|
1001
|
+
invoke(method, ...params) {
|
|
1002
|
+
return invokeHelper(callbacks, ipc, method, params, false);
|
|
1003
|
+
},
|
|
1004
|
+
invokeAndTransfer(method, ...params) {
|
|
1005
|
+
return invokeHelper(callbacks, ipc, method, params, true);
|
|
1006
|
+
},
|
|
970
1007
|
// @ts-ignore
|
|
971
1008
|
ipc,
|
|
972
1009
|
/**
|
|
973
1010
|
* @deprecated
|
|
974
1011
|
*/
|
|
975
1012
|
send(method, ...params) {
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
invoke(method, ...params) {
|
|
979
|
-
return invoke$1(ipc, method, ...params);
|
|
980
|
-
},
|
|
981
|
-
invokeAndTransfer(method, ...params) {
|
|
982
|
-
return invokeAndTransfer(ipc, method, ...params);
|
|
983
|
-
},
|
|
984
|
-
async dispose() {
|
|
985
|
-
await ipc?.dispose();
|
|
1013
|
+
const message = create$6(method, params);
|
|
1014
|
+
ipc.send(message);
|
|
986
1015
|
}
|
|
987
1016
|
};
|
|
988
1017
|
return rpc;
|
|
989
1018
|
};
|
|
1019
|
+
|
|
990
1020
|
const requiresSocket = () => {
|
|
991
1021
|
return false;
|
|
992
1022
|
};
|
|
@@ -999,8 +1029,9 @@ const logError = () => {
|
|
|
999
1029
|
const handleMessage = event => {
|
|
1000
1030
|
const actualRequiresSocket = event?.target?.requiresSocket || requiresSocket;
|
|
1001
1031
|
const actualExecute = event?.target?.execute || execute;
|
|
1002
|
-
return handleJsonRpcMessage(event.target, event.data, actualExecute,
|
|
1032
|
+
return handleJsonRpcMessage(event.target, event.data, actualExecute, event.target._resolve, preparePrettyError, logError, actualRequiresSocket);
|
|
1003
1033
|
};
|
|
1034
|
+
|
|
1004
1035
|
const handleIpc = ipc => {
|
|
1005
1036
|
if ('addEventListener' in ipc) {
|
|
1006
1037
|
ipc.addEventListener('message', handleMessage);
|
|
@@ -1009,6 +1040,7 @@ const handleIpc = ipc => {
|
|
|
1009
1040
|
ipc.on('message', handleMessage);
|
|
1010
1041
|
}
|
|
1011
1042
|
};
|
|
1043
|
+
|
|
1012
1044
|
const listen$2 = async (module, options) => {
|
|
1013
1045
|
const rawIpc = await module.listen(options);
|
|
1014
1046
|
if (module.signal) {
|
|
@@ -1017,7 +1049,8 @@ const listen$2 = async (module, options) => {
|
|
|
1017
1049
|
const ipc = module.wrap(rawIpc);
|
|
1018
1050
|
return ipc;
|
|
1019
1051
|
};
|
|
1020
|
-
|
|
1052
|
+
|
|
1053
|
+
const create$3 = async ({
|
|
1021
1054
|
commandMap,
|
|
1022
1055
|
messagePort,
|
|
1023
1056
|
requiresSocket
|
|
@@ -1034,11 +1067,8 @@ const create$j = async ({
|
|
|
1034
1067
|
const rpc = createRpc(ipc);
|
|
1035
1068
|
return rpc;
|
|
1036
1069
|
};
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
create: create$j
|
|
1040
|
-
};
|
|
1041
|
-
const create$i = async ({
|
|
1070
|
+
|
|
1071
|
+
const create$2 = async ({
|
|
1042
1072
|
commandMap
|
|
1043
1073
|
}) => {
|
|
1044
1074
|
// TODO create a commandMap per rpc instance
|
|
@@ -1048,11 +1078,8 @@ const create$i = async ({
|
|
|
1048
1078
|
const rpc = createRpc(ipc);
|
|
1049
1079
|
return rpc;
|
|
1050
1080
|
};
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
create: create$i
|
|
1054
|
-
};
|
|
1055
|
-
const create$9 = async ({
|
|
1081
|
+
|
|
1082
|
+
const create$1 = async ({
|
|
1056
1083
|
commandMap
|
|
1057
1084
|
}) => {
|
|
1058
1085
|
// TODO create a commandMap per rpc instance
|
|
@@ -1062,11 +1089,8 @@ const create$9 = async ({
|
|
|
1062
1089
|
const rpc = createRpc(ipc);
|
|
1063
1090
|
return rpc;
|
|
1064
1091
|
};
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
create: create$9
|
|
1068
|
-
};
|
|
1069
|
-
const create$6 = async ({
|
|
1092
|
+
|
|
1093
|
+
const create = async ({
|
|
1070
1094
|
commandMap
|
|
1071
1095
|
}) => {
|
|
1072
1096
|
// TODO create a commandMap per rpc instance
|
|
@@ -1076,10 +1100,6 @@ const create$6 = async ({
|
|
|
1076
1100
|
const rpc = createRpc(ipc);
|
|
1077
1101
|
return rpc;
|
|
1078
1102
|
};
|
|
1079
|
-
const NodeWorkerRpcClient = {
|
|
1080
|
-
__proto__: null,
|
|
1081
|
-
create: create$6
|
|
1082
|
-
};
|
|
1083
1103
|
|
|
1084
1104
|
const NodeWorker = 1;
|
|
1085
1105
|
const NodeForkedProcess = 2;
|
|
@@ -1103,14 +1123,14 @@ const Auto = () => {
|
|
|
1103
1123
|
|
|
1104
1124
|
const getModule = method => {
|
|
1105
1125
|
switch (method) {
|
|
1126
|
+
case ElectronMessagePort:
|
|
1127
|
+
return create$3;
|
|
1128
|
+
case ElectronUtilityProcess:
|
|
1129
|
+
return create$2;
|
|
1106
1130
|
case NodeForkedProcess:
|
|
1107
|
-
return
|
|
1131
|
+
return create$1;
|
|
1108
1132
|
case NodeWorker:
|
|
1109
|
-
return
|
|
1110
|
-
case ElectronUtilityProcess:
|
|
1111
|
-
return ElectronUtilityProcessRpcClient.create;
|
|
1112
|
-
case ElectronMessagePort:
|
|
1113
|
-
return ElectronMessagePortRpcClient.create;
|
|
1133
|
+
return create;
|
|
1114
1134
|
default:
|
|
1115
1135
|
throw new Error('unexpected ipc type');
|
|
1116
1136
|
}
|
|
@@ -1129,15 +1149,15 @@ const listen$1 = async ({
|
|
|
1129
1149
|
|
|
1130
1150
|
const handleElectronMessagePort = async messagePort => {
|
|
1131
1151
|
await listen$1({
|
|
1132
|
-
|
|
1133
|
-
|
|
1152
|
+
messagePort,
|
|
1153
|
+
method: ElectronMessagePort
|
|
1134
1154
|
});
|
|
1135
1155
|
};
|
|
1136
1156
|
|
|
1137
1157
|
const SharedProcess = 1;
|
|
1138
1158
|
|
|
1139
1159
|
const rpcs = Object.create(null);
|
|
1140
|
-
const set
|
|
1160
|
+
const set = (id, rpc) => {
|
|
1141
1161
|
rpcs[id] = rpc;
|
|
1142
1162
|
};
|
|
1143
1163
|
const get = id => {
|
|
@@ -1156,7 +1176,8 @@ const watchInternal = async (path, options, callback) => {
|
|
|
1156
1176
|
await callback(event);
|
|
1157
1177
|
}
|
|
1158
1178
|
} catch (error) {
|
|
1159
|
-
|
|
1179
|
+
const message = new VError(error, 'Failed to watch');
|
|
1180
|
+
console.error(`[file-watcher-process] ${message}`);
|
|
1160
1181
|
}
|
|
1161
1182
|
};
|
|
1162
1183
|
|
|
@@ -1176,6 +1197,8 @@ const watchFile2 = async (id, uri) => {
|
|
|
1176
1197
|
});
|
|
1177
1198
|
};
|
|
1178
1199
|
const path = fileURLToPath(uri);
|
|
1200
|
+
const controller = new AbortController();
|
|
1201
|
+
add(id, controller);
|
|
1179
1202
|
await watchInternal(path, {}, callback);
|
|
1180
1203
|
};
|
|
1181
1204
|
|
|
@@ -1189,10 +1212,24 @@ const normalizeEvent = (eventName, path) => {
|
|
|
1189
1212
|
|
|
1190
1213
|
const waitForWatcherToBeReady = async watcher => {
|
|
1191
1214
|
const {
|
|
1192
|
-
|
|
1193
|
-
|
|
1215
|
+
promise,
|
|
1216
|
+
reject,
|
|
1217
|
+
resolve
|
|
1194
1218
|
} = Promise.withResolvers();
|
|
1195
|
-
|
|
1219
|
+
const cleanup = () => {
|
|
1220
|
+
watcher.off('ready', handleReady);
|
|
1221
|
+
watcher.off('error', handleError);
|
|
1222
|
+
};
|
|
1223
|
+
const handleReady = () => {
|
|
1224
|
+
cleanup();
|
|
1225
|
+
resolve();
|
|
1226
|
+
};
|
|
1227
|
+
const handleError = error => {
|
|
1228
|
+
cleanup();
|
|
1229
|
+
reject(error);
|
|
1230
|
+
};
|
|
1231
|
+
watcher.on('ready', handleReady);
|
|
1232
|
+
watcher.on('error', handleError);
|
|
1196
1233
|
await promise;
|
|
1197
1234
|
};
|
|
1198
1235
|
|
|
@@ -1203,30 +1240,35 @@ const callBackInternal = async (eventName, path, stats) => {
|
|
|
1203
1240
|
const callback = (eventName, path, stats) => {
|
|
1204
1241
|
void callBackInternal(eventName, path);
|
|
1205
1242
|
};
|
|
1206
|
-
const errorCallback = error => {
|
|
1243
|
+
const errorCallback$1 = error => {
|
|
1207
1244
|
console.error(`[file-watcher-process] ${error}`);
|
|
1208
1245
|
};
|
|
1209
1246
|
const watchFolder = async uri => {
|
|
1210
1247
|
const path = fileURLToPath(uri);
|
|
1211
|
-
const watcher =
|
|
1248
|
+
const watcher = new FSWatcher();
|
|
1212
1249
|
watcher.on('all', callback);
|
|
1213
|
-
watcher.on('error', errorCallback);
|
|
1214
|
-
|
|
1250
|
+
watcher.on('error', errorCallback$1);
|
|
1251
|
+
const readyPromise = waitForWatcherToBeReady(watcher);
|
|
1252
|
+
watcher.add(path);
|
|
1253
|
+
await readyPromise;
|
|
1215
1254
|
};
|
|
1216
1255
|
|
|
1217
1256
|
const normalizeEvent2 = (id, eventName, path) => {
|
|
1218
1257
|
const uri = pathToFileURL(path).toString();
|
|
1219
1258
|
return {
|
|
1220
1259
|
eventName,
|
|
1221
|
-
|
|
1222
|
-
|
|
1260
|
+
id,
|
|
1261
|
+
uri
|
|
1223
1262
|
};
|
|
1224
1263
|
};
|
|
1225
1264
|
|
|
1265
|
+
const errorCallback = error => {
|
|
1266
|
+
console.error(`[file-watcher-process] ${error}`);
|
|
1267
|
+
};
|
|
1226
1268
|
const watchFolders = async ({
|
|
1227
|
-
|
|
1269
|
+
exclude,
|
|
1228
1270
|
id,
|
|
1229
|
-
|
|
1271
|
+
roots
|
|
1230
1272
|
}) => {
|
|
1231
1273
|
const callBackInternal = async (eventName, path, stats) => {
|
|
1232
1274
|
const event = normalizeEvent2(id, eventName, path);
|
|
@@ -1240,34 +1282,52 @@ const watchFolders = async ({
|
|
|
1240
1282
|
const callback = (eventName, path, stats) => {
|
|
1241
1283
|
void callBackInternal(eventName, path);
|
|
1242
1284
|
};
|
|
1243
|
-
const
|
|
1285
|
+
const watcherEntries = roots.map(root => {
|
|
1244
1286
|
const path = fileURLToPath(root);
|
|
1245
|
-
const watcher =
|
|
1287
|
+
const watcher = new FSWatcher({
|
|
1246
1288
|
ignoreInitial: true,
|
|
1247
1289
|
ignorePermissionErrors: true
|
|
1248
1290
|
});
|
|
1249
|
-
|
|
1291
|
+
watcher.on('error', errorCallback);
|
|
1292
|
+
const readyPromise = waitForWatcherToBeReady(watcher);
|
|
1293
|
+
watcher.add(path);
|
|
1294
|
+
return {
|
|
1295
|
+
readyPromise,
|
|
1296
|
+
watcher
|
|
1297
|
+
};
|
|
1250
1298
|
});
|
|
1251
|
-
|
|
1252
|
-
|
|
1299
|
+
try {
|
|
1300
|
+
await Promise.all(watcherEntries.map(({
|
|
1301
|
+
readyPromise
|
|
1302
|
+
}) => readyPromise));
|
|
1303
|
+
} catch (error) {
|
|
1304
|
+
await Promise.allSettled(watcherEntries.map(({
|
|
1305
|
+
watcher
|
|
1306
|
+
}) => watcher.close()));
|
|
1307
|
+
throw error;
|
|
1308
|
+
}
|
|
1309
|
+
for (const {
|
|
1310
|
+
watcher
|
|
1311
|
+
} of watcherEntries) {
|
|
1253
1312
|
watcher.on('all', callback);
|
|
1254
1313
|
}
|
|
1255
1314
|
};
|
|
1256
1315
|
|
|
1257
1316
|
const commandMap = {
|
|
1258
|
-
'
|
|
1317
|
+
'FileWatcher.dispose': disposeWatcher,
|
|
1259
1318
|
'FileWatcher.watchFile': watchFile,
|
|
1260
1319
|
'FileWatcher.watchFile2': watchFile2,
|
|
1261
1320
|
'FileWatcher.watchFolder': watchFolder,
|
|
1262
|
-
'FileWatcher.watchFolders': watchFolders
|
|
1321
|
+
'FileWatcher.watchFolders': watchFolders,
|
|
1322
|
+
'HandleElectronMessagePort.handleElectronMessagePort': handleElectronMessagePort
|
|
1263
1323
|
};
|
|
1264
1324
|
|
|
1265
1325
|
const listen = async () => {
|
|
1266
1326
|
const rpc = await listen$1({
|
|
1267
|
-
|
|
1268
|
-
|
|
1327
|
+
commandMap: commandMap,
|
|
1328
|
+
method: Auto()
|
|
1269
1329
|
});
|
|
1270
|
-
set
|
|
1330
|
+
set(SharedProcess, rpc);
|
|
1271
1331
|
};
|
|
1272
1332
|
|
|
1273
1333
|
const main = async () => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lvce-editor/file-watcher-process",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "File Watcher Process",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Lvce Editor",
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
"file-watcher-process": "bin/fileWatcherProcess.js"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@lvce-editor/assert": "^1.
|
|
22
|
-
"chokidar": "^
|
|
21
|
+
"@lvce-editor/assert": "^1.5.1",
|
|
22
|
+
"chokidar": "^5.0.0"
|
|
23
23
|
},
|
|
24
24
|
"engines": {
|
|
25
25
|
"node": ">=22"
|