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.

Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the filesrc/vs/platform/environment/node/argv.ts · 536 LOCnode/argv.tsenvironmentService.ts ×1 · 7 introduced LOCenvironmentService.ts ×1environmentService.ts ×2 · 4 introduced LOCenvironmentService.ts ×2environmentService.ts ×3 · 12 introduced LOCenvironmentService.ts ×3environmentService.ts ×4 · 22 introduced LOCenvironmentService.ts ×4userDataPath.ts ×5 · 17 introduced LOCuserDataPath.ts ×5userDataPath.test|title=User data path getUserDataPath - --user-data-dir|occurrence=1 · 0 introduced LOCuserDataPath.test|title=…userDataPath.ts ×1 · 2 introduced LOCuserDataPath.ts ×1userDataPath.ts ×1 · 2 introduced LOCuserDataPath.ts ×1userDataPath.ts ×1 · 2 introduced LOCuserDataPath.ts ×1userDataPath.ts ×1 · 7 introduced LOCuserDataPath.ts ×1userDataPath.ts ×1 · 4 introduced LOCuserDataPath.ts ×1userDataPath.ts ×1 · 2 introduced LOCuserDataPath.ts ×1userDataPath.ts ×4 · 21 introduced LOCuserDataPath.ts ×4argv.ts ×7 · 54 introduced LOCargv.ts ×7environmentService.test|title=EnvironmentService careful with boolean file names|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/environment/test/node/environmentService.test|title=EnvironmentService careful with boolean file names|occurrence=1environmentService.test|…environmentService.test|title=EnvironmentService parseExtensionHostPort when built|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/environment/test/node/environmentService.test|title=EnvironmentService parseExtensionHostPort when built|occurrence=1environmentService.test|…environmentService.test|title=EnvironmentService parseExtensionHostPort when unbuilt|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/environment/test/node/environmentService.test|title=EnvironmentService parseExtensionHostPort when unbuilt|occurrence=1environmentService.test|…environmentService.test|title=EnvironmentService userDataDir|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/environment/test/node/environmentService.test|title=EnvironmentService userDataDir|occurrence=1environmentService.test|…userDataPath.test|title=User data path getUserDataPath - --user-data-dir|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/environment/test/node/userDataPath.test|title=User data path getUserDataPath - --user-data-dir|occurrence=1userDataPath.test|title=…userDataPath.test|title=User data path getUserDataPath - VSCODE_APPDATA|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/environment/test/node/userDataPath.test|title=User data path getUserDataPath - VSCODE_APPDATA|occurrence=1userDataPath.test|title=…userDataPath.test|title=User data path getUserDataPath - default|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/environment/test/node/userDataPath.test|title=User data path getUserDataPath - default|occurrence=1userDataPath.test|title=…userDataPath.test|title=User data path getUserDataPath - portable mode|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/environment/test/node/userDataPath.test|title=User data path getUserDataPath - portable mode|occurrence=1userDataPath.test|title=…Focused file · src/vs/platform/environment/node/userDataPath.ts · 106 LOCnode/userDataPath.ts

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.

1 > /*--------------------------------------------------------------------------------------------- argv.ts ×7
2 > * Copyright (c) Microsoft Corporation. All rights reserved.
3 > * Licensed under the MIT License. See License.txt in the project root for license information.
4 > *--------------------------------------------------------------------------------------------*/
5 >
6 > import { homedir } from 'os';
7 > import { NativeParsedArgs } from '../common/argv.js';
8 > // This file used to be a pure JS file and was always
9 > // importing `path` from node.js even though we ship
10 > // our own version of the library and prefer to use
11 > // that.
12 > // However, resolution of user-data-path is critical
13 > // and while our version of `path` is a copy of node.js
14 > // one, you never know. As such, preserve the use of
15 > // the built-in `path` lib for the time being.
16 > // eslint-disable-next-line local/code-import-patterns
17 > import { resolve, isAbsolute, join } from 'path';
18 >
19 > const cwd = process.env['VSCODE_CWD'] || process.cwd();
20 >
21 > /**
22 > * Returns the user data path to use with some rules:
23 > * - respect portable mode
24 > * - respect VSCODE_APPDATA environment variable
25 > * - respect --user-data-dir CLI argument
26 > */
27 > export function getUserDataPath(cliArgs: NativeParsedArgs, productName: string): string {
28 > const userDataPath = doGetUserDataPath(cliArgs, productName); userDataPath.ts ×4
29 > const pathsToResolve = [userDataPath];
30 >
31 > // If the user-data-path is not absolute, make
32 > // sure to resolve it against the passed in
33 > // current working directory. We cannot use the
34 > // node.js `path.resolve()` logic because it will
35 > // not pick up our `VSCODE_CWD` environment variable
36 > // (https://github.com/microsoft/vscode/issues/120269)
37 > if (!isAbsolute(userDataPath)) {
38 > pathsToResolve.unshift(cwd); userDataPath.ts ×1
39 > }
41 > return resolve(...pathsToResolve);
42 > }
44 > function doGetUserDataPath(cliArgs: NativeParsedArgs, productName: string): string { userDataPath.ts ×4
45 >
46 > // 0. Running out of sources has a fixed productName
47 > if (process.env['VSCODE_DEV']) {
48 productName = 'code-oss-dev';
49 }
51 > // 1. Support portable mode
52 > const portablePath = process.env['VSCODE_PORTABLE'];
53 > if (portablePath) {
54 > return join(portablePath, 'user-data'); userDataPath.ts ×1
55 > }
57 > // 2. Support global VSCODE_APPDATA environment variable
58 > const appDataPath = process.env['VSCODE_APPDATA'];
59 > if (appDataPath) {
60 > return join(appDataPath, productName); userDataPath.ts ×1
61 > }
63 > // With Electron>=13 --user-data-dir switch will be propagated to
64 > // all processes https://github.com/electron/electron/blob/1897b14af36a02e9aa7e4d814159303441548251/shell/browser/electron_browser_client.cc#L546-L553
65 > // Check VSCODE_PORTABLE and VSCODE_APPDATA before this case to get correct values.
66 > // 3. Support explicit --user-data-dir
67 > const cliPath = cliArgs['user-data-dir'];
68 > if (cliPath) {
69 > return cliPath; userDataPath.ts ×1
70 > }
72 > return getDefaultUserDataPath(productName);
73 > }
75 > /**
76 > * Returns the default user data path for a given product name using
77 > * the platform-specific application data directory.
78 > */
79 > export function getDefaultUserDataPath(productName: string): string {
80 > let appDataPath: string | undefined; userDataPath.ts ×5
81 >
82 > // 4. Otherwise check per platform
83 > switch (process.platform) {
84 > case 'win32':
85 appDataPath = process.env['APPDATA'];
86 if (!appDataPath) {
87 const userProfile = process.env['USERPROFILE'];
88 if (typeof userProfile !== 'string') {
89 throw new Error('Windows: Unexpected undefined %USERPROFILE% environment variable');
90 }
91
92 appDataPath = join(userProfile, 'AppData', 'Roaming');
93 }
94 break;
95 > case 'darwin': userDataPath.ts ×5
96 appDataPath = join(homedir(), 'Library', 'Application Support');
97 break;
98 > case 'linux': userDataPath.ts ×5
99 > appDataPath = process.env['XDG_CONFIG_HOME'] || join(homedir(), '.config');
100 > break;
101 > default:
102 throw new Error('Platform not supported');
104 >
105 > return join(appDataPath, productName);
106 > }