nx-update-ts-references
v0.0.8
Published
An Nx plugin to update references in tsconfig based on local dependencies
Downloads
293
Maintainers
Readme
nx-update-ts-references
An Nx plugin that updates your tsconfig.json references based on your local dependencies.
Table of Contents
Introduction
When working with typescript in a monorepo, you can use the references field of tsconfig.json to point to packages that your code depends on locally, so Typescript can efficently build and infer types as your codebase grows.
Nx already manages a dependency graph of your local typescript packages based on the dependencies on your package.json
.
nx-update-ts-references
will use this dependency graph to ensure your typescript configuration is up to date, so you don't have to manage it manually.
Installation
npm i nx-update-ts-references
Register it as a target in your project.json
:
{
"targets": {
"update-ts-references": {
"executor": "nx-update-ts-references:update-ts-references"
}
}
}
Usage
Due to Nx deriving the dependency graph from your package.json
, and the rest of the fields of tsconfig.json
being maintained, those are the only two inputs, and the tsconfig.json
file is the out, this is a trivially cacheable operation:
{
"targets": {
"update-ts-references": {
"executor": "nx-update-ts-references:update-ts-references",
"cache": true,
"inputs": [
"{projectRoot}/package.json",
"{projectRoot}/tsconfig.json"
],
"outputs": [
"{projectRoot}/tsconfig.json"
],
}
}
}
It is recommended to include this in every project that is based on typescript.
API
The following options can be passed to the options object.
check
boolean
When true, target will fail if the tsconfig.json
is out of sync from the desired state.
Defaults to false when executing locally, but defaults to true when running in CI environments. Useful for enforcing that any updates to package dependencies are reflected in the version-controlled code prior to deployment.
dryRun
boolean
When true, will not actually write the tsconfig.json
file. Can still fail if check is true.
Defaults to false.