What is tsconfck?
The tsconfck package is a utility for TypeScript configuration management. It helps in resolving and loading TypeScript configuration files (tsconfig.json) by handling inheritance and references within these configurations. This is particularly useful in complex projects where tsconfig settings are split across multiple files or extended from other configurations.
What are tsconfck's main functionalities?
Load and resolve tsconfig.json
This feature allows loading a tsconfig.json file, resolving all its extends and references to provide a final resolved configuration object. It handles the asynchronous nature of file reading and parsing, providing a promise-based API.
const { loadTsconfig } = require('tsconfck');
loadTsconfig('path/to/tsconfig.json').then(tsconfig => {
console.log(tsconfig);
}).catch(error => {
console.error(error);
});
Other packages similar to tsconfck
tsconfig-paths
tsconfig-paths is a package that helps in resolving and loading paths from tsconfig.json files for module resolution. Unlike tsconfck, which focuses more broadly on configuration loading and resolution, tsconfig-paths specifically targets path resolution to aid in module loading in non-TypeScript environments.
tsconfig-loader
tsconfig-loader provides functionality to load tsconfig.json files without resolving the entire configuration. It's simpler than tsconfck as it does not handle the resolution of 'extends' or other complex configurations, focusing instead on direct loading of configurations as they are defined.
tsconfck
A utility to find and parse tsconfig files without depending on typescript
Why
Because no simple official api exists and tsconfig.json isn't actual json.
Features
Usage
without typescript installed
import { parse } from 'tsconfck';
const {
filename,
tsconfig,
extended
} = await parse('foo/bar.ts');
with typescript
import { parseNative } from 'tsconfck';
const {
filename,
tsconfig,
result
} = await parseNative('foo/bar.ts');
Advanced
caching
You should cache results to avoid reparsing if you process multiple ts files that share few tsconfig files
import { find, parse } from 'tsconfck';
const cache = new Map();
const cachedParse = async (filename) => {
const tsconfigFile = find(filename);
if (cache.has(tsconfigFile)) {
return cache.get(tsconfigFile);
}
const parseResult = parse(tsconfigFile);
cache.put(tsconfigFile, parseResult);
return parseResult;
};
Links
Develop
This repo uses
In addition to default commit-msg prefixes you can use 'wip: ' for commit messages in branches.
PRs are going to be squash-merged
# install dependencies
pnpm install
# run tests
pnpm test
#run tests in watch mode (doesn't require dev in parallel)
pnpm test:watch