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