@lvce-editor/file-system-worker 5.10.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}`);
@@ -1672,6 +1713,7 @@ const Http = 'http:';
1672
1713
  const Memory = 'memfs:';
1673
1714
  const Https = 'https:';
1674
1715
  const File$2 = 'file:';
1716
+ const Fetch$1 = 'fetch:';
1675
1717
 
1676
1718
  const watchCallbacks = Object.create(null);
1677
1719
  const registerWatchCallback = (id, rpcId, commandId, uri) => {
@@ -1855,6 +1897,10 @@ const FileSystemMemory = {
1855
1897
  writeFile: writeFile$1
1856
1898
  };
1857
1899
 
1900
+ const isFetch = uri => {
1901
+ return uri.startsWith(Fetch$1);
1902
+ };
1903
+
1858
1904
  const isHttp = uri => {
1859
1905
  return uri.startsWith(Http) || uri.startsWith(Https);
1860
1906
  };
@@ -1870,6 +1916,9 @@ const remove = async dirent => {
1870
1916
  return remove$2(dirent);
1871
1917
  };
1872
1918
  const readFile = async uri => {
1919
+ if (isFetch(uri)) {
1920
+ return invoke$2('FileSystem.readFile', uri);
1921
+ }
1873
1922
  if (isHttp(uri)) {
1874
1923
  return readFile$3(uri);
1875
1924
  }
@@ -1885,6 +1934,9 @@ const appendFile = async (uri, text) => {
1885
1934
  return appendFile$1(uri, text);
1886
1935
  };
1887
1936
  const readDirWithFileTypes = async uri => {
1937
+ if (isFetch(uri)) {
1938
+ return invoke$2('FileSystem.readDirWithFileTypes', uri);
1939
+ }
1888
1940
  if (isMemory(uri)) {
1889
1941
  return invoke$2('FileSystem.readDirWithFileTypes', uri);
1890
1942
  }
@@ -1931,6 +1983,9 @@ const stat = async dirent => {
1931
1983
  return stat$2(dirent);
1932
1984
  };
1933
1985
  const exists = async uri => {
1986
+ if (isFetch(uri)) {
1987
+ return invoke$2('FileSystem.exists', uri);
1988
+ }
1934
1989
  if (isHttp(uri)) {
1935
1990
  return exists$3(uri);
1936
1991
  }
@@ -2072,8 +2127,25 @@ const createFileSystemProcessRpc = async platform => {
2072
2127
  return create();
2073
2128
  };
2074
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
+
2075
2146
  const initializeFileSystemProcess = async platform => {
2076
2147
  if (platform === Web) {
2148
+ set(createUnavailableFileSystemProcessRpc());
2077
2149
  return;
2078
2150
  }
2079
2151
  const rpc = await createFileSystemProcessRpc(platform);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/file-system-worker",
3
- "version": "5.10.0",
3
+ "version": "5.10.1",
4
4
  "description": "File System Worker",
5
5
  "keywords": [
6
6
  "Lvce Editor"