Merge pull request #13937 from strapi/fix/ts-false-positive-get-config-path

Fix false positive results for ts utils' getConfigPath
This commit is contained in:
Jean-Sébastien Herbaux 2022-08-02 17:56:48 +02:00 committed by GitHub
commit f7a7098ef2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 4 deletions

View File

@ -1,9 +1,17 @@
'use strict'; 'use strict';
const path = require('path');
const ts = require('typescript'); const ts = require('typescript');
const DEFAULT_TS_CONFIG_FILENAME = 'tsconfig.json'; const DEFAULT_TS_CONFIG_FILENAME = 'tsconfig.json';
module.exports = (dir, filename = DEFAULT_TS_CONFIG_FILENAME) => { module.exports = (dir, { filename = DEFAULT_TS_CONFIG_FILENAME, ancestorsLookup = false } = {}) => {
return ts.findConfigFile(dir, ts.sys.fileExists, filename); 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} * @returns {boolean}
*/ */
module.exports = (dir, filename = undefined) => { module.exports = (dir, filename = undefined) => {
const filePath = getConfigPath(dir, filename); const filePath = getConfigPath(dir, { filename });
return fse.pathExistsSync(filePath); return fse.pathExistsSync(filePath);
}; };

View File

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