Skip to content

Commit

Permalink
fix: use wslpath to resolve Windows paths
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Rath committed May 14, 2020
1 parent c68e180 commit acab753
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 53 deletions.
6 changes: 3 additions & 3 deletions src/chrome-finder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const {execSync, execFileSync} = require('child_process');
const escapeRegExp = require('escape-string-regexp');
const log = require('lighthouse-logger');

import {getLocalAppDataPath, ChromePathNotSetError} from './utils';
import {getLocalAppDataPath, toWinDirFormat, ChromePathNotSetError} from './utils';

const newLineRegex = /\r?\n/;

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

return win32();
}
Expand Down
15 changes: 4 additions & 11 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
'use strict';

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

Expand Down Expand Up @@ -74,21 +74,14 @@ export function makeTmpDir() {
}

export function toWinDirFormat(dir: string = ''): string {
const results = /\/mnt\/([a-z])\//.exec(dir);
if (!results) {
return dir;
}

const driveLetter = results[1];
return dir.replace(`/mnt/${driveLetter}/`, `${driveLetter.toUpperCase()}:\\`)
.replace(/\//g, '\\');
return execFileSync('wslpath', [dir]).toString().trim();
}

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

return `/mnt/${results[1]}/Users/${results[2]}/AppData/Local`;
return toWinDirFormat(`C:\\${results[1]}\\Users\\${results[2]}\\AppData\\Local`);
}

function makeUnixTmpDir() {
Expand Down
39 changes: 0 additions & 39 deletions test/utils-test.ts

This file was deleted.

0 comments on commit acab753

Please sign in to comment.