How to manage package dependencies in a single place?

Is there a way to manage package dependencies in a single place? Let’s say multiple Typst files in my project use Glossarium and import it with:

#import "@preview/glossarium:0.5.8"

How to I avoid repeating the version number 0.5.8 every time?

From what I found so far, it seems Typst does not provide any dedicated dependency management file or similar.

The approach I am currently using is having a separate package-imports.typ file which only defines the package imports, and then importing all packages from that file instead:

#import "/package-imports.typ": glossarium.gls

If that is currently the approach suggested by the community, are there any conventions for how to name this file? I noticed the typst-community/setup-typst action uses requirements.typ, but I am not sure if that is only intended to be used by the GitHub action or also by the project itself, and I don’t know either how widespread that file name convention is.

Or which approaches do you use to manage package dependencies in a single place?

I use the same approach, and think it’s ideal atm.

I’m not sure if there is a convention; I generally use libs.typ as it’s short and imo descriptive enough. How it works in setup-typst is (roughly) this: you point the action to your dependencies file (whatever it is named), and it collects all package imports in that file, and caches the packages that were installed by Typst for subsequent runs.

I guess by suggesting requirements.typ the action is somewhat establishing a convention. It’s similar to e.g. Python’s requirements.txt so that’s a plus. But it’s not a default value of the action, so choosing anything else is just as easy.

2 Likes

I faced this problem almost 1.5 years ago, and posted this Move external dependencies to a single file · Issue #403 · cetz-package/cetz · GitHub, which was added in Group external dependencies in single file by johannes-wolf · Pull Request #406 · cetz-package/cetz · GitHub, and then I did Consolidated external package imports into a separate file by Andrew15-5 · Pull Request #11 · Jollywatt/typst-fletcher · GitHub. So yeah, that’s the best one yet.

1 Like