or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

file-matching.mdindex.mdpath-resolution.md
tile.json

index.mddocs/

get-tsconfig

get-tsconfig is a zero-dependency TypeScript library for finding and parsing tsconfig.json files. It provides comprehensive tools for locating TypeScript configuration files through directory traversal, parsing them with support for JSON comments and dangling commas, and resolving extends chains. The library includes advanced features like file matching and path resolution, making it ideal for TypeScript tooling and build systems.

Package Information

  • Package Name: get-tsconfig
  • Package Type: npm
  • Language: TypeScript
  • Installation: npm install get-tsconfig

Core Imports

import { getTsconfig, parseTsconfig, createFilesMatcher, createPathsMatcher, type TsConfigResult, type TsConfigJsonResolved, type FileMatcher, type Cache } from "get-tsconfig";

For CommonJS:

const { getTsconfig, parseTsconfig, createFilesMatcher, createPathsMatcher } = require("get-tsconfig");

Basic Usage

import { getTsconfig, parseTsconfig } from "get-tsconfig";

// Find and parse tsconfig.json starting from current directory
const result = getTsconfig();
if (result) {
  console.log("Found tsconfig at:", result.path);
  console.log("Compiler options:", result.config.compilerOptions);
}

// Find tsconfig.json from a specific path
const configFromPath = getTsconfig("./src/components");

// Parse a specific tsconfig file
const customConfig = parseTsconfig("./tsconfig.build.json");

Architecture

get-tsconfig is built around several key components:

  • Core Functions: getTsconfig and parseTsconfig for finding and parsing TypeScript configurations
  • File Matching: createFilesMatcher for determining which files match tsconfig include/exclude patterns
  • Path Resolution: createPathsMatcher for resolving module specifiers using compilerOptions.paths
  • Extends Resolution: Automatic resolution of extends chains in tsconfig files
  • Caching System: Optional caching for improved performance in repeated operations

Capabilities

TSConfig Discovery and Parsing

Core functionality for finding and parsing TypeScript configuration files with full support for extends resolution and JSON with comments.

function getTsconfig(
  searchPath?: string,
  configName?: string,
  cache?: Cache
): TsConfigResult | null;

function parseTsconfig(
  tsconfigPath: string,
  cache?: Cache<string>
): TsConfigJsonResolved;

interface TsConfigResult {
  path: string;
  config: TsConfigJsonResolved;
}

type TsConfigJsonResolved = Except<TsConfigJson, 'extends'>;
type Cache<T = any> = Map<string, T>;

File Pattern Matching

Determines whether files match TypeScript configuration include/exclude patterns, essential for build tools and file processors.

function createFilesMatcher(
  tsconfig: TsConfigResult,
  caseSensitivePaths?: boolean
): FileMatcher;

type FileMatcher = (filePath: string) => (TsConfigJsonResolved | undefined);

File Matching

Module Path Resolution

Resolves module specifiers using TypeScript's path mapping configuration, compatible with compilerOptions.paths and baseUrl settings.

function createPathsMatcher(
  tsconfig: TsConfigResult
): ((specifier: string) => string[]) | null;

Path Resolution

Types

// Re-exported from type-fest for complete TypeScript configuration schema
type TsConfigJson = {
  extends?: string | string[];
  compilerOptions?: CompilerOptions;
  files?: string[];
  include?: string[];
  exclude?: string[];
  references?: ProjectReference[];
  // ... complete TypeScript configuration schema
};

// Resolved configuration with extends processed
type TsConfigJsonResolved = Except<TsConfigJson, 'extends'>;

// Result object from getTsconfig
interface TsConfigResult {
  /** The path to the tsconfig.json file */
  path: string;
  /** The resolved tsconfig.json file */
  config: TsConfigJsonResolved;
}

// Generic cache type for performance optimization
type Cache<value = any> = Map<string, value>;

// File matcher function type
type FileMatcher = (filePath: string) => (TsConfigJsonResolved | undefined);