Skip to content

Commit

Permalink
chore: optimize ts lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
spence-s committed Apr 3, 2023
1 parent 03e5eaa commit acc89b4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
15 changes: 5 additions & 10 deletions lib/options-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import prettier from 'prettier';
import semver from 'semver';
import {cosmiconfig, defaultLoaders} from 'cosmiconfig';
import micromatch from 'micromatch';
import JSON5 from 'json5';
import stringify from 'json-stable-stringify-without-jsonify';
import {Legacy} from '@eslint/eslintrc';
import createEsmUtils from 'esm-utils';
Expand Down Expand Up @@ -159,21 +158,17 @@ const handleTSConfig = async options => {
options.tsConfig = {};
options.tsConfigPath = '';

const {project: tsConfigProjectPath, tsconfigRootDir} = options.parserOptions || {};
const {project: tsConfigProjectPath} = options.parserOptions || {};

if (tsConfigProjectPath) {
options.tsConfigPath = path.resolve(options.cwd, tsConfigProjectPath);
options.tsConfig = tsConfigResolvePaths(getTsconfig(options.tsConfigPath).config, options.tsConfigPath);
} else {
const tsConfigExplorer = cosmiconfig([], {
searchPlaces: ['tsconfig.json'],
loaders: {'.json': (_, content) => JSON5.parse(content)},
stopDir: tsconfigRootDir,
});
const searchResults = (await tsConfigExplorer.search(options.filePath)) || {};
options.tsConfigPath = searchResults.filepath;
const {config: tsConfig, path: filepath} = getTsconfig(options.filePath) || {};
options.tsConfigPath = filepath;
options.tsConfig = tsConfig;
if (options.tsConfigPath) {
options.tsConfig = tsConfigResolvePaths(getTsconfig(options.tsConfigPath).config, options.tsConfigPath);
options.tsConfig = tsConfigResolvePaths(tsConfig, options.tsConfigPath);
} else {
delete options.tsConfig;
}
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@
"globby": "^13.1.2",
"imurmurhash": "^0.1.4",
"json-stable-stringify-without-jsonify": "^1.0.1",
"json5": "^2.2.1",
"lodash-es": "^4.17.21",
"meow": "^11.0.0",
"micromatch": "^4.0.5",
Expand All @@ -94,7 +93,8 @@
"semver": "^7.3.8",
"slash": "^5.0.0",
"to-absolute-glob": "^2.0.2",
"typescript": "^5.0.3"
"typescript": "^5.0.3",
"xo": "file:."
},
"devDependencies": {
"ava": "^5.1.0",
Expand Down

0 comments on commit acc89b4

Please sign in to comment.