@theia/plugin-utils 1.75.0-next.28

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 (122) hide show
  1. package/README.md +30 -0
  2. package/lib/common/constants.d.ts +12 -0
  3. package/lib/common/constants.d.ts.map +1 -0
  4. package/lib/common/constants.js +30 -0
  5. package/lib/common/constants.js.map +1 -0
  6. package/lib/common/constants.spec.d.ts +2 -0
  7. package/lib/common/constants.spec.d.ts.map +1 -0
  8. package/lib/common/constants.spec.js +33 -0
  9. package/lib/common/constants.spec.js.map +1 -0
  10. package/lib/common/contribution-types.d.ts +648 -0
  11. package/lib/common/contribution-types.d.ts.map +1 -0
  12. package/lib/common/contribution-types.js +30 -0
  13. package/lib/common/contribution-types.js.map +1 -0
  14. package/lib/common/manifest-types.d.ts +105 -0
  15. package/lib/common/manifest-types.d.ts.map +1 -0
  16. package/lib/common/manifest-types.js +31 -0
  17. package/lib/common/manifest-types.js.map +1 -0
  18. package/lib/common/manifest-types.spec.d.ts +2 -0
  19. package/lib/common/manifest-types.spec.d.ts.map +1 -0
  20. package/lib/common/manifest-types.spec.js +35 -0
  21. package/lib/common/manifest-types.spec.js.map +1 -0
  22. package/lib/common/package-nls.d.ts +24 -0
  23. package/lib/common/package-nls.d.ts.map +1 -0
  24. package/lib/common/package-nls.js +82 -0
  25. package/lib/common/package-nls.js.map +1 -0
  26. package/lib/common/package-nls.spec.d.ts +2 -0
  27. package/lib/common/package-nls.spec.d.ts.map +1 -0
  28. package/lib/common/package-nls.spec.js +98 -0
  29. package/lib/common/package-nls.spec.js.map +1 -0
  30. package/lib/common/plugin-activation-events.d.ts +7 -0
  31. package/lib/common/plugin-activation-events.d.ts.map +1 -0
  32. package/lib/common/plugin-activation-events.js +95 -0
  33. package/lib/common/plugin-activation-events.js.map +1 -0
  34. package/lib/common/plugin-activation-events.spec.d.ts +2 -0
  35. package/lib/common/plugin-activation-events.spec.d.ts.map +1 -0
  36. package/lib/common/plugin-activation-events.spec.js +89 -0
  37. package/lib/common/plugin-activation-events.spec.js.map +1 -0
  38. package/lib/common/plugin-manifest.d.ts +10 -0
  39. package/lib/common/plugin-manifest.d.ts.map +1 -0
  40. package/lib/common/plugin-manifest.js +35 -0
  41. package/lib/common/plugin-manifest.js.map +1 -0
  42. package/lib/common/plugin-manifest.spec.d.ts +2 -0
  43. package/lib/common/plugin-manifest.spec.d.ts.map +1 -0
  44. package/lib/common/plugin-manifest.spec.js +83 -0
  45. package/lib/common/plugin-manifest.spec.js.map +1 -0
  46. package/lib/common/plugin-model.d.ts +33 -0
  47. package/lib/common/plugin-model.d.ts.map +1 -0
  48. package/lib/common/plugin-model.js +166 -0
  49. package/lib/common/plugin-model.js.map +1 -0
  50. package/lib/common/plugin-model.spec.d.ts +2 -0
  51. package/lib/common/plugin-model.spec.d.ts.map +1 -0
  52. package/lib/common/plugin-model.spec.js +204 -0
  53. package/lib/common/plugin-model.spec.js.map +1 -0
  54. package/lib/common/protocol-shims.d.ts +128 -0
  55. package/lib/common/protocol-shims.d.ts.map +1 -0
  56. package/lib/common/protocol-shims.js +29 -0
  57. package/lib/common/protocol-shims.js.map +1 -0
  58. package/lib/common/test-helpers.d.ts +5 -0
  59. package/lib/common/test-helpers.d.ts.map +1 -0
  60. package/lib/common/test-helpers.js +41 -0
  61. package/lib/common/test-helpers.js.map +1 -0
  62. package/lib/common/utils.d.ts +20 -0
  63. package/lib/common/utils.d.ts.map +1 -0
  64. package/lib/common/utils.js +74 -0
  65. package/lib/common/utils.js.map +1 -0
  66. package/lib/common/utils.spec.d.ts +2 -0
  67. package/lib/common/utils.spec.d.ts.map +1 -0
  68. package/lib/common/utils.spec.js +77 -0
  69. package/lib/common/utils.spec.js.map +1 -0
  70. package/lib/node/normalize-contributions.d.ts +54 -0
  71. package/lib/node/normalize-contributions.d.ts.map +1 -0
  72. package/lib/node/normalize-contributions.js +985 -0
  73. package/lib/node/normalize-contributions.js.map +1 -0
  74. package/lib/node/normalize-contributions.spec.d.ts +2 -0
  75. package/lib/node/normalize-contributions.spec.d.ts.map +1 -0
  76. package/lib/node/normalize-contributions.spec.js +850 -0
  77. package/lib/node/normalize-contributions.spec.js.map +1 -0
  78. package/lib/node/package-nls.d.ts +3 -0
  79. package/lib/node/package-nls.d.ts.map +1 -0
  80. package/lib/node/package-nls.js +45 -0
  81. package/lib/node/package-nls.js.map +1 -0
  82. package/lib/node/plugin-manifest.d.ts +6 -0
  83. package/lib/node/plugin-manifest.d.ts.map +1 -0
  84. package/lib/node/plugin-manifest.js +26 -0
  85. package/lib/node/plugin-manifest.js.map +1 -0
  86. package/lib/node/plugin-model.d.ts +5 -0
  87. package/lib/node/plugin-model.d.ts.map +1 -0
  88. package/lib/node/plugin-model.js +36 -0
  89. package/lib/node/plugin-model.js.map +1 -0
  90. package/lib/node/read-grammars.d.ts +10 -0
  91. package/lib/node/read-grammars.d.ts.map +1 -0
  92. package/lib/node/read-grammars.js +83 -0
  93. package/lib/node/read-grammars.js.map +1 -0
  94. package/lib/node/read-grammars.spec.d.ts +2 -0
  95. package/lib/node/read-grammars.spec.d.ts.map +1 -0
  96. package/lib/node/read-grammars.spec.js +109 -0
  97. package/lib/node/read-grammars.spec.js.map +1 -0
  98. package/package.json +42 -0
  99. package/src/common/constants.spec.ts +34 -0
  100. package/src/common/constants.ts +35 -0
  101. package/src/common/contribution-types.ts +677 -0
  102. package/src/common/manifest-types.spec.ts +36 -0
  103. package/src/common/manifest-types.ts +126 -0
  104. package/src/common/package-nls.spec.ts +122 -0
  105. package/src/common/package-nls.ts +95 -0
  106. package/src/common/plugin-activation-events.spec.ts +104 -0
  107. package/src/common/plugin-activation-events.ts +102 -0
  108. package/src/common/plugin-manifest.spec.ts +94 -0
  109. package/src/common/plugin-manifest.ts +44 -0
  110. package/src/common/plugin-model.spec.ts +246 -0
  111. package/src/common/plugin-model.ts +194 -0
  112. package/src/common/protocol-shims.ts +148 -0
  113. package/src/common/test-helpers.ts +44 -0
  114. package/src/common/utils.spec.ts +86 -0
  115. package/src/common/utils.ts +81 -0
  116. package/src/node/normalize-contributions.spec.ts +931 -0
  117. package/src/node/normalize-contributions.ts +1098 -0
  118. package/src/node/package-nls.ts +45 -0
  119. package/src/node/plugin-manifest.ts +30 -0
  120. package/src/node/plugin-model.ts +33 -0
  121. package/src/node/read-grammars.spec.ts +128 -0
  122. package/src/node/read-grammars.ts +97 -0
