A tool for loading the nearest tsconfig file in the same way the TypeScript compiler does. It walks up the directory tree until it finds the first matching
Table of Contents
tsconfig-resolver is designed to be used inside your node project. It automatically populates the extends field so that the configuration received is the same as would be used by any consuming TypeScript project.
First, install the plugin and it's peer dependencies:
npm install --save tsconfig-resolver
yarn add tsconfig-resolver
The following will load the first
tsconfig.json file working upwards from the
process.cwd() of the running node process.
;;// without type narrowingconsole.logresult?.config);// with type narrowingif result.exists
Configuration options can also be passed into the export function.
The function returns an object consisting of the following.
||The configuration object.
||Whether or not the configuration could be loaded.
||The reason for failure.
||The absolute path to the tsconfig.json or given filename.
||The extendedPaths array.
||The directory to start searching from.|
||The tsconfig file name to search for. This is where the
||A direct path to the tsconfig file you would like to load. The path will be resolved relative to the current
||Set the caching strategy that will be used when searching for a file that's already been found. When a
||When true will not automatically populate the
The same API as
tsconfigResolverSync except the return value is wrapped in a promise.
Clears the cache.
;;// Now clear the cache.clearCache;
Provides the available caching strategies that can be used.
Sometimes you'll want to run this module several times during runtime but it can be slow and expensive walk up the file tree for the tsconfig value every time.
To help prevent unnecessary lookups there are custom caching strategies available.
CacheStrategy.Never- Caching never happens and the returned value is always recalculated
CacheStrategy.Always- The first time the
tsconfigResolvermethod is run it will save a cached value (by
searchName) which will be returned every time after that. This value will always be the same. This is turned on by default when a
CacheStrategy.Directory- The cache will be used when the same directory (and
searchName) is being searched.
This provides the reason for the error in resolving the
tsconfigfile could not be found.
TsConfigErrorReason.InvalidConfig- The file was found but the configuration was invalid.
Dive into the codebase with Gitpod.
This project is licensed under the MIT License - see the LICENSE file for details