Skip to content

Commit 0430df6

Browse files
authored
Warn about installing chromium on WSL (#4596)
* Warn about chromium installation limitation when using `quarto install tools chromium` * refactor into simpler statement * changelog
1 parent f4f4d9e commit 0430df6

File tree

3 files changed

+63
-39
lines changed

3 files changed

+63
-39
lines changed

news/changelog-1.3.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@
192192
- Use "iso" date form instead of "short" to format citations properly ([#4586](https://github.com/quarto-dev/quarto-cli/issues/4586)).
193193
- Fix typo `thumnail-image` -> `thumbnail-image` in listing template ([#4602](//github.com/quarto-dev/quarto-cli/pull/4602)) (Thank you, @mattspence!).
194194
- Add support for targeting the `#refs` divs with citations when using `natbib` or `biblatex` to generate a bibliography.
195+
- Warn users about Chromium installation issues in WSL ([#4596](https://github.com/quarto-dev/quarto-cli/issues/4586)).
195196

196197
## Pandoc filter changes
197198

src/core/platform.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ export function isWindows() {
1313
return Deno.build.os === "windows";
1414
}
1515

16+
export function isWSL() {
17+
return !!Deno.env.get("WSL_DISTRO_NAME");
18+
}
19+
1620
export function isMac() {
1721
return Deno.build.os === "darwin";
1822
}

src/tools/tools.ts

Lines changed: 58 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
*/
77

8-
import { info } from "log/mod.ts";
8+
import { info, warning } from "log/mod.ts";
99
import { withSpinner } from "../core/console.ts";
1010
import { logError } from "../core/log.ts";
1111

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

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

87+
export function checkToolRequirement(name: string) {
88+
if (name.toLowerCase() === "chromium" && isWSL()) {
89+
// TODO: Change to a quarto-web url page ?
90+
const troubleshootUrl =
91+
"https://pptr.dev/next/troubleshooting#running-puppeteer-on-wsl-windows-subsystem-for-linux.";
92+
warning([
93+
`${name} can't be installed fully on WSL with Quarto as system requirements could be missing.`,
94+
`- Please do a manual installation following recommandations at ${troubleshootUrl}`,
95+
"- See https://github.com/quarto-dev/quarto-cli/issues/1822 for more context.",
96+
].join("\n"));
97+
return false;
98+
} else {
99+
return true;
100+
}
101+
}
102+
86103
export async function installTool(name: string, updatePath?: boolean) {
87104
name = name || "";
88105
// Run the install
89106
const installableTool = kInstallableTools[name.toLowerCase()];
90107
if (installableTool) {
91-
// Create a working directory for the installer to use
92-
const workingDir = Deno.makeTempDirSync();
93-
try {
94-
// The context for the installers
95-
const context = installContext(workingDir, updatePath);
108+
if (checkToolRequirement(name)) {
109+
// Create a working directory for the installer to use
110+
const workingDir = Deno.makeTempDirSync();
111+
try {
112+
// The context for the installers
113+
const context = installContext(workingDir, updatePath);
96114

97-
context.info(`Installing ${name}`);
115+
context.info(`Installing ${name}`);
98116

99-
// See if it is already installed
100-
const alreadyInstalled = await installableTool.installed();
101-
if (alreadyInstalled) {
102-
// Already installed, do nothing
103-
context.error(`Install canceled - ${name} is already installed.`);
104-
return Promise.reject();
105-
} else {
106-
// Prereqs for this platform
107-
const platformPrereqs = installableTool.prereqs.filter((prereq) =>
108-
prereq.os.includes(Deno.build.os)
109-
);
117+
// See if it is already installed
118+
const alreadyInstalled = await installableTool.installed();
119+
if (alreadyInstalled) {
120+
// Already installed, do nothing
121+
context.error(`Install canceled - ${name} is already installed.`);
122+
return Promise.reject();
123+
} else {
124+
// Prereqs for this platform
125+
const platformPrereqs = installableTool.prereqs.filter((prereq) =>
126+
prereq.os.includes(Deno.build.os)
127+
);
110128

111-
// Check to see whether any prerequisites are satisfied
112-
for (const prereq of platformPrereqs) {
113-
const met = await prereq.check(context);
114-
if (!met) {
115-
context.error(prereq.message);
116-
return Promise.reject();
129+
// Check to see whether any prerequisites are satisfied
130+
for (const prereq of platformPrereqs) {
131+
const met = await prereq.check(context);
132+
if (!met) {
133+
context.error(prereq.message);
134+
return Promise.reject();
135+
}
117136
}
118-
}
119137

120-
// Fetch the package information
121-
const pkgInfo = await installableTool.preparePackage(context);
138+
// Fetch the package information
139+
const pkgInfo = await installableTool.preparePackage(context);
122140

123-
// Do the install
124-
await installableTool.install(pkgInfo, context);
141+
// Do the install
142+
await installableTool.install(pkgInfo, context);
125143

126-
// post install
127-
const restartRequired = await installableTool.afterInstall(context);
144+
// post install
145+
const restartRequired = await installableTool.afterInstall(context);
128146

129-
context.info("Installation successful");
130-
if (restartRequired) {
131-
context.info(
132-
"To complete this installation, please restart your system.",
133-
);
147+
context.info("Installation successful");
148+
if (restartRequired) {
149+
context.info(
150+
"To complete this installation, please restart your system.",
151+
);
152+
}
134153
}
154+
} finally {
155+
// Cleanup the working directory
156+
Deno.removeSync(workingDir, { recursive: true });
135157
}
136-
} finally {
137-
// Cleanup the working directory
138-
Deno.removeSync(workingDir, { recursive: true });
139158
}
140159
} else {
141160
// No tool found

0 commit comments

Comments
 (0)