Skip to content

Commit 4214647

Browse files
committed
fix: use wslpath to resolve Windows paths
1 parent c68e180 commit 4214647

File tree

3 files changed

+7
-53
lines changed

3 files changed

+7
-53
lines changed

src/chrome-finder.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const {execSync, execFileSync} = require('child_process');
1212
const escapeRegExp = require('escape-string-regexp');
1313
const log = require('lighthouse-logger');
1414

15-
import {getLocalAppDataPath, ChromePathNotSetError} from './utils';
15+
import {getLocalAppDataPath, toWinDirFormat, ChromePathNotSetError} from './utils';
1616

1717
const newLineRegex = /\r?\n/;
1818

@@ -158,8 +158,8 @@ export function linux() {
158158
export function wsl() {
159159
// Manually populate the environment variables assuming it's the default config
160160
process.env.LOCALAPPDATA = getLocalAppDataPath(`${process.env.PATH}`);
161-
process.env.PROGRAMFILES = '/mnt/c/Program Files';
162-
process.env['PROGRAMFILES(X86)'] = '/mnt/c/Program Files (x86)';
161+
process.env.PROGRAMFILES = toWinDirFormat('C:/Program Files');
162+
process.env['PROGRAMFILES(X86)'] = toWinDirFormat('C:/Program Files (x86)');
163163

164164
return win32();
165165
}

src/utils.ts

+4-11
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
'use strict';
77

88
import {join} from 'path';
9-
import {execSync} from 'child_process';
9+
import {execSync, execFileSync} from 'child_process';
1010
import * as mkdirp from 'mkdirp';
1111
const isWsl = require('is-wsl');
1212

@@ -74,21 +74,14 @@ export function makeTmpDir() {
7474
}
7575

7676
export function toWinDirFormat(dir: string = ''): string {
77-
const results = /\/mnt\/([a-z])\//.exec(dir);
78-
if (!results) {
79-
return dir;
80-
}
81-
82-
const driveLetter = results[1];
83-
return dir.replace(`/mnt/${driveLetter}/`, `${driveLetter.toUpperCase()}:\\`)
84-
.replace(/\//g, '\\');
77+
return execFileSync('wslpath', [dir]).toString().trim();
8578
}
8679

8780
export function getLocalAppDataPath(path: string): string {
88-
const userRegExp = /\/mnt\/([a-z])\/Users\/([^\/:]+)\/AppData\//;
81+
const userRegExp = /\/([a-z])\/Users\/([^\/:]+)\/AppData\//;
8982
const results = userRegExp.exec(path) || [];
9083

91-
return `/mnt/${results[1]}/Users/${results[2]}/AppData/Local`;
84+
return toWinDirFormat(`${results[1]}:\\Users\\${results[2]}\\AppData\\Local`);
9285
}
9386

9487
function makeUnixTmpDir() {

test/utils-test.ts

-39
This file was deleted.

0 commit comments

Comments
 (0)