@theia/vsx-registry 1.45.0 → 1.46.0-next.72

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 (100) hide show
  1. package/README.md +45 -45
  2. package/lib/browser/recommended-extensions/preference-provider-overrides.d.ts +17 -17
  3. package/lib/browser/recommended-extensions/preference-provider-overrides.js +95 -95
  4. package/lib/browser/recommended-extensions/recommended-extensions-json-schema.d.ts +14 -14
  5. package/lib/browser/recommended-extensions/recommended-extensions-json-schema.js +94 -94
  6. package/lib/browser/recommended-extensions/recommended-extensions-preference-contribution.d.ts +11 -11
  7. package/lib/browser/recommended-extensions/recommended-extensions-preference-contribution.js +59 -59
  8. package/lib/browser/vsx-extension-commands.d.ts +14 -13
  9. package/lib/browser/vsx-extension-commands.d.ts.map +1 -1
  10. package/lib/browser/vsx-extension-commands.js +68 -63
  11. package/lib/browser/vsx-extension-commands.js.map +1 -1
  12. package/lib/browser/vsx-extension-editor-manager.d.ts +9 -9
  13. package/lib/browser/vsx-extension-editor-manager.js +49 -49
  14. package/lib/browser/vsx-extension-editor.d.ts +21 -21
  15. package/lib/browser/vsx-extension-editor.js +109 -109
  16. package/lib/browser/vsx-extension.d.ts +146 -143
  17. package/lib/browser/vsx-extension.d.ts.map +1 -1
  18. package/lib/browser/vsx-extension.js +616 -596
  19. package/lib/browser/vsx-extension.js.map +1 -1
  20. package/lib/browser/vsx-extensions-contribution.d.ts +70 -60
  21. package/lib/browser/vsx-extensions-contribution.d.ts.map +1 -1
  22. package/lib/browser/vsx-extensions-contribution.js +375 -344
  23. package/lib/browser/vsx-extensions-contribution.js.map +1 -1
  24. package/lib/browser/vsx-extensions-model.d.ts +75 -72
  25. package/lib/browser/vsx-extensions-model.d.ts.map +1 -1
  26. package/lib/browser/vsx-extensions-model.js +437 -391
  27. package/lib/browser/vsx-extensions-model.js.map +1 -1
  28. package/lib/browser/vsx-extensions-preferences.d.ts +12 -0
  29. package/lib/browser/vsx-extensions-preferences.d.ts.map +1 -0
  30. package/lib/browser/vsx-extensions-preferences.js +47 -0
  31. package/lib/browser/vsx-extensions-preferences.js.map +1 -0
  32. package/lib/browser/vsx-extensions-search-bar.d.ts +22 -14
  33. package/lib/browser/vsx-extensions-search-bar.d.ts.map +1 -1
  34. package/lib/browser/vsx-extensions-search-bar.js +106 -75
  35. package/lib/browser/vsx-extensions-search-bar.js.map +1 -1
  36. package/lib/browser/vsx-extensions-search-model.d.ts +21 -21
  37. package/lib/browser/vsx-extensions-search-model.js +70 -70
  38. package/lib/browser/vsx-extensions-source.d.ts +19 -19
  39. package/lib/browser/vsx-extensions-source.js +102 -102
  40. package/lib/browser/vsx-extensions-view-container.d.ts +49 -49
  41. package/lib/browser/vsx-extensions-view-container.js +179 -179
  42. package/lib/browser/vsx-extensions-widget.d.ts +35 -34
  43. package/lib/browser/vsx-extensions-widget.d.ts.map +1 -1
  44. package/lib/browser/vsx-extensions-widget.js +164 -156
  45. package/lib/browser/vsx-extensions-widget.js.map +1 -1
  46. package/lib/browser/vsx-language-quick-pick-service.d.ts +15 -15
  47. package/lib/browser/vsx-language-quick-pick-service.js +121 -121
  48. package/lib/browser/vsx-registry-frontend-module.d.ts +4 -4
  49. package/lib/browser/vsx-registry-frontend-module.d.ts.map +1 -1
  50. package/lib/browser/vsx-registry-frontend-module.js +99 -97
  51. package/lib/browser/vsx-registry-frontend-module.js.map +1 -1
  52. package/lib/common/index.d.ts +3 -3
  53. package/lib/common/index.js +25 -25
  54. package/lib/common/ovsx-client-provider.d.ts +13 -13
  55. package/lib/common/ovsx-client-provider.js +29 -29
  56. package/lib/common/vsx-environment.d.ts +9 -9
  57. package/lib/common/vsx-environment.js +20 -20
  58. package/lib/common/vsx-extension-uri.d.ts +3 -3
  59. package/lib/common/vsx-extension-uri.js +20 -20
  60. package/lib/common/vsx-registry-common-module.d.ts +3 -3
  61. package/lib/common/vsx-registry-common-module.js +57 -57
  62. package/lib/node/vsx-cli.d.ts +9 -9
  63. package/lib/node/vsx-cli.js +41 -41
  64. package/lib/node/vsx-environment-impl.d.ts +14 -14
  65. package/lib/node/vsx-environment-impl.js +61 -61
  66. package/lib/node/vsx-extension-resolver.d.ts +20 -20
  67. package/lib/node/vsx-extension-resolver.js +154 -154
  68. package/lib/node/vsx-registry-backend-module.d.ts +3 -3
  69. package/lib/node/vsx-registry-backend-module.js +35 -35
  70. package/lib/package.spec.js +25 -25
  71. package/package.json +12 -12
  72. package/src/browser/recommended-extensions/preference-provider-overrides.ts +99 -99
  73. package/src/browser/recommended-extensions/recommended-extensions-json-schema.ts +74 -74
  74. package/src/browser/recommended-extensions/recommended-extensions-preference-contribution.ts +68 -68
  75. package/src/browser/style/extensions.svg +4 -4
  76. package/src/browser/style/index.css +436 -373
  77. package/src/browser/vsx-extension-commands.ts +68 -63
  78. package/src/browser/vsx-extension-editor-manager.ts +42 -42
  79. package/src/browser/vsx-extension-editor.tsx +96 -96
  80. package/src/browser/vsx-extension.tsx +704 -675
  81. package/src/browser/vsx-extensions-contribution.ts +361 -327
  82. package/src/browser/vsx-extensions-model.ts +436 -389
  83. package/src/browser/vsx-extensions-preferences.ts +58 -0
  84. package/src/browser/vsx-extensions-search-bar.tsx +107 -69
  85. package/src/browser/vsx-extensions-search-model.ts +61 -61
  86. package/src/browser/vsx-extensions-source.ts +83 -83
  87. package/src/browser/vsx-extensions-view-container.ts +179 -179
  88. package/src/browser/vsx-extensions-widget.tsx +165 -156
  89. package/src/browser/vsx-language-quick-pick-service.ts +110 -110
  90. package/src/browser/vsx-registry-frontend-module.ts +108 -106
  91. package/src/common/index.ts +19 -19
  92. package/src/common/ovsx-client-provider.ts +35 -35
  93. package/src/common/vsx-environment.ts +27 -27
  94. package/src/common/vsx-extension-uri.ts +20 -20
  95. package/src/common/vsx-registry-common-module.ts +63 -63
  96. package/src/node/vsx-cli.ts +38 -38
  97. package/src/node/vsx-environment-impl.ts +50 -50
  98. package/src/node/vsx-extension-resolver.ts +125 -125
  99. package/src/node/vsx-registry-backend-module.ts +35 -35
  100. package/src/package.spec.ts +29 -29
