UNPKG

eslint-config-galex

Version:
39 lines (38 loc) 1.59 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getTopLevelTsConfig = void 0; const fs_1 = require("fs"); const path_1 = require("path"); const typescript_1 = __importDefault(require("typescript")); const defaultTsConfigName = 'tsconfig.json'; const getTopLevelTsConfig = ({ cwd, tsConfigPath, }) => { const resolveArgs = tsConfigPath ? [tsConfigPath] : [cwd, cwd.includes('.json') ? '' : defaultTsConfigName]; const path = (0, path_1.resolve)(...resolveArgs); const tsConfigName = tsConfigPath ? tsConfigPath.split('/').pop() : defaultTsConfigName; if (!tsConfigName) { throw new Error(`missing tsConfigName`); } const tsConfigRaw = (0, fs_1.readFileSync)(path, 'utf-8'); const tsConfig = typescript_1.default.convertToObject(typescript_1.default.parseJsonText(tsConfigName, tsConfigRaw), []); // really only thing we need from the config if (tsConfig.compilerOptions) { return tsConfig; } // no compilerOptions, check for parent configs if (tsConfig.extends) { return (0, exports.getTopLevelTsConfig)({ // on current path, replace tsConfigName with nothing to prevent having // an path with 2x file names cwd: (0, path_1.resolve)(path.replace(tsConfigName, ''), tsConfig.extends), }); } return tsConfig; }; exports.getTopLevelTsConfig = getTopLevelTsConfig;