Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
quarto-dev
GitHub Repository: quarto-dev/quarto-cli
Path: blob/main/src/command/render/latexmk/pkgmgr.ts
3587 views
1
/*
2
* pkgmgr.ts
3
*
4
* Copyright (C) 2020-2022 Posit Software, PBC
5
*/
6
7
import * as ld from "../../../core/lodash.ts";
8
9
import { ProcessResult } from "../../../core/process-types.ts";
10
11
import {
12
findPackages,
13
installPackages,
14
TexLiveContext,
15
updatePackages,
16
} from "./texlive.ts";
17
import { LatexmkOptions } from "./types.ts";
18
19
export interface PackageManager {
20
autoInstall: boolean;
21
searchPackages(searchTerms: string[]): Promise<string[]>;
22
installPackages(pkgs: string[]): Promise<boolean>;
23
updatePackages(all: boolean, self: boolean): Promise<ProcessResult>;
24
}
25
26
export function packageManager(
27
mkOptions: LatexmkOptions,
28
texLive: TexLiveContext,
29
): PackageManager {
30
let lastPkgs: string[] = [];
31
return {
32
autoInstall: mkOptions.autoInstall === undefined
33
? true
34
: mkOptions.autoInstall,
35
installPackages: async (pkgs: string[]) => {
36
// See whether we just tried to install the same packages or
37
// if there are no packages detected to install
38
// (if so, just give up as we can't suceed)
39
const difference = ld.difference(pkgs, lastPkgs);
40
if (difference.length > 0) {
41
// Attempt to install the packages
42
await installPackages(
43
pkgs,
44
texLive,
45
mkOptions.engine.tlmgrOpts,
46
mkOptions.quiet,
47
);
48
49
// Note that we tried to install these packages
50
lastPkgs = pkgs;
51
52
// Try running the engine again now that we've installed packages
53
return true;
54
} else {
55
// We have already tried installing these packages, don't install the packages
56
return false;
57
}
58
},
59
updatePackages: (all: boolean, self: boolean) => {
60
return updatePackages(
61
all,
62
self,
63
texLive,
64
mkOptions.engine.tlmgrOpts,
65
mkOptions.quiet,
66
);
67
},
68
searchPackages: (searchTerms: string[]) => {
69
return findPackages(
70
searchTerms,
71
texLive,
72
mkOptions.engine.tlmgrOpts,
73
mkOptions.quiet,
74
);
75
},
76
};
77
}
78
79