Skip to content

Commit fc05c78

Browse files
dragonstylejjallaire
authored andcommitted
Permit overriding of tools using
export QUARTO_<binary-name>=<my-custom-path> (pandoc, dart, esbuild)
1 parent c1d6bb3 commit fc05c78

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

src/core/resources.ts

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,35 @@ export function formatResourcePath(format: string, resource: string) {
3030
}
3131

3232
export function toolsPath(binary: string): string {
33-
return join(quartoConfig.toolsPath(), binary);
34-
}
33+
const displayWarning = () => {
34+
warnOnce(
35+
`Specified ${binaryEnvKey} does not exist, using built in ${binary}`,
36+
);
37+
};
3538

36-
export function pandocBinaryPath(): string {
37-
// allow override of built-in pandoc w/ QUARTO_PANDOC environment variable
38-
const quartoPandoc = Deno.env.get("QUARTO_PANDOC");
39-
if (quartoPandoc) {
40-
if (!existsSync(quartoPandoc)) {
41-
warnOnce("Specified QUARTO_PANDOC does not exist, using built in Pandoc");
42-
}
43-
if (Deno.statSync(quartoPandoc).isFile) {
44-
return quartoPandoc;
39+
const binaryEnvKey = `QUARTO_${binary.toUpperCase()}`;
40+
const binaryPath = Deno.env.get(binaryEnvKey);
41+
if (binaryPath) {
42+
if (!existsSync(binaryPath)) {
43+
displayWarning();
4544
} else {
46-
return join(quartoPandoc, "pandoc");
45+
if (Deno.statSync(binaryPath).isFile) {
46+
return binaryPath;
47+
} else {
48+
const fullPath = join(binaryPath, binary);
49+
if (!existsSync(fullPath)) {
50+
displayWarning();
51+
} else {
52+
return fullPath;
53+
}
54+
}
4755
}
4856
}
4957

58+
return join(quartoConfig.toolsPath(), binary);
59+
}
60+
61+
export function pandocBinaryPath(): string {
5062
return toolsPath("pandoc");
5163
}
5264

0 commit comments

Comments
 (0)