projen

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 files.

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

project.deps.addDependency(dep, type);

By default, npx projen will automatically install dependencies in your project if they are not already installed.

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 (i.e. for node projects, this is the npm module name) and VERSION is an optional semantic version requirement (e.g. @^7).

Dependency Types

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

Overriding Dependency Specifications

If a dependency is added multiple times, the last specification will prevail. This allows you to override dependency specs added by projects or components.

For example, if you wish to change the version of the TypeScript compiler used in TypeScript projects:

const { typescript } = require('projen');

const project = new typescript.TypeScriptProject({ 
  /* ... */ 
});
project.addDevDeps('typescript@^5');
project.synth();