src/vs/platform/environment/node/userDataPath.ts
106 LOC · 91 covered · 15 uncovered · 18 ranges · 14 concepts · 9 introducers · 8 tests
File neighbourhood
The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.
Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file
In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the related-file, concept, and source links on this page.
Graph controls are ready.
Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.
/*---------------------------------------------------------------------------------------------
argv.ts ×7
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { homedir } from 'os';
import { NativeParsedArgs } from '../common/argv.js';
// This file used to be a pure JS file and was always
// importing `path` from node.js even though we ship
// our own version of the library and prefer to use
// that.
// However, resolution of user-data-path is critical
// and while our version of `path` is a copy of node.js
// one, you never know. As such, preserve the use of
// the built-in `path` lib for the time being.
// eslint-disable-next-line local/code-import-patterns
import { resolve, isAbsolute, join } from 'path';
const cwd = process.env['VSCODE_CWD'] || process.cwd();
/**
* Returns the user data path to use with some rules:
* - respect portable mode
* - respect VSCODE_APPDATA environment variable
* - respect --user-data-dir CLI argument
*/
export function getUserDataPath(cliArgs: NativeParsedArgs, productName: string): string {
const pathsToResolve = [userDataPath];
// If the user-data-path is not absolute, make
// sure to resolve it against the passed in
// current working directory. We cannot use the
// node.js `path.resolve()` logic because it will
// not pick up our `VSCODE_CWD` environment variable
// (https://github.com/microsoft/vscode/issues/120269)
if (!isAbsolute(userDataPath)) {
}
return resolve(...pathsToResolve);
}
function doGetUserDataPath(cliArgs: NativeParsedArgs, productName: string): string {
userDataPath.ts ×4
// 0. Running out of sources has a fixed productName
if (process.env['VSCODE_DEV']) {
productName = 'code-oss-dev';
}
// 1. Support portable mode
const portablePath = process.env['VSCODE_PORTABLE'];
if (portablePath) {
}
// 2. Support global VSCODE_APPDATA environment variable
const appDataPath = process.env['VSCODE_APPDATA'];
if (appDataPath) {
}
// With Electron>=13 --user-data-dir switch will be propagated to
// all processes https://github.com/electron/electron/blob/1897b14af36a02e9aa7e4d814159303441548251/shell/browser/electron_browser_client.cc#L546-L553
// Check VSCODE_PORTABLE and VSCODE_APPDATA before this case to get correct values.
// 3. Support explicit --user-data-dir
const cliPath = cliArgs['user-data-dir'];
if (cliPath) {
}
return getDefaultUserDataPath(productName);
}
/**
* Returns the default user data path for a given product name using
* the platform-specific application data directory.
*/
export function getDefaultUserDataPath(productName: string): string {
// 4. Otherwise check per platform
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 = join(userProfile, 'AppData', 'Roaming');
}
break;
appDataPath = join(homedir(), 'Library', 'Application Support');
break;
appDataPath = process.env['XDG_CONFIG_HOME'] || join(homedir(), '.config');
break;
default:
throw new Error('Platform not supported');
return join(appDataPath, productName);
}