
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
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.
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);
});
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 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.
A utility to find and parse tsconfig files without depending on typescript
Because no simple official api exists and tsconfig.json isn't actual json.
npm install --save-dev tsconfck # or pnpm, yarn
import { parse } from 'tsconfck';
const {
tsconfigFile, // full path to found tsconfig
tsconfig, // tsconfig object including merged values from extended configs
extended, // separate unmerged results of all tsconfig files that contributed to tsconfig
solution, // solution result if tsconfig is part of a solution
referenced // referenced tsconfig results if tsconfig is a solution
} = await parse('foo/bar.ts');
import { parseNative } from 'tsconfck';
const {
tsconfigFile, // full path to found tsconfig
tsconfig, // tsconfig object including merged values from extended configs, normalized
result, // output of ts.parseJsonConfigFileContent
solution, // solution result if tsconfig is part of a solution
referenced // referenced tsconfig results if tsconfig is a solution
} = await parseNative('foo/bar.ts');
see API-DOCS
You can use a map to cache results and avoid reparsing if you process multiple ts files that share few tsconfig files
import { parse } from 'tsconfck';
// 1. create cache instance
const cache = new Map();
// 2. pass cache instance in options
const fooResult = await parse('src/foo.ts', { cache });
// 3. profit (if they share the same tsconfig.json, it is not parsed again)
const barResult = await parse('src/bar.ts', { cache });
You are responsible for clearing the cache if tsconfig files change on disk during its lifetime.
Always clear the whole cache if anything changes as objects in the cache can ref each other
Returned results are direct cache objects.
If you want to modify them, deep-clone first.
find and parse reject for all errors they encounter.
For parse, you can choose to resolve with an empty result instead if no tsconfig file was found
import { parse } from 'tsconfck';
const result = await parse('some/path/without/tsconfig/foo.ts', {
resolveWithEmptyIfConfigNotFound: true
});
// result = { tsconfigFile: 'no_tsconfig_file_found',tsconfig: {} }
import type { TSConfig } from 'pkg-types';
Check out https://github.com/unjs/pkg-types
A simple cli wrapper is included, you can use it like this
# prints /path/to/tsconfig.json on stdout
tsconfck find src/index.ts
# print content of ParseResult.tsconfig on stdout
tsconfck parse src/index.ts
# print to file
tsconfck parse src/index.ts > output.json
# print content of ParseResult on stdout
tsconfck parse-result src/index.ts
# print to file
tsconfck parse-result src/index.ts > output.json
# print usage
tsconfck -h # or --help, -?, help
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
FAQs
A utility to work with tsconfig.json without typescript
The npm package tsconfck receives a total of 2,825,897 weekly downloads. As such, tsconfck popularity was classified as popular.
We found that tsconfck demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.