### Install Dependencies and Run Scripts with pnpm Source: https://github.com/dominikg/tsconfck/blob/main/CONTRIBUTING.md Use these pnpm commands to manage dependencies, run tests, generate documentation and types, and create a changeset for your changes. ```shell pnpm install ``` ```shell pnpm test ``` ```shell pnpm generate ``` ```shell pnpm changeset ``` -------------------------------- ### Find tsconfig.json (Native) Source: https://github.com/dominikg/tsconfck/blob/main/docs/api.md Finds the closest tsconfig.json file using TypeScript's native `ts.findConfigFile` function. Requires the `typescript` package to be installed. ```APIDOC ## POST /api/findNative ### Description Finds the closest tsconfig.json file using native ts.findConfigFile. ### Method POST ### Endpoint /api/findNative ### Parameters #### Query Parameters - **filename** (string) - Required - Path to file to find tsconfig for (absolute or relative to cwd). - **options** (TSConfckFindOptions) - Optional - Options for finding the tsconfig file. #### Request Body ```json { "filename": "path/to/your/file.ts", "options": { "cache": { /* TSConfckCache object */ }, "root": "/path/to/project/root", "ignoreNodeModules": false, "configName": "tsconfig.json" } } ``` ### Response #### Success Response (200) - **string** - Absolute path to the closest tsconfig.json file. #### Response Example ```json { "example": "/path/to/your/tsconfig.json" } ``` ``` -------------------------------- ### Find tsconfig.json Source: https://github.com/dominikg/tsconfck/blob/main/docs/api.md Finds the closest tsconfig.json file starting from a given file path. Supports custom options for caching, project root, ignoring node_modules, and custom config file names. ```APIDOC ## POST /api/find ### Description Finds the closest tsconfig.json file. ### Method POST ### Endpoint /api/find ### Parameters #### Query Parameters - **filename** (string) - Required - Path to file to find tsconfig for (absolute or relative to cwd). - **options** (TSConfckFindOptions) - Optional - Options for finding the tsconfig file. #### Request Body ```json { "filename": "path/to/your/file.ts", "options": { "cache": { /* TSConfckCache object */ }, "root": "/path/to/project/root", "ignoreNodeModules": false, "configName": "tsconfig.json" } } ``` ### Response #### Success Response (200) - **string | null** - Absolute path to the closest tsconfig.json file, or null if not found. #### Response Example ```json { "example": "/path/to/your/tsconfig.json" } ``` ``` -------------------------------- ### Parse tsconfig.json (Native) Source: https://github.com/dominikg/tsconfck/blob/main/docs/api.md Parses the closest tsconfig.json file using TypeScript's native parsing functions. Requires the `typescript` package to be installed. Supports options to ignore source files for performance. ```APIDOC ## POST /api/parseNative ### Description Parses the closest tsconfig.json file with typescript native functions. ### Method POST ### Endpoint /api/parseNative ### Parameters #### Query Parameters - **filename** (string) - Required - Path to a tsconfig .json or a source file (absolute or relative to cwd). - **options** (TSConfckParseNativeOptions) - Optional - Options for parsing the tsconfig file. Extends TSConfckParseOptions. - **ignoreSourceFiles** (boolean) - Optional - Set to true to force typescript to ignore all source files. This is faster but results in `files: [], include: []` and may not resolve solution references correctly. #### Request Body ```json { "filename": "path/to/your/file.ts", "options": { "cache": { /* TSConfckCache object */ }, "root": "/path/to/project/root", "ignoreNodeModules": false, "configName": "tsconfig.json", "ignoreSourceFiles": false } } ``` ### Response #### Success Response (200) - **TSConfckParseNativeResult** - An object containing the native parsed tsconfig details. - **tsconfigFile** (string) - Absolute path to the parsed tsconfig.json. - **tsconfig** (any) - The parsed tsconfig content, including merged values from extended and normalized. - **solution** (TSConfckParseNativeResult) - Optional - ParseResult for the parent solution. - **referenced** (TSConfckParseNativeResult[]) - Optional - ParseNativeResults for all tsconfig files referenced in a solution. - **result** (any) - The full output of `ts.parseJsonConfigFileContent`. #### Response Example ```json { "example": { "tsconfigFile": "/path/to/your/tsconfig.json", "tsconfig": { "compilerOptions": { "target": "es2016" } }, "result": { "config": { "compilerOptions": { "target": "es2016" } }, "fileNames": ["index.ts"], "raw": { /* raw tsconfig content */ }, "errors": [] } } } ``` ``` -------------------------------- ### Find tsconfig.json using Native TypeScript Source: https://github.com/dominikg/tsconfck/blob/main/docs/api.md Use `findNative` to find the closest `tsconfig.json` using TypeScript's native `findConfigFile` function. Requires `typescript` to be installed. Returns the absolute path to the config file. ```typescript export function findNative(filename: string, options?: TSConfckFindOptions): Promise; ``` -------------------------------- ### Parse tsconfig.json using Native TypeScript Source: https://github.com/dominikg/tsconfck/blob/main/docs/api.md Use `parseNative` to parse `tsconfig.json` with TypeScript's native functions. Requires `typescript` to be installed. It accepts a filename and `TSConfckParseNativeOptions`, returning detailed parsing results. ```typescript export function parseNative(filename: string, options?: TSConfckParseNativeOptions): Promise; ``` -------------------------------- ### TSConfckFindAllOptions Interface Source: https://github.com/dominikg/tsconfck/blob/main/docs/api.md Options for the `findAll` function. Allows customization of directory skipping logic and the names of configuration files to search for. ```typescript export interface TSConfckFindAllOptions { /** * helper to skip subdirectories when scanning for tsconfig.json * * eg ` dir => dir === 'node_modules' || dir === '.git'` */ skip?: (dir: string) => boolean; /** * list of config filenames to include, use ["tsconfig.json","jsconfig.json"] if you need both * * @default ["tsconfig.json"] */ configNames?: string[]; } ``` -------------------------------- ### findAll Function Source: https://github.com/dominikg/tsconfck/blob/main/docs/api.md Searches for all tsconfig.json files within a specified directory and its subdirectories. Supports custom options for skipping directories and specifying configuration file names. ```APIDOC ## findAll Function ### Description Finds all `tsconfig.json` files in a given directory. ### Parameters #### Path Parameters - **dir** (string) - Required - The path to the directory to search in (absolute or relative to cwd). #### Query Parameters - **options** (TSConfckFindAllOptions) - Optional - Options to customize the search behavior. - **skip** (function) - Optional - A function that takes a directory name and returns `true` if the directory should be skipped (e.g., `dir => dir === 'node_modules'`). - **configNames** (string[]) - Optional - A list of configuration filenames to look for (defaults to `["tsconfig.json"]`). Use `["tsconfig.json", "jsconfig.json"]` to include both. ``` -------------------------------- ### TSConfckFindOptions Interface Source: https://github.com/dominikg/tsconfck/blob/main/docs/api.md Options for the `find` function. Includes a cache for performance, a root directory to limit the search scope, a flag to ignore `node_modules`, and an option to specify a different config file name. ```typescript export interface TSConfckFindOptions { /** * A cache to improve performance for multiple calls in the same project * * Warning: You must clear this cache in case tsconfig files are added/removed during it's lifetime */ cache?: TSConfckCache; /** * project root dir, does not continue scanning outside of this directory. * * Improves performance but may lead to different results from native typescript when no tsconfig is found inside root */ root?: string; /** * set to true if you don't want to find tsconfig for files inside node_modules * * This is useful if you want to use the output with esbuild.transform as esbuild itself also ignores node_modules * * @default false */ ignoreNodeModules?: boolean; /** * Override the default name of the config file to find. * * Use `jsconfig.json` in projects that have typechecking for js files with jsconfig.json * * @default tsconfig.json */ configName?: string; } ``` -------------------------------- ### Find All Tsconfig Files Source: https://github.com/dominikg/tsconfck/blob/main/docs/api.md Asynchronously finds all tsconfig.json files within a specified directory. Supports custom options for skipping directories and specifying config file names. ```typescript /** * find all tsconfig.json files in dir * * @param dir - path to dir (absolute or relative to cwd) * @param options - options * @returns list of absolute paths to all found tsconfig.json files */ export function findAll(dir: string, options?: TSConfckFindAllOptions): Promise; ``` -------------------------------- ### Parse tsconfig.json Source: https://github.com/dominikg/tsconfck/blob/main/docs/api.md Use `parse` to process the nearest `tsconfig.json` file. It takes a filename and optional `TSConfckParseOptions`. The result includes the file path, parsed configuration, and details about extended or referenced configurations. ```typescript export function parse(filename: string, options?: TSConfckParseOptions): Promise; ``` -------------------------------- ### Parse tsconfig.json Source: https://github.com/dominikg/tsconfck/blob/main/docs/api.md Parses the closest tsconfig.json file. It accepts a file path and optional configurations, returning the parsed tsconfig content along with extended and solution information. ```APIDOC ## POST /api/parse ### Description Parses the closest tsconfig.json file. ### Method POST ### Endpoint /api/parse ### Parameters #### Query Parameters - **filename** (string) - Required - Path to a tsconfig .json or a source file or directory (absolute or relative to cwd). - **options** (TSConfckParseOptions) - Optional - Options for parsing the tsconfig file. Extends TSConfckFindOptions. #### Request Body ```json { "filename": "path/to/your/file.ts", "options": { "cache": { /* TSConfckCache object */ }, "root": "/path/to/project/root", "ignoreNodeModules": false, "configName": "tsconfig.json" } } ``` ### Response #### Success Response (200) - **TSConfckParseResult** - An object containing the parsed tsconfig details. - **tsconfigFile** (string) - Absolute path to the parsed tsconfig.json. - **tsconfig** (any) - The parsed tsconfig content, including merged values from extended configurations. - **solution** (TSConfckParseResult) - Optional - ParseResult for the parent solution. - **referenced** (TSConfckParseResult[]) - Optional - ParseResults for all tsconfig files referenced in a solution. - **extended** (TSConfckParseResult[]) - Optional - ParseResult for all tsconfig files, where each extends the next in the array. #### Response Example ```json { "example": { "tsconfigFile": "/path/to/your/tsconfig.json", "tsconfig": { "compilerOptions": { "target": "es2016" } }, "extended": [ { "tsconfigFile": "/path/to/base/tsconfig.json", "tsconfig": { "compilerOptions": { "module": "commonjs" } } } ] } } ``` ``` -------------------------------- ### Find Closest tsconfig.json Source: https://github.com/dominikg/tsconfck/blob/main/docs/api.md Use `find` to locate the nearest `tsconfig.json` file. It accepts a filename and optional options for caching, root directory, ignoring `node_modules`, and custom config file names. Returns the absolute path or null if not found. ```typescript export function find(filename: string, options?: TSConfckFindOptions): Promise; ``` -------------------------------- ### TSConfckParseResult Interface Source: https://github.com/dominikg/tsconfck/blob/main/docs/api.md Represents the result of parsing a `tsconfig.json` file. It contains the path to the config file, the parsed configuration object, and optional references to parent solutions or extended configurations. ```typescript export interface TSConfckParseResult { /** * absolute path to parsed tsconfig.json */ tsconfigFile: string; /** * parsed result, including merged values from extended */ tsconfig: any; /** * ParseResult for parent solution */ solution?: TSConfckParseResult; /** * ParseResults for all tsconfig files referenced in a solution */ referenced?: TSConfckParseResult[]; /** * ParseResult for all tsconfig files * * [a,b,c] where a extends b and b extends c */ extended?: TSConfckParseResult[]; } ``` -------------------------------- ### TSConfckCache Class Source: https://github.com/dominikg/tsconfck/blob/main/docs/api.md Manages a cache for parsed tsconfig results and file paths. Provides methods to clear the cache, check for cached configurations, retrieve cached configurations, and check/get parsed results for specific files. ```APIDOC ## TSConfckCache Class ### Description Manages caching for parsed tsconfig results and file paths to optimize performance. ### Methods - **clear()**: Clears the entire cache. Useful for long-running processes when tsconfig files may change. - **hasConfigPath(dir: string, configName?: string): boolean**: Checks if a cached closest config path exists for the given directory and optional config name. - **getConfigPath(dir: string, configName?: string): Promise | string | null**: Retrieves the cached closest tsconfig file path for the given directory. Throws an error if the cached value is an error. - **hasParseResult(file: string): boolean**: Checks if a parsed tsconfig result is cached for the given file. - **getParseResult(file: string): Promise | T**: Retrieves the cached parsed tsconfig result for the given file. Throws an error if the cached value is an error. ### Properties - **isRootFile** (boolean) - A flag used internally to distinguish between normal cache lookups and those initiated by the `parse()` API, differentiating from caches populated solely by `parseFile()`. ``` -------------------------------- ### TSConfckParseOptions Interface Source: https://github.com/dominikg/tsconfck/blob/main/docs/api.md Options for the `parse` function, which extend `TSConfckFindOptions`. These options allow for fine-tuning how the `tsconfig.json` file is located and parsed. ```typescript export interface TSConfckParseOptions extends TSConfckFindOptions { // same as find options } ``` -------------------------------- ### TSConfckParseNativeOptions Interface Source: https://github.com/dominikg/tsconfck/blob/main/docs/api.md Options for `parseNative`, extending `TSConfckParseOptions`. Includes `ignoreSourceFiles` to speed up parsing by skipping source file analysis, with caveats about output and reference resolution. ```typescript export interface TSConfckParseNativeOptions extends TSConfckParseOptions { /** * Set this option to true to force typescript to ignore all source files. * * This is faster - especially for large projects - but comes with 2 caveats * * 1) output tsconfig always has `files: [],include: []` instead of any real values configured. * 2) as a result of 1), it won't be able to resolve solution-style references and always return the closest tsconfig */ ignoreSourceFiles?: boolean; } ``` -------------------------------- ### toJson Function Source: https://github.com/dominikg/tsconfck/blob/main/docs/api.md Converts the content of a tsconfig.json file (provided as a string) into a standard JSON string. It handles the removal of comments and dangling commas. ```APIDOC ## toJson Function ### Description Converts the content of a `tsconfig.json` file into a regular JSON string, removing comments and dangling commas. ### Parameters #### Request Body - **tsconfigJson** (string) - Required - The content of the `tsconfig.json` file as a string. ### Returns - (string) - The content as a regular JSON string. ``` -------------------------------- ### TSConfckCache Class Source: https://github.com/dominikg/tsconfck/blob/main/docs/api.md A generic cache for storing parsed TypeScript configuration results. Provides methods to clear the cache, check for cached configurations, and retrieve parsed results. ```typescript export class TSConfckCache { /** * clear cache, use this if you have a long running process and tsconfig files have been added,changed or deleted */ clear(): void; /** * has cached closest config for files in dir * */ hasConfigPath(dir: string, configName?: string): boolean; /** * get cached closest tsconfig for files in dir * @throws {unknown} if cached value is an error */ getConfigPath(dir: string, configName?: string): Promise | string | null; /** * has parsed tsconfig for file * */ hasParseResult(file: string): boolean; /** * get parsed tsconfig for file * @throws {unknown} if cached value is an error */ getParseResult(file: string): Promise | T; /** * @param isRootFile a flag to check if current file which involking the parse() api, used to distinguish the normal cache which only parsed by parseFile() * */ } ``` -------------------------------- ### Convert Tsconfig to JSON Source: https://github.com/dominikg/tsconfck/blob/main/docs/api.md Converts the content of a tsconfig.json string into a regular JSON string. This utility removes comments and dangling commas. ```typescript /** * convert content of tsconfig.json to regular json * * @param tsconfigJson - content of tsconfig.json * @returns content as regular json, comments and dangling commas have been replaced with whitespace */ export function toJson(tsconfigJson: string): string; ``` -------------------------------- ### TSConfckParseError Class Source: https://github.com/dominikg/tsconfck/blob/main/docs/api.md Custom error class for parsing `tsconfig.json` files. It includes an error message, code, the path to the problematic `tsconfig.json` file, and the original cause of the error. ```typescript export class TSConfckParseError extends Error { /** * * @param message - error message * @param code - error code * @param tsconfigFile - path to tsconfig file * @param cause - cause of this error */ constructor(message: string, code: string, tsconfigFile: string, cause: Error | null); /** * error code * */ code: string; /** * error cause * */ cause: Error | undefined; /** * absolute path of tsconfig file where the error happened * */ tsconfigFile: string; } ``` -------------------------------- ### TSConfckParseNativeResult Interface Source: https://github.com/dominikg/tsconfck/blob/main/docs/api.md Result structure for `parseNative`. It includes the config file path, parsed config, and optional solution/referenced results. It also contains the full output of `ts.parseJsonConfigFileContent`. ```typescript export interface TSConfckParseNativeResult { /** * absolute path to parsed tsconfig.json */ tsconfigFile: string; /** * parsed result, including merged values from extended and normalized */ tsconfig: any; /** * ParseResult for parent solution */ solution?: TSConfckParseNativeResult; /** * ParseNativeResults for all tsconfig files referenced in a solution */ referenced?: TSConfckParseNativeResult[]; /** * full output of ts.parseJsonConfigFileContent */ result: any; } ``` -------------------------------- ### TSConfckParseNativeError Class Source: https://github.com/dominikg/tsconfck/blob/main/docs/api.md Represents a native TypeScript parsing error. Use this class to handle errors during tsconfig.json parsing. ```typescript export class TSConfckParseNativeError extends Error { /** * * @param diagnostic - diagnostics of ts * @param tsconfigFile - file that errored * @param result - parsed result, if any */ constructor(diagnostic: TSDiagnosticError, tsconfigFile: string, result: any | null); /** * code of typescript diagnostic, prefixed with "TS " * */ code: string; /** * full ts diagnostic that caused this error * */ diagnostic: TSDiagnosticError; /** * native result if present, contains all errors in result.errors * */ result: any | undefined; /** * absolute path of tsconfig file where the error happened * */ tsconfigFile: string; } ``` -------------------------------- ### TSConfckParseNativeError Class Source: https://github.com/dominikg/tsconfck/blob/main/docs/api.md Represents a native TypeScript parsing error encountered by TSConfck. It includes details about the diagnostic, the affected tsconfig file, and any parsing results. ```APIDOC ## TSConfckParseNativeError Class ### Description Represents a native TypeScript parsing error. It stores diagnostic information, the tsconfig file path, and the parsing result. ### Properties - **code** (string) - The TypeScript diagnostic code, prefixed with "TS ". - **diagnostic** (TSDiagnosticError) - The full TypeScript diagnostic that caused this error. - **result** (any | undefined) - The native parsing result, which may contain an `errors` array. - **tsconfigFile** (string) - The absolute path of the tsconfig file where the error occurred. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.