@theia/cli 1.53.0-next.4 → 1.53.0-next.55
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.
- package/README.md +367 -367
- package/bin/theia +2 -2
- package/bin/theia-patch.js +37 -37
- package/lib/download-plugins.d.ts +2 -2
- package/lib/download-plugins.d.ts.map +1 -1
- package/lib/download-plugins.js +2 -4
- package/lib/download-plugins.js.map +1 -1
- package/lib/theia.js +10 -5
- package/lib/theia.js.map +1 -1
- package/package.json +8 -8
- package/patches/@phosphor+widgets+1.9.3.patch +157 -157
- package/patches/@theia+monaco-editor-core+1.83.101.patch +32 -32
- package/src/check-dependencies.ts +328 -328
- package/src/download-plugins.ts +364 -363
- package/src/run-test.ts +87 -87
- package/src/test-page.ts +138 -138
- package/src/theia.ts +691 -686
package/src/download-plugins.ts
CHANGED
|
@@ -1,363 +1,364 @@
|
|
|
1
|
-
// *****************************************************************************
|
|
2
|
-
// Copyright (C) 2020 Ericsson 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
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
18
|
-
|
|
19
|
-
import { OVSXApiFilterImpl, OVSXClient, VSXTargetPlatform } from '@theia/ovsx-client';
|
|
20
|
-
import * as chalk from 'chalk';
|
|
21
|
-
import * as decompress from 'decompress';
|
|
22
|
-
import { promises as fs } from 'fs';
|
|
23
|
-
import * as path from 'path';
|
|
24
|
-
import * as temp from 'temp';
|
|
25
|
-
import { DEFAULT_SUPPORTED_API_VERSION } from '@theia/application-package/lib/api';
|
|
26
|
-
import { RequestContext, RequestService } from '@theia/request';
|
|
27
|
-
import { RateLimiter } from 'limiter';
|
|
28
|
-
import escapeStringRegexp = require('escape-string-regexp');
|
|
29
|
-
|
|
30
|
-
temp.track();
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Available options when downloading.
|
|
34
|
-
*/
|
|
35
|
-
export interface DownloadPluginsOptions {
|
|
36
|
-
/**
|
|
37
|
-
* Determines if a plugin should be unpacked.
|
|
38
|
-
* Defaults to `false`.
|
|
39
|
-
*/
|
|
40
|
-
packed?: boolean;
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Determines if failures while downloading plugins should be ignored.
|
|
44
|
-
* Defaults to `false`.
|
|
45
|
-
*/
|
|
46
|
-
ignoreErrors?: boolean;
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* The supported vscode API version.
|
|
50
|
-
* Used to determine extension compatibility.
|
|
51
|
-
*/
|
|
52
|
-
apiVersion?: string;
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Fetch plugins in parallel
|
|
56
|
-
*/
|
|
57
|
-
parallel?: boolean;
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
//
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
.
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
const
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
await
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
*
|
|
192
|
-
* @param
|
|
193
|
-
* @param
|
|
194
|
-
* @param
|
|
195
|
-
* @param
|
|
196
|
-
* @param
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
const
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
let
|
|
235
|
-
let
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
const
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
await
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
*
|
|
286
|
-
*
|
|
287
|
-
*
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
*
|
|
296
|
-
* @
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
const
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
*
|
|
316
|
-
*
|
|
317
|
-
* @param
|
|
318
|
-
* @
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
const
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
const
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
*
|
|
342
|
-
*
|
|
343
|
-
* @param
|
|
344
|
-
* @
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
const
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
const
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2020 Ericsson 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
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
18
|
+
|
|
19
|
+
import { OVSXApiFilterImpl, OVSXClient, VSXTargetPlatform } from '@theia/ovsx-client';
|
|
20
|
+
import * as chalk from 'chalk';
|
|
21
|
+
import * as decompress from 'decompress';
|
|
22
|
+
import { promises as fs } from 'fs';
|
|
23
|
+
import * as path from 'path';
|
|
24
|
+
import * as temp from 'temp';
|
|
25
|
+
import { DEFAULT_SUPPORTED_API_VERSION } from '@theia/application-package/lib/api';
|
|
26
|
+
import { RequestContext, RequestService } from '@theia/request';
|
|
27
|
+
import { RateLimiter } from 'limiter';
|
|
28
|
+
import escapeStringRegexp = require('escape-string-regexp');
|
|
29
|
+
|
|
30
|
+
temp.track();
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Available options when downloading.
|
|
34
|
+
*/
|
|
35
|
+
export interface DownloadPluginsOptions {
|
|
36
|
+
/**
|
|
37
|
+
* Determines if a plugin should be unpacked.
|
|
38
|
+
* Defaults to `false`.
|
|
39
|
+
*/
|
|
40
|
+
packed?: boolean;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Determines if failures while downloading plugins should be ignored.
|
|
44
|
+
* Defaults to `false`.
|
|
45
|
+
*/
|
|
46
|
+
ignoreErrors?: boolean;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The supported vscode API version.
|
|
50
|
+
* Used to determine extension compatibility.
|
|
51
|
+
*/
|
|
52
|
+
apiVersion?: string;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Fetch plugins in parallel
|
|
56
|
+
*/
|
|
57
|
+
parallel?: boolean;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
interface PluginDownload {
|
|
61
|
+
id: string,
|
|
62
|
+
downloadUrl: string,
|
|
63
|
+
version?: string | undefined
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export default async function downloadPlugins(
|
|
67
|
+
ovsxClient: OVSXClient,
|
|
68
|
+
rateLimiter: RateLimiter,
|
|
69
|
+
requestService: RequestService,
|
|
70
|
+
options: DownloadPluginsOptions = {}
|
|
71
|
+
): Promise<void> {
|
|
72
|
+
const {
|
|
73
|
+
packed = false,
|
|
74
|
+
ignoreErrors = false,
|
|
75
|
+
apiVersion = DEFAULT_SUPPORTED_API_VERSION,
|
|
76
|
+
parallel = true
|
|
77
|
+
} = options;
|
|
78
|
+
|
|
79
|
+
const apiFilter = new OVSXApiFilterImpl(ovsxClient, apiVersion);
|
|
80
|
+
|
|
81
|
+
// Collect the list of failures to be appended at the end of the script.
|
|
82
|
+
const failures: string[] = [];
|
|
83
|
+
|
|
84
|
+
// Resolve the `package.json` at the current working directory.
|
|
85
|
+
const pck = JSON.parse(await fs.readFile(path.resolve('package.json'), 'utf8'));
|
|
86
|
+
|
|
87
|
+
// Resolve the directory for which to download the plugins.
|
|
88
|
+
const pluginsDir = pck.theiaPluginsDir || 'plugins';
|
|
89
|
+
|
|
90
|
+
// Excluded extension ids.
|
|
91
|
+
const excludedIds = new Set<string>(pck.theiaPluginsExcludeIds || []);
|
|
92
|
+
|
|
93
|
+
const parallelOrSequence = async (tasks: (() => unknown)[]) => {
|
|
94
|
+
if (parallel) {
|
|
95
|
+
await Promise.all(tasks.map(task => task()));
|
|
96
|
+
} else {
|
|
97
|
+
for (const task of tasks) {
|
|
98
|
+
await task();
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
// Downloader wrapper
|
|
104
|
+
const downloadPlugin = async (plugin: PluginDownload): Promise<void> => {
|
|
105
|
+
await downloadPluginAsync(requestService, rateLimiter, failures, plugin.id, plugin.downloadUrl, pluginsDir, packed, plugin.version);
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const downloader = async (plugins: PluginDownload[]) => {
|
|
109
|
+
await parallelOrSequence(plugins.map(plugin => () => downloadPlugin(plugin)));
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
await fs.mkdir(pluginsDir, { recursive: true });
|
|
113
|
+
|
|
114
|
+
if (!pck.theiaPlugins) {
|
|
115
|
+
console.log(chalk.red('error: missing mandatory \'theiaPlugins\' property.'));
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
try {
|
|
119
|
+
console.warn('--- downloading plugins ---');
|
|
120
|
+
// Download the raw plugins defined by the `theiaPlugins` property.
|
|
121
|
+
// This will include both "normal" plugins as well as "extension packs".
|
|
122
|
+
const pluginsToDownload = Object.entries(pck.theiaPlugins)
|
|
123
|
+
.filter((entry: [string, unknown]): entry is [string, string] => typeof entry[1] === 'string')
|
|
124
|
+
.map(([id, url]) => ({ id, downloadUrl: resolveDownloadUrlPlaceholders(url) }));
|
|
125
|
+
await downloader(pluginsToDownload);
|
|
126
|
+
|
|
127
|
+
const handleDependencyList = async (dependencies: (string | string[])[]) => {
|
|
128
|
+
// De-duplicate extension ids to only download each once:
|
|
129
|
+
const ids = new Set<string>(dependencies.flat());
|
|
130
|
+
await parallelOrSequence(Array.from(ids, id => async () => {
|
|
131
|
+
try {
|
|
132
|
+
await rateLimiter.removeTokens(1);
|
|
133
|
+
const extension = await apiFilter.findLatestCompatibleExtension({
|
|
134
|
+
extensionId: id,
|
|
135
|
+
includeAllVersions: true,
|
|
136
|
+
targetPlatform
|
|
137
|
+
});
|
|
138
|
+
const version = extension?.version;
|
|
139
|
+
const downloadUrl = extension?.files.download;
|
|
140
|
+
if (downloadUrl) {
|
|
141
|
+
await rateLimiter.removeTokens(1);
|
|
142
|
+
await downloadPlugin({ id, downloadUrl, version });
|
|
143
|
+
} else {
|
|
144
|
+
failures.push(`No download url for extension pack ${id} (${version})`);
|
|
145
|
+
}
|
|
146
|
+
} catch (err) {
|
|
147
|
+
console.error(err);
|
|
148
|
+
failures.push(err.message);
|
|
149
|
+
}
|
|
150
|
+
}));
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
console.warn('--- collecting extension-packs ---');
|
|
154
|
+
const extensionPacks = await collectExtensionPacks(pluginsDir, excludedIds);
|
|
155
|
+
if (extensionPacks.size > 0) {
|
|
156
|
+
console.warn(`--- resolving ${extensionPacks.size} extension-packs ---`);
|
|
157
|
+
await handleDependencyList(Array.from(extensionPacks.values()));
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
console.warn('--- collecting extension dependencies ---');
|
|
161
|
+
const pluginDependencies = await collectPluginDependencies(pluginsDir, excludedIds);
|
|
162
|
+
if (pluginDependencies.length > 0) {
|
|
163
|
+
console.warn(`--- resolving ${pluginDependencies.length} extension dependencies ---`);
|
|
164
|
+
await handleDependencyList(pluginDependencies);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
} finally {
|
|
168
|
+
temp.cleanupSync();
|
|
169
|
+
}
|
|
170
|
+
for (const failure of failures) {
|
|
171
|
+
console.error(failure);
|
|
172
|
+
}
|
|
173
|
+
if (!ignoreErrors && failures.length > 0) {
|
|
174
|
+
throw new Error('Errors downloading some plugins. To make these errors non fatal, re-run with --ignore-errors');
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const targetPlatform = `${process.platform}-${process.arch}` as VSXTargetPlatform;
|
|
179
|
+
|
|
180
|
+
const placeholders: Record<string, string> = {
|
|
181
|
+
targetPlatform
|
|
182
|
+
};
|
|
183
|
+
function resolveDownloadUrlPlaceholders(url: string): string {
|
|
184
|
+
for (const [name, value] of Object.entries(placeholders)) {
|
|
185
|
+
url = url.replace(new RegExp(escapeStringRegexp(`\${${name}}`), 'g'), value);
|
|
186
|
+
}
|
|
187
|
+
return url;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Downloads a plugin, will make multiple attempts before actually failing.
|
|
192
|
+
* @param requestService
|
|
193
|
+
* @param failures reference to an array storing all failures.
|
|
194
|
+
* @param plugin plugin short name.
|
|
195
|
+
* @param pluginUrl url to download the plugin at.
|
|
196
|
+
* @param target where to download the plugin in.
|
|
197
|
+
* @param packed whether to decompress or not.
|
|
198
|
+
*/
|
|
199
|
+
async function downloadPluginAsync(
|
|
200
|
+
requestService: RequestService,
|
|
201
|
+
rateLimiter: RateLimiter,
|
|
202
|
+
failures: string[],
|
|
203
|
+
plugin: string,
|
|
204
|
+
pluginUrl: string,
|
|
205
|
+
pluginsDir: string,
|
|
206
|
+
packed: boolean,
|
|
207
|
+
version?: string
|
|
208
|
+
): Promise<void> {
|
|
209
|
+
if (!plugin) {
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
let fileExt: string;
|
|
213
|
+
if (pluginUrl.endsWith('tar.gz')) {
|
|
214
|
+
fileExt = '.tar.gz';
|
|
215
|
+
} else if (pluginUrl.endsWith('vsix')) {
|
|
216
|
+
fileExt = '.vsix';
|
|
217
|
+
} else if (pluginUrl.endsWith('theia')) {
|
|
218
|
+
fileExt = '.theia'; // theia plugins.
|
|
219
|
+
} else {
|
|
220
|
+
failures.push(chalk.red(`error: '${plugin}' has an unsupported file type: '${pluginUrl}'`));
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
const targetPath = path.resolve(pluginsDir, `${plugin}${packed === true ? fileExt : ''}`);
|
|
224
|
+
|
|
225
|
+
// Skip plugins which have previously been downloaded.
|
|
226
|
+
if (await isDownloaded(targetPath)) {
|
|
227
|
+
console.warn('- ' + plugin + ': already downloaded - skipping');
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
const maxAttempts = 5;
|
|
232
|
+
const retryDelay = 2000;
|
|
233
|
+
|
|
234
|
+
let attempts: number;
|
|
235
|
+
let lastError: Error | undefined;
|
|
236
|
+
let response: RequestContext | undefined;
|
|
237
|
+
|
|
238
|
+
for (attempts = 0; attempts < maxAttempts; attempts++) {
|
|
239
|
+
if (attempts > 0) {
|
|
240
|
+
await new Promise(resolve => setTimeout(resolve, retryDelay));
|
|
241
|
+
}
|
|
242
|
+
lastError = undefined;
|
|
243
|
+
try {
|
|
244
|
+
await rateLimiter.removeTokens(1);
|
|
245
|
+
response = await requestService.request({
|
|
246
|
+
url: pluginUrl
|
|
247
|
+
});
|
|
248
|
+
} catch (error) {
|
|
249
|
+
lastError = error;
|
|
250
|
+
continue;
|
|
251
|
+
}
|
|
252
|
+
const status = response.res.statusCode;
|
|
253
|
+
const retry = status && (status === 429 || status === 439 || status >= 500);
|
|
254
|
+
if (!retry) {
|
|
255
|
+
break;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
if (lastError) {
|
|
259
|
+
failures.push(chalk.red(`x ${plugin}: failed to download, last error:\n ${lastError}`));
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
if (typeof response === 'undefined') {
|
|
263
|
+
failures.push(chalk.red(`x ${plugin}: failed to download (unknown reason)`));
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
if (response.res.statusCode !== 200) {
|
|
267
|
+
failures.push(chalk.red(`x ${plugin}: failed to download with: ${response.res.statusCode}`));
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
if ((fileExt === '.vsix' || fileExt === '.theia') && packed === true) {
|
|
272
|
+
// Download .vsix without decompressing.
|
|
273
|
+
await fs.writeFile(targetPath, response.buffer);
|
|
274
|
+
} else {
|
|
275
|
+
await fs.mkdir(targetPath, { recursive: true });
|
|
276
|
+
const tempFile = temp.path('theia-plugin-download');
|
|
277
|
+
await fs.writeFile(tempFile, response.buffer);
|
|
278
|
+
await decompress(tempFile, targetPath);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
console.warn(chalk.green(`+ ${plugin}${version ? `@${version}` : ''}: downloaded successfully ${attempts > 1 ? `(after ${attempts} attempts)` : ''}`));
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* Determine if the resource for the given path is already downloaded.
|
|
286
|
+
* @param filePath the resource path.
|
|
287
|
+
*
|
|
288
|
+
* @returns `true` if the resource is already downloaded, else `false`.
|
|
289
|
+
*/
|
|
290
|
+
async function isDownloaded(filePath: string): Promise<boolean> {
|
|
291
|
+
return fs.stat(filePath).then(() => true, () => false);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* Walk the plugin directory and collect available extension paths.
|
|
296
|
+
* @param pluginDir the plugin directory.
|
|
297
|
+
* @returns the list of all available extension paths.
|
|
298
|
+
*/
|
|
299
|
+
async function collectPackageJsonPaths(pluginDir: string): Promise<string[]> {
|
|
300
|
+
const packageJsonPathList: string[] = [];
|
|
301
|
+
const files = await fs.readdir(pluginDir);
|
|
302
|
+
// Recursively fetch the list of extension `package.json` files.
|
|
303
|
+
for (const file of files) {
|
|
304
|
+
const filePath = path.join(pluginDir, file);
|
|
305
|
+
if ((await fs.stat(filePath)).isDirectory()) {
|
|
306
|
+
packageJsonPathList.push(...await collectPackageJsonPaths(filePath));
|
|
307
|
+
} else if (path.basename(filePath) === 'package.json' && !path.dirname(filePath).includes('node_modules')) {
|
|
308
|
+
packageJsonPathList.push(filePath);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
return packageJsonPathList;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* Get the mapping of extension-pack paths and their included plugin ids.
|
|
316
|
+
* - If an extension-pack references an explicitly excluded `id` the `id` will be omitted.
|
|
317
|
+
* @param pluginDir the plugin directory.
|
|
318
|
+
* @param excludedIds the list of plugin ids to exclude.
|
|
319
|
+
* @returns the mapping of extension-pack paths and their included plugin ids.
|
|
320
|
+
*/
|
|
321
|
+
async function collectExtensionPacks(pluginDir: string, excludedIds: Set<string>): Promise<Map<string, string[]>> {
|
|
322
|
+
const extensionPackPaths = new Map<string, string[]>();
|
|
323
|
+
const packageJsonPaths = await collectPackageJsonPaths(pluginDir);
|
|
324
|
+
await Promise.all(packageJsonPaths.map(async packageJsonPath => {
|
|
325
|
+
const json = JSON.parse(await fs.readFile(packageJsonPath, 'utf8'));
|
|
326
|
+
const extensionPack: unknown = json.extensionPack;
|
|
327
|
+
if (Array.isArray(extensionPack)) {
|
|
328
|
+
extensionPackPaths.set(packageJsonPath, extensionPack.filter(id => {
|
|
329
|
+
if (excludedIds.has(id)) {
|
|
330
|
+
console.log(chalk.yellow(`'${id}' referred to by '${json.name}' (ext pack) is excluded because of 'theiaPluginsExcludeIds'`));
|
|
331
|
+
return false; // remove
|
|
332
|
+
}
|
|
333
|
+
return true; // keep
|
|
334
|
+
}));
|
|
335
|
+
}
|
|
336
|
+
}));
|
|
337
|
+
return extensionPackPaths;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* Get the mapping of paths and their included plugin ids.
|
|
342
|
+
* - If an extension-pack references an explicitly excluded `id` the `id` will be omitted.
|
|
343
|
+
* @param pluginDir the plugin directory.
|
|
344
|
+
* @param excludedIds the list of plugin ids to exclude.
|
|
345
|
+
* @returns the mapping of extension-pack paths and their included plugin ids.
|
|
346
|
+
*/
|
|
347
|
+
async function collectPluginDependencies(pluginDir: string, excludedIds: Set<string>): Promise<string[]> {
|
|
348
|
+
const dependencyIds: string[] = [];
|
|
349
|
+
const packageJsonPaths = await collectPackageJsonPaths(pluginDir);
|
|
350
|
+
await Promise.all(packageJsonPaths.map(async packageJsonPath => {
|
|
351
|
+
const json = JSON.parse(await fs.readFile(packageJsonPath, 'utf8'));
|
|
352
|
+
const extensionDependencies: unknown = json.extensionDependencies;
|
|
353
|
+
if (Array.isArray(extensionDependencies)) {
|
|
354
|
+
for (const dependency of extensionDependencies) {
|
|
355
|
+
if (excludedIds.has(dependency)) {
|
|
356
|
+
console.log(chalk.yellow(`'${dependency}' referred to by '${json.name}' is excluded because of 'theiaPluginsExcludeIds'`));
|
|
357
|
+
} else {
|
|
358
|
+
dependencyIds.push(dependency);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
}));
|
|
363
|
+
return dependencyIds;
|
|
364
|
+
}
|