UNPKG

@trapi/utils

Version:

Utils library package for the trapi infrastructure.

30 lines 1.54 kB
"use strict"; /* * Copyright (c) 2021. * Author Peter Placzek (tada5hi) * For the full copyright and license information, * view the LICENSE file that was distributed with this source code. */ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getCompilerOptions = void 0; const typescript_1 = require("typescript"); const fs_1 = __importDefault(require("fs")); const path_1 = __importDefault(require("path")); const object_1 = require("./object"); function getCompilerOptions(filePath, fileName = 'tsconfig.json') { const cwd = process.cwd(); // get absolute file path let fullPath = filePath ? path_1.default.isAbsolute(filePath) ? filePath : path_1.default.join(cwd, filePath) : path_1.default.join(cwd, fileName); // check permission to read file fs_1.default.accessSync(fullPath, fs_1.default.constants.R_OK); const fileStats = fs_1.default.lstatSync(fullPath); fullPath = fileStats.isDirectory() ? path_1.default.join(fullPath, fileName) : fullPath; const raw = fs_1.default.readFileSync(fullPath, { encoding: 'utf-8' }); const content = JSON.parse(raw); return (0, object_1.hasOwnProperty)(content, 'compilerOptions') ? (0, typescript_1.convertCompilerOptionsFromJson)(content.compilerOptions, cwd).options : {}; } exports.getCompilerOptions = getCompilerOptions; //# sourceMappingURL=typescript.js.map