UNPKG

@kya-os/mcp-i

Version:

The TypeScript MCP framework with identity features built-in

41 lines (40 loc) 1.73 kB
"use strict"; // Based on https://gist.github.com/nerdyman/2f97b24ab826623bff9202750013f99e var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.resolveTsconfigPathsToAlias = resolveTsconfigPathsToAlias; const path_1 = __importDefault(require("path")); const fs_1 = require("fs"); const fs_utils_1 = require("../../utils/fs-utils"); /** * Resolve tsconfig.json paths to Webpack aliases * @param {string} tsconfigPath - Path to tsconfig * @param {string} webpackConfigBasePath - Path from tsconfig to Webpack config to create absolute aliases * @return {object} - Webpack alias config */ function resolveTsconfigPathsToAlias({ tsconfigPath = "./tsconfig.json", } = {}) { if (!(0, fs_1.existsSync)(tsconfigPath)) { return {}; } const tsconfigContent = (0, fs_1.readFileSync)(tsconfigPath, "utf-8"); const [parsedTsconfig, parsingError] = (0, fs_utils_1.parseJson)(tsconfigContent); if (parsingError) { console.error(`Error parsing tsconfig.json: ${parsingError.message} at ${tsconfigPath}`); console.log(tsconfigContent); return {}; } if (!parsedTsconfig.compilerOptions || !parsedTsconfig.compilerOptions.paths) { return {}; } const paths = parsedTsconfig.compilerOptions.paths; const aliases = {}; Object.keys(paths).forEach((item) => { const key = item.replace("/*", ""); const value = path_1.default.resolve(paths[item][0].replace("/*", "").replace("*", "")); aliases[key] = value; }); return aliases; }