提交 4c8410c1 编写于 作者: J Joao Moreno

extension.manifest

上级 60798fda
...@@ -17,8 +17,7 @@ import { IEnvironmentService } from 'vs/platform/environment/common/environment' ...@@ -17,8 +17,7 @@ import { IEnvironmentService } from 'vs/platform/environment/common/environment'
import { EnvironmentService } from 'vs/platform/environment/node/environmentService'; import { EnvironmentService } from 'vs/platform/environment/node/environmentService';
import { IEventService } from 'vs/platform/event/common/event'; import { IEventService } from 'vs/platform/event/common/event';
import { EventService } from 'vs/platform/event/common/eventService'; import { EventService } from 'vs/platform/event/common/eventService';
import { IExtensionManagementService, IExtensionGalleryService, IQueryResult } from 'vs/platform/extensionManagement/common/extensionManagement'; import { IExtensionManagementService, IExtensionGalleryService, IQueryResult, IExtensionManifest } from 'vs/platform/extensionManagement/common/extensionManagement';
import { getExtensionId } from 'vs/platform/extensionManagement/node/extensionManagementUtil';
import { ExtensionManagementService } from 'vs/platform/extensionManagement/node/extensionManagementService'; import { ExtensionManagementService } from 'vs/platform/extensionManagement/node/extensionManagementService';
import { ExtensionGalleryService } from 'vs/platform/extensionManagement/node/extensionGalleryService'; import { ExtensionGalleryService } from 'vs/platform/extensionManagement/node/extensionGalleryService';
import { ITelemetryService, combinedAppender, NullTelemetryService } from 'vs/platform/telemetry/common/telemetry'; import { ITelemetryService, combinedAppender, NullTelemetryService } from 'vs/platform/telemetry/common/telemetry';
...@@ -34,6 +33,10 @@ const notFound = id => localize('notFound', "Extension '{0}' not found.", id); ...@@ -34,6 +33,10 @@ const notFound = id => localize('notFound', "Extension '{0}' not found.", id);
const notInstalled = id => localize('notInstalled', "Extension '{0}' is not installed.", id); const notInstalled = id => localize('notInstalled', "Extension '{0}' is not installed.", id);
const useId = localize('useId', "Make sure you use the full extension ID, eg: {0}", 'ms-vscode.csharp'); const useId = localize('useId', "Make sure you use the full extension ID, eg: {0}", 'ms-vscode.csharp');
function getId(manifest: IExtensionManifest): string {
return `${ manifest.publisher }.${ manifest.name }`;
}
class Main { class Main {
constructor( constructor(
...@@ -59,14 +62,14 @@ class Main { ...@@ -59,14 +62,14 @@ class Main {
private listExtensions(): TPromise<any> { private listExtensions(): TPromise<any> {
return this.extensionManagementService.getInstalled().then(extensions => { return this.extensionManagementService.getInstalled().then(extensions => {
extensions.forEach(e => console.log(getExtensionId(e))); extensions.forEach(e => console.log(getId(e.manifest)));
}); });
} }
private installExtension(ids: string[]): TPromise<any> { private installExtension(ids: string[]): TPromise<any> {
return sequence(ids.map(id => () => { return sequence(ids.map(id => () => {
return this.extensionManagementService.getInstalled().then(installed => { return this.extensionManagementService.getInstalled().then(installed => {
const isInstalled = installed.some(e => getExtensionId(e) === id); const isInstalled = installed.some(e => getId(e.manifest) === id);
if (isInstalled) { if (isInstalled) {
console.log(localize('alreadyInstalled', "Extension '{0}' is already installed.", id)); console.log(localize('alreadyInstalled', "Extension '{0}' is already installed.", id));
...@@ -105,7 +108,7 @@ class Main { ...@@ -105,7 +108,7 @@ class Main {
private uninstallExtension(ids: string[]): TPromise<any> { private uninstallExtension(ids: string[]): TPromise<any> {
return sequence(ids.map(id => () => { return sequence(ids.map(id => () => {
return this.extensionManagementService.getInstalled().then(installed => { return this.extensionManagementService.getInstalled().then(installed => {
const [extension] = installed.filter(e => getExtensionId(e) === id); const [extension] = installed.filter(e => getId(e.manifest) === id);
if (!extension) { if (!extension) {
return TPromise.wrapError(`${ notInstalled(id) }\n${ useId }`); return TPromise.wrapError(`${ notInstalled(id) }\n${ useId }`);
......
...@@ -39,7 +39,8 @@ export interface IGalleryMetadata { ...@@ -39,7 +39,8 @@ export interface IGalleryMetadata {
versions: IGalleryVersion[]; versions: IGalleryVersion[];
} }
export interface IExtension extends IExtensionManifest { export interface IExtension {
manifest: IExtensionManifest;
path?: string; path?: string;
} }
......
...@@ -38,7 +38,7 @@ function parseManifest(raw: string): TPromise<IExtensionManifest> { ...@@ -38,7 +38,7 @@ function parseManifest(raw: string): TPromise<IExtensionManifest> {
}); });
} }
function validate(zipPath: string, extension?: IExtension, version = extension && extension.version): TPromise<IExtension> { function validate(zipPath: string, extension?: IExtensionManifest, version = extension && extension.version): TPromise<IExtensionManifest> {
return buffer(zipPath, 'extension/package.json') return buffer(zipPath, 'extension/package.json')
.then(buffer => parseManifest(buffer.toString('utf8'))) .then(buffer => parseManifest(buffer.toString('utf8')))
.then(manifest => { .then(manifest => {
...@@ -61,14 +61,7 @@ function validate(zipPath: string, extension?: IExtension, version = extension & ...@@ -61,14 +61,7 @@ function validate(zipPath: string, extension?: IExtension, version = extension &
} }
function createExtension(manifest: IExtensionManifest, path?: string): IExtension { function createExtension(manifest: IExtensionManifest, path?: string): IExtension {
const extension: IExtension = { const extension: IExtension = { manifest };
name: manifest.name,
displayName: manifest.displayName || manifest.name,
publisher: manifest.publisher,
version: manifest.version,
engines: { vscode: manifest.engines.vscode },
description: manifest.description || ''
};
// if (galleryInformation) { // if (galleryInformation) {
// extension.galleryInformation = galleryInformation; // extension.galleryInformation = galleryInformation;
...@@ -133,10 +126,12 @@ export class ExtensionManagementService implements IExtensionManagementService { ...@@ -133,10 +126,12 @@ export class ExtensionManagementService implements IExtensionManagementService {
return this.installFromZip(arg); return this.installFromZip(arg);
} }
const extension = arg as IExtension; const extension = arg as IGalleryExtension;
const { manifest } = extension;
return this.isObsolete(extension).then(obsolete => { return this.isObsolete(extension).then(obsolete => {
if (obsolete) { if (obsolete) {
return TPromise.wrapError<void>(new Error(nls.localize('restartCode', "Please restart Code before reinstalling {0}.", extension.name))); return TPromise.wrapError<void>(new Error(nls.localize('restartCode', "Please restart Code before reinstalling {0}.", manifest.name)));
} }
return this.installFromGallery(arg); return this.installFromGallery(arg);
...@@ -206,8 +201,9 @@ export class ExtensionManagementService implements IExtensionManagementService { ...@@ -206,8 +201,9 @@ export class ExtensionManagementService implements IExtensionManagementService {
} }
uninstall(extension: IExtension): TPromise<void> { uninstall(extension: IExtension): TPromise<void> {
const extensionPath = extension.path || path.join(this.extensionsPath, getExtensionId(extension)); const { manifest } = extension;
const id = getExtensionId(extension); const id = getExtensionId(manifest);
const extensionPath = extension.path || path.join(this.extensionsPath, id);
return pfs.exists(extensionPath) return pfs.exists(extensionPath)
.then(exists => exists ? null : Promise.wrapError(new Error(nls.localize('notExists', "Could not find extension")))) .then(exists => exists ? null : Promise.wrapError(new Error(nls.localize('notExists', "Could not find extension"))))
...@@ -226,8 +222,8 @@ export class ExtensionManagementService implements IExtensionManagementService { ...@@ -226,8 +222,8 @@ export class ExtensionManagementService implements IExtensionManagementService {
} }
return all.then(extensions => { return all.then(extensions => {
const byId = values(groupBy(extensions, p => `${ p.publisher }.${ p.name }`)); const byId = values(groupBy(extensions, p => `${ p.manifest.publisher }.${ p.manifest.name }`));
return byId.map(p => p.sort((a, b) => semver.rcompare(a.version, b.version))[0]); return byId.map(p => p.sort((a, b) => semver.rcompare(a.manifest.version, b.manifest.version))[0]);
}); });
} }
...@@ -254,7 +250,7 @@ export class ExtensionManagementService implements IExtensionManagementService { ...@@ -254,7 +250,7 @@ export class ExtensionManagementService implements IExtensionManagementService {
removeDeprecatedExtensions(): TPromise<void> { removeDeprecatedExtensions(): TPromise<void> {
const outdated = this.getOutdatedExtensions() const outdated = this.getOutdatedExtensions()
.then(extensions => extensions.map(e => getExtensionId(e))); .then(extensions => extensions.map(({ manifest }) => getExtensionId(manifest)));
const obsolete = this.getObsoleteExtensions() const obsolete = this.getObsoleteExtensions()
.then(obsolete => Object.keys(obsolete)); .then(obsolete => Object.keys(obsolete));
...@@ -271,26 +267,26 @@ export class ExtensionManagementService implements IExtensionManagementService { ...@@ -271,26 +267,26 @@ export class ExtensionManagementService implements IExtensionManagementService {
private getOutdatedExtensions(): TPromise<IExtension[]> { private getOutdatedExtensions(): TPromise<IExtension[]> {
return this.getAllInstalled().then(plugins => { return this.getAllInstalled().then(plugins => {
const byId = values(groupBy(plugins, p => `${ p.publisher }.${ p.name }`)); const byId = values(groupBy(plugins, p => `${ p.manifest.publisher }.${ p.manifest.name }`));
const extensions = flatten(byId.map(p => p.sort((a, b) => semver.rcompare(a.version, b.version)).slice(1))); const extensions = flatten(byId.map(p => p.sort((a, b) => semver.rcompare(a.manifest.version, b.manifest.version)).slice(1)));
return extensions return extensions
.filter(e => !!e.path); .filter(e => !!e.path);
}); });
} }
private isObsolete(extension: IExtension): TPromise<boolean> { private isObsolete({ manifest }: IExtension): TPromise<boolean> {
const id = getExtensionId(extension); const id = getExtensionId(manifest);
return this.withObsoleteExtensions(obsolete => !!obsolete[id]); return this.withObsoleteExtensions(obsolete => !!obsolete[id]);
} }
private setObsolete(extension: IExtension): TPromise<void> { private setObsolete({ manifest }: IExtension): TPromise<void> {
const id = getExtensionId(extension); const id = getExtensionId(manifest);
return this.withObsoleteExtensions(obsolete => assign(obsolete, { [id]: true })); return this.withObsoleteExtensions(obsolete => assign(obsolete, { [id]: true }));
} }
private unsetObsolete(extension: IExtension): TPromise<void> { private unsetObsolete({ manifest }: IExtension): TPromise<void> {
const id = getExtensionId(extension); const id = getExtensionId(manifest);
return this.withObsoleteExtensions<void>(obsolete => delete obsolete[id]); return this.withObsoleteExtensions<void>(obsolete => delete obsolete[id]);
} }
......
...@@ -9,10 +9,6 @@ import { IExtension, IExtensionManifest, IExtensionManagementService, IExtension ...@@ -9,10 +9,6 @@ import { IExtension, IExtensionManifest, IExtensionManagementService, IExtension
import { TPromise } from 'vs/base/common/winjs.base'; import { TPromise } from 'vs/base/common/winjs.base';
import * as semver from 'semver'; import * as semver from 'semver';
export function getExtensionId(extension: IExtension): string {
return `${ extension.publisher }.${ extension.name }`;
}
export function extensionEquals(one: IExtensionManifest, other: IExtensionManifest): boolean { export function extensionEquals(one: IExtensionManifest, other: IExtensionManifest): boolean {
return one.publisher === other.publisher && one.name === other.name; return one.publisher === other.publisher && one.name === other.name;
} }
...@@ -36,14 +32,14 @@ export function getOutdatedExtensions(extensionsService: IExtensionManagementSer ...@@ -36,14 +32,14 @@ export function getOutdatedExtensions(extensionsService: IExtensionManagementSer
} }
return extensionsService.getInstalled().then(installed => { return extensionsService.getInstalled().then(installed => {
const ids = installed.map(getExtensionId); const ids = installed.map(({ manifest }) => `${ manifest.publisher }.${ manifest.name }`);
return galleryService.query({ ids, pageSize: 1000 }).then(result => { return galleryService.query({ ids, pageSize: 1000 }).then(result => {
const available = result.firstPage; const available = result.firstPage;
return available.map(extension => { return available.map(extension => {
const local = installed.filter(local => extensionEquals(local, extension.manifest))[0]; const local = installed.filter(local => extensionEquals(local.manifest, extension.manifest))[0];
if (local && semver.lt(local.version, extension.manifest.version)) { if (local && semver.lt(local.manifest.version, extension.manifest.version)) {
return local; return local;
} else { } else {
return null; return null;
......
...@@ -32,7 +32,7 @@ export class ListExtensionsAction extends Action { ...@@ -32,7 +32,7 @@ export class ListExtensionsAction extends Action {
super(id, label, null, true); super(id, label, null, true);
} }
public run(): Promise { run(): Promise {
return this.quickOpenService.show('ext '); return this.quickOpenService.show('ext ');
} }
...@@ -55,7 +55,7 @@ export class InstallExtensionAction extends Action { ...@@ -55,7 +55,7 @@ export class InstallExtensionAction extends Action {
super(id, label, null, true); super(id, label, null, true);
} }
public run(): Promise { run(): Promise {
return this.quickOpenService.show('ext install '); return this.quickOpenService.show('ext install ');
} }
...@@ -78,7 +78,7 @@ export class ListOutdatedExtensionsAction extends Action { ...@@ -78,7 +78,7 @@ export class ListOutdatedExtensionsAction extends Action {
super(id, label, null, true); super(id, label, null, true);
} }
public run(): Promise { run(): Promise {
return this.quickOpenService.show('ext update '); return this.quickOpenService.show('ext update ');
} }
...@@ -101,7 +101,7 @@ export class ListSuggestedExtensionsAction extends Action { ...@@ -101,7 +101,7 @@ export class ListSuggestedExtensionsAction extends Action {
super(id, label, null, true); super(id, label, null, true);
} }
public run(): Promise { run(): Promise {
return this.quickOpenService.show('ext recommend '); return this.quickOpenService.show('ext recommend ');
} }
...@@ -123,11 +123,11 @@ export class InstallAction extends Action { ...@@ -123,11 +123,11 @@ export class InstallAction extends Action {
super('extensions.install', label, 'octicon octicon-cloud-download', true); super('extensions.install', label, 'octicon octicon-cloud-download', true);
} }
public run(extension: IGalleryExtension): TPromise<any> { run(extension: IGalleryExtension): TPromise<any> {
this.enabled = false; this.enabled = false;
return this.extensionManagementService.getInstalled() return this.extensionManagementService.getInstalled()
.then(installed => installed.some(e => extensionEquals(e, extension.manifest))) .then(installed => installed.some(({ manifest }) => extensionEquals(manifest, extension.manifest)))
.then(isUpdate => { .then(isUpdate => {
return this.extensionManagementService return this.extensionManagementService
.install(extension) .install(extension)
...@@ -173,18 +173,20 @@ export class UninstallAction extends Action { ...@@ -173,18 +173,20 @@ export class UninstallAction extends Action {
super('extensions.uninstall', nls.localize('uninstall', "Uninstall Extension"), 'octicon octicon-x', true); super('extensions.uninstall', nls.localize('uninstall', "Uninstall Extension"), 'octicon octicon-x', true);
} }
public run(extension: IExtension): TPromise<any> { run(extension: IExtension): TPromise<any> {
if (!window.confirm(nls.localize('deleteSure', "Are you sure you want to uninstall '{0}'?", extension.displayName))) { const name = extension.manifest.displayName || extension.manifest.name;
if (!window.confirm(nls.localize('deleteSure', "Are you sure you want to uninstall '{0}'?", name))) {
return TPromise.as(null); return TPromise.as(null);
} }
this.enabled = false; this.enabled = false;
return this.extensionManagementService.getInstalled().then(localExtensions => { return this.extensionManagementService.getInstalled().then(localExtensions => {
const [local] = localExtensions.filter(local => extensionEquals(local, extension)); const [local] = localExtensions.filter(local => extensionEquals(local.manifest, extension.manifest));
if (!local) { if (!local) {
return TPromise.wrapError(nls.localize('notFound', "Extension '{0}' not installed.", extension.displayName)); return TPromise.wrapError(nls.localize('notFound', "Extension '{0}' not installed.", name));
} }
return this.extensionManagementService.uninstall(local) return this.extensionManagementService.uninstall(local)
...@@ -195,9 +197,11 @@ export class UninstallAction extends Action { ...@@ -195,9 +197,11 @@ export class UninstallAction extends Action {
} }
private onSuccess(extension: IExtension) { private onSuccess(extension: IExtension) {
const name = extension.manifest.displayName || extension.manifest.name;
this.reportTelemetry(extension, true); this.reportTelemetry(extension, true);
this.messageService.show(Severity.Info, { this.messageService.show(Severity.Info, {
message: nls.localize('success-uninstalled', "'{0}' was successfully uninstalled. Restart to deactivate it.", extension.displayName), message: nls.localize('success-uninstalled', "'{0}' was successfully uninstalled. Restart to deactivate it.", name),
actions: [ actions: [
CloseAction, CloseAction,
this.instantiationService.createInstance(ReloadWindowAction, ReloadWindowAction.ID, nls.localize('restartNow2', "Restart Now")) this.instantiationService.createInstance(ReloadWindowAction, ReloadWindowAction.ID, nls.localize('restartNow2', "Restart Now"))
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册