Organizing dependencies in workspace with several project folder
Suppose you have a workspace with several folder, and in each folder you have a deno project.
What is the best solution to handle dependencies for this workspace ?
- A single import_map.json at the root of the workspace and each project reference it in their respective deno.json with the importMap property ?
- Defining for each project the imports key in their respective deno.json ?
- Another option ?
Also, what is the best option to play nicely with IDE ? (I'm using Neovim)
2 Replies
In Deno, the standard practice for managing dependencies is to create a
deps.ts
file in each project. All required remote dependencies are referenced in this file and the required methods and classes are re-exported. The dependent local modules then reference the deps.ts
rather than the remote dependencies. This makes it easier to manage and update dependencies, as they are all centralized in one place. Dev dependencies can also be managed in a separate dev_deps.ts
file, allowing clean separation between dev only and production dependencies.
As for import maps, they are a powerful tool for managing dependencies, but they are not composable, meaning you can only provide a single import map to deno run
/ deno test
. Because of this, library authors should still use regular, non-bare specifiers (relative or absolute file / http URLs); otherwise the users of the library will manually need to add your libraries (and your libraries dependencies) bare specifiers into their import map.
In a workspace with several projects, it might be more practical to have a deps.ts
and dev_deps.ts
file in each project folder, rather than a single import_map.json
at the root. This way, each project can manage its own dependencies independently. However, if there are shared dependencies across projects and you want to ensure they all use the same version, a single import_map.json
at the root could be beneficial. Just remember that each project would still need to reference this import map in their respective deno.json
file with the importMap
property.
As for working with Neovim, the documentation does not provide specific advice for this editor. However, as long as your project is properly configured with a deps.ts
file and an import_map.json
(if used), and you'reusing a Deno plugin for Neovim that supports these features, you should be able to get autocompletion and other IDE features.
Remember, this advice is not explicitly stated in the documentation, but is a general recommendation based on the information provided in the documentation. 🦕