@@ -1,392 +1,438 @@
1
- "use strict";
2
- // *****************************************************************************
3
- // Copyright (C) 2020 TypeFox and others.
4
- //
5
- // This program and the accompanying materials are made available under the
6
- // terms of the Eclipse Public License v. 2.0 which is available at
7
- // http://www.eclipse.org/legal/epl-2.0.
8
- //
9
- // This Source Code may also be made available under the following Secondary
10
- // Licenses when the conditions for such availability set forth in the Eclipse
11
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
12
- // with the GNU Classpath Exception which is available at
13
- // https://www.gnu.org/software/classpath/license.html.
14
- //
15
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
16
- // *****************************************************************************
17
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
18
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
19
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
20
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
21
- return c > 3 && r && Object.defineProperty(target, key, r), r;
22
- };
23
- var __metadata = (this && this.__metadata) || function (k, v) {
24
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
25
- };
26
- Object.defineProperty(exports, "__esModule", { value: true });
27
- exports.VSXExtensionsModel = void 0;
28
- const inversify_1 = require("@theia/core/shared/inversify");
29
- const p_debounce_1 = require("p-debounce");
30
- const markdownit = require("@theia/core/shared/markdown-it");
31
- const DOMPurify = require("@theia/core/shared/dompurify");
32
- const event_1 = require("@theia/core/lib/common/event");
33
- const cancellation_1 = require("@theia/core/lib/common/cancellation");
34
- const hosted_plugin_1 = require("@theia/plugin-ext/lib/hosted/browser/hosted-plugin");
35
- const vsx_extension_1 = require("./vsx-extension");
36
- const progress_service_1 = require("@theia/core/lib/common/progress-service");
37
- const vsx_extensions_search_model_1 = require("./vsx-extensions-search-model");
38
- const browser_1 = require("@theia/core/lib/browser");
39
- const browser_2 = require("@theia/workspace/lib/browser");
40
- const ovsx_types_1 = require("@theia/ovsx-client/lib/ovsx-types");
41
- const ovsx_client_provider_1 = require("../common/ovsx-client-provider");
42
- const request_1 = require("@theia/core/shared/@theia/request");
43
- const ovsx_client_1 = require("@theia/ovsx-client");
44
- let VSXExtensionsModel = class VSXExtensionsModel {
45
- constructor() {
46
- /**
47
- * Single source for all extensions
48
- */
49
- this.extensions = new Map();
50
- this.onDidChangeEmitter = new event_1.Emitter();
51
- this._installed = new Set();
52
- this._recommended = new Set();
53
- this._searchResult = new Set();
54
- this.searchCancellationTokenSource = new cancellation_1.CancellationTokenSource();
55
- this.updateSearchResult = (0, p_debounce_1.default)(async () => {
56
- const { token } = this.resetSearchCancellationTokenSource();
57
- await this.doUpdateSearchResult({ query: this.search.query, includeAllVersions: true }, token);
58
- }, 500);
59
- }
60
- init() {
61
- this.initialized = this.doInit().catch(console.error);
62
- }
63
- async doInit() {
64
- await Promise.all([
65
- this.initInstalled(),
66
- this.initSearchResult(),
67
- this.initRecommended(),
68
- ]);
69
- }
70
- get onDidChange() {
71
- return this.onDidChangeEmitter.event;
72
- }
73
- get installed() {
74
- return this._installed.values();
75
- }
76
- get searchError() {
77
- return this._searchError;
78
- }
79
- get searchResult() {
80
- return this._searchResult.values();
81
- }
82
- get recommended() {
83
- return this._recommended.values();
84
- }
85
- isInstalled(id) {
86
- return this._installed.has(id);
87
- }
88
- getExtension(id) {
89
- return this.extensions.get(id);
90
- }
91
- resolve(id) {
92
- return this.doChange(async () => {
93
- await this.initialized;
94
- const extension = await this.refresh(id);
95
- if (!extension) {
96
- throw new Error(`Failed to resolve ${id} extension.`);
97
- }
98
- if (extension.readmeUrl) {
99
- try {
100
- const rawReadme = request_1.RequestContext.asText(await this.request.request({ url: extension.readmeUrl }));
101
- const readme = this.compileReadme(rawReadme);
102
- extension.update({ readme });
103
- }
104
- catch (e) {
105
- if (!ovsx_types_1.VSXResponseError.is(e) || e.statusCode !== 404) {
106
- console.error(`[${id}]: failed to compile readme, reason:`, e);
107
- }
108
- }
109
- }
110
- return extension;
111
- });
112
- }
113
- async initInstalled() {
114
- await this.pluginSupport.willStart;
115
- this.pluginSupport.onDidChangePlugins(() => this.updateInstalled());
116
- try {
117
- await this.updateInstalled();
118
- }
119
- catch (e) {
120
- console.error(e);
121
- }
122
- }
123
- async initSearchResult() {
124
- this.search.onDidChangeQuery(() => this.updateSearchResult());
125
- try {
126
- await this.updateSearchResult();
127
- }
128
- catch (e) {
129
- console.error(e);
130
- }
131
- }
132
- async initRecommended() {
133
- this.preferences.onPreferenceChanged(change => {
134
- if (change.preferenceName === 'extensions') {
135
- this.updateRecommended();
136
- }
137
- });
138
- await this.preferences.ready;
139
- try {
140
- await this.updateRecommended();
141
- }
142
- catch (e) {
143
- console.error(e);
144
- }
145
- }
146
- resetSearchCancellationTokenSource() {
147
- this.searchCancellationTokenSource.cancel();
148
- return this.searchCancellationTokenSource = new cancellation_1.CancellationTokenSource();
149
- }
150
- setExtension(id) {
151
- let extension = this.extensions.get(id);
152
- if (!extension) {
153
- extension = this.extensionFactory({ id });
154
- this.extensions.set(id, extension);
155
- }
156
- return extension;
157
- }
158
- doChange(task, token = cancellation_1.CancellationToken.None) {
159
- return this.progressService.withProgress('', 'extensions', async () => {
160
- if (token && token.isCancellationRequested) {
161
- return;
162
- }
163
- const result = await task();
164
- if (token && token.isCancellationRequested) {
165
- return;
166
- }
167
- this.onDidChangeEmitter.fire();
168
- return result;
169
- });
170
- }
171
- doUpdateSearchResult(param, token) {
172
- return this.doChange(async () => {
173
- const searchResult = new Set();
174
- if (!param.query) {
175
- this._searchResult = searchResult;
176
- return;
177
- }
178
- const client = await this.clientProvider();
179
- const result = await client.search(param);
180
- this._searchError = result.error;
181
- if (token.isCancellationRequested) {
182
- return;
183
- }
184
- for (const data of result.extensions) {
185
- const id = data.namespace.toLowerCase() + '.' + data.name.toLowerCase();
186
- const allVersions = this.vsxApiFilter.getLatestCompatibleVersion(data);
187
- if (!allVersions) {
188
- continue;
189
- }
190
- this.setExtension(id).update(Object.assign(data, {
191
- publisher: data.namespace,
192
- downloadUrl: data.files.download,
193
- iconUrl: data.files.icon,
194
- readmeUrl: data.files.readme,
195
- licenseUrl: data.files.license,
196
- version: allVersions.version
197
- }));
198
- searchResult.add(id);
199
- }
200
- this._searchResult = searchResult;
201
- }, token);
202
- }
203
- async updateInstalled() {
204
- const prevInstalled = this._installed;
205
- return this.doChange(async () => {
206
- const plugins = this.pluginSupport.plugins;
207
- const currInstalled = new Set();
208
- const refreshing = [];
209
- for (const plugin of plugins) {
210
- if (plugin.model.engine.type === 'vscode') {
211
- const version = plugin.model.version;
212
- const id = plugin.model.id;
213
- this._installed.delete(id);
214
- const extension = this.setExtension(id);
215
- currInstalled.add(extension.id);
216
- refreshing.push(this.refresh(id, version));
217
- }
218
- }
219
- for (const id of this._installed) {
220
- const extension = this.getExtension(id);
221
- if (!extension) {
222
- continue;
223
- }
224
- refreshing.push(this.refresh(id, extension.version));
225
- }
226
- const installed = new Set([...prevInstalled, ...currInstalled]);
227
- const installedSorted = Array.from(installed).sort((a, b) => this.compareExtensions(a, b));
228
- this._installed = new Set(installedSorted.values());
229
- await Promise.all(refreshing);
230
- });
231
- }
232
- updateRecommended() {
233
- return this.doChange(async () => {
234
- const allRecommendations = new Set();
235
- const allUnwantedRecommendations = new Set();
236
- const updateRecommendationsForScope = (scope, root) => {
237
- const { recommendations, unwantedRecommendations } = this.getRecommendationsForScope(scope, root);
238
- recommendations.forEach(recommendation => allRecommendations.add(recommendation));
239
- unwantedRecommendations.forEach(unwantedRecommendation => allUnwantedRecommendations.add(unwantedRecommendation));
240
- };
241
- updateRecommendationsForScope('defaultValue'); // In case there are application-default recommendations.
242
- const roots = await this.workspaceService.roots;
243
- for (const root of roots) {
244
- updateRecommendationsForScope('workspaceFolderValue', root.resource);
245
- }
246
- if (this.workspaceService.saved) {
247
- updateRecommendationsForScope('workspaceValue');
248
- }
249
- const recommendedSorted = new Set(Array.from(allRecommendations).sort((a, b) => this.compareExtensions(a, b)));
250
- allUnwantedRecommendations.forEach(unwantedRecommendation => recommendedSorted.delete(unwantedRecommendation));
251
- this._recommended = recommendedSorted;
252
- return Promise.all(Array.from(recommendedSorted, plugin => this.refresh(plugin)));
253
- });
254
- }
255
- getRecommendationsForScope(scope, root) {
256
- var _a, _b, _c;
257
- const configuredValue = (_a = this.preferences.inspect('extensions', root === null || root === void 0 ? void 0 : root.toString())) === null || _a === void 0 ? void 0 : _a[scope];
258
- return {
259
- recommendations: (_b = configuredValue === null || configuredValue === void 0 ? void 0 : configuredValue.recommendations) !== null && _b !== void 0 ? _b : [],
260
- unwantedRecommendations: (_c = configuredValue === null || configuredValue === void 0 ? void 0 : configuredValue.unwantedRecommendations) !== null && _c !== void 0 ? _c : [],
261
- };
262
- }
263
- compileReadme(readmeMarkdown) {
264
- const readmeHtml = markdownit({ html: true }).render(readmeMarkdown);
265
- return DOMPurify.sanitize(readmeHtml);
266
- }
267
- async refresh(id, version) {
268
- try {
269
- let extension = this.getExtension(id);
270
- if (!this.shouldRefresh(extension)) {
271
- return extension;
272
- }
273
- const client = await this.clientProvider();
274
- let data;
275
- if (version === undefined) {
276
- const { extensions } = await client.query({ extensionId: id, includeAllVersions: true });
277
- if (extensions === null || extensions === void 0 ? void 0 : extensions.length) {
278
- data = this.vsxApiFilter.getLatestCompatibleExtension(extensions);
279
- }
280
- }
281
- else {
282
- const { extensions } = await client.query({ extensionId: id, extensionVersion: version, includeAllVersions: true });
283
- if (extensions === null || extensions === void 0 ? void 0 : extensions.length) {
284
- data = extensions === null || extensions === void 0 ? void 0 : extensions[0];
285
- }
286
- }
287
- if (!data) {
288
- return;
289
- }
290
- if (data.error) {
291
- return this.onDidFailRefresh(id, data.error);
292
- }
293
- extension = this.setExtension(id);
294
- extension.update(Object.assign(data, {
295
- publisher: data.namespace,
296
- downloadUrl: data.files.download,
297
- iconUrl: data.files.icon,
298
- readmeUrl: data.files.readme,
299
- licenseUrl: data.files.license,
300
- version: data.version
301
- }));
302
- return extension;
303
- }
304
- catch (e) {
305
- return this.onDidFailRefresh(id, e);
306
- }
307
- }
308
- /**
309
- * Determines if the given extension should be refreshed.
310
- * @param extension the extension to refresh.
311
- */
312
- shouldRefresh(extension) {
313
- if (extension === undefined) {
314
- return true;
315
- }
316
- return !extension.builtin;
317
- }
318
- onDidFailRefresh(id, error) {
319
- const cached = this.getExtension(id);
320
- if (cached && cached.installed) {
321
- return cached;
322
- }
323
- console.error(`[${id}]: failed to refresh, reason:`, error);
324
- return undefined;
325
- }
326
- /**
327
- * Compare two extensions based on their display name, and publisher if applicable.
328
- * @param a the first extension id for comparison.
329
- * @param b the second extension id for comparison.
330
- */
331
- compareExtensions(a, b) {
332
- const extensionA = this.getExtension(a);
333
- const extensionB = this.getExtension(b);
334
- if (!extensionA || !extensionB) {
335
- return 0;
336
- }
337
- if (extensionA.displayName && extensionB.displayName) {
338
- return extensionA.displayName.localeCompare(extensionB.displayName);
339
- }
340
- if (extensionA.publisher && extensionB.publisher) {
341
- return extensionA.publisher.localeCompare(extensionB.publisher);
342
- }
343
- return 0;
344
- }
345
- };
346
- __decorate([
347
- (0, inversify_1.inject)(ovsx_client_provider_1.OVSXClientProvider),
348
- __metadata("design:type", Function)
349
- ], VSXExtensionsModel.prototype, "clientProvider", void 0);
350
- __decorate([
351
- (0, inversify_1.inject)(hosted_plugin_1.HostedPluginSupport),
352
- __metadata("design:type", hosted_plugin_1.HostedPluginSupport)
353
- ], VSXExtensionsModel.prototype, "pluginSupport", void 0);
354
- __decorate([
355
- (0, inversify_1.inject)(vsx_extension_1.VSXExtensionFactory),
356
- __metadata("design:type", Function)
357
- ], VSXExtensionsModel.prototype, "extensionFactory", void 0);
358
- __decorate([
359
- (0, inversify_1.inject)(progress_service_1.ProgressService),
360
- __metadata("design:type", progress_service_1.ProgressService)
361
- ], VSXExtensionsModel.prototype, "progressService", void 0);
362
- __decorate([
363
- (0, inversify_1.inject)(browser_1.PreferenceService),
364
- __metadata("design:type", Object)
365
- ], VSXExtensionsModel.prototype, "preferences", void 0);
366
- __decorate([
367
- (0, inversify_1.inject)(browser_2.WorkspaceService),
368
- __metadata("design:type", browser_2.WorkspaceService)
369
- ], VSXExtensionsModel.prototype, "workspaceService", void 0);
370
- __decorate([
371
- (0, inversify_1.inject)(vsx_extensions_search_model_1.VSXExtensionsSearchModel),
372
- __metadata("design:type", vsx_extensions_search_model_1.VSXExtensionsSearchModel)
373
- ], VSXExtensionsModel.prototype, "search", void 0);
374
- __decorate([
375
- (0, inversify_1.inject)(request_1.RequestService),
376
- __metadata("design:type", Object)
377
- ], VSXExtensionsModel.prototype, "request", void 0);
378
- __decorate([
379
- (0, inversify_1.inject)(ovsx_client_1.OVSXApiFilter),
380
- __metadata("design:type", Object)
381
- ], VSXExtensionsModel.prototype, "vsxApiFilter", void 0);
382
- __decorate([
383
- (0, inversify_1.postConstruct)(),
384
- __metadata("design:type", Function),
385
- __metadata("design:paramtypes", []),
386
- __metadata("design:returntype", void 0)
387
- ], VSXExtensionsModel.prototype, "init", null);
388
- VSXExtensionsModel = __decorate([
389
- (0, inversify_1.injectable)()
390
- ], VSXExtensionsModel);
391
- exports.VSXExtensionsModel = VSXExtensionsModel;
1
+ "use strict";
2
+ // *****************************************************************************
3
+ // Copyright (C) 2020 TypeFox and others.
4
+ //
5
+ // This program and the accompanying materials are made available under the
6
+ // terms of the Eclipse Public License v. 2.0 which is available at
7
+ // http://www.eclipse.org/legal/epl-2.0.
8
+ //
9
+ // This Source Code may also be made available under the following Secondary
10
+ // Licenses when the conditions for such availability set forth in the Eclipse
11
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
12
+ // with the GNU Classpath Exception which is available at
13
+ // https://www.gnu.org/software/classpath/license.html.
14
+ //
15
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
16
+ // *****************************************************************************
17
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
18
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
19
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
20
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
21
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
22
+ };
23
+ var __metadata = (this && this.__metadata) || function (k, v) {
24
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
25
+ };
26
+ Object.defineProperty(exports, "__esModule", { value: true });
27
+ exports.VSXExtensionsModel = void 0;
28
+ const inversify_1 = require("@theia/core/shared/inversify");
29
+ const p_debounce_1 = require("p-debounce");
30
+ const markdownit = require("@theia/core/shared/markdown-it");
31
+ const DOMPurify = require("@theia/core/shared/dompurify");
32
+ const event_1 = require("@theia/core/lib/common/event");
33
+ const cancellation_1 = require("@theia/core/lib/common/cancellation");
34
+ const hosted_plugin_1 = require("@theia/plugin-ext/lib/hosted/browser/hosted-plugin");
35
+ const vsx_extension_1 = require("./vsx-extension");
36
+ const progress_service_1 = require("@theia/core/lib/common/progress-service");
37
+ const vsx_extensions_search_model_1 = require("./vsx-extensions-search-model");
38
+ const browser_1 = require("@theia/core/lib/browser");
39
+ const browser_2 = require("@theia/workspace/lib/browser");
40
+ const ovsx_types_1 = require("@theia/ovsx-client/lib/ovsx-types");
41
+ const ovsx_client_provider_1 = require("../common/ovsx-client-provider");
42
+ const request_1 = require("@theia/core/shared/@theia/request");
43
+ const ovsx_client_1 = require("@theia/ovsx-client");
44
+ let VSXExtensionsModel = class VSXExtensionsModel {
45
+ constructor() {
46
+ /**
47
+ * Single source for all extensions
48
+ */
49
+ this.extensions = new Map();
50
+ this.onDidChangeEmitter = new event_1.Emitter();
51
+ this._installed = new Set();
52
+ this._recommended = new Set();
53
+ this._searchResult = new Set();
54
+ this.searchCancellationTokenSource = new cancellation_1.CancellationTokenSource();
55
+ this.updateSearchResult = (0, p_debounce_1.default)(async () => {
56
+ const { token } = this.resetSearchCancellationTokenSource();
57
+ await this.doUpdateSearchResult({ query: this.search.query, includeAllVersions: true }, token);
58
+ }, 500);
59
+ }
60
+ init() {
61
+ this.initialized = this.doInit().catch(console.error);
62
+ }
63
+ async doInit() {
64
+ await Promise.all([
65
+ this.initInstalled(),
66
+ this.initSearchResult(),
67
+ this.initRecommended(),
68
+ ]);
69
+ }
70
+ get onDidChange() {
71
+ return this.onDidChangeEmitter.event;
72
+ }
73
+ get installed() {
74
+ return this._installed.values();
75
+ }
76
+ get searchError() {
77
+ return this._searchError;
78
+ }
79
+ get searchResult() {
80
+ return this._searchResult.values();
81
+ }
82
+ get recommended() {
83
+ return this._recommended.values();
84
+ }
85
+ setOnlyShowVerifiedExtensions(bool) {
86
+ if (this.preferences.get('extensions.onlyShowVerifiedExtensions') !== bool) {
87
+ this.preferences.updateValue('extensions.onlyShowVerifiedExtensions', bool);
88
+ }
89
+ this.updateSearchResult();
90
+ }
91
+ isInstalled(id) {
92
+ return this._installed.has(id);
93
+ }
94
+ getExtension(id) {
95
+ return this.extensions.get(id);
96
+ }
97
+ resolve(id) {
98
+ return this.doChange(async () => {
99
+ await this.initialized;
100
+ const extension = await this.refresh(id);
101
+ if (!extension) {
102
+ throw new Error(`Failed to resolve ${id} extension.`);
103
+ }
104
+ if (extension.readmeUrl) {
105
+ try {
106
+ const rawReadme = request_1.RequestContext.asText(await this.request.request({ url: extension.readmeUrl }));
107
+ const readme = this.compileReadme(rawReadme);
108
+ extension.update({ readme });
109
+ }
110
+ catch (e) {
111
+ if (!ovsx_types_1.VSXResponseError.is(e) || e.statusCode !== 404) {
112
+ console.error(`[${id}]: failed to compile readme, reason:`, e);
113
+ }
114
+ }
115
+ }
116
+ return extension;
117
+ });
118
+ }
119
+ async initInstalled() {
120
+ await this.pluginSupport.willStart;
121
+ this.pluginSupport.onDidChangePlugins(() => this.updateInstalled());
122
+ try {
123
+ await this.updateInstalled();
124
+ }
125
+ catch (e) {
126
+ console.error(e);
127
+ }
128
+ }
129
+ async initSearchResult() {
130
+ this.search.onDidChangeQuery(() => this.updateSearchResult());
131
+ try {
132
+ await this.updateSearchResult();
133
+ }
134
+ catch (e) {
135
+ console.error(e);
136
+ }
137
+ }
138
+ async initRecommended() {
139
+ this.preferences.onPreferenceChanged(change => {
140
+ if (change.preferenceName === 'extensions') {
141
+ this.updateRecommended();
142
+ }
143
+ });
144
+ await this.preferences.ready;
145
+ try {
146
+ await this.updateRecommended();
147
+ }
148
+ catch (e) {
149
+ console.error(e);
150
+ }
151
+ }
152
+ resetSearchCancellationTokenSource() {
153
+ this.searchCancellationTokenSource.cancel();
154
+ return this.searchCancellationTokenSource = new cancellation_1.CancellationTokenSource();
155
+ }
156
+ setExtension(id) {
157
+ let extension = this.extensions.get(id);
158
+ if (!extension) {
159
+ extension = this.extensionFactory({ id });
160
+ this.extensions.set(id, extension);
161
+ }
162
+ return extension;
163
+ }
164
+ doChange(task, token = cancellation_1.CancellationToken.None) {
165
+ return this.progressService.withProgress('', 'extensions', async () => {
166
+ if (token && token.isCancellationRequested) {
167
+ return;
168
+ }
169
+ const result = await task();
170
+ if (token && token.isCancellationRequested) {
171
+ return;
172
+ }
173
+ this.onDidChangeEmitter.fire();
174
+ return result;
175
+ });
176
+ }
177
+ doUpdateSearchResult(param, token) {
178
+ return this.doChange(async () => {
179
+ this._searchResult = new Set();
180
+ if (!param.query) {
181
+ return;
182
+ }
183
+ const client = await this.clientProvider();
184
+ const result = await client.search(param);
185
+ this._searchError = result.error;
186
+ if (token.isCancellationRequested) {
187
+ return;
188
+ }
189
+ for (const data of result.extensions) {
190
+ const id = data.namespace.toLowerCase() + '.' + data.name.toLowerCase();
191
+ const allVersions = this.vsxApiFilter.getLatestCompatibleVersion(data);
192
+ if (!allVersions) {
193
+ continue;
194
+ }
195
+ if (this.preferences.get('extensions.onlyShowVerifiedExtensions')) {
196
+ this.fetchVerifiedStatus(id, client, allVersions).then(verified => {
197
+ this.doChange(() => {
198
+ this.addExtensions(data, id, allVersions, !!verified);
199
+ return Promise.resolve();
200
+ });
201
+ });
202
+ }
203
+ else {
204
+ this.addExtensions(data, id, allVersions);
205
+ this.fetchVerifiedStatus(id, client, allVersions).then(verified => {
206
+ this.doChange(() => {
207
+ let extension = this.getExtension(id);
208
+ extension = this.setExtension(id);
209
+ extension.update(Object.assign({
210
+ verified: verified
211
+ }));
212
+ return Promise.resolve();
213
+ });
214
+ });
215
+ }
216
+ }
217
+ }, token);
218
+ }
219
+ async fetchVerifiedStatus(id, client, allVersions) {
220
+ var _a, _b;
221
+ const res = await client.query({ extensionId: id, extensionVersion: allVersions.version, includeAllVersions: true });
222
+ let verified = (_a = res.extensions) === null || _a === void 0 ? void 0 : _a[0].verified;
223
+ if (!verified && ((_b = res.extensions) === null || _b === void 0 ? void 0 : _b[0].publishedBy.loginName) === 'open-vsx') {
224
+ verified = true;
225
+ }
226
+ return verified;
227
+ }
228
+ addExtensions(data, id, allVersions, verified) {
229
+ if (!this.preferences.get('extensions.onlyShowVerifiedExtensions') || verified) {
230
+ const extension = this.setExtension(id);
231
+ extension.update(Object.assign(data, {
232
+ publisher: data.namespace,
233
+ downloadUrl: data.files.download,
234
+ iconUrl: data.files.icon,
235
+ readmeUrl: data.files.readme,
236
+ licenseUrl: data.files.license,
237
+ version: allVersions.version,
238
+ verified: verified
239
+ }));
240
+ this._searchResult.add(id);
241
+ }
242
+ }
243
+ async updateInstalled() {
244
+ const prevInstalled = this._installed;
245
+ return this.doChange(async () => {
246
+ const plugins = this.pluginSupport.plugins;
247
+ const currInstalled = new Set();
248
+ const refreshing = [];
249
+ for (const plugin of plugins) {
250
+ if (plugin.model.engine.type === 'vscode') {
251
+ const version = plugin.model.version;
252
+ const id = plugin.model.id;
253
+ this._installed.delete(id);
254
+ const extension = this.setExtension(id);
255
+ currInstalled.add(extension.id);
256
+ refreshing.push(this.refresh(id, version));
257
+ }
258
+ }
259
+ for (const id of this._installed) {
260
+ const extension = this.getExtension(id);
261
+ if (!extension) {
262
+ continue;
263
+ }
264
+ refreshing.push(this.refresh(id, extension.version));
265
+ }
266
+ const installed = new Set([...prevInstalled, ...currInstalled]);
267
+ const installedSorted = Array.from(installed).sort((a, b) => this.compareExtensions(a, b));
268
+ this._installed = new Set(installedSorted.values());
269
+ await Promise.all(refreshing);
270
+ });
271
+ }
272
+ updateRecommended() {
273
+ return this.doChange(async () => {
274
+ const allRecommendations = new Set();
275
+ const allUnwantedRecommendations = new Set();
276
+ const updateRecommendationsForScope = (scope, root) => {
277
+ const { recommendations, unwantedRecommendations } = this.getRecommendationsForScope(scope, root);
278
+ recommendations.forEach(recommendation => allRecommendations.add(recommendation));
279
+ unwantedRecommendations.forEach(unwantedRecommendation => allUnwantedRecommendations.add(unwantedRecommendation));
280
+ };
281
+ updateRecommendationsForScope('defaultValue'); // In case there are application-default recommendations.
282
+ const roots = await this.workspaceService.roots;
283
+ for (const root of roots) {
284
+ updateRecommendationsForScope('workspaceFolderValue', root.resource);
285
+ }
286
+ if (this.workspaceService.saved) {
287
+ updateRecommendationsForScope('workspaceValue');
288
+ }
289
+ const recommendedSorted = new Set(Array.from(allRecommendations).sort((a, b) => this.compareExtensions(a, b)));
290
+ allUnwantedRecommendations.forEach(unwantedRecommendation => recommendedSorted.delete(unwantedRecommendation));
291
+ this._recommended = recommendedSorted;
292
+ return Promise.all(Array.from(recommendedSorted, plugin => this.refresh(plugin)));
293
+ });
294
+ }
295
+ getRecommendationsForScope(scope, root) {
296
+ var _a, _b, _c;
297
+ const configuredValue = (_a = this.preferences.inspect('extensions', root === null || root === void 0 ? void 0 : root.toString())) === null || _a === void 0 ? void 0 : _a[scope];
298
+ return {
299
+ recommendations: (_b = configuredValue === null || configuredValue === void 0 ? void 0 : configuredValue.recommendations) !== null && _b !== void 0 ? _b : [],
300
+ unwantedRecommendations: (_c = configuredValue === null || configuredValue === void 0 ? void 0 : configuredValue.unwantedRecommendations) !== null && _c !== void 0 ? _c : [],
301
+ };
302
+ }
303
+ compileReadme(readmeMarkdown) {
304
+ const readmeHtml = markdownit({ html: true }).render(readmeMarkdown);
305
+ return DOMPurify.sanitize(readmeHtml);
306
+ }
307
+ async refresh(id, version) {
308
+ try {
309
+ let extension = this.getExtension(id);
310
+ if (!this.shouldRefresh(extension)) {
311
+ return extension;
312
+ }
313
+ const client = await this.clientProvider();
314
+ let data;
315
+ if (version === undefined) {
316
+ const { extensions } = await client.query({ extensionId: id, includeAllVersions: true });
317
+ if (extensions === null || extensions === void 0 ? void 0 : extensions.length) {
318
+ data = this.vsxApiFilter.getLatestCompatibleExtension(extensions);
319
+ }
320
+ }
321
+ else {
322
+ const { extensions } = await client.query({ extensionId: id, extensionVersion: version, includeAllVersions: true });
323
+ if (extensions === null || extensions === void 0 ? void 0 : extensions.length) {
324
+ data = extensions === null || extensions === void 0 ? void 0 : extensions[0];
325
+ }
326
+ }
327
+ if (!data) {
328
+ return;
329
+ }
330
+ if (data.error) {
331
+ return this.onDidFailRefresh(id, data.error);
332
+ }
333
+ if (!data.verified) {
334
+ if (data.publishedBy.loginName === 'open-vsx') {
335
+ data.verified = true;
336
+ }
337
+ }
338
+ extension = this.setExtension(id);
339
+ extension.update(Object.assign(data, {
340
+ publisher: data.namespace,
341
+ downloadUrl: data.files.download,
342
+ iconUrl: data.files.icon,
343
+ readmeUrl: data.files.readme,
344
+ licenseUrl: data.files.license,
345
+ version: data.version,
346
+ verified: data.verified
347
+ }));
348
+ return extension;
349
+ }
350
+ catch (e) {
351
+ return this.onDidFailRefresh(id, e);
352
+ }
353
+ }
354
+ /**
355
+ * Determines if the given extension should be refreshed.
356
+ * @param extension the extension to refresh.
357
+ */
358
+ shouldRefresh(extension) {
359
+ if (extension === undefined) {
360
+ return true;
361
+ }
362
+ return !extension.builtin;
363
+ }
364
+ onDidFailRefresh(id, error) {
365
+ const cached = this.getExtension(id);
366
+ if (cached && cached.installed) {
367
+ return cached;
368
+ }
369
+ console.error(`[${id}]: failed to refresh, reason:`, error);
370
+ return undefined;
371
+ }
372
+ /**
373
+ * Compare two extensions based on their display name, and publisher if applicable.
374
+ * @param a the first extension id for comparison.
375
+ * @param b the second extension id for comparison.
376
+ */
377
+ compareExtensions(a, b) {
378
+ const extensionA = this.getExtension(a);
379
+ const extensionB = this.getExtension(b);
380
+ if (!extensionA || !extensionB) {
381
+ return 0;
382
+ }
383
+ if (extensionA.displayName && extensionB.displayName) {
384
+ return extensionA.displayName.localeCompare(extensionB.displayName);
385
+ }
386
+ if (extensionA.publisher && extensionB.publisher) {
387
+ return extensionA.publisher.localeCompare(extensionB.publisher);
388
+ }
389
+ return 0;
390
+ }
391
+ };
392
+ __decorate([
393
+ (0, inversify_1.inject)(ovsx_client_provider_1.OVSXClientProvider),
394
+ __metadata("design:type", Function)
395
+ ], VSXExtensionsModel.prototype, "clientProvider", void 0);
396
+ __decorate([
397
+ (0, inversify_1.inject)(hosted_plugin_1.HostedPluginSupport),
398
+ __metadata("design:type", hosted_plugin_1.HostedPluginSupport)
399
+ ], VSXExtensionsModel.prototype, "pluginSupport", void 0);
400
+ __decorate([
401
+ (0, inversify_1.inject)(vsx_extension_1.VSXExtensionFactory),
402
+ __metadata("design:type", Function)
403
+ ], VSXExtensionsModel.prototype, "extensionFactory", void 0);
404
+ __decorate([
405
+ (0, inversify_1.inject)(progress_service_1.ProgressService),
406
+ __metadata("design:type", progress_service_1.ProgressService)
407
+ ], VSXExtensionsModel.prototype, "progressService", void 0);
408
+ __decorate([
409
+ (0, inversify_1.inject)(browser_1.PreferenceService),
410
+ __metadata("design:type", Object)
411
+ ], VSXExtensionsModel.prototype, "preferences", void 0);
412
+ __decorate([
413
+ (0, inversify_1.inject)(browser_2.WorkspaceService),
414
+ __metadata("design:type", browser_2.WorkspaceService)
415
+ ], VSXExtensionsModel.prototype, "workspaceService", void 0);
416
+ __decorate([
417
+ (0, inversify_1.inject)(vsx_extensions_search_model_1.VSXExtensionsSearchModel),
418
+ __metadata("design:type", vsx_extensions_search_model_1.VSXExtensionsSearchModel)
419
+ ], VSXExtensionsModel.prototype, "search", void 0);
420
+ __decorate([
421
+ (0, inversify_1.inject)(request_1.RequestService),
422
+ __metadata("design:type", Object)
423
+ ], VSXExtensionsModel.prototype, "request", void 0);
424
+ __decorate([
425
+ (0, inversify_1.inject)(ovsx_client_1.OVSXApiFilter),
426
+ __metadata("design:type", Object)
427
+ ], VSXExtensionsModel.prototype, "vsxApiFilter", void 0);
428
+ __decorate([
429
+ (0, inversify_1.postConstruct)(),
430
+ __metadata("design:type", Function),
431
+ __metadata("design:paramtypes", []),
432
+ __metadata("design:returntype", void 0)
433
+ ], VSXExtensionsModel.prototype, "init", null);
434
+ VSXExtensionsModel = __decorate([
435
+ (0, inversify_1.injectable)()
436
+ ], VSXExtensionsModel);
437
+ exports.VSXExtensionsModel = VSXExtensionsModel;
392
438
  //# sourceMappingURL=vsx-extensions-model.js.map