mirror of
https://github.com/coder/code-server.git
synced 2026-05-06 12:31:58 +02:00
chore(vscode): update to 1.55.2
This commit is contained in:
@@ -43,6 +43,7 @@ export interface NativeParsedArgs {
|
||||
'builtin-extensions-dir'?: string;
|
||||
extensionDevelopmentPath?: string[]; // // undefined or array of 1 or more local paths or URIs
|
||||
extensionTestsPath?: string; // either a local path or a URI
|
||||
extensionDevelopmentKind?: string[];
|
||||
'inspect-extensions'?: string;
|
||||
'inspect-brk-extensions'?: string;
|
||||
debugId?: string;
|
||||
|
||||
@@ -3,12 +3,13 @@
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { createDecorator, refineServiceDecorator } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { NativeParsedArgs } from 'vs/platform/environment/common/argv';
|
||||
import { ExtensionKind } from 'vs/platform/extensions/common/extensions';
|
||||
|
||||
export const IEnvironmentService = createDecorator<IEnvironmentService>('environmentService');
|
||||
export const INativeEnvironmentService = createDecorator<INativeEnvironmentService>('nativeEnvironmentService');
|
||||
export const INativeEnvironmentService = refineServiceDecorator<IEnvironmentService, INativeEnvironmentService>(IEnvironmentService);
|
||||
|
||||
export interface IDebugParams {
|
||||
port: number | null;
|
||||
@@ -62,6 +63,7 @@ export interface IEnvironmentService {
|
||||
isExtensionDevelopment: boolean;
|
||||
disableExtensions: boolean | string[];
|
||||
extensionDevelopmentLocationURI?: URI[];
|
||||
extensionDevelopmentKind?: ExtensionKind[];
|
||||
extensionTestsLocationURI?: URI;
|
||||
|
||||
// --- logging
|
||||
@@ -106,7 +108,7 @@ export interface INativeEnvironmentService extends IEnvironmentService {
|
||||
// --- CLI Arguments
|
||||
args: NativeParsedArgs;
|
||||
|
||||
// --- paths
|
||||
// --- data paths
|
||||
appRoot: string;
|
||||
userHome: URI;
|
||||
appSettingsHome: URI;
|
||||
@@ -115,14 +117,14 @@ export interface INativeEnvironmentService extends IEnvironmentService {
|
||||
machineSettingsResource: URI;
|
||||
installSourcePath: string;
|
||||
|
||||
// --- Extensions
|
||||
// --- extensions
|
||||
extensionsPath: string;
|
||||
extensionsDownloadPath: string;
|
||||
builtinExtensionsPath: string;
|
||||
extraExtensionPaths: string[]
|
||||
extraBuiltinExtensionPaths: string[]
|
||||
|
||||
// --- Smoke test support
|
||||
// --- smoke test support
|
||||
driverHandle?: string;
|
||||
|
||||
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
|
||||
@@ -0,0 +1,257 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { IProductService } from 'vs/platform/product/common/productService';
|
||||
import { IDebugParams, IExtensionHostDebugParams, INativeEnvironmentService } from 'vs/platform/environment/common/environment';
|
||||
import { NativeParsedArgs } from 'vs/platform/environment/common/argv';
|
||||
import { dirname, join, normalize, resolve } from 'vs/base/common/path';
|
||||
import { joinPath } from 'vs/base/common/resources';
|
||||
import { memoize } from 'vs/base/common/decorators';
|
||||
import { toLocalISOString } from 'vs/base/common/date';
|
||||
import { FileAccess } from 'vs/base/common/network';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { ExtensionKind } from 'vs/platform/extensions/common/extensions';
|
||||
import { env } from 'vs/base/common/process';
|
||||
|
||||
export interface INativeEnvironmentPaths {
|
||||
|
||||
/**
|
||||
* The user data directory to use for anything that should be
|
||||
* persisted except for the content that is meant for the `homeDir`.
|
||||
*
|
||||
* Only one instance of VSCode can use the same `userDataDir`.
|
||||
*/
|
||||
userDataDir: string
|
||||
|
||||
/**
|
||||
* The user home directory mainly used for persisting extensions
|
||||
* and global configuration that should be shared across all
|
||||
* versions.
|
||||
*/
|
||||
homeDir: string;
|
||||
|
||||
/**
|
||||
* OS tmp dir.
|
||||
*/
|
||||
tmpDir: string,
|
||||
}
|
||||
|
||||
export abstract class AbstractNativeEnvironmentService implements INativeEnvironmentService {
|
||||
|
||||
declare readonly _serviceBrand: undefined;
|
||||
|
||||
@memoize
|
||||
get appRoot(): string { return dirname(FileAccess.asFileUri('', require).fsPath); }
|
||||
|
||||
@memoize
|
||||
get userHome(): URI { return URI.file(this.paths.homeDir); }
|
||||
|
||||
@memoize
|
||||
get userDataPath(): string { return this.paths.userDataDir; }
|
||||
|
||||
@memoize
|
||||
get appSettingsHome(): URI { return URI.file(join(this.userDataPath, 'User')); }
|
||||
|
||||
@memoize
|
||||
get tmpDir(): URI { return URI.file(this.paths.tmpDir); }
|
||||
|
||||
@memoize
|
||||
get userRoamingDataHome(): URI { return this.appSettingsHome; }
|
||||
|
||||
@memoize
|
||||
get settingsResource(): URI { return joinPath(this.userRoamingDataHome, 'settings.json'); }
|
||||
|
||||
@memoize
|
||||
get userDataSyncHome(): URI { return joinPath(this.userRoamingDataHome, 'sync'); }
|
||||
|
||||
get logsPath(): string {
|
||||
if (!this.args.logsPath) {
|
||||
const key = toLocalISOString(new Date()).replace(/-|:|\.\d+Z$/g, '');
|
||||
this.args.logsPath = join(this.userDataPath, 'logs', key);
|
||||
}
|
||||
|
||||
return this.args.logsPath;
|
||||
}
|
||||
|
||||
@memoize
|
||||
get userDataSyncLogResource(): URI { return URI.file(join(this.logsPath, 'userDataSync.log')); }
|
||||
|
||||
@memoize
|
||||
get sync(): 'on' | 'off' | undefined { return this.args.sync; }
|
||||
|
||||
@memoize
|
||||
get machineSettingsResource(): URI { return joinPath(URI.file(join(this.userDataPath, 'Machine')), 'settings.json'); }
|
||||
|
||||
@memoize
|
||||
get globalStorageHome(): URI { return URI.joinPath(this.appSettingsHome, 'globalStorage'); }
|
||||
|
||||
@memoize
|
||||
get workspaceStorageHome(): URI { return URI.joinPath(this.appSettingsHome, 'workspaceStorage'); }
|
||||
|
||||
@memoize
|
||||
get keybindingsResource(): URI { return joinPath(this.userRoamingDataHome, 'keybindings.json'); }
|
||||
|
||||
@memoize
|
||||
get keyboardLayoutResource(): URI { return joinPath(this.userRoamingDataHome, 'keyboardLayout.json'); }
|
||||
|
||||
@memoize
|
||||
get argvResource(): URI {
|
||||
const vscodePortable = env['VSCODE_PORTABLE'];
|
||||
if (vscodePortable) {
|
||||
return URI.file(join(vscodePortable, 'argv.json'));
|
||||
}
|
||||
|
||||
return joinPath(this.userHome, this.productService.dataFolderName, 'argv.json');
|
||||
}
|
||||
|
||||
@memoize
|
||||
get snippetsHome(): URI { return joinPath(this.userRoamingDataHome, 'snippets'); }
|
||||
|
||||
@memoize
|
||||
get isExtensionDevelopment(): boolean { return !!this.args.extensionDevelopmentPath; }
|
||||
|
||||
@memoize
|
||||
get untitledWorkspacesHome(): URI { return URI.file(join(this.userDataPath, 'Workspaces')); }
|
||||
|
||||
@memoize
|
||||
get installSourcePath(): string { return join(this.userDataPath, 'installSource'); }
|
||||
|
||||
@memoize
|
||||
get builtinExtensionsPath(): string {
|
||||
const cliBuiltinExtensionsDir = this.args['builtin-extensions-dir'];
|
||||
if (cliBuiltinExtensionsDir) {
|
||||
return resolve(cliBuiltinExtensionsDir);
|
||||
}
|
||||
|
||||
return normalize(join(FileAccess.asFileUri('', require).fsPath, '..', 'extensions'));
|
||||
}
|
||||
|
||||
get extensionsDownloadPath(): string {
|
||||
const cliExtensionsDownloadDir = this.args['extensions-download-dir'];
|
||||
if (cliExtensionsDownloadDir) {
|
||||
return resolve(cliExtensionsDownloadDir);
|
||||
}
|
||||
|
||||
return join(this.userDataPath, 'CachedExtensionVSIXs');
|
||||
}
|
||||
|
||||
@memoize
|
||||
get extensionsPath(): string {
|
||||
const cliExtensionsDir = this.args['extensions-dir'];
|
||||
if (cliExtensionsDir) {
|
||||
return resolve(cliExtensionsDir);
|
||||
}
|
||||
|
||||
const vscodeExtensions = env['VSCODE_EXTENSIONS'];
|
||||
if (vscodeExtensions) {
|
||||
return vscodeExtensions;
|
||||
}
|
||||
|
||||
const vscodePortable = env['VSCODE_PORTABLE'];
|
||||
if (vscodePortable) {
|
||||
return join(vscodePortable, 'extensions');
|
||||
}
|
||||
|
||||
return joinPath(this.userHome, this.productService.dataFolderName, 'extensions').fsPath;
|
||||
}
|
||||
|
||||
@memoize
|
||||
get extensionDevelopmentLocationURI(): URI[] | undefined {
|
||||
const extensionDevelopmentPaths = this.args.extensionDevelopmentPath;
|
||||
if (Array.isArray(extensionDevelopmentPaths)) {
|
||||
return extensionDevelopmentPaths.map(extensionDevelopmentPath => {
|
||||
if (/^[^:/?#]+?:\/\//.test(extensionDevelopmentPath)) {
|
||||
return URI.parse(extensionDevelopmentPath);
|
||||
}
|
||||
|
||||
return URI.file(normalize(extensionDevelopmentPath));
|
||||
});
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
@memoize
|
||||
get extensionDevelopmentKind(): ExtensionKind[] | undefined {
|
||||
return this.args.extensionDevelopmentKind?.map(kind => kind === 'ui' || kind === 'workspace' || kind === 'web' ? kind : 'workspace');
|
||||
}
|
||||
|
||||
@memoize
|
||||
get extensionTestsLocationURI(): URI | undefined {
|
||||
const extensionTestsPath = this.args.extensionTestsPath;
|
||||
if (extensionTestsPath) {
|
||||
if (/^[^:/?#]+?:\/\//.test(extensionTestsPath)) {
|
||||
return URI.parse(extensionTestsPath);
|
||||
}
|
||||
|
||||
return URI.file(normalize(extensionTestsPath));
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
get disableExtensions(): boolean | string[] {
|
||||
if (this.args['disable-extensions']) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const disableExtensions = this.args['disable-extension'];
|
||||
if (disableExtensions) {
|
||||
if (typeof disableExtensions === 'string') {
|
||||
return [disableExtensions];
|
||||
}
|
||||
|
||||
if (Array.isArray(disableExtensions) && disableExtensions.length > 0) {
|
||||
return disableExtensions;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@memoize
|
||||
get debugExtensionHost(): IExtensionHostDebugParams { return parseExtensionHostPort(this.args, this.isBuilt); }
|
||||
get debugRenderer(): boolean { return !!this.args.debugRenderer; }
|
||||
|
||||
get isBuilt(): boolean { return !env['VSCODE_DEV']; }
|
||||
get verbose(): boolean { return !!this.args.verbose; }
|
||||
get logLevel(): string | undefined { return this.args.log; }
|
||||
|
||||
@memoize
|
||||
get serviceMachineIdResource(): URI { return joinPath(URI.file(this.userDataPath), 'machineid'); }
|
||||
|
||||
get crashReporterId(): string | undefined { return this.args['crash-reporter-id']; }
|
||||
get crashReporterDirectory(): string | undefined { return this.args['crash-reporter-directory']; }
|
||||
|
||||
get driverHandle(): string | undefined { return this.args['driver']; }
|
||||
|
||||
@memoize
|
||||
get telemetryLogResource(): URI { return URI.file(join(this.logsPath, 'telemetry.log')); }
|
||||
get disableTelemetry(): boolean { return !!this.args['disable-telemetry']; }
|
||||
|
||||
get args(): NativeParsedArgs { return this._args; }
|
||||
|
||||
constructor(
|
||||
private readonly _args: NativeParsedArgs,
|
||||
private readonly paths: INativeEnvironmentPaths,
|
||||
protected readonly productService: IProductService
|
||||
) { }
|
||||
}
|
||||
|
||||
export function parseExtensionHostPort(args: NativeParsedArgs, isBuild: boolean): IExtensionHostDebugParams {
|
||||
return parseDebugPort(args['inspect-extensions'], args['inspect-brk-extensions'], 5870, isBuild, args.debugId);
|
||||
}
|
||||
|
||||
export function parseSearchPort(args: NativeParsedArgs, isBuild: boolean): IDebugParams {
|
||||
return parseDebugPort(args['inspect-search'], args['inspect-brk-search'], 5876, isBuild);
|
||||
}
|
||||
|
||||
function parseDebugPort(debugArg: string | undefined, debugBrkArg: string | undefined, defaultBuildPort: number, isBuild: boolean, debugId?: string): IExtensionHostDebugParams {
|
||||
const portStr = debugBrkArg || debugArg;
|
||||
const port = Number(portStr) || (!isBuild ? defaultBuildPort : null);
|
||||
const brk = port ? Boolean(!!debugBrkArg) : false;
|
||||
|
||||
return { port, break: brk, debugId };
|
||||
}
|
||||
@@ -5,13 +5,12 @@
|
||||
|
||||
import { join } from 'vs/base/common/path';
|
||||
import { memoize } from 'vs/base/common/decorators';
|
||||
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { INativeEnvironmentService } from 'vs/platform/environment/common/environment';
|
||||
import { refineServiceDecorator } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { IEnvironmentService, INativeEnvironmentService } from 'vs/platform/environment/common/environment';
|
||||
import { NativeEnvironmentService } from 'vs/platform/environment/node/environmentService';
|
||||
import { createStaticIPCHandle } from 'vs/base/parts/ipc/node/ipc.net';
|
||||
import product from 'vs/platform/product/common/product';
|
||||
|
||||
export const IEnvironmentMainService = createDecorator<IEnvironmentMainService>('nativeEnvironmentService');
|
||||
export const IEnvironmentMainService = refineServiceDecorator<IEnvironmentService, IEnvironmentMainService>(IEnvironmentService);
|
||||
|
||||
/**
|
||||
* A subclass of the `INativeEnvironmentService` to be used only in electron-main
|
||||
@@ -51,19 +50,19 @@ export class EnvironmentMainService extends NativeEnvironmentService implements
|
||||
get backupWorkspacesPath(): string { return join(this.backupHome, 'workspaces.json'); }
|
||||
|
||||
@memoize
|
||||
get mainIPCHandle(): string { return createStaticIPCHandle(this.userDataPath, 'main', product.version); }
|
||||
get mainIPCHandle(): string { return createStaticIPCHandle(this.userDataPath, 'main', this.productService.version); }
|
||||
|
||||
@memoize
|
||||
get sandbox(): boolean { return !!this._args['__sandbox']; }
|
||||
get sandbox(): boolean { return !!this.args['__sandbox']; }
|
||||
|
||||
@memoize
|
||||
get driverVerbose(): boolean { return !!this._args['driver-verbose']; }
|
||||
get driverVerbose(): boolean { return !!this.args['driver-verbose']; }
|
||||
|
||||
@memoize
|
||||
get disableUpdates(): boolean { return !!this._args['disable-updates']; }
|
||||
get disableUpdates(): boolean { return !!this.args['disable-updates']; }
|
||||
|
||||
@memoize
|
||||
get disableKeytar(): boolean { return !!this._args['disable-keytar']; }
|
||||
get disableKeytar(): boolean { return !!this.args['disable-keytar']; }
|
||||
|
||||
@memoize
|
||||
get nodeCachedDataDir(): string | undefined { return process.env['VSCODE_NODE_CACHED_DATA_DIR'] || undefined; }
|
||||
|
||||
@@ -85,6 +85,7 @@ export const OPTIONS: OptionDescriptions<Required<NativeParsedArgs>> = {
|
||||
|
||||
'locate-extension': { type: 'string[]' },
|
||||
'extensionDevelopmentPath': { type: 'string[]' },
|
||||
'extensionDevelopmentKind': { type: 'string[]' },
|
||||
'extensionTestsPath': { type: 'string' },
|
||||
'debugId': { type: 'string' },
|
||||
'debugRenderer': { type: 'boolean' },
|
||||
@@ -263,7 +264,7 @@ export function formatOptions(options: OptionDescriptions<any>, columns: number)
|
||||
}
|
||||
|
||||
function indent(count: number): string {
|
||||
return (<any>' ').repeat(count);
|
||||
return ' '.repeat(count);
|
||||
}
|
||||
|
||||
function wrapText(text: string, columns: number): string[] {
|
||||
|
||||
@@ -4,40 +4,21 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { homedir, tmpdir } from 'os';
|
||||
import product from 'vs/platform/product/common/product';
|
||||
import { IDebugParams, IExtensionHostDebugParams, INativeEnvironmentService } from 'vs/platform/environment/common/environment';
|
||||
import { NativeParsedArgs } from 'vs/platform/environment/common/argv';
|
||||
import { getDefaultUserDataPath } from 'vs/base/node/userDataPath';
|
||||
import { dirname, join, normalize, resolve } from 'vs/base/common/path';
|
||||
import { joinPath } from 'vs/base/common/resources';
|
||||
import { memoize } from 'vs/base/common/decorators';
|
||||
import { toLocalISOString } from 'vs/base/common/date';
|
||||
import { FileAccess } from 'vs/base/common/network';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { getUserDataPath } from 'vs/platform/environment/node/userDataPath';
|
||||
import { AbstractNativeEnvironmentService } from 'vs/platform/environment/common/environmentService';
|
||||
import { IProductService } from 'vs/platform/product/common/productService';
|
||||
|
||||
export class NativeEnvironmentService implements INativeEnvironmentService {
|
||||
export class NativeEnvironmentService extends AbstractNativeEnvironmentService {
|
||||
|
||||
declare readonly _serviceBrand: undefined;
|
||||
|
||||
get args(): NativeParsedArgs { return this._args; }
|
||||
|
||||
@memoize
|
||||
get appRoot(): string { return dirname(FileAccess.asFileUri('', require).fsPath); }
|
||||
|
||||
readonly logsPath: string;
|
||||
|
||||
@memoize
|
||||
get userHome(): URI { return URI.file(homedir()); }
|
||||
|
||||
@memoize
|
||||
get userDataPath(): string {
|
||||
const vscodePortable = process.env['VSCODE_PORTABLE'];
|
||||
if (vscodePortable) {
|
||||
return join(vscodePortable, 'user-data');
|
||||
}
|
||||
|
||||
return parseUserDataDir(this._args, process);
|
||||
constructor(args: NativeParsedArgs, productService: IProductService) {
|
||||
super(args, {
|
||||
homeDir: homedir(),
|
||||
tmpDir: tmpdir(),
|
||||
userDataDir: getUserDataPath(args)
|
||||
}, productService);
|
||||
}
|
||||
<<<<<<< HEAD
|
||||
|
||||
@memoize
|
||||
get appSettingsHome(): URI { return URI.file(join(this.userDataPath, 'User')); }
|
||||
@@ -249,4 +230,6 @@ export function parsePathArg(arg: string | undefined, process: NodeJS.Process):
|
||||
|
||||
export function parseUserDataDir(args: NativeParsedArgs, process: NodeJS.Process): string {
|
||||
return parsePathArg(args['user-data-dir'], process) || resolve(getDefaultUserDataPath());
|
||||
=======
|
||||
>>>>>>> 801aed93200dc0ccf325a09089c911e8e2b612d0
|
||||
}
|
||||
|
||||
@@ -79,7 +79,9 @@ async function doResolveUnixShellEnv(logService: ILogService): Promise<typeof pr
|
||||
logService.trace('getUnixShellEnvironment#env', env);
|
||||
logService.trace('getUnixShellEnvironment#spawn', command);
|
||||
|
||||
const systemShellUnix = await getSystemShell(platform);
|
||||
const systemShellUnix = await getSystemShell(platform, env);
|
||||
logService.trace('getUnixShellEnvironment#shell', systemShellUnix);
|
||||
|
||||
const child = spawn(systemShellUnix, ['-ilc', command], {
|
||||
detached: true,
|
||||
stdio: ['ignore', 'pipe', process.stderr],
|
||||
|
||||
14
lib/vscode/src/vs/platform/environment/node/userDataPath.d.ts
vendored
Normal file
14
lib/vscode/src/vs/platform/environment/node/userDataPath.d.ts
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { NativeParsedArgs } from 'vs/platform/environment/common/argv';
|
||||
|
||||
/**
|
||||
* Returns the user data path to use with some rules:
|
||||
* - respect portable mode
|
||||
* - respect --user-data-dir CLI argument
|
||||
* - respect VSCODE_APPDATA environment variable
|
||||
*/
|
||||
export function getUserDataPath(args: NativeParsedArgs): string;
|
||||
99
lib/vscode/src/vs/platform/environment/node/userDataPath.js
Normal file
99
lib/vscode/src/vs/platform/environment/node/userDataPath.js
Normal file
@@ -0,0 +1,99 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
/// <reference path="../../../../typings/require.d.ts" />
|
||||
|
||||
//@ts-check
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* @param {typeof import('path')} path
|
||||
* @param {typeof import('os')} os
|
||||
* @param {string} productName
|
||||
*/
|
||||
function factory(path, os, productName) {
|
||||
|
||||
/**
|
||||
* @param {import('../../environment/common/argv').NativeParsedArgs} cliArgs
|
||||
*
|
||||
* @returns {string}
|
||||
*/
|
||||
function getUserDataPath(cliArgs) {
|
||||
return path.resolve(doGetUserDataPath(cliArgs));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {import('../../environment/common/argv').NativeParsedArgs} cliArgs
|
||||
*
|
||||
* @returns {string}
|
||||
*/
|
||||
function doGetUserDataPath(cliArgs) {
|
||||
|
||||
// 1. Support portable mode
|
||||
const portablePath = process.env['VSCODE_PORTABLE'];
|
||||
if (portablePath) {
|
||||
return path.join(portablePath, 'user-data');
|
||||
}
|
||||
|
||||
// 2. Support explicit --user-data-dir
|
||||
const cliPath = cliArgs['user-data-dir'];
|
||||
if (cliPath) {
|
||||
return cliPath;
|
||||
}
|
||||
|
||||
// 3. Support global VSCODE_APPDATA environment variable
|
||||
let appDataPath = process.env['VSCODE_APPDATA'];
|
||||
|
||||
// 4. Otherwise check per platform
|
||||
if (!appDataPath) {
|
||||
switch (process.platform) {
|
||||
case 'win32':
|
||||
appDataPath = process.env['APPDATA'];
|
||||
if (!appDataPath) {
|
||||
const userProfile = process.env['USERPROFILE'];
|
||||
if (typeof userProfile !== 'string') {
|
||||
throw new Error('Windows: Unexpected undefined %USERPROFILE% environment variable');
|
||||
}
|
||||
|
||||
appDataPath = path.join(userProfile, 'AppData', 'Roaming');
|
||||
}
|
||||
break;
|
||||
case 'darwin':
|
||||
appDataPath = path.join(os.homedir(), 'Library', 'Application Support');
|
||||
break;
|
||||
case 'linux':
|
||||
appDataPath = process.env['XDG_CONFIG_HOME'] || path.join(os.homedir(), '.config');
|
||||
break;
|
||||
default:
|
||||
throw new Error('Platform not supported');
|
||||
}
|
||||
}
|
||||
|
||||
return path.join(appDataPath, productName);
|
||||
}
|
||||
|
||||
return {
|
||||
getUserDataPath
|
||||
};
|
||||
}
|
||||
|
||||
if (typeof define === 'function') {
|
||||
define(['require', 'path', 'os', 'vs/base/common/network', 'vs/base/common/resources'], function (require, /** @type {typeof import('path')} */ path, /** @type {typeof import('os')} */ os, /** @type {typeof import('../../../base/common/network')} */ network, /** @type {typeof import("../../../base/common/resources")} */ resources) {
|
||||
const rootPath = resources.dirname(network.FileAccess.asFileUri('', require));
|
||||
const pkg = require.__$__nodeRequire(resources.joinPath(rootPath, 'package.json').fsPath);
|
||||
|
||||
return factory(path, os, pkg.name);
|
||||
}); // amd
|
||||
} else if (typeof module === 'object' && typeof module.exports === 'object') {
|
||||
const pkg = require('../../../../../package.json');
|
||||
const path = require('path');
|
||||
const os = require('os');
|
||||
|
||||
module.exports = factory(path, os, pkg.name); // commonjs
|
||||
} else {
|
||||
throw new Error('Unknown context');
|
||||
}
|
||||
}());
|
||||
@@ -4,9 +4,10 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as assert from 'assert';
|
||||
import * as path from 'vs/base/common/path';
|
||||
import { parseArgs, OPTIONS } from 'vs/platform/environment/node/argv';
|
||||
import { parseExtensionHostPort, parseUserDataDir } from 'vs/platform/environment/node/environmentService';
|
||||
import { parseExtensionHostPort } from 'vs/platform/environment/common/environmentService';
|
||||
import { NativeEnvironmentService } from 'vs/platform/environment/node/environmentService';
|
||||
import product from 'vs/platform/product/common/product';
|
||||
|
||||
suite('EnvironmentService', () => {
|
||||
|
||||
@@ -44,15 +45,6 @@ suite('EnvironmentService', () => {
|
||||
assert.deepStrictEqual(parse(['--inspect-extensions=1234', '--inspect-brk-extensions=5678', '--debugId=7']), { port: 5678, break: true, debugId: '7' });
|
||||
});
|
||||
|
||||
test('userDataPath', () => {
|
||||
const parse = (a: string[], b: { cwd: () => string, env: { [key: string]: string } }) => parseUserDataDir(parseArgs(a, OPTIONS), <any>b);
|
||||
|
||||
assert.equal(parse(['--user-data-dir', './dir'], { cwd: () => '/foo', env: {} }), path.resolve('/foo/dir'),
|
||||
'should use cwd when --user-data-dir is specified');
|
||||
assert.equal(parse(['--user-data-dir', './dir'], { cwd: () => '/foo', env: { 'VSCODE_CWD': '/bar' } }), path.resolve('/bar/dir'),
|
||||
'should use VSCODE_CWD as the cwd when --user-data-dir is specified');
|
||||
});
|
||||
|
||||
// https://github.com/microsoft/vscode/issues/78440
|
||||
test('careful with boolean file names', function () {
|
||||
let actual = parseArgs(['-r', 'arg.txt'], OPTIONS);
|
||||
@@ -63,4 +55,15 @@ suite('EnvironmentService', () => {
|
||||
assert(actual['reuse-window']);
|
||||
assert.deepStrictEqual(actual._, ['true.txt']);
|
||||
});
|
||||
|
||||
test('userDataDir', () => {
|
||||
const service1 = new NativeEnvironmentService(parseArgs(process.argv, OPTIONS), { _serviceBrand: undefined, ...product });
|
||||
assert.ok(service1.userDataPath.length > 0);
|
||||
|
||||
const args = parseArgs(process.argv, OPTIONS);
|
||||
args['user-data-dir'] = '/userDataDir/folder';
|
||||
|
||||
const service2 = new NativeEnvironmentService(args, { _serviceBrand: undefined, ...product });
|
||||
assert.notStrictEqual(service1.userDataPath, service2.userDataPath);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -37,9 +37,9 @@ suite('Native Modules (all platforms)', () => {
|
||||
assert.ok(typeof spdlog.createRotatingLogger === 'function', testErrorMessage('spdlog'));
|
||||
});
|
||||
|
||||
test('vscode-nsfw', async () => {
|
||||
const nsfWatcher = await import('vscode-nsfw');
|
||||
assert.ok(typeof nsfWatcher === 'function', testErrorMessage('vscode-nsfw'));
|
||||
test('nsfw', async () => {
|
||||
const nsfWatcher = await import('nsfw');
|
||||
assert.ok(typeof nsfWatcher === 'function', testErrorMessage('nsfw'));
|
||||
});
|
||||
|
||||
test('vscode-sqlite3', async () => {
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as assert from 'assert';
|
||||
import { OPTIONS, parseArgs } from 'vs/platform/environment/node/argv';
|
||||
import { getUserDataPath } from 'vs/platform/environment/node/userDataPath';
|
||||
|
||||
suite('User data path', () => {
|
||||
|
||||
test('getUserDataPath - default', () => {
|
||||
const path = getUserDataPath(parseArgs(process.argv, OPTIONS));
|
||||
assert.ok(path.length > 0);
|
||||
});
|
||||
|
||||
test('getUserDataPath - portable mode', () => {
|
||||
const origPortable = process.env['VSCODE_PORTABLE'];
|
||||
try {
|
||||
const portableDir = 'portable-dir';
|
||||
process.env['VSCODE_PORTABLE'] = portableDir;
|
||||
|
||||
const path = getUserDataPath(parseArgs(process.argv, OPTIONS));
|
||||
assert.ok(path.includes(portableDir));
|
||||
} finally {
|
||||
if (typeof origPortable === 'string') {
|
||||
process.env['VSCODE_PORTABLE'] = origPortable;
|
||||
} else {
|
||||
delete process.env['VSCODE_PORTABLE'];
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test('getUserDataPath - --user-data-dir', () => {
|
||||
const cliUserDataDir = 'cli-data-dir';
|
||||
const args = parseArgs(process.argv, OPTIONS);
|
||||
args['user-data-dir'] = cliUserDataDir;
|
||||
|
||||
const path = getUserDataPath(args);
|
||||
assert.ok(path.includes(cliUserDataDir));
|
||||
});
|
||||
|
||||
test('getUserDataPath - VSCODE_APPDATA', () => {
|
||||
const origAppData = process.env['VSCODE_APPDATA'];
|
||||
try {
|
||||
const appDataDir = 'appdata-dir';
|
||||
process.env['VSCODE_APPDATA'] = appDataDir;
|
||||
|
||||
const path = getUserDataPath(parseArgs(process.argv, OPTIONS));
|
||||
assert.ok(path.includes(appDataDir));
|
||||
} finally {
|
||||
if (typeof origAppData === 'string') {
|
||||
process.env['VSCODE_APPDATA'] = origAppData;
|
||||
} else {
|
||||
delete process.env['VSCODE_APPDATA'];
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user