@@ -0,0 +1,86 @@
1
+ // *****************************************************************************
2
+ // Copyright (C) 2026 Maksim Kachurin 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-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ import { expect } from 'chai';
18
+ import { rejects } from 'assert';
19
+ import { promises as fs } from 'fs';
20
+ import { deepClone, isENOENT, isObject, isStringArray } from './utils';
21
+
22
+ describe('utils', () => {
23
+
24
+ describe('isObject', () => {
25
+ it('returns true for plain objects', () => {
26
+ expect(isObject({})).to.equal(true);
27
+ expect(isObject({ a: 1 })).to.equal(true);
28
+ });
29
+
30
+ it('returns false for null and primitives', () => {
31
+ // eslint-disable-next-line no-null/no-null
32
+ expect(isObject(null)).to.equal(false);
33
+ expect(isObject(undefined)).to.equal(false);
34
+ expect(isObject('x')).to.equal(false);
35
+ });
36
+
37
+ it('returns true for arrays because they are objects in JavaScript', () => {
38
+ expect(isObject([])).to.equal(true);
39
+ });
40
+ });
41
+
42
+ describe('isStringArray', () => {
43
+ it('returns true only for string arrays', () => {
44
+ expect(isStringArray(['a', 'b'])).to.equal(true);
45
+ expect(isStringArray([])).to.equal(true);
46
+ });
47
+
48
+ it('returns false for mixed or non-array values', () => {
49
+ expect(isStringArray(['a', 1])).to.equal(false);
50
+ expect(isStringArray('a')).to.equal(false);
51
+ });
52
+ });
53
+
54
+ describe('isENOENT', () => {
55
+ it('detects fs ENOENT errors', async () => {
56
+ await rejects(fs.readFile('definitely-missing-' + Date.now()), reason => isENOENT(reason));
57
+ });
58
+
59
+ it('returns false for plain errors and null', () => {
60
+ expect(isENOENT(new Error('I am not ENOENT'))).to.equal(false);
61
+ // eslint-disable-next-line no-null/no-null
62
+ expect(isENOENT(null)).to.equal(false);
63
+ });
64
+
65
+ it('returns false for other errno codes', async () => {
66
+ await rejects(fs.readdir(__filename), reason => !isENOENT(reason));
67
+ });
68
+ });
69
+
70
+ describe('deepClone', () => {
71
+ it('clones nested objects without sharing references', () => {
72
+ const source = { nested: { value: 1 }, list: [1, 2] };
73
+ const clone = deepClone(source);
74
+ expect(clone).to.deep.equal(source);
75
+ expect(clone).to.not.equal(source);
76
+ expect(clone.nested).to.not.equal(source.nested);
77
+ expect(clone.list).to.not.equal(source.list);
78
+ });
79
+
80
+ it('returns primitives and regexps unchanged', () => {
81
+ expect(deepClone(42)).to.equal(42);
82
+ const re = /abc/;
83
+ expect(deepClone(re)).to.equal(re);
84
+ });
85
+ });
86
+ });
@@ -0,0 +1,81 @@
1
+ // *****************************************************************************
2
+ // Copyright (C) 2026 Maksim Kachurin 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-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ export function isObject(value: unknown): value is Record<string, unknown> {
18
+ // eslint-disable-next-line no-null/no-null
19
+ return typeof value === 'object' && value !== null;
20
+ }
21
+
22
+ export function isStringArray(value: unknown): value is string[] {
23
+ return Array.isArray(value) && value.every(item => typeof item === 'string');
24
+ }
25
+
26
+ export function flatten<T>(arrays: readonly (readonly T[])[]): T[] {
27
+ const result: T[] = [];
28
+ for (const arr of arrays) {
29
+ result.push(...arr);
30
+ }
31
+ return result;
32
+ }
33
+
34
+ export function isColorDefaults(value: unknown): value is { light: string; dark: string; highContrast: string } {
35
+ return isObject(value)
36
+ && typeof value.light === 'string'
37
+ && typeof value.dark === 'string'
38
+ && typeof value.highContrast === 'string';
39
+ }
40
+
41
+ interface Errno {
42
+ readonly code: string;
43
+ readonly errno: number;
44
+ }
45
+
46
+ const ENOENT = 'ENOENT' as const;
47
+
48
+ type ErrnoException = Error & Errno;
49
+
50
+ function isErrnoException(arg: unknown): arg is ErrnoException {
51
+ return arg instanceof Error
52
+ && isObject(arg)
53
+ && typeof arg.code === 'string'
54
+ && typeof arg.errno === 'number';
55
+ }
56
+
57
+ export function isENOENT(
58
+ arg: unknown
59
+ ): arg is ErrnoException & Readonly<{ code: typeof ENOENT }> {
60
+ return isErrnoException(arg) && arg.code === ENOENT;
61
+ }
62
+
63
+ export function deepClone<T>(obj: T): T {
64
+ if (!isObject(obj)) {
65
+ return obj;
66
+ }
67
+ if (obj instanceof RegExp) {
68
+ return obj;
69
+ }
70
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
71
+ const result: any = Array.isArray(obj) ? [] : {};
72
+ Object.keys(obj).forEach((key: string) => {
73
+ const prop = obj[key];
74
+ if (isObject(prop)) {
75
+ result[key] = deepClone(prop);
76
+ } else {
77
+ result[key] = prop;
78
+ }
79
+ });
80
+ return result as T;
81
+ }