UNPKG

resolve-tspaths

Version:

Transform path mappings in your compiled Typescript code

24 lines (23 loc) 916 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.computeAliases = computeAliases; const path_1 = require("path"); const errors_1 = require("../utils/errors"); /** * Compute the alias paths provided by the tsconfig. */ function computeAliases(basePath, paths) { const regex = /\*$/; const aliases = Object.keys(paths).map((alias) => ({ alias, prefix: alias.replace(regex, ""), aliasPaths: paths[alias].map((path) => (0, path_1.resolve)(basePath, path.replace(regex, ""))), })); // Ensure that aliases do not start with a relative path // This will lead to unknown behaviour, and why would you use ./ or ../ as an alias anyway? for (const { alias } of aliases) { if (alias.startsWith("./") || alias.startsWith("../")) throw new errors_1.InvalidAliasError(computeAliases.name, alias); } return aliases; }