Skip to content

Commit 00249a4

Browse files
committed
honor QUARTO_VERSION_REQUIREMENT environment variable
1 parent df96aab commit 00249a4

File tree

2 files changed

+59
-30
lines changed

2 files changed

+59
-30
lines changed

news/changelog-1.6.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ All changes included in 1.6:
129129
- ([#10332](https://github.com/quarto-dev/quarto-cli/issues/10332)): Use `exitWithCleanup` whenever possible instead of `Deno.exit` to clean up temporary resources.
130130
- ([#10334](https://github.com/quarto-dev/quarto-cli/issues/10334)): Fix `author` field rendered incorrectly in dashboards when multiple authors are present.
131131
- ([#8383](https://github.com/quarto-dev/quarto-cli/issues/8383)), ([#10087](https://github.com/quarto-dev/quarto-cli/issues/10087)), ([#10369](https://github.coma/quarto-dev/quarto-cli/issues/10369)): Track theme generation and file naming through content hashing to allow different themes to coexist in the same project.
132+
- ([#10442](https://github.com/quarto-dev/quarto-cli/issues/10442)): Honor the `semver` requirement in `QUARTO_VERSION_REQUIREMENT` and stop execution when that isn't met.
132133
- ([#10552](https://github.com/quarto-dev/quarto-cli/issues/10552)): Add `contents` shortcode.
133134
- ([#10581](https://github.com/quarto-dev/quarto-cli/issues/10581)): Add `.landscape` div processing to `typst`, `docx` and `pdf` formats to support pages in landscape orientation.
134135
- ([#10591](https://github.com/quarto-dev/quarto-cli/issues/10591)): Make fenced div syntax slightly more robust by removing spaces around the `=` sign ahead of Pandoc's reader.

src/quarto.ts

Lines changed: 58 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { pandocBinaryPath } from "./core/resources.ts";
2424
import { appendProfileArg, setProfileFromArg } from "./quarto-core/profile.ts";
2525
import { logError } from "./core/log.ts";
2626
import { CommandError } from "cliffy/command/_errors.ts";
27+
import { satisfies } from "semver/mod.ts";
2728

2829
import {
2930
devConfigsEqual,
@@ -51,11 +52,19 @@ import "./format/imports.ts";
5152
import { kCliffyImplicitCwd } from "./config/constants.ts";
5253
import { mainRunner } from "./core/main.ts";
5354

54-
export async function quarto(
55-
args: string[],
56-
cmdHandler?: (command: Command) => Command,
57-
env?: Record<string, string>,
58-
) {
55+
const checkVersionRequirement = () => {
56+
const versionReq = Deno.env.get("QUARTO_VERSION_REQUIREMENT");
57+
if (versionReq) {
58+
if (!satisfies(quartoConfig.version(), versionReq)) {
59+
error(
60+
`Quarto version ${quartoConfig.version()} does not meet semver requirement ${versionReq}`,
61+
);
62+
Deno.exit(1);
63+
}
64+
}
65+
};
66+
67+
const checkReconfiguration = async () => {
5968
// check for need to reconfigure
6069
if (quartoConfig.isDebug()) {
6170
const installed = readInstalledDevConfig();
@@ -65,36 +74,55 @@ export async function quarto(
6574
Deno.exit(1);
6675
}
6776
}
77+
};
6878

69-
// passthrough to pandoc
70-
if (args[0] === "pandoc" && args[1] !== "help") {
71-
const result = await execProcess(
72-
{
73-
cmd: [pandocBinaryPath(), ...args.slice(1)],
74-
env,
75-
},
76-
undefined,
77-
undefined,
78-
undefined,
79-
true,
79+
const passThroughPandoc = async (
80+
args: string[],
81+
env?: Record<string, string>,
82+
) => {
83+
const result = await execProcess(
84+
{
85+
cmd: [pandocBinaryPath(), ...args.slice(1)],
86+
env,
87+
},
88+
undefined,
89+
undefined,
90+
undefined,
91+
true,
92+
);
93+
Deno.exit(result.code);
94+
};
95+
96+
const passThroughTypst = async (
97+
args: string[],
98+
env?: Record<string, string>,
99+
) => {
100+
if (args[1] === "update") {
101+
error(
102+
"The 'typst update' command is not supported.\n" +
103+
"Please install the latest version of Quarto from http://quarto.org to get the latest supported typst features.",
80104
);
81-
Deno.exit(result.code);
105+
Deno.exit(1);
82106
}
107+
const result = await execProcess({
108+
cmd: [typstBinaryPath(), ...args.slice(1)],
109+
env,
110+
});
111+
Deno.exit(result.code);
112+
};
83113

84-
// passthrough to typst
114+
export async function quarto(
115+
args: string[],
116+
cmdHandler?: (command: Command) => Command,
117+
env?: Record<string, string>,
118+
) {
119+
await checkReconfiguration();
120+
checkVersionRequirement();
121+
if (args[0] === "pandoc" && args[1] !== "help") {
122+
await passThroughPandoc(args.slice(1), env);
123+
}
85124
if (args[0] === "typst") {
86-
if (args[1] === "update") {
87-
error(
88-
"The 'typst update' command is not supported.\n" +
89-
"Please install the latest version of Quarto from http://quarto.org to get the latest supported typst features.",
90-
);
91-
Deno.exit(1);
92-
}
93-
const result = await execProcess({
94-
cmd: [typstBinaryPath(), ...args.slice(1)],
95-
env,
96-
});
97-
Deno.exit(result.code);
125+
await passThroughTypst(args, env);
98126
}
99127

100128
// passthrough to run handlers

0 commit comments

Comments
 (0)