Skip to content

Commit ea94c97

Browse files
committed
Add support for —update-path flag
-> used when installing or removing a tool -> will notify the tool of the request to update paths -> only tinytex respects this
1 parent 4227711 commit ea94c97

File tree

7 files changed

+49
-16
lines changed

7 files changed

+49
-16
lines changed

news/changelog-1.2.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
- `quarto install tool tinytex` will no longer add TinyTex to the system path by default.
8383
- When rendering PDFs, Quarto will prefer an existing installation of TinyTex over a system Tex installation
8484
- To prevent Quarto from using an installation of TinyTex (if you'd prefer the system installation be used), set `latex-tinytex: false` in your project or document front matter.
85+
- To install TinyTex system wide, using the `--update-path` flag when installing (this will add TinyTex to the system path)
8586

8687
## Miscellaneous
8788

src/command/install/cmd.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ export const installCommand = new Command()
2828
"--embed <extensionId>",
2929
"Embed this extension within another extension (used when authoring extensions).",
3030
)
31+
.option(
32+
"--update-path",
33+
"Update system path when a tool is installed",
34+
)
3135
.description(
3236
"Installs an extension or global dependency.",
3337
)
@@ -57,7 +61,7 @@ export const installCommand = new Command()
5761
)
5862
.action(
5963
async (
60-
options: { prompt?: boolean; embed?: string },
64+
options: { prompt?: boolean; embed?: string; updatePath?: boolean },
6165
type: string,
6266
target?: string,
6367
) => {
@@ -80,7 +84,12 @@ export const installCommand = new Command()
8084
// Install a tool
8185
if (target) {
8286
// Use the tool name
83-
await updateOrInstallTool(target, "install", options.prompt);
87+
await updateOrInstallTool(
88+
target,
89+
"install",
90+
options.prompt,
91+
options.updatePath,
92+
);
8493
} else {
8594
// Not provided, give the user a list to choose from
8695
const allTools = await loadTools();
@@ -91,7 +100,7 @@ export const installCommand = new Command()
91100
const toolTarget = await selectTool(allTools, "install");
92101
if (toolTarget) {
93102
info("");
94-
await installTool(toolTarget);
103+
await installTool(toolTarget, options.updatePath);
95104
}
96105
}
97106
}

src/command/remove/cmd.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ export const removeCommand = new Command()
3939
"--embed <extensionId>",
4040
"Remove this extension from within another extension (used when authoring extensions).",
4141
)
42+
.option(
43+
"--update-path",
44+
"Update system path when a tool is installed",
45+
)
4246
.description(
4347
"Removes an extension or global dependency.",
4448
)
@@ -64,7 +68,7 @@ export const removeCommand = new Command()
6468
)
6569
.action(
6670
async (
67-
options: { prompt?: boolean; embed?: string },
71+
options: { prompt?: boolean; embed?: string; updatePath?: boolean },
6872
type: string,
6973
target?: string,
7074
) => {
@@ -130,7 +134,7 @@ export const removeCommand = new Command()
130134
// Process tool
131135
if (target) {
132136
// Explicitly provided
133-
await removeTool(target, options.prompt);
137+
await removeTool(target, options.prompt, options.updatePath);
134138
} else {
135139
// Not provided, give the user a list to choose from
136140
const allTools = await loadTools();

src/tools/impl/tinytex.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { execProcess } from "../../core/process.ts";
2222
import {
2323
InstallableTool,
2424
InstallContext,
25+
kUpdatePath,
2526
PackageInfo,
2627
RemotePackageInfo,
2728
ToolConfigurationState,
@@ -292,7 +293,7 @@ async function afterInstall(context: InstallContext) {
292293

293294
// If the environment has requested, add this tex installation to
294295
// the system path
295-
if (addTexLiveToPath()) {
296+
if (context.flags[kUpdatePath]) {
296297
const message =
297298
`Unable to determine a path to use when installing TeX Live.
298299
To complete the installation, please run the following:
@@ -380,7 +381,7 @@ async function uninstall(context: InstallContext) {
380381
return Promise.reject();
381382
}
382383

383-
if (addTexLiveToPath()) {
384+
if (context.flags[kUpdatePath]) {
384385
// remove symlinks
385386
if (await texLiveInPath()) {
386387
await context.withSpinner(

src/tools/tools-console.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,15 @@ export async function afterConfirm(
146146
}
147147
}
148148

149-
export const removeTool = (toolname: string, prompt?: boolean) => {
149+
export const removeTool = (
150+
toolname: string,
151+
prompt?: boolean,
152+
updatePath?: boolean,
153+
) => {
150154
return afterConfirm(
151155
`Are you sure you'd like to remove ${toolname}?`,
152156
() => {
153-
return uninstallTool(toolname);
157+
return uninstallTool(toolname, updatePath);
154158
},
155159
prompt,
156160
);
@@ -160,6 +164,7 @@ export async function updateOrInstallTool(
160164
tool: string,
161165
action: "update" | "install",
162166
prompt?: boolean,
167+
updatePath?: boolean,
163168
) {
164169
const summary = await toolSummary(tool);
165170

@@ -168,7 +173,7 @@ export async function updateOrInstallTool(
168173
return afterConfirm(
169174
`${tool} is not installed. Do you want to install it now?`,
170175
() => {
171-
return installTool(tool);
176+
return installTool(tool, updatePath);
172177
},
173178
prompt,
174179
);
@@ -203,7 +208,7 @@ export async function updateOrInstallTool(
203208
);
204209
}
205210
} else {
206-
return installTool(tool);
211+
return installTool(tool, updatePath);
207212
}
208213
}
209214
}

src/tools/tools.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { logError } from "../core/log.ts";
1212
import {
1313
InstallableTool,
1414
InstallContext,
15+
kUpdatePath,
1516
ToolConfigurationState,
1617
ToolSummaryData,
1718
} from "./types.ts";
@@ -81,7 +82,7 @@ export async function printToolInfo(name: string) {
8182
}
8283
}
8384

84-
export async function installTool(name: string) {
85+
export async function installTool(name: string, updatePath?: boolean) {
8586
name = name || "";
8687
// Run the install
8788
const installableTool = kInstallableTools[name.toLowerCase()];
@@ -90,7 +91,8 @@ export async function installTool(name: string) {
9091
const workingDir = Deno.makeTempDirSync();
9192
try {
9293
// The context for the installers
93-
const context = installContext(workingDir);
94+
const context = installContext(workingDir, updatePath);
95+
9496
context.info(`Installing ${name}`);
9597

9698
// See if it is already installed
@@ -145,13 +147,13 @@ export async function installTool(name: string) {
145147
}
146148
}
147149

148-
export async function uninstallTool(name: string) {
150+
export async function uninstallTool(name: string, updatePath?: boolean) {
149151
const installableTool = kInstallableTools[name.toLowerCase()];
150152
if (installableTool) {
151153
const installed = await installableTool.installed();
152154
if (installed) {
153155
const workingDir = Deno.makeTempDirSync();
154-
const context = installContext(workingDir);
156+
const context = installContext(workingDir, updatePath);
155157

156158
// Emit initial message
157159
context.info(`Uninstalling ${name}`);
@@ -244,7 +246,10 @@ export function installableTool(name: string) {
244246
return kInstallableTools[name.toLowerCase()];
245247
}
246248

247-
const installContext = (workingDir: string): InstallContext => {
249+
const installContext = (
250+
workingDir: string,
251+
updatePath?: boolean,
252+
): InstallContext => {
248253
const installMessaging = {
249254
info: (msg: string) => {
250255
info(msg);
@@ -280,5 +285,8 @@ const installContext = (workingDir: string): InstallContext => {
280285
workingDir,
281286
...installMessaging,
282287
props: {},
288+
flags: {
289+
[kUpdatePath]: updatePath,
290+
},
283291
};
284292
};

src/tools/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
import { SpinnerOptions } from "../core/console.ts";
99

10+
export const kUpdatePath = "update-path";
11+
1012
// Installable Tool interface
1113
export interface InstallableTool {
1214
name: string;
@@ -69,6 +71,9 @@ export interface InstallContext {
6971
confirm: (msg: string, def?: boolean) => Promise<boolean>;
7072
download: (name: string, url: string, target: string) => Promise<void>;
7173
props: { [key: string]: unknown };
74+
flags: {
75+
[kUpdatePath]?: boolean;
76+
};
7277
}
7378

7479
export interface ToolSummaryData {

0 commit comments

Comments
 (0)