1
>
/*---------------------------------------------------------------------------------------------
userDataPath.ts
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);
29
const pathsToResolve = [userDataPath];