@@ -7,10 +7,49 @@ const isWsl = require('is-wsl');
7
7
const isDocker = require ( 'is-docker' ) ;
8
8
9
9
const pAccess = promisify ( fs . access ) ;
10
+ const pReadFile = promisify ( fs . readFile ) ;
10
11
11
12
// Path to included `xdg-open`.
12
13
const localXdgOpenPath = path . join ( __dirname , 'xdg-open' ) ;
13
14
15
+ /**
16
+ Get the mount point for fixed drives in WSL.
17
+
18
+ @inner
19
+ @returns {string } The mount point.
20
+ */
21
+ const getWslDrivesMountPoint = ( ( ) => {
22
+ let mountPoint ;
23
+
24
+ return async function ( ) {
25
+ if ( mountPoint ) {
26
+ // Return memoized mount point value
27
+ return mountPoint ;
28
+ }
29
+
30
+ const configFilePath = '/etc/wsl.conf' ;
31
+
32
+ let isConfigFileExists = false ;
33
+ try {
34
+ await pAccess ( configFilePath , fs . constants . F_OK ) ;
35
+ isConfigFileExists = true ;
36
+ } catch ( _ ) { }
37
+
38
+ if ( ! isConfigFileExists ) {
39
+ // Default value for "root" param
40
+ // according to https://docs.microsoft.com/en-us/windows/wsl/wsl-config
41
+ return '/mnt/' ;
42
+ }
43
+
44
+ const configContent = await pReadFile ( configFilePath , { encoding : 'utf8' } ) ;
45
+
46
+ mountPoint = ( / r o o t \s * = \s * ( .* ) / g. exec ( configContent ) [ 1 ] || '' ) . trim ( ) ;
47
+ mountPoint = mountPoint . endsWith ( '/' ) ? mountPoint : mountPoint + '/' ;
48
+
49
+ return mountPoint ;
50
+ } ;
51
+ } ) ( ) ;
52
+
14
53
module . exports = async ( target , options ) => {
15
54
if ( typeof target !== 'string' ) {
16
55
throw new TypeError ( 'Expected a `target`' ) ;
@@ -49,8 +88,10 @@ module.exports = async (target, options) => {
49
88
cliArguments . push ( '-a' , app ) ;
50
89
}
51
90
} else if ( process . platform === 'win32' || ( isWsl && ! isDocker ( ) ) ) {
91
+ const mountPoint = await getWslDrivesMountPoint ( ) ;
92
+
52
93
command = isWsl ?
53
- '/mnt/ c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe' :
94
+ ` ${ mountPoint } c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe` :
54
95
`${ process . env . SYSTEMROOT } \\System32\\WindowsPowerShell\\v1.0\\powershell` ;
55
96
56
97
cliArguments . push (
0 commit comments