Skip to content

Conversation

@lightninglu10
Copy link
Contributor

Summary

Replaces the fragile regex-based tsconfig.json parsing with the well-tested tsconfig-paths library.

Problem

The previous implementation used regex to parse tsconfig.json:

const pathsMatch = tsconfigContent.match(/"paths"\s*:\s*\{([^}]+)\}/);

This approach had several limitations:

  • Could fail on multi-line path definitions with nested braces
  • Didn't follow the extends field to resolve inherited configurations
  • Couldn't handle all JSON5 syntax TypeScript allows (comments, trailing commas)

Solution

Use the tsconfig-paths library which:

  • Uses json5 parser to handle comments and trailing commas
  • Properly resolves extends chains
  • Is well-tested and maintained
  • Handles complex path patterns correctly

Changes

Test plan

  • npm run build passes
  • npm test passes (104 tests)
  • Tested with tsconfig files containing comments and extends

🤖 Generated with Claude Code

Replace fragile regex-based tsconfig.json parsing with the tsconfig-paths
library which properly handles:
- JSON with comments (TypeScript's JSON5-like syntax)
- The "extends" field to resolve inherited configurations
- Complex path patterns and multi-line definitions

Also moves fs/path to top-level imports.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@lightninglu10 lightninglu10 force-pushed the fix/use-tsconfig-paths-library branch from 86ab625 to 4dd57ea Compare November 29, 2025 20:00
Tests cover:
- Basic path alias parsing
- JSON with comments (single-line, multi-line, trailing commas)
- Extended tsconfig files (extends field resolution)
- Webpack resolve.alias taking precedence
- Next.js fallback behavior
- Edge cases (missing tsconfig, no compilerOptions, multiple targets)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@lightninglu10 lightninglu10 self-assigned this Dec 1, 2025
@lightninglu10 lightninglu10 merged commit 95f1f88 into main Dec 1, 2025
7 checks passed
@lightninglu10 lightninglu10 deleted the fix/use-tsconfig-paths-library branch December 1, 2025 01:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants