UNPKG

resolve-tspaths

Version:

Transform path mappings in your compiled Typescript code

36 lines (35 loc) 2.2 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.resolveTsPaths = resolveTsPaths; const constants_1 = require("./constants"); const loadTSConfig_1 = require("./steps/loadTSConfig"); const resolvePaths_1 = require("./steps/resolvePaths"); const computeAliases_1 = require("./steps/computeAliases"); const getFilesToProcess_1 = require("./steps/getFilesToProcess"); const generateChanges_1 = require("./steps/generateChanges"); const applyChanges_1 = require("./steps/applyChanges"); /** * Convert Typescript path aliases to proper relative paths * in your transpiled JavaScript code. */ function resolveTsPaths() { return __awaiter(this, arguments, void 0, function* (options = {}) { var _a, _b; const { project = "tsconfig.json", src = "src", ext = constants_1.DEFAULT_EXTENSIONS, out, } = options; const tsConfig = (0, loadTSConfig_1.loadTSConfig)(project); const programPaths = (0, resolvePaths_1.resolvePaths)({ project, src, out }, tsConfig); const aliases = (0, computeAliases_1.computeAliases)(programPaths.basePath, (_b = (_a = tsConfig === null || tsConfig === void 0 ? void 0 : tsConfig.options) === null || _a === void 0 ? void 0 : _a.paths) !== null && _b !== void 0 ? _b : {}); const files = (0, getFilesToProcess_1.getFilesToProcess)(programPaths.outPath, ext); const changes = (0, generateChanges_1.generateChanges)(files, aliases, programPaths); (0, applyChanges_1.applyChanges)(changes); }); }