Search code examples
typescriptmonorepodeno

should deps.ts be per workspace or shared?


I'm trying to set up my first monorepo for a Deno-based app. The workspaces in this monorepo will be "modules" which the API code can import from, each module will for example have its own test suite.

The Deno documentation recommends creating a deps.ts file that imports and exports all the various dependencies, to have one central location to track those and review what versions are used etc.

Given the modular architecture of the workspaces, where should a deps.ts-file be? In each workspace, or in the root folder?

A "global" deps.ts would give a file structure somewhat like this:

  • src/modules/first/ with index.ts and deno.jsonc
  • src/modules/second/ with index.ts and deno.jsonc
  • src/deps.ts to be shared between modules.

All import statements look somewhat like

import {jose} from "../../deps.ts";

This would violate the "modularity" of the workspaces since you import stuff from outside their own directory. On the other hand, it seems to negate the point of using deps.ts to scatter many of them around in the tree.


Solution

  • Workspace support relies on configuration files (e.g. deno.json), and is explained in the manual (source permalink) and the corresponding blog post. (The std library is an example of using workspaces effectively.)

    The recommendation of using deps.ts predates Deno support for config files… and config files can be used to control import specifier resolution (and more), so the pattern of using deps.ts to manage dependencies is not necessary when using a config file.


    On topic: A post was actually published today on the Deno blog that goes into some detail about the trade-offs involved in management and resolution of dependencies using URL-specifiers: What we got wrong about HTTP imports