@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,62 @@
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
+ import { regExpFlags } from './strings';
6
+ import { URI } from './uri';
7
+
8
+ export function stringify(obj: any): string {
9
+ return JSON.stringify(obj, replacer);
10
+ }
11
+
12
+ export function parse(text: string): any {
13
+ let data = JSON.parse(text);
14
+ data = revive(data, 0);
15
+ return data;
16
+ }
17
+
18
+ export interface MarshalledObject {
19
+ $mid: number;
20
+ }
21
+
22
+ function replacer(key: string, value: any): any {
23
+ // URI is done via toJSON-member
24
+ if (value instanceof RegExp) {
25
+ return {
26
+ $mid: 2,
27
+ source: value.source,
28
+ flags: regExpFlags(value),
29
+ };
30
+ }
31
+ return value;
32
+ }
33
+
34
+ export function revive(obj: any, depth = 0): any {
35
+ if (!obj || depth > 200) {
36
+ return obj;
37
+ }
38
+
39
+ if (typeof obj === 'object') {
40
+ switch ((obj as MarshalledObject).$mid) {
41
+ case 1:
42
+ return URI.revive(obj);
43
+ case 2:
44
+ return new RegExp(obj.source, obj.flags);
45
+ }
46
+
47
+ if (Array.isArray(obj)) {
48
+ for (let i = 0; i < obj.length; ++i) {
49
+ obj[i] = revive(obj[i], depth + 1);
50
+ }
51
+ } else {
52
+ // walk object
53
+ for (const key in obj) {
54
+ if (Object.hasOwnProperty.call(obj, key)) {
55
+ obj[key] = revive(obj[key], depth + 1);
56
+ }
57
+ }
58
+ }
59
+ }
60
+
61
+ return obj;
62
+ }
package/src/objects.ts ADDED
@@ -0,0 +1,145 @@
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/1.44.0/src/vs/base/common/objects.ts
6
+
7
+ import { isUndefinedOrNull, isArray, isObject } from './types';
8
+
9
+ const _hasOwnProperty = Object.prototype.hasOwnProperty;
10
+
11
+ export function deepFreeze<T>(obj: T): T {
12
+ if (!obj || typeof obj !== 'object') {
13
+ return obj;
14
+ }
15
+ const stack: any[] = [obj];
16
+ while (stack.length > 0) {
17
+ const objectToFreeze = stack.shift();
18
+ Object.freeze(objectToFreeze);
19
+ for (const key in objectToFreeze) {
20
+ if (_hasOwnProperty.call(objectToFreeze, key)) {
21
+ const prop = objectToFreeze[key];
22
+ if (typeof prop === 'object' && !Object.isFrozen(prop)) {
23
+ stack.push(prop);
24
+ }
25
+ }
26
+ }
27
+ }
28
+ return obj;
29
+ }
30
+
31
+ export function cloneAndChange(obj: any, changer: (orig: any) => any): any {
32
+ return _cloneAndChange(obj, changer, new Set());
33
+ }
34
+
35
+ function _cloneAndChange(obj: any, changer: (orig: any) => any, seen: Set<any>): any {
36
+ if (isUndefinedOrNull(obj)) {
37
+ return obj;
38
+ }
39
+
40
+ const changed = changer(obj);
41
+ if (typeof changed !== 'undefined') {
42
+ return changed;
43
+ }
44
+
45
+ if (isArray(obj)) {
46
+ const r1: any[] = [];
47
+ for (const e of obj) {
48
+ r1.push(_cloneAndChange(e, changer, seen));
49
+ }
50
+ return r1;
51
+ }
52
+
53
+ if (isObject(obj)) {
54
+ if (seen.has(obj)) {
55
+ throw new Error('Cannot clone recursive data-structure');
56
+ }
57
+ seen.add(obj);
58
+ const r2 = {};
59
+ for (const i2 in obj) {
60
+ if (_hasOwnProperty.call(obj, i2)) {
61
+ (r2 as any)[i2] = _cloneAndChange(obj[i2], changer, seen);
62
+ }
63
+ }
64
+ seen.delete(obj);
65
+ return r2;
66
+ }
67
+
68
+ return obj;
69
+ }
70
+
71
+ export function deepClone<T>(obj: T): T {
72
+ if (!obj || typeof obj !== 'object') {
73
+ return obj;
74
+ }
75
+ if (obj instanceof RegExp) {
76
+ return obj;
77
+ }
78
+ const result: any = Array.isArray(obj) ? [] : {};
79
+ Object.keys(obj).forEach((key: string) => {
80
+ const prop = (obj as any)[key];
81
+ if (prop && typeof prop === 'object') {
82
+ result[key] = deepClone(prop);
83
+ } else {
84
+ result[key] = prop;
85
+ }
86
+ });
87
+ return result;
88
+ }
89
+
90
+ export function isPlainObject(obj: object) {
91
+ return typeof obj === 'object' && obj.constructor === Object;
92
+ }
93
+
94
+ export function removeUndefined<T extends object = any>(obj: T): T {
95
+ if (!isPlainObject(obj)) {
96
+ return obj;
97
+ }
98
+ const keys = Object.keys(obj);
99
+ keys.forEach((key) => {
100
+ if (obj[key] === undefined) {
101
+ delete obj[key];
102
+ }
103
+ });
104
+ return obj;
105
+ }
106
+
107
+ export function cloneAndChangeByKV(obj: any, changer: (key: string, orig: any) => any): any {
108
+ return _cloneAndChangeByKV(obj, changer, new Set());
109
+ }
110
+
111
+ function _cloneAndChangeByKV(obj: any, changer: (key: string, orig: any) => any, seen: Set<any>): any {
112
+ if (isUndefinedOrNull(obj)) {
113
+ return obj;
114
+ }
115
+
116
+ if (isArray(obj)) {
117
+ const r1: any[] = [];
118
+ for (const e of obj) {
119
+ r1.push(_cloneAndChangeByKV(e, changer, seen));
120
+ }
121
+ return r1;
122
+ }
123
+
124
+ if (isObject(obj)) {
125
+ if (seen.has(obj)) {
126
+ throw new Error('Cannot clone recursive data-structure');
127
+ }
128
+ seen.add(obj);
129
+ const r2 = {};
130
+ for (const i2 in obj) {
131
+ if (_hasOwnProperty.call(obj, i2)) {
132
+ const changed = changer(i2, obj[i2]);
133
+ if (typeof changed !== 'undefined') {
134
+ (r2 as any)[i2] = changed;
135
+ } else {
136
+ (r2 as any)[i2] = _cloneAndChangeByKV(obj[i2], changer, seen);
137
+ }
138
+ }
139
+ }
140
+ seen.delete(obj);
141
+ return r2;
142
+ }
143
+
144
+ return obj;
145
+ }
package/src/os.ts ADDED
@@ -0,0 +1,76 @@
1
+ /** ******************************************************************************
2
+ * Copyright (C) 2017 TypeFox 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 { isWindows, isMacintosh, OperatingSystem } from './platform';
18
+
19
+ export type CMD = [string, string[]];
20
+ export function cmd(command: string, ...args: string[]): CMD {
21
+ return [isWindows ? 'cmd' : command, isWindows ? ['/c', command, ...args] : args];
22
+ }
23
+
24
+ export namespace OS {
25
+ export enum Type {
26
+ Windows = OperatingSystem.Windows,
27
+ Linux = OperatingSystem.Linux,
28
+ OSX = OperatingSystem.Macintosh,
29
+ }
30
+
31
+ export function type(): OperatingSystem {
32
+ if (isWindows) {
33
+ return OperatingSystem.Windows;
34
+ }
35
+ if (isMacintosh) {
36
+ return OperatingSystem.Macintosh;
37
+ }
38
+ return OperatingSystem.Linux;
39
+ }
40
+ }
41
+
42
+ export function isNodeIntegrated(): boolean {
43
+ return typeof module !== 'undefined' && !!module.exports;
44
+ }
45
+
46
+ export function isElectronEnv(): boolean {
47
+ return isElectronRenderer() || isElectronNode();
48
+ }
49
+
50
+ export function isElectronRenderer() {
51
+ return (
52
+ (global as any).isElectronRenderer ||
53
+ (typeof navigator === 'object' &&
54
+ typeof navigator.userAgent === 'string' &&
55
+ navigator.userAgent.indexOf('Electron') >= 0)
56
+ );
57
+ }
58
+
59
+ export function isElectronNode() {
60
+ return process && process.env && !!process.env.ELECTRON_RUN_AS_NODE;
61
+ }
62
+
63
+ export function isDevelopment() {
64
+ return (global as any).isDev || (process && process.env.IS_DEV);
65
+ }
66
+
67
+ /**
68
+ * 在 Electron 中,会将 opensumi 中的 extension-host 使用 webpack 打成一个,所以需要其他方法来获取原始的 require
69
+ */
70
+ declare let __webpack_require__: any;
71
+ declare let __non_webpack_require__: any;
72
+
73
+ // https://github.com/webpack/webpack/issues/4175#issuecomment-342931035
74
+ export function getNodeRequire() {
75
+ return typeof __webpack_require__ === 'function' ? __non_webpack_require__ : require;
76
+ }