Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
for (const folder of desktopInstallationFolders) {
const executable = findChromeExecutable(folder, executables);
if (executable) {
return executable;
}
}
// 2. Look for executables by using the which command
for (const executable of executables) {
try {
const chromePath =
execFileSync('which', [executable], { stdio: 'pipe' }).toString()
.split(newLineRegex)[0];
if (chromePath && isFile(chromePath)) {
return chromePath;
}
} catch (e) {
// Not installed.
}
}
return '';
};
public static getFilenameForDirectory = (directory: string): string | null => {
for (let i = 0, len = CONFIG_FILES.length; i < len; i++) {
const filename: string = path.join(directory, CONFIG_FILES[i]);
if (isFile(filename)) {
return filename;
}
}
const homedir = os.homedir();
// If we reach this point we've tested in the original directory and homedir
if (directory === homedir) {
return null;
}
return Configuration.getFilenameForDirectory(homedir);
};
}
/* istanbul ignore if */
if (!suffixes) {
throw new Error(ERRORS.NotSupportedBrowser`${browser}`);
}
const prefixes = [
getVariable('LOCALAPPDATA'),
getVariable('PROGRAMFILES'),
getVariable('PROGRAMFILES(X86)')
].filter(Boolean);
for (const suffix of suffixes) {
for (const prefix of prefixes) {
const browserPath = path.join(prefix!, suffix);
if (isFile(browserPath)) {
return browserPath;
}
}
}
return '';
};
return new Promise(async (resolve, reject) => {
const isF = isFile(targetString);
/* istanbul ignore next */
const target = isF ? targetString : '.';
const ignored = await this.getGitIgnore();
this.watcher = chokidar.watch(target, {
/* istanbul ignore next */
cwd: !isF ? targetString : undefined,
ignored: ignored.concat(['.git/']),
ignoreInitial: true,
/*
* If you are using vscode and create and remove a folder
* from the editor, an EPERM error is thrown.
* This option avoid that error.
*/
ignorePermissionErrors: true
});
* See https://github.com/GoogleChrome/chrome-launcher/issues/46 for more context.
*/
try {
execPaths = execSync(`grep -ER "${chromeExecRegex}" ${folder} | awk -F '=' '{print $2}'`);
} catch (e) {
execPaths = execSync(`grep -Er "${chromeExecRegex}" ${folder} | awk -F '=' '{print $2}'`);
}
execPaths = execPaths.toString()
.split(newLineRegex)
.map((execPath: string) => {
return execPath.replace(argumentsRegex, '$1');
});
for (const execPath of execPaths) {
if (isFile(execPath)) {
return execPath;
}
}
}
}
return '';
};
.split(newLineRegex);
/**
* Because `suffixes` are already prioritized, we iterate them first to make
* sure that priorization is respected
*/
for (const suffix of suffixes) {
for (const inst of lines) {
const execPath = path.join(inst.trim(), suffix);
/**
* An example of valid path for Chrome would be:
* `/Applications/Google Chrome.app/Contents/MacOS/Google Chrome`
*/
if (isFile(execPath)) {
return execPath;
}
}
}
return '';
};
public static getUserConfig(filePath?: string): UserConfig | null {
const isDirectory = !isFile(filePath);
const configPath = isDirectory ? Configuration.getFilenameForDirectory(filePath || cwd()) : filePath;
if (!configPath) {
return null;
}
try {
const resolvedPath = path.resolve(isDirectory ? (filePath || cwd()) : cwd(), configPath);
return Configuration.loadConfigFile(resolvedPath);
} catch {
return null;
}
}
const resolveChromiumPath = () => {
const chromiumPaths = [
getVariable('WEBHINT_CHROMIUM_PATH'),
getVariable('CHROME_PATH')
];
while (chromiumPaths.length > 0) {
const browserPath = chromiumPaths.shift()!;
if (isFile(browserPath)) {
return browserPath;
}
}
return '';
};