Security News
The Unpaid Backbone of Open Source: Solo Maintainers Face Increasing Security Demands
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
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 isn't actual json.
Used by vite*, vite-tsconfig-paths, astro and many more
(*) vite bundles tsconfck so it is listed as a devDependency
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
esbuild ignores node_modules so when you want to use tsconfck with esbuild, you can set ignoreNodeModules: true
import { find, parse } from 'tsconfck';
// returns some-lib/tsconfig.json
const fooTSConfig = await find('node_modules/some-lib/src/foo.ts');
// returns null
const fooTSConfigIgnored = await find('node_modules/some-lib/src/foo.ts', {
ignoreNodeModules: true
});
// returns empty config
const { tsconfig } = await parse('node_modules/some-lib/src/foo.ts', { ignoreNodeModules: true });
a TSConfckCache instance can be created and passed to find and parse functions to reduce overhead when they are called often within the same project
import { find, parse, TSCOnfckCache } from 'tsconfck';
// 1. create cache instance
const cache = new TSCOnfckCache();
// 2. pass cache instance in options
const fooTSConfig = await find(('src/foo.ts', { cache })); // stores tsconfig for src in cache
const barTSConfig = await find(('src/bar.ts', { cache })); // reuses tsconfig result for src without fs call
const fooResult = await parse('src/foo.ts', { cache }); // uses cached path for tsconfig, stores parse result in cache
const barResult = await parse('src/bar.ts', { cache }); // uses cached parse result without fs call or resolving
You are responsible for clearing the cache if tsconfig files are added/removed/changed after reading them during the cache lifetime.
Call cache.clear()
and also discard all previous compilation results based previously cached configs.
Returned results are direct cache objects. If you want to modify them, deep-clone first.
Never use the same cache instance for mixed calls of find/findNative or parse/parseNative as result structures are different
This option can be used to limit finding tsconfig files outside of a root directory
import { parse, TSConfckCache } from 'tsconfck';
const root = '.';
const parseOptions = { root };
// these calls are not going to look for tsconfig files outside root
const fooResult = await find('src/foo.ts', parseOptions);
const barResult = await parse('src/bar.ts', parseOptions);
Using the root option can lead to errors if there is no tsconfig found inside root.
find and parse reject for errors they encounter, but return null or empty result if no config was found
If you want them to error instead, test the result and throw
import { parse } from 'tsconfck';
find('some/path/without/tsconfig/foo.ts').then((result) => {
if (result === null) {
throw new Error('not found');
}
return result;
});
parse('some/path/without/tsconfig/foo.ts').then((result) => {
if (result.tsconfigFile === null) {
throw new Error('not found');
}
return result;
});
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
# prints all tsconfig.json in dir on stdout
tsconfck find-all src/
# 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 every PR you have to add a changeset by running pnpm changeset
and following the prompts
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,081,407 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
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
Security News
License exceptions modify the terms of open source licenses, impacting how software can be used, modified, and distributed. Developers should be aware of the legal implications of these exceptions.
Security News
A developer is accusing Tencent of violating the GPL by modifying a Python utility and changing its license to BSD, highlighting the importance of copyleft compliance.