This is a highly configurable module resolution library used as the core resolver inside webpack. It implements a plugin pipeline based on the tapable hook system, allowing third-party extensions. The library supports standard Node.js resolution (relative, absolute, node_modules), package.json exports/imports fields, TypeScript tsconfig path mapping, aliases, symlinks, PnP (Yarn Berry), and browser field resolution. The codebase is meticulously optimized for performance with custom caching layers (CachedInputFileSystem, per-field WeakMap caches, char-code-based path classification) and includes extensive benchmarks tracked by CodSpeed. It has broad runtime support including Node.js, Deno, Bun, and browser environments via shims. The architecture is modular with each resolution step implemented as a separate plugin, making it both extensible and testable.
typescript-transform-paths is a TypeScript transformer plugin that resolves module specifiers using tsconfig path mappings and custom transformation rules. It operates during TypeScript compilation to rewrite import/export paths in emitted JavaScript and declaration files, supporting features like virtual directories (rootDirs), exclusion patterns, and type-only import elision. The architecture centers around a visitor pattern that traverses the AST, resolving module names via TypeScript's resolver and adjusting paths based on compiler options. Key entry points include the main transformer (src/transformer.ts) and an Nx adapter (src/plugins/nx.ts). The tool integrates with ts-patch, ts-node, or build systems to enable path transformation without requiring changes to source code.
This is a mature Node.js library that makes TypeScript's compile-time path aliases (tsconfig/jsconfig 'paths') work at runtime in plain Node. The code confirms the core claim: src/register.ts patches Module._resolveFilename to intercept module requests, resolves them through tsconfig path mappings, and falls back to Node's original resolution when no mapping matches. The architecture is a clean pipeline: config discovery and loading (tsconfig-loader.ts walks directories, parses JSON5 with comments/trailing commas, resolves 'extends' chains including array form and node_modules packages), mapping construction (mapping-entry.ts sorts patterns by longest prefix and resolves paths to absolute form once), candidate generation (try-path.ts builds file/extension/package.json-main/index probe lists), and matching (match-path-sync.ts and match-path-async.ts) over an injectable filesystem abstraction (filesystem.ts). The public API surface includes register(), loadConfig(), createMatchPath/createMatchPathAsync, and matchFromAbsolutePaths/matchFromAbsolutePathsAsync, plus the 'tsconfig-paths/register' require-hook for CLI usage (node -r tsconfig-paths/register). Data flows from tsconfig.json on disk -> parsed config -> absolute mapping entries -> probed physical paths on each module load. All filesystem operations (fileExists, readJson) are injectable, which makes the test suite pure and deterministic. Runtime dependencies are minimal (json5, minimist, strip-bom), with no network calls, daemons, or persistent state. Craftsmanship is high and the modules are small, single-purpose, and individually extractable. Non-obvious details include: pre-sorting mappings once to avoid per-request sorting; matchStar enforcing a one-character minimum star match; careful async recursion that avoids double-calling callbacks (a real bug that surfaced in tsconfig-paths-webpack-plugin); a suffix-regex that converts .js/.mjs/.cjs requests to .ts/.tsx probes; and a table-driven fixture file (src/__tests__/data/match-path-data.ts) whose 20+ vectors drive both the sync and async test suites, forcing behavioral parity. Code is conservative by design (ES5 target, CommonJS) to support old Node, and strict ESLint rules enforce explicit typing and style. The project is actively maintained (recent commits, an [Unreleased] changelog section, CI matrix on Node 14/16/18). However, the dev toolchain shows measurable drift: TypeScript 4.5, Jest 27, @types/node 6, GitHub Actions versions from 2019-2021, and 'engines' still claiming node >=6 (long EOL). The runtime logic itself remains current and sound; risk is low, but modernization of tooling is overdue. With 1906 stars and 114 open issues, this is the de facto standard for tsconfig paths resolution, relied on by ts-node, mocha setups, and the tsconfig-paths-webpack-plugin.