@lvce-editor/file-system-worker 5.17.0 → 5.18.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.
@@ -1256,6 +1256,34 @@ const listen$1 = async (module, options) => {
1256
1256
  return ipc;
1257
1257
  };
1258
1258
 
1259
+ const createSharedLazyRpc = factory => {
1260
+ let rpcPromise;
1261
+ const getOrCreate = () => {
1262
+ if (!rpcPromise) {
1263
+ rpcPromise = factory();
1264
+ }
1265
+ return rpcPromise;
1266
+ };
1267
+ return {
1268
+ async dispose() {
1269
+ const rpc = await getOrCreate();
1270
+ await rpc.dispose();
1271
+ },
1272
+ async invoke(method, ...params) {
1273
+ const rpc = await getOrCreate();
1274
+ return rpc.invoke(method, ...params);
1275
+ },
1276
+ async invokeAndTransfer(method, ...params) {
1277
+ const rpc = await getOrCreate();
1278
+ return rpc.invokeAndTransfer(method, ...params);
1279
+ },
1280
+ async send(method, ...params) {
1281
+ const rpc = await getOrCreate();
1282
+ rpc.send(method, ...params);
1283
+ }
1284
+ };
1285
+ };
1286
+
1259
1287
  const create$6 = async ({
1260
1288
  commandMap,
1261
1289
  isMessagePortOpen = true,
@@ -1291,34 +1319,6 @@ const create$5 = async ({
1291
1319
  });
1292
1320
  };
1293
1321
 
1294
- const createSharedLazyRpc = factory => {
1295
- let rpcPromise;
1296
- const getOrCreate = () => {
1297
- if (!rpcPromise) {
1298
- rpcPromise = factory();
1299
- }
1300
- return rpcPromise;
1301
- };
1302
- return {
1303
- async dispose() {
1304
- const rpc = await getOrCreate();
1305
- await rpc.dispose();
1306
- },
1307
- async invoke(method, ...params) {
1308
- const rpc = await getOrCreate();
1309
- return rpc.invoke(method, ...params);
1310
- },
1311
- async invokeAndTransfer(method, ...params) {
1312
- const rpc = await getOrCreate();
1313
- return rpc.invokeAndTransfer(method, ...params);
1314
- },
1315
- async send(method, ...params) {
1316
- const rpc = await getOrCreate();
1317
- rpc.send(method, ...params);
1318
- }
1319
- };
1320
- };
1321
-
1322
1322
  const create$4 = async ({
1323
1323
  commandMap,
1324
1324
  isMessagePortOpen,
@@ -1506,6 +1506,9 @@ const create = rpcId => {
1506
1506
  };
1507
1507
  };
1508
1508
 
1509
+ const Directory$1 = 3;
1510
+ const File$3 = 7;
1511
+
1509
1512
  const DebugWorker = 55;
1510
1513
  const ExtensionHostWorker = 44;
1511
1514
  const FileSystemProcess$1 = 210;
@@ -1535,10 +1538,6 @@ const appendFile$2 = async (uri, text) => {
1535
1538
  const readDirWithFileTypes$4 = async uri => {
1536
1539
  return invoke$3('FileSystem.readDirWithFileTypes', uri);
1537
1540
  };
1538
- const getPathSeparator$4 = async root => {
1539
- // @ts-ignore
1540
- return invoke$3('FileSystem.getPathSeparator', root);
1541
- };
1542
1541
  const readJson$4 = async root => {
1543
1542
  // @ts-ignore
1544
1543
  return invoke$3('FileSystem.readJson', root);
@@ -1582,7 +1581,6 @@ const FileSystemProcess = {
1582
1581
  copy: copy$4,
1583
1582
  exists: exists$4,
1584
1583
  getFolderSize: getFolderSize$4,
1585
- getPathSeparator: getPathSeparator$4,
1586
1584
  getRealPath: getRealPath$4,
1587
1585
  invoke: invoke$3,
1588
1586
  mkdir: mkdir$4,
@@ -1596,58 +1594,101 @@ const FileSystemProcess = {
1596
1594
  writeFile: writeFile$4
1597
1595
  };
1598
1596
 
1599
- const {
1600
- set: set$2
1601
- } = create(RendererProcess);
1602
-
1603
- const {
1604
- invoke: invoke$2,
1605
- invokeAndTransfer,
1606
- set: set$1
1607
- } = create(RendererWorker);
1608
- const sendMessagePortToExtensionHostWorker = async (port, rpcId = 0) => {
1609
- const command = 'HandleMessagePort.handleMessagePort2';
1610
- await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToExtensionHostWorker', port, command, rpcId);
1611
- };
1612
- const sendMessagePortToRendererProcess = async port => {
1613
- const command = 'HandleMessagePort.handleMessagePort';
1614
- await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToRendererProcess', port, command, DebugWorker);
1615
- };
1616
- const sendMessagePortToFileSystemProcess$1 = async (port, rpcId) => {
1617
- const command = 'HandleMessagePortForFileSystemProcess.handleMessagePortForFileSystemProcess';
1618
- await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToSharedProcess', port, command, rpcId);
1619
- };
1620
-
1621
1597
  const createLazyRpc = rpcId => {
1622
- let rpcPromise;
1598
+ let activeRpc;
1623
1599
  let factory;
1624
- const createRpc = async () => {
1600
+ let generation = 0;
1601
+ let rpcPromise;
1602
+ const resetListeners = new Set();
1603
+ const createRpc = async expectedGeneration => {
1625
1604
  const rpc = await factory();
1605
+ if (generation !== expectedGeneration) {
1606
+ await rpc.dispose();
1607
+ throw new Error('Lazy RPC launch was superseded');
1608
+ }
1609
+ activeRpc = rpc;
1626
1610
  set$5(rpcId, rpc);
1611
+ return rpc;
1627
1612
  };
1628
1613
  const ensureRpc = async () => {
1614
+ if (activeRpc) {
1615
+ return activeRpc;
1616
+ }
1629
1617
  if (!rpcPromise) {
1630
- rpcPromise = createRpc();
1618
+ const pending = createRpc(generation);
1619
+ rpcPromise = pending;
1620
+ void pending.catch(() => {
1621
+ if (rpcPromise === pending) {
1622
+ rpcPromise = undefined;
1623
+ }
1624
+ });
1631
1625
  }
1632
- await rpcPromise;
1626
+ return rpcPromise;
1627
+ };
1628
+ const clear = async (reason, notify) => {
1629
+ generation++;
1630
+ const rpc = activeRpc;
1631
+ activeRpc = undefined;
1632
+ rpcPromise = undefined;
1633
+ if (rpc && get(rpcId) === rpc) {
1634
+ remove$5(rpcId);
1635
+ }
1636
+ if (notify) {
1637
+ for (const listener of resetListeners) {
1638
+ listener(reason);
1639
+ }
1640
+ }
1641
+ await rpc?.dispose();
1633
1642
  };
1634
1643
  return {
1644
+ dispose() {
1645
+ return clear(undefined, false);
1646
+ },
1635
1647
  async invoke(method, ...params) {
1636
- await ensureRpc();
1637
- const rpc = get(rpcId);
1648
+ const rpc = await ensureRpc();
1638
1649
  return rpc.invoke(method, ...params);
1639
1650
  },
1640
1651
  async invokeAndTransfer(method, ...params) {
1641
- await ensureRpc();
1642
- const rpc = get(rpcId);
1652
+ const rpc = await ensureRpc();
1643
1653
  return rpc.invokeAndTransfer(method, ...params);
1644
1654
  },
1655
+ onDidReset(listener) {
1656
+ resetListeners.add(listener);
1657
+ return () => {
1658
+ resetListeners.delete(listener);
1659
+ };
1660
+ },
1661
+ reset(reason) {
1662
+ return clear(reason, true);
1663
+ },
1645
1664
  setFactory(value) {
1646
1665
  factory = value;
1647
1666
  }
1648
1667
  };
1649
1668
  };
1650
1669
 
1670
+ const {
1671
+ set: set$2
1672
+ } = create(RendererProcess);
1673
+
1674
+ const {
1675
+ invoke: invoke$2,
1676
+ invokeAndTransfer,
1677
+ set: set$1
1678
+ } = create(RendererWorker);
1679
+ const sendMessagePortToRendererProcess = async port => {
1680
+ const command = 'HandleMessagePort.handleMessagePort';
1681
+ await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToRendererProcess', port, command, DebugWorker);
1682
+ };
1683
+ const sendMessagePortToFileSystemProcess$1 = async (port, rpcId) => {
1684
+ const command = 'HandleMessagePortForFileSystemProcess.handleMessagePortForFileSystemProcess';
1685
+ await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToSharedProcess', port, command, rpcId);
1686
+ };
1687
+ const sendMessagePortToExtensionManagementWorker = async (port, rpcId) => {
1688
+ const command = 'Extensions.handleMessagePort';
1689
+ await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToExtensionManagementWorker', port, command, rpcId);
1690
+ };
1691
+
1651
1692
  const remove$3 = async dirent => {
1652
1693
  throw new Error('not implemented');
1653
1694
  };
@@ -1674,9 +1715,6 @@ const exists$3 = async uri => {
1674
1715
  const readDirWithFileTypes$3 = async uri => {
1675
1716
  throw new Error('not implemented');
1676
1717
  };
1677
- const getPathSeparator$3 = async root => {
1678
- return '/';
1679
- };
1680
1718
  const readJson$3 = async uri => {
1681
1719
  const response = await fetch(uri);
1682
1720
  if (!response.ok) {
@@ -1716,7 +1754,6 @@ const FileSystemFetch = {
1716
1754
  createFile: createFile$2,
1717
1755
  exists: exists$3,
1718
1756
  getFolderSize: getFolderSize$3,
1719
- getPathSeparator: getPathSeparator$3,
1720
1757
  getRealPath: getRealPath$3,
1721
1758
  mkdir: mkdir$3,
1722
1759
  readDirWithFileTypes: readDirWithFileTypes$3,
@@ -1748,7 +1785,6 @@ const {
1748
1785
  copy: copy$2,
1749
1786
  exists: exists$2,
1750
1787
  getFolderSize: getFolderSize$2,
1751
- getPathSeparator: getPathSeparator$2,
1752
1788
  getRealPath: getRealPath$2,
1753
1789
  invoke: invoke$1,
1754
1790
  mkdir: mkdir$2,
@@ -1890,9 +1926,6 @@ const exists$1 = async uri => {
1890
1926
  const readDirWithFileTypes$1 = async uri => {
1891
1927
  throw new Error('not implemented');
1892
1928
  };
1893
- const getPathSeparator$1 = async root => {
1894
- return '/';
1895
- };
1896
1929
  const readJson$1 = async uri => {
1897
1930
  throw new Error('not implemented');
1898
1931
  };
@@ -1934,7 +1967,6 @@ const FileSystemMemory = {
1934
1967
  createFile: createFile$1,
1935
1968
  exists: exists$1,
1936
1969
  getFolderSize: getFolderSize$1,
1937
- getPathSeparator: getPathSeparator$1,
1938
1970
  getRealPath: getRealPath$1,
1939
1971
  mkdir: mkdir$1,
1940
1972
  readDirWithFileTypes: readDirWithFileTypes$1,
@@ -1999,9 +2031,6 @@ const readDirWithFileTypes = async uri => {
1999
2031
  }
2000
2032
  return readDirWithFileTypes$2(uri);
2001
2033
  };
2002
- const getPathSeparator = async root => {
2003
- return getPathSeparator$2(root);
2004
- };
2005
2034
  const isReadonly = async uri => {
2006
2035
  return invoke$1('FileSystem.isReadonly', uri);
2007
2036
  };
@@ -2105,7 +2134,6 @@ const FileSystemDisk = {
2105
2134
  getFileHash,
2106
2135
  getFileHashes,
2107
2136
  getFolderSize,
2108
- getPathSeparator,
2109
2137
  getRealPath,
2110
2138
  isReadonly,
2111
2139
  mkdir,
@@ -2120,6 +2148,250 @@ const FileSystemDisk = {
2120
2148
  writeFile
2121
2149
  };
2122
2150
 
2151
+ const createGlobImplementation = () => {
2152
+ const batchSize = 32;
2153
+ /* eslint-disable unicorn/consistent-function-scoping -- Keep implementation helpers lazy to stay within the worker memory budget. */
2154
+
2155
+ const joinPath = (base, name) => {
2156
+ return base ? `${base}/${name}` : name;
2157
+ };
2158
+ const joinUri = (base, name) => {
2159
+ return base.endsWith('/') ? `${base}${name}` : `${base}/${name}`;
2160
+ };
2161
+ const escapeRegexCharacter = character => {
2162
+ return /[\\^$.*+?()[\]|{}]/.test(character) ? `\\${character}` : character;
2163
+ };
2164
+ const getCharacterClass = (pattern, index) => {
2165
+ const endIndex = pattern.indexOf(']', index + 1);
2166
+ if (endIndex === -1) {
2167
+ return undefined;
2168
+ }
2169
+ let contents = pattern.slice(index + 1, endIndex).replaceAll('\\', '\\\\');
2170
+ if (contents.startsWith('!')) {
2171
+ contents = `^${contents.slice(1)}`;
2172
+ }
2173
+ return {
2174
+ endIndex,
2175
+ source: `[${contents}]`
2176
+ };
2177
+ };
2178
+ const getAsteriskToken = (pattern, index) => {
2179
+ if (pattern[index + 1] !== '*') {
2180
+ return {
2181
+ endIndex: index,
2182
+ source: '[^/]*'
2183
+ };
2184
+ }
2185
+ if (pattern[index + 2] === '/') {
2186
+ return {
2187
+ endIndex: index + 2,
2188
+ source: '(?:.*/)?'
2189
+ };
2190
+ }
2191
+ return {
2192
+ endIndex: index + 1,
2193
+ source: '.*'
2194
+ };
2195
+ };
2196
+ const getCharacterClassToken = (pattern, index) => {
2197
+ return getCharacterClass(pattern, index) || {
2198
+ endIndex: index,
2199
+ source: '\\['
2200
+ };
2201
+ };
2202
+ const getEscapeToken = (pattern, index) => {
2203
+ const nextCharacter = pattern[index + 1];
2204
+ if (!nextCharacter) {
2205
+ return {
2206
+ endIndex: index,
2207
+ source: '\\\\'
2208
+ };
2209
+ }
2210
+ return {
2211
+ endIndex: index + 1,
2212
+ source: escapeRegexCharacter(nextCharacter)
2213
+ };
2214
+ };
2215
+ const getGlobToken = (pattern, index) => {
2216
+ const character = pattern[index];
2217
+ switch (character) {
2218
+ case '?':
2219
+ return {
2220
+ endIndex: index,
2221
+ source: '[^/]'
2222
+ };
2223
+ case '[':
2224
+ return getCharacterClassToken(pattern, index);
2225
+ case '*':
2226
+ return getAsteriskToken(pattern, index);
2227
+ case '\\':
2228
+ return getEscapeToken(pattern, index);
2229
+ default:
2230
+ return {
2231
+ endIndex: index,
2232
+ source: escapeRegexCharacter(character)
2233
+ };
2234
+ }
2235
+ };
2236
+ const globToRegexSource = pattern => {
2237
+ let source = '';
2238
+ let index = 0;
2239
+ while (index < pattern.length) {
2240
+ const token = getGlobToken(pattern, index);
2241
+ source += token.source;
2242
+ index = token.endIndex + 1;
2243
+ }
2244
+ return source;
2245
+ };
2246
+ const compileGlob = pattern => {
2247
+ const regex = new RegExp(`^${globToRegexSource(pattern)}$`);
2248
+ return path => regex.test(path);
2249
+ };
2250
+ const compileIgnoreRule = line => {
2251
+ let pattern = line.trimEnd();
2252
+ if (!pattern || pattern.startsWith('#')) {
2253
+ return undefined;
2254
+ }
2255
+ let ignored = true;
2256
+ if (pattern.startsWith('!')) {
2257
+ ignored = false;
2258
+ pattern = pattern.slice(1);
2259
+ } else if (pattern.startsWith('\\!') || pattern.startsWith('\\#')) {
2260
+ pattern = pattern.slice(1);
2261
+ }
2262
+ const directoryOnly = pattern.endsWith('/');
2263
+ if (directoryOnly) {
2264
+ pattern = pattern.slice(0, -1);
2265
+ }
2266
+ const anchored = pattern.startsWith('/');
2267
+ if (anchored) {
2268
+ pattern = pattern.slice(1);
2269
+ }
2270
+ if (!pattern) {
2271
+ return undefined;
2272
+ }
2273
+ const prefix = anchored || pattern.includes('/') ? '^' : '(?:^|/)';
2274
+ return {
2275
+ directoryOnly,
2276
+ ignored,
2277
+ regex: new RegExp(`${prefix}${globToRegexSource(pattern)}$`)
2278
+ };
2279
+ };
2280
+ const parseGitIgnore = contents => {
2281
+ const rules = [];
2282
+ for (const line of contents.split(/\r?\n/)) {
2283
+ const rule = compileIgnoreRule(line);
2284
+ if (rule) {
2285
+ rules.push(rule);
2286
+ }
2287
+ }
2288
+ return rules;
2289
+ };
2290
+ const getPathForLayer = (relativePath, layerBasePath) => {
2291
+ if (!layerBasePath) {
2292
+ return relativePath;
2293
+ }
2294
+ return relativePath.slice(layerBasePath.length + 1);
2295
+ };
2296
+ const isIgnored = (relativePath, isDirectory, ignoreLayers) => {
2297
+ let ignored = false;
2298
+ for (const layer of ignoreLayers) {
2299
+ if (layer.basePath && relativePath !== layer.basePath && !relativePath.startsWith(`${layer.basePath}/`)) {
2300
+ continue;
2301
+ }
2302
+ const pathForLayer = getPathForLayer(relativePath, layer.basePath);
2303
+ for (const rule of layer.rules) {
2304
+ const {
2305
+ directoryOnly,
2306
+ ignored: ruleIgnored,
2307
+ regex
2308
+ } = rule;
2309
+ if ((!directoryOnly || isDirectory) && regex.test(pathForLayer)) {
2310
+ ignored = ruleIgnored;
2311
+ }
2312
+ }
2313
+ }
2314
+ return ignored;
2315
+ };
2316
+ const readIgnoreLayer = async (fileSystem, uri, relativePath, entries) => {
2317
+ const gitIgnore = entries.find(entry => entry.name === '.gitignore' && entry.type === File$3);
2318
+ if (!gitIgnore) {
2319
+ return undefined;
2320
+ }
2321
+ try {
2322
+ const contents = await fileSystem.readFile(joinUri(uri, gitIgnore.name));
2323
+ return {
2324
+ basePath: relativePath,
2325
+ rules: parseGitIgnore(contents)
2326
+ };
2327
+ } catch {
2328
+ return undefined;
2329
+ }
2330
+ };
2331
+ const scanDirectory = async (fileSystem, task, isMatch) => {
2332
+ const entries = await fileSystem.readDirWithFileTypes(task.uri);
2333
+ const ignoreLayer = await readIgnoreLayer(fileSystem, task.uri, task.relativePath, entries);
2334
+ const ignoreLayers = ignoreLayer ? [...task.ignoreLayers, ignoreLayer] : task.ignoreLayers;
2335
+ const directories = [];
2336
+ const matches = [];
2337
+ const sortedEntries = entries.toSorted((left, right) => left.name.localeCompare(right.name));
2338
+ for (const entry of sortedEntries) {
2339
+ const relativePath = joinPath(task.relativePath, entry.name);
2340
+ if (entry.type === Directory$1) {
2341
+ if (entry.name !== '.git' && !isIgnored(relativePath, true, ignoreLayers)) {
2342
+ directories.push({
2343
+ ignoreLayers,
2344
+ relativePath,
2345
+ uri: joinUri(task.uri, entry.name)
2346
+ });
2347
+ }
2348
+ } else if (entry.type === File$3 && isMatch(relativePath) && !isIgnored(relativePath, false, ignoreLayers)) {
2349
+ matches.push(joinUri(task.uri, entry.name));
2350
+ }
2351
+ }
2352
+ return {
2353
+ directories,
2354
+ matches
2355
+ };
2356
+ };
2357
+ const globWithFileSystemImplementation = async (fileSystem, root, pattern) => {
2358
+ const isMatch = compileGlob(pattern);
2359
+ const matches = [];
2360
+ let pending = [{
2361
+ ignoreLayers: [],
2362
+ relativePath: '',
2363
+ uri: root
2364
+ }];
2365
+ while (pending.length > 0) {
2366
+ const next = [];
2367
+ for (let index = 0; index < pending.length; index += batchSize) {
2368
+ const batch = pending.slice(index, index + batchSize);
2369
+ const results = await Promise.all(batch.map(task => scanDirectory(fileSystem, task, isMatch)));
2370
+ for (const result of results) {
2371
+ next.push(...result.directories);
2372
+ matches.push(...result.matches);
2373
+ }
2374
+ }
2375
+ pending = next;
2376
+ }
2377
+ return matches.toSorted((left, right) => left.localeCompare(right));
2378
+ };
2379
+
2380
+ /* eslint-enable unicorn/consistent-function-scoping */
2381
+ return globWithFileSystemImplementation;
2382
+ };
2383
+ const createLazyGlobImplementation = () => {
2384
+ let implementation;
2385
+ return async (fileSystem, root, pattern) => {
2386
+ implementation ||= createGlobImplementation();
2387
+ return implementation(fileSystem, root, pattern);
2388
+ };
2389
+ };
2390
+ const globWithFileSystem = createLazyGlobImplementation();
2391
+ const glob = async (root, pattern) => {
2392
+ return globWithFileSystem(FileSystemDisk, root, pattern);
2393
+ };
2394
+
2123
2395
  const handleMessagePort = async (port, rpcId) => {
2124
2396
  const rpc = await create$6({
2125
2397
  commandMap: {},
@@ -2319,8 +2591,8 @@ const commandMap = {
2319
2591
  'FileSystem.getFileHash': getFileHash,
2320
2592
  'FileSystem.getFileHashes': getFileHashes,
2321
2593
  'FileSystem.getFolderSize': getFolderSize,
2322
- 'FileSystem.getPathSeparator': getPathSeparator,
2323
2594
  'FileSystem.getRealPath': getRealPath,
2595
+ 'FileSystem.glob': glob,
2324
2596
  'FileSystem.handleMessagePort': handleMessagePort,
2325
2597
  'FileSystem.isReadonly': isReadonly,
2326
2598
  'FileSystem.mkdir': mkdir,
@@ -2361,7 +2633,7 @@ const initializeExtensionHostWorker = async () => {
2361
2633
  try {
2362
2634
  const rpc = await create$4({
2363
2635
  commandMap: {},
2364
- send: sendMessagePortToExtensionHostWorker
2636
+ send: port => sendMessagePortToExtensionManagementWorker(port, 0)
2365
2637
  });
2366
2638
  set$4(rpc);
2367
2639
  } catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/file-system-worker",
3
- "version": "5.17.0",
3
+ "version": "5.18.1",
4
4
  "description": "File System Worker",
5
5
  "keywords": [
6
6
  "Lvce Editor"