@theia/plugin-dev 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 +31 -31
- package/lib/browser/hosted-plugin-controller.d.ts +74 -74
- package/lib/browser/hosted-plugin-controller.js +352 -352
- package/lib/browser/hosted-plugin-frontend-contribution.d.ts +6 -6
- package/lib/browser/hosted-plugin-frontend-contribution.js +56 -56
- package/lib/browser/hosted-plugin-informer.d.ts +25 -25
- package/lib/browser/hosted-plugin-informer.js +102 -102
- package/lib/browser/hosted-plugin-log-viewer.d.ts +14 -14
- package/lib/browser/hosted-plugin-log-viewer.js +69 -69
- package/lib/browser/hosted-plugin-manager-client.d.ts +80 -80
- package/lib/browser/hosted-plugin-manager-client.js +410 -410
- package/lib/browser/hosted-plugin-preferences.d.ts +13 -13
- package/lib/browser/hosted-plugin-preferences.js +60 -60
- package/lib/browser/plugin-dev-frontend-module.d.ts +3 -3
- package/lib/browser/plugin-dev-frontend-module.js +42 -42
- package/lib/common/index.d.ts +2 -2
- package/lib/common/index.js +31 -31
- package/lib/common/plugin-dev-protocol.d.ts +24 -24
- package/lib/common/plugin-dev-protocol.js +20 -20
- package/lib/node/hosted-instance-manager.d.ts +104 -104
- package/lib/node/hosted-instance-manager.js +320 -320
- package/lib/node/hosted-instance-manager.js.map +1 -1
- package/lib/node/hosted-plugin-reader.d.ts +11 -11
- package/lib/node/hosted-plugin-reader.js +68 -68
- package/lib/node/hosted-plugin-reader.js.map +1 -1
- package/lib/node/hosted-plugin-uri-postprocessor.d.ts +6 -6
- package/lib/node/hosted-plugin-uri-postprocessor.js +27 -27
- package/lib/node/hosted-plugins-manager.d.ts +41 -41
- package/lib/node/hosted-plugins-manager.js +119 -119
- package/lib/node/plugin-dev-backend-module.d.ts +4 -4
- package/lib/node/plugin-dev-backend-module.js +53 -53
- package/lib/node/plugin-dev-service.d.ts +25 -25
- package/lib/node/plugin-dev-service.js +108 -108
- package/lib/node-electron/plugin-dev-electron-backend-module.d.ts +3 -3
- package/lib/node-electron/plugin-dev-electron-backend-module.js +28 -28
- package/lib/package.spec.js +25 -25
- package/package.json +9 -9
- package/src/browser/hosted-plugin-controller.ts +356 -356
- package/src/browser/hosted-plugin-frontend-contribution.ts +45 -45
- package/src/browser/hosted-plugin-informer.ts +93 -93
- package/src/browser/hosted-plugin-log-viewer.ts +52 -52
- package/src/browser/hosted-plugin-manager-client.ts +430 -430
- package/src/browser/hosted-plugin-preferences.ts +71 -71
- package/src/browser/plugin-dev-frontend-module.ts +45 -45
- package/src/common/index.ts +21 -21
- package/src/common/plugin-dev-protocol.ts +45 -45
- package/src/node/hosted-instance-manager.ts +382 -382
- package/src/node/hosted-plugin-reader.ts +58 -58
- package/src/node/hosted-plugin-uri-postprocessor.ts +32 -32
- package/src/node/hosted-plugins-manager.ts +146 -146
- package/src/node/plugin-dev-backend-module.ts +54 -54
- package/src/node/plugin-dev-service.ts +107 -107
- package/src/node-electron/plugin-dev-electron-backend-module.ts +29 -29
- package/src/package.spec.ts +28 -28
|
@@ -1,321 +1,321 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// *****************************************************************************
|
|
3
|
-
// Copyright (C) 2018 Red Hat, Inc. 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.ElectronNodeHostedPluginRunner = exports.NodeHostedPluginRunner = exports.AbstractHostedInstanceManager = exports.HostedInstanceManager = void 0;
|
|
28
|
-
const request_1 = require("@theia/core/shared/@theia/request");
|
|
29
|
-
const inversify_1 = require("@theia/core/shared/inversify");
|
|
30
|
-
const cp = require("child_process");
|
|
31
|
-
const fs = require("@theia/core/shared/fs-extra");
|
|
32
|
-
const net = require("net");
|
|
33
|
-
const path = require("path");
|
|
34
|
-
const uri_1 = require("@theia/core/lib/common/uri");
|
|
35
|
-
const contribution_provider_1 = require("@theia/core/lib/common/contribution-provider");
|
|
36
|
-
const hosted_plugin_uri_postprocessor_1 = require("./hosted-plugin-uri-postprocessor");
|
|
37
|
-
const core_1 = require("@theia/core");
|
|
38
|
-
const file_uri_1 = require("@theia/core/lib/
|
|
39
|
-
const types_1 = require("@theia/plugin-ext/lib/common/types");
|
|
40
|
-
const hosted_plugin_1 = require("@theia/plugin-ext/lib/hosted/node/hosted-plugin");
|
|
41
|
-
const metadata_scanner_1 = require("@theia/plugin-ext/lib/hosted/node/metadata-scanner");
|
|
42
|
-
const hosted_plugin_process_1 = require("@theia/plugin-ext/lib/hosted/node/hosted-plugin-process");
|
|
43
|
-
const errors_1 = require("@theia/plugin-ext/lib/common/errors");
|
|
44
|
-
const DEFAULT_HOSTED_PLUGIN_PORT = 3030;
|
|
45
|
-
exports.HostedInstanceManager = Symbol('HostedInstanceManager');
|
|
46
|
-
const HOSTED_INSTANCE_START_TIMEOUT_MS = 30000;
|
|
47
|
-
const THEIA_INSTANCE_REGEX = /.*Theia app listening on (.*).*\./;
|
|
48
|
-
const PROCESS_OPTIONS = {
|
|
49
|
-
cwd: process.cwd(),
|
|
50
|
-
env: { ...process.env }
|
|
51
|
-
};
|
|
52
|
-
let AbstractHostedInstanceManager = class AbstractHostedInstanceManager {
|
|
53
|
-
constructor() {
|
|
54
|
-
this.isPluginRunning = false;
|
|
55
|
-
}
|
|
56
|
-
isRunning() {
|
|
57
|
-
return this.isPluginRunning;
|
|
58
|
-
}
|
|
59
|
-
async run(pluginUri, port) {
|
|
60
|
-
return this.doRun(pluginUri, port);
|
|
61
|
-
}
|
|
62
|
-
async debug(pluginUri, debugConfig) {
|
|
63
|
-
return this.doRun(pluginUri, undefined, debugConfig);
|
|
64
|
-
}
|
|
65
|
-
async doRun(pluginUri, port, debugConfig) {
|
|
66
|
-
if (this.isPluginRunning) {
|
|
67
|
-
this.hostedPluginSupport.sendLog({ data: 'Hosted plugin instance is already running.', type: types_1.LogType.Info });
|
|
68
|
-
throw new Error('Hosted instance is already running.');
|
|
69
|
-
}
|
|
70
|
-
let command;
|
|
71
|
-
let processOptions;
|
|
72
|
-
if (pluginUri.scheme === 'file') {
|
|
73
|
-
processOptions = { ...PROCESS_OPTIONS };
|
|
74
|
-
// get filesystem path that work cross operating systems
|
|
75
|
-
processOptions.env.HOSTED_PLUGIN = file_uri_1.FileUri.fsPath(pluginUri.toString());
|
|
76
|
-
// Disable all the other plugins on this instance
|
|
77
|
-
processOptions.env.THEIA_PLUGINS = '';
|
|
78
|
-
command = await this.getStartCommand(port, debugConfig);
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
81
|
-
throw new Error('Not supported plugin location: ' + pluginUri.toString());
|
|
82
|
-
}
|
|
83
|
-
this.instanceUri = await this.postProcessInstanceUri(await this.runHostedPluginTheiaInstance(command, processOptions));
|
|
84
|
-
this.pluginUri = pluginUri;
|
|
85
|
-
// disable redirect to grab the release
|
|
86
|
-
this.instanceOptions = {
|
|
87
|
-
followRedirects: 0
|
|
88
|
-
};
|
|
89
|
-
this.instanceOptions = await this.postProcessInstanceOptions(this.instanceOptions);
|
|
90
|
-
await this.checkInstanceUriReady();
|
|
91
|
-
return this.instanceUri;
|
|
92
|
-
}
|
|
93
|
-
terminate() {
|
|
94
|
-
if (this.isPluginRunning && !!this.hostedInstanceProcess.pid) {
|
|
95
|
-
this.hostedPluginProcess.killProcessTree(this.hostedInstanceProcess.pid);
|
|
96
|
-
this.hostedPluginSupport.sendLog({ data: 'Hosted instance has been terminated', type: types_1.LogType.Info });
|
|
97
|
-
this.isPluginRunning = false;
|
|
98
|
-
}
|
|
99
|
-
else {
|
|
100
|
-
throw new Error('Hosted plugin instance is not running.');
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
getInstanceURI() {
|
|
104
|
-
if (this.isPluginRunning) {
|
|
105
|
-
return this.instanceUri;
|
|
106
|
-
}
|
|
107
|
-
throw new Error('Hosted plugin instance is not running.');
|
|
108
|
-
}
|
|
109
|
-
getPluginURI() {
|
|
110
|
-
if (this.isPluginRunning) {
|
|
111
|
-
return this.pluginUri;
|
|
112
|
-
}
|
|
113
|
-
throw new Error('Hosted plugin instance is not running.');
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* Checks that the `instanceUri` is responding before exiting method
|
|
117
|
-
*/
|
|
118
|
-
async checkInstanceUriReady() {
|
|
119
|
-
return new Promise((resolve, reject) => this.pingLoop(60, resolve, reject));
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* Start a loop to ping, if ping is OK return immediately, else start a new ping after 1second. We iterate for the given amount of loops provided in remainingCount
|
|
123
|
-
* @param remainingCount the number of occurrence to check
|
|
124
|
-
* @param resolve resolve function if ok
|
|
125
|
-
* @param reject reject function if error
|
|
126
|
-
*/
|
|
127
|
-
async pingLoop(remainingCount, resolve, reject) {
|
|
128
|
-
const isOK = await this.ping();
|
|
129
|
-
if (isOK) {
|
|
130
|
-
resolve();
|
|
131
|
-
}
|
|
132
|
-
else {
|
|
133
|
-
if (remainingCount > 0) {
|
|
134
|
-
setTimeout(() => this.pingLoop(--remainingCount, resolve, reject), 1000);
|
|
135
|
-
}
|
|
136
|
-
else {
|
|
137
|
-
reject(new Error('Unable to ping the remote server'));
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
/**
|
|
142
|
-
* Ping the plugin URI (checking status of the head)
|
|
143
|
-
*/
|
|
144
|
-
async ping() {
|
|
145
|
-
try {
|
|
146
|
-
const url = this.instanceUri.toString();
|
|
147
|
-
// Wait that the status is OK
|
|
148
|
-
const response = await this.request.request({ url, type: 'HEAD', ...this.instanceOptions });
|
|
149
|
-
return response.res.statusCode === 200;
|
|
150
|
-
}
|
|
151
|
-
catch {
|
|
152
|
-
return false;
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
async isPluginValid(uri) {
|
|
156
|
-
const pckPath = path.join(file_uri_1.FileUri.fsPath(uri), 'package.json');
|
|
157
|
-
try {
|
|
158
|
-
const pck = await fs.readJSON(pckPath);
|
|
159
|
-
this.metadata.getScanner(pck);
|
|
160
|
-
return true;
|
|
161
|
-
}
|
|
162
|
-
catch (err) {
|
|
163
|
-
if (!(0, errors_1.isENOENT)(err)) {
|
|
164
|
-
console.error(err);
|
|
165
|
-
}
|
|
166
|
-
return false;
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
async getStartCommand(port, debugConfig) {
|
|
170
|
-
const processArguments = process.argv;
|
|
171
|
-
let command;
|
|
172
|
-
if (core_1.environment.electron.is()) {
|
|
173
|
-
command = ['yarn', 'theia', 'start'];
|
|
174
|
-
}
|
|
175
|
-
else {
|
|
176
|
-
command = processArguments.filter((arg, index, args) => {
|
|
177
|
-
// remove --port=X and --port X arguments if set
|
|
178
|
-
// remove --plugins arguments
|
|
179
|
-
if (arg.startsWith('--port') || args[index - 1] === '--port') {
|
|
180
|
-
return;
|
|
181
|
-
}
|
|
182
|
-
else {
|
|
183
|
-
return arg;
|
|
184
|
-
}
|
|
185
|
-
});
|
|
186
|
-
}
|
|
187
|
-
if (process.env.HOSTED_PLUGIN_HOSTNAME) {
|
|
188
|
-
command.push('--hostname=' + process.env.HOSTED_PLUGIN_HOSTNAME);
|
|
189
|
-
}
|
|
190
|
-
if (port) {
|
|
191
|
-
await this.validatePort(port);
|
|
192
|
-
command.push('--port=' + port);
|
|
193
|
-
}
|
|
194
|
-
if (debugConfig) {
|
|
195
|
-
command.push(`--hosted-plugin-${debugConfig.debugMode || 'inspect'}=0.0.0.0${debugConfig.debugPort ? ':' + debugConfig.debugPort : ''}`);
|
|
196
|
-
}
|
|
197
|
-
return command;
|
|
198
|
-
}
|
|
199
|
-
async postProcessInstanceUri(uri) {
|
|
200
|
-
return uri;
|
|
201
|
-
}
|
|
202
|
-
async postProcessInstanceOptions(options) {
|
|
203
|
-
return options;
|
|
204
|
-
}
|
|
205
|
-
runHostedPluginTheiaInstance(command, options) {
|
|
206
|
-
this.isPluginRunning = true;
|
|
207
|
-
return new Promise((resolve, reject) => {
|
|
208
|
-
let started = false;
|
|
209
|
-
const outputListener = (data) => {
|
|
210
|
-
const line = data.toString();
|
|
211
|
-
const match = THEIA_INSTANCE_REGEX.exec(line);
|
|
212
|
-
if (match) {
|
|
213
|
-
this.hostedInstanceProcess.stdout.removeListener('data', outputListener);
|
|
214
|
-
started = true;
|
|
215
|
-
resolve(new uri_1.default(match[1]));
|
|
216
|
-
}
|
|
217
|
-
};
|
|
218
|
-
if (core_1.isWindows) {
|
|
219
|
-
// Has to be set for running on windows (electron).
|
|
220
|
-
// See also: https://github.com/nodejs/node/issues/3675
|
|
221
|
-
options.shell = true;
|
|
222
|
-
}
|
|
223
|
-
this.hostedInstanceProcess = cp.spawn(command.shift(), command, options);
|
|
224
|
-
this.hostedInstanceProcess.on('error', () => { this.isPluginRunning = false; });
|
|
225
|
-
this.hostedInstanceProcess.on('exit', () => { this.isPluginRunning = false; });
|
|
226
|
-
this.hostedInstanceProcess.stdout.addListener('data', outputListener);
|
|
227
|
-
this.hostedInstanceProcess.stdout.addListener('data', data => {
|
|
228
|
-
this.hostedPluginSupport.sendLog({ data: data.toString(), type: types_1.LogType.Info });
|
|
229
|
-
});
|
|
230
|
-
this.hostedInstanceProcess.stderr.addListener('data', data => {
|
|
231
|
-
this.hostedPluginSupport.sendLog({ data: data.toString(), type: types_1.LogType.Error });
|
|
232
|
-
});
|
|
233
|
-
setTimeout(() => {
|
|
234
|
-
if (!started) {
|
|
235
|
-
this.terminate();
|
|
236
|
-
this.isPluginRunning = false;
|
|
237
|
-
reject(new Error('Timeout.'));
|
|
238
|
-
}
|
|
239
|
-
}, HOSTED_INSTANCE_START_TIMEOUT_MS);
|
|
240
|
-
});
|
|
241
|
-
}
|
|
242
|
-
async validatePort(port) {
|
|
243
|
-
if (port < 1 || port > 65535) {
|
|
244
|
-
throw new Error('Port value is incorrect.');
|
|
245
|
-
}
|
|
246
|
-
if (!await this.isPortFree(port)) {
|
|
247
|
-
throw new Error('Port ' + port + ' is already in use.');
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
isPortFree(port) {
|
|
251
|
-
return new Promise(resolve => {
|
|
252
|
-
const server = net.createServer();
|
|
253
|
-
server.listen(port, '0.0.0.0');
|
|
254
|
-
server.on('error', () => {
|
|
255
|
-
resolve(false);
|
|
256
|
-
});
|
|
257
|
-
server.on('listening', () => {
|
|
258
|
-
server.close();
|
|
259
|
-
resolve(true);
|
|
260
|
-
});
|
|
261
|
-
});
|
|
262
|
-
}
|
|
263
|
-
};
|
|
264
|
-
__decorate([
|
|
265
|
-
(0, inversify_1.inject)(hosted_plugin_1.HostedPluginSupport),
|
|
266
|
-
__metadata("design:type", hosted_plugin_1.HostedPluginSupport)
|
|
267
|
-
], AbstractHostedInstanceManager.prototype, "hostedPluginSupport", void 0);
|
|
268
|
-
__decorate([
|
|
269
|
-
(0, inversify_1.inject)(metadata_scanner_1.MetadataScanner),
|
|
270
|
-
__metadata("design:type", metadata_scanner_1.MetadataScanner)
|
|
271
|
-
], AbstractHostedInstanceManager.prototype, "metadata", void 0);
|
|
272
|
-
__decorate([
|
|
273
|
-
(0, inversify_1.inject)(hosted_plugin_process_1.HostedPluginProcess),
|
|
274
|
-
__metadata("design:type", hosted_plugin_process_1.HostedPluginProcess)
|
|
275
|
-
], AbstractHostedInstanceManager.prototype, "hostedPluginProcess", void 0);
|
|
276
|
-
__decorate([
|
|
277
|
-
(0, inversify_1.inject)(request_1.RequestService),
|
|
278
|
-
__metadata("design:type", Object)
|
|
279
|
-
], AbstractHostedInstanceManager.prototype, "request", void 0);
|
|
280
|
-
AbstractHostedInstanceManager = __decorate([
|
|
281
|
-
(0, inversify_1.injectable)()
|
|
282
|
-
], AbstractHostedInstanceManager);
|
|
283
|
-
exports.AbstractHostedInstanceManager = AbstractHostedInstanceManager;
|
|
284
|
-
let NodeHostedPluginRunner = class NodeHostedPluginRunner extends AbstractHostedInstanceManager {
|
|
285
|
-
async postProcessInstanceUri(uri) {
|
|
286
|
-
for (const uriPostProcessor of this.uriPostProcessors.getContributions()) {
|
|
287
|
-
uri = await uriPostProcessor.processUri(uri);
|
|
288
|
-
}
|
|
289
|
-
return uri;
|
|
290
|
-
}
|
|
291
|
-
async postProcessInstanceOptions(options) {
|
|
292
|
-
for (const uriPostProcessor of this.uriPostProcessors.getContributions()) {
|
|
293
|
-
options = await uriPostProcessor.processOptions(options);
|
|
294
|
-
}
|
|
295
|
-
return options;
|
|
296
|
-
}
|
|
297
|
-
async getStartCommand(port, debugConfig) {
|
|
298
|
-
if (!port) {
|
|
299
|
-
port = process.env.HOSTED_PLUGIN_PORT ?
|
|
300
|
-
Number(process.env.HOSTED_PLUGIN_PORT) :
|
|
301
|
-
((debugConfig === null || debugConfig === void 0 ? void 0 : debugConfig.debugPort) ? Number(debugConfig.debugPort) : DEFAULT_HOSTED_PLUGIN_PORT);
|
|
302
|
-
}
|
|
303
|
-
return super.getStartCommand(port, debugConfig);
|
|
304
|
-
}
|
|
305
|
-
};
|
|
306
|
-
__decorate([
|
|
307
|
-
(0, inversify_1.inject)(contribution_provider_1.ContributionProvider),
|
|
308
|
-
(0, inversify_1.named)(Symbol.for(hosted_plugin_uri_postprocessor_1.HostedPluginUriPostProcessorSymbolName)),
|
|
309
|
-
__metadata("design:type", Object)
|
|
310
|
-
], NodeHostedPluginRunner.prototype, "uriPostProcessors", void 0);
|
|
311
|
-
NodeHostedPluginRunner = __decorate([
|
|
312
|
-
(0, inversify_1.injectable)()
|
|
313
|
-
], NodeHostedPluginRunner);
|
|
314
|
-
exports.NodeHostedPluginRunner = NodeHostedPluginRunner;
|
|
315
|
-
let ElectronNodeHostedPluginRunner = class ElectronNodeHostedPluginRunner extends AbstractHostedInstanceManager {
|
|
316
|
-
};
|
|
317
|
-
ElectronNodeHostedPluginRunner = __decorate([
|
|
318
|
-
(0, inversify_1.injectable)()
|
|
319
|
-
], ElectronNodeHostedPluginRunner);
|
|
320
|
-
exports.ElectronNodeHostedPluginRunner = ElectronNodeHostedPluginRunner;
|
|
1
|
+
"use strict";
|
|
2
|
+
// *****************************************************************************
|
|
3
|
+
// Copyright (C) 2018 Red Hat, Inc. 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.ElectronNodeHostedPluginRunner = exports.NodeHostedPluginRunner = exports.AbstractHostedInstanceManager = exports.HostedInstanceManager = void 0;
|
|
28
|
+
const request_1 = require("@theia/core/shared/@theia/request");
|
|
29
|
+
const inversify_1 = require("@theia/core/shared/inversify");
|
|
30
|
+
const cp = require("child_process");
|
|
31
|
+
const fs = require("@theia/core/shared/fs-extra");
|
|
32
|
+
const net = require("net");
|
|
33
|
+
const path = require("path");
|
|
34
|
+
const uri_1 = require("@theia/core/lib/common/uri");
|
|
35
|
+
const contribution_provider_1 = require("@theia/core/lib/common/contribution-provider");
|
|
36
|
+
const hosted_plugin_uri_postprocessor_1 = require("./hosted-plugin-uri-postprocessor");
|
|
37
|
+
const core_1 = require("@theia/core");
|
|
38
|
+
const file_uri_1 = require("@theia/core/lib/common/file-uri");
|
|
39
|
+
const types_1 = require("@theia/plugin-ext/lib/common/types");
|
|
40
|
+
const hosted_plugin_1 = require("@theia/plugin-ext/lib/hosted/node/hosted-plugin");
|
|
41
|
+
const metadata_scanner_1 = require("@theia/plugin-ext/lib/hosted/node/metadata-scanner");
|
|
42
|
+
const hosted_plugin_process_1 = require("@theia/plugin-ext/lib/hosted/node/hosted-plugin-process");
|
|
43
|
+
const errors_1 = require("@theia/plugin-ext/lib/common/errors");
|
|
44
|
+
const DEFAULT_HOSTED_PLUGIN_PORT = 3030;
|
|
45
|
+
exports.HostedInstanceManager = Symbol('HostedInstanceManager');
|
|
46
|
+
const HOSTED_INSTANCE_START_TIMEOUT_MS = 30000;
|
|
47
|
+
const THEIA_INSTANCE_REGEX = /.*Theia app listening on (.*).*\./;
|
|
48
|
+
const PROCESS_OPTIONS = {
|
|
49
|
+
cwd: process.cwd(),
|
|
50
|
+
env: { ...process.env }
|
|
51
|
+
};
|
|
52
|
+
let AbstractHostedInstanceManager = class AbstractHostedInstanceManager {
|
|
53
|
+
constructor() {
|
|
54
|
+
this.isPluginRunning = false;
|
|
55
|
+
}
|
|
56
|
+
isRunning() {
|
|
57
|
+
return this.isPluginRunning;
|
|
58
|
+
}
|
|
59
|
+
async run(pluginUri, port) {
|
|
60
|
+
return this.doRun(pluginUri, port);
|
|
61
|
+
}
|
|
62
|
+
async debug(pluginUri, debugConfig) {
|
|
63
|
+
return this.doRun(pluginUri, undefined, debugConfig);
|
|
64
|
+
}
|
|
65
|
+
async doRun(pluginUri, port, debugConfig) {
|
|
66
|
+
if (this.isPluginRunning) {
|
|
67
|
+
this.hostedPluginSupport.sendLog({ data: 'Hosted plugin instance is already running.', type: types_1.LogType.Info });
|
|
68
|
+
throw new Error('Hosted instance is already running.');
|
|
69
|
+
}
|
|
70
|
+
let command;
|
|
71
|
+
let processOptions;
|
|
72
|
+
if (pluginUri.scheme === 'file') {
|
|
73
|
+
processOptions = { ...PROCESS_OPTIONS };
|
|
74
|
+
// get filesystem path that work cross operating systems
|
|
75
|
+
processOptions.env.HOSTED_PLUGIN = file_uri_1.FileUri.fsPath(pluginUri.toString());
|
|
76
|
+
// Disable all the other plugins on this instance
|
|
77
|
+
processOptions.env.THEIA_PLUGINS = '';
|
|
78
|
+
command = await this.getStartCommand(port, debugConfig);
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
throw new Error('Not supported plugin location: ' + pluginUri.toString());
|
|
82
|
+
}
|
|
83
|
+
this.instanceUri = await this.postProcessInstanceUri(await this.runHostedPluginTheiaInstance(command, processOptions));
|
|
84
|
+
this.pluginUri = pluginUri;
|
|
85
|
+
// disable redirect to grab the release
|
|
86
|
+
this.instanceOptions = {
|
|
87
|
+
followRedirects: 0
|
|
88
|
+
};
|
|
89
|
+
this.instanceOptions = await this.postProcessInstanceOptions(this.instanceOptions);
|
|
90
|
+
await this.checkInstanceUriReady();
|
|
91
|
+
return this.instanceUri;
|
|
92
|
+
}
|
|
93
|
+
terminate() {
|
|
94
|
+
if (this.isPluginRunning && !!this.hostedInstanceProcess.pid) {
|
|
95
|
+
this.hostedPluginProcess.killProcessTree(this.hostedInstanceProcess.pid);
|
|
96
|
+
this.hostedPluginSupport.sendLog({ data: 'Hosted instance has been terminated', type: types_1.LogType.Info });
|
|
97
|
+
this.isPluginRunning = false;
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
throw new Error('Hosted plugin instance is not running.');
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
getInstanceURI() {
|
|
104
|
+
if (this.isPluginRunning) {
|
|
105
|
+
return this.instanceUri;
|
|
106
|
+
}
|
|
107
|
+
throw new Error('Hosted plugin instance is not running.');
|
|
108
|
+
}
|
|
109
|
+
getPluginURI() {
|
|
110
|
+
if (this.isPluginRunning) {
|
|
111
|
+
return this.pluginUri;
|
|
112
|
+
}
|
|
113
|
+
throw new Error('Hosted plugin instance is not running.');
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Checks that the `instanceUri` is responding before exiting method
|
|
117
|
+
*/
|
|
118
|
+
async checkInstanceUriReady() {
|
|
119
|
+
return new Promise((resolve, reject) => this.pingLoop(60, resolve, reject));
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Start a loop to ping, if ping is OK return immediately, else start a new ping after 1second. We iterate for the given amount of loops provided in remainingCount
|
|
123
|
+
* @param remainingCount the number of occurrence to check
|
|
124
|
+
* @param resolve resolve function if ok
|
|
125
|
+
* @param reject reject function if error
|
|
126
|
+
*/
|
|
127
|
+
async pingLoop(remainingCount, resolve, reject) {
|
|
128
|
+
const isOK = await this.ping();
|
|
129
|
+
if (isOK) {
|
|
130
|
+
resolve();
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
if (remainingCount > 0) {
|
|
134
|
+
setTimeout(() => this.pingLoop(--remainingCount, resolve, reject), 1000);
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
reject(new Error('Unable to ping the remote server'));
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Ping the plugin URI (checking status of the head)
|
|
143
|
+
*/
|
|
144
|
+
async ping() {
|
|
145
|
+
try {
|
|
146
|
+
const url = this.instanceUri.toString();
|
|
147
|
+
// Wait that the status is OK
|
|
148
|
+
const response = await this.request.request({ url, type: 'HEAD', ...this.instanceOptions });
|
|
149
|
+
return response.res.statusCode === 200;
|
|
150
|
+
}
|
|
151
|
+
catch {
|
|
152
|
+
return false;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
async isPluginValid(uri) {
|
|
156
|
+
const pckPath = path.join(file_uri_1.FileUri.fsPath(uri), 'package.json');
|
|
157
|
+
try {
|
|
158
|
+
const pck = await fs.readJSON(pckPath);
|
|
159
|
+
this.metadata.getScanner(pck);
|
|
160
|
+
return true;
|
|
161
|
+
}
|
|
162
|
+
catch (err) {
|
|
163
|
+
if (!(0, errors_1.isENOENT)(err)) {
|
|
164
|
+
console.error(err);
|
|
165
|
+
}
|
|
166
|
+
return false;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
async getStartCommand(port, debugConfig) {
|
|
170
|
+
const processArguments = process.argv;
|
|
171
|
+
let command;
|
|
172
|
+
if (core_1.environment.electron.is()) {
|
|
173
|
+
command = ['yarn', 'theia', 'start'];
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
command = processArguments.filter((arg, index, args) => {
|
|
177
|
+
// remove --port=X and --port X arguments if set
|
|
178
|
+
// remove --plugins arguments
|
|
179
|
+
if (arg.startsWith('--port') || args[index - 1] === '--port') {
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
return arg;
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
if (process.env.HOSTED_PLUGIN_HOSTNAME) {
|
|
188
|
+
command.push('--hostname=' + process.env.HOSTED_PLUGIN_HOSTNAME);
|
|
189
|
+
}
|
|
190
|
+
if (port) {
|
|
191
|
+
await this.validatePort(port);
|
|
192
|
+
command.push('--port=' + port);
|
|
193
|
+
}
|
|
194
|
+
if (debugConfig) {
|
|
195
|
+
command.push(`--hosted-plugin-${debugConfig.debugMode || 'inspect'}=0.0.0.0${debugConfig.debugPort ? ':' + debugConfig.debugPort : ''}`);
|
|
196
|
+
}
|
|
197
|
+
return command;
|
|
198
|
+
}
|
|
199
|
+
async postProcessInstanceUri(uri) {
|
|
200
|
+
return uri;
|
|
201
|
+
}
|
|
202
|
+
async postProcessInstanceOptions(options) {
|
|
203
|
+
return options;
|
|
204
|
+
}
|
|
205
|
+
runHostedPluginTheiaInstance(command, options) {
|
|
206
|
+
this.isPluginRunning = true;
|
|
207
|
+
return new Promise((resolve, reject) => {
|
|
208
|
+
let started = false;
|
|
209
|
+
const outputListener = (data) => {
|
|
210
|
+
const line = data.toString();
|
|
211
|
+
const match = THEIA_INSTANCE_REGEX.exec(line);
|
|
212
|
+
if (match) {
|
|
213
|
+
this.hostedInstanceProcess.stdout.removeListener('data', outputListener);
|
|
214
|
+
started = true;
|
|
215
|
+
resolve(new uri_1.default(match[1]));
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
if (core_1.isWindows) {
|
|
219
|
+
// Has to be set for running on windows (electron).
|
|
220
|
+
// See also: https://github.com/nodejs/node/issues/3675
|
|
221
|
+
options.shell = true;
|
|
222
|
+
}
|
|
223
|
+
this.hostedInstanceProcess = cp.spawn(command.shift(), command, options);
|
|
224
|
+
this.hostedInstanceProcess.on('error', () => { this.isPluginRunning = false; });
|
|
225
|
+
this.hostedInstanceProcess.on('exit', () => { this.isPluginRunning = false; });
|
|
226
|
+
this.hostedInstanceProcess.stdout.addListener('data', outputListener);
|
|
227
|
+
this.hostedInstanceProcess.stdout.addListener('data', data => {
|
|
228
|
+
this.hostedPluginSupport.sendLog({ data: data.toString(), type: types_1.LogType.Info });
|
|
229
|
+
});
|
|
230
|
+
this.hostedInstanceProcess.stderr.addListener('data', data => {
|
|
231
|
+
this.hostedPluginSupport.sendLog({ data: data.toString(), type: types_1.LogType.Error });
|
|
232
|
+
});
|
|
233
|
+
setTimeout(() => {
|
|
234
|
+
if (!started) {
|
|
235
|
+
this.terminate();
|
|
236
|
+
this.isPluginRunning = false;
|
|
237
|
+
reject(new Error('Timeout.'));
|
|
238
|
+
}
|
|
239
|
+
}, HOSTED_INSTANCE_START_TIMEOUT_MS);
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
async validatePort(port) {
|
|
243
|
+
if (port < 1 || port > 65535) {
|
|
244
|
+
throw new Error('Port value is incorrect.');
|
|
245
|
+
}
|
|
246
|
+
if (!await this.isPortFree(port)) {
|
|
247
|
+
throw new Error('Port ' + port + ' is already in use.');
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
isPortFree(port) {
|
|
251
|
+
return new Promise(resolve => {
|
|
252
|
+
const server = net.createServer();
|
|
253
|
+
server.listen(port, '0.0.0.0');
|
|
254
|
+
server.on('error', () => {
|
|
255
|
+
resolve(false);
|
|
256
|
+
});
|
|
257
|
+
server.on('listening', () => {
|
|
258
|
+
server.close();
|
|
259
|
+
resolve(true);
|
|
260
|
+
});
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
};
|
|
264
|
+
__decorate([
|
|
265
|
+
(0, inversify_1.inject)(hosted_plugin_1.HostedPluginSupport),
|
|
266
|
+
__metadata("design:type", hosted_plugin_1.HostedPluginSupport)
|
|
267
|
+
], AbstractHostedInstanceManager.prototype, "hostedPluginSupport", void 0);
|
|
268
|
+
__decorate([
|
|
269
|
+
(0, inversify_1.inject)(metadata_scanner_1.MetadataScanner),
|
|
270
|
+
__metadata("design:type", metadata_scanner_1.MetadataScanner)
|
|
271
|
+
], AbstractHostedInstanceManager.prototype, "metadata", void 0);
|
|
272
|
+
__decorate([
|
|
273
|
+
(0, inversify_1.inject)(hosted_plugin_process_1.HostedPluginProcess),
|
|
274
|
+
__metadata("design:type", hosted_plugin_process_1.HostedPluginProcess)
|
|
275
|
+
], AbstractHostedInstanceManager.prototype, "hostedPluginProcess", void 0);
|
|
276
|
+
__decorate([
|
|
277
|
+
(0, inversify_1.inject)(request_1.RequestService),
|
|
278
|
+
__metadata("design:type", Object)
|
|
279
|
+
], AbstractHostedInstanceManager.prototype, "request", void 0);
|
|
280
|
+
AbstractHostedInstanceManager = __decorate([
|
|
281
|
+
(0, inversify_1.injectable)()
|
|
282
|
+
], AbstractHostedInstanceManager);
|
|
283
|
+
exports.AbstractHostedInstanceManager = AbstractHostedInstanceManager;
|
|
284
|
+
let NodeHostedPluginRunner = class NodeHostedPluginRunner extends AbstractHostedInstanceManager {
|
|
285
|
+
async postProcessInstanceUri(uri) {
|
|
286
|
+
for (const uriPostProcessor of this.uriPostProcessors.getContributions()) {
|
|
287
|
+
uri = await uriPostProcessor.processUri(uri);
|
|
288
|
+
}
|
|
289
|
+
return uri;
|
|
290
|
+
}
|
|
291
|
+
async postProcessInstanceOptions(options) {
|
|
292
|
+
for (const uriPostProcessor of this.uriPostProcessors.getContributions()) {
|
|
293
|
+
options = await uriPostProcessor.processOptions(options);
|
|
294
|
+
}
|
|
295
|
+
return options;
|
|
296
|
+
}
|
|
297
|
+
async getStartCommand(port, debugConfig) {
|
|
298
|
+
if (!port) {
|
|
299
|
+
port = process.env.HOSTED_PLUGIN_PORT ?
|
|
300
|
+
Number(process.env.HOSTED_PLUGIN_PORT) :
|
|
301
|
+
((debugConfig === null || debugConfig === void 0 ? void 0 : debugConfig.debugPort) ? Number(debugConfig.debugPort) : DEFAULT_HOSTED_PLUGIN_PORT);
|
|
302
|
+
}
|
|
303
|
+
return super.getStartCommand(port, debugConfig);
|
|
304
|
+
}
|
|
305
|
+
};
|
|
306
|
+
__decorate([
|
|
307
|
+
(0, inversify_1.inject)(contribution_provider_1.ContributionProvider),
|
|
308
|
+
(0, inversify_1.named)(Symbol.for(hosted_plugin_uri_postprocessor_1.HostedPluginUriPostProcessorSymbolName)),
|
|
309
|
+
__metadata("design:type", Object)
|
|
310
|
+
], NodeHostedPluginRunner.prototype, "uriPostProcessors", void 0);
|
|
311
|
+
NodeHostedPluginRunner = __decorate([
|
|
312
|
+
(0, inversify_1.injectable)()
|
|
313
|
+
], NodeHostedPluginRunner);
|
|
314
|
+
exports.NodeHostedPluginRunner = NodeHostedPluginRunner;
|
|
315
|
+
let ElectronNodeHostedPluginRunner = class ElectronNodeHostedPluginRunner extends AbstractHostedInstanceManager {
|
|
316
|
+
};
|
|
317
|
+
ElectronNodeHostedPluginRunner = __decorate([
|
|
318
|
+
(0, inversify_1.injectable)()
|
|
319
|
+
], ElectronNodeHostedPluginRunner);
|
|
320
|
+
exports.ElectronNodeHostedPluginRunner = ElectronNodeHostedPluginRunner;
|
|
321
321
|
//# sourceMappingURL=hosted-instance-manager.js.map
|