UNPKG

@nxworker/workspace

Version:

Nx plugin providing generators for managing workspace files, including the move-file generator for safely moving files between projects while updating all imports

48 lines (47 loc) 1.74 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "getProjectImportPath", { enumerable: true, get: function() { return getProjectImportPath; } }); const _readcompilerpaths = require("./read-compiler-paths"); const _tofirstpath = require("./to-first-path"); const _pointstoprojectindex = require("./points-to-project-index"); const _iswildcardalias = require("./is-wildcard-alias"); /** * Resolves a wildcard alias to the project-specific alias string. * * @param alias - The alias key from tsconfig paths * @param sourceRoot - Source root of the project * @param projectName - Fallback project name when the directory name is missing * @returns The resolved alias string */ function resolveWildcardAlias(alias, sourceRoot, projectName) { const projectDirName = sourceRoot.split('/').pop(); return alias.replace(/\*/g, projectDirName || projectName); } function getProjectImportPath(tree, projectName, project) { const paths = (0, _readcompilerpaths.readCompilerPaths)(tree); if (!paths) { return null; } const sourceRoot = project.sourceRoot || project.root; for (const [alias, pathEntry] of Object.entries(paths)){ const pathStr = (0, _tofirstpath.toFirstPath)(pathEntry); if (!pathStr) { continue; } if (!(0, _pointstoprojectindex.pointsToProjectIndex)(tree, pathStr, sourceRoot)) { continue; } if ((0, _iswildcardalias.isWildcardAlias)(alias, pathStr)) { return resolveWildcardAlias(alias, sourceRoot, projectName); } return alias; } return null; } //# sourceMappingURL=get-project-import-path.js.map