提交 de63daf3 编写于 作者: J Joao Moreno

remove TPromise.wrapError

related to #63897
上级 a901902c
...@@ -9,7 +9,6 @@ import pkg from 'vs/platform/node/package'; ...@@ -9,7 +9,6 @@ import pkg from 'vs/platform/node/package';
import * as path from 'path'; import * as path from 'path';
import * as semver from 'semver'; import * as semver from 'semver';
import { TPromise } from 'vs/base/common/winjs.base';
import { sequence } from 'vs/base/common/async'; import { sequence } from 'vs/base/common/async';
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection'; import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors'; import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
...@@ -63,7 +62,7 @@ export function getIdAndVersion(id: string): [string, string] { ...@@ -63,7 +62,7 @@ export function getIdAndVersion(id: string): [string, string] {
} }
type Task = { (): TPromise<void> }; type Task = { (): Thenable<void> };
class Main { class Main {
...@@ -73,41 +72,40 @@ class Main { ...@@ -73,41 +72,40 @@ class Main {
@IExtensionGalleryService private extensionGalleryService: IExtensionGalleryService @IExtensionGalleryService private extensionGalleryService: IExtensionGalleryService
) { } ) { }
run(argv: ParsedArgs): TPromise<any> { async run(argv: ParsedArgs): Promise<any> {
// TODO@joao - make this contributable
let returnPromise: TPromise<any>;
if (argv['install-source']) { if (argv['install-source']) {
returnPromise = this.setInstallSource(argv['install-source']); await this.setInstallSource(argv['install-source']);
} else if (argv['list-extensions']) { } else if (argv['list-extensions']) {
returnPromise = this.listExtensions(argv['show-versions']); await this.listExtensions(argv['show-versions']);
} else if (argv['install-extension']) { } else if (argv['install-extension']) {
const arg = argv['install-extension']; const arg = argv['install-extension'];
const args: string[] = typeof arg === 'string' ? [arg] : arg; const args: string[] = typeof arg === 'string' ? [arg] : arg;
returnPromise = this.installExtension(args, argv['force']); await this.installExtension(args, argv['force']);
} else if (argv['uninstall-extension']) { } else if (argv['uninstall-extension']) {
const arg = argv['uninstall-extension']; const arg = argv['uninstall-extension'];
const ids: string[] = typeof arg === 'string' ? [arg] : arg; const ids: string[] = typeof arg === 'string' ? [arg] : arg;
returnPromise = this.uninstallExtension(ids); await this.uninstallExtension(ids);
} }
return returnPromise || TPromise.as(null);
} }
private setInstallSource(installSource: string): TPromise<any> { private setInstallSource(installSource: string): Promise<any> {
return writeFile(this.environmentService.installSourcePath, installSource.slice(0, 30)); return writeFile(this.environmentService.installSourcePath, installSource.slice(0, 30));
} }
private listExtensions(showVersions: boolean): TPromise<any> { private async listExtensions(showVersions: boolean): Promise<any> {
return this.extensionManagementService.getInstalled(LocalExtensionType.User).then(extensions => { const extensions = await this.extensionManagementService.getInstalled(LocalExtensionType.User);
extensions.forEach(e => console.log(getId(e.manifest, showVersions))); extensions.forEach(e => console.log(getId(e.manifest, showVersions)));
});
} }
private installExtension(extensions: string[], force: boolean): TPromise<any> { private installExtension(extensions: string[], force: boolean): Promise<any> {
const vsixTasks: Task[] = extensions const vsixTasks: Task[] = extensions
.filter(e => /\.vsix$/i.test(e)) .filter(e => /\.vsix$/i.test(e))
.map(id => () => { .map(id => () => {
const extension = path.isAbsolute(id) ? id : path.join(process.cwd(), id); const extension = path.isAbsolute(id) ? id : path.join(process.cwd(), id);
return this.validate(extension, force) return this.validate(extension, force)
.then(valid => { .then(valid => {
if (valid) { if (valid) {
...@@ -118,7 +116,7 @@ class Main { ...@@ -118,7 +116,7 @@ class Main {
console.log(localize('cancelVsixInstall', "Cancelled installing Extension '{0}'.", getBaseLabel(extension))); console.log(localize('cancelVsixInstall', "Cancelled installing Extension '{0}'.", getBaseLabel(extension)));
return null; return null;
} else { } else {
return TPromise.wrapError(error); return Promise.reject(error);
} }
}); });
} }
...@@ -136,16 +134,16 @@ class Main { ...@@ -136,16 +134,16 @@ class Main {
if (err.responseText) { if (err.responseText) {
try { try {
const response = JSON.parse(err.responseText); const response = JSON.parse(err.responseText);
return TPromise.wrapError(response.message); return Promise.reject(response.message);
} catch (e) { } catch (e) {
// noop // noop
} }
} }
return TPromise.wrapError(err); return Promise.reject(err);
}) })
.then(extension => { .then(extension => {
if (!extension) { if (!extension) {
return TPromise.wrapError(new Error(`${notFound(version ? `${id}@${version}` : id)}\n${useId}`)); return Promise.reject(new Error(`${notFound(version ? `${id}@${version}` : id)}\n${useId}`));
} }
const [installedExtension] = installed.filter(e => areSameExtensions({ id: getGalleryExtensionIdFromLocal(e) }, { id })); const [installedExtension] = installed.filter(e => areSameExtensions({ id: getGalleryExtensionIdFromLocal(e) }, { id }));
...@@ -160,7 +158,7 @@ class Main { ...@@ -160,7 +158,7 @@ class Main {
} }
} else { } else {
console.log(localize('alreadyInstalled', "Extension '{0}' is already installed.", version ? `${id}@${version}` : id)); console.log(localize('alreadyInstalled', "Extension '{0}' is already installed.", version ? `${id}@${version}` : id));
return TPromise.as(null); return Promise.resolve(null);
} }
} else { } else {
console.log(localize('foundExtension', "Found '{0}' in the marketplace.", id)); console.log(localize('foundExtension', "Found '{0}' in the marketplace.", id));
...@@ -173,42 +171,41 @@ class Main { ...@@ -173,42 +171,41 @@ class Main {
return sequence([...vsixTasks, ...galleryTasks]); return sequence([...vsixTasks, ...galleryTasks]);
} }
private validate(vsix: string, force: boolean): Thenable<boolean> { private async validate(vsix: string, force: boolean): Promise<boolean> {
return getManifest(vsix) const manifest = await getManifest(vsix);
.then(manifest => {
if (manifest) { if (!manifest) {
const extensionIdentifier = { id: getGalleryExtensionId(manifest.publisher, manifest.name) }; throw new Error('Invalid vsix');
return this.extensionManagementService.getInstalled(LocalExtensionType.User) }
.then(installedExtensions => {
const newer = installedExtensions.filter(local => areSameExtensions(extensionIdentifier, { id: getGalleryExtensionIdFromLocal(local) }) && semver.gt(local.manifest.version, manifest.version))[0]; const extensionIdentifier = { id: getGalleryExtensionId(manifest.publisher, manifest.name) };
if (newer && !force) { const installedExtensions = await this.extensionManagementService.getInstalled(LocalExtensionType.User);
console.log(localize('forceDowngrade', "A newer version of this extension '{0}' v{1} is already installed. Use '--force' option to downgrade to older version.", newer.galleryIdentifier.id, newer.manifest.version, manifest.version)); const newer = installedExtensions.filter(local => areSameExtensions(extensionIdentifier, { id: getGalleryExtensionIdFromLocal(local) }) && semver.gt(local.manifest.version, manifest.version))[0];
return false;
} if (newer && !force) {
return true; console.log(localize('forceDowngrade', "A newer version of this extension '{0}' v{1} is already installed. Use '--force' option to downgrade to older version.", newer.galleryIdentifier.id, newer.manifest.version, manifest.version));
}); return false;
} else { }
return Promise.reject(new Error('Invalid vsix'));
} return true;
});
} }
private installFromGallery(id: string, extension: IGalleryExtension): TPromise<void> { private async installFromGallery(id: string, extension: IGalleryExtension): Promise<void> {
console.log(localize('installing', "Installing...")); console.log(localize('installing', "Installing..."));
return this.extensionManagementService.installFromGallery(extension)
.then( try {
() => console.log(localize('successInstall', "Extension '{0}' v{1} was successfully installed!", id, extension.version)), await this.extensionManagementService.installFromGallery(extension);
error => { console.log(localize('successInstall', "Extension '{0}' v{1} was successfully installed!", id, extension.version));
if (isPromiseCanceledError(error)) { } catch (error) {
console.log(localize('cancelVsixInstall', "Cancelled installing Extension '{0}'.", id)); if (isPromiseCanceledError(error)) {
return null; console.log(localize('cancelVsixInstall', "Cancelled installing Extension '{0}'.", id));
} else { } else {
return TPromise.wrapError(error); throw error;
} }
}); }
} }
private uninstallExtension(extensions: string[]): TPromise<any> { private uninstallExtension(extensions: string[]): Thenable<any> {
async function getExtensionId(extensionDescription: string): Promise<string> { async function getExtensionId(extensionDescription: string): Promise<string> {
if (!/\.vsix$/i.test(extensionDescription)) { if (!/\.vsix$/i.test(extensionDescription)) {
return extensionDescription; return extensionDescription;
...@@ -225,7 +222,7 @@ class Main { ...@@ -225,7 +222,7 @@ class Main {
const [extension] = installed.filter(e => areSameExtensions({ id: getGalleryExtensionIdFromLocal(e) }, { id })); const [extension] = installed.filter(e => areSameExtensions({ id: getGalleryExtensionIdFromLocal(e) }, { id }));
if (!extension) { if (!extension) {
return TPromise.wrapError(new Error(`${notInstalled(id)}\n${useId}`)); return Promise.reject(new Error(`${notInstalled(id)}\n${useId}`));
} }
console.log(localize('uninstalling', "Uninstalling {0}...", id)); console.log(localize('uninstalling', "Uninstalling {0}...", id));
...@@ -240,7 +237,7 @@ class Main { ...@@ -240,7 +237,7 @@ class Main {
const eventPrefix = 'monacoworkbench'; const eventPrefix = 'monacoworkbench';
export function main(argv: ParsedArgs): TPromise<void> { export function main(argv: ParsedArgs): Promise<void> {
const services = new ServiceCollection(); const services = new ServiceCollection();
const environmentService = new EnvironmentService(argv, process.execPath); const environmentService = new EnvironmentService(argv, process.execPath);
...@@ -259,7 +256,7 @@ export function main(argv: ParsedArgs): TPromise<void> { ...@@ -259,7 +256,7 @@ export function main(argv: ParsedArgs): TPromise<void> {
const envService = accessor.get(IEnvironmentService); const envService = accessor.get(IEnvironmentService);
const stateService = accessor.get(IStateService); const stateService = accessor.get(IStateService);
return TPromise.join([envService.appSettingsHome, envService.extensionsPath].map(p => mkdirp(p))).then(() => { return Promise.all([envService.appSettingsHome, envService.extensionsPath].map(p => mkdirp(p))).then(() => {
const { appRoot, extensionsPath, extensionDevelopmentLocationURI, isBuilt, installSourcePath } = envService; const { appRoot, extensionsPath, extensionDevelopmentLocationURI, isBuilt, installSourcePath } = envService;
const services = new ServiceCollection(); const services = new ServiceCollection();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册