diff --git a/src/vs/code/node/cliProcessMain.ts b/src/vs/code/node/cliProcessMain.ts index 0320f835502..4d661e13e9e 100644 --- a/src/vs/code/node/cliProcessMain.ts +++ b/src/vs/code/node/cliProcessMain.ts @@ -274,7 +274,7 @@ class CliMain extends Disposable { // Install Extension else if (this.argv['install-extension'] || this.argv['install-builtin-extension']) { const installOptions: InstallOptions = { isMachineScoped: !!this.argv['do-not-sync'], installPreReleaseVersion: !!this.argv['pre-release'], profileLocation }; - return instantiationService.createInstance(ExtensionManagementCLI).installExtensions(this.asExtensionIdOrVSIX(this.argv['install-extension'] || []), this.argv['install-builtin-extension'] || [], installOptions, !!this.argv['force']); + return instantiationService.createInstance(ExtensionManagementCLI).installExtensions(this.asExtensionIdOrVSIX(this.argv['install-extension'] || []), this.asExtensionIdOrVSIX(this.argv['install-builtin-extension'] || []), installOptions, !!this.argv['force']); } // Uninstall Extension diff --git a/src/vs/platform/extensionManagement/common/extensionManagementCLI.ts b/src/vs/platform/extensionManagement/common/extensionManagementCLI.ts index da71203302f..50a1e56405e 100644 --- a/src/vs/platform/extensionManagement/common/extensionManagementCLI.ts +++ b/src/vs/platform/extensionManagement/common/extensionManagementCLI.ts @@ -27,9 +27,9 @@ function getId(manifest: IExtensionManifest, withVersion?: boolean): string { } } +type InstallVSIXInfo = { vsix: URI; installOptions: InstallOptions }; type InstallExtensionInfo = { id: string; version?: string; installOptions: InstallOptions }; - export class ExtensionManagementCLI { constructor( @@ -77,7 +77,7 @@ export class ExtensionManagementCLI { } } - public async installExtensions(extensions: (string | URI)[], builtinExtensionIds: string[], installOptions: InstallOptions, force: boolean, output: CLIOutput = console): Promise { + public async installExtensions(extensions: (string | URI)[], builtinExtensions: (string | URI)[], installOptions: InstallOptions, force: boolean, output: CLIOutput = console): Promise { const failed: string[] = []; const installedExtensionsManifests: IExtensionManifest[] = []; if (extensions.length) { @@ -102,11 +102,11 @@ export class ExtensionManagementCLI { const addInstallExtensionInfo = (id: string, version: string | undefined, isBuiltin: boolean) => { installExtensionInfos.push({ id, version: version !== 'prerelease' ? version : undefined, installOptions: { ...installOptions, isBuiltin, installPreReleaseVersion: version === 'prerelease' || installOptions.installPreReleaseVersion } }); }; - const vsixs: URI[] = []; + const installVSIXInfos: InstallVSIXInfo[] = []; const installExtensionInfos: InstallExtensionInfo[] = []; for (const extension of extensions) { if (extension instanceof URI) { - vsixs.push(extension); + installVSIXInfos.push({ vsix: extension, installOptions }); } else { const [id, version] = getIdAndVersion(extension); if (checkIfNotInstalled(id, version)) { @@ -114,17 +114,21 @@ export class ExtensionManagementCLI { } } } - for (const extension of builtinExtensionIds) { - const [id, version] = getIdAndVersion(extension); - if (checkIfNotInstalled(id, version)) { - addInstallExtensionInfo(id, version, true); + for (const extension of builtinExtensions) { + if (extension instanceof URI) { + installVSIXInfos.push({ vsix: extension, installOptions: { ...installOptions, isBuiltin: true, donotIncludePackAndDependencies: false } }); + } else { + const [id, version] = getIdAndVersion(extension); + if (checkIfNotInstalled(id, version)) { + addInstallExtensionInfo(id, version, true); + } } } - if (vsixs.length) { - await Promise.all(vsixs.map(async vsix => { + if (installVSIXInfos.length) { + await Promise.all(installVSIXInfos.map(async ({ vsix, installOptions }) => { try { - const manifest = await this.installVSIX(vsix, { ...installOptions, isBuiltin: false }, force, output); + const manifest = await this.installVSIX(vsix, installOptions, force, output); if (manifest) { installedExtensionsManifests.push(manifest); } diff --git a/src/vs/platform/extensionManagement/node/extensionManagementService.ts b/src/vs/platform/extensionManagement/node/extensionManagementService.ts index 0a3a830fcf4..79c9cf30a7b 100644 --- a/src/vs/platform/extensionManagement/node/extensionManagementService.ts +++ b/src/vs/platform/extensionManagement/node/extensionManagementService.ts @@ -886,16 +886,23 @@ class InstallVSIXTask extends InstallExtensionTask { super({ id: getGalleryExtensionId(manifest.publisher, manifest.name) }, location, options, extensionsScanner, uriIdentityService, userDataProfilesService, extensionsScannerService, extensionsProfileScannerService, logService); } + protected override async doRun(token: CancellationToken): Promise { + const local = await super.doRun(token); + this.updateMetadata(local, token); + return local; + } + protected async install(token: CancellationToken): Promise<[ILocalExtension, Metadata]> { const extensionKey = new ExtensionKey(this.identifier, this.manifest.version); const installedExtensions = await this.extensionsScanner.scanExtensions(ExtensionType.User, this.options.profileLocation); const existing = installedExtensions.find(i => areSameExtensions(this.identifier, i.identifier)); - const metadata = await this.getMetadata(this.identifier.id, this.manifest.version, token); - metadata.isApplicationScoped = isApplicationScopedExtension(this.manifest); - metadata.isMachineScoped = this.options.isMachineScoped || existing?.isMachineScoped; - metadata.isBuiltin = this.options.isBuiltin || existing?.isBuiltin; - metadata.installedTimestamp = Date.now(); - metadata.pinned = this.options.installGivenVersion ? true : undefined; + const metadata: Metadata = { + isApplicationScoped: isApplicationScopedExtension(this.manifest), + isMachineScoped: this.options.isMachineScoped || existing?.isMachineScoped, + isBuiltin: this.options.isBuiltin || existing?.isBuiltin, + installedTimestamp: Date.now(), + pinned: this.options.installGivenVersion ? true : undefined, + }; if (existing) { this._operation = InstallOperation.Update; @@ -925,25 +932,25 @@ class InstallVSIXTask extends InstallExtensionTask { return [local, metadata]; } - private async getMetadata(id: string, version: string, token: CancellationToken): Promise { + private async updateMetadata(extension: ILocalExtension, token: CancellationToken): Promise { try { - let [galleryExtension] = await this.galleryService.getExtensions([{ id, version }], token); + let [galleryExtension] = await this.galleryService.getExtensions([{ id: extension.identifier.id, version: extension.manifest.version }], token); if (!galleryExtension) { - [galleryExtension] = await this.galleryService.getExtensions([{ id }], token); + [galleryExtension] = await this.galleryService.getExtensions([{ id: extension.identifier.id }], token); } if (galleryExtension) { - return { + const metadata = { id: galleryExtension.identifier.uuid, publisherDisplayName: galleryExtension.publisherDisplayName, publisherId: galleryExtension.publisherId, isPreReleaseVersion: galleryExtension.properties.isPreReleaseVersion, preRelease: galleryExtension.properties.isPreReleaseVersion || this.options.installPreReleaseVersion }; + await this.extensionsScanner.updateMetadata(extension, metadata, this.options.profileLocation); } } catch (error) { /* Ignore Error */ } - return {}; } } diff --git a/src/vs/server/node/remoteExtensionHostAgentCli.ts b/src/vs/server/node/remoteExtensionHostAgentCli.ts index 2ea8b96116a..e48c18cd28e 100644 --- a/src/vs/server/node/remoteExtensionHostAgentCli.ts +++ b/src/vs/server/node/remoteExtensionHostAgentCli.ts @@ -139,7 +139,7 @@ class CliMain extends Disposable { // Install Extension else if (this.args['install-extension'] || this.args['install-builtin-extension']) { const installOptions: InstallOptions = { isMachineScoped: !!this.args['do-not-sync'], installPreReleaseVersion: !!this.args['pre-release'] }; - return extensionManagementCLI.installExtensions(this.asExtensionIdOrVSIX(this.args['install-extension'] || []), this.args['install-builtin-extension'] || [], installOptions, !!this.args['force']); + return extensionManagementCLI.installExtensions(this.asExtensionIdOrVSIX(this.args['install-extension'] || []), this.asExtensionIdOrVSIX(this.args['install-builtin-extension'] || []), installOptions, !!this.args['force']); } // Uninstall Extension diff --git a/src/vs/server/node/remoteExtensionsScanner.ts b/src/vs/server/node/remoteExtensionsScanner.ts index d11da3a2d6d..e4f42ce2c57 100644 --- a/src/vs/server/node/remoteExtensionsScanner.ts +++ b/src/vs/server/node/remoteExtensionsScanner.ts @@ -39,10 +39,11 @@ export class RemoteExtensionsScannerService implements IRemoteExtensionsScannerS private readonly _extensionGalleryService: IExtensionGalleryService, private readonly _languagePackService: ILanguagePackService ) { - if (environmentService.args['install-builtin-extension']) { + const builtinExtensionsToInstall = environmentService.args['install-builtin-extension']; + if (builtinExtensionsToInstall) { const installOptions: InstallOptions = { isMachineScoped: !!environmentService.args['do-not-sync'], installPreReleaseVersion: !!environmentService.args['pre-release'] }; performance.mark('code/server/willInstallBuiltinExtensions'); - this._whenExtensionsReady = _extensionManagementCLI.installExtensions([], environmentService.args['install-builtin-extension'], installOptions, !!environmentService.args['force']) + this._whenExtensionsReady = _extensionManagementCLI.installExtensions([], this._asExtensionIdOrVSIX(builtinExtensionsToInstall), installOptions, !!environmentService.args['force']) .then(() => performance.mark('code/server/didInstallBuiltinExtensions'), error => { _logService.error(error); }); @@ -52,15 +53,18 @@ export class RemoteExtensionsScannerService implements IRemoteExtensionsScannerS const extensionsToInstall = environmentService.args['install-extension']; if (extensionsToInstall) { - const idsOrVSIX = extensionsToInstall.map(input => /\.vsix$/i.test(input) ? URI.file(isAbsolute(input) ? input : join(cwd(), input)) : input); this._whenExtensionsReady - .then(() => _extensionManagementCLI.installExtensions(idsOrVSIX, [], { isMachineScoped: !!environmentService.args['do-not-sync'], installPreReleaseVersion: !!environmentService.args['pre-release'] }, !!environmentService.args['force'])) + .then(() => _extensionManagementCLI.installExtensions(this._asExtensionIdOrVSIX(extensionsToInstall), [], { isMachineScoped: !!environmentService.args['do-not-sync'], installPreReleaseVersion: !!environmentService.args['pre-release'] }, !!environmentService.args['force'])) .then(null, error => { _logService.error(error); }); } } + private _asExtensionIdOrVSIX(inputs: string[]): (string | URI)[] { + return inputs.map(input => /\.vsix$/i.test(input) ? URI.file(isAbsolute(input) ? input : join(cwd(), input)) : input); + } + whenExtensionsReady(): Promise { return this._whenExtensionsReady; }