@theia/core 1.38.0-next.38 → 1.38.0-next.43

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.
Files changed (50) hide show
  1. package/README.md +6 -6
  2. package/lib/browser/common-styling-participants.d.ts.map +1 -1
  3. package/lib/browser/common-styling-participants.js +20 -0
  4. package/lib/browser/common-styling-participants.js.map +1 -1
  5. package/lib/browser/endpoint.js +3 -3
  6. package/lib/browser/endpoint.js.map +1 -1
  7. package/lib/browser/keybinding.js +1 -1
  8. package/lib/browser/keybinding.js.map +1 -1
  9. package/lib/browser/label-provider.js +1 -1
  10. package/lib/browser/label-provider.js.map +1 -1
  11. package/lib/browser/preferences/preference-proxy.js +2 -2
  12. package/lib/browser/preferences/preference-proxy.js.map +1 -1
  13. package/lib/browser/tree/search-box-debounce.js +1 -1
  14. package/lib/browser/tree/search-box-debounce.js.map +1 -1
  15. package/lib/browser/widget-decoration.js +1 -1
  16. package/lib/browser/widget-decoration.js.map +1 -1
  17. package/lib/common/glob.js +5 -5
  18. package/lib/common/glob.js.map +1 -1
  19. package/lib/common/path.js +9 -9
  20. package/lib/common/path.js.map +1 -1
  21. package/lib/common/paths.js +1 -1
  22. package/lib/common/paths.js.map +1 -1
  23. package/lib/node/backend-application-module.d.ts.map +1 -1
  24. package/lib/node/backend-application-module.js +2 -0
  25. package/lib/node/backend-application-module.js.map +1 -1
  26. package/lib/node/filesystem-locking.d.ts +24 -0
  27. package/lib/node/filesystem-locking.d.ts.map +1 -0
  28. package/lib/node/filesystem-locking.js +71 -0
  29. package/lib/node/filesystem-locking.js.map +1 -0
  30. package/lib/node/index.d.ts +1 -0
  31. package/lib/node/index.d.ts.map +1 -1
  32. package/lib/node/index.js +3 -0
  33. package/lib/node/index.js.map +1 -1
  34. package/lib/node/messaging/ipc-connection-provider.js +1 -1
  35. package/lib/node/messaging/ipc-connection-provider.js.map +1 -1
  36. package/package.json +5 -4
  37. package/src/browser/common-styling-participants.ts +20 -0
  38. package/src/browser/endpoint.ts +3 -3
  39. package/src/browser/keybinding.ts +1 -1
  40. package/src/browser/label-provider.ts +1 -1
  41. package/src/browser/preferences/preference-proxy.ts +2 -2
  42. package/src/browser/tree/search-box-debounce.ts +1 -1
  43. package/src/browser/widget-decoration.ts +1 -1
  44. package/src/common/glob.ts +5 -5
  45. package/src/common/path.ts +9 -9
  46. package/src/common/paths.ts +1 -1
  47. package/src/node/backend-application-module.ts +3 -0
  48. package/src/node/filesystem-locking.ts +77 -0
  49. package/src/node/index.ts +1 -0
  50. package/src/node/messaging/ipc-connection-provider.ts +1 -1
@@ -0,0 +1,77 @@
1
+ // *****************************************************************************
2
+ // Copyright (C) 2023 Ericsson and others.
3
+ //
4
+ // This program and the accompanying materials are made available under the
5
+ // terms of the Eclipse Public License v. 2.0 which is available at
6
+ // http://www.eclipse.org/legal/epl-2.0.
7
+ //
8
+ // This Source Code may also be made available under the following Secondary
9
+ // Licenses when the conditions for such availability set forth in the Eclipse
10
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ // with the GNU Classpath Exception which is available at
12
+ // https://www.gnu.org/software/classpath/license.html.
13
+ //
14
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ import { Mutex } from 'async-mutex';
18
+ import { injectable, interfaces } from 'inversify';
19
+ import * as path from 'path';
20
+
21
+ export const FileSystemLocking = Symbol('FileSystemLocking') as symbol & interfaces.Abstract<FileSystemLocking>;
22
+ /**
23
+ * Use this backend service to help prevent race access to files on disk.
24
+ */
25
+ export interface FileSystemLocking {
26
+ /**
27
+ * Get exclusive access to a file for reading and/or writing.
28
+ * @param lockPath The path to request exclusive access to.
29
+ * @param transaction The job to do while having exclusive access.
30
+ * @param thisArg `this` argument used when calling `transaction`.
31
+ */
32
+ lockPath<T>(lockPath: string, transaction: (lockPath: string) => T | Promise<T>, thisArg?: unknown): Promise<T>;
33
+ }
34
+
35
+ @injectable()
36
+ export class FileSystemLockingImpl implements FileSystemLocking {
37
+
38
+ lockPath<T>(lockPath: string, transaction: (lockPath: string) => T | Promise<T>, thisArg?: unknown): Promise<T> {
39
+ const resolvedLockPath = this.resolveLockPath(lockPath);
40
+ return this.getLock(resolvedLockPath).runExclusive(async () => transaction.call(thisArg, resolvedLockPath));
41
+ }
42
+
43
+ protected resolveLockPath(lockPath: string): string {
44
+ // try to normalize the path to avoid two paths pointing to the same file
45
+ return path.resolve(lockPath);
46
+ }
47
+
48
+ protected getLocks(): Map<string, Mutex> {
49
+ const kLocks = Symbol.for('FileSystemLockingImpl.Locks');
50
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
51
+ return (globalThis as any)[kLocks] ??= this.initializeLocks();
52
+ }
53
+
54
+ protected initializeLocks(): Map<string, Mutex> {
55
+ const locks = new Map();
56
+ const cleanup = setInterval(() => this.cleanupLocks(locks), 60_000);
57
+ process.once('beforeExit', () => clearInterval(cleanup));
58
+ return locks;
59
+ }
60
+
61
+ protected cleanupLocks(locks: Map<string, Mutex>): void {
62
+ locks.forEach((lock, lockPath) => {
63
+ if (!lock.isLocked()) {
64
+ locks.delete(lockPath);
65
+ }
66
+ });
67
+ }
68
+
69
+ protected getLock(lockPath: string): Mutex {
70
+ const locks = this.getLocks();
71
+ let lock = locks.get(lockPath);
72
+ if (!lock) {
73
+ locks.set(lockPath, lock = new Mutex());
74
+ }
75
+ return lock;
76
+ }
77
+ }
package/src/node/index.ts CHANGED
@@ -19,3 +19,4 @@ export * from './debug';
19
19
  export * from './file-uri';
20
20
  export * from './messaging';
21
21
  export * from './cli';
22
+ export { FileSystemLocking } from './filesystem-locking';
@@ -90,7 +90,7 @@ export class IPCConnectionProvider {
90
90
  const inspectArgPrefix = `--${options.serverName}-inspect`;
91
91
  const inspectArg = process.argv.find(v => v.startsWith(inspectArgPrefix));
92
92
  if (inspectArg !== undefined) {
93
- forkOptions.execArgv = ['--nolazy', `--inspect${inspectArg.substr(inspectArgPrefix.length)}`];
93
+ forkOptions.execArgv = ['--nolazy', `--inspect${inspectArg.substring(inspectArgPrefix.length)}`];
94
94
  }
95
95
 
96
96
  const childProcess = cp.fork(path.join(__dirname, 'ipc-bootstrap'), options.args, forkOptions);