@theia/plugin-ext 1.37.0-next.19 → 1.37.0-next.22
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/lib/main/node/plugin-github-resolver.d.ts +3 -1
- package/lib/main/node/plugin-github-resolver.d.ts.map +1 -1
- package/lib/main/node/plugin-github-resolver.js +64 -71
- package/lib/main/node/plugin-github-resolver.js.map +1 -1
- package/lib/main/node/plugin-http-resolver.d.ts +2 -0
- package/lib/main/node/plugin-http-resolver.d.ts.map +1 -1
- package/lib/main/node/plugin-http-resolver.js +31 -31
- package/lib/main/node/plugin-http-resolver.js.map +1 -1
- package/package.json +27 -29
- package/src/main/node/plugin-github-resolver.ts +65 -81
- package/src/main/node/plugin-http-resolver.ts +29 -35
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { RequestService } from '@theia/core/shared/@theia/request';
|
|
1
2
|
import { PluginDeployerResolver, PluginDeployerResolverContext } from '../../common';
|
|
2
3
|
/**
|
|
3
4
|
* Resolver that handle the github: protocol
|
|
@@ -8,12 +9,13 @@ export declare class GithubPluginDeployerResolver implements PluginDeployerResol
|
|
|
8
9
|
private static PREFIX;
|
|
9
10
|
private static GITHUB_ENDPOINT;
|
|
10
11
|
private unpackedFolder;
|
|
12
|
+
protected readonly request: RequestService;
|
|
11
13
|
constructor();
|
|
12
14
|
/**
|
|
13
15
|
* Grab the remote file specified by Github URL
|
|
14
16
|
*/
|
|
15
17
|
resolve(pluginResolverContext: PluginDeployerResolverContext): Promise<void>;
|
|
16
|
-
protected grabGithubFile(pluginResolverContext: PluginDeployerResolverContext, orgName: string, repoName: string, filename: string, version: string
|
|
18
|
+
protected grabGithubFile(pluginResolverContext: PluginDeployerResolverContext, orgName: string, repoName: string, filename: string, version: string): Promise<void>;
|
|
17
19
|
/**
|
|
18
20
|
* Handle only the plugins that starts with github:
|
|
19
21
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin-github-resolver.d.ts","sourceRoot":"","sources":["../../../src/main/node/plugin-github-resolver.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"plugin-github-resolver.d.ts","sourceRoot":"","sources":["../../../src/main/node/plugin-github-resolver.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAkB,cAAc,EAAE,MAAM,mCAAmC,CAAC;AAKnF,OAAO,EAAE,sBAAsB,EAAE,6BAA6B,EAAE,MAAM,cAAc,CAAC;AAErF;;;;GAIG;AACH,qBACa,4BAA6B,YAAW,sBAAsB;IAEvE,OAAO,CAAC,MAAM,CAAC,MAAM,CAAa;IAElC,OAAO,CAAC,MAAM,CAAC,eAAe,CAAyB;IAEvD,OAAO,CAAC,cAAc,CAAS;IAG/B,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,cAAc,CAAC;;IAS3C;;OAEG;IACG,OAAO,CAAC,qBAAqB,EAAE,6BAA6B,GAAG,OAAO,CAAC,IAAI,CAAC;cAyDlE,cAAc,CAAC,qBAAqB,EAAE,6BAA6B,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAkBzK;;OAEG;IACH,MAAM,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;CAGpC"}
|
|
@@ -26,11 +26,11 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
26
26
|
var GithubPluginDeployerResolver_1;
|
|
27
27
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
28
|
exports.GithubPluginDeployerResolver = void 0;
|
|
29
|
+
const request_1 = require("@theia/core/shared/@theia/request");
|
|
29
30
|
const inversify_1 = require("@theia/core/shared/inversify");
|
|
30
|
-
const
|
|
31
|
+
const fs_1 = require("fs");
|
|
31
32
|
const os = require("os");
|
|
32
33
|
const path = require("path");
|
|
33
|
-
const request = require("request");
|
|
34
34
|
/**
|
|
35
35
|
* Resolver that handle the github: protocol
|
|
36
36
|
* github:<org>/<repo>/<filename>@latest
|
|
@@ -39,8 +39,8 @@ const request = require("request");
|
|
|
39
39
|
let GithubPluginDeployerResolver = GithubPluginDeployerResolver_1 = class GithubPluginDeployerResolver {
|
|
40
40
|
constructor() {
|
|
41
41
|
this.unpackedFolder = path.resolve(os.tmpdir(), 'github-remote');
|
|
42
|
-
if (!
|
|
43
|
-
|
|
42
|
+
if (!(0, fs_1.existsSync)(this.unpackedFolder)) {
|
|
43
|
+
(0, fs_1.mkdirSync)(this.unpackedFolder);
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
/**
|
|
@@ -48,83 +48,72 @@ let GithubPluginDeployerResolver = GithubPluginDeployerResolver_1 = class Github
|
|
|
48
48
|
*/
|
|
49
49
|
async resolve(pluginResolverContext) {
|
|
50
50
|
// download the file
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
51
|
+
// extract data
|
|
52
|
+
const extracted = /^github:(.*)\/(.*)\/(.*)$/gm.exec(pluginResolverContext.getOriginId());
|
|
53
|
+
if (!extracted || extracted === null || extracted.length !== 4) {
|
|
54
|
+
throw new Error('Invalid extension' + pluginResolverContext.getOriginId());
|
|
55
|
+
}
|
|
56
|
+
const orgName = extracted[1];
|
|
57
|
+
const repoName = extracted[2];
|
|
58
|
+
const file = extracted[3];
|
|
59
|
+
// get version if any
|
|
60
|
+
const splitFile = file.split('@');
|
|
61
|
+
let version;
|
|
62
|
+
let filename;
|
|
63
|
+
if (splitFile.length === 1) {
|
|
64
|
+
filename = file;
|
|
65
|
+
version = 'latest';
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
filename = splitFile[0];
|
|
69
|
+
version = splitFile[1];
|
|
70
|
+
}
|
|
71
|
+
// latest version, need to get the redirect
|
|
72
|
+
const url = GithubPluginDeployerResolver_1.GITHUB_ENDPOINT + orgName + '/' + repoName + '/releases/latest';
|
|
73
|
+
// if latest, resolve first the real version
|
|
74
|
+
if (version === 'latest') {
|
|
75
75
|
// disable redirect to grab the release
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
if (!taggedValueArray || taggedValueArray.length !== 2) {
|
|
92
|
-
reject(new Error('The redirect link for latest is invalid ' + redirectLocation));
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
// grab version of tag
|
|
96
|
-
this.grabGithubFile(pluginResolverContext, orgName, repoName, filename, taggedValueArray[1], resolve, reject);
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
else {
|
|
101
|
-
this.grabGithubFile(pluginResolverContext, orgName, repoName, filename, version, resolve, reject);
|
|
76
|
+
const followRedirects = 0;
|
|
77
|
+
const response = await this.request.request({ url, followRedirects });
|
|
78
|
+
// should have a redirect
|
|
79
|
+
if (response.res.statusCode === 302) {
|
|
80
|
+
const redirectLocation = response.res.headers.location;
|
|
81
|
+
if (!redirectLocation) {
|
|
82
|
+
throw new Error('Invalid github link with latest not being found');
|
|
83
|
+
}
|
|
84
|
+
// parse redirect link
|
|
85
|
+
const taggedValueArray = /^https:\/\/.*tag\/(.*)/gm.exec(redirectLocation);
|
|
86
|
+
if (!taggedValueArray || taggedValueArray.length !== 2) {
|
|
87
|
+
throw new Error('The redirect link for latest is invalid ' + redirectLocation);
|
|
88
|
+
}
|
|
89
|
+
// grab version of tag
|
|
90
|
+
return this.grabGithubFile(pluginResolverContext, orgName, repoName, filename, taggedValueArray[1]);
|
|
102
91
|
}
|
|
103
|
-
}
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
return this.grabGithubFile(pluginResolverContext, orgName, repoName, filename, version);
|
|
95
|
+
}
|
|
104
96
|
}
|
|
105
97
|
/*
|
|
106
98
|
* Grab the github file specified by the plugin's ID
|
|
107
99
|
*/
|
|
108
|
-
grabGithubFile(pluginResolverContext, orgName, repoName, filename, version
|
|
109
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
110
|
-
resolve, reject) {
|
|
100
|
+
async grabGithubFile(pluginResolverContext, orgName, repoName, filename, version) {
|
|
111
101
|
const unpackedPath = path.resolve(this.unpackedFolder, path.basename(version + filename));
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
};
|
|
116
|
-
// use of cache. If file is already there use it directly
|
|
117
|
-
if (fs.existsSync(unpackedPath)) {
|
|
118
|
-
finish();
|
|
102
|
+
try {
|
|
103
|
+
await fs_1.promises.access(unpackedPath);
|
|
104
|
+
// use of cache. If file is already there use it directly
|
|
119
105
|
return;
|
|
120
106
|
}
|
|
121
|
-
|
|
122
|
-
dest.addListener('finish', finish);
|
|
107
|
+
catch (_a) { }
|
|
123
108
|
const url = GithubPluginDeployerResolver_1.GITHUB_ENDPOINT + orgName + '/' + repoName + '/releases/download/' + version + '/' + filename;
|
|
124
|
-
request.
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
109
|
+
const response = await this.request.request({ url });
|
|
110
|
+
if (request_1.RequestContext.isSuccess(response)) {
|
|
111
|
+
await fs_1.promises.writeFile(unpackedPath, response.buffer);
|
|
112
|
+
pluginResolverContext.addPlugin(pluginResolverContext.getOriginId(), unpackedPath);
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
throw new Error(`Could not download the plugin from GitHub. URL: ${url}. HTTP status code: ${response.res.statusCode}`);
|
|
116
|
+
}
|
|
128
117
|
}
|
|
129
118
|
/**
|
|
130
119
|
* Handle only the plugins that starts with github:
|
|
@@ -135,6 +124,10 @@ let GithubPluginDeployerResolver = GithubPluginDeployerResolver_1 = class Github
|
|
|
135
124
|
};
|
|
136
125
|
GithubPluginDeployerResolver.PREFIX = 'github:';
|
|
137
126
|
GithubPluginDeployerResolver.GITHUB_ENDPOINT = 'https://github.com/';
|
|
127
|
+
__decorate([
|
|
128
|
+
(0, inversify_1.inject)(request_1.RequestService),
|
|
129
|
+
__metadata("design:type", Object)
|
|
130
|
+
], GithubPluginDeployerResolver.prototype, "request", void 0);
|
|
138
131
|
GithubPluginDeployerResolver = GithubPluginDeployerResolver_1 = __decorate([
|
|
139
132
|
(0, inversify_1.injectable)(),
|
|
140
133
|
__metadata("design:paramtypes", [])
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin-github-resolver.js","sourceRoot":"","sources":["../../../src/main/node/plugin-github-resolver.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,+CAA+C;AAC/C,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,2EAA2E;AAC3E,gFAAgF;;;;;;;;;;;;;AAEhF,
|
|
1
|
+
{"version":3,"file":"plugin-github-resolver.js","sourceRoot":"","sources":["../../../src/main/node/plugin-github-resolver.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,+CAA+C;AAC/C,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,2EAA2E;AAC3E,gFAAgF;;;;;;;;;;;;;AAEhF,+DAAmF;AACnF,4DAAkE;AAClE,2BAA2D;AAC3D,yBAAy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E,IAAI,CAAC,QAAQ,CAAC,OAAO,GAAG,QAAQ,CAAC,CAAC,CAAC;QAC1F,IAAI;YACA,MAAM,aAAE,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;YAC9B,yDAAyD;YACzD,OAAO;SACV;QAAC,WAAM,GAAG;QAEX,MAAM,GAAG,GAAG,8BAA4B,CAAC,eAAe,GAAG,OAAO,GAAG,GAAG,GAAG,QAAQ,GAAG,qBAAqB,GAAG,OAAO,GAAG,GAAG,GAAG,QAAQ,CAAC;QACvI,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC;QACrD,IAAI,wBAAc,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE;YACpC,MAAM,aAAE,CAAC,SAAS,CAAC,YAAY,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;YAClD,qBAAqB,CAAC,SAAS,CAAC,qBAAqB,CAAC,WAAW,EAAE,EAAE,YAAY,CAAC,CAAC;SACtF;aAAM;YACH,MAAM,IAAI,KAAK,CAAC,mDAAmD,GAAG,uBAAuB,QAAQ,CAAC,GAAG,CAAC,UAAU,EAAE,CAAC,CAAC;SAC3H;IACL,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,QAAgB;QACnB,OAAO,QAAQ,CAAC,UAAU,CAAC,8BAA4B,CAAC,MAAM,CAAC,CAAC;IACpE,CAAC;CACJ,CAAA;AApGkB,mCAAM,GAAG,SAAU,CAAA;AAEnB,4CAAe,GAAG,qBAAsB,CAAA;AAKvD;IADC,IAAA,kBAAM,EAAC,wBAAc,CAAC;;6DACoB;AATlC,4BAA4B;IADxC,IAAA,sBAAU,GAAE;;GACA,4BAA4B,CAsGxC;AAtGY,oEAA4B"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { RequestService } from '@theia/core/shared/@theia/request';
|
|
1
2
|
import { PluginDeployerResolver, PluginDeployerResolverContext } from '../../common';
|
|
2
3
|
/**
|
|
3
4
|
* Resolver that handle the http(s): protocol
|
|
@@ -6,6 +7,7 @@ import { PluginDeployerResolver, PluginDeployerResolverContext } from '../../com
|
|
|
6
7
|
*/
|
|
7
8
|
export declare class HttpPluginDeployerResolver implements PluginDeployerResolver {
|
|
8
9
|
private unpackedFolder;
|
|
10
|
+
protected readonly request: RequestService;
|
|
9
11
|
constructor();
|
|
10
12
|
/**
|
|
11
13
|
* Grab the remote file specified by the given URL
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin-http-resolver.d.ts","sourceRoot":"","sources":["../../../src/main/node/plugin-http-resolver.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"plugin-http-resolver.d.ts","sourceRoot":"","sources":["../../../src/main/node/plugin-http-resolver.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAkB,cAAc,EAAE,MAAM,mCAAmC,CAAC;AAMnF,OAAO,EAAE,sBAAsB,EAAE,6BAA6B,EAAE,MAAM,cAAc,CAAC;AAErF;;;;GAIG;AACH,qBACa,0BAA2B,YAAW,sBAAsB;IAErE,OAAO,CAAC,cAAc,CAAS;IAG/B,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,cAAc,CAAC;;IAS3C;;OAEG;IACG,OAAO,CAAC,qBAAqB,EAAE,6BAA6B,GAAG,OAAO,CAAC,IAAI,CAAC;IA+BlF;;OAEG;IACH,MAAM,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;CAGpC"}
|
|
@@ -25,12 +25,12 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
25
25
|
};
|
|
26
26
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
27
|
exports.HttpPluginDeployerResolver = void 0;
|
|
28
|
+
const request_1 = require("@theia/core/shared/@theia/request");
|
|
28
29
|
const inversify_1 = require("@theia/core/shared/inversify");
|
|
29
|
-
const
|
|
30
|
+
const fs_1 = require("fs");
|
|
30
31
|
const os = require("os");
|
|
31
32
|
const path = require("path");
|
|
32
33
|
const url = require("url");
|
|
33
|
-
const request = require("request");
|
|
34
34
|
/**
|
|
35
35
|
* Resolver that handle the http(s): protocol
|
|
36
36
|
* http://path/to/my.plugin
|
|
@@ -39,8 +39,8 @@ const request = require("request");
|
|
|
39
39
|
let HttpPluginDeployerResolver = class HttpPluginDeployerResolver {
|
|
40
40
|
constructor() {
|
|
41
41
|
this.unpackedFolder = path.resolve(os.tmpdir(), 'http-remote');
|
|
42
|
-
if (!
|
|
43
|
-
|
|
42
|
+
if (!(0, fs_1.existsSync)(this.unpackedFolder)) {
|
|
43
|
+
(0, fs_1.mkdirSync)(this.unpackedFolder);
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
/**
|
|
@@ -48,34 +48,30 @@ let HttpPluginDeployerResolver = class HttpPluginDeployerResolver {
|
|
|
48
48
|
*/
|
|
49
49
|
async resolve(pluginResolverContext) {
|
|
50
50
|
// download the file
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const finish = () => {
|
|
64
|
-
pluginResolverContext.addPlugin(pluginResolverContext.getOriginId(), unpackedPath);
|
|
65
|
-
resolve();
|
|
66
|
-
};
|
|
51
|
+
// keep filename of the url
|
|
52
|
+
const urlPath = pluginResolverContext.getOriginId();
|
|
53
|
+
const link = url.parse(urlPath);
|
|
54
|
+
if (!link.pathname) {
|
|
55
|
+
throw new Error('invalid link URI' + urlPath);
|
|
56
|
+
}
|
|
57
|
+
const dirname = path.dirname(link.pathname);
|
|
58
|
+
const basename = path.basename(link.pathname);
|
|
59
|
+
const filename = dirname.replace(/\W/g, '_') + ('-') + basename;
|
|
60
|
+
const unpackedPath = path.resolve(this.unpackedFolder, path.basename(filename));
|
|
61
|
+
try {
|
|
62
|
+
await fs_1.promises.access(unpackedPath);
|
|
67
63
|
// use of cache. If file is already there use it directly
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
catch (_a) { }
|
|
67
|
+
const response = await this.request.request({ url: pluginResolverContext.getOriginId() });
|
|
68
|
+
if (request_1.RequestContext.isSuccess(response)) {
|
|
69
|
+
await fs_1.promises.writeFile(unpackedPath, response.buffer);
|
|
70
|
+
pluginResolverContext.addPlugin(pluginResolverContext.getOriginId(), unpackedPath);
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
throw new Error(`Could not download the plugin from ${pluginResolverContext.getOriginId()}. HTTP status code: ${response.res.statusCode}`);
|
|
74
|
+
}
|
|
79
75
|
}
|
|
80
76
|
/**
|
|
81
77
|
* Handle only the plugins that starts with http or https:
|
|
@@ -84,6 +80,10 @@ let HttpPluginDeployerResolver = class HttpPluginDeployerResolver {
|
|
|
84
80
|
return /^http[s]?:\/\/.*$/gm.test(pluginId);
|
|
85
81
|
}
|
|
86
82
|
};
|
|
83
|
+
__decorate([
|
|
84
|
+
(0, inversify_1.inject)(request_1.RequestService),
|
|
85
|
+
__metadata("design:type", Object)
|
|
86
|
+
], HttpPluginDeployerResolver.prototype, "request", void 0);
|
|
87
87
|
HttpPluginDeployerResolver = __decorate([
|
|
88
88
|
(0, inversify_1.injectable)(),
|
|
89
89
|
__metadata("design:paramtypes", [])
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin-http-resolver.js","sourceRoot":"","sources":["../../../src/main/node/plugin-http-resolver.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,+CAA+C;AAC/C,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAA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
|
-
"version": "1.37.0-next.
|
|
3
|
+
"version": "1.37.0-next.22+0e0e9ee4b",
|
|
4
4
|
"description": "Theia - Plugin Extension",
|
|
5
5
|
"main": "lib/common/index.js",
|
|
6
6
|
"typings": "lib/common/index.d.ts",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@theia/bulk-edit": "1.37.0-next.
|
|
9
|
-
"@theia/callhierarchy": "1.37.0-next.
|
|
10
|
-
"@theia/console": "1.37.0-next.
|
|
11
|
-
"@theia/core": "1.37.0-next.
|
|
12
|
-
"@theia/debug": "1.37.0-next.
|
|
13
|
-
"@theia/editor": "1.37.0-next.
|
|
14
|
-
"@theia/editor-preview": "1.37.0-next.
|
|
15
|
-
"@theia/file-search": "1.37.0-next.
|
|
16
|
-
"@theia/filesystem": "1.37.0-next.
|
|
17
|
-
"@theia/markers": "1.37.0-next.
|
|
18
|
-
"@theia/messages": "1.37.0-next.
|
|
19
|
-
"@theia/monaco": "1.37.0-next.
|
|
8
|
+
"@theia/bulk-edit": "1.37.0-next.22+0e0e9ee4b",
|
|
9
|
+
"@theia/callhierarchy": "1.37.0-next.22+0e0e9ee4b",
|
|
10
|
+
"@theia/console": "1.37.0-next.22+0e0e9ee4b",
|
|
11
|
+
"@theia/core": "1.37.0-next.22+0e0e9ee4b",
|
|
12
|
+
"@theia/debug": "1.37.0-next.22+0e0e9ee4b",
|
|
13
|
+
"@theia/editor": "1.37.0-next.22+0e0e9ee4b",
|
|
14
|
+
"@theia/editor-preview": "1.37.0-next.22+0e0e9ee4b",
|
|
15
|
+
"@theia/file-search": "1.37.0-next.22+0e0e9ee4b",
|
|
16
|
+
"@theia/filesystem": "1.37.0-next.22+0e0e9ee4b",
|
|
17
|
+
"@theia/markers": "1.37.0-next.22+0e0e9ee4b",
|
|
18
|
+
"@theia/messages": "1.37.0-next.22+0e0e9ee4b",
|
|
19
|
+
"@theia/monaco": "1.37.0-next.22+0e0e9ee4b",
|
|
20
20
|
"@theia/monaco-editor-core": "1.72.3",
|
|
21
|
-
"@theia/navigator": "1.37.0-next.
|
|
22
|
-
"@theia/output": "1.37.0-next.
|
|
23
|
-
"@theia/plugin": "1.37.0-next.
|
|
24
|
-
"@theia/preferences": "1.37.0-next.
|
|
25
|
-
"@theia/scm": "1.37.0-next.
|
|
26
|
-
"@theia/search-in-workspace": "1.37.0-next.
|
|
27
|
-
"@theia/task": "1.37.0-next.
|
|
28
|
-
"@theia/terminal": "1.37.0-next.
|
|
29
|
-
"@theia/timeline": "1.37.0-next.
|
|
30
|
-
"@theia/typehierarchy": "1.37.0-next.
|
|
31
|
-
"@theia/variable-resolver": "1.37.0-next.
|
|
32
|
-
"@theia/workspace": "1.37.0-next.
|
|
21
|
+
"@theia/navigator": "1.37.0-next.22+0e0e9ee4b",
|
|
22
|
+
"@theia/output": "1.37.0-next.22+0e0e9ee4b",
|
|
23
|
+
"@theia/plugin": "1.37.0-next.22+0e0e9ee4b",
|
|
24
|
+
"@theia/preferences": "1.37.0-next.22+0e0e9ee4b",
|
|
25
|
+
"@theia/scm": "1.37.0-next.22+0e0e9ee4b",
|
|
26
|
+
"@theia/search-in-workspace": "1.37.0-next.22+0e0e9ee4b",
|
|
27
|
+
"@theia/task": "1.37.0-next.22+0e0e9ee4b",
|
|
28
|
+
"@theia/terminal": "1.37.0-next.22+0e0e9ee4b",
|
|
29
|
+
"@theia/timeline": "1.37.0-next.22+0e0e9ee4b",
|
|
30
|
+
"@theia/typehierarchy": "1.37.0-next.22+0e0e9ee4b",
|
|
31
|
+
"@theia/variable-resolver": "1.37.0-next.22+0e0e9ee4b",
|
|
32
|
+
"@theia/workspace": "1.37.0-next.22+0e0e9ee4b",
|
|
33
33
|
"@types/mime": "^2.0.1",
|
|
34
34
|
"@vscode/debugprotocol": "^1.51.0",
|
|
35
35
|
"decompress": "^4.2.1",
|
|
@@ -41,7 +41,6 @@
|
|
|
41
41
|
"macaddress": "^0.2.9",
|
|
42
42
|
"mime": "^2.4.4",
|
|
43
43
|
"ps-tree": "^1.2.0",
|
|
44
|
-
"request": "^2.82.0",
|
|
45
44
|
"semver": "^5.4.1",
|
|
46
45
|
"uuid": "^8.0.0",
|
|
47
46
|
"vhost": "^3.0.2",
|
|
@@ -90,11 +89,10 @@
|
|
|
90
89
|
"@types/decompress": "^4.2.2",
|
|
91
90
|
"@types/escape-html": "^0.0.20",
|
|
92
91
|
"@types/lodash.clonedeep": "^4.5.3",
|
|
93
|
-
"@types/ps-tree": "^1.1.0"
|
|
94
|
-
"@types/request": "^2.0.3"
|
|
92
|
+
"@types/ps-tree": "^1.1.0"
|
|
95
93
|
},
|
|
96
94
|
"nyc": {
|
|
97
95
|
"extends": "../../configs/nyc.json"
|
|
98
96
|
},
|
|
99
|
-
"gitHead": "
|
|
97
|
+
"gitHead": "0e0e9ee4b38b94edfee5d521b8cdacb832d72f86"
|
|
100
98
|
}
|
|
@@ -14,11 +14,11 @@
|
|
|
14
14
|
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
15
15
|
// *****************************************************************************
|
|
16
16
|
|
|
17
|
-
import {
|
|
18
|
-
import
|
|
17
|
+
import { RequestContext, RequestService } from '@theia/core/shared/@theia/request';
|
|
18
|
+
import { inject, injectable } from '@theia/core/shared/inversify';
|
|
19
|
+
import { promises as fs, existsSync, mkdirSync } from 'fs';
|
|
19
20
|
import * as os from 'os';
|
|
20
21
|
import * as path from 'path';
|
|
21
|
-
import * as request from 'request';
|
|
22
22
|
import { PluginDeployerResolver, PluginDeployerResolverContext } from '../../common';
|
|
23
23
|
|
|
24
24
|
/**
|
|
@@ -35,10 +35,13 @@ export class GithubPluginDeployerResolver implements PluginDeployerResolver {
|
|
|
35
35
|
|
|
36
36
|
private unpackedFolder: string;
|
|
37
37
|
|
|
38
|
+
@inject(RequestService)
|
|
39
|
+
protected readonly request: RequestService;
|
|
40
|
+
|
|
38
41
|
constructor() {
|
|
39
42
|
this.unpackedFolder = path.resolve(os.tmpdir(), 'github-remote');
|
|
40
|
-
if (!
|
|
41
|
-
|
|
43
|
+
if (!existsSync(this.unpackedFolder)) {
|
|
44
|
+
mkdirSync(this.unpackedFolder);
|
|
42
45
|
}
|
|
43
46
|
}
|
|
44
47
|
|
|
@@ -48,95 +51,76 @@ export class GithubPluginDeployerResolver implements PluginDeployerResolver {
|
|
|
48
51
|
async resolve(pluginResolverContext: PluginDeployerResolverContext): Promise<void> {
|
|
49
52
|
|
|
50
53
|
// download the file
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
54
|
+
// extract data
|
|
55
|
+
const extracted = /^github:(.*)\/(.*)\/(.*)$/gm.exec(pluginResolverContext.getOriginId());
|
|
56
|
+
if (!extracted || extracted === null || extracted.length !== 4) {
|
|
57
|
+
throw new Error('Invalid extension' + pluginResolverContext.getOriginId());
|
|
58
|
+
}
|
|
58
59
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
60
|
+
const orgName = extracted[1];
|
|
61
|
+
const repoName = extracted[2];
|
|
62
|
+
const file = extracted[3];
|
|
63
|
+
|
|
64
|
+
// get version if any
|
|
65
|
+
const splitFile = file.split('@');
|
|
66
|
+
let version;
|
|
67
|
+
let filename: string;
|
|
68
|
+
if (splitFile.length === 1) {
|
|
69
|
+
filename = file;
|
|
70
|
+
version = 'latest';
|
|
71
|
+
} else {
|
|
72
|
+
filename = splitFile[0];
|
|
73
|
+
version = splitFile[1];
|
|
74
|
+
}
|
|
75
|
+
// latest version, need to get the redirect
|
|
76
|
+
const url = GithubPluginDeployerResolver.GITHUB_ENDPOINT + orgName + '/' + repoName + '/releases/latest';
|
|
76
77
|
|
|
78
|
+
// if latest, resolve first the real version
|
|
79
|
+
if (version === 'latest') {
|
|
77
80
|
// disable redirect to grab the release
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
if (!taggedValueArray || taggedValueArray.length !== 2) {
|
|
96
|
-
reject(new Error('The redirect link for latest is invalid ' + redirectLocation));
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// grab version of tag
|
|
101
|
-
this.grabGithubFile(pluginResolverContext, orgName, repoName, filename, taggedValueArray[1], resolve, reject);
|
|
102
|
-
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
} else {
|
|
106
|
-
this.grabGithubFile(pluginResolverContext, orgName, repoName, filename, version, resolve, reject);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
});
|
|
81
|
+
const followRedirects = 0;
|
|
82
|
+
const response = await this.request.request({ url, followRedirects });
|
|
83
|
+
// should have a redirect
|
|
84
|
+
if (response.res.statusCode === 302) {
|
|
85
|
+
const redirectLocation = response.res.headers.location;
|
|
86
|
+
if (!redirectLocation) {
|
|
87
|
+
throw new Error('Invalid github link with latest not being found');
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// parse redirect link
|
|
91
|
+
const taggedValueArray = /^https:\/\/.*tag\/(.*)/gm.exec(redirectLocation);
|
|
92
|
+
if (!taggedValueArray || taggedValueArray.length !== 2) {
|
|
93
|
+
throw new Error('The redirect link for latest is invalid ' + redirectLocation);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// grab version of tag
|
|
97
|
+
return this.grabGithubFile(pluginResolverContext, orgName, repoName, filename, taggedValueArray[1]);
|
|
110
98
|
|
|
99
|
+
}
|
|
100
|
+
} else {
|
|
101
|
+
return this.grabGithubFile(pluginResolverContext, orgName, repoName, filename, version);
|
|
102
|
+
}
|
|
111
103
|
}
|
|
112
104
|
|
|
113
105
|
/*
|
|
114
106
|
* Grab the github file specified by the plugin's ID
|
|
115
107
|
*/
|
|
116
|
-
protected grabGithubFile(pluginResolverContext: PluginDeployerResolverContext, orgName: string, repoName: string, filename: string, version: string
|
|
117
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
118
|
-
resolve: (value?: void | PromiseLike<void>) => void, reject: (reason?: any) => void): void {
|
|
119
|
-
|
|
108
|
+
protected async grabGithubFile(pluginResolverContext: PluginDeployerResolverContext, orgName: string, repoName: string, filename: string, version: string): Promise<void> {
|
|
120
109
|
const unpackedPath = path.resolve(this.unpackedFolder, path.basename(version + filename));
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
// use of cache. If file is already there use it directly
|
|
127
|
-
if (fs.existsSync(unpackedPath)) {
|
|
128
|
-
finish();
|
|
110
|
+
try {
|
|
111
|
+
await fs.access(unpackedPath);
|
|
112
|
+
// use of cache. If file is already there use it directly
|
|
129
113
|
return;
|
|
130
|
-
}
|
|
131
|
-
const dest = fs.createWriteStream(unpackedPath);
|
|
114
|
+
} catch { }
|
|
132
115
|
|
|
133
|
-
dest.addListener('finish', finish);
|
|
134
116
|
const url = GithubPluginDeployerResolver.GITHUB_ENDPOINT + orgName + '/' + repoName + '/releases/download/' + version + '/' + filename;
|
|
135
|
-
request.
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
117
|
+
const response = await this.request.request({ url });
|
|
118
|
+
if (RequestContext.isSuccess(response)) {
|
|
119
|
+
await fs.writeFile(unpackedPath, response.buffer);
|
|
120
|
+
pluginResolverContext.addPlugin(pluginResolverContext.getOriginId(), unpackedPath);
|
|
121
|
+
} else {
|
|
122
|
+
throw new Error(`Could not download the plugin from GitHub. URL: ${url}. HTTP status code: ${response.res.statusCode}`);
|
|
123
|
+
}
|
|
140
124
|
}
|
|
141
125
|
|
|
142
126
|
/**
|
|
@@ -14,13 +14,12 @@
|
|
|
14
14
|
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
15
15
|
// *****************************************************************************
|
|
16
16
|
|
|
17
|
-
import {
|
|
18
|
-
import
|
|
17
|
+
import { RequestContext, RequestService } from '@theia/core/shared/@theia/request';
|
|
18
|
+
import { inject, injectable } from '@theia/core/shared/inversify';
|
|
19
|
+
import { promises as fs, existsSync, mkdirSync } from 'fs';
|
|
19
20
|
import * as os from 'os';
|
|
20
21
|
import * as path from 'path';
|
|
21
22
|
import * as url from 'url';
|
|
22
|
-
import * as request from 'request';
|
|
23
|
-
|
|
24
23
|
import { PluginDeployerResolver, PluginDeployerResolverContext } from '../../common';
|
|
25
24
|
|
|
26
25
|
/**
|
|
@@ -33,10 +32,13 @@ export class HttpPluginDeployerResolver implements PluginDeployerResolver {
|
|
|
33
32
|
|
|
34
33
|
private unpackedFolder: string;
|
|
35
34
|
|
|
35
|
+
@inject(RequestService)
|
|
36
|
+
protected readonly request: RequestService;
|
|
37
|
+
|
|
36
38
|
constructor() {
|
|
37
39
|
this.unpackedFolder = path.resolve(os.tmpdir(), 'http-remote');
|
|
38
|
-
if (!
|
|
39
|
-
|
|
40
|
+
if (!existsSync(this.unpackedFolder)) {
|
|
41
|
+
mkdirSync(this.unpackedFolder);
|
|
40
42
|
}
|
|
41
43
|
}
|
|
42
44
|
|
|
@@ -46,39 +48,31 @@ export class HttpPluginDeployerResolver implements PluginDeployerResolver {
|
|
|
46
48
|
async resolve(pluginResolverContext: PluginDeployerResolverContext): Promise<void> {
|
|
47
49
|
|
|
48
50
|
// download the file
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
reject(new Error('invalid link URI' + urlPath));
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const dirname = path.dirname(link.pathname);
|
|
60
|
-
const basename = path.basename(link.pathname);
|
|
61
|
-
const filename = dirname.replace(/\W/g, '_') + ('-') + basename;
|
|
62
|
-
const unpackedPath = path.resolve(this.unpackedFolder, path.basename(filename));
|
|
51
|
+
// keep filename of the url
|
|
52
|
+
const urlPath = pluginResolverContext.getOriginId();
|
|
53
|
+
const link = url.parse(urlPath);
|
|
54
|
+
if (!link.pathname) {
|
|
55
|
+
throw new Error('invalid link URI' + urlPath);
|
|
56
|
+
}
|
|
63
57
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
58
|
+
const dirname = path.dirname(link.pathname);
|
|
59
|
+
const basename = path.basename(link.pathname);
|
|
60
|
+
const filename = dirname.replace(/\W/g, '_') + ('-') + basename;
|
|
61
|
+
const unpackedPath = path.resolve(this.unpackedFolder, path.basename(filename));
|
|
68
62
|
|
|
63
|
+
try {
|
|
64
|
+
await fs.access(unpackedPath);
|
|
69
65
|
// use of cache. If file is already there use it directly
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
const dest = fs.createWriteStream(unpackedPath);
|
|
66
|
+
return;
|
|
67
|
+
} catch { }
|
|
75
68
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
69
|
+
const response = await this.request.request({ url: pluginResolverContext.getOriginId() });
|
|
70
|
+
if (RequestContext.isSuccess(response)) {
|
|
71
|
+
await fs.writeFile(unpackedPath, response.buffer);
|
|
72
|
+
pluginResolverContext.addPlugin(pluginResolverContext.getOriginId(), unpackedPath);
|
|
73
|
+
} else {
|
|
74
|
+
throw new Error(`Could not download the plugin from ${pluginResolverContext.getOriginId()}. HTTP status code: ${response.res.statusCode}`);
|
|
75
|
+
}
|
|
82
76
|
|
|
83
77
|
}
|
|
84
78
|
|