Path: blob/main/src/command/render/latexmk/pkgmgr.ts
3587 views
/*1* pkgmgr.ts2*3* Copyright (C) 2020-2022 Posit Software, PBC4*/56import * as ld from "../../../core/lodash.ts";78import { ProcessResult } from "../../../core/process-types.ts";910import {11findPackages,12installPackages,13TexLiveContext,14updatePackages,15} from "./texlive.ts";16import { LatexmkOptions } from "./types.ts";1718export interface PackageManager {19autoInstall: boolean;20searchPackages(searchTerms: string[]): Promise<string[]>;21installPackages(pkgs: string[]): Promise<boolean>;22updatePackages(all: boolean, self: boolean): Promise<ProcessResult>;23}2425export function packageManager(26mkOptions: LatexmkOptions,27texLive: TexLiveContext,28): PackageManager {29let lastPkgs: string[] = [];30return {31autoInstall: mkOptions.autoInstall === undefined32? true33: mkOptions.autoInstall,34installPackages: async (pkgs: string[]) => {35// See whether we just tried to install the same packages or36// if there are no packages detected to install37// (if so, just give up as we can't suceed)38const difference = ld.difference(pkgs, lastPkgs);39if (difference.length > 0) {40// Attempt to install the packages41await installPackages(42pkgs,43texLive,44mkOptions.engine.tlmgrOpts,45mkOptions.quiet,46);4748// Note that we tried to install these packages49lastPkgs = pkgs;5051// Try running the engine again now that we've installed packages52return true;53} else {54// We have already tried installing these packages, don't install the packages55return false;56}57},58updatePackages: (all: boolean, self: boolean) => {59return updatePackages(60all,61self,62texLive,63mkOptions.engine.tlmgrOpts,64mkOptions.quiet,65);66},67searchPackages: (searchTerms: string[]) => {68return findPackages(69searchTerms,70texLive,71mkOptions.engine.tlmgrOpts,72mkOptions.quiet,73);74},75};76}777879