@lvce-editor/file-system-worker 5.9.0 → 5.10.1

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.
@@ -828,7 +828,10 @@ const constructError = (message, type, name) => {
828
828
  if (ErrorConstructor === Error) {
829
829
  const error = new Error(message);
830
830
  if (name && name !== 'VError') {
831
- error.name = name;
831
+ Object.defineProperty(error, 'name', {
832
+ configurable: true,
833
+ value: name
834
+ });
832
835
  }
833
836
  return error;
834
837
  }
@@ -845,8 +848,10 @@ const getCurrentStack = () => {
845
848
  const currentStack = joinLines(splitLines(new Error().stack || '').slice(stackLinesToSkip));
846
849
  return currentStack;
847
850
  };
848
- const getNewLineIndex = (string, startIndex = undefined) => {
849
- return string.indexOf(NewLine, startIndex);
851
+ const getNewLineIndex = (string, startIndex) => {
852
+ {
853
+ return string.indexOf(NewLine);
854
+ }
850
855
  };
851
856
  const getParentStack = error => {
852
857
  let parentStack = error.stack || error.data || error.message || '';
@@ -857,55 +862,91 @@ const getParentStack = error => {
857
862
  };
858
863
  const MethodNotFound = -32601;
859
864
  const Custom = -32001;
865
+ const setStack = (error, stack) => {
866
+ const descriptor = Object.getOwnPropertyDescriptor(error, 'stack');
867
+ if (descriptor) {
868
+ if (!descriptor.configurable && !descriptor.writable) {
869
+ return;
870
+ }
871
+ if (!descriptor.configurable && descriptor.writable) {
872
+ error.stack = stack;
873
+ return;
874
+ }
875
+ }
876
+ Object.defineProperty(error, 'stack', {
877
+ configurable: true,
878
+ value: stack,
879
+ writable: true
880
+ });
881
+ };
882
+ const restoreExistingError = (error, currentStack) => {
883
+ if (typeof error.stack === 'string') {
884
+ setStack(error, `${error.stack}${NewLine}${currentStack}`);
885
+ }
886
+ return error;
887
+ };
888
+ const restoreMethodNotFoundError = (error, currentStack) => {
889
+ const restoredError = new JsonRpcError(error.message);
890
+ const parentStack = getParentStack(error);
891
+ setStack(restoredError, `${parentStack}${NewLine}${currentStack}`);
892
+ return restoredError;
893
+ };
894
+ const restoreStackFromData = (restoredError, error, currentStack) => {
895
+ if (error.data.stack && error.data.type && error.message) {
896
+ setStack(restoredError, `${error.data.type}: ${error.message}${NewLine}${error.data.stack}${NewLine}${currentStack}`);
897
+ return;
898
+ }
899
+ if (error.data.stack) {
900
+ setStack(restoredError, error.data.stack);
901
+ }
902
+ };
903
+ const applyDataProperties = (restoredError, error) => {
904
+ restoreStackFromData(restoredError, error, getCurrentStack());
905
+ if (error.data.codeFrame) {
906
+ // @ts-ignore
907
+ restoredError.codeFrame = error.data.codeFrame;
908
+ }
909
+ if (error.data.code) {
910
+ // @ts-ignore
911
+ restoredError.code = error.data.code;
912
+ }
913
+ if (error.data.type) {
914
+ // @ts-ignore
915
+ restoredError.name = error.data.type;
916
+ }
917
+ };
918
+ const applyDirectProperties = (restoredError, error) => {
919
+ if (error.stack) {
920
+ const lowerStack = restoredError.stack || '';
921
+ const indexNewLine = getNewLineIndex(lowerStack);
922
+ const parentStack = getParentStack(error);
923
+ // @ts-ignore
924
+ setStack(restoredError, `${parentStack}${lowerStack.slice(indexNewLine)}`);
925
+ }
926
+ if (error.codeFrame) {
927
+ // @ts-ignore
928
+ restoredError.codeFrame = error.codeFrame;
929
+ }
930
+ };
931
+ const restoreMessageError = (error, _currentStack) => {
932
+ const restoredError = constructError(error.message, error.type, error.name);
933
+ if (error.data) {
934
+ applyDataProperties(restoredError, error);
935
+ } else {
936
+ applyDirectProperties(restoredError, error);
937
+ }
938
+ return restoredError;
939
+ };
860
940
  const restoreJsonRpcError = error => {
861
941
  const currentStack = getCurrentStack();
862
942
  if (error && error instanceof Error) {
863
- if (typeof error.stack === 'string') {
864
- error.stack = error.stack + NewLine + currentStack;
865
- }
866
- return error;
943
+ return restoreExistingError(error, currentStack);
867
944
  }
868
945
  if (error && error.code && error.code === MethodNotFound) {
869
- const restoredError = new JsonRpcError(error.message);
870
- const parentStack = getParentStack(error);
871
- restoredError.stack = parentStack + NewLine + currentStack;
872
- return restoredError;
946
+ return restoreMethodNotFoundError(error, currentStack);
873
947
  }
874
948
  if (error && error.message) {
875
- const restoredError = constructError(error.message, error.type, error.name);
876
- if (error.data) {
877
- if (error.data.stack && error.data.type && error.message) {
878
- restoredError.stack = error.data.type + ': ' + error.message + NewLine + error.data.stack + NewLine + currentStack;
879
- } else if (error.data.stack) {
880
- restoredError.stack = error.data.stack;
881
- }
882
- if (error.data.codeFrame) {
883
- // @ts-ignore
884
- restoredError.codeFrame = error.data.codeFrame;
885
- }
886
- if (error.data.code) {
887
- // @ts-ignore
888
- restoredError.code = error.data.code;
889
- }
890
- if (error.data.type) {
891
- // @ts-ignore
892
- restoredError.name = error.data.type;
893
- }
894
- } else {
895
- if (error.stack) {
896
- const lowerStack = restoredError.stack || '';
897
- // @ts-ignore
898
- const indexNewLine = getNewLineIndex(lowerStack);
899
- const parentStack = getParentStack(error);
900
- // @ts-ignore
901
- restoredError.stack = parentStack + lowerStack.slice(indexNewLine);
902
- }
903
- if (error.codeFrame) {
904
- // @ts-ignore
905
- restoredError.codeFrame = error.codeFrame;
906
- }
907
- }
908
- return restoredError;
949
+ return restoreMessageError(error);
909
950
  }
910
951
  if (typeof error === 'string') {
911
952
  return new Error(`JsonRpc Error: ${error}`);
@@ -1646,6 +1687,9 @@ const assertUri = uri => {
1646
1687
  }
1647
1688
  };
1648
1689
 
1690
+ const getFileHash$1 = async uri => {
1691
+ return invoke$3('FileSystem.getFileHash', uri);
1692
+ };
1649
1693
  const {
1650
1694
  appendFile: appendFile$1,
1651
1695
  copy: copy$2,
@@ -1669,6 +1713,7 @@ const Http = 'http:';
1669
1713
  const Memory = 'memfs:';
1670
1714
  const Https = 'https:';
1671
1715
  const File$2 = 'file:';
1716
+ const Fetch$1 = 'fetch:';
1672
1717
 
1673
1718
  const watchCallbacks = Object.create(null);
1674
1719
  const registerWatchCallback = (id, rpcId, commandId, uri) => {
@@ -1852,6 +1897,10 @@ const FileSystemMemory = {
1852
1897
  writeFile: writeFile$1
1853
1898
  };
1854
1899
 
1900
+ const isFetch = uri => {
1901
+ return uri.startsWith(Fetch$1);
1902
+ };
1903
+
1855
1904
  const isHttp = uri => {
1856
1905
  return uri.startsWith(Http) || uri.startsWith(Https);
1857
1906
  };
@@ -1867,6 +1916,9 @@ const remove = async dirent => {
1867
1916
  return remove$2(dirent);
1868
1917
  };
1869
1918
  const readFile = async uri => {
1919
+ if (isFetch(uri)) {
1920
+ return invoke$2('FileSystem.readFile', uri);
1921
+ }
1870
1922
  if (isHttp(uri)) {
1871
1923
  return readFile$3(uri);
1872
1924
  }
@@ -1875,10 +1927,16 @@ const readFile = async uri => {
1875
1927
  }
1876
1928
  return readFile$2(uri);
1877
1929
  };
1930
+ const getFileHash = async uri => {
1931
+ return getFileHash$1(uri);
1932
+ };
1878
1933
  const appendFile = async (uri, text) => {
1879
1934
  return appendFile$1(uri, text);
1880
1935
  };
1881
1936
  const readDirWithFileTypes = async uri => {
1937
+ if (isFetch(uri)) {
1938
+ return invoke$2('FileSystem.readDirWithFileTypes', uri);
1939
+ }
1882
1940
  if (isMemory(uri)) {
1883
1941
  return invoke$2('FileSystem.readDirWithFileTypes', uri);
1884
1942
  }
@@ -1925,6 +1983,9 @@ const stat = async dirent => {
1925
1983
  return stat$2(dirent);
1926
1984
  };
1927
1985
  const exists = async uri => {
1986
+ if (isFetch(uri)) {
1987
+ return invoke$2('FileSystem.exists', uri);
1988
+ }
1928
1989
  if (isHttp(uri)) {
1929
1990
  return exists$3(uri);
1930
1991
  }
@@ -1988,6 +2049,7 @@ const FileSystemDisk = {
1988
2049
  copy,
1989
2050
  createFile,
1990
2051
  exists,
2052
+ getFileHash,
1991
2053
  getFolderSize,
1992
2054
  getPathSeparator,
1993
2055
  getRealPath,
@@ -2065,8 +2127,25 @@ const createFileSystemProcessRpc = async platform => {
2065
2127
  return create();
2066
2128
  };
2067
2129
 
2130
+ const throwUnavailableError = () => {
2131
+ throw new Error('Disk file system is not available in web');
2132
+ };
2133
+ const createUnavailableFileSystemProcessRpc = () => {
2134
+ return {
2135
+ dispose: async () => {},
2136
+ invoke: async () => {
2137
+ return throwUnavailableError();
2138
+ },
2139
+ invokeAndTransfer: async () => {
2140
+ return throwUnavailableError();
2141
+ },
2142
+ send: throwUnavailableError
2143
+ };
2144
+ };
2145
+
2068
2146
  const initializeFileSystemProcess = async platform => {
2069
2147
  if (platform === Web) {
2148
+ set(createUnavailableFileSystemProcessRpc());
2070
2149
  return;
2071
2150
  }
2072
2151
  const rpc = await createFileSystemProcessRpc(platform);
@@ -2170,6 +2249,7 @@ const commandMap = {
2170
2249
  'FileSystem.createFile': createFile,
2171
2250
  'FileSystem.executeWatchCallback': executeWatchCallback,
2172
2251
  'FileSystem.exists': exists,
2252
+ 'FileSystem.getFileHash': getFileHash,
2173
2253
  'FileSystem.getFolderSize': getFolderSize,
2174
2254
  'FileSystem.getPathSeparator': getPathSeparator,
2175
2255
  'FileSystem.getRealPath': getRealPath,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/file-system-worker",
3
- "version": "5.9.0",
3
+ "version": "5.10.1",
4
4
  "description": "File System Worker",
5
5
  "keywords": [
6
6
  "Lvce Editor"