@lvce-editor/file-search-worker 1.2.0 → 1.4.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/fileSearchWorkerMain.js +479 -4
- package/package.json +5 -2
|
@@ -18,10 +18,483 @@ const execute = (command, ...args) => {
|
|
|
18
18
|
return fn(...args);
|
|
19
19
|
};
|
|
20
20
|
|
|
21
|
-
const searchFile$
|
|
21
|
+
const searchFile$3 = async (workspace, root) => {
|
|
22
22
|
return [];
|
|
23
23
|
};
|
|
24
24
|
|
|
25
|
+
const Fetch = 'fetch';
|
|
26
|
+
|
|
27
|
+
const removeLeadingSlash = path => {
|
|
28
|
+
const workspacePath = ''; // TODO ask renderer worker for path
|
|
29
|
+
return path.slice(workspacePath.length - Fetch.length - 2);
|
|
30
|
+
};
|
|
31
|
+
const searchFile$2 = async (path, value, assetDir) => {
|
|
32
|
+
const fetchUri = `${assetDir}/config/fileMap.json`;
|
|
33
|
+
const response = await fetch(fetchUri);
|
|
34
|
+
if (!response.ok) {
|
|
35
|
+
throw new Error(response.statusText);
|
|
36
|
+
}
|
|
37
|
+
const fileList = await response.json();
|
|
38
|
+
const result = fileList.map(removeLeadingSlash);
|
|
39
|
+
return result;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const Directory = 'directory';
|
|
43
|
+
const File = 'file';
|
|
44
|
+
|
|
45
|
+
// based on https://github.com/microsoft/vscode/blob/c0769274fa136b45799edeccc0d0a2f645b75caf/src/vs/base/common/arrays.ts#L625 (License MIT)
|
|
46
|
+
|
|
47
|
+
const fromAsync = async asyncIterable => {
|
|
48
|
+
const children = [];
|
|
49
|
+
for await (const value of asyncIterable) {
|
|
50
|
+
children.push(value);
|
|
51
|
+
}
|
|
52
|
+
return children;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
let AssertionError$1 = class AssertionError extends Error {
|
|
56
|
+
constructor(message) {
|
|
57
|
+
super(message);
|
|
58
|
+
this.name = 'AssertionError';
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
const getType$2 = value => {
|
|
62
|
+
switch (typeof value) {
|
|
63
|
+
case 'number':
|
|
64
|
+
return 'number';
|
|
65
|
+
case 'function':
|
|
66
|
+
return 'function';
|
|
67
|
+
case 'string':
|
|
68
|
+
return 'string';
|
|
69
|
+
case 'object':
|
|
70
|
+
if (value === null) {
|
|
71
|
+
return 'null';
|
|
72
|
+
}
|
|
73
|
+
if (Array.isArray(value)) {
|
|
74
|
+
return 'array';
|
|
75
|
+
}
|
|
76
|
+
return 'object';
|
|
77
|
+
case 'boolean':
|
|
78
|
+
return 'boolean';
|
|
79
|
+
default:
|
|
80
|
+
return 'unknown';
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
const object = value => {
|
|
84
|
+
const type = getType$2(value);
|
|
85
|
+
if (type !== 'object') {
|
|
86
|
+
throw new AssertionError$1('expected value to be of type object');
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Do not use directly, use FileSystemHtml.getChildHandles
|
|
92
|
+
* instead which prompts for the required permission to
|
|
93
|
+
* retrieve the child handles
|
|
94
|
+
*
|
|
95
|
+
*/
|
|
96
|
+
const getChildHandles = async handle => {
|
|
97
|
+
object(handle);
|
|
98
|
+
// @ts-ignore
|
|
99
|
+
const handles = await fromAsync(handle.values());
|
|
100
|
+
return handles;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
const dirname = (pathSeparator, path) => {
|
|
104
|
+
const index = path.lastIndexOf(pathSeparator);
|
|
105
|
+
if (index === -1) {
|
|
106
|
+
return path;
|
|
107
|
+
}
|
|
108
|
+
return path.slice(0, index);
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
const instanceOfAny = (object, constructors) => constructors.some(c => object instanceof c);
|
|
112
|
+
let idbProxyableTypes;
|
|
113
|
+
let cursorAdvanceMethods;
|
|
114
|
+
// This is a function to prevent it throwing up in node environments.
|
|
115
|
+
function getIdbProxyableTypes() {
|
|
116
|
+
return idbProxyableTypes || (idbProxyableTypes = [IDBDatabase, IDBObjectStore, IDBIndex, IDBCursor, IDBTransaction]);
|
|
117
|
+
}
|
|
118
|
+
// This is a function to prevent it throwing up in node environments.
|
|
119
|
+
function getCursorAdvanceMethods() {
|
|
120
|
+
return cursorAdvanceMethods || (cursorAdvanceMethods = [IDBCursor.prototype.advance, IDBCursor.prototype.continue, IDBCursor.prototype.continuePrimaryKey]);
|
|
121
|
+
}
|
|
122
|
+
const transactionDoneMap = new WeakMap();
|
|
123
|
+
const transformCache = new WeakMap();
|
|
124
|
+
const reverseTransformCache = new WeakMap();
|
|
125
|
+
function promisifyRequest(request) {
|
|
126
|
+
const promise = new Promise((resolve, reject) => {
|
|
127
|
+
const unlisten = () => {
|
|
128
|
+
request.removeEventListener('success', success);
|
|
129
|
+
request.removeEventListener('error', error);
|
|
130
|
+
};
|
|
131
|
+
const success = () => {
|
|
132
|
+
resolve(wrap(request.result));
|
|
133
|
+
unlisten();
|
|
134
|
+
};
|
|
135
|
+
const error = () => {
|
|
136
|
+
reject(request.error);
|
|
137
|
+
unlisten();
|
|
138
|
+
};
|
|
139
|
+
request.addEventListener('success', success);
|
|
140
|
+
request.addEventListener('error', error);
|
|
141
|
+
});
|
|
142
|
+
// This mapping exists in reverseTransformCache but doesn't doesn't exist in transformCache. This
|
|
143
|
+
// is because we create many promises from a single IDBRequest.
|
|
144
|
+
reverseTransformCache.set(promise, request);
|
|
145
|
+
return promise;
|
|
146
|
+
}
|
|
147
|
+
function cacheDonePromiseForTransaction(tx) {
|
|
148
|
+
// Early bail if we've already created a done promise for this transaction.
|
|
149
|
+
if (transactionDoneMap.has(tx)) return;
|
|
150
|
+
const done = new Promise((resolve, reject) => {
|
|
151
|
+
const unlisten = () => {
|
|
152
|
+
tx.removeEventListener('complete', complete);
|
|
153
|
+
tx.removeEventListener('error', error);
|
|
154
|
+
tx.removeEventListener('abort', error);
|
|
155
|
+
};
|
|
156
|
+
const complete = () => {
|
|
157
|
+
resolve();
|
|
158
|
+
unlisten();
|
|
159
|
+
};
|
|
160
|
+
const error = () => {
|
|
161
|
+
reject(tx.error || new DOMException('AbortError', 'AbortError'));
|
|
162
|
+
unlisten();
|
|
163
|
+
};
|
|
164
|
+
tx.addEventListener('complete', complete);
|
|
165
|
+
tx.addEventListener('error', error);
|
|
166
|
+
tx.addEventListener('abort', error);
|
|
167
|
+
});
|
|
168
|
+
// Cache it for later retrieval.
|
|
169
|
+
transactionDoneMap.set(tx, done);
|
|
170
|
+
}
|
|
171
|
+
let idbProxyTraps = {
|
|
172
|
+
get(target, prop, receiver) {
|
|
173
|
+
if (target instanceof IDBTransaction) {
|
|
174
|
+
// Special handling for transaction.done.
|
|
175
|
+
if (prop === 'done') return transactionDoneMap.get(target);
|
|
176
|
+
// Make tx.store return the only store in the transaction, or undefined if there are many.
|
|
177
|
+
if (prop === 'store') {
|
|
178
|
+
return receiver.objectStoreNames[1] ? undefined : receiver.objectStore(receiver.objectStoreNames[0]);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
// Else transform whatever we get back.
|
|
182
|
+
return wrap(target[prop]);
|
|
183
|
+
},
|
|
184
|
+
set(target, prop, value) {
|
|
185
|
+
target[prop] = value;
|
|
186
|
+
return true;
|
|
187
|
+
},
|
|
188
|
+
has(target, prop) {
|
|
189
|
+
if (target instanceof IDBTransaction && (prop === 'done' || prop === 'store')) {
|
|
190
|
+
return true;
|
|
191
|
+
}
|
|
192
|
+
return prop in target;
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
function replaceTraps(callback) {
|
|
196
|
+
idbProxyTraps = callback(idbProxyTraps);
|
|
197
|
+
}
|
|
198
|
+
function wrapFunction(func) {
|
|
199
|
+
// Due to expected object equality (which is enforced by the caching in `wrap`), we
|
|
200
|
+
// only create one new func per func.
|
|
201
|
+
// Cursor methods are special, as the behaviour is a little more different to standard IDB. In
|
|
202
|
+
// IDB, you advance the cursor and wait for a new 'success' on the IDBRequest that gave you the
|
|
203
|
+
// cursor. It's kinda like a promise that can resolve with many values. That doesn't make sense
|
|
204
|
+
// with real promises, so each advance methods returns a new promise for the cursor object, or
|
|
205
|
+
// undefined if the end of the cursor has been reached.
|
|
206
|
+
if (getCursorAdvanceMethods().includes(func)) {
|
|
207
|
+
return function (...args) {
|
|
208
|
+
// Calling the original function with the proxy as 'this' causes ILLEGAL INVOCATION, so we use
|
|
209
|
+
// the original object.
|
|
210
|
+
func.apply(unwrap(this), args);
|
|
211
|
+
return wrap(this.request);
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
return function (...args) {
|
|
215
|
+
// Calling the original function with the proxy as 'this' causes ILLEGAL INVOCATION, so we use
|
|
216
|
+
// the original object.
|
|
217
|
+
return wrap(func.apply(unwrap(this), args));
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
function transformCachableValue(value) {
|
|
221
|
+
if (typeof value === 'function') return wrapFunction(value);
|
|
222
|
+
// This doesn't return, it just creates a 'done' promise for the transaction,
|
|
223
|
+
// which is later returned for transaction.done (see idbObjectHandler).
|
|
224
|
+
if (value instanceof IDBTransaction) cacheDonePromiseForTransaction(value);
|
|
225
|
+
if (instanceOfAny(value, getIdbProxyableTypes())) return new Proxy(value, idbProxyTraps);
|
|
226
|
+
// Return the same value back if we're not going to transform it.
|
|
227
|
+
return value;
|
|
228
|
+
}
|
|
229
|
+
function wrap(value) {
|
|
230
|
+
// We sometimes generate multiple promises from a single IDBRequest (eg when cursoring), because
|
|
231
|
+
// IDB is weird and a single IDBRequest can yield many responses, so these can't be cached.
|
|
232
|
+
if (value instanceof IDBRequest) return promisifyRequest(value);
|
|
233
|
+
// If we've already transformed this value before, reuse the transformed value.
|
|
234
|
+
// This is faster, but it also provides object equality.
|
|
235
|
+
if (transformCache.has(value)) return transformCache.get(value);
|
|
236
|
+
const newValue = transformCachableValue(value);
|
|
237
|
+
// Not all types are transformed.
|
|
238
|
+
// These may be primitive types, so they can't be WeakMap keys.
|
|
239
|
+
if (newValue !== value) {
|
|
240
|
+
transformCache.set(value, newValue);
|
|
241
|
+
reverseTransformCache.set(newValue, value);
|
|
242
|
+
}
|
|
243
|
+
return newValue;
|
|
244
|
+
}
|
|
245
|
+
const unwrap = value => reverseTransformCache.get(value);
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Open a database.
|
|
249
|
+
*
|
|
250
|
+
* @param name Name of the database.
|
|
251
|
+
* @param version Schema version.
|
|
252
|
+
* @param callbacks Additional callbacks.
|
|
253
|
+
*/
|
|
254
|
+
function openDB(name, version, {
|
|
255
|
+
blocked,
|
|
256
|
+
upgrade,
|
|
257
|
+
blocking,
|
|
258
|
+
terminated
|
|
259
|
+
} = {}) {
|
|
260
|
+
const request = indexedDB.open(name, version);
|
|
261
|
+
const openPromise = wrap(request);
|
|
262
|
+
if (upgrade) {
|
|
263
|
+
request.addEventListener('upgradeneeded', event => {
|
|
264
|
+
upgrade(wrap(request.result), event.oldVersion, event.newVersion, wrap(request.transaction), event);
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
if (blocked) {
|
|
268
|
+
request.addEventListener('blocked', event => blocked(
|
|
269
|
+
// Casting due to https://github.com/microsoft/TypeScript-DOM-lib-generator/pull/1405
|
|
270
|
+
event.oldVersion, event.newVersion, event));
|
|
271
|
+
}
|
|
272
|
+
openPromise.then(db => {
|
|
273
|
+
if (terminated) db.addEventListener('close', () => terminated());
|
|
274
|
+
if (blocking) {
|
|
275
|
+
db.addEventListener('versionchange', event => blocking(event.oldVersion, event.newVersion, event));
|
|
276
|
+
}
|
|
277
|
+
}).catch(() => {});
|
|
278
|
+
return openPromise;
|
|
279
|
+
}
|
|
280
|
+
const readMethods = ['get', 'getKey', 'getAll', 'getAllKeys', 'count'];
|
|
281
|
+
const writeMethods = ['put', 'add', 'delete', 'clear'];
|
|
282
|
+
const cachedMethods = new Map();
|
|
283
|
+
function getMethod(target, prop) {
|
|
284
|
+
if (!(target instanceof IDBDatabase && !(prop in target) && typeof prop === 'string')) {
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
if (cachedMethods.get(prop)) return cachedMethods.get(prop);
|
|
288
|
+
const targetFuncName = prop.replace(/FromIndex$/, '');
|
|
289
|
+
const useIndex = prop !== targetFuncName;
|
|
290
|
+
const isWrite = writeMethods.includes(targetFuncName);
|
|
291
|
+
if (
|
|
292
|
+
// Bail if the target doesn't exist on the target. Eg, getAll isn't in Edge.
|
|
293
|
+
!(targetFuncName in (useIndex ? IDBIndex : IDBObjectStore).prototype) || !(isWrite || readMethods.includes(targetFuncName))) {
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
const method = async function (storeName, ...args) {
|
|
297
|
+
// isWrite ? 'readwrite' : undefined gzipps better, but fails in Edge :(
|
|
298
|
+
const tx = this.transaction(storeName, isWrite ? 'readwrite' : 'readonly');
|
|
299
|
+
let target = tx.store;
|
|
300
|
+
if (useIndex) target = target.index(args.shift());
|
|
301
|
+
// Must reject if op rejects.
|
|
302
|
+
// If it's a write operation, must reject if tx.done rejects.
|
|
303
|
+
// Must reject with op rejection first.
|
|
304
|
+
// Must resolve with op value.
|
|
305
|
+
// Must handle both promises (no unhandled rejections)
|
|
306
|
+
return (await Promise.all([target[targetFuncName](...args), isWrite && tx.done]))[0];
|
|
307
|
+
};
|
|
308
|
+
cachedMethods.set(prop, method);
|
|
309
|
+
return method;
|
|
310
|
+
}
|
|
311
|
+
replaceTraps(oldTraps => ({
|
|
312
|
+
...oldTraps,
|
|
313
|
+
get: (target, prop, receiver) => getMethod(target, prop) || oldTraps.get(target, prop, receiver),
|
|
314
|
+
has: (target, prop) => !!getMethod(target, prop) || oldTraps.has(target, prop)
|
|
315
|
+
}));
|
|
316
|
+
const advanceMethodProps = ['continue', 'continuePrimaryKey', 'advance'];
|
|
317
|
+
const methodMap = {};
|
|
318
|
+
const advanceResults = new WeakMap();
|
|
319
|
+
const ittrProxiedCursorToOriginalProxy = new WeakMap();
|
|
320
|
+
const cursorIteratorTraps = {
|
|
321
|
+
get(target, prop) {
|
|
322
|
+
if (!advanceMethodProps.includes(prop)) return target[prop];
|
|
323
|
+
let cachedFunc = methodMap[prop];
|
|
324
|
+
if (!cachedFunc) {
|
|
325
|
+
cachedFunc = methodMap[prop] = function (...args) {
|
|
326
|
+
advanceResults.set(this, ittrProxiedCursorToOriginalProxy.get(this)[prop](...args));
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
return cachedFunc;
|
|
330
|
+
}
|
|
331
|
+
};
|
|
332
|
+
async function* iterate(...args) {
|
|
333
|
+
// tslint:disable-next-line:no-this-assignment
|
|
334
|
+
let cursor = this;
|
|
335
|
+
if (!(cursor instanceof IDBCursor)) {
|
|
336
|
+
cursor = await cursor.openCursor(...args);
|
|
337
|
+
}
|
|
338
|
+
if (!cursor) return;
|
|
339
|
+
cursor = cursor;
|
|
340
|
+
const proxiedCursor = new Proxy(cursor, cursorIteratorTraps);
|
|
341
|
+
ittrProxiedCursorToOriginalProxy.set(proxiedCursor, cursor);
|
|
342
|
+
// Map this double-proxy back to the original, so other cursor methods work.
|
|
343
|
+
reverseTransformCache.set(proxiedCursor, unwrap(cursor));
|
|
344
|
+
while (cursor) {
|
|
345
|
+
yield proxiedCursor;
|
|
346
|
+
// If one of the advancing methods was not called, call continue().
|
|
347
|
+
cursor = await (advanceResults.get(proxiedCursor) || cursor.continue());
|
|
348
|
+
advanceResults.delete(proxiedCursor);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
function isIteratorProp(target, prop) {
|
|
352
|
+
return prop === Symbol.asyncIterator && instanceOfAny(target, [IDBIndex, IDBObjectStore, IDBCursor]) || prop === 'iterate' && instanceOfAny(target, [IDBIndex, IDBObjectStore]);
|
|
353
|
+
}
|
|
354
|
+
replaceTraps(oldTraps => ({
|
|
355
|
+
...oldTraps,
|
|
356
|
+
get(target, prop, receiver) {
|
|
357
|
+
if (isIteratorProp(target, prop)) return iterate;
|
|
358
|
+
return oldTraps.get(target, prop, receiver);
|
|
359
|
+
},
|
|
360
|
+
has(target, prop) {
|
|
361
|
+
return isIteratorProp(target, prop) || oldTraps.has(target, prop);
|
|
362
|
+
}
|
|
363
|
+
}));
|
|
364
|
+
|
|
365
|
+
const normalizeLine$1 = line => {
|
|
366
|
+
if (line.startsWith('Error: ')) {
|
|
367
|
+
return line.slice(`Error: `.length);
|
|
368
|
+
}
|
|
369
|
+
if (line.startsWith('VError: ')) {
|
|
370
|
+
return line.slice(`VError: `.length);
|
|
371
|
+
}
|
|
372
|
+
return line;
|
|
373
|
+
};
|
|
374
|
+
const getCombinedMessage$1 = (error, message) => {
|
|
375
|
+
const stringifiedError = normalizeLine$1(`${error}`);
|
|
376
|
+
if (message) {
|
|
377
|
+
return `${message}: ${stringifiedError}`;
|
|
378
|
+
}
|
|
379
|
+
return stringifiedError;
|
|
380
|
+
};
|
|
381
|
+
const NewLine$3 = '\n';
|
|
382
|
+
const getNewLineIndex$2 = (string, startIndex = undefined) => {
|
|
383
|
+
return string.indexOf(NewLine$3, startIndex);
|
|
384
|
+
};
|
|
385
|
+
const mergeStacks$1 = (parent, child) => {
|
|
386
|
+
if (!child) {
|
|
387
|
+
return parent;
|
|
388
|
+
}
|
|
389
|
+
const parentNewLineIndex = getNewLineIndex$2(parent);
|
|
390
|
+
const childNewLineIndex = getNewLineIndex$2(child);
|
|
391
|
+
if (childNewLineIndex === -1) {
|
|
392
|
+
return parent;
|
|
393
|
+
}
|
|
394
|
+
const parentFirstLine = parent.slice(0, parentNewLineIndex);
|
|
395
|
+
const childRest = child.slice(childNewLineIndex);
|
|
396
|
+
const childFirstLine = normalizeLine$1(child.slice(0, childNewLineIndex));
|
|
397
|
+
if (parentFirstLine.includes(childFirstLine)) {
|
|
398
|
+
return parentFirstLine + childRest;
|
|
399
|
+
}
|
|
400
|
+
return child;
|
|
401
|
+
};
|
|
402
|
+
let VError$1 = class VError extends Error {
|
|
403
|
+
constructor(error, message) {
|
|
404
|
+
const combinedMessage = getCombinedMessage$1(error, message);
|
|
405
|
+
super(combinedMessage);
|
|
406
|
+
this.name = 'VError';
|
|
407
|
+
if (error instanceof Error) {
|
|
408
|
+
this.stack = mergeStacks$1(this.stack, error.stack);
|
|
409
|
+
}
|
|
410
|
+
if (error.codeFrame) {
|
|
411
|
+
// @ts-ignore
|
|
412
|
+
this.codeFrame = error.codeFrame;
|
|
413
|
+
}
|
|
414
|
+
if (error.code) {
|
|
415
|
+
// @ts-ignore
|
|
416
|
+
this.code = error.code;
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
};
|
|
420
|
+
|
|
421
|
+
const state$3 = {
|
|
422
|
+
databases: Object.create(null),
|
|
423
|
+
eventId: 0,
|
|
424
|
+
dbVersion: 1,
|
|
425
|
+
cachedDb: undefined
|
|
426
|
+
};
|
|
427
|
+
|
|
428
|
+
// TODO high memory usage in idb because of transactionDoneMap
|
|
429
|
+
|
|
430
|
+
const getHandleDb = async () => {
|
|
431
|
+
// @ts-ignore
|
|
432
|
+
const db = await openDB('handle', state$3.dbVersion, {
|
|
433
|
+
async upgrade(db, oldVersion) {
|
|
434
|
+
if (!db.objectStoreNames.contains('file-handles-store')) {
|
|
435
|
+
// @ts-ignore
|
|
436
|
+
await db.createObjectStore('file-handles-store', {});
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
});
|
|
440
|
+
return db;
|
|
441
|
+
};
|
|
442
|
+
const getHandle$1 = async uri => {
|
|
443
|
+
const handleDb = await getHandleDb();
|
|
444
|
+
const handle = await handleDb.get('file-handles-store', uri);
|
|
445
|
+
return handle;
|
|
446
|
+
};
|
|
447
|
+
|
|
448
|
+
const getHandle = async uri => {
|
|
449
|
+
try {
|
|
450
|
+
// TODO retrieve handle from state or from indexeddb
|
|
451
|
+
// TODO if not found, throw error
|
|
452
|
+
const handle = await getHandle$1(uri);
|
|
453
|
+
return handle;
|
|
454
|
+
} catch (error) {
|
|
455
|
+
throw new VError$1(error, 'Failed to get handle');
|
|
456
|
+
}
|
|
457
|
+
};
|
|
458
|
+
|
|
459
|
+
const getDirectoryHandle = async uri => {
|
|
460
|
+
const handle = await getHandle(uri);
|
|
461
|
+
if (handle) {
|
|
462
|
+
return handle;
|
|
463
|
+
}
|
|
464
|
+
const dirname$1 = dirname('/', uri);
|
|
465
|
+
if (uri === dirname$1) {
|
|
466
|
+
return undefined;
|
|
467
|
+
}
|
|
468
|
+
return getDirectoryHandle(dirname$1);
|
|
469
|
+
};
|
|
470
|
+
const searchFilesRecursively = async (all, parent, handle) => {
|
|
471
|
+
const childHandles = await getChildHandles(handle);
|
|
472
|
+
const promises = [];
|
|
473
|
+
for (const childHandle of childHandles) {
|
|
474
|
+
const absolutePath = parent + '/' + childHandle.name;
|
|
475
|
+
switch (childHandle.kind) {
|
|
476
|
+
case Directory:
|
|
477
|
+
promises.push(searchFilesRecursively(all, absolutePath, childHandle));
|
|
478
|
+
break;
|
|
479
|
+
case File:
|
|
480
|
+
all.push(absolutePath);
|
|
481
|
+
break;
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
await Promise.all(promises);
|
|
485
|
+
};
|
|
486
|
+
const searchFile$1 = async uri => {
|
|
487
|
+
const path = uri.slice('html://'.length);
|
|
488
|
+
const handle = await getDirectoryHandle(path);
|
|
489
|
+
if (!handle) {
|
|
490
|
+
// @ts-ignore
|
|
491
|
+
throw new VError$1(`Folder not found ${uri}`);
|
|
492
|
+
}
|
|
493
|
+
const all = [];
|
|
494
|
+
await searchFilesRecursively(all, '', handle);
|
|
495
|
+
return all;
|
|
496
|
+
};
|
|
497
|
+
|
|
25
498
|
const getFileSearchRipGrepArgs = () => {
|
|
26
499
|
const ripGrepArgs = ['--files', '--sort-files'];
|
|
27
500
|
return ripGrepArgs;
|
|
@@ -439,8 +912,10 @@ const searchFile = async (path, value) => {
|
|
|
439
912
|
};
|
|
440
913
|
|
|
441
914
|
const commandMap = {
|
|
442
|
-
'SearchFile.searchFile': searchFile$
|
|
443
|
-
'SearchFile.searchFileWithRipGrep': searchFile
|
|
915
|
+
'SearchFile.searchFile': searchFile$3,
|
|
916
|
+
'SearchFile.searchFileWithRipGrep': searchFile,
|
|
917
|
+
'SearchFile.searchFileWithHtml': searchFile$1,
|
|
918
|
+
'SearchFile.searchFileWithFetch': searchFile$2
|
|
444
919
|
};
|
|
445
920
|
|
|
446
921
|
const requiresSocket = () => {
|
|
@@ -450,7 +925,7 @@ const preparePrettyError = error => {
|
|
|
450
925
|
return error;
|
|
451
926
|
};
|
|
452
927
|
const logError = error => {
|
|
453
|
-
|
|
928
|
+
// handled by renderer worker
|
|
454
929
|
};
|
|
455
930
|
const handleMessage = event => {
|
|
456
931
|
return handleJsonRpcMessage(event.target, event.data, execute, resolve, preparePrettyError, logError, requiresSocket);
|
package/package.json
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lvce-editor/file-search-worker",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/fileSearchWorkerMain.js",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"keywords": [],
|
|
8
8
|
"author": "",
|
|
9
|
-
"license": "MIT"
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"idb": "^8.0.0"
|
|
12
|
+
}
|
|
10
13
|
}
|