Skip to content

Commit

Permalink
Warn about installing chromium on WSL (#4596)
Browse files Browse the repository at this point in the history
* Warn about chromium installation limitation when using `quarto install tools chromium`
* refactor into simpler statement
* changelog
  • Loading branch information
cderv authored Mar 3, 2023
1 parent f4f4d9e commit 0430df6
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 39 deletions.
1 change: 1 addition & 0 deletions news/changelog-1.3.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@
- Use "iso" date form instead of "short" to format citations properly ([#4586](https://github.com/quarto-dev/quarto-cli/issues/4586)).
- Fix typo `thumnail-image` -> `thumbnail-image` in listing template ([#4602](//github.com/quarto-dev/quarto-cli/pull/4602)) (Thank you, @mattspence!).
- Add support for targeting the `#refs` divs with citations when using `natbib` or `biblatex` to generate a bibliography.
- Warn users about Chromium installation issues in WSL ([#4596](https://github.com/quarto-dev/quarto-cli/issues/4586)).

## Pandoc filter changes

Expand Down
4 changes: 4 additions & 0 deletions src/core/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ export function isWindows() {
return Deno.build.os === "windows";
}

export function isWSL() {
return !!Deno.env.get("WSL_DISTRO_NAME");
}

export function isMac() {
return Deno.build.os === "darwin";
}
Expand Down
97 changes: 58 additions & 39 deletions src/tools/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*
*/

import { info } from "log/mod.ts";
import { info, warning } from "log/mod.ts";
import { withSpinner } from "../core/console.ts";
import { logError } from "../core/log.ts";

Expand All @@ -20,6 +20,7 @@ import { tinyTexInstallable } from "./impl/tinytex.ts";
import { chromiumInstallable } from "./impl/chromium.ts";
import { downloadWithProgress } from "../core/download.ts";
import { Confirm } from "cliffy/prompt/mod.ts";
import { isWSL } from "../core/platform.ts";

// The tools that are available to install
const kInstallableTools: { [key: string]: InstallableTool } = {
Expand Down Expand Up @@ -83,59 +84,77 @@ export async function printToolInfo(name: string) {
}
}

export function checkToolRequirement(name: string) {
if (name.toLowerCase() === "chromium" && isWSL()) {
// TODO: Change to a quarto-web url page ?
const troubleshootUrl =
"https://pptr.dev/next/troubleshooting#running-puppeteer-on-wsl-windows-subsystem-for-linux.";
warning([
`${name} can't be installed fully on WSL with Quarto as system requirements could be missing.`,
`- Please do a manual installation following recommandations at ${troubleshootUrl}`,
"- See https://github.com/quarto-dev/quarto-cli/issues/1822 for more context.",
].join("\n"));
return false;
} else {
return true;
}
}

export async function installTool(name: string, updatePath?: boolean) {
name = name || "";
// Run the install
const installableTool = kInstallableTools[name.toLowerCase()];
if (installableTool) {
// Create a working directory for the installer to use
const workingDir = Deno.makeTempDirSync();
try {
// The context for the installers
const context = installContext(workingDir, updatePath);
if (checkToolRequirement(name)) {
// Create a working directory for the installer to use
const workingDir = Deno.makeTempDirSync();
try {
// The context for the installers
const context = installContext(workingDir, updatePath);

context.info(`Installing ${name}`);
context.info(`Installing ${name}`);

// See if it is already installed
const alreadyInstalled = await installableTool.installed();
if (alreadyInstalled) {
// Already installed, do nothing
context.error(`Install canceled - ${name} is already installed.`);
return Promise.reject();
} else {
// Prereqs for this platform
const platformPrereqs = installableTool.prereqs.filter((prereq) =>
prereq.os.includes(Deno.build.os)
);
// See if it is already installed
const alreadyInstalled = await installableTool.installed();
if (alreadyInstalled) {
// Already installed, do nothing
context.error(`Install canceled - ${name} is already installed.`);
return Promise.reject();
} else {
// Prereqs for this platform
const platformPrereqs = installableTool.prereqs.filter((prereq) =>
prereq.os.includes(Deno.build.os)
);

// Check to see whether any prerequisites are satisfied
for (const prereq of platformPrereqs) {
const met = await prereq.check(context);
if (!met) {
context.error(prereq.message);
return Promise.reject();
// Check to see whether any prerequisites are satisfied
for (const prereq of platformPrereqs) {
const met = await prereq.check(context);
if (!met) {
context.error(prereq.message);
return Promise.reject();
}
}
}

// Fetch the package information
const pkgInfo = await installableTool.preparePackage(context);
// Fetch the package information
const pkgInfo = await installableTool.preparePackage(context);

// Do the install
await installableTool.install(pkgInfo, context);
// Do the install
await installableTool.install(pkgInfo, context);

// post install
const restartRequired = await installableTool.afterInstall(context);
// post install
const restartRequired = await installableTool.afterInstall(context);

context.info("Installation successful");
if (restartRequired) {
context.info(
"To complete this installation, please restart your system.",
);
context.info("Installation successful");
if (restartRequired) {
context.info(
"To complete this installation, please restart your system.",
);
}
}
} finally {
// Cleanup the working directory
Deno.removeSync(workingDir, { recursive: true });
}
} finally {
// Cleanup the working directory
Deno.removeSync(workingDir, { recursive: true });
}
} else {
// No tool found
Expand Down

0 comments on commit 0430df6

Please sign in to comment.