Skip to content

Dependencies

Dependencies are an intrinsic part of every software project.

The Dependencies component is responsible to track the list of dependencies a project has, and then used by project types as the model for rendering project-specific dependency manifests such as the dependencies section package.json, pom.xml or pyproject.toml files.

To add a dependency, use a project-type specific API such as nodeProject.addDeps() or use the generic API project.deps:

project.deps.addDependency(dep, type);

By default, npx projen will automatically install dependencies in your project if they are not already installed. You can also install your dependencies manually by running npx projen install from the root of your monorepo.

Semantic requirements

The first argument (dep) is a string in the form MODULE@VERSION where MODULE is the package-manager specific name of the dependency (for node projects, this is the npm module name) and VERSION is an optional semantic version requirement (for example, @^7).

Dependency types

The second argument (type) defines the dependency type and is one of:

  • DependencyType.RUNTIME: The dependency is required for the program/library during runtime.
  • DependencyType.PEER: The dependency is required at runtime but only a single copy of the module must exist in the dependency closure of the consumer. In most package managers (PyPI, NuGet, Maven) there is no difference between runtime and peer dependencies (since all dependencies are installed as peers), but in npm, this is an important distinction. Prior to npm@7, peer dependencies must be installed explicitly by consumers.
  • DependencyType.BUNDLED: A runtime dependency that is bundled and shipped with the module, so consumers are not required to install it.
  • DependencyType.BUILD: The dependency is required to run the build task.
  • DependencyType.TEST: The dependency is required to run the test task.
  • DependencyType.DEVENV: The dependency is required for development (e.g. IDE plugins).

Sourced from: https://projen.io/deps.html

Upgrading Dependencies

The monorepo projects expose a task for updating dependencies across subprojects within your monorepo. You can invoke this by running the following command in the root of your monorepo:

npx projen upgrade-deps

This will have slightly different behaviour depending on the language of a subproject:

  • TypeScript: Minor version updates will be applied to dependencies and reflected in the package.json file, and lockfile.
  • Python: The pyproject.toml file remains unchanged, but the lockfile is updated to the latest version of each dependency within the constraints of the pyproject.toml file.
  • Java: No updates are performed. To upgrade dependencies you must update their versions referenced in your .projenrc and synthesize them so that the changes are reflected in the pom.xml

Note

If you're using the MonorepoTsProject, dependency versions in TypeScript subprojects will also be synchronised across the monorepo using syncpack.

To upgrade dependencies for an individual TypeScript or Python project, you can run npx projen upgrade within that package.


Last update: 2024-05-08