@opensumi/ide-utils 2.21.13 → 2.22.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.
Files changed (114) hide show
  1. package/lib/arrays.d.ts +3 -3
  2. package/lib/arrays.d.ts.map +1 -1
  3. package/lib/arrays.js.map +1 -1
  4. package/lib/async.d.ts +3 -3
  5. package/lib/async.d.ts.map +1 -1
  6. package/lib/buffer.js +4 -4
  7. package/lib/buffer.js.map +1 -1
  8. package/lib/character-classifier.js +3 -3
  9. package/lib/character-classifier.js.map +1 -1
  10. package/lib/decorators.d.ts +1 -1
  11. package/lib/decorators.d.ts.map +1 -1
  12. package/lib/encoding.d.ts +7 -1
  13. package/lib/encoding.d.ts.map +1 -1
  14. package/lib/encoding.js +15 -2
  15. package/lib/encoding.js.map +1 -1
  16. package/lib/errors.d.ts +2 -2
  17. package/lib/errors.d.ts.map +1 -1
  18. package/lib/event.d.ts +2 -2
  19. package/lib/event.d.ts.map +1 -1
  20. package/lib/filters.d.ts +3 -3
  21. package/lib/filters.d.ts.map +1 -1
  22. package/lib/filters.js +25 -25
  23. package/lib/filters.js.map +1 -1
  24. package/lib/glob.d.ts +2 -2
  25. package/lib/glob.d.ts.map +1 -1
  26. package/lib/glob.js +1 -1
  27. package/lib/glob.js.map +1 -1
  28. package/lib/hash.js +10 -10
  29. package/lib/hash.js.map +1 -1
  30. package/lib/iterator.d.ts +1 -1
  31. package/lib/iterator.d.ts.map +1 -1
  32. package/lib/linked-text.d.ts +1 -1
  33. package/lib/linked-text.d.ts.map +1 -1
  34. package/lib/linked-text.js.map +1 -1
  35. package/lib/map.js +17 -17
  36. package/lib/map.js.map +1 -1
  37. package/lib/objects.d.ts +1 -0
  38. package/lib/objects.d.ts.map +1 -1
  39. package/lib/objects.js +38 -1
  40. package/lib/objects.js.map +1 -1
  41. package/lib/os.d.ts +1 -8
  42. package/lib/os.d.ts.map +1 -1
  43. package/lib/os.js +4 -8
  44. package/lib/os.js.map +1 -1
  45. package/lib/path.d.ts +1 -1
  46. package/lib/path.d.ts.map +1 -1
  47. package/lib/path.js +29 -29
  48. package/lib/path.js.map +1 -1
  49. package/lib/platform.js +8 -8
  50. package/lib/platform.js.map +1 -1
  51. package/lib/process.d.ts.map +1 -1
  52. package/lib/process.js +28 -13
  53. package/lib/process.js.map +1 -1
  54. package/lib/progress.js +3 -3
  55. package/lib/progress.js.map +1 -1
  56. package/lib/strings.js +9 -9
  57. package/lib/strings.js.map +1 -1
  58. package/lib/types.d.ts +5 -1
  59. package/lib/types.d.ts.map +1 -1
  60. package/lib/types.js +8 -1
  61. package/lib/types.js.map +1 -1
  62. package/lib/uint.js +4 -4
  63. package/lib/uint.js.map +1 -1
  64. package/lib/uri.js +8 -8
  65. package/lib/uri.js.map +1 -1
  66. package/lib/uuid.d.ts +1 -1
  67. package/lib/uuid.d.ts.map +1 -1
  68. package/lib/uuid.js +3 -2
  69. package/lib/uuid.js.map +1 -1
  70. package/package.json +8 -6
  71. package/src/ansi.ts +10 -0
  72. package/src/argv.ts +57 -0
  73. package/src/arrays.ts +328 -0
  74. package/src/async.ts +580 -0
  75. package/src/buffer.ts +290 -0
  76. package/src/cache.ts +37 -0
  77. package/src/cancellation.ts +136 -0
  78. package/src/charCode.ts +425 -0
  79. package/src/character-classifier.ts +82 -0
  80. package/src/const/encoding.ts +242 -0
  81. package/src/const/index.ts +1 -0
  82. package/src/date.ts +36 -0
  83. package/src/decorators.ts +166 -0
  84. package/src/disposable.ts +377 -0
  85. package/src/encoding.ts +278 -0
  86. package/src/errors.ts +192 -0
  87. package/src/event.ts +1024 -0
  88. package/src/file-uri.ts +41 -0
  89. package/src/filters.ts +887 -0
  90. package/src/functional.ts +43 -0
  91. package/src/glob.ts +752 -0
  92. package/src/hash.ts +336 -0
  93. package/src/iconLabels.ts +149 -0
  94. package/src/index.ts +40 -0
  95. package/src/iterator.ts +36 -0
  96. package/src/lifecycle.ts +48 -0
  97. package/src/linked-list.ts +144 -0
  98. package/src/linked-text.ts +55 -0
  99. package/src/lru-map.ts +133 -0
  100. package/src/map.ts +934 -0
  101. package/src/marshalling.ts +62 -0
  102. package/src/objects.ts +145 -0
  103. package/src/os.ts +76 -0
  104. package/src/path.ts +1885 -0
  105. package/src/platform.ts +194 -0
  106. package/src/process.ts +43 -0
  107. package/src/progress.ts +83 -0
  108. package/src/promises.ts +23 -0
  109. package/src/sequence.ts +28 -0
  110. package/src/strings.ts +1002 -0
  111. package/src/types.ts +214 -0
  112. package/src/uint.ts +59 -0
  113. package/src/uri.ts +298 -0
  114. package/src/uuid.ts +6 -0
