wangzhibo
2026-05-09 53418655c061ac26f66058253f39200aced1ab1d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import process from 'node:process';
import fs, {constants as fsConstants} from 'node:fs/promises';
import isWsl from 'is-wsl';
 
export const wslDrivesMountPoint = (() => {
    // Default value for "root" param
    // according to https://docs.microsoft.com/en-us/windows/wsl/wsl-config
    const defaultMountPoint = '/mnt/';
 
    let mountPoint;
 
    return async function () {
        if (mountPoint) {
            // Return memoized mount point value
            return mountPoint;
        }
 
        const configFilePath = '/etc/wsl.conf';
 
        let isConfigFileExists = false;
        try {
            await fs.access(configFilePath, fsConstants.F_OK);
            isConfigFileExists = true;
        } catch {}
 
        if (!isConfigFileExists) {
            return defaultMountPoint;
        }
 
        const configContent = await fs.readFile(configFilePath, {encoding: 'utf8'});
        const configMountPoint = /(?<!#.*)root\s*=\s*(?<mountPoint>.*)/g.exec(configContent);
 
        if (!configMountPoint) {
            return defaultMountPoint;
        }
 
        mountPoint = configMountPoint.groups.mountPoint.trim();
        mountPoint = mountPoint.endsWith('/') ? mountPoint : `${mountPoint}/`;
 
        return mountPoint;
    };
})();
 
export const powerShellPathFromWsl = async () => {
    const mountPoint = await wslDrivesMountPoint();
    return `${mountPoint}c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe`;
};
 
export const powerShellPath = async () => {
    if (isWsl) {
        return powerShellPathFromWsl();
    }
 
    return `${process.env.SYSTEMROOT || process.env.windir || String.raw`C:\Windows`}\\System32\\WindowsPowerShell\\v1.0\\powershell.exe`;
};
 
export {default as isWsl} from 'is-wsl';