@@ -2,7 +2,6 @@ import {existsSync, promises as fs} from 'node:fs';
22import process from 'node:process' ;
33import os from 'node:os' ;
44import path from 'node:path' ;
5- import { createRequire } from 'node:module' ;
65import arrify from 'arrify' ;
76import { mergeWith , flow , pick } from 'lodash-es' ;
87import { findUpSync } from 'find-up' ;
@@ -11,12 +10,12 @@ import prettier from 'prettier';
1110import semver from 'semver' ;
1211import { cosmiconfig , defaultLoaders } from 'cosmiconfig' ;
1312import micromatch from 'micromatch' ;
14- import JSON5 from 'json5' ;
1513import stringify from 'json-stable-stringify-without-jsonify' ;
1614import { Legacy } from '@eslint/eslintrc' ;
1715import createEsmUtils from 'esm-utils' ;
1816import MurmurHash3 from 'imurmurhash' ;
1917import slash from 'slash' ;
18+ import { getTsconfig } from 'get-tsconfig' ;
2019import {
2120 DEFAULT_IGNORES ,
2221 DEFAULT_EXTENSION ,
@@ -159,26 +158,20 @@ const handleTSConfig = async options => {
159158 options . tsConfig = { } ;
160159 options . tsConfigPath = '' ;
161160
162- const { project : tsConfigProjectPath , tsconfigRootDir } = options . parserOptions || { } ;
161+ const { project : tsConfigProjectPath } = options . parserOptions || { } ;
163162
164163 if ( tsConfigProjectPath ) {
165164 options . tsConfigPath = path . resolve ( options . cwd , tsConfigProjectPath ) ;
166- options . tsConfig = JSON5 . parse ( await fs . readFile ( options . tsConfigPath ) ) ;
165+ options . tsConfig = tsConfigResolvePaths ( getTsconfig ( options . tsConfigPath ) . config , options . tsConfigPath ) ;
167166 } else {
168- const tsConfigExplorer = cosmiconfig ( [ ] , {
169- searchPlaces : [ 'tsconfig.json' ] ,
170- loaders : { '.json' : ( _ , content ) => JSON5 . parse ( content ) } ,
171- stopDir : tsconfigRootDir ,
172- } ) ;
173- const searchResults = ( await tsConfigExplorer . search ( options . filePath ) ) || { } ;
174- options . tsConfigPath = searchResults . filepath ;
175- options . tsConfig = searchResults . config ;
176- }
177-
178- if ( options . tsConfig ) {
179- // If the tsconfig extends from another file, we need to ensure that the file is covered by the tsconfig
180- // or not. The basefile could have includes/excludes/files properties that should be applied to the final tsconfig representation.
181- options . tsConfig = await recursiveBuildTsConfig ( options . tsConfig , options . tsConfigPath ) ;
167+ const { config : tsConfig , path : filepath } = getTsconfig ( options . filePath ) || { } ;
168+ options . tsConfigPath = filepath ;
169+ options . tsConfig = tsConfig ;
170+ if ( options . tsConfigPath ) {
171+ options . tsConfig = tsConfigResolvePaths ( tsConfig , options . tsConfigPath ) ;
172+ } else {
173+ delete options . tsConfig ;
174+ }
182175 }
183176
184177 let hasMatch ;
@@ -637,46 +630,6 @@ const getOptionGroups = async (files, options) => {
637630 return optionGroups ;
638631} ;
639632
640- async function recursiveBuildTsConfig ( tsConfig , tsConfigPath ) {
641- tsConfig = tsConfigResolvePaths ( tsConfig , tsConfigPath ) ;
642-
643- if ( ! tsConfig . extends || ( typeof tsConfig . extends === 'string' && tsConfig . extends . includes ( 'node_modules' ) ) ) {
644- return tsConfig ;
645- }
646-
647- // If any of the following are missing, then we need to look up the base config as it could apply
648- const require = createRequire ( tsConfigPath ) ;
649-
650- let basePath ;
651- try {
652- basePath = require . resolve ( tsConfig . extends ) ;
653- } catch ( error ) {
654- // Tsconfig resolution is odd, It allows behavior that is not exactly like node resolution
655- // therefore we attempt to smooth this out here with this hack
656- try {
657- basePath = require . resolve ( path . join ( tsConfig . extends , 'tsconfig.json' ) ) ;
658- } catch {
659- // Throw the orginal resolution error to let the user know their extends block is invalid
660- throw error ;
661- }
662- }
663-
664- const baseTsConfig = JSON5 . parse ( await fs . readFile ( basePath ) ) ;
665-
666- delete tsConfig . extends ;
667-
668- tsConfig = {
669- compilerOptions : {
670- ...baseTsConfig . compilerOptions ,
671- ...tsConfig . compilerOptions ,
672- } ,
673- ...baseTsConfig ,
674- ...tsConfig ,
675- } ;
676-
677- return recursiveBuildTsConfig ( tsConfig , basePath ) ;
678- }
679-
680633// Convert all include, files, and exclude to absolute paths
681634// and or globs. This works because ts only allows simple glob subset
682635const tsConfigResolvePaths = ( tsConfig , tsConfigPath ) => {
0 commit comments