@@ -0,0 +1,194 @@
1
+ /* ---------------------------------------------------------------------------------------------
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License. See License.txt in the project root for license information.
4
+ *--------------------------------------------------------------------------------------------*/
5
+ // Some code copied and modified from https://github.com/microsoft/vscode/blob/01d1ea52e639615c4513689ce66576829438f748/src/vs/base/common/platform.ts
6
+
7
+ const LANGUAGE_DEFAULT = 'en';
8
+
9
+ let _isWindows = false;
10
+ let _isMacintosh = false;
11
+ let _isLinux = false;
12
+ let _isNative = false;
13
+ let _isWeb = false;
14
+ let _locale: string | undefined;
15
+ let _language: string = LANGUAGE_DEFAULT;
16
+ let _translationsConfigFile: string | undefined;
17
+ let _isWebKit = false;
18
+
19
+ interface NLSConfig {
20
+ locale: string;
21
+ availableLanguages: { [key: string]: string };
22
+ _translationsConfigFile: string;
23
+ }
24
+
25
+ export interface IProcessEnvironment {
26
+ [key: string]: string | null | undefined;
27
+ }
28
+
29
+ interface INodeProcess {
30
+ platform: string;
31
+ env: IProcessEnvironment;
32
+ getuid(): number;
33
+ nextTick: any;
34
+ versions?: {
35
+ electron?: string;
36
+ };
37
+ type?: string;
38
+ }
39
+ declare const process: INodeProcess;
40
+ declare const global: any;
41
+
42
+ interface INavigator {
43
+ userAgent: string;
44
+ language: string;
45
+ }
46
+ declare const navigator: INavigator;
47
+ declare const self: any;
48
+
49
+ const isElectronRenderer =
50
+ typeof process !== 'undefined' &&
51
+ typeof process.versions !== 'undefined' &&
52
+ typeof process.versions.electron !== 'undefined' &&
53
+ process.type === 'renderer';
54
+
55
+ // OS detection
56
+ if (typeof navigator === 'object' && !isElectronRenderer) {
57
+ const userAgent = navigator.userAgent;
58
+ _isWindows = userAgent.indexOf('Windows') >= 0;
59
+ _isMacintosh = userAgent.indexOf('Macintosh') >= 0;
60
+ _isLinux = userAgent.indexOf('Linux') >= 0;
61
+ _isWeb = true;
62
+ _locale = navigator.language;
63
+ _language = _locale;
64
+ _isWebKit = userAgent.indexOf('AppleWebKit') >= 0;
65
+ } else if (typeof process === 'object') {
66
+ _isWindows = process.platform === 'win32';
67
+ _isMacintosh = process.platform === 'darwin';
68
+ _isLinux = process.platform === 'linux';
69
+ _locale = LANGUAGE_DEFAULT;
70
+ _language = LANGUAGE_DEFAULT;
71
+ const rawNlsConfig = process.env['VSCODE_NLS_CONFIG'];
72
+ if (rawNlsConfig) {
73
+ try {
74
+ const nlsConfig: NLSConfig = JSON.parse(rawNlsConfig);
75
+ const resolved = nlsConfig.availableLanguages['*'];
76
+ _locale = nlsConfig.locale;
77
+ // VSCode's default language is 'en'
78
+ _language = resolved ? resolved : LANGUAGE_DEFAULT;
79
+ _translationsConfigFile = nlsConfig._translationsConfigFile;
80
+ } catch (e) {}
81
+ }
82
+ _isNative = true;
83
+ }
84
+
85
+ export const enum Platform {
86
+ Web,
87
+ Mac,
88
+ Linux,
89
+ Windows,
90
+ }
91
+
92
+ export function PlatformToString(platform: Platform) {
93
+ switch (platform) {
94
+ case Platform.Web:
95
+ return 'Web';
96
+ case Platform.Mac:
97
+ return 'Mac';
98
+ case Platform.Linux:
99
+ return 'Linux';
100
+ case Platform.Windows:
101
+ return 'Windows';
102
+ }
103
+ }
104
+
105
+ let _platform: Platform = Platform.Web;
106
+ if (_isNative) {
107
+ if (_isMacintosh) {
108
+ _platform = Platform.Mac;
109
+ } else if (_isWindows) {
110
+ _platform = Platform.Windows;
111
+ } else if (_isLinux) {
112
+ _platform = Platform.Linux;
113
+ }
114
+ }
115
+
116
+ export const isWindows = _isWindows;
117
+ export const isMacintosh = _isMacintosh;
118
+ export const isOSX = _isMacintosh;
119
+ export const isLinux = _isLinux;
120
+ export const isNative = _isNative;
121
+ export const isWeb = _isWeb;
122
+ export const platform = _platform;
123
+ export const isWebKit = _isWebKit;
124
+
125
+ export function isRootUser(): boolean {
126
+ return _isNative && !_isWindows && process.getuid() === 0;
127
+ }
128
+
129
+ /**
130
+ * The language used for the user interface. The format of
131
+ * the string is all lower case (e.g. zh-tw for Traditional
132
+ * Chinese)
133
+ */
134
+ export const language = _language;
135
+
136
+ export namespace Language {
137
+ export function value(): string {
138
+ return language;
139
+ }
140
+
141
+ export function isDefaultVariant(): boolean {
142
+ if (language.length === 2) {
143
+ return language === 'en';
144
+ } else if (language.length >= 3) {
145
+ return language[0] === 'e' && language[1] === 'n' && language[2] === '-';
146
+ } else {
147
+ return false;
148
+ }
149
+ }
150
+
151
+ export function isDefault(): boolean {
152
+ return language === 'en';
153
+ }
154
+ }
155
+
156
+ /**
157
+ * The OS locale or the locale specified by --locale. The format of
158
+ * the string is all lower case (e.g. zh-tw for Traditional
159
+ * Chinese). The UI is not necessarily shown in the provided locale.
160
+ */
161
+ export const locale = _locale;
162
+
163
+ /**
164
+ * The translatios that are available through language packs.
165
+ */
166
+ export const translationsConfigFile = _translationsConfigFile;
167
+
168
+ const _globals = typeof self === 'object' ? self : typeof global === 'object' ? global : ({} as any);
169
+ export const globals: any = _globals;
170
+
171
+ let _setImmediate: ((callback: (...args: any[]) => void) => number) | null = null;
172
+ export function setImmediate(callback: (...args: any[]) => void): number {
173
+ if (_setImmediate === null) {
174
+ if (globals.setImmediate) {
175
+ _setImmediate = globals.setImmediate.bind(globals);
176
+ } else if (typeof process !== 'undefined' && typeof process.nextTick === 'function') {
177
+ _setImmediate = process.nextTick.bind(process);
178
+ } else {
179
+ _setImmediate = globals.setTimeout.bind(globals);
180
+ }
181
+ }
182
+ return _setImmediate!(callback);
183
+ }
184
+
185
+ export enum OperatingSystem {
186
+ Windows = 1,
187
+ Macintosh = 2,
188
+ Linux = 3,
189
+ }
190
+
191
+ export const userAgent = typeof navigator === 'object' ? navigator.userAgent : null;
192
+
193
+ export const isChrome = userAgent?.indexOf('Chrome')! >= 0;
194
+ export const isSafari = !isChrome && userAgent?.indexOf('Safari')! >= 0;
package/src/process.ts ADDED
@@ -0,0 +1,43 @@
1
+ import { isElectronRenderer } from './os';
2
+ import { isWindows, isMacintosh, setImmediate } from './platform';
3
+
4
+ interface IProcess {
5
+ platform: string;
6
+ env: object;
7
+ cwd(): string;
8
+ nextTick(callback: (...args: any[]) => void): number;
9
+ }
10
+
11
+ declare const process: IProcess;
12
+
13
+ const _safeProcess = {
14
+ cwd(): string {
15
+ return '/';
16
+ },
17
+ env: Object.create(null),
18
+ get platform(): string {
19
+ return isWindows ? 'win32' : isMacintosh ? 'darwin' : 'linux';
20
+ },
21
+ nextTick(callback: (...args: any[]) => void): number {
22
+ return setImmediate(callback);
23
+ },
24
+ };
25
+
26
+ let safeProcess: IProcess;
27
+ if (typeof process === 'undefined') {
28
+ safeProcess = _safeProcess;
29
+ } else {
30
+ // 因为我们不推荐开启 browserNodeIntegrated,所以这里需要检查是否为 Electron Renderer 环境
31
+ if (isElectronRenderer()) {
32
+ safeProcess = _safeProcess;
33
+ } else if (typeof process.cwd === 'undefined') {
34
+ safeProcess = _safeProcess;
35
+ } else {
36
+ safeProcess = process;
37
+ }
38
+ }
39
+
40
+ export const cwd = safeProcess.cwd;
41
+ export const env = safeProcess.env;
42
+ export const platform = safeProcess.platform;
43
+ export const nextTick = safeProcess.nextTick;
@@ -0,0 +1,83 @@
1
+ import { IDisposable } from './disposable';
2
+
3
+ export enum ProgressLocation {
4
+ Explorer = 1,
5
+ Scm = 3,
6
+ Extensions = 5,
7
+ Window = 10,
8
+ Notification = 15,
9
+ Dialog = 20,
10
+ }
11
+
12
+ export interface IAction extends IDisposable {
13
+ readonly id: string;
14
+ label: string;
15
+ tooltip: string;
16
+ class: string | undefined;
17
+ enabled: boolean;
18
+ checked: boolean;
19
+ run(event?: any): Promise<any>;
20
+ }
21
+
22
+ export interface IProgressOptions {
23
+ readonly location: ProgressLocation | string;
24
+ readonly title?: string;
25
+ readonly source?: string;
26
+ readonly total?: number;
27
+ readonly cancellable?: boolean;
28
+ readonly closeable?: boolean;
29
+ // 暂不支持
30
+ readonly buttons?: string[];
31
+ }
32
+
33
+ export interface IProgressNotificationOptions extends IProgressOptions {
34
+ readonly location: ProgressLocation.Notification;
35
+ // 暂不支持
36
+ // readonly primaryActions?: ReadonlyArray<IAction>;
37
+ // readonly secondaryActions?: ReadonlyArray<IAction>;
38
+ readonly delay?: number;
39
+ readonly silent?: boolean;
40
+ }
41
+
42
+ export interface IProgressWindowOptions extends IProgressOptions {
43
+ readonly location: ProgressLocation.Window;
44
+ readonly command?: string;
45
+ }
46
+
47
+ export interface IProgressCompositeOptions extends IProgressOptions {
48
+ readonly location:
49
+ | ProgressLocation.Explorer
50
+ | ProgressLocation.Extensions
51
+ | ProgressLocation.Scm
52
+ | ProgressLocation.Window
53
+ | ProgressLocation.Notification
54
+ | ProgressLocation.Dialog
55
+ | string;
56
+ readonly delay?: number;
57
+ }
58
+
59
+ export interface IProgressStep {
60
+ message?: string;
61
+ increment?: number;
62
+ total?: number;
63
+ }
64
+
65
+ export interface IProgress<T> {
66
+ report(item: T): void;
67
+ }
68
+
69
+ export class Progress<T> implements IProgress<T> {
70
+ static readonly None: IProgress<unknown> = Object.freeze({ report() {} });
71
+
72
+ private _value?: T;
73
+ get value(): T | undefined {
74
+ return this._value;
75
+ }
76
+
77
+ constructor(private callback: (data: T) => void) {}
78
+
79
+ report(item: T) {
80
+ this._value = item;
81
+ this.callback(this._value);
82
+ }
83
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Simple implementation of the deferred pattern.
3
+ * An object that exposes a promise and functions to resolve and reject it.
4
+ */
5
+ export class Deferred<T> {
6
+ resolve: (value?: T | PromiseLike<T>) => void;
7
+ reject: (err?: any) => void;
8
+
9
+ promise = new Promise<T>((resolve, reject) => {
10
+ this.resolve = resolve;
11
+ this.reject = reject;
12
+ });
13
+ }
14
+
15
+ export async function pSeries<T>(tasks: Iterable<() => Promise<T> | T>): Promise<T[]> {
16
+ const results = [] as T[];
17
+
18
+ for (const task of tasks) {
19
+ results.push(await task());
20
+ }
21
+
22
+ return results;
23
+ }
@@ -0,0 +1,28 @@
1
+ import { Event, Emitter } from './event';
2
+
3
+ export interface ISplice<T> {
4
+ readonly start: number;
5
+ readonly deleteCount: number;
6
+ readonly toInsert: T[];
7
+ }
8
+
9
+ export interface ISpliceable<T> {
10
+ splice(start: number, deleteCount: number, toInsert: T[]): void;
11
+ }
12
+
13
+ export interface ISequence<T> {
14
+ readonly elements: T[];
15
+ readonly onDidSplice: Event<ISplice<T>>;
16
+ }
17
+
18
+ export class Sequence<T> implements ISequence<T>, ISpliceable<T> {
19
+ readonly elements: T[] = [];
20
+
21
+ private _onDidSplice = new Emitter<ISplice<T>>();
22
+ readonly onDidSplice: Event<ISplice<T>> = this._onDidSplice.event;
23
+
24
+ splice(start: number, deleteCount: number, toInsert: T[] = []): void {
25
+ this.elements.splice(start, deleteCount, ...toInsert);
26
+ this._onDidSplice.fire({ start, deleteCount, toInsert });
27
+ }
28
+ }