Skip to content

Signatures

ensurePackage(tree: Tree, pkg: string, requiredVersion: string, options: Object): void

Parameters

  • tree: Tree - the file system tree
  • pkg: string - the package to check (e.g. @nx/jest)
  • requiredVersion: string - the version or semver range to check (e.g. ~1.0.0, >=1.0.0 <2.0.0)
  • options: Object
ensurePackage(pkg: string, version: string): T

Ensure that dependencies and devDependencies from package.json are installed at the required versions. Returns null for ESM dependencies. Import them with a dynamic import instead.

For example:

ensurePackage('@nx/jest', nxVersion)

Parameters

  • pkg: string - the package to install and require
  • version: string - the version to install if the package doesn’t exist already