Revert "Revert "allow setting default tag while installing extensions""

This reverts commit 40559425c7.
This commit is contained in:
Sandeep Somavarapu
2020-05-28 08:07:47 +02:00
parent fd0051cde7
commit f676774cb7
7 changed files with 55 additions and 52 deletions

View File

@@ -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']);
await this.installExtensions(argv['install-extension'], !!argv['force'], !!argv['default']);
} 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): Promise<void> {
private async installExtensions(extensions: string[], force: boolean, isDefault: 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);
const manifest = await this.installExtension(extension, force, isDefault);
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): Promise<IExtensionManifest | null> {
private async installExtension(extension: string, force: boolean, isDefault: 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);
await this.installFromGallery(id, extension, isDefault);
return manifest;
}));
}
@@ -227,11 +227,11 @@ export class Main {
return true;
}
private async installFromGallery(id: string, extension: IGalleryExtension): Promise<void> {
private async installFromGallery(id: string, extension: IGalleryExtension, isDefault: boolean): Promise<void> {
console.log(localize('installing', "Installing extension '{0}' v{1}...", id, extension.version));
try {
await this.extensionManagementService.installFromGallery(extension);
await this.extensionManagementService.installFromGallery(extension, isDefault);
console.log(localize('successInstall', "Extension '{0}' v{1} was successfully installed.", id, extension.version));
} catch (error) {
if (isPromiseCanceledError(error)) {

View File

@@ -72,6 +72,7 @@ export interface ParsedArgs {
remote?: string;
'disable-user-env-probe'?: boolean;
'force'?: boolean;
'default'?: boolean;
'force-user-env'?: boolean;
'sync'?: 'on' | 'off';
@@ -187,6 +188,7 @@ 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' },

View File

@@ -92,7 +92,9 @@ export interface IGalleryMetadata {
export interface ILocalExtension extends IExtension {
readonly manifest: IExtensionManifest;
metadata: IGalleryMetadata;
isDefault: boolean;
publisherId: string | null;
publisherDisplayName: string | null;
readmeUrl: URI | null;
changelogUrl: URI | null;
}
@@ -204,8 +206,8 @@ export interface IExtensionManagementService {
zip(extension: ILocalExtension): Promise<URI>;
unzip(zipLocation: URI): Promise<IExtensionIdentifier>;
getManifest(vsix: URI): Promise<IExtensionManifest>;
install(vsix: URI): Promise<ILocalExtension>;
installFromGallery(extension: IGalleryExtension): Promise<ILocalExtension>;
install(vsix: URI, isDefault?: boolean): Promise<ILocalExtension>;
installFromGallery(extension: IGalleryExtension, isDefault?: boolean): Promise<ILocalExtension>;
uninstall(extension: ILocalExtension, force?: boolean): Promise<void>;
reinstallFromGallery(extension: ILocalExtension): Promise<void>;
getInstalled(type?: ExtensionType): Promise<ILocalExtension[]>;

View File

@@ -69,9 +69,9 @@ export function getLocalExtensionTelemetryData(extension: ILocalExtension): any
id: extension.identifier.id,
name: extension.manifest.name,
galleryId: null,
publisherId: extension.metadata ? extension.metadata.publisherId : null,
publisherId: extension.publisherId,
publisherName: extension.manifest.publisher,
publisherDisplayName: extension.metadata ? extension.metadata.publisherDisplayName : null,
publisherDisplayName: extension.publisherDisplayName,
dependencies: extension.manifest.extensionDependencies && extension.manifest.extensionDependencies.length > 0
};
}
@@ -116,4 +116,4 @@ export function getMaliciousExtensionsSet(report: IReportedExtension[]): Set<str
}
return result;
}
}

View 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 } from 'vs/platform/extensionManagement/node/extensionsScanner';
import { ExtensionsScanner, IMetadata } 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: IGalleryMetadata | null;
metadata?: IMetadata;
}
export class ExtensionManagementService extends Disposable implements IExtensionManagementService {
@@ -152,7 +152,7 @@ export class ExtensionManagementService extends Disposable implements IExtension
}
install(vsix: URI): Promise<ILocalExtension> {
install(vsix: URI, isDefault: boolean = false): 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.getMetadata(getGalleryExtensionId(manifest.publisher, manifest.name))
return this.getGalleryMetadata(getGalleryExtensionId(manifest.publisher, manifest.name))
.then(
metadata => this.installFromZipPath(identifierWithVersion, zipPath, metadata, operation, token),
() => this.installFromZipPath(identifierWithVersion, zipPath, null, operation, token))
metadata => this.installFromZipPath(identifierWithVersion, zipPath, { ...metadata, isDefault }, operation, token),
() => this.installFromZipPath(identifierWithVersion, zipPath, { isDefault }, 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: IGalleryMetadata | null, operation: InstallOperation, token: CancellationToken): Promise<ILocalExtension> {
private installFromZipPath(identifierWithVersion: ExtensionIdentifierWithVersion, zipPath: string, metadata: IMetadata, 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): Promise<ILocalExtension> {
async installFromGallery(extension: IGalleryExtension, isDefault?: boolean): Promise<ILocalExtension> {
if (!this.galleryService.isEnabled()) {
return Promise.reject(new Error(nls.localize('MarketPlaceDisabled', "Marketplace is not enabled")));
}
@@ -287,8 +287,11 @@ export class ExtensionManagementService extends Disposable implements IExtension
}
this.downloadInstallableExtension(extension, operation)
.then(installableExtension => this.installExtension(installableExtension, cancellationToken)
.then(local => this.extensionsDownloader.delete(URI.file(installableExtension.zipPath)).finally(() => { }).then(() => local)))
.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(local => this.installDependenciesAndPackExtensions(local, existingExtension)
.then(() => local, error => this.uninstall(local, true).then(() => Promise.reject(error), () => Promise.reject(error))))
.then(
@@ -358,7 +361,7 @@ export class ExtensionManagementService extends Disposable implements IExtension
.then(report => getMaliciousExtensionsSet(report).has(extension.identifier.id));
}
private downloadInstallableExtension(extension: IGalleryExtension, operation: InstallOperation): Promise<InstallableExtension> {
private downloadInstallableExtension(extension: IGalleryExtension, operation: InstallOperation): Promise<Required<InstallableExtension>> {
const metadata = <IGalleryMetadata>{
id: extension.identifier.uuid,
publisherId: extension.publisherId,
@@ -373,7 +376,7 @@ export class ExtensionManagementService extends Disposable implements IExtension
this.logService.info('Downloaded extension:', extension.identifier.id, zipPath);
return getManifest(zipPath)
.then(
manifest => (<InstallableExtension>{ zipPath, identifierWithVersion: new ExtensionIdentifierWithVersion(extension.identifier, manifest.version), metadata }),
manifest => (<Required<InstallableExtension>>{ zipPath, identifierWithVersion: new ExtensionIdentifierWithVersion(extension.identifier, manifest.version), metadata }),
error => Promise.reject(new ExtensionManagementError(this.joinErrors(error).message, INSTALL_ERROR_VALIDATING))
);
},
@@ -419,8 +422,7 @@ 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) {
this.setMetadata(local, metadata);
local = await this.extensionsScanner.saveMetadataForLocalExtension(local);
local = await this.extensionsScanner.saveMetadataForLocalExtension(local, metadata);
}
return local;
}
@@ -481,15 +483,14 @@ export class ExtensionManagementService extends Disposable implements IExtension
async updateMetadata(local: ILocalExtension, metadata: IGalleryMetadata): Promise<ILocalExtension> {
this.logService.trace('ExtensionManagementService#updateMetadata', local.identifier.id);
local.metadata = metadata;
local = await this.extensionsScanner.saveMetadataForLocalExtension(local);
local = await this.extensionsScanner.saveMetadataForLocalExtension(local, { ...metadata, isDefault: local.isDefault });
this.manifestCache.invalidate();
return local;
}
private getMetadata(extensionName: string): Promise<IGalleryMetadata | null> {
private getGalleryMetadata(extensionName: string): Promise<IGalleryMetadata | undefined> {
return this.findGalleryExtensionByName(extensionName)
.then(galleryExtension => galleryExtension ? <IGalleryMetadata>{ id: galleryExtension.identifier.uuid, publisherDisplayName: galleryExtension.publisherDisplayName, publisherId: galleryExtension.publisherId } : null);
.then(galleryExtension => galleryExtension ? <IGalleryMetadata>{ id: galleryExtension.identifier.uuid, publisherDisplayName: galleryExtension.publisherDisplayName, publisherId: galleryExtension.publisherId } : undefined);
}
private findGalleryExtension(local: ILocalExtension): Promise<IGalleryExtension> {
@@ -629,11 +630,6 @@ 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();
}

View File

@@ -32,6 +32,8 @@ 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;
@@ -127,14 +129,13 @@ export class ExtensionsScanner extends Disposable {
throw new Error(localize('cannot read', "Cannot read the extension from {0}", this.extensionsPath));
}
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'));
}
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'));
return local;
}
@@ -228,7 +229,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, metadata, location: URI.file(extensionPath), readmeUrl, changelogUrl };
const local = <ILocalExtension>{ type, identifier, manifest, location: URI.file(extensionPath), readmeUrl, changelogUrl, publisherDisplayName: null, publisherId: null, isDefault: false };
if (metadata) {
this.setMetadata(local, metadata);
}
@@ -256,9 +257,11 @@ export class ExtensionsScanner extends Disposable {
}
}
private setMetadata(local: ILocalExtension, metadata: IGalleryMetadata): void {
local.metadata = metadata;
private setMetadata(local: ILocalExtension, metadata: IMetadata): void {
local.publisherDisplayName = metadata.publisherDisplayName || null;
local.publisherId = metadata.publisherId || null;
local.identifier.uuid = metadata.id;
local.isDefault = metadata.isDefault;
}
private async removeUninstalledExtensions(): Promise<void> {
@@ -314,7 +317,7 @@ export class ExtensionsScanner extends Disposable {
return this._devSystemExtensionsPath;
}
private async readManifest(extensionPath: string): Promise<{ manifest: IExtensionManifest; metadata: IGalleryMetadata; }> {
private async readManifest(extensionPath: string): Promise<{ manifest: IExtensionManifest; metadata: IMetadata | null; }> {
const promises = [
pfs.readFile(path.join(extensionPath, 'package.json'), 'utf8')
.then(raw => this.parseManifest(raw)),
@@ -330,7 +333,7 @@ export class ExtensionsScanner extends Disposable {
};
}
private parseManifest(raw: string): Promise<{ manifest: IExtensionManifest; metadata: IGalleryMetadata; }> {
private parseManifest(raw: string): Promise<{ manifest: IExtensionManifest; metadata: IMetadata | null; }> {
return new Promise((c, e) => {
try {
const manifest = JSON.parse(raw);

View File

@@ -94,8 +94,8 @@ class Extension implements IExtension {
return this.gallery.publisherDisplayName || this.gallery.publisher;
}
if (this.local!.metadata && this.local!.metadata.publisherDisplayName) {
return this.local!.metadata.publisherDisplayName;
if (this.local?.publisherDisplayName) {
return this.local.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.metadata ? extension.local : await this.server.extensionManagementService.updateMetadata(extension.local, { id: compatible.identifier.uuid, publisherDisplayName: compatible.publisherDisplayName, publisherId: compatible.publisherId });
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 });
extension.local = local;
extension.gallery = compatible;
this._onChange.fire({ extension });