@lvce-editor/file-search-worker 1.12.0 → 1.14.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.
@@ -23,6 +23,8 @@ const assetDir = '';
23
23
  const Directory$1 = 3;
24
24
  const File$1 = 7;
25
25
 
26
+ const fileMapUrl = `${assetDir}/config/fileMap.json`;
27
+
26
28
  const normalizeLine$1 = line => {
27
29
  if (line.startsWith('Error: ')) {
28
30
  return line.slice(`Error: `.length);
@@ -79,6 +81,19 @@ let VError$1 = class VError extends Error {
79
81
  }
80
82
  };
81
83
 
84
+ const getJson = async url => {
85
+ try {
86
+ const response = await fetch(url);
87
+ if (!response.ok) {
88
+ throw new Error(response.statusText);
89
+ }
90
+ const text = await response.json();
91
+ return text;
92
+ } catch (error) {
93
+ throw new VError$1(error, `Failed to request json for ${url}`);
94
+ }
95
+ };
96
+
82
97
  const getText = async url => {
83
98
  try {
84
99
  const response = await fetch(url);
@@ -96,23 +111,24 @@ const Slash$1 = '/';
96
111
 
97
112
  const Slash = Slash$1;
98
113
 
114
+ // TODO move all of this to an extension
115
+
99
116
  const readFile$1 = async uri => {
100
117
  const fetchUri = `${assetDir}${uri}`;
101
118
  const text = await getText(fetchUri);
102
119
  return text;
103
120
  };
104
- const writeFile$1 = (uri, content) => {
121
+ const writeFile$1 = () => {
105
122
  throw new Error('not implemented');
106
123
  };
107
- const mkdir$1 = uri => {
124
+ const mkdir$1 = () => {
108
125
  throw new Error('not implemented');
109
126
  };
110
- const remove$2 = uri => {
127
+ const remove$2 = () => {
111
128
  throw new Error('not implemented');
112
129
  };
113
130
  const readDirWithFileTypes$1 = async uri => {
114
- const fetchUri = `${assetDir}/config/fileMap.json`;
115
- const fileList = await getText(fetchUri);
131
+ const fileList = await getJson(fileMapUrl);
116
132
  const dirents = [];
117
133
  for (const fileUri of fileList) {
118
134
  if (fileUri.startsWith(uri)) {
@@ -136,7 +152,7 @@ const readDirWithFileTypes$1 = async uri => {
136
152
  }
137
153
  return dirents;
138
154
  };
139
- const chmod$1 = (path, permissions) => {
155
+ const chmod$1 = () => {
140
156
  throw new Error('[memfs] chmod not implemented');
141
157
  };
142
158
  const getBlob$1 = async uri => {
@@ -152,6 +168,8 @@ class FileNotFoundError extends Error {
152
168
  }
153
169
  }
154
170
 
171
+ // TODO move this to an extension?
172
+
155
173
  const state$4 = {
156
174
  files: Object.create(null)
157
175
  };
@@ -293,15 +311,19 @@ const removeLeadingSlash = path => {
293
311
  }
294
312
  return path;
295
313
  };
314
+
315
+ // TODO simplify code
316
+ // 1. don't have playground prefix in fileMap json
317
+ // 2. remove code here that removes the prefix
296
318
  const searchFile$3 = async (path, value, prepare, assetDir) => {
297
- const fetchUri = `${assetDir}/config/fileMap.json`;
298
- const response = await fetch(fetchUri);
299
- if (!response.ok) {
300
- throw new Error(response.statusText);
301
- }
302
- const fileList = await response.json();
319
+ const fileList = await getJson(fileMapUrl);
303
320
  const result = fileList.map(removeLeadingSlash);
304
- return result;
321
+ const prefixLength = path.length - 'file:///'.length;
322
+ const final = [];
323
+ for (const item of result) {
324
+ final.push(item.slice(prefixLength));
325
+ }
326
+ return final;
305
327
  };
306
328
 
307
329
  const SearchFileFetch = {
@@ -1304,6 +1326,9 @@ const invoke = (method, ...params) => {
1304
1326
  };
1305
1327
 
1306
1328
  const splitLines$1 = lines => {
1329
+ if (!lines) {
1330
+ return [];
1331
+ }
1307
1332
  return lines.split('\n');
1308
1333
  };
1309
1334
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/file-search-worker",
3
- "version": "1.12.0",
3
+ "version": "1.14.0",
4
4
  "description": "",
5
5
  "main": "dist/fileSearchWorkerMain.js",
6
6
  "type": "module",