UNPKG

@stryke/fs

Version:

A package containing various file system utilities that expand the functionality of NodeJs's built-in `fs` module.

28 lines (27 loc) 1.36 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.loadTsConfig = loadTsConfig; var _exists = require("@stryke/path/exists"); var _filePathFns = require("@stryke/path/file-path-fns"); var _joinPaths = require("@stryke/path/join-paths"); var _defu = _interopRequireDefault(require("defu")); var _mlly = require("mlly"); var _json = require("./json.cjs"); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } async function loadTsConfig(e = process.cwd()) { let s = e.endsWith(".json") ? e : (0, _joinPaths.joinPaths)(e, "tsconfig.json"); if (!(0, _exists.existsSync)(s) && (s = await (0, _mlly.resolvePath)(e, { url: require('url').pathToFileURL(__filename).toString() }), !(0, _exists.existsSync)(s))) throw new Error(`tsconfig.json not found at ${s}. Please ensure the file exists.`); let o = await (0, _json.readJsonFile)(s); if (o?.compilerOptions?.baseUrl && (o.compilerOptions.baseUrl = (0, _joinPaths.joinPaths)((0, _filePathFns.findFilePath)(s), o.compilerOptions.baseUrl)), o?.extends) { const f = Array.isArray(o.extends) ? o.extends : [o.extends]; for (const m of f) { const n = await loadTsConfig((0, _joinPaths.joinPaths)((0, _filePathFns.findFilePath)(s), m)); n && (o = (0, _defu.default)(o, n ?? {})); } } return o.extends = void 0, o; }