提交 40559425 编写于 作者: M Matt Bierner

Revert "allow setting default tag while installing extensions"

This reverts commit a2bc061b.

Revert "merge metadata into local extension"

This reverts commit b354b435.
上级 ce9ed171
......@@ -86,7 +86,7 @@ export class Main {
} else if (argv['list-extensions']) {
await this.listExtensions(!!argv['show-versions'], argv['category']);
} else if (argv['install-extension']) {
await this.installExtensions(argv['install-extension'], !!argv['force'], !!argv['default']);
await this.installExtensions(argv['install-extension'], !!argv['force']);
} else if (argv['uninstall-extension']) {
await this.uninstallExtension(argv['uninstall-extension']);
} else if (argv['locate-extension']) {
......@@ -126,7 +126,7 @@ export class Main {
extensions.forEach(e => console.log(getId(e.manifest, showVersions)));
}
private async installExtensions(extensions: string[], force: boolean, isDefault: boolean): Promise<void> {
private async installExtensions(extensions: string[], force: boolean): Promise<void> {
const failed: string[] = [];
const installedExtensionsManifests: IExtensionManifest[] = [];
if (extensions.length) {
......@@ -135,7 +135,7 @@ export class Main {
for (const extension of extensions) {
try {
const manifest = await this.installExtension(extension, force, isDefault);
const manifest = await this.installExtension(extension, force);
if (manifest) {
installedExtensionsManifests.push(manifest);
}
......@@ -150,7 +150,7 @@ export class Main {
return failed.length ? Promise.reject(localize('installation failed', "Failed Installing Extensions: {0}", failed.join(', '))) : Promise.resolve();
}
private async installExtension(extension: string, force: boolean, isDefault: boolean): Promise<IExtensionManifest | null> {
private async installExtension(extension: string, force: boolean): Promise<IExtensionManifest | null> {
if (/\.vsix$/i.test(extension)) {
extension = path.isAbsolute(extension) ? extension : path.join(process.cwd(), extension);
......@@ -205,7 +205,7 @@ export class Main {
}
console.log(localize('updateMessage', "Updating the extension '{0}' to the version {1}", id, extension.version));
}
await this.installFromGallery(id, extension, isDefault);
await this.installFromGallery(id, extension);
return manifest;
}));
}
......@@ -227,11 +227,11 @@ export class Main {
return true;
}
private async installFromGallery(id: string, extension: IGalleryExtension, isDefault: boolean): Promise<void> {
private async installFromGallery(id: string, extension: IGalleryExtension): Promise<void> {
console.log(localize('installing', "Installing extension '{0}' v{1}...", id, extension.version));
try {
await this.extensionManagementService.installFromGallery(extension, isDefault);
await this.extensionManagementService.installFromGallery(extension);
console.log(localize('successInstall', "Extension '{0}' v{1} was successfully installed.", id, extension.version));
} catch (error) {
if (isPromiseCanceledError(error)) {
......
......@@ -72,7 +72,6 @@ export interface ParsedArgs {
remote?: string;
'disable-user-env-probe'?: boolean;
'force'?: boolean;
'default'?: boolean;
'force-user-env'?: boolean;
'sync'?: 'on' | 'off';
......@@ -188,7 +187,6 @@ export const OPTIONS: OptionDescriptions<Required<ParsedArgs>> = {
'file-chmod': { type: 'boolean' },
'driver-verbose': { type: 'boolean' },
'force': { type: 'boolean' },
'default': { type: 'boolean' },
'trace': { type: 'boolean' },
'trace-category-filter': { type: 'string' },
'trace-options': { type: 'string' },
......
......@@ -92,9 +92,7 @@ export interface IGalleryMetadata {
export interface ILocalExtension extends IExtension {
readonly manifest: IExtensionManifest;
isDefault: boolean;
publisherId: string | null;
publisherDisplayName: string | null;
metadata: IGalleryMetadata;
readmeUrl: URI | null;
changelogUrl: URI | null;
}
......@@ -206,8 +204,8 @@ export interface IExtensionManagementService {
zip(extension: ILocalExtension): Promise<URI>;
unzip(zipLocation: URI): Promise<IExtensionIdentifier>;
getManifest(vsix: URI): Promise<IExtensionManifest>;
install(vsix: URI, isDefault?: boolean): Promise<ILocalExtension>;
installFromGallery(extension: IGalleryExtension, isDefault?: boolean): Promise<ILocalExtension>;
install(vsix: URI): Promise<ILocalExtension>;
installFromGallery(extension: IGalleryExtension): Promise<ILocalExtension>;
uninstall(extension: ILocalExtension, force?: boolean): Promise<void>;
reinstallFromGallery(extension: ILocalExtension): Promise<void>;
getInstalled(type?: ExtensionType): Promise<ILocalExtension[]>;
......
......@@ -69,9 +69,9 @@ export function getLocalExtensionTelemetryData(extension: ILocalExtension): any
id: extension.identifier.id,
name: extension.manifest.name,
galleryId: null,
publisherId: extension.publisherId,
publisherId: extension.metadata ? extension.metadata.publisherId : null,
publisherName: extension.manifest.publisher,
publisherDisplayName: extension.publisherDisplayName,
publisherDisplayName: extension.metadata ? extension.metadata.publisherDisplayName : null,
dependencies: extension.manifest.extensionDependencies && extension.manifest.extensionDependencies.length > 0
};
}
......@@ -116,4 +116,4 @@ export function getMaliciousExtensionsSet(report: IReportedExtension[]): Set<str
}
return result;
}
}
\ No newline at end of file
......@@ -45,7 +45,7 @@ import { CancellationToken } from 'vs/base/common/cancellation';
import { getManifest } from 'vs/platform/extensionManagement/node/extensionManagementUtil';
import { IExtensionManifest, ExtensionType } from 'vs/platform/extensions/common/extensions';
import { ExtensionsDownloader } from 'vs/platform/extensionManagement/node/extensionDownloader';
import { ExtensionsScanner, IMetadata } from 'vs/platform/extensionManagement/node/extensionsScanner';
import { ExtensionsScanner } from 'vs/platform/extensionManagement/node/extensionsScanner';
import { ExtensionsLifecycle } from 'vs/platform/extensionManagement/node/extensionLifecycle';
const INSTALL_ERROR_UNSET_UNINSTALLED = 'unsetUninstalled';
......@@ -57,7 +57,7 @@ const ERROR_UNKNOWN = 'unknown';
interface InstallableExtension {
zipPath: string;
identifierWithVersion: ExtensionIdentifierWithVersion;
metadata?: IMetadata;
metadata: IGalleryMetadata | null;
}
export class ExtensionManagementService extends Disposable implements IExtensionManagementService {
......@@ -152,7 +152,7 @@ export class ExtensionManagementService extends Disposable implements IExtension
}
install(vsix: URI, isDefault: boolean = false): Promise<ILocalExtension> {
install(vsix: URI): Promise<ILocalExtension> {
this.logService.trace('ExtensionManagementService#install', vsix.toString());
return createCancelablePromise(token => {
return this.downloadVsix(vsix).then(downloadLocation => {
......@@ -192,10 +192,10 @@ export class ExtensionManagementService extends Disposable implements IExtension
.then(() => {
this.logService.info('Installing the extension:', identifier.id);
this._onInstallExtension.fire({ identifier, zipPath });
return this.getGalleryMetadata(getGalleryExtensionId(manifest.publisher, manifest.name))
return this.getMetadata(getGalleryExtensionId(manifest.publisher, manifest.name))
.then(
metadata => this.installFromZipPath(identifierWithVersion, zipPath, { ...metadata, isDefault }, operation, token),
() => this.installFromZipPath(identifierWithVersion, zipPath, { isDefault }, operation, token))
metadata => this.installFromZipPath(identifierWithVersion, zipPath, metadata, operation, token),
() => this.installFromZipPath(identifierWithVersion, zipPath, null, operation, token))
.then(
local => { this.logService.info('Successfully installed the extension:', identifier.id); return local; },
e => {
......@@ -219,7 +219,7 @@ export class ExtensionManagementService extends Disposable implements IExtension
return this.downloadService.download(vsix, URI.file(downloadedLocation)).then(() => URI.file(downloadedLocation));
}
private installFromZipPath(identifierWithVersion: ExtensionIdentifierWithVersion, zipPath: string, metadata: IMetadata, operation: InstallOperation, token: CancellationToken): Promise<ILocalExtension> {
private installFromZipPath(identifierWithVersion: ExtensionIdentifierWithVersion, zipPath: string, metadata: IGalleryMetadata | null, operation: InstallOperation, token: CancellationToken): Promise<ILocalExtension> {
return this.toNonCancellablePromise(this.installExtension({ zipPath, identifierWithVersion, metadata }, token)
.then(local => this.installDependenciesAndPackExtensions(local, null)
.then(
......@@ -239,7 +239,7 @@ export class ExtensionManagementService extends Disposable implements IExtension
));
}
async installFromGallery(extension: IGalleryExtension, isDefault?: boolean): Promise<ILocalExtension> {
async installFromGallery(extension: IGalleryExtension): Promise<ILocalExtension> {
if (!this.galleryService.isEnabled()) {
return Promise.reject(new Error(nls.localize('MarketPlaceDisabled', "Marketplace is not enabled")));
}
......@@ -287,11 +287,8 @@ export class ExtensionManagementService extends Disposable implements IExtension
}
this.downloadInstallableExtension(extension, operation)
.then(installableExtension => {
installableExtension.metadata.isDefault = isDefault !== undefined ? isDefault : existingExtension.isDefault;
return this.installExtension(installableExtension, cancellationToken)
.then(local => this.extensionsDownloader.delete(URI.file(installableExtension.zipPath)).finally(() => { }).then(() => local));
})
.then(installableExtension => this.installExtension(installableExtension, cancellationToken)
.then(local => this.extensionsDownloader.delete(URI.file(installableExtension.zipPath)).finally(() => { }).then(() => local)))
.then(local => this.installDependenciesAndPackExtensions(local, existingExtension)
.then(() => local, error => this.uninstall(local, true).then(() => Promise.reject(error), () => Promise.reject(error))))
.then(
......@@ -361,7 +358,7 @@ export class ExtensionManagementService extends Disposable implements IExtension
.then(report => getMaliciousExtensionsSet(report).has(extension.identifier.id));
}
private downloadInstallableExtension(extension: IGalleryExtension, operation: InstallOperation): Promise<Required<InstallableExtension>> {
private downloadInstallableExtension(extension: IGalleryExtension, operation: InstallOperation): Promise<InstallableExtension> {
const metadata = <IGalleryMetadata>{
id: extension.identifier.uuid,
publisherId: extension.publisherId,
......@@ -376,7 +373,7 @@ export class ExtensionManagementService extends Disposable implements IExtension
this.logService.info('Downloaded extension:', extension.identifier.id, zipPath);
return getManifest(zipPath)
.then(
manifest => (<Required<InstallableExtension>>{ zipPath, identifierWithVersion: new ExtensionIdentifierWithVersion(extension.identifier, manifest.version), metadata }),
manifest => (<InstallableExtension>{ zipPath, identifierWithVersion: new ExtensionIdentifierWithVersion(extension.identifier, manifest.version), metadata }),
error => Promise.reject(new ExtensionManagementError(this.joinErrors(error).message, INSTALL_ERROR_VALIDATING))
);
},
......@@ -422,7 +419,8 @@ export class ExtensionManagementService extends Disposable implements IExtension
let local = await this.extensionsScanner.extractUserExtension(identifierWithVersion, zipPath, token);
this.logService.info('Installation completed.', identifier.id);
if (metadata) {
local = await this.extensionsScanner.saveMetadataForLocalExtension(local, metadata);
this.setMetadata(local, metadata);
local = await this.extensionsScanner.saveMetadataForLocalExtension(local);
}
return local;
}
......@@ -483,14 +481,15 @@ export class ExtensionManagementService extends Disposable implements IExtension
async updateMetadata(local: ILocalExtension, metadata: IGalleryMetadata): Promise<ILocalExtension> {
this.logService.trace('ExtensionManagementService#updateMetadata', local.identifier.id);
local = await this.extensionsScanner.saveMetadataForLocalExtension(local, { ...metadata, isDefault: local.isDefault });
local.metadata = metadata;
local = await this.extensionsScanner.saveMetadataForLocalExtension(local);
this.manifestCache.invalidate();
return local;
}
private getGalleryMetadata(extensionName: string): Promise<IGalleryMetadata | undefined> {
private getMetadata(extensionName: string): Promise<IGalleryMetadata | null> {
return this.findGalleryExtensionByName(extensionName)
.then(galleryExtension => galleryExtension ? <IGalleryMetadata>{ id: galleryExtension.identifier.uuid, publisherDisplayName: galleryExtension.publisherDisplayName, publisherId: galleryExtension.publisherId } : undefined);
.then(galleryExtension => galleryExtension ? <IGalleryMetadata>{ id: galleryExtension.identifier.uuid, publisherDisplayName: galleryExtension.publisherDisplayName, publisherId: galleryExtension.publisherId } : null);
}
private findGalleryExtension(local: ILocalExtension): Promise<IGalleryExtension> {
......@@ -630,6 +629,11 @@ export class ExtensionManagementService extends Disposable implements IExtension
return this.extensionsScanner.scanExtensions(type);
}
private setMetadata(local: ILocalExtension, metadata: IGalleryMetadata): void {
local.metadata = metadata;
local.identifier.uuid = metadata.id;
}
removeDeprecatedExtensions(): Promise<void> {
return this.extensionsScanner.cleanUp();
}
......
......@@ -32,8 +32,6 @@ const INSTALL_ERROR_EXTRACTING = 'extracting';
const INSTALL_ERROR_DELETING = 'deleting';
const INSTALL_ERROR_RENAMING = 'renaming';
export type IMetadata = Partial<IGalleryMetadata> & { isDefault: boolean; };
export class ExtensionsScanner extends Disposable {
private readonly systemExtensionsPath: string;
......@@ -129,13 +127,14 @@ export class ExtensionsScanner extends Disposable {
throw new Error(localize('cannot read', "Cannot read the extension from {0}", this.extensionsPath));
}
async saveMetadataForLocalExtension(local: ILocalExtension, metadata: IMetadata): Promise<ILocalExtension> {
this.setMetadata(local, metadata);
const manifestPath = path.join(local.location.fsPath, 'package.json');
const raw = await pfs.readFile(manifestPath, 'utf8');
const { manifest } = await this.parseManifest(raw);
assign(manifest, { __metadata: metadata });
await pfs.writeFile(manifestPath, JSON.stringify(manifest, null, '\t'));
async saveMetadataForLocalExtension(local: ILocalExtension): Promise<ILocalExtension> {
if (local.metadata) {
const manifestPath = path.join(local.location.fsPath, 'package.json');
const raw = await pfs.readFile(manifestPath, 'utf8');
const { manifest } = await this.parseManifest(raw);
assign(manifest, { __metadata: local.metadata });
await pfs.writeFile(manifestPath, JSON.stringify(manifest, null, '\t'));
}
return local;
}
......@@ -229,7 +228,7 @@ export class ExtensionsScanner extends Disposable {
const changelog = children.filter(child => /^changelog(\.txt|\.md|)$/i.test(child))[0];
const changelogUrl = changelog ? URI.file(path.join(extensionPath, changelog)) : null;
const identifier = { id: getGalleryExtensionId(manifest.publisher, manifest.name) };
const local = <ILocalExtension>{ type, identifier, manifest, location: URI.file(extensionPath), readmeUrl, changelogUrl, publisherDisplayName: null, publisherId: null, isDefault: false };
const local = <ILocalExtension>{ type, identifier, manifest, metadata, location: URI.file(extensionPath), readmeUrl, changelogUrl };
if (metadata) {
this.setMetadata(local, metadata);
}
......@@ -257,11 +256,9 @@ export class ExtensionsScanner extends Disposable {
}
}
private setMetadata(local: ILocalExtension, metadata: IMetadata): void {
local.publisherDisplayName = metadata.publisherDisplayName || null;
local.publisherId = metadata.publisherId || null;
private setMetadata(local: ILocalExtension, metadata: IGalleryMetadata): void {
local.metadata = metadata;
local.identifier.uuid = metadata.id;
local.isDefault = metadata.isDefault;
}
private async removeUninstalledExtensions(): Promise<void> {
......@@ -317,7 +314,7 @@ export class ExtensionsScanner extends Disposable {
return this._devSystemExtensionsPath;
}
private async readManifest(extensionPath: string): Promise<{ manifest: IExtensionManifest; metadata: IMetadata | null; }> {
private async readManifest(extensionPath: string): Promise<{ manifest: IExtensionManifest; metadata: IGalleryMetadata; }> {
const promises = [
pfs.readFile(path.join(extensionPath, 'package.json'), 'utf8')
.then(raw => this.parseManifest(raw)),
......@@ -333,7 +330,7 @@ export class ExtensionsScanner extends Disposable {
};
}
private parseManifest(raw: string): Promise<{ manifest: IExtensionManifest; metadata: IMetadata | null; }> {
private parseManifest(raw: string): Promise<{ manifest: IExtensionManifest; metadata: IGalleryMetadata; }> {
return new Promise((c, e) => {
try {
const manifest = JSON.parse(raw);
......
......@@ -94,8 +94,8 @@ class Extension implements IExtension {
return this.gallery.publisherDisplayName || this.gallery.publisher;
}
if (this.local?.publisherDisplayName) {
return this.local.publisherDisplayName;
if (this.local!.metadata && this.local!.metadata.publisherDisplayName) {
return this.local!.metadata.publisherDisplayName;
}
return this.local!.manifest.publisher;
......@@ -367,7 +367,7 @@ class Extensions extends Disposable {
}
// Sync the local extension with gallery extension if local extension doesnot has metadata
if (extension.local) {
const local = extension.local.identifier.uuid ? extension.local : await this.server.extensionManagementService.updateMetadata(extension.local, { id: compatible.identifier.uuid, publisherDisplayName: compatible.publisherDisplayName, publisherId: compatible.publisherId });
const local = extension.local.metadata ? extension.local : await this.server.extensionManagementService.updateMetadata(extension.local, { id: compatible.identifier.uuid, publisherDisplayName: compatible.publisherDisplayName, publisherId: compatible.publisherId });
extension.local = local;
extension.gallery = compatible;
this._onChange.fire({ extension });
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册