Merge from vscode bead496a613e475819f89f08e9e882b841bc1fe8 (#14883)

* Merge from vscode bead496a613e475819f89f08e9e882b841bc1fe8

* Bump distro

* Upgrade GCC to 4.9 due to yarn install errors

* Update build image

* Fix bootstrap base url

* Bump distro

* Fix build errors

* Update source map file

* Disable checkbox for blocking migration issues (#15131)

* disable checkbox for blocking issues

* wip

* disable checkbox fixes

* fix strings

* Remove duplicate tsec command

* Default to off for tab color if settings not present

* re-skip failing tests

* Fix mocha error

* Bump sqlite version & fix notebooks search view

* Turn off esbuild warnings

* Update esbuild log level

* Fix overflowactionbar tests

* Fix ts-ignore in dropdown tests

* cleanup/fixes

* Fix hygiene

* Bundle in entire zone.js module

* Remove extra constructor param

* bump distro for web compile break

* bump distro for web compile break v2

* Undo log level change

* New distro

* Fix integration test scripts

* remove the "no yarn.lock changes" workflow

* fix scripts v2

* Update unit test scripts

* Ensure ads-kerberos2 updates in .vscodeignore

* Try fix unit tests

* Upload crash reports

* remove nogpu

* always upload crashes

* Use bash script

* Consolidate data/ext dir names

* Create in tmp directory

Co-authored-by: chlafreniere <hichise@gmail.com>
Co-authored-by: Christopher Suh <chsuh@microsoft.com>
Co-authored-by: chgagnon <chgagnon@microsoft.com>
This commit is contained in:
Karl Burtram
2021-04-27 14:01:59 -07:00
committed by GitHub
parent 7e1c0076ba
commit 867a963882
1817 changed files with 81812 additions and 50843 deletions

View File

@@ -3,15 +3,15 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as os from 'os';
import * as fs from 'fs';
import { homedir } from 'os';
import { constants, existsSync, statSync, unlinkSync, chmodSync, truncateSync, readFileSync } from 'fs';
import { spawn, ChildProcess, SpawnOptions } from 'child_process';
import { buildHelpMessage, buildVersionMessage, OPTIONS } from 'vs/platform/environment/node/argv';
import { NativeParsedArgs } from 'vs/platform/environment/common/argv';
import { parseCLIProcessArgv, addArg } from 'vs/platform/environment/node/argvHelper';
import { createWaitMarkerFile } from 'vs/platform/environment/node/waitMarkerFile';
import product from 'vs/platform/product/common/product';
import * as paths from 'vs/base/common/path';
import { isAbsolute, join } from 'vs/base/common/path';
import { whenDeleted, writeFileSync } from 'vs/base/node/pfs';
import { findFreePort, randomPort } from 'vs/base/node/ports';
import { isWindows, isLinux } from 'vs/base/common/platform';
@@ -69,10 +69,10 @@ export async function main(argv: string[]): Promise<any> {
// Validate
if (
!source || !target || source === target || // make sure source and target are provided and are not the same
!paths.isAbsolute(source) || !paths.isAbsolute(target) || // make sure both source and target are absolute paths
!fs.existsSync(source) || !fs.statSync(source).isFile() || // make sure source exists as file
!fs.existsSync(target) || !fs.statSync(target).isFile() // make sure target exists as file
!source || !target || source === target || // make sure source and target are provided and are not the same
!isAbsolute(source) || !isAbsolute(target) || // make sure both source and target are absolute paths
!existsSync(source) || !statSync(source).isFile() || // make sure source exists as file
!existsSync(target) || !statSync(target).isFile() // make sure target exists as file
) {
throw new Error('Using --file-write with invalid arguments.');
}
@@ -83,15 +83,15 @@ export async function main(argv: string[]): Promise<any> {
let targetMode: number = 0;
let restoreMode = false;
if (!!args['file-chmod']) {
targetMode = fs.statSync(target).mode;
if (!(targetMode & 128) /* readonly */) {
fs.chmodSync(target, targetMode | 128);
targetMode = statSync(target).mode;
if (!(targetMode & constants.S_IWUSR)) {
chmodSync(target, targetMode | constants.S_IWUSR);
restoreMode = true;
}
}
// Write source to target
const data = fs.readFileSync(source);
const data = readFileSync(source);
if (isWindows) {
// On Windows we use a different strategy of saving the file
// by first truncating the file and then writing with r+ mode.
@@ -99,7 +99,7 @@ export async function main(argv: string[]): Promise<any> {
// (see https://github.com/microsoft/vscode/issues/931) and
// prevent removing alternate data streams
// (see https://github.com/microsoft/vscode/issues/6363)
fs.truncateSync(target, 0);
truncateSync(target, 0);
writeFileSync(target, data, { flag: 'r+' });
} else {
writeFileSync(target, data);
@@ -107,7 +107,7 @@ export async function main(argv: string[]): Promise<any> {
// Restore previous mode as needed
if (restoreMode) {
fs.chmodSync(target, targetMode);
chmodSync(target, targetMode);
}
} catch (error) {
error.message = `Error using --file-write: ${error.message}`;
@@ -215,7 +215,7 @@ export async function main(argv: string[]): Promise<any> {
throw new Error('Failed to find free ports for profiler. Make sure to shutdown all instances of the editor first.');
}
const filenamePrefix = paths.join(os.homedir(), 'prof-' + Math.random().toString(16).slice(-4));
const filenamePrefix = join(homedir(), 'prof-' + Math.random().toString(16).slice(-4));
addArg(argv, `--inspect-brk=${portMain}`);
addArg(argv, `--remote-debugging-port=${portRenderer}`);
@@ -338,7 +338,7 @@ export async function main(argv: string[]): Promise<any> {
// Make sure to delete the tmp stdin file if we have any
if (stdinFilePath) {
fs.unlinkSync(stdinFilePath);
unlinkSync(stdinFilePath);
}
});
}

View File

@@ -3,11 +3,12 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { localize } from 'vs/nls';
import { release } from 'os';
import * as fs from 'fs';
import { gracefulify } from 'graceful-fs';
import { isAbsolute, join } from 'vs/base/common/path';
import { raceTimeout } from 'vs/base/common/async';
import * as semver from 'vs/base/common/semver/semver';
import product from 'vs/platform/product/common/product';
import * as path from 'vs/base/common/path';
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
@@ -15,416 +16,148 @@ import { InstantiationService } from 'vs/platform/instantiation/common/instantia
import { IEnvironmentService, INativeEnvironmentService } from 'vs/platform/environment/common/environment';
import { NativeParsedArgs } from 'vs/platform/environment/common/argv';
import { NativeEnvironmentService } from 'vs/platform/environment/node/environmentService';
import { IExtensionManagementService, IExtensionGalleryService, IGalleryExtension, ILocalExtension, InstallOptions } from 'vs/platform/extensionManagement/common/extensionManagement';
import { IExtensionManagementService, IExtensionGalleryService, IExtensionManagementCLIService } from 'vs/platform/extensionManagement/common/extensionManagement';
import { ExtensionManagementService } from 'vs/platform/extensionManagement/node/extensionManagementService';
import { ExtensionGalleryService } from 'vs/platform/extensionManagement/common/extensionGalleryService';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { combinedAppender, NullTelemetryService } from 'vs/platform/telemetry/common/telemetryUtils';
import { TelemetryService, ITelemetryServiceConfig } from 'vs/platform/telemetry/common/telemetryService';
import { resolveCommonProperties } from 'vs/platform/telemetry/node/commonProperties';
import { resolveCommonProperties } from 'vs/platform/telemetry/common/commonProperties';
import { IRequestService } from 'vs/platform/request/common/request';
import { RequestService } from 'vs/platform/request/node/requestService';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { ConfigurationService } from 'vs/platform/configuration/common/configurationService';
import { AppInsightsAppender } from 'vs/platform/telemetry/node/appInsightsAppender';
import { mkdirp, writeFile } from 'vs/base/node/pfs';
import { getBaseLabel } from 'vs/base/common/labels';
import { IStateService } from 'vs/platform/state/node/state';
import { StateService } from 'vs/platform/state/node/stateService';
import { ILogService, getLogLevel, LogLevel, ConsoleLogService, MultiplexLogService } from 'vs/platform/log/common/log';
import { isPromiseCanceledError } from 'vs/base/common/errors';
import { areSameExtensions, adoptToGalleryExtensionId, getGalleryExtensionId } from 'vs/platform/extensionManagement/common/extensionManagementUtil';
import { URI } from 'vs/base/common/uri';
import { getManifest } from 'vs/platform/extensionManagement/node/extensionManagementUtil';
import { IExtensionManifest, ExtensionType, isLanguagePackExtension, EXTENSION_CATEGORIES } from 'vs/platform/extensions/common/extensions';
import { CancellationToken } from 'vs/base/common/cancellation';
import { LocalizationsService } from 'vs/platform/localizations/node/localizations';
import { Schemas } from 'vs/base/common/network';
import { SpdLogService } from 'vs/platform/log/node/spdlogService';
import { buildTelemetryMessage } from 'vs/platform/telemetry/node/telemetry';
import { FileService } from 'vs/platform/files/common/fileService';
import { IFileService } from 'vs/platform/files/common/files';
import { DiskFileSystemProvider } from 'vs/platform/files/node/diskFileSystemProvider';
import { DisposableStore } from 'vs/base/common/lifecycle';
import { Disposable } from 'vs/base/common/lifecycle';
import { IProductService } from 'vs/platform/product/common/productService';
import { ExtensionManagementCLIService } from 'vs/platform/extensionManagement/common/extensionManagementCLIService';
import { URI } from 'vs/base/common/uri';
import { LocalizationsService } from 'vs/platform/localizations/node/localizations';
import { ILocalizationsService } from 'vs/platform/localizations/common/localizations';
import { setUnexpectedErrorHandler } from 'vs/base/common/errors';
import { toErrorMessage } from 'vs/base/common/errorMessage';
import { VSBuffer } from 'vs/base/common/buffer';
const notFound = (id: string) => localize('notFound', "Extension '{0}' not found.", id);
const notInstalled = (id: string) => localize('notInstalled', "Extension '{0}' is not installed.", id);
const useId = localize('useId', "Make sure you use the full extension ID, including the publisher, e.g.: {0}", 'ms-dotnettools.csharp');
function getId(manifest: IExtensionManifest, withVersion?: boolean): string {
if (withVersion) {
return `${manifest.publisher}.${manifest.name}@${manifest.version}`;
} else {
return `${manifest.publisher}.${manifest.name}`;
}
}
const EXTENSION_ID_REGEX = /^([^.]+\..+)@(\d+\.\d+\.\d+(-.*)?)$/;
export function getIdAndVersion(id: string): [string, string | undefined] {
const matches = EXTENSION_ID_REGEX.exec(id);
if (matches && matches[1]) {
return [adoptToGalleryExtensionId(matches[1]), matches[2]];
}
return [adoptToGalleryExtensionId(id), undefined];
}
type InstallExtensionInfo = { id: string, version?: string, installOptions: InstallOptions };
export class Main {
class CliMain extends Disposable {
constructor(
@IInstantiationService private readonly instantiationService: IInstantiationService,
@INativeEnvironmentService private readonly environmentService: INativeEnvironmentService,
@IExtensionManagementService private readonly extensionManagementService: IExtensionManagementService,
@IExtensionGalleryService private readonly extensionGalleryService: IExtensionGalleryService,
) { }
private argv: NativeParsedArgs
) {
super();
async run(argv: NativeParsedArgs): Promise<void> {
if (argv['install-source']) {
await this.setInstallSource(argv['install-source']);
} else if (argv['list-extensions']) {
await this.listExtensions(!!argv['show-versions'], argv['category']);
} else if (argv['install-extension'] || argv['install-builtin-extension']) {
await this.installExtensions(argv['install-extension'] || [], argv['install-builtin-extension'] || [], !!argv['do-not-sync'], !!argv['force']);
} else if (argv['uninstall-extension']) {
await this.uninstallExtension(argv['uninstall-extension'], !!argv['force']);
} else if (argv['locate-extension']) {
await this.locateExtension(argv['locate-extension']);
} else if (argv['telemetry']) {
console.log(buildTelemetryMessage(this.environmentService.appRoot, this.environmentService.extensionsPath));
}
// Enable gracefulFs
gracefulify(fs);
this.registerListeners();
}
private setInstallSource(installSource: string): Promise<void> {
return writeFile(this.environmentService.installSourcePath, installSource.slice(0, 30));
private registerListeners(): void {
// Dispose on exit
process.once('exit', () => this.dispose());
}
private async listExtensions(showVersions: boolean, category?: string): Promise<void> {
let extensions = await this.extensionManagementService.getInstalled(ExtensionType.User);
const categories = EXTENSION_CATEGORIES.map(c => c.toLowerCase());
if (category && category !== '') {
if (categories.indexOf(category.toLowerCase()) < 0) {
console.log('Invalid category please enter a valid category. To list valid categories run --category without a category specified');
return;
}
extensions = extensions.filter(e => {
if (e.manifest.categories) {
const lowerCaseCategories: string[] = e.manifest.categories.map(c => c.toLowerCase());
return lowerCaseCategories.indexOf(category.toLowerCase()) > -1;
}
return false;
});
} else if (category === '') {
console.log('Possible Categories: ');
categories.forEach(category => {
console.log(category);
});
return;
}
extensions.forEach(e => console.log(getId(e.manifest, showVersions)));
}
async run(): Promise<void> {
async installExtensions(extensions: string[], builtinExtensionIds: string[], isMachineScoped: boolean, force: boolean): Promise<void> {
const failed: string[] = [];
const installedExtensionsManifests: IExtensionManifest[] = [];
if (extensions.length) {
console.log(localize('installingExtensions', "Installing extensions..."));
}
// Services
const [instantiationService, appenders] = await this.initServices();
const installed = await this.extensionManagementService.getInstalled(ExtensionType.User);
const checkIfNotInstalled = (id: string, version?: string): boolean => {
const installedExtension = installed.find(i => areSameExtensions(i.identifier, { id }));
if (installedExtension) {
if (!version && !force) {
console.log(localize('alreadyInstalled-checkAndUpdate', "Extension '{0}' v{1} is already installed. Use '--force' option to update to latest version or provide '@<version>' to install a specific version, for example: '{2}@1.2.3'.", id, installedExtension.manifest.version, id));
return false;
}
if (version && installedExtension.manifest.version === version) {
console.log(localize('alreadyInstalled', "Extension '{0}' is already installed.", `${id}@${version}`));
return false;
}
}
return true;
};
const vsixs: string[] = [];
const installExtensionInfos: InstallExtensionInfo[] = [];
for (const extension of extensions) {
if (/\.vsix$/i.test(extension)) {
vsixs.push(extension);
} else {
const [id, version] = getIdAndVersion(extension);
if (checkIfNotInstalled(id, version)) {
installExtensionInfos.push({ id, version, installOptions: { isBuiltin: false, isMachineScoped } });
}
}
}
for (const extension of builtinExtensionIds) {
const [id, version] = getIdAndVersion(extension);
if (checkIfNotInstalled(id, version)) {
installExtensionInfos.push({ id, version, installOptions: { isBuiltin: true, isMachineScoped: false } });
}
}
return instantiationService.invokeFunction(async accessor => {
const logService = accessor.get(ILogService);
const fileService = accessor.get(IFileService);
const environmentService = accessor.get(INativeEnvironmentService);
const extensionManagementCLIService = accessor.get(IExtensionManagementCLIService);
if (vsixs.length) {
await Promise.all(vsixs.map(async vsix => {
try {
const manifest = await this.installVSIX(vsix, force);
if (manifest) {
installedExtensionsManifests.push(manifest);
}
} catch (err) {
console.error(err.message || err.stack || err);
failed.push(vsix);
}
}));
}
// Log info
logService.info('CLI main', this.argv);
if (installExtensionInfos.length) {
// Error handler
this.registerErrorHandler(logService);
const galleryExtensions = await this.getGalleryExtensions(installExtensionInfos);
// Run based on argv
await this.doRun(environmentService, extensionManagementCLIService, fileService);
await Promise.all(installExtensionInfos.map(async extensionInfo => {
const gallery = galleryExtensions.get(extensionInfo.id.toLowerCase());
if (gallery) {
try {
const manifest = await this.installFromGallery(extensionInfo, gallery, installed, force);
if (manifest) {
installedExtensionsManifests.push(manifest);
}
} catch (err) {
console.error(err.message || err.stack || err);
failed.push(extensionInfo.id);
}
} else {
console.error(`${notFound(extensionInfo.version ? `${extensionInfo.id}@${extensionInfo.version}` : extensionInfo.id)}\n${useId}`);
failed.push(extensionInfo.id);
}
}));
}
if (installedExtensionsManifests.some(manifest => isLanguagePackExtension(manifest))) {
await this.updateLocalizationsCache();
}
if (failed.length) {
throw new Error(localize('installation failed', "Failed Installing Extensions: {0}", failed.join(', ')));
}
}
private async installVSIX(vsix: string, force: boolean): Promise<IExtensionManifest | null> {
vsix = path.isAbsolute(vsix) ? vsix : path.join(process.cwd(), vsix);
const manifest = await getManifest(vsix);
const valid = await this.validate(manifest, force);
if (valid) {
try {
await this.extensionManagementService.install(URI.file(vsix));
console.log(localize('successVsixInstall', "Extension '{0}' was successfully installed.", getBaseLabel(vsix)));
return manifest;
} catch (error) {
if (isPromiseCanceledError(error)) {
console.log(localize('cancelVsixInstall', "Cancelled installing extension '{0}'.", getBaseLabel(vsix)));
return null;
} else {
throw error;
}
}
}
return null;
}
private async getGalleryExtensions(extensions: InstallExtensionInfo[]): Promise<Map<string, IGalleryExtension>> {
const extensionIds = extensions.filter(({ version }) => version === undefined).map(({ id }) => id);
const extensionsWithIdAndVersion = extensions.filter(({ version }) => version !== undefined);
const galleryExtensions = new Map<string, IGalleryExtension>();
await Promise.all([
(async () => {
const result = await this.extensionGalleryService.getExtensions(extensionIds, CancellationToken.None);
result.forEach(extension => galleryExtensions.set(extension.identifier.id.toLowerCase(), extension));
})(),
Promise.all(extensionsWithIdAndVersion.map(async ({ id, version }) => {
const extension = await this.extensionGalleryService.getCompatibleExtension({ id }, version);
if (extension) {
galleryExtensions.set(extension.identifier.id.toLowerCase(), extension);
}
}))
]);
return galleryExtensions;
}
private async installFromGallery({ id, version, installOptions }: InstallExtensionInfo, galleryExtension: IGalleryExtension, installed: ILocalExtension[], force: boolean): Promise<IExtensionManifest | null> {
const manifest = await this.extensionGalleryService.getManifest(galleryExtension, CancellationToken.None);
const installedExtension = installed.find(e => areSameExtensions(e.identifier, galleryExtension.identifier));
if (installedExtension) {
if (galleryExtension.version === installedExtension.manifest.version) {
console.log(localize('alreadyInstalled', "Extension '{0}' is already installed.", version ? `${id}@${version}` : id));
return null;
}
console.log(localize('updateMessage', "Updating the extension '{0}' to the version {1}", id, galleryExtension.version));
}
try {
if (installOptions.isBuiltin) {
console.log(localize('installing builtin ', "Installing builtin extension '{0}' v{1}...", id, galleryExtension.version));
} else {
console.log(localize('installing', "Installing extension '{0}' v{1}...", id, galleryExtension.version));
}
await this.extensionManagementService.installFromGallery(galleryExtension, installOptions);
console.log(localize('successInstall', "Extension '{0}' v{1} was successfully installed.", id, galleryExtension.version));
return manifest;
} catch (error) {
if (isPromiseCanceledError(error)) {
console.log(localize('cancelInstall', "Cancelled installing extension '{0}'.", id));
return null;
} else {
throw error;
}
}
}
private async validate(manifest: IExtensionManifest, force: boolean): Promise<boolean> {
if (!manifest) {
throw new Error('Invalid vsix');
}
const extensionIdentifier = { id: getGalleryExtensionId(manifest.publisher, manifest.name) };
const installedExtensions = await this.extensionManagementService.getInstalled(ExtensionType.User);
const newer = installedExtensions.find(local => areSameExtensions(extensionIdentifier, local.identifier) && semver.gt(local.manifest.version, manifest.version));
if (newer && !force) {
console.log(localize('forceDowngrade', "A newer version of extension '{0}' v{1} is already installed. Use '--force' option to downgrade to older version.", newer.identifier.id, newer.manifest.version, manifest.version));
return false;
}
return true;
}
private async uninstallExtension(extensions: string[], force: boolean): Promise<void> {
async function getExtensionId(extensionDescription: string): Promise<string> {
if (!/\.vsix$/i.test(extensionDescription)) {
return extensionDescription;
}
const zipPath = path.isAbsolute(extensionDescription) ? extensionDescription : path.join(process.cwd(), extensionDescription);
const manifest = await getManifest(zipPath);
return getId(manifest);
}
const uninstalledExtensions: ILocalExtension[] = [];
for (const extension of extensions) {
const id = await getExtensionId(extension);
const installed = await this.extensionManagementService.getInstalled();
const extensionToUninstall = installed.find(e => areSameExtensions(e.identifier, { id }));
if (!extensionToUninstall) {
throw new Error(`${notInstalled(id)}\n${useId}`);
}
if (extensionToUninstall.type === ExtensionType.System) {
console.log(localize('builtin', "Extension '{0}' is a Built-in extension and cannot be installed", id));
return;
}
if (extensionToUninstall.isBuiltin && !force) {
console.log(localize('forceUninstall', "Extension '{0}' is marked as a Built-in extension by user. Please use '--force' option to uninstall it.", id));
return;
}
console.log(localize('uninstalling', "Uninstalling {0}...", id));
await this.extensionManagementService.uninstall(extensionToUninstall);
uninstalledExtensions.push(extensionToUninstall);
console.log(localize('successUninstall', "Extension '{0}' was successfully uninstalled!", id));
}
if (uninstalledExtensions.some(e => isLanguagePackExtension(e.manifest))) {
await this.updateLocalizationsCache();
}
}
private async locateExtension(extensions: string[]): Promise<void> {
const installed = await this.extensionManagementService.getInstalled();
extensions.forEach(e => {
installed.forEach(i => {
if (i.identifier.id === e) {
if (i.location.scheme === Schemas.file) {
console.log(i.location.fsPath);
return;
}
}
});
// Flush the remaining data in AI adapter (with 1s timeout)
return raceTimeout(combinedAppender(...appenders).flush(), 1000);
});
}
private async updateLocalizationsCache(): Promise<void> {
const localizationService = this.instantiationService.createInstance(LocalizationsService);
await localizationService.update();
localizationService.dispose();
}
}
private async initServices(): Promise<[IInstantiationService, AppInsightsAppender[]]> {
const services = new ServiceCollection();
const eventPrefix = 'adsworkbench'; // {{SQL CARBON EDIT}}
// Environment
const environmentService = new NativeEnvironmentService(this.argv);
services.set(IEnvironmentService, environmentService);
services.set(INativeEnvironmentService, environmentService);
export async function main(argv: NativeParsedArgs): Promise<void> {
const services = new ServiceCollection();
const disposables = new DisposableStore();
// Init folders
await Promise.all([environmentService.appSettingsHome.fsPath, environmentService.extensionsPath].map(path => path ? fs.promises.mkdir(path, { recursive: true }) : undefined));
const environmentService = new NativeEnvironmentService(argv);
const logLevel = getLogLevel(environmentService);
const loggers: ILogService[] = [];
loggers.push(new SpdLogService('cli', environmentService.logsPath, logLevel));
if (logLevel === LogLevel.Trace) {
loggers.push(new ConsoleLogService(logLevel));
}
const logService = new MultiplexLogService(loggers);
process.once('exit', () => logService.dispose());
logService.info('main', argv);
// Log
const logLevel = getLogLevel(environmentService);
const loggers: ILogService[] = [];
loggers.push(new SpdLogService('cli', environmentService.logsPath, logLevel));
if (logLevel === LogLevel.Trace) {
loggers.push(new ConsoleLogService(logLevel));
}
await Promise.all<void | undefined>([environmentService.appSettingsHome.fsPath, environmentService.extensionsPath]
.map((path): undefined | Promise<void> => path ? mkdirp(path) : undefined));
const logService = this._register(new MultiplexLogService(loggers));
services.set(ILogService, logService);
// Files
const fileService = new FileService(logService);
disposables.add(fileService);
services.set(IFileService, fileService);
// Files
const fileService = this._register(new FileService(logService));
services.set(IFileService, fileService);
const diskFileSystemProvider = new DiskFileSystemProvider(logService);
disposables.add(diskFileSystemProvider);
fileService.registerProvider(Schemas.file, diskFileSystemProvider);
const diskFileSystemProvider = this._register(new DiskFileSystemProvider(logService));
fileService.registerProvider(Schemas.file, diskFileSystemProvider);
const configurationService = new ConfigurationService(environmentService.settingsResource, fileService);
disposables.add(configurationService);
await configurationService.initialize();
// Configuration
const configurationService = this._register(new ConfigurationService(environmentService.settingsResource, fileService));
services.set(IConfigurationService, configurationService);
services.set(IEnvironmentService, environmentService);
services.set(INativeEnvironmentService, environmentService);
// Init config
await configurationService.initialize();
services.set(ILogService, logService);
services.set(IConfigurationService, configurationService);
services.set(IStateService, new SyncDescriptor(StateService));
services.set(IProductService, { _serviceBrand: undefined, ...product });
// State
const stateService = new StateService(environmentService, logService);
services.set(IStateService, stateService);
const instantiationService: IInstantiationService = new InstantiationService(services);
return instantiationService.invokeFunction(async accessor => {
const stateService = accessor.get(IStateService);
// Product
services.set(IProductService, { _serviceBrand: undefined, ...product });
const { appRoot, extensionsPath, extensionDevelopmentLocationURI, isBuilt, installSourcePath } = environmentService;
const services = new ServiceCollection();
// Request
services.set(IRequestService, new SyncDescriptor(RequestService));
// Extensions
services.set(IExtensionManagementService, new SyncDescriptor(ExtensionManagementService));
services.set(IExtensionGalleryService, new SyncDescriptor(ExtensionGalleryService));
services.set(IExtensionManagementCLIService, new SyncDescriptor(ExtensionManagementCLIService));
// Localizations
services.set(ILocalizationsService, new SyncDescriptor(LocalizationsService));
// Telemetry
const appenders: AppInsightsAppender[] = [];
if (isBuilt && !extensionDevelopmentLocationURI && !environmentService.disableTelemetry && product.enableTelemetry) {
if (product.aiConfig && product.aiConfig.asimovKey) {
appenders.push(new AppInsightsAppender(eventPrefix, null, product.aiConfig.asimovKey));
appenders.push(new AppInsightsAppender('monacoworkbench', null, product.aiConfig.asimovKey));
}
const config: ITelemetryServiceConfig = {
appender: combinedAppender(...appenders),
sendErrorTelemetry: false,
commonProperties: resolveCommonProperties(product.commit, product.version, stateService.getItem('telemetry.machineId'), product.msftInternalDomains, installSourcePath),
commonProperties: resolveCommonProperties(fileService, release(), process.arch, product.commit, product.version, stateService.getItem('telemetry.machineId'), product.msftInternalDomains, installSourcePath),
piiPaths: [appRoot, extensionsPath]
};
@@ -434,17 +167,70 @@ export async function main(argv: NativeParsedArgs): Promise<void> {
services.set(ITelemetryService, NullTelemetryService);
}
const instantiationService2 = instantiationService.createChild(services);
const main = instantiationService2.createInstance(Main);
return [new InstantiationService(services), appenders];
}
try {
await main.run(argv);
private registerErrorHandler(logService: ILogService): void {
// Flush the remaining data in AI adapter.
// If it does not complete in 1 second, exit the process.
await raceTimeout(combinedAppender(...appenders).flush(), 1000);
} finally {
disposables.dispose();
// Install handler for unexpected errors
setUnexpectedErrorHandler(error => {
const message = toErrorMessage(error, true);
if (!message) {
return;
}
logService.error(`[uncaught exception in CLI]: ${message}`);
});
}
private async doRun(environmentService: INativeEnvironmentService, extensionManagementCLIService: IExtensionManagementCLIService, fileService: IFileService): Promise<void> {
// Install Source
if (this.argv['install-source']) {
return this.setInstallSource(environmentService, fileService, this.argv['install-source']);
}
});
// List Extensions
if (this.argv['list-extensions']) {
return extensionManagementCLIService.listExtensions(!!this.argv['show-versions'], this.argv['category']);
}
// Install Extension
else if (this.argv['install-extension'] || this.argv['install-builtin-extension']) {
return extensionManagementCLIService.installExtensions(this.asExtensionIdOrVSIX(this.argv['install-extension'] || []), this.argv['install-builtin-extension'] || [], !!this.argv['do-not-sync'], !!this.argv['force']);
}
// Uninstall Extension
else if (this.argv['uninstall-extension']) {
return extensionManagementCLIService.uninstallExtensions(this.asExtensionIdOrVSIX(this.argv['uninstall-extension']), !!this.argv['force']);
}
// Locate Extension
else if (this.argv['locate-extension']) {
return extensionManagementCLIService.locateExtension(this.argv['locate-extension']);
}
// Telemetry
else if (this.argv['telemetry']) {
console.log(buildTelemetryMessage(environmentService.appRoot, environmentService.extensionsPath));
}
}
private asExtensionIdOrVSIX(inputs: string[]): (string | URI)[] {
return inputs.map(input => /\.vsix$/i.test(input) ? URI.file(isAbsolute(input) ? input : join(process.cwd(), input)) : input);
}
private async setInstallSource(environmentService: INativeEnvironmentService, fileService: IFileService, installSource: string): Promise<void> {
await fileService.writeFile(URI.file(environmentService.installSourcePath), VSBuffer.fromString(installSource.slice(0, 30)));
}
}
export async function main(argv: NativeParsedArgs): Promise<void> {
const cliMain = new CliMain(argv);
try {
await cliMain.run();
} finally {
cliMain.dispose();
}
}

View File

@@ -5,11 +5,12 @@
import { spawn } from 'child_process';
import { generateUuid } from 'vs/base/common/uuid';
import { isWindows } from 'vs/base/common/platform';
import { isWindows, platform } from 'vs/base/common/platform';
import { ILogService } from 'vs/platform/log/common/log';
import { NativeParsedArgs } from 'vs/platform/environment/common/argv';
import { isLaunchedFromCli } from 'vs/platform/environment/node/argvHelper';
import { toErrorMessage } from 'vs/base/common/errorMessage';
import { getSystemShell } from 'vs/base/node/shell';
/**
* We need to get the environment from a user's shell.
@@ -58,7 +59,7 @@ export async function resolveShellEnv(logService: ILogService, args: NativeParse
let unixShellEnvPromise: Promise<typeof process.env> | undefined = undefined;
async function doResolveUnixShellEnv(logService: ILogService): Promise<typeof process.env> {
const promise = new Promise<typeof process.env>((resolve, reject) => {
const promise = new Promise<typeof process.env>(async (resolve, reject) => {
const runAsNode = process.env['ELECTRON_RUN_AS_NODE'];
logService.trace('getUnixShellEnvironment#runAsNode', runAsNode);
@@ -78,7 +79,8 @@ async function doResolveUnixShellEnv(logService: ILogService): Promise<typeof pr
logService.trace('getUnixShellEnvironment#env', env);
logService.trace('getUnixShellEnvironment#spawn', command);
const child = spawn(process.env.SHELL!, ['-ilc', command], {
const systemShellUnix = await getSystemShell(platform);
const child = spawn(systemShellUnix, ['-ilc', command], {
detached: true,
stdio: ['ignore', 'pipe', process.stderr],
env