@opensumi/ide-utils 2.21.8-rc-1670567192.0 → 2.21.8

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.
@@ -1,62 +0,0 @@
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 DELETED
@@ -1,105 +0,0 @@
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
- }
package/src/os.ts DELETED
@@ -1,78 +0,0 @@
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
- /**
47
- * @deprecated isElectronEnv is deprecated, please use appConfig#isElectronRenderer instead.
48
- * 框架目前使用 isElectronEnv 的场景基本都与 isElectronRenderer 重复,所以直接废弃 isElectronEnv
49
- */
50
- export function isElectronEnv(): boolean {
51
- return isElectronRenderer() || isElectronNode();
52
- }
53
-
54
- /**
55
- * @deprecated isElectronRenderer will deprecate, please use appConfig#isElectronRenderer instead.
56
- */
57
- export function isElectronRenderer() {
58
- return (global as any).isElectronRenderer;
59
- }
60
-
61
- export function isElectronNode() {
62
- return process && process.env && !!process.env.ELECTRON_RUN_AS_NODE;
63
- }
64
-
65
- export function isDevelopment() {
66
- return (global as any).isDev || (process && process.env.IS_DEV);
67
- }
68
-
69
- /**
70
- * 在 Electron 中,会将 opensumi 中的 extension-host 使用 webpack 打成一个,所以需要其他方法来获取原始的 require
71
- */
72
- declare let __webpack_require__: any;
73
- declare let __non_webpack_require__: any;
74
-
75
- // https://github.com/webpack/webpack/issues/4175#issuecomment-342931035
76
- export function getNodeRequire() {
77
- return typeof __webpack_require__ === 'function' ? __non_webpack_require__ : require;
78
- }