Fix ts utils' getConfigPath returning false positive due to ancestors lookup

This commit is contained in:
Convly 2022-08-02 10:52:10 +02:00
parent 7039c0d228
commit 20259d944d
3 changed files with 12 additions and 4 deletions

View File

@ -1,9 +1,17 @@
'use strict';
const path = require('path');
const ts = require('typescript');
const DEFAULT_TS_CONFIG_FILENAME = 'tsconfig.json';
module.exports = (dir, filename = DEFAULT_TS_CONFIG_FILENAME) => {
return ts.findConfigFile(dir, ts.sys.fileExists, filename);
module.exports = (dir, { filename = DEFAULT_TS_CONFIG_FILENAME, ancestorsLookup = false } = {}) => {
const dirAbsolutePath = path.resolve(dir);
const configFilePath = ts.findConfigFile(dirAbsolutePath, ts.sys.fileExists, filename);
if (!configFilePath || ancestorsLookup) {
return configFilePath;
}
return configFilePath.startsWith(dirAbsolutePath);
};

View File

@ -11,7 +11,7 @@ const getConfigPath = require('./get-config-path');
* @returns {boolean}
*/
module.exports = (dir, filename = undefined) => {
const filePath = getConfigPath(dir, filename);
const filePath = getConfigPath(dir, { filename });
return fse.pathExistsSync(filePath);
};

View File

@ -11,7 +11,7 @@ const getConfigPath = require('./get-config-path');
* @returns {Promise<boolean>}
*/
module.exports = (dir, filename = undefined) => {
const filePath = getConfigPath(dir, filename);
const filePath = getConfigPath(dir, { filename });
return fse.pathExists(filePath);
};