@lvce-editor/file-system-process 5.17.1 → 5.18.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 +78 -17
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createHash } from 'node:crypto';
|
|
1
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
2
2
|
import { existsSync, constants } from 'node:fs';
|
|
3
3
|
import * as fs from 'node:fs/promises';
|
|
4
4
|
import * as os from 'node:os';
|
|
@@ -70,9 +70,9 @@ class AssertionError extends Error {
|
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
const Object$1 = 1;
|
|
73
|
-
const Number = 2;
|
|
73
|
+
const Number$1 = 2;
|
|
74
74
|
const Array$1 = 3;
|
|
75
|
-
const String = 4;
|
|
75
|
+
const String$1 = 4;
|
|
76
76
|
const Boolean$1 = 5;
|
|
77
77
|
const Function = 6;
|
|
78
78
|
const Null = 7;
|
|
@@ -80,11 +80,11 @@ const Unknown$1 = 8;
|
|
|
80
80
|
const getType = value => {
|
|
81
81
|
switch (typeof value) {
|
|
82
82
|
case 'number':
|
|
83
|
-
return Number;
|
|
83
|
+
return Number$1;
|
|
84
84
|
case 'function':
|
|
85
85
|
return Function;
|
|
86
86
|
case 'string':
|
|
87
|
-
return String;
|
|
87
|
+
return String$1;
|
|
88
88
|
case 'object':
|
|
89
89
|
if (value === null) {
|
|
90
90
|
return Null;
|
|
@@ -107,13 +107,13 @@ const object = value => {
|
|
|
107
107
|
};
|
|
108
108
|
const number = value => {
|
|
109
109
|
const type = getType(value);
|
|
110
|
-
if (type !== Number) {
|
|
110
|
+
if (type !== Number$1) {
|
|
111
111
|
throw new AssertionError('expected value to be of type number');
|
|
112
112
|
}
|
|
113
113
|
};
|
|
114
114
|
const string = value => {
|
|
115
115
|
const type = getType(value);
|
|
116
|
-
if (type !== String) {
|
|
116
|
+
if (type !== String$1) {
|
|
117
117
|
throw new AssertionError('expected value to be of type string');
|
|
118
118
|
}
|
|
119
119
|
};
|
|
@@ -888,6 +888,9 @@ const restoreExistingError = (error, currentStack) => {
|
|
|
888
888
|
};
|
|
889
889
|
const restoreMethodNotFoundError = (error, currentStack) => {
|
|
890
890
|
const restoredError = new JsonRpcError(error.message);
|
|
891
|
+
Object.assign(restoredError, {
|
|
892
|
+
code: error.code
|
|
893
|
+
});
|
|
891
894
|
const parentStack = getParentStack(error);
|
|
892
895
|
setStack(restoredError, `${parentStack}${NewLine}${currentStack}`);
|
|
893
896
|
return restoredError;
|
|
@@ -907,9 +910,13 @@ const applyDataProperties = (restoredError, error) => {
|
|
|
907
910
|
// @ts-ignore
|
|
908
911
|
restoredError.codeFrame = error.data.codeFrame;
|
|
909
912
|
}
|
|
910
|
-
if (error.data.code) {
|
|
913
|
+
if (typeof error.data.code === 'string' || typeof error.data.code === 'number') {
|
|
911
914
|
// @ts-ignore
|
|
912
|
-
restoredError
|
|
915
|
+
Object.defineProperty(restoredError, 'code', {
|
|
916
|
+
configurable: true,
|
|
917
|
+
value: error.data.code,
|
|
918
|
+
writable: true
|
|
919
|
+
});
|
|
913
920
|
}
|
|
914
921
|
if (error.data.type) {
|
|
915
922
|
// @ts-ignore
|
|
@@ -930,7 +937,14 @@ const applyDirectProperties = (restoredError, error) => {
|
|
|
930
937
|
}
|
|
931
938
|
};
|
|
932
939
|
const restoreMessageError = (error, _currentStack) => {
|
|
933
|
-
const restoredError = constructError(error.message, error.type, error.name);
|
|
940
|
+
const restoredError = constructError(error.message, error.type || error.data?.type, error.name);
|
|
941
|
+
if (typeof error.code === 'string' || typeof error.code === 'number') {
|
|
942
|
+
Object.defineProperty(restoredError, 'code', {
|
|
943
|
+
configurable: true,
|
|
944
|
+
value: error.code,
|
|
945
|
+
writable: true
|
|
946
|
+
});
|
|
947
|
+
}
|
|
934
948
|
if (error.data) {
|
|
935
949
|
applyDataProperties(restoredError, error);
|
|
936
950
|
} else {
|
|
@@ -938,6 +952,23 @@ const restoreMessageError = (error, _currentStack) => {
|
|
|
938
952
|
}
|
|
939
953
|
return restoredError;
|
|
940
954
|
};
|
|
955
|
+
const getFallbackMessage = error => {
|
|
956
|
+
if (error && typeof error.message === 'string' && error.message) {
|
|
957
|
+
return error.message;
|
|
958
|
+
}
|
|
959
|
+
if (error && error.data) {
|
|
960
|
+
return getFallbackMessage(error.data);
|
|
961
|
+
}
|
|
962
|
+
const stringified = String(error);
|
|
963
|
+
if (stringified !== '[object Object]') {
|
|
964
|
+
return stringified;
|
|
965
|
+
}
|
|
966
|
+
try {
|
|
967
|
+
return JSON.stringify(error);
|
|
968
|
+
} catch {
|
|
969
|
+
return stringified;
|
|
970
|
+
}
|
|
971
|
+
};
|
|
941
972
|
const restoreJsonRpcError = error => {
|
|
942
973
|
const currentStack = getCurrentStack();
|
|
943
974
|
if (error && error instanceof Error) {
|
|
@@ -946,13 +977,13 @@ const restoreJsonRpcError = error => {
|
|
|
946
977
|
if (error && error.code && error.code === MethodNotFound) {
|
|
947
978
|
return restoreMethodNotFoundError(error, currentStack);
|
|
948
979
|
}
|
|
980
|
+
if (error && error.error) {
|
|
981
|
+
return restoreJsonRpcError(error.error);
|
|
982
|
+
}
|
|
949
983
|
if (error && error.message) {
|
|
950
984
|
return restoreMessageError(error);
|
|
951
985
|
}
|
|
952
|
-
|
|
953
|
-
return new Error(`JsonRpc Error: ${error}`);
|
|
954
|
-
}
|
|
955
|
-
return new Error(`JsonRpc Error: ${error}`);
|
|
986
|
+
return new Error(`JsonRpc Error: ${getFallbackMessage(error)}`);
|
|
956
987
|
};
|
|
957
988
|
const unwrapJsonRpcResult = responseMessage => {
|
|
958
989
|
if ('error' in responseMessage) {
|
|
@@ -1009,9 +1040,9 @@ const getErrorProperty = (error, prettyError) => {
|
|
|
1009
1040
|
return {
|
|
1010
1041
|
code: Custom,
|
|
1011
1042
|
data: {
|
|
1012
|
-
code: prettyError.code,
|
|
1043
|
+
code: prettyError.code ?? error?.code,
|
|
1013
1044
|
codeFrame: prettyError.codeFrame,
|
|
1014
|
-
name: prettyError.name,
|
|
1045
|
+
name: prettyError.name ?? error?.name,
|
|
1015
1046
|
stack: getStack(prettyError),
|
|
1016
1047
|
type: getErrorType(prettyError)
|
|
1017
1048
|
},
|
|
@@ -1046,7 +1077,12 @@ const getErrorResponseSimple = (id, error) => {
|
|
|
1046
1077
|
return {
|
|
1047
1078
|
error: {
|
|
1048
1079
|
code: Custom,
|
|
1049
|
-
data: error
|
|
1080
|
+
data: error instanceof Error ? {
|
|
1081
|
+
...error,
|
|
1082
|
+
code: 'code' in error ? error.code : undefined,
|
|
1083
|
+
stack: error.stack,
|
|
1084
|
+
type: error.name
|
|
1085
|
+
} : error,
|
|
1050
1086
|
// @ts-ignore
|
|
1051
1087
|
message: error.message
|
|
1052
1088
|
},
|
|
@@ -2129,6 +2165,30 @@ const unwatchFile = uri => {
|
|
|
2129
2165
|
// TODO
|
|
2130
2166
|
};
|
|
2131
2167
|
|
|
2168
|
+
// A process owns one filesystem connection. Never reuse a persisted listing
|
|
2169
|
+
// against a different machine or a replacement connection with the same URI.
|
|
2170
|
+
const namespace = randomUUID();
|
|
2171
|
+
const timestampResolutionWindow = 2000;
|
|
2172
|
+
|
|
2173
|
+
/** An opaque listing validator, or null when directory metadata is unsafe to cache. */
|
|
2174
|
+
const getDirectoryVersion = async uri => {
|
|
2175
|
+
const path = fileURLToPath(uri);
|
|
2176
|
+
const stats = await fs.stat(path, {
|
|
2177
|
+
bigint: true
|
|
2178
|
+
});
|
|
2179
|
+
if (!stats.isDirectory()) {
|
|
2180
|
+
return null;
|
|
2181
|
+
}
|
|
2182
|
+
// Do not cache within a coarse filesystem timestamp tick. Both timestamps
|
|
2183
|
+
// matter: restoring mtime must not hide an entry change or directory replacement.
|
|
2184
|
+
const modified = Number(stats.mtimeNs / 1_000_000n);
|
|
2185
|
+
const changed = Number(stats.ctimeNs / 1_000_000n);
|
|
2186
|
+
if (Date.now() - Math.max(modified, changed) < timestampResolutionWindow) {
|
|
2187
|
+
return null;
|
|
2188
|
+
}
|
|
2189
|
+
return `${namespace}:${stats.dev}:${stats.ino}:${stats.size}:${stats.mtimeNs}:${stats.ctimeNs}:${stats.birthtimeNs}`;
|
|
2190
|
+
};
|
|
2191
|
+
|
|
2132
2192
|
const handleElectronMessagePort = async (messagePort, rpcId) => {
|
|
2133
2193
|
object(messagePort);
|
|
2134
2194
|
const rpc = await create$8({
|
|
@@ -2165,6 +2225,7 @@ const commandMap = {
|
|
|
2165
2225
|
'FileSystem.copy': copy,
|
|
2166
2226
|
'FileSystem.exists': exists,
|
|
2167
2227
|
'FileSystem.forceRemove': forceRemove,
|
|
2228
|
+
'FileSystem.getDirectoryVersion': getDirectoryVersion,
|
|
2168
2229
|
'FileSystem.getFileHash': getFileHash,
|
|
2169
2230
|
'FileSystem.getFileHashes': getFileHashes,
|
|
2170
2231
|
'FileSystem.getFileSize': getFileSize,
|