Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(deps): switched from request to @theia/request #12413

Merged
merged 2 commits into from
Apr 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions dev-packages/application-package/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,14 @@
"watch": "theiaext watch"
},
"dependencies": {
"@theia/request": "1.36.0",
"@types/fs-extra": "^4.0.2",
"@types/request": "^2.0.3",
"@types/semver": "^5.4.0",
"@types/write-json-file": "^2.2.1",
"deepmerge": "^4.2.2",
"fs-extra": "^4.0.2",
"is-electron": "^2.1.0",
"nano": "^9.0.5",
"request": "^2.82.0",
"resolve-package-path": "^4.0.3",
"semver": "^5.4.1",
"write-json-file": "^2.2.0"
Expand Down
30 changes: 11 additions & 19 deletions dev-packages/application-package/src/npm-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
// *****************************************************************************

/* eslint-disable @typescript-eslint/no-explicit-any */
import * as request from 'request';
import * as nano from 'nano';
import { RequestContext } from '@theia/request';
import { NodeRequestService } from '@theia/request/lib/node-request-service';
import { NpmRegistryProps } from './application-props';

export interface IChangeStream {
Expand Down Expand Up @@ -96,12 +97,15 @@ export class NpmRegistry {
protected changes?: nano.ChangesReaderScope;
protected readonly index = new Map<string, Promise<ViewResult>>();

protected request: NodeRequestService;

constructor(options?: Partial<NpmRegistryOptions>) {
this.options = {
watchChanges: false,
...options
};
this.resetIndex();
this.request = new NodeRequestService();
}

updateProps(props?: Partial<NpmRegistryProps>): void {
Expand Down Expand Up @@ -140,30 +144,18 @@ export class NpmRegistry {
return result;
}

protected doView(name: string): Promise<ViewResult> {
protected async doView(name: string): Promise<ViewResult> {
let url = this.props.registry;
if (name[0] === '@') {
url += '@' + encodeURIComponent(name.substr(1));
} else {
url += encodeURIComponent(name);
}
const headers: {
[header: string]: string
} = {};
return new Promise((resolve, reject) => {
request({
url, headers
}, (err, response, body) => {
if (err) {
reject(err);
} else if (response.statusCode !== 200) {
reject(new Error(`${response.statusCode}: ${response.statusMessage} for ${url}`));
} else {
const data = JSON.parse(body);
resolve(data);
}
});
});
const response = await this.request.request({ url });
if (response.res.statusCode !== 200) {
throw new Error(`HTTP ${response.res.statusCode}: for ${url}`);
}
return RequestContext.asJson<ViewResult>(response);
}

}
6 changes: 5 additions & 1 deletion dev-packages/application-package/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,9 @@
"include": [
"src"
],
"references": []
"references": [
{
"path": "../request"
}
]
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"@types/chai": "4.3.0",
"@types/chai-spies": "1.0.3",
"@types/chai-string": "^1.4.0",
"@types/jsdom": "^11.0.4",
"@types/jsdom": "^21.1.1",
"@types/node": "16",
"@types/sinon": "^10.0.6",
"@types/temp": "^0.8.29",
Expand All @@ -38,7 +38,7 @@
"if-env": "^1.0.4",
"ignore-styles": "^5.0.1",
"improved-yarn-audit": "^3.0.0",
"jsdom": "^11.5.1",
"jsdom": "^21.1.1",
"lerna": "^6.0.1",
"mkdirp": "^0.5.0",
"node-gyp": "^9.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/browser/test/jsdom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export function enableJSDOM(): () => void {

const toCleanup: string[] = [];
Object.getOwnPropertyNames((dom.window as any)).forEach(property => {
if (typeof (global as any)[property] === 'undefined') {
if (!(property in global)) {
(global as any)[property] = (dom.window as any)[property];
toCleanup.push(property);
}
Expand Down
4 changes: 1 addition & 3 deletions packages/plugin-dev/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
"@theia/output": "1.36.0",
"@theia/plugin-ext": "1.36.0",
"@theia/workspace": "1.36.0",
"@types/request": "^2.0.3",
"ps-tree": "^1.2.0",
"request": "^2.82.0"
"ps-tree": "^1.2.0"
},
"publishConfig": {
"access": "public"
Expand Down
27 changes: 14 additions & 13 deletions packages/plugin-dev/src/node/hosted-instance-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
// *****************************************************************************

import { RequestOptions, RequestService } from '@theia/core/shared/@theia/request';
import { inject, injectable, named } from '@theia/core/shared/inversify';
import * as cp from 'child_process';
import * as fs from '@theia/core/shared/fs-extra';
import * as net from 'net';
import * as path from 'path';
import * as request from 'request';

import URI from '@theia/core/lib/common/uri';
import { ContributionProvider } from '@theia/core/lib/common/contribution-provider';
import { HostedPluginUriPostProcessor, HostedPluginUriPostProcessorSymbolName } from './hosted-plugin-uri-postprocessor';
Expand Down Expand Up @@ -101,7 +100,7 @@ export abstract class AbstractHostedInstanceManager implements HostedInstanceMan
protected isPluginRunning: boolean = false;
protected instanceUri: URI;
protected pluginUri: URI;
protected instanceOptions: object;
protected instanceOptions: Omit<RequestOptions, 'url'>;

@inject(HostedPluginSupport)
protected readonly hostedPluginSupport: HostedPluginSupport;
Expand All @@ -112,6 +111,9 @@ export abstract class AbstractHostedInstanceManager implements HostedInstanceMan
@inject(HostedPluginProcess)
protected readonly hostedPluginProcess: HostedPluginProcess;

@inject(RequestService)
protected readonly request: RequestService;

isRunning(): boolean {
return this.isPluginRunning;
}
Expand Down Expand Up @@ -148,7 +150,7 @@ export abstract class AbstractHostedInstanceManager implements HostedInstanceMan
this.pluginUri = pluginUri;
// disable redirect to grab the release
this.instanceOptions = {
followRedirect: false
followRedirects: 0
};
this.instanceOptions = await this.postProcessInstanceOptions(this.instanceOptions);
await this.checkInstanceUriReady();
Expand Down Expand Up @@ -212,15 +214,14 @@ export abstract class AbstractHostedInstanceManager implements HostedInstanceMan
* Ping the plugin URI (checking status of the head)
*/
private async ping(): Promise<boolean> {
return new Promise<boolean>((resolve, reject) => {
try {
const url = this.instanceUri.toString();
request.head(url, this.instanceOptions).on('response', res => {
// Wait that the status is OK
resolve(res.statusCode === 200);
}).on('error', error => {
resolve(false);
});
});
// Wait that the status is OK
const response = await this.request.request({ url, type: 'HEAD', ...this.instanceOptions });
return response.res.statusCode === 200;
} catch {
return false;
}
}

isPluginValid(uri: URI): boolean {
Expand Down Expand Up @@ -274,7 +275,7 @@ export abstract class AbstractHostedInstanceManager implements HostedInstanceMan
return uri;
}

protected async postProcessInstanceOptions(options: object): Promise<object> {
protected async postProcessInstanceOptions(options: Omit<RequestOptions, 'url'>): Promise<Omit<RequestOptions, 'url'>> {
return options;
}

Expand Down
4 changes: 1 addition & 3 deletions packages/plugin-ext-vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
"@theia/typehierarchy": "1.36.0",
"@theia/userstorage": "1.36.0",
"@theia/workspace": "1.36.0",
"@types/request": "^2.0.3",
"filenamify": "^4.1.0",
"request": "^2.82.0"
"filenamify": "^4.1.0"
},
"publishConfig": {
"access": "public"
Expand Down
4 changes: 1 addition & 3 deletions packages/plugin-ext/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
"macaddress": "^0.2.9",
"mime": "^2.4.4",
"ps-tree": "^1.2.0",
"request": "^2.82.0",
"semver": "^5.4.1",
"uuid": "^8.0.0",
"vhost": "^3.0.2",
Expand Down Expand Up @@ -90,8 +89,7 @@
"@types/decompress": "^4.2.2",
"@types/escape-html": "^0.0.20",
"@types/lodash.clonedeep": "^4.5.3",
"@types/ps-tree": "^1.1.0",
"@types/request": "^2.0.3"
"@types/ps-tree": "^1.1.0"
},
"nyc": {
"extends": "../../configs/nyc.json"
Expand Down
Loading