buddy check-deps
buddy check-deps reports every package the project’s Jest config uses, through its whole preset chain, that no
dependency field of package.json declares.
buddy check-deps [--cwd <dir>]Alias: buddy check-dependencies.
Options
Section titled “Options”| Option | Type | Default | Effect |
|---|---|---|---|
--cwd |
string | the current directory | The project to check. It must hold a package.json. |
The global options also apply.
How it works
Section titled “How it works”- It finds the Jest config. It tries
jest.config.js,jest.config.mjs,jest.config.cjs,jest.config.ts,jest.config.mts,jest.config.cts, andjest.config.json, in that order. When none exists, it uses thejestkey ofpackage.json. A module config may export an object or a function, sync or async. - It lists the packages that config names, with the field that names each one (
transform,watchPlugins,preset, and so on). - It follows
preset. It resolves the preset from the project directory as the module itself, then as<preset>/jest-preset.js, then as<preset>/jest-preset.json. It repeats for that preset’s ownpreset, up to 10 levels, and stops on a loop. - It compares the list with
dependencies,devDependencies,peerDependencies, andoptionalDependencies.
Rules:
- A package found in
node_modulesbut not declared still counts as missing. The next install can remove it. jest-environment-nodeis never reported. It arrives with Jest.- The project’s own package name is never reported.
- A preset that does not load gives the warning
could not load preset "<name>". The preset package itself is then reported as missing. - The install line follows the
packageManagerfield ofpackage.json, searched in the project directory and then in each parent directory:pnpm add -D,yarn add -D,bun add -d, ornpm i -Dwhen none is set.
The packages a preset needs can depend on what is already installed. For example,
@repobuddy/jest/presets/ts reported jest-esm-transformer-2 and ts-jest in one project and @swc/jest after
those two were declared. Run the command again after you install.
Output
Section titled “Output”All declared:
dependencies: 3 used by jest.config.mjs, all declared in package.jsonNo Jest config:
dependencies: no jest configuration found, nothing to checkMissing packages (a project with "packageManager": "pnpm@10.0.0" and only @repobuddy/jest and jest
declared):
missing dependencies: 5 used by jest.config.mjs but not declared in package.json jest-esm-transformer-2 preset(@repobuddy/jest/presets/ts-watch) transform jest-watch-suspend preset(@repobuddy/jest/presets/ts-watch) watchPlugins jest-watch-toggle-config preset(@repobuddy/jest/presets/ts-watch) watchPlugins jest-watch-typeahead preset(@repobuddy/jest/presets/ts-watch) watchPlugins ts-jest preset(@repobuddy/jest/presets/ts-watch) transforminstall: pnpm add -D jest-esm-transformer-2 jest-watch-suspend jest-watch-toggle-config jest-watch-typeahead ts-jestEach detail line names the package, then where it came from: the config file or preset(<name>), and the field.
When the config lives in package.json, the summary says used by package.json#jest.
Exit codes
Section titled “Exit codes”| Code | When |
|---|---|
0 |
Every package is declared, or the project has no Jest config. |
1 |
At least one package is missing, or the directory has no readable package.json. |
2 |
An unknown option. |
Examples
Section titled “Examples”Check the current project
Section titled “Check the current project”buddy check-depsCheck a workspace package from the repository root
Section titled “Check a workspace package from the repository root”buddy check-deps --cwd packages/appA preset that does not resolve
Section titled “A preset that does not resolve”jest.config.cjs:
module.exports = { preset: 'no-such-preset' }could not load preset "no-such-preset"missing dependencies: 1 used by jest.config.cjs but not declared in package.json no-such-preset jest.config.cjs presetinstall: npm i -D no-such-presetA directory that is not a project
Section titled “A directory that is not a project”buddy check-deps --cwd does-not-existcannot read the project at does-not-existcheck-deps needs a directory with a package.jsonRelated
Section titled “Related”- Check Jest dependencies in CI
@repobuddy/jest: the presets this command follows.