Function: ensurePackage

ensurePackage(tree, pkg, requiredVersion, options?): void

Deprecated

Use the other function signature without a Tree

Use a package that has not been installed as a dependency.

For example:

ensurePackage(tree, '@nx/jest', nxVersion);
Nx 15 and lower use @nrwl/ instead of @nx/

This install the @nx/jest@<nxVersion> and return the module When running with --dryRun, the function will throw when dependencies are missing. Returns null for ESM dependencies. Import them with a dynamic import instead.

Parameters

NameTypeDescription
treeTreethe file system tree
pkgstringthe package to check (e.g. @nx/jest)
requiredVersionstringthe version or semver range to check (e.g. ~1.0.0, >=1.0.0 <2.0.0)
options?Object-
options.dev?boolean-
options.throwOnMissing?boolean-

Returns

void

ensurePackage<T>(pkg, version): 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);
Nx 15 and lower use @nrwl/ instead of @nx/

Type parameters

NameType
Textends unknown = any

Parameters

NameTypeDescription
pkgstringthe package to install and require
versionstringthe version to install if the package doesn't exist already

Returns

T