This commit is contained in:
Sam Saccone 2017-05-14 10:00:40 -07:00
Родитель 9049f86c5e
Коммит 96322ec73b
2 изменённых файлов: 20 добавлений и 16 удалений

Просмотреть файл

@ -21,7 +21,7 @@ import * as childProcess from 'child_process';
import * as fs from 'fs';
import * as chromeFinder from './chrome-finder';
import {DEFAULT_FLAGS} from './flags';
import {defaults, delay, makeUnixTmpDir, makeWin32TmpDir} from './utils';
import {makeTmpDir, defaults, delay} from './utils';
import * as net from 'net';
const rimraf = require('rimraf');
const log = require('../lighthouse-core/lib/log');
@ -30,6 +30,7 @@ const execSync = childProcess.execSync;
const isWindows = process.platform === 'win32';
const _SIGINT = 'SIGINT';
const _SIGINT_EXIT_CODE = 130;
const _SUPPORTED_PLATFORMS = new Set(['darwin', 'linux', 'win32']);
type SupportedPlatforms = 'darwin'|'linux'|'win32';
@ -101,21 +102,12 @@ class ChromeLauncher {
private prepare() {
const platform = process.platform as SupportedPlatforms;
switch (platform) {
case 'darwin':
case 'linux':
this.TMP_PROFILE_DIR = makeUnixTmpDir();
break;
case 'win32':
this.TMP_PROFILE_DIR = makeWin32TmpDir();
break;
default:
throw new Error(`Platform ${platform} is not supported`);
if (!_SUPPORTED_PLATFORMS.has(platform)) {
throw new Error(`Platform ${platform} is not supported`);
}
this.TMP_PROFILE_DIR = makeTmpDir();
this.outFile = fs.openSync(`${this.TMP_PROFILE_DIR}/chrome-out.log`, 'a');
this.errFile = fs.openSync(`${this.TMP_PROFILE_DIR}/chrome-err.log`, 'a');

Просмотреть файл

@ -29,11 +29,23 @@ export async function delay(time: number) {
return new Promise(resolve => setTimeout(resolve, time));
}
export function makeUnixTmpDir() {
export function makeTmpDir() {
switch (process.platform) {
case 'darwin':
case 'linux':
return makeUnixTmpDir();
case 'win32':
return makeWin32TmpDir();
default:
throw new Error(`Platform ${process.platform} is not supported`);
}
}
function makeUnixTmpDir() {
return execSync('mktemp -d -t lighthouse.XXXXXXX').toString().trim();
}
export function makeWin32TmpDir() {
function makeWin32TmpDir() {
const winTmpPath = process.env.TEMP || process.env.TMP ||
(process.env.SystemRoot || process.env.windir) + '\\temp';
const randomNumber = Math.floor(Math.random() * 9e7 + 1e7);