Skip to content

feat: add tsconfig.json extends resolution to project detection #345

@jonaslagoni

Description

@jonaslagoni

Enhancement Request

The automatic project detection in detectTypeScriptImportExtension currently reads tsconfig.json directly but does not resolve the extends field. This means projects using base configurations (e.g., "extends": "@tsconfig/node18/tsconfig.json") won't have their moduleResolution detected if it's defined in the parent config.

Background

Introduced in PR #344, the basic detection works for many cases where moduleResolution is directly in tsconfig.json. However, many real-world TypeScript projects use base configurations via the extends field.

Scope

Add recursive tsconfig resolution to:

  1. Read the extends field from tsconfig.json
  2. Load and parse the base config (can be a local file or npm package)
  3. Merge compilerOptions with proper precedence (child overrides parent)
  4. Support multiple levels of inheritance (base can extend another base)

Example Use Cases

Projects using:

  • @tsconfig/node18, @tsconfig/node20, etc.
  • ./tsconfig.base.json in monorepos
  • Custom shared configs

Implementation Notes

  • Handle both relative paths (./tsconfig.base.json) and npm packages (@tsconfig/node18/tsconfig.json)
  • Use proper Node.js resolution for npm packages
  • Implement proper merge logic (arrays override, objects shallow merge)
  • Add tests for common scenarios

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions