@lvce-editor/file-watcher-process 3.6.0 → 4.1.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 +213 -180
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
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}`);
|
|
@@ -312,8 +312,8 @@ const getModuleNotFoundError = stderr => {
|
|
|
312
312
|
const messageIndex = lines.findIndex(isModuleNotFoundMessage);
|
|
313
313
|
const message = lines[messageIndex];
|
|
314
314
|
return {
|
|
315
|
-
|
|
316
|
-
|
|
315
|
+
code: ERR_MODULE_NOT_FOUND,
|
|
316
|
+
message
|
|
317
317
|
};
|
|
318
318
|
};
|
|
319
319
|
const isModuleNotFoundError = stderr => {
|
|
@@ -336,14 +336,14 @@ const isUnhelpfulNativeModuleError = stderr => {
|
|
|
336
336
|
const getNativeModuleErrorMessage = stderr => {
|
|
337
337
|
const message = getMessageCodeBlock(stderr);
|
|
338
338
|
return {
|
|
339
|
-
|
|
340
|
-
|
|
339
|
+
code: E_INCOMPATIBLE_NATIVE_MODULE,
|
|
340
|
+
message: `Incompatible native node module: ${message}`
|
|
341
341
|
};
|
|
342
342
|
};
|
|
343
343
|
const getModuleSyntaxError = () => {
|
|
344
344
|
return {
|
|
345
|
-
|
|
346
|
-
|
|
345
|
+
code: E_MODULES_NOT_SUPPORTED_IN_ELECTRON,
|
|
346
|
+
message: `ES Modules are not supported in electron`
|
|
347
347
|
};
|
|
348
348
|
};
|
|
349
349
|
const getHelpfulChildProcessError = (stdout, stderr) => {
|
|
@@ -362,8 +362,8 @@ const getHelpfulChildProcessError = (stdout, stderr) => {
|
|
|
362
362
|
rest
|
|
363
363
|
} = getDetails(lines);
|
|
364
364
|
return {
|
|
365
|
-
message: actualMessage,
|
|
366
365
|
code: '',
|
|
366
|
+
message: actualMessage,
|
|
367
367
|
stack: rest
|
|
368
368
|
};
|
|
369
369
|
};
|
|
@@ -373,8 +373,8 @@ class IpcError extends VError {
|
|
|
373
373
|
if (stdout || stderr) {
|
|
374
374
|
// @ts-ignore
|
|
375
375
|
const {
|
|
376
|
-
message,
|
|
377
376
|
code,
|
|
377
|
+
message,
|
|
378
378
|
stack
|
|
379
379
|
} = getHelpfulChildProcessError(stdout, stderr);
|
|
380
380
|
const cause = new Error(message);
|
|
@@ -457,7 +457,7 @@ const listen$a = () => {
|
|
|
457
457
|
parentPort
|
|
458
458
|
} = process;
|
|
459
459
|
if (!parentPort) {
|
|
460
|
-
throw new
|
|
460
|
+
throw new IpcError('parent port must be defined');
|
|
461
461
|
}
|
|
462
462
|
return parentPort;
|
|
463
463
|
};
|
|
@@ -515,7 +515,7 @@ const getTransferrablesNode = value => {
|
|
|
515
515
|
};
|
|
516
516
|
const listen$5 = async () => {
|
|
517
517
|
if (!process.send) {
|
|
518
|
-
throw new
|
|
518
|
+
throw new IpcError('process.send must be defined');
|
|
519
519
|
}
|
|
520
520
|
return process;
|
|
521
521
|
};
|
|
@@ -595,56 +595,35 @@ const IpcChildWithNodeWorker$1 = {
|
|
|
595
595
|
wrap: wrap$b
|
|
596
596
|
};
|
|
597
597
|
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
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);
|
|
605
607
|
};
|
|
606
|
-
const
|
|
607
|
-
|
|
608
|
-
callbacks[id] = fn;
|
|
608
|
+
const getCommand = key => {
|
|
609
|
+
return commands[key];
|
|
609
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);
|
|
610
621
|
const get$1 = id => {
|
|
611
622
|
return callbacks[id];
|
|
612
623
|
};
|
|
613
624
|
const remove = id => {
|
|
614
625
|
delete callbacks[id];
|
|
615
626
|
};
|
|
616
|
-
let id = 0;
|
|
617
|
-
const create$3 = () => {
|
|
618
|
-
return ++id;
|
|
619
|
-
};
|
|
620
|
-
const registerPromise = () => {
|
|
621
|
-
const id = create$3();
|
|
622
|
-
const {
|
|
623
|
-
resolve,
|
|
624
|
-
promise
|
|
625
|
-
} = Promise.withResolvers();
|
|
626
|
-
set(id, resolve);
|
|
627
|
-
return {
|
|
628
|
-
id,
|
|
629
|
-
promise
|
|
630
|
-
};
|
|
631
|
-
};
|
|
632
|
-
const create$2 = (method, params) => {
|
|
633
|
-
const {
|
|
634
|
-
id,
|
|
635
|
-
promise
|
|
636
|
-
} = registerPromise();
|
|
637
|
-
const message = {
|
|
638
|
-
jsonrpc: Two,
|
|
639
|
-
method,
|
|
640
|
-
params,
|
|
641
|
-
id
|
|
642
|
-
};
|
|
643
|
-
return {
|
|
644
|
-
message,
|
|
645
|
-
promise
|
|
646
|
-
};
|
|
647
|
-
};
|
|
648
627
|
class JsonRpcError extends Error {
|
|
649
628
|
constructor(message) {
|
|
650
629
|
super(message);
|
|
@@ -661,12 +640,12 @@ const getErrorConstructor = (message, type) => {
|
|
|
661
640
|
switch (type) {
|
|
662
641
|
case DomException:
|
|
663
642
|
return DOMException;
|
|
664
|
-
case TypeError$1:
|
|
665
|
-
return TypeError;
|
|
666
|
-
case SyntaxError$1:
|
|
667
|
-
return SyntaxError;
|
|
668
643
|
case ReferenceError$1:
|
|
669
644
|
return ReferenceError;
|
|
645
|
+
case SyntaxError$1:
|
|
646
|
+
return SyntaxError;
|
|
647
|
+
case TypeError$1:
|
|
648
|
+
return TypeError;
|
|
670
649
|
default:
|
|
671
650
|
return Error;
|
|
672
651
|
}
|
|
@@ -703,7 +682,8 @@ const splitLines = lines => {
|
|
|
703
682
|
return lines.split(NewLine);
|
|
704
683
|
};
|
|
705
684
|
const getCurrentStack = () => {
|
|
706
|
-
const
|
|
685
|
+
const stackLinesToSkip = 3;
|
|
686
|
+
const currentStack = joinLines(splitLines(new Error().stack || '').slice(stackLinesToSkip));
|
|
707
687
|
return currentStack;
|
|
708
688
|
};
|
|
709
689
|
const getNewLineIndex = (string, startIndex = undefined) => {
|
|
@@ -821,56 +801,56 @@ const getErrorProperty = (error, prettyError) => {
|
|
|
821
801
|
if (error && error.code === E_COMMAND_NOT_FOUND) {
|
|
822
802
|
return {
|
|
823
803
|
code: MethodNotFound,
|
|
824
|
-
|
|
825
|
-
|
|
804
|
+
data: error.stack,
|
|
805
|
+
message: error.message
|
|
826
806
|
};
|
|
827
807
|
}
|
|
828
808
|
return {
|
|
829
809
|
code: Custom,
|
|
830
|
-
message: prettyError.message,
|
|
831
810
|
data: {
|
|
832
|
-
stack: getStack(prettyError),
|
|
833
|
-
codeFrame: prettyError.codeFrame,
|
|
834
|
-
type: getErrorType(prettyError),
|
|
835
811
|
code: prettyError.code,
|
|
836
|
-
|
|
837
|
-
|
|
812
|
+
codeFrame: prettyError.codeFrame,
|
|
813
|
+
name: prettyError.name,
|
|
814
|
+
stack: getStack(prettyError),
|
|
815
|
+
type: getErrorType(prettyError)
|
|
816
|
+
},
|
|
817
|
+
message: prettyError.message
|
|
838
818
|
};
|
|
839
819
|
};
|
|
840
|
-
const create$1 = (id, error) => {
|
|
820
|
+
const create$1$1 = (id, error) => {
|
|
841
821
|
return {
|
|
842
|
-
|
|
822
|
+
error,
|
|
843
823
|
id,
|
|
844
|
-
|
|
824
|
+
jsonrpc: Two$1
|
|
845
825
|
};
|
|
846
826
|
};
|
|
847
827
|
const getErrorResponse = (id, error, preparePrettyError, logError) => {
|
|
848
828
|
const prettyError = preparePrettyError(error);
|
|
849
829
|
logError(error, prettyError);
|
|
850
830
|
const errorProperty = getErrorProperty(error, prettyError);
|
|
851
|
-
return create$1(id, errorProperty);
|
|
831
|
+
return create$1$1(id, errorProperty);
|
|
852
832
|
};
|
|
853
|
-
const create = (message, result) => {
|
|
833
|
+
const create$7 = (message, result) => {
|
|
854
834
|
return {
|
|
855
|
-
jsonrpc: Two,
|
|
856
835
|
id: message.id,
|
|
836
|
+
jsonrpc: Two$1,
|
|
857
837
|
result: result ?? null
|
|
858
838
|
};
|
|
859
839
|
};
|
|
860
840
|
const getSuccessResponse = (message, result) => {
|
|
861
841
|
const resultProperty = result ?? null;
|
|
862
|
-
return create(message, resultProperty);
|
|
842
|
+
return create$7(message, resultProperty);
|
|
863
843
|
};
|
|
864
844
|
const getErrorResponseSimple = (id, error) => {
|
|
865
845
|
return {
|
|
866
|
-
jsonrpc: Two,
|
|
867
|
-
id,
|
|
868
846
|
error: {
|
|
869
847
|
code: Custom,
|
|
848
|
+
data: error,
|
|
870
849
|
// @ts-ignore
|
|
871
|
-
message: error.message
|
|
872
|
-
|
|
873
|
-
|
|
850
|
+
message: error.message
|
|
851
|
+
},
|
|
852
|
+
id,
|
|
853
|
+
jsonrpc: Two$1
|
|
874
854
|
};
|
|
875
855
|
};
|
|
876
856
|
const getResponse = async (message, ipc, execute, preparePrettyError, logError, requiresSocket) => {
|
|
@@ -900,35 +880,35 @@ const normalizeParams = args => {
|
|
|
900
880
|
if (args.length === 1) {
|
|
901
881
|
const options = args[0];
|
|
902
882
|
return {
|
|
883
|
+
execute: options.execute,
|
|
903
884
|
ipc: options.ipc,
|
|
885
|
+
logError: options.logError || defaultLogError,
|
|
904
886
|
message: options.message,
|
|
905
|
-
execute: options.execute,
|
|
906
|
-
resolve: options.resolve || defaultResolve,
|
|
907
887
|
preparePrettyError: options.preparePrettyError || defaultPreparePrettyError,
|
|
908
|
-
|
|
909
|
-
|
|
888
|
+
requiresSocket: options.requiresSocket || defaultRequiresSocket,
|
|
889
|
+
resolve: options.resolve || defaultResolve
|
|
910
890
|
};
|
|
911
891
|
}
|
|
912
892
|
return {
|
|
893
|
+
execute: args[2],
|
|
913
894
|
ipc: args[0],
|
|
895
|
+
logError: args[5],
|
|
914
896
|
message: args[1],
|
|
915
|
-
execute: args[2],
|
|
916
|
-
resolve: args[3],
|
|
917
897
|
preparePrettyError: args[4],
|
|
918
|
-
|
|
919
|
-
|
|
898
|
+
requiresSocket: args[6],
|
|
899
|
+
resolve: args[3]
|
|
920
900
|
};
|
|
921
901
|
};
|
|
922
902
|
const handleJsonRpcMessage = async (...args) => {
|
|
923
903
|
const options = normalizeParams(args);
|
|
924
904
|
const {
|
|
925
|
-
message,
|
|
926
|
-
ipc,
|
|
927
905
|
execute,
|
|
928
|
-
|
|
929
|
-
preparePrettyError,
|
|
906
|
+
ipc,
|
|
930
907
|
logError,
|
|
931
|
-
|
|
908
|
+
message,
|
|
909
|
+
preparePrettyError,
|
|
910
|
+
requiresSocket,
|
|
911
|
+
resolve
|
|
932
912
|
} = options;
|
|
933
913
|
if ('id' in message) {
|
|
934
914
|
if ('method' in message) {
|
|
@@ -950,11 +930,51 @@ const handleJsonRpcMessage = async (...args) => {
|
|
|
950
930
|
}
|
|
951
931
|
throw new JsonRpcError('unexpected message');
|
|
952
932
|
};
|
|
953
|
-
|
|
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();
|
|
954
961
|
const {
|
|
955
|
-
|
|
962
|
+
promise,
|
|
963
|
+
resolve
|
|
964
|
+
} = Promise.withResolvers();
|
|
965
|
+
map[id] = resolve;
|
|
966
|
+
return {
|
|
967
|
+
id,
|
|
968
|
+
promise
|
|
969
|
+
};
|
|
970
|
+
};
|
|
971
|
+
|
|
972
|
+
const invokeHelper = async (callbacks, ipc, method, params, useSendAndTransfer) => {
|
|
973
|
+
const {
|
|
974
|
+
id,
|
|
956
975
|
promise
|
|
957
|
-
} =
|
|
976
|
+
} = registerPromise(callbacks);
|
|
977
|
+
const message = create$5(id, method, params);
|
|
958
978
|
if (useSendAndTransfer && ipc.sendAndTransfer) {
|
|
959
979
|
ipc.sendAndTransfer(message);
|
|
960
980
|
} else {
|
|
@@ -963,54 +983,40 @@ const invokeHelper = async (ipc, method, params, useSendAndTransfer) => {
|
|
|
963
983
|
const responseMessage = await promise;
|
|
964
984
|
return unwrapJsonRpcResult(responseMessage);
|
|
965
985
|
};
|
|
966
|
-
const send = (transport, method, ...params) => {
|
|
967
|
-
const message = create$4(method, params);
|
|
968
|
-
transport.send(message);
|
|
969
|
-
};
|
|
970
|
-
const invoke$1 = (ipc, method, ...params) => {
|
|
971
|
-
return invokeHelper(ipc, method, params, false);
|
|
972
|
-
};
|
|
973
|
-
const invokeAndTransfer = (ipc, method, ...params) => {
|
|
974
|
-
return invokeHelper(ipc, method, params, true);
|
|
975
|
-
};
|
|
976
|
-
|
|
977
|
-
const commands = Object.create(null);
|
|
978
|
-
const register = commandMap => {
|
|
979
|
-
Object.assign(commands, commandMap);
|
|
980
|
-
};
|
|
981
|
-
const getCommand = key => {
|
|
982
|
-
return commands[key];
|
|
983
|
-
};
|
|
984
|
-
const execute = (command, ...args) => {
|
|
985
|
-
const fn = getCommand(command);
|
|
986
|
-
if (!fn) {
|
|
987
|
-
throw new Error(`command not found ${command}`);
|
|
988
|
-
}
|
|
989
|
-
return fn(...args);
|
|
990
|
-
};
|
|
991
|
-
|
|
992
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
|
+
};
|
|
993
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
|
+
},
|
|
994
1007
|
// @ts-ignore
|
|
995
1008
|
ipc,
|
|
996
1009
|
/**
|
|
997
1010
|
* @deprecated
|
|
998
1011
|
*/
|
|
999
1012
|
send(method, ...params) {
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
invoke(method, ...params) {
|
|
1003
|
-
return invoke$1(ipc, method, ...params);
|
|
1004
|
-
},
|
|
1005
|
-
invokeAndTransfer(method, ...params) {
|
|
1006
|
-
return invokeAndTransfer(ipc, method, ...params);
|
|
1007
|
-
},
|
|
1008
|
-
async dispose() {
|
|
1009
|
-
await ipc?.dispose();
|
|
1013
|
+
const message = create$6(method, params);
|
|
1014
|
+
ipc.send(message);
|
|
1010
1015
|
}
|
|
1011
1016
|
};
|
|
1012
1017
|
return rpc;
|
|
1013
1018
|
};
|
|
1019
|
+
|
|
1014
1020
|
const requiresSocket = () => {
|
|
1015
1021
|
return false;
|
|
1016
1022
|
};
|
|
@@ -1023,8 +1029,9 @@ const logError = () => {
|
|
|
1023
1029
|
const handleMessage = event => {
|
|
1024
1030
|
const actualRequiresSocket = event?.target?.requiresSocket || requiresSocket;
|
|
1025
1031
|
const actualExecute = event?.target?.execute || execute;
|
|
1026
|
-
return handleJsonRpcMessage(event.target, event.data, actualExecute,
|
|
1032
|
+
return handleJsonRpcMessage(event.target, event.data, actualExecute, event.target._resolve, preparePrettyError, logError, actualRequiresSocket);
|
|
1027
1033
|
};
|
|
1034
|
+
|
|
1028
1035
|
const handleIpc = ipc => {
|
|
1029
1036
|
if ('addEventListener' in ipc) {
|
|
1030
1037
|
ipc.addEventListener('message', handleMessage);
|
|
@@ -1033,6 +1040,7 @@ const handleIpc = ipc => {
|
|
|
1033
1040
|
ipc.on('message', handleMessage);
|
|
1034
1041
|
}
|
|
1035
1042
|
};
|
|
1043
|
+
|
|
1036
1044
|
const listen$2 = async (module, options) => {
|
|
1037
1045
|
const rawIpc = await module.listen(options);
|
|
1038
1046
|
if (module.signal) {
|
|
@@ -1041,7 +1049,8 @@ const listen$2 = async (module, options) => {
|
|
|
1041
1049
|
const ipc = module.wrap(rawIpc);
|
|
1042
1050
|
return ipc;
|
|
1043
1051
|
};
|
|
1044
|
-
|
|
1052
|
+
|
|
1053
|
+
const create$3 = async ({
|
|
1045
1054
|
commandMap,
|
|
1046
1055
|
messagePort,
|
|
1047
1056
|
requiresSocket
|
|
@@ -1058,11 +1067,8 @@ const create$j = async ({
|
|
|
1058
1067
|
const rpc = createRpc(ipc);
|
|
1059
1068
|
return rpc;
|
|
1060
1069
|
};
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
create: create$j
|
|
1064
|
-
};
|
|
1065
|
-
const create$i = async ({
|
|
1070
|
+
|
|
1071
|
+
const create$2 = async ({
|
|
1066
1072
|
commandMap
|
|
1067
1073
|
}) => {
|
|
1068
1074
|
// TODO create a commandMap per rpc instance
|
|
@@ -1072,11 +1078,8 @@ const create$i = async ({
|
|
|
1072
1078
|
const rpc = createRpc(ipc);
|
|
1073
1079
|
return rpc;
|
|
1074
1080
|
};
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
create: create$i
|
|
1078
|
-
};
|
|
1079
|
-
const create$9 = async ({
|
|
1081
|
+
|
|
1082
|
+
const create$1 = async ({
|
|
1080
1083
|
commandMap
|
|
1081
1084
|
}) => {
|
|
1082
1085
|
// TODO create a commandMap per rpc instance
|
|
@@ -1086,11 +1089,8 @@ const create$9 = async ({
|
|
|
1086
1089
|
const rpc = createRpc(ipc);
|
|
1087
1090
|
return rpc;
|
|
1088
1091
|
};
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
create: create$9
|
|
1092
|
-
};
|
|
1093
|
-
const create$6 = async ({
|
|
1092
|
+
|
|
1093
|
+
const create = async ({
|
|
1094
1094
|
commandMap
|
|
1095
1095
|
}) => {
|
|
1096
1096
|
// TODO create a commandMap per rpc instance
|
|
@@ -1100,10 +1100,6 @@ const create$6 = async ({
|
|
|
1100
1100
|
const rpc = createRpc(ipc);
|
|
1101
1101
|
return rpc;
|
|
1102
1102
|
};
|
|
1103
|
-
const NodeWorkerRpcClient = {
|
|
1104
|
-
__proto__: null,
|
|
1105
|
-
create: create$6
|
|
1106
|
-
};
|
|
1107
1103
|
|
|
1108
1104
|
const NodeWorker = 1;
|
|
1109
1105
|
const NodeForkedProcess = 2;
|
|
@@ -1127,14 +1123,14 @@ const Auto = () => {
|
|
|
1127
1123
|
|
|
1128
1124
|
const getModule = method => {
|
|
1129
1125
|
switch (method) {
|
|
1126
|
+
case ElectronMessagePort:
|
|
1127
|
+
return create$3;
|
|
1128
|
+
case ElectronUtilityProcess:
|
|
1129
|
+
return create$2;
|
|
1130
1130
|
case NodeForkedProcess:
|
|
1131
|
-
return
|
|
1131
|
+
return create$1;
|
|
1132
1132
|
case NodeWorker:
|
|
1133
|
-
return
|
|
1134
|
-
case ElectronUtilityProcess:
|
|
1135
|
-
return ElectronUtilityProcessRpcClient.create;
|
|
1136
|
-
case ElectronMessagePort:
|
|
1137
|
-
return ElectronMessagePortRpcClient.create;
|
|
1133
|
+
return create;
|
|
1138
1134
|
default:
|
|
1139
1135
|
throw new Error('unexpected ipc type');
|
|
1140
1136
|
}
|
|
@@ -1153,15 +1149,15 @@ const listen$1 = async ({
|
|
|
1153
1149
|
|
|
1154
1150
|
const handleElectronMessagePort = async messagePort => {
|
|
1155
1151
|
await listen$1({
|
|
1156
|
-
|
|
1157
|
-
|
|
1152
|
+
messagePort,
|
|
1153
|
+
method: ElectronMessagePort
|
|
1158
1154
|
});
|
|
1159
1155
|
};
|
|
1160
1156
|
|
|
1161
1157
|
const SharedProcess = 1;
|
|
1162
1158
|
|
|
1163
1159
|
const rpcs = Object.create(null);
|
|
1164
|
-
const set
|
|
1160
|
+
const set = (id, rpc) => {
|
|
1165
1161
|
rpcs[id] = rpc;
|
|
1166
1162
|
};
|
|
1167
1163
|
const get = id => {
|
|
@@ -1180,7 +1176,8 @@ const watchInternal = async (path, options, callback) => {
|
|
|
1180
1176
|
await callback(event);
|
|
1181
1177
|
}
|
|
1182
1178
|
} catch (error) {
|
|
1183
|
-
|
|
1179
|
+
const message = new VError(error, 'Failed to watch');
|
|
1180
|
+
console.error(`[file-watcher-process] ${message}`);
|
|
1184
1181
|
}
|
|
1185
1182
|
};
|
|
1186
1183
|
|
|
@@ -1215,10 +1212,24 @@ const normalizeEvent = (eventName, path) => {
|
|
|
1215
1212
|
|
|
1216
1213
|
const waitForWatcherToBeReady = async watcher => {
|
|
1217
1214
|
const {
|
|
1218
|
-
|
|
1219
|
-
|
|
1215
|
+
promise,
|
|
1216
|
+
reject,
|
|
1217
|
+
resolve
|
|
1220
1218
|
} = Promise.withResolvers();
|
|
1221
|
-
|
|
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);
|
|
1222
1233
|
await promise;
|
|
1223
1234
|
};
|
|
1224
1235
|
|
|
@@ -1229,30 +1240,35 @@ const callBackInternal = async (eventName, path, stats) => {
|
|
|
1229
1240
|
const callback = (eventName, path, stats) => {
|
|
1230
1241
|
void callBackInternal(eventName, path);
|
|
1231
1242
|
};
|
|
1232
|
-
const errorCallback = error => {
|
|
1243
|
+
const errorCallback$1 = error => {
|
|
1233
1244
|
console.error(`[file-watcher-process] ${error}`);
|
|
1234
1245
|
};
|
|
1235
1246
|
const watchFolder = async uri => {
|
|
1236
1247
|
const path = fileURLToPath(uri);
|
|
1237
|
-
const watcher =
|
|
1248
|
+
const watcher = new FSWatcher();
|
|
1238
1249
|
watcher.on('all', callback);
|
|
1239
|
-
watcher.on('error', errorCallback);
|
|
1240
|
-
|
|
1250
|
+
watcher.on('error', errorCallback$1);
|
|
1251
|
+
const readyPromise = waitForWatcherToBeReady(watcher);
|
|
1252
|
+
watcher.add(path);
|
|
1253
|
+
await readyPromise;
|
|
1241
1254
|
};
|
|
1242
1255
|
|
|
1243
1256
|
const normalizeEvent2 = (id, eventName, path) => {
|
|
1244
1257
|
const uri = pathToFileURL(path).toString();
|
|
1245
1258
|
return {
|
|
1246
1259
|
eventName,
|
|
1247
|
-
|
|
1248
|
-
|
|
1260
|
+
id,
|
|
1261
|
+
uri
|
|
1249
1262
|
};
|
|
1250
1263
|
};
|
|
1251
1264
|
|
|
1265
|
+
const errorCallback = error => {
|
|
1266
|
+
console.error(`[file-watcher-process] ${error}`);
|
|
1267
|
+
};
|
|
1252
1268
|
const watchFolders = async ({
|
|
1253
|
-
|
|
1269
|
+
exclude,
|
|
1254
1270
|
id,
|
|
1255
|
-
|
|
1271
|
+
roots
|
|
1256
1272
|
}) => {
|
|
1257
1273
|
const callBackInternal = async (eventName, path, stats) => {
|
|
1258
1274
|
const event = normalizeEvent2(id, eventName, path);
|
|
@@ -1266,16 +1282,33 @@ const watchFolders = async ({
|
|
|
1266
1282
|
const callback = (eventName, path, stats) => {
|
|
1267
1283
|
void callBackInternal(eventName, path);
|
|
1268
1284
|
};
|
|
1269
|
-
const
|
|
1285
|
+
const watcherEntries = roots.map(root => {
|
|
1270
1286
|
const path = fileURLToPath(root);
|
|
1271
|
-
const watcher =
|
|
1287
|
+
const watcher = new FSWatcher({
|
|
1272
1288
|
ignoreInitial: true,
|
|
1273
1289
|
ignorePermissionErrors: true
|
|
1274
1290
|
});
|
|
1275
|
-
|
|
1291
|
+
watcher.on('error', errorCallback);
|
|
1292
|
+
const readyPromise = waitForWatcherToBeReady(watcher);
|
|
1293
|
+
watcher.add(path);
|
|
1294
|
+
return {
|
|
1295
|
+
readyPromise,
|
|
1296
|
+
watcher
|
|
1297
|
+
};
|
|
1276
1298
|
});
|
|
1277
|
-
|
|
1278
|
-
|
|
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) {
|
|
1279
1312
|
watcher.on('all', callback);
|
|
1280
1313
|
}
|
|
1281
1314
|
};
|
|
@@ -1291,10 +1324,10 @@ const commandMap = {
|
|
|
1291
1324
|
|
|
1292
1325
|
const listen = async () => {
|
|
1293
1326
|
const rpc = await listen$1({
|
|
1294
|
-
|
|
1295
|
-
|
|
1327
|
+
commandMap: commandMap,
|
|
1328
|
+
method: Auto()
|
|
1296
1329
|
});
|
|
1297
|
-
set
|
|
1330
|
+
set(SharedProcess, rpc);
|
|
1298
1331
|
};
|
|
1299
1332
|
|
|
1300
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.1.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"
|