Path: blob/main/package/src/common/dependencies/dependencies.ts
12926 views
/*1* dependencies.ts2*3* Copyright (C) 2020-2022 Posit Software, PBC4*5*/67import { join } from "../../../../src/deno_ral/path.ts";8import { info, warning } from "../../../../src/deno_ral/log.ts";9import { PlatformConfiguration } from "../config.ts";1011import { dartSass } from "./dartsass.ts";12import { deno_dom } from "./deno_dom.ts";13import { esBuild } from "./esbuild.ts";14import { pandoc } from "./pandoc.ts";15import { archiveUrl } from "../archive-binary-dependencies.ts";16import { typst } from "./typst.ts";17import { typstGather } from "./typst-gather.ts";18import { verapdf } from "./verapdf.ts";1920// The list of binary dependencies for Quarto21export const kDependencies = [22deno_dom(version("DENO_DOM")),23pandoc(version("PANDOC")),24dartSass(version("DARTSASS")),25esBuild(version("ESBUILD")),26typst(version("TYPST")),27typstGather(version("TYPST_GATHER")),28verapdf(version("VERAPDF")),29];3031// Defines a binary dependency for Quarto32export interface Dependency {33name: string;34bucket: string;35version: string;36// If true, this dependency is only archived to S3 but not downloaded during configure.37// Use for optional dependencies installed separately via `quarto install`.38archiveOnly?: boolean;39architectureDependencies: Record<40string,41ArchitectureDependency42>;43}4445// Defines the specific Platform dependencies for46// a given architecture47export interface ArchitectureDependency {48"darwin"?: PlatformDependency;49"linux"?: PlatformDependency;50"windows"?: PlatformDependency;51}5253// Defines an individual binary dependency, specific54// to a Platform (and architecture)55export interface PlatformDependency {56filename: string;57url: string;58configure(config: PlatformConfiguration, path: string): Promise<void>;59}6061function version(env: string) {62const version = Deno.env.get(env);63if (!version) {64throw Error(`${env} isn't defined with dependency version`);65} else {66return version;67}68}6970export async function configureDependency(71dependency: Dependency,72targetDir: string,73config: PlatformConfiguration,74) {75// Skip archive-only dependencies (installed separately via `quarto install`)76if (dependency.archiveOnly) {77info(`Skipping ${dependency.name} (archive-only)`);78return;79}8081info(`Preparing ${dependency.name} (${config.os} - ${config.arch})`);82const archDep = dependency.architectureDependencies[config.arch];8384if (archDep) {85const platformDep = archDep[config.os];86const vendor = Deno.env.get("QUARTO_VENDOR_BINARIES");87let targetFile = "";88if (platformDep && (vendor === undefined || vendor === "true")) {89info(`Downloading ${dependency.name}`);9091try {92targetFile = await downloadBinaryDependency(93dependency,94platformDep,95targetDir,96);97} catch (error) {98const msg =99`Failed to Download ${dependency.name}\nAre you sure that version ${dependency.version} of ${dependency.bucket} has been archived using './quarto-bld archive-bin-deps'?\n${error.message}`;100throw new Error(msg);101}102}103104if (platformDep) {105info(`Configuring ${dependency.name}`);106await platformDep.configure(config, targetFile);107}108109if (targetFile) {110info(`Cleaning up`);111Deno.removeSync(targetFile);112}113} else {114throw new Error(115`The architecture ${config.arch} is missing the dependency ${dependency.name}`,116);117}118119info(`${dependency.name} complete.\n`);120}121122async function downloadBinaryDependency(123dependency: Dependency,124platformDependency: PlatformDependency,125targetDir: string,126) {127const targetFile = join(targetDir, platformDependency.filename);128const dlUrl = archiveUrl(dependency, platformDependency);129130info("Downloading " + dlUrl);131info("to " + targetFile);132const response = await fetch(dlUrl);133if (response.status === 200) {134const blob = await response.blob();135136const bytes = await blob.arrayBuffer();137const data = new Uint8Array(bytes);138139Deno.writeFileSync(140targetFile,141data,142);143return targetFile;144} else {145throw new Error(response.statusText);146}147}148149150