UNPKG

resolve-tspaths

Version:

Transform path mappings in your compiled Typescript code

25 lines (24 loc) 1.36 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.resolvePaths = resolvePaths; const path_1 = require("path"); const errors_1 = require("../utils/errors"); /** * Resolve paths provided to the program to absolute paths. */ function resolvePaths(options, tsConfig) { var _a, _b, _c, _d, _e; const { baseUrl = "", outDir, paths } = (_a = tsConfig.options) !== null && _a !== void 0 ? _a : {}; const out = (_b = options.out) !== null && _b !== void 0 ? _b : outDir; if (!out) { throw new errors_1.StepError(resolvePaths.name, `Output directory must be specified using either the --out option or in tsconfig`); } if (!paths) throw new errors_1.TSConfigPropertyError(resolvePaths.name, "compilerOptions.paths"); const configFile = (0, path_1.resolve)(process.cwd(), options.project); const configPath = (0, path_1.dirname)(configFile); const basePath = (0, path_1.resolve)(configPath, baseUrl); const srcPath = (0, path_1.resolve)((_e = (_c = options.src) !== null && _c !== void 0 ? _c : (_d = tsConfig === null || tsConfig === void 0 ? void 0 : tsConfig.options) === null || _d === void 0 ? void 0 : _d.rootDir) !== null && _e !== void 0 ? _e : "src"); const outPath = (0, path_1.resolve)(out); return { basePath, configPath, configFile, srcPath, outPath }; }