UNPKG

@visulima/tsconfig

Version:

Find and/or parse the tsconfig.json file from a directory path.

75 lines (70 loc) 2.44 kB
'use strict'; Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } }); const fs = require('@visulima/fs'); const error = require('@visulima/fs/error'); const implicitBaseUrlSymbol = require('./implicitBaseUrlSymbol-ClUn71e4.cjs'); var __defProp = Object.defineProperty; var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); const TsConfigFileCache = /* @__PURE__ */ new Map(); const findTsConfig = /* @__PURE__ */ __name(async (cwd, options = {}) => { const configFileName = options.configFileName ?? "tsconfig.json"; let filePath = await fs.findUp(configFileName, { ...cwd && { cwd }, type: "file" }); if (!filePath) { filePath = await fs.findUp("jsconfig.json", { ...cwd && { cwd }, type: "file" }); } if (!filePath) { throw new error.NotFoundError("No such file or directory, for '" + configFileName + "' or 'jsconfig.json' found."); } const cache = options.cache && typeof options.cache !== "boolean" ? options.cache : TsConfigFileCache; if (options.cache && cache.has(filePath)) { return cache.get(filePath); } const output = { config: implicitBaseUrlSymbol.readTsConfig(filePath, { tscCompatible: options.tscCompatible }), path: filePath }; if (options.cache) { cache.set(filePath, output); } return output; }, "findTsConfig"); const findTsConfigSync = /* @__PURE__ */ __name((cwd, options = {}) => { const configFileName = options.configFileName ?? "tsconfig.json"; let filePath = fs.findUpSync(configFileName, { ...cwd && { cwd }, type: "file" }); if (!filePath) { filePath = fs.findUpSync("jsconfig.json", { ...cwd && { cwd }, type: "file" }); } if (!filePath) { throw new error.NotFoundError("No such file or directory, for '" + configFileName + "' or 'jsconfig.json' found."); } const cache = options.cache && typeof options.cache !== "boolean" ? options.cache : TsConfigFileCache; if (options.cache && cache.has(filePath)) { return cache.get(filePath); } const output = { config: implicitBaseUrlSymbol.readTsConfig(filePath, { tscCompatible: options.tscCompatible }), path: filePath }; if (options.cache) { cache.set(filePath, output); } return output; }, "findTsConfigSync"); exports.findTsConfig = findTsConfig; exports.findTsConfigSync = findTsConfigSync;