Path: blob/main/package/src/common/dependencies/typst.ts
6451 views
1import { join, dirname, basename } from "../../../../src/deno_ral/path.ts"2import { ensureDirSync, existsSync } from "../../../../src/deno_ral/fs.ts"34import { Configuration } from "../config.ts";5import { Dependency } from "./dependencies.ts";6import { which } from "../../../../src/core/path.ts";7import { unTar } from "../../util/tar.ts";89export function typst(version: string ): Dependency {10const typst_release = (filename: string ) => {11return {12filename,13url: `https://github.com/typst/typst/releases/download/v${version}/${filename}`,14configure: async(config: Configuration, path: string) => {15const file = config.os === "windows" ? "typst.exe" : "typst";16const archiveExt = config.os === "windows" ? ".zip" : ".tar.xz";17const vendor = Deno.env.get("QUARTO_VENDOR_BINARIES");18if (vendor === undefined || vendor === "true") {19// establish archive expand dir and remove existing if necessary20const dir = dirname(path);2122const targetDir = join(dir, config.arch);23ensureDirSync(targetDir);242526const archiveDir = basename(path, archiveExt);27const typstDir = join(dir, archiveDir);28const cleanup = () => {29if (existsSync(typstDir)) {30Deno.removeSync(typstDir, { recursive: true });31}32}33cleanup();3435// expand36await unTar(path);3738// move the file and cleanup39try {40const extractedPath = join(typstDir, file);41Deno.renameSync(extractedPath, join(targetDir, file));42} finally {43cleanup();44}45} else {46// verify that the binary is on PATH, but otherwise don't do anything47if (which(file) === undefined) {48throw new Error(49`${file} is not on PATH. Please install it and add it to PATH.`,50);51}52}53}54}55}5657return {58name: "Typst",59bucket: "typst",60version,61architectureDependencies: {62"x86_64": {63"windows": typst_release("typst-x86_64-pc-windows-msvc.zip"),64"linux": typst_release("typst-x86_64-unknown-linux-musl.tar.xz"),65"darwin": typst_release("typst-x86_64-apple-darwin.tar.xz"),66},67"aarch64": {68"linux": typst_release("typst-aarch64-unknown-linux-musl.tar.xz"),69"darwin": typst_release("typst-aarch64-apple-darwin.tar.xz")70}71}72}73}7475767778