Skip to content

Commit

Permalink
tinytex - after install, set the CTAN mirror to the one resolved by h…
Browse files Browse the repository at this point in the history
…ttps://mirror.ctan.org

This will make sure any user installing TinyTeX with quarto does not end up with a US-based mirror.
  • Loading branch information
cderv committed Mar 14, 2024
1 parent 581c7e5 commit 78e7f84
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
1 change: 1 addition & 0 deletions news/changelog-1.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,4 @@ All changes included in 1.5:
- Resolve data URIs in Pandoc's mediabag when rendering documents.
- Increase v8's max heap size by default, to avoid out-of-memory errors when rendering large documents (also cf. https://github.com/denoland/deno/issues/18935).
- Upgrade Deno to 1.41.0
- `quarto install tinytex` will now try to set the default CTAN repository to the nearest mirror resolved from https://mirror.ctan.org.
23 changes: 19 additions & 4 deletions src/tools/impl/tinytex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ async function afterInstall(context: InstallContext) {

// Set the default repo to an https repo
let restartRequired = false;
const defaultRepo = textLiveRepo();
const defaultRepo = await textLiveRepo();
await context.withSpinner(
{
message: `Setting default repository`,
Expand Down Expand Up @@ -471,9 +471,24 @@ function exec(path: string, cmd: string[]) {

const kTlMgrKey = "tlmgr";

function textLiveRepo(): string {
const randomInt = Math.floor(Math.random() * kDefaultRepos.length);
return kDefaultRepos[randomInt];
async function textLiveRepo() {
// We don't set the default to `ctan` because one caveat of mirror.ctan.org
// is that it resolves to many different hosts, and they are not perfectly synchronized;
// Recommendation is to update only daily (at most), and not more often, which we don't want.
// So:
// 1. Try to get the automatic CTAN mirror returned from mirror.ctan.org
// 2. If that fails, use one of the selected mirrors
let autoUrl;
try {
const url = "https://mirror.ctan.org/systems/texlive/tlnet";
const response = await fetch(url, { redirect: "follow" });
autoUrl = response.url;
} catch (_e) {}
if (!autoUrl) {
const randomInt = Math.floor(Math.random() * kDefaultRepos.length);
autoUrl = kDefaultRepos[randomInt];
}
return autoUrl;
}

function tinyTexPkgName(base?: string, ver?: string) {
Expand Down

0 comments on commit 78e7f84

Please sign in to